pro read_diff_movie2,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=2500
rebinsize=4.
numpixrd=row_number*column_number
gap_size=10

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

if bias gt 8 then begin
	bias_str=string(bias,format='(I2)')
endif else begin
	bias_str=string(bias,format='(I1)')
endelse

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_end_1=strsplit(file_parts_1(6),'.',/extract)
        file_end_2=strsplit(file_parts_2(6),'.',/extract)

        file_num_1=file_end_1(0)
        file_num_2=file_end_2(0)

	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([512,512],quality=40)

for read_num=0,total_frames-1 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_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 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,512,512),min=-threshold,max=threshold)

for i=0,gap_size do begin 
	mpeg_put,poofy_movie,IMAGE=diff,FRAME=((read_num*gap_size)+i) 
endfor

endfor

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

end

