pro sci5k_disp_img2, infil, idpc, new_disp=new_disp, window=window, $
		missing=missing, charsize=charsize, disp_size=disp_size, win_size=win_size
;
;
;
if (n_elements(win_size) eq 0) then win_size = 700
if (keyword_set(new_disp)) then wdef, xx, 700, 700, /free
tv2, win_size, 0.7*win_size, /already, /init, win=!d.window>0
if (keyword_set(new_disp)) then return
if (keyword_set(window)) then return
if (n_elements(charsize) eq 0) then charsize = 0.6
;
if (n_elements(disp_size) eq 0) then disp_size = 128
xsiz = disp_size
;
	img = rfits(infil, head=head)
	nnn = n_elements(img)
	img(nnn-1) = img(nnn-2)		;MDM added 14-Mar-96 to avoid problem with the downlink # of pixels
	;;if (n_elements(missing) eq 0) then missing = min(img) - 0.25 * (max(img)-min(img))
	if (n_elements(missing) eq 0) then missing = min(img) - 0.25 * (max(img)-min(img))
	bimg = mk_dpc_image(xsiz, img, head=head, /pixmap2, missing=missing)
	if (n_elements(bimg) gt 1) then begin		;found the necessary information to build the image
	    if (n_elements(bimg(*,0)) ne xsiz) then bimg = congrid(bimg, xsiz, xsiz/2)		;limb figure
	    if (n_elements(img) eq 1) then img = [0,0]		;Patch for bad FITS file
	    ;
	    int_dpc = sxpar(head, 'dpc')
	    if (data_type(int_dpc) eq 7) then begin
		str_dpc = int_dpc
		int_dpc = 0L
		reads, str_dpc, int_dpc, format='(z8)'
	    end
	    str_dpc = string(int_dpc, format='(z8)')
	    get_dpc_info, int_dpc, nx, ny, npix, sum, err, mnem
	    x0 = (idpc mod 3) * (xsiz+94)
	    y0 = (idpc/3) * xsiz*1.1
	    ss = where(img ne -32768, nss)		;MDM added screening for non-missing (-32768) for scaling
	    if (nss eq 0) then imin = 0 else imin = min(img(ss))
	    if (nss eq 0) then imax = 0 else imax = max(img(ss))
	    if (n_elements(img) eq 180) then begin	;MDM added 28-May-96 to handle LOI normalization case
		imin = min(bimg)
		imax = max(bimg)
	    end
	    sminmax = get_mdi_scale(int_dpc)
	    if (sminmax(0) ne sminmax(1)) then begin
		imin = sminmax(0)
		imax = sminmax(1)
	    end
	    tv2, bytscl(bimg, imin, imax, top=!d.n_colors-1), x0, y0
	    idev = stdev(img, iavg)
	    tim = sxpar(head, 'T_REF')
	    tim = str_replace(tim, '.', '/')
	    tim = str_replace(tim, '_', ' ')
	    tim = str_replace(tim, 'TAI', '')

	    xyouts2, charsize=charsize, x0+xsiz, y0+7*15,  fmt_tim(tim)
	    xyouts2, charsize=charsize, x0+xsiz, y0+6*15, 'DPC:  ' + str_dpc
	    xyouts2, charsize=charsize, x0+xsiz, y0+5*15, 'Mnem: ' + mnem
	    ;;xyouts2, charsize=charsize, x0+xsiz, y0+4*15, 'Imin: ' + string(fix(min(img)))
	    ;;xyouts2, charsize=charsize, x0+xsiz, y0+3*15, 'Imax: ' + string(fix(max(img)))
	    xyouts2, charsize=charsize, x0+xsiz, y0+4*15, 'Imin: ' + string(fix(imin))
	    xyouts2, charsize=charsize, x0+xsiz, y0+3*15, 'Imax: ' + string(fix(imax))
	    xyouts2, charsize=charsize, x0+xsiz, y0+2*15, 'Iavg: ' + string(iavg)
	    xyouts2, charsize=charsize, x0+xsiz, y0+1*15, 'Idev: ' + string(idev)
	end

end
;--------------------------------------------------------------
pro disp_sci5k, dattim, indir=indir, missing=missing, charsize=charsize, $
			disp_size=disp_size, dpc_filter=dpc_filter, win_size=win_size
;+
;SAMPLE CALLING SEQUENCE:
;	disp_sci5k, '1-Jun-97'
;	disp_sci5k, '2-Jul-97', disp_size=256, dpc_filter='168*', win_size=400
;HISTORY:
;	Written Feb-96 by M.Morrison
;	14-Mar-96 (MDM) - Added "missing" keyword option
;			- Dropped the last data point from the scaling
;	 2-Apr-96 (MDM) - Scale only for the range of values which are non -32768 (missing)
;			- let missing be 0 by default
;			- display the min/max excluding the missing
;	28-May-96 (MDM) - Added special handling of LOI image
;	12-Sep-96 (MDM) - Modified to not grab the image on the edge
;			  of the requested time since it is probably
;			  incomplete
;	14-Apr-97 (MDM) - Added call to GET_MDI_SCALE to force magnetogram scaling
;	 2-Jul-97 (MDM) - Added DISP_SIZE and DPC_FILTER options, WIN_SIZE
;	27-May-99 (RIB) - Selected only 0* and 168* dpcs
;	22-Nov-99 (RIB) - Changed indir fromm /md84/fits to $MDI_FITS_DIR
;-
;
;
;if (n_elements(indir) eq 0) then indir = '/md84/fits/sci5k/lev0'
if (n_elements(indir) eq 0) then indir = concat_dir(getenv('MDI_FITS_DIR'),'sci5k/lev0')
;
dpc_dirs = file_list(indir, '*', /cd, file=dpcs)
if (keyword_set(dpc_filter)) then begin
    ss = wc_where(dpcs, dpc_filter, nss)
    if (nss eq 0) then return
end else begin
    ss1 = wc_where(dpcs, '0*', nss1)
    ss2 = wc_where(dpcs, '168*', nss2)
    nss = nss1+nss2
    if (nss eq 0) then return
    ss=lonarr(nss)
    ss(0:nss1-1) = ss1
    ss(nss1:nss-1) = ss2
end
dpc_dirs = dpc_dirs(ss)
dpcs = dpcs(ss)
ndpcs = n_elements(dpcs)
;
tarr = anytim2ex(dattim)
fid = ex2fid(tarr)
fid = str_replace(fid, '.', '_')
filter = strmid(fid, 0, 6) + '*'
;
erase
idpc_disp = 0
for idpc=0,ndpcs-1 do begin
    ff = file_list(dpc_dirs(idpc), filter, file=file)
    if (ff(0) eq '') then begin
	print, 'No files found for DPC: ' + dpcs(idpc) + ' for filter: ' + filter
    end else begin
	file_times = anytim2ints(fid2ex(strmid(file, 0, 13)))
	idset = tim2dset(file_times, tarr)
	n = n_elements(file_times)
	del = int2secarr(file_times(idset), tarr)
	if (del gt  300) then idset = (idset + 1)<(n-1)			;FITS file over 5 minutes in the future
	if (del lt -300) then idset = (idset - 1)>0			;FITS file over 5 minutes in the past
	infil = ff(idset)
	print, 'Processing: ' + infil
	sci5k_disp_img2, infil, idpc_disp, missing=missing, charsize=charsize, disp_size=disp_size, win_size=win_size
	idpc_disp = idpc_disp + 1
    end
end
;
if (idpc_disp eq 0) then begin
    print, 'No SCI5K FITS data files found at all for that day'
end else begin
    xyouts2, !d.x_size/2, !d.y_size-50, align=0.5, 'Requested Time: !c' + fmt_tim(tarr), size=1.5
end
;
end

