;PHASE_OUT_PLOT
;
;PURPOSE:
;	This script will take in a phase screen generated by turb2d.c (written
;	by Garret Jernigan) and generate a color image of that screen
;
;CALLING SEQUENCE:
;	phase_out_plot,


pro phase_scroll_plot_soar,Date=Date,$
                   xwindspeed=xwindspeed,ywindspeed=ywindspeed,$
                   depth=depth,k=k,phase_dim=phase_dim,$
                   low=low,lcut=lcut

If (not keyword_set(Date)) then Date='11'
If (not keyword_set(Date)) then Date='11'
If (not keyword_set(xwindspeed)) then xwindspeed=25
If (not keyword_set(ywindspeed)) then ywindspeed=25
If (not keyword_set(depth)) then depth=0
If (not keyword_set(k)) then k=100
If (not keyword_set(phase_dim)) then phase_dim=long(1024)
If (not keyword_set(low)) then low=100.5
If (not keyword_set(lcut)) then lcut=10000.0
                                       
lowstr=strtrim(string(low,format='(%"%10.1f")'),2)
lcutstr=strtrim(string(lcut,format='(%"%10.1f")'),2)

;DIMENSIONS OF PHASE SCREEN
phase_dim=1024
sub_sec=64
offset=sub_sec/2-12

color_screen_sub=indgen(sub_sec,sub_sec,3)
stats_dir='/nfs/slac/g/ki/ki08/lsst/CPanalysis/2005-05-'+Date+$
	'/ShackHartman/coo/'
atmosphere_dir='/nfs/slac/g/ki/ki08/lsst/CPanalysis/lsst_sim/atmosphere/'
color_screen=indgen(phase_dim,phase_dim,3)
openr,phase,atmosphere_dir+'phase_'+strtrim(lowstr,2)+'_'+$
           strtrim(lcutstr,2)+'*.out',/get_lun
screen=read_binary(phase,data_dims=[phase_dim,phase_dim],data_type=4)

max_screen=max(screen)
min_screen=min(screen)

screen_val=floor(255*((screen-min_screen)/(max_screen-min_screen)))

readcol,stats_dir+'fiducial_reference.txt',spots,format='x,x,f'
spot_arr=intarr(25,25)
spot_arr(spots)=130



loadct,36
tvlct,R,G,B,/get

color_screen(*,*,0)=r(screen_val)
color_screen(*,*,1)=g(screen_val)
color_screen(*,*,2)=b(screen_val)

for segment=0,200 do begin

  color_screen_sub[*,*,0]=color_screen[segment:segment+sub_sec-1,$
    segment:segment+sub_sec-1,0]
  color_screen_sub[*,*,1]=color_screen[segment:segment+sub_sec-1,$
    segment:segment+sub_sec-1,1]
  color_screen_sub[*,*,2]=color_screen[segment:segment+sub_sec-1,$
    segment:segment+sub_sec-1,2]
  color_screen_sub[offset:offset+24,offset:offset+24,0]=$
    color_screen_sub[offset:offset+24,offset:offset+24,0]+spot_arr
 
;  color_screen_sub[offset:offset+24,offset:offset+24,1]=$
 ;   color_screen_sub[offset:offset+24,offset:offset+24,1]+spot_arr
 
  wait,.001
  tv,congrid(color_screen_sub,512,512,3,/center),true=3

endfor
stop

end

