pro shackgrid, Directory=Directory

If (not keyword_set(Directory)) then Directory='/a/pippin01/Volumes/u08/lsst/CPanalysis/2005-05-10/ShackHartman/'

x_ref_col=[225,250,278,302,332,353,380,404,428,452,476,502,528,532,554,578,604,630,$
	654,680,704,730,754,780,806,832,856]
y_ref_col=[144,164,188,214,238,264,290,314,340,366,390,414,440,464,490,516,542,568,$
	592,616,642,668,692,718,742,768,794]


for file_number=1, 100 do begin
                                                                                
	if file_number lt 10 then file_name=Directory+'hr5132a_'+$
		string(file_number,format='(I1)')+'_raw.fits.coo.1'
	if file_number ge 10 and file_number lt 100 then file_name=Directory+'hr5132a_'+$
		string(file_number,format='(I2)')+'_raw.fits.coo.1'
	if file_number ge 100 and file_number lt 1000 then file_name=Directory+'hr5132a_'+$
		string(file_number,format='(I3)')+'_raw.fits.coo.1'

	readcol,file_name,x_coord,y_coord,format='f,f',SKIPLINE=42

	;This loop will go through all of the possible places where a point could be
	;and check to see if there is an image point near it
	for col_num=0,N_elements(y_ref_col)-1 do begin
		for row_num=0,N_elements(x_ref_col)-1 do begin

				;Pick points where x might be near and those where y might 
				;be near
				x_index_pos=where(abs(x_coord-x_ref_col(row_num)) lt 4)
				y_index_pos=where(abs(y_coord-y_ref_col(col_num)) lt 4)
				
				
				for y_sub_index=0,N_elements(y_index_pos)-1 do begin
					x_sub_index=where(x_index_pos eq $
							  y_index_pos(y_sub_index))
					if (x_sub_index(0) ne -1) then begin
						x_index=x_index_pos(x_sub_index)
						y_index=y_index_pos(y_sub_index)
						
						print,FORMAT='(%"%d\t\t%0.2f\t\t%0.2f")',col_num*N_elements(x_ref_col)+row_num,x_coord(x_index),y_coord(y_index)
						found_point=1
						break
					endif else begin
						found_point=0
					endelse
				
				endfor
				
				if found_point eq 0 then print,FORMAT='(%"%d\t\t%d\t\t%d")',col_num*N_elements(x_ref_col)+row_num,-1,-1
	
				
		endfor
	endfor 

endfor

end
