;  
; Use mean image and cross correlations to improve shifts
; in SWRI calibrated eclipse images
;

pixX = 1024
pixY = 256
img = fltarr(pixX,pixY)
meanimg = img

y0 = 20
numy = 30
x0 = 725
numx = 200
cross=fltarr(21,21)
!x.title='X shift'
!y.title='Y shift'
!z.title='Cross correlation'
!z.range=[0.90,1.0]

loadct,9
 
filenm=' '
listfile='./elist.cal.sft.sft'
 
    close,13 & openr,13,listfile

    close,14 & openr,14,'meanimg' & readu,14,meanimg & close,14

    close,2 & openw,2,'fineshifts'

    ii=0 
    fred=meanimg(x0:x0+numx,y0:y0+numy)
    while ( not eof(13) ) do begin ;{
	img=fltarr(pixX,pixY)
        readf,13,filenm
	close,1 & openr,1,filenm
	readu,1,img
	for jj=-10,10 do begin
		for kk=-10,10 do begin
			mary=shift(img,jj,kk)
			sally=mary(x0:x0+numx,y0:y0+numy)
			cross(jj+10,kk+10) = correlate(fred,sally)
		end
	end
	surface,cross

	m = max(cross)
	jj = !c/21
	ii = !c-jj*21
	print,filenm,ii-10,jj-10
	printf,2,ii-10,jj-10
        ii=ii+1
    endwhile ;} 
 
   close,13
   close,2

    stop

end 
