pro disp_limbfig, dattim, latest=latest, outfil=outfil
;+
;NAME:
;	disp_limbfig
;PURPOSE:
;	To display the current limb figure information
;SAMPLE CALLING SEQUENCE:
;	disp_limbfig
;	disp_limbfig, '1-Nov-97'
;       disp_limbfig, /latest, outfil='latest'
;HISTORY:
;	Written Feb 1999 by R. Bush
;

if (n_elements(dattim) eq 0) then dattim = ut_time()
if (n_elements(outfil) eq 0) then dev = 'x' else dev = 'z'

dir = getenv('MDI_FITS_DIR') + '/sci5k/lev0/168*'
tmp = ''

dev_status = !d.name

set_plot, dev

if (dev eq 'z') then charsize = 1.0 else charsize = 1.2
x0 = 10
y0 = 5

tarr = anytim2ex(dattim)

tim2 = anytim2ints(dattim)
tim1 = tim2
tim1.day = tim2.day - 1
tim = [tim1, tim2]

timarr = anytim2ex(tim)
fid = str_replace( ex2fid(timarr), '.', '_')
filter = strmid(fid, 0, 6) + '*'

ff = file_list(dir, filter, file=file)
nn = n_elements(ff)
print,nn,ff
if (nn eq 0) then return

loop = 1
i = 0

while (loop eq 1) do begin

    if keyword_set(latest) then begin
        i = nn - 2
        loop = 0
    end else begin
        i = i + 1
    end

    infil = ff(i) 
    print,nn, i, infil
    dat = rfits(infil,head=hd)

    tim = sxpar(hd, 'T_REF')
    str_dpc = sxpar(hd, 'DPC')
    hex2dec,strmid(str_dpc,4,1),dr,/quiet
    hex2dec,strmid(str_dpc,5,3),rad,/quiet
    rinner = rad/8.
    router = rinner + dr/2.

    ss = where(dat ne -32768, nss)
    if (nss eq 0) then begin
       imin = 0 
       imax = 0
       iavg = 0 
       idev = 0
    end else begin
       imin = min(dat(ss))
       imax = max(dat(ss))
       imom = moment(dat(ss))
       iavg = imom(0)
       idev = sqrt(imom(1))
    end

    if (dev eq 'z') then begin
        tv2,600,400,/already,/init
        erase
    end else begin
        window,0,xsize=600,ysize=400
    end

    loadct,23

    limb = mk_dpc_image(1024,dat,head=hd,/pixmap2)
    lmbplot = rebin(limb,600,400)
    tv2, bytscl(lmbplot,min=0,max=25000),0,0

    xyouts2, charsize=charsize, x0, y0+4*18, 'T_REF:  ' + tim   ; fmt_tim(tim)
    xyouts2, charsize=charsize, x0, y0+3*18, 'DPC:    ' + str_dpc
    xyouts2, charsize=charsize, x0, y0+2*18, 'Rinner: ' + string(rinner, format='(f8.1)')
    xyouts2, charsize=charsize, x0, y0+1*18, 'Router: ' + string(router, format='(f8.1)')
    xyouts2, charsize=charsize, x0+400, y0+4*18, 'Imin:   ' + string(fix(imin), format='(i6)')
    xyouts2, charsize=charsize, x0+400, y0+3*18, 'Imax:   ' + string(fix(imax), format='(i6)')
    xyouts2, charsize=charsize, x0+400, y0+2*18, 'Iavg:   ' + string(fix(iavg), format='(i6)')
    xyouts2, charsize=charsize, x0+400, y0+1*18, 'Idev:   ' + string(fix(idev), format='(i6)')
    xyouts2, charsize=charsize, x0+120, y0+130, 'North
    xyouts2, charsize=charsize, x0+270, y0+130, 'East'
    xyouts2, charsize=charsize, x0+420, y0+130, 'South'

    if (dev eq 'z') then begin
        outfil1 = outfil + '.gif'
        file_delete, outfil1
        zbuff2file, outfil1, /gif
    end

    if (dev eq 'z') then begin
        tv2,500,400,/already,/init
        erase
        loadct, 0
    end else begin
        window,1,xsize=500,ysize=400
    end

    xx = 'DPC = ' + str_dpc
    yy = 'Intensity'
    ll = fix(505 - router)
    rr = fix(479 + router)

    img = mk_dpc_image(1024,dat,head=hd)         
    plot,img(ll:ll+40,512), title = tim, xtitle = xx, ytitle = yy, yrange=[0,25000]
    oplot,img(rr:rr+40,512)			;west
    oplot,img(512,ll:ll+40), linestyle = 2	;south
    oplot,img(512,rr:rr+40), linestyle = 2	;north
    xyouts2, charsize=charsize, 200, 345, 'Solid - E/W; Dashed - S/N'

    if (dev eq 'z') then begin
        outfil2 = outfil + '_profile.gif'
        file_delete, outfil2
        zbuff2file, outfil2, /gif
    end

    if not keyword_set(latest) then begin
        read,tmp,prompt='next:'
        if (tmp ne '') then loop = 0
	if (i eq nn - 2) then loop = 0
    end

end

set_plot, dev_status

end
