;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
;	simply for viewing purposes.
;
;CALLING SEQUENCE:
;	phase_out_plot,


pro phase_out_plot,screennum=screennum,low=low,lcut=lcut

if (not keyword_set(screennum)) then screennum=0.0
If (not keyword_set(low)) then low=100.5
If (not keyword_set(lcut)) then lcut=10000.0
phase_dim=1024
slopes=0;

lowstr=strtrim(string(low,format='(%"%10.1f")'),2)
lcutstr=strtrim(string(lcut,format='(%"%10.1f")'),2)
screenumstr=strtrim(string(screennum,format='(%"%d")'),2)

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)+'_'+strtrim(screenumstr,2)+$
      '.out',/get_lun

if (slopes eq 1) then begin


openr,see,atmosphere_dir+'see_'+strtrim(lowstr,2)+'_'+$
      strtrim(lcutstr,2)+'_'+strtrim(screenumstr,2)+$
      '.out',/get_lun

  readcol,atmosphere_dir+'see_'+strtrim(lowstr,2)+'_'+$
      strtrim(lcutstr,2)+'_'+strtrim(screenumstr,2)+$
      'x.out',x_slopes,format='f'

  readcol,atmosphere_dir+'see_'+strtrim(lowstr,2)+'_'+$
      strtrim(lcutstr,2)+'_'+strtrim(screenumstr,2)+$
      'y.out',y_slopes,format='f'

  slopes=read_binary(see,data_dims=[phase_dim,phase_dim],data_type=4)
endif
  
  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)))

set_plot,'x'

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)

tv,congrid(color_screen,1024,1024,3),true=3

stop

end

