;All_Centroids
;
;This script will obtain every centroid found by IRAF and plot it up

pro All_Centroids,Date=Date

If (not keyword_set(date)) then date='10'

coo_dir='/a/pippin01/Volumes/u08/lsst/CPanalysis/2005-05-'+date+'/ShackHartman/coo/'
postscript_dir='/a/pippin01/Volumes/u08/lsst/CPanalysis/2005-05-'+date+'/ShackHartman/distorted_postscripts/'

coordinate_files=file_search(coo_dir+'*raw.fits.coo.1',count=num_coo_files)

;FIDUCIAL-These points will not be included in the analysis
fiducial=[1,2,3,4,5,6,7,8,18,19,20,21,22,23,24,25,$
          26,27,28,29,30,31,45,46,47,48,49,50,$
          51,52,53,54,55,72,73,74,75,$
          76,77,78,79,98,99,100,$
          101,102,103,123,124,125,$
          126,127,149,150,$
          151,152,174,175,$
          176,200,$
          201,225,$
          238,239,$
          261,262,263,264,265,266,$
          286,287,288,289,290,291,$
          301,302,303,304,305,306,307,308,309,$
          310,311,312,313,314,315,316,$
          317,318,319,320,321,322,323,324,325,$
          336,337,338,339,340,341,$
          361,362,363,364,365,366,$
          388,389,$
          401,425,$
          426,427,449,450,$
          451,452,452,473,474,475,$
          476,477,478,498,499,500,$
          501,502,503,504,522,523,524,525,$
          526,527,528,529,530,546,547,548,549,550,$
          551,552,553,554,555,556,570,571,572,573,574,575,$
          576,577,578,579,580,581,582,594,595,596,597,598,599,600,$
          601,602,603,604,605,606,607,608,609,617,618,619,620,621,$
          622,623,624,625]-1

;Here is the reference grid I am using to index the spots
num=25
x_center=[542]
y_center=[465]
subx=2*indgen(num)-25           ;The x-reference numbers
suby=indgen(num)-12             ;The y-reference numbers

x_ref_col=12.5*subx+x_center[0]
y_ref_col=25.0*suby+y_center[0]

xcoord_arr=[0]
ycoord_arr=[0]

for i=0, num_coo_files-1 do begin
  readcol,coordinate_files(i),xcoord,ycoord,format='f,f',skipline=41
  xcoord_arr=[xcoord_arr,xcoord]
  ycoord_arr=[ycoord_arr,ycoord]

endfor

set_plot,'ps'
device,filename=Postscript_Dir+'All_IRAF_centroids.ps'
loadct,39                       ;load color table 39
device,/color                   ;allow color on the postscript
device,ysize=8.5,/inches        ;Height of plot in y
device,xsize=10.0,/inches        ;Width of plot in x
device,yoffset=1.0,/inches      ;Y position of lower left corner
                                                                                
white='FFFFFF'x
black='000000'x
!P.CHARSIZE=.7 
!P.THICK=4.

plot,xcoord_arr(where(xcoord_arr ne 0)),ycoord_arr(where(ycoord_arr ne 0)),$
	xrange=[140,860],yrange=[100,800],psym=3

;Draw the lines
for j=0, num-1 do begin
   left=[x_ref_col(j)-11,x_ref_col(j)-11]
   right=[x_ref_col(j)+11,x_ref_col(j)+11]
   top=[y_ref_col(j)+11,y_ref_col(j)+11]
   bottom=[y_ref_col(j)-11,y_ref_col(j)-11]
   oplot,[0,1000],top
   oplot,[0,1000],bottom
   oplot,left,[0,1000]
   oplot,right,[0,1000]
endfor

device,/close
stop

end
