pro puffy_events_final_read_dif

;This script will attempt to locate the events on the H2RG-015 that are attributed
;to electron-hole pairs in the CdZnTe 800 um substrate

;Constants.  Force some to be floating point integers
read_num=123

;File numbers.  These are the two files that will be differenced and used
file_number_1=1
file_number_str_1=string(file_number_1,format='(I1)')

file_number_2=5
file_number_str_2=string(file_number_2,format='(I1)')

readsnum=250
readsstr=string(readsnum,format='(I3)')

file_name_1='dark_26K_'+readsstr+'_min_1_0'+file_number_str_1+'.fits'
file_name_2='dark_26K_'+readsstr+'_min_1_0'+file_number_str_2+'.fits'

numpixrd=2048.*2048.    ;Size of device
threshold=1000       ;Threshold to flag pixel as Cosmic Ray

;Enter the directory that holds the dark current files for the device
cd,'\\Rabbit\raid1\Rockwell4\H2RG-015-5.0mu\cold1\dktest.9May03'

;Get the intial Bias from the first read of both ramps
;and then add the two together so they can be subtracted together
fits_read,file_name_1,x1,first=0,last=long(numpixrd)-1
fits_read,file_name_2,x2,first=0,last=long(numpixrd)-1
bias1_offset=reform(float(x1),2048.,2048.)
bias2_offset=reform(float(x2),2048.,2048.)

;Take in section of one file as the vector x and the section of another file
;as the vector x2
fits_read,file_name_1,x1,first=long(read_num*numpixrd),last=long((read_num+1)*numpixrd)-1
fits_read,file_name_2,x2,first=long(read_num*numpixrd),last=long((read_num+1)*numpixrd)-1

;Since x and x2 are one-dimensional vectors, we need to turn them into 2-dimensional
;arrays where the size of each dimension is 2048

im1=reform(float(x1),2048.,2048.)
im2=reform(float(x2),2048.,2048.)
diff=float((im2-bias2_offset)-(im1-bias1_offset))

tv,bytscl(congrid(diff,1024,1024),min=-1000,max=1000)
writefits,'C:\H2RG_15_EVENTS\dktest.9May03\diff'+file_number_str_1+file_number_str_2+'.fits',diff

end


