pro read_diff_movie3,indir,file_1,file_2

file_name_1=indir+'/'+file_1
;file_name_2=indir+'/'+file_2

fits_read,file_name_1,im,h,/header_only
row_number=sxpar(h,'NAXIS1')
column_number=sxpar(h,'NAXIS2')
total_frames=sxpar(h,'NAXIS3')
temp=sxpar(h,'MOLYTABL')
bias=sxpar(h,'VSUB')
threshold=1000
rebinsize=4.
numpixrd=row_number*column_number

file_parts=strsplit(file_1,'_',/extract)

if N_elements(file_parts) eq 6 then begin

	file_parts_1=strsplit(file_1,'_',/extract)
;	file_parts_2=strsplit(file_2,'_',/extract)

	file_end_1=strsplit(file_parts_1(5),'.',/extract)
;	file_end_2=strsplit(file_parts_2(5),'.',/extract)

	file_num_1=file_end_1(0)
;	file_num_2=file_end_2(0)
	
	tempstr=file_parts_1(1)
	
endif else begin

	file_parts_1=strsplit(file_1,'_',/extract)
 ;       file_parts_2=strsplit(file_2,'_',/extract)

        file_num_1=file_parts_1(4)
  ;      file_num_2=file_parts_2(4)

	tempstr=file_parts(1)

endelse 

Dir_parts=strsplit(indir,'/',/extract)

Dir=Dir_parts(4)+'_'+Dir_parts(6)

;Create MPEG Object to generate movie
poofy_movie=mpeg_open([row_number/rebinsize,column_number/rebinsize],quality=10)

for read_num=0,total_frames-2 do begin

print,'processing frame #',strtrim(string(read_num+1),2)
;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_1,x2,first=long((read_num+1)*numpixrd),last=long((read_num+2)*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 size of dimension in device
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=-threshold,max=threshold)

for i=0,30 do begin & mpeg_put,poofy_movie,IMAGE=diff,FRAME=read_num+i &
endfor

endfor

mpeg_save,poofy_movie,FILENAME=Dir+'_'+tempstr+'_'+file_num_1+'.mpg'
mpeg_close,poofy_movie

end

