pro puffy_events_slideshow

;Files.  These are the two files that will be differenced and used for the slide;show
readsnum=127.
gap_num=2.
total_frames=readsnum*gap_num

file_num_1='28'
file_num_2='29'
temp='160'
Dir='H1RG-022_12May05'

readsstr=string(readsnum,format='(I3)')

file_name_1='/data/skunk3/idtl/data/H1RG-022-SIPIN/cold1/darkcurrent_test.12May05/dark_160K_129_min_1_'+file_num_1+'.fits'
file_name_2='/data/skunk3/idtl/data/H1RG-022-SIPIN/cold1/darkcurrent_test.12May05/dark_160K_129_min_1_'+file_num_2+'.fits'

row_number=1024.
column_number=1024.
numpixrd=row_number*column_number    ;Size of device
threshold=1000       ;Threshold to flag pixel as Cosmic Ray

;Create MPEG Object to generate movie
poofy_movie=mpeg_open([512,512])

for read_num_inc=0,total_frames do begin

;Take in section of one file as the vector x and the section of another file
;as the vector x2
;Make 20 separate frames for each difference image

read_num=floor(read_num_inc/gap_num)

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),row_number,column_number)
im2=reform(float(x2),row_number,column_number)
diff=float(im2-im1)
diff=bytscl(congrid(diff,1024.,1024.),min=-1000,max=1000)

mpeg_put,poofy_movie,IMAGE=diff,FRAME=read_num_inc

;tv,diff

endfor

mpeg_save,poofy_movie,FILENAME=Dir+'_'+temp+'_'+file_num_1+'_'+file_num_2+'.mpg'
mpeg_close,poofy_movie

end


