
; 

openr,2,"cammap1.dat"

map4=intarr(4)
map=intarr(16,20)
m=intarr(20)
i=0L

ecnt = 0
icnt = 0

for i=0,19 do begin
    readf,2,map4
    map(0:3,i) = map4
end
print,map,format='(16z4)'
close,2

;openw,1,"map_results.dat"
openw,1,"map_results.dat",/APPEND

print,format='($,"Enter input file name ")'
read,f

printf, 1, f, format = '(//"Start Processing of File:", a)'

print,"File name: :",f
;printf,1,"File name: :",f
read_mdi,f,i,n,/nimage
print,n

lindex = -1
nn=50
for i=long(start),n-1,nn do begin
;   read_mdi,f,lindgen(nn)+i,im,h,tfr_head=t
   rdtfr,f,first=i+1,nimg=nn,img,t
   for j=0,nn-1 do begin
   m = t(423:442,j)
   index=m(19) mod 20
   print,lindex,index
   if lindex ge 0 then begin
     if index ne (lindex + 1) mod 20 then begin
       icnt = icnt + 1
       print,i+j,lindex,index,format='("Indexing error at Sample ",i5,"  Previous = ",i2,"  Current = ",i2)'
       printf,1,i+j,lindex,index,format='("Indexing error at Sample ",i5,"  Previous = ",i2,"  Current = ",i2)'
     endif
   endif
   lindex = index
       
   print,i+j,n,index,icnt,ecnt,format='("$Processing sample #",i5," of ",i5," Frame Number ",i2," Total errors: ",i5,i5)'
   evec = where (map(*,index) ne m(0:15),count)
   if count ne 0 then begin
       ecnt = ecnt + 1
       print,i+j,index,map(*,index),m(0:15),format='("#",i5," Frame ",i5,"  is bad. Should be:",t60,16z1/," Is:",t60,16z1)'
       printf,1,i+j,index,map(*,index),m(0:15),format='("#",i5," Frame ",i5,"  is bad. Should be:",t60,16z1/," Is:",t60,16z1)'
     end
   end
   end
print,f,n,ecnt,icnt,format='(//"Summary for file ",a,2x,i," Samples ",i," Page Errors ",i," Indexing Errors")'
printf,1,f,n,ecnt,icnt,format='(//"Summary for file ",a,2x,i," Samples ",i," Page Errors ",i," Indexing Errors")'
close,1
end
