pro xy_offsets_cn_plot,Date=Date,stats_directory=stats_directory,letter=letter

If (not keyword_set(Date)) then Date='10'
If (not keyword_set(stats_directory)) then stats_directory='stats_temp'
If (not keyword_set(letter)) then letter=['a','b','c','d','e','f','g','h','i']

Directory='/a/pippin01/Volumes/u08/lsst/CPanalysis/2005-05-'+Date+$
          '/ShackHartman/'+stats_directory+'/'
postscript_dir='/a/pippin01/Volumes/u08/lsst/CPanalysis/2005-05-'+Date+$
          '/ShackHartman/postscripts/'

letters=N_elements(letter)

cxl_full=fltarr(letters*100,24)
cxt_full=fltarr(letters*100,24)
cyl_full=fltarr(letters*100,24)
cyt_full=fltarr(letters*100,24)

for letter_index=0, letters-1 do begin

	for file_index=1,100 do begin

		num=letter_index*100+file_index-1
	 
		xcor_name=Directory+'hr5132'+letter(letter_index)+'_'+$
                  strtrim(string(file_index),2)+'_xcorrelations.txt'
        	ycor_name=Directory+'hr5132'+letter(letter_index)+'_'+$
                  strtrim(string(file_index),2)+'_ycorrelations.txt'

		 readcol,xcor_name,cxl,cxt,format='(f,f)'
		 readcol,ycor_name,cyl,cyt,format='(f,f)'

		 cxl_full(num,*)=cxl
		 cxt_full(num,*)=cxt
		 cyl_full(num,*)=cyl
		 cyt_full(num,*)=cyt

	
	endfor
endfor

Cxt_means=fltarr(24)
Cxl_means=fltarr(24)
Cyt_means=fltarr(24)
Cyl_means=fltarr(24)


for n=0, 23 do begin

        Cxt_means(n)=mean(Cxt_full(*,n))
        Cxl_means(n)=mean(Cxl_full(*,n))
        Cyl_means(n)=mean(Cyl_full(*,n))
        Cyt_means(n)=mean(Cyt_full(*,n))

endfor

set_plot,'ps'
device,filename=Postscript_dir+'Cn.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=1.2
!P.THICK=4.
;!P.NOERASE=0
;!P.POSITION=[0.10,0.10,0.9,0.9]


plot,findgen(24)+1,Cxt_means,psym=1,title="Transverse correlation along X direction",$
	       xtitle="n",ytitle="Covariance",$
               background=white,color=black,$
	       yrange=[min(Cxt_means)-.5,max(Cxt_means+.5)],$
	       POSITION=[0.10,0.10,0.9,0.9] 
plot,findgen(24)+1,Cxl_means,psym=1,title="Longitudinal correlation along X direction",$
               xtitle="n",ytitle="Covariance",$
               background=white,color=black,$
               yrange=[min(Cxl_means)-.5,max(Cxl_means+.5)],$
               POSITION=[0.10,0.10,0.9,0.9]

plot,findgen(24)+1,Cyt_means,psym=1,title="Transverse correlation along Y direction",$
               xtitle="n",ytitle="Covariance",$
               background=white,color=black,$
               yrange=[min(Cyt_means)-.5,max(Cyt_means+.5)],$
               POSITION=[0.10,0.10,0.9,0.9]

plot,findgen(24)+1,Cyt_means,psym=1,title="Longitudinal correlation along Y direction",$
               xtitle="n",ytitle="Covariance",$
               background=white,color=black,$
               yrange=[min(Cyl_means)-.5,max(Cyl_means+.5)],$
               POSITION=[0.10,0.10,0.9,0.9]

device,/close
set_plot,'X'



end
