;NAME:
;  pro cmos_ramp_diff_slideshow
;
;PURPOSE:
;  To provide a visual display of the difference between two successive reads
;  of an H2RG array dark exposure.  The difference image should consist 
;  entirely of cosmic ray events.
;
;CALLING SEQUENCE:
;  cmos_ramp_diff_slideshow,[filename[,cmos_dir]]
;
;KEYWORDS: 
;  filename		the name of the particular .fits file that will
;			be displayed
;  cmos_dir		the path to the directory containing the files
;			the default is 
;			/nfs/slac/g/ki/ki08/lsst/sipinrocwell/65_Meg_Files
;

pro cmos_ramp_diff_slideshow,filename=filename,cmos_dir=cmos_dir

if (not keyword_set(cmos_dir)) then $
	cmos_dir='/nfs/slac/g/ki/ki08/lsst/sipinrockwell/65_Meg_Files/'
if (not keyword_set(filename)) then $
	filename='dark_160K_33_min_1_10.0_37.fits'
file_path=cmos_dir+filename
fits_read,file_path,im,h	;read in image and header
row_count=sxpar(h,'NAXIS1')		;number of pixels in a row
column_count=sxpar(h,'NAXIS2')	 	;number of pixels in a column
total_reads=sxpar(h,'NAXIS3')		;number of reads in the file
arr_size=row_count*column_count		;number of pixels in single read
threshold=1000  		        ;Threshold to flag pixel as Cosmic Ray

diff_arr=fltarr(2)
window,xsize=512,ysize=624
for read_num=6,total_reads-2 do begin
  ;Take only two reads into memory...5GB files can't be opened with mrdfits
  fits_read,file_path,frame1,first=long(read_num*arr_size),$
			    last=long((read_num+1)*arr_size)-1
  fits_read,file_path,frame2,first=long((read_num+1)*arr_size),$
			    last=long((read_num+2)*arr_size)-1
  diff=float(frame2-frame1)
  ;frame1=reform(float(frame1),row_count,column_count)		
  ;frame2=reform(float(frame2),row_count,column_count)
  diff_arr=[diff_arr,diff]
  diff=reform(float(diff),row_count,column_count)
  tv,bytscl(congrid(diff,512,512,/center),min=0,max=1000)
  ;tv,congrid(diff,1024,1024)
  colorbar,range=[min(diff),max(diff)],$
        format='(f10.2)',$
        position=[0.1,0.92,0.9,0.97],color=255,$
        title='intensity'
  xyouts,.1,.85,'Read Numbers '+strtrim(read_num,2)+' and '+$
	 strtrim(read_num+1,2),color=255,/normal
  wait,0.9
  erase
endfor
stop

end


