pro makeqepics

	;indir='C:\figerdev\idtl\sipinrockwell\H1RG-18-SIPIN\cold2\dqe.15Jun04\temp\'
	;skip=1
	indir='\\rabbit\raid2\snaprockwell\H2RG-32-39\cold2\dqe.19May04\'
	skip=1
	outdir=indir

	x1=0
	x2=2047
	y1=0
	y2=2047

	cd,indir
	onlist=file_search('*_140K.fits')
	off='dqe_scan_bias_140K.fits'
	im1=readfits(off)*1.

	; this loop cycles over all images
	for i=0,n_elements(onlist)-1 do begin

		; this loop cycles over the number of types of pixels on a device, i.e. 1 type for H1RG-18-SIPIN and two
		; types for H1RG-021-SIPIN
		for j=0,skip-1 do begin

			; check to see if we are analyzing data from a detector that has separate types of pixels in alternating rows
			; if so, we should analyze the odd and even rows separately. on the second pass through this for loop, we should
			; start at row number 1.
			im2=readfits(onlist(i))*1.
			diff=im2(x1:x2,j:y2:skip,1)-im2(x1:x2,j:y2:skip,0)-(im1(x1:x2,j:y2:skip,1)-im1(x1:x2,j:y2:skip,0))
			meddiff=median(diff)
			min=meddiff*.8
			max=meddiff*1.2

			print,'processing '+onlist(i)

			; set text in JPG file name to indicate which pixels were processed
			if (skip eq 1) then ext=''
			if (skip eq 2 and j eq 0) then ext='evens'
			if (skip eq 2 and j eq 1) then ext='odds'

			jpgfile = outdir+strmid(onlist(i),0,strpos(onlist(i),'.fits'))+'_'+ext+'.jpg'
			; set up to plot to memory buffer.  This plot will later be
			; written from memory to a JPEG file.
			set_plot, 'z'
			sizeim=size(diff)

			device, set_resolution=[sizeim(1),sizeim(2)]
			device, set_font='Courier'
			fsub = jpgfile		; filename to be written at bottom of plot

			tv,bytscl(diff,min=min,max=max)

			jpgimg = tvrd()
			write_jpeg, jpgfile, $
			congrid(jpgimg, sizeim(1),sizeim(2), /interp, /center), quality=70

			device, /close

		endfor
	endfor

end

