;+ 
; NAME:
;     LASTSFD_DIFF
; PURPOSE:
;     Compare two SFDs as a difference on an exaggerated color table.
;     Shows Q res AlMg's or Al.1 upon demand, otherwise defaults to
;       half-res Al.1.
;     Main purpose is to do the most recent daily difference to search
;       for emerging flux and/or other interesting variations.
; CATEGORY:
; CALLING SEQUENCE:
;     lastsfd_diff
;     lastsfd_diff, number = 10
; INPUTS:
;     infil (optional) a range of file ID's. Default is the last few (see
;       NUMBER below).  
; OPTIONAL (KEYWORD) INPUT PARAMETERS:
;     diff_range, the DN range bytescaled out to the image
;     /scale, calls DIFF_SCALE to show the double-square-root version
;     /thinal, requires an Al.1 difference
;     n_start is the most recent file to consider
;     number = number of files to get (default 5 normally handles a
;       one-day operations cycle)
; OUTPUTS:
; COMMON BLOCKS:
; SIDE EFFECTS:
;     works best with color table 0
;     puts an image up on your current window
; RESTRICTIONS:
; MODIFICATION HISTORY:
;     23-Oct-98, written by HSH
;      6-Nov-98, added /thinal and number (HSH)
;     22-Nov-98, complete lube and oil job on the logic (HSH)
;      7-Jan-99, made thin Al the default (replaced /thinal with /dag) 
;        and reset the default diff_range (HSH)
;     14-May-99, debugged and changed some parameters. Replaced
;        FINDFILE with FILE_LIST (HSH)
;     10-jan-99, sorted infil by time.  (y2k) (PGS)
;-
pro lastsfd_diff, scale=scale, diff_range=diff_range, dag = dag, $
  quart = quart, n_start = n_start, number = number, qstop=qstop
if n_elements(diff_range) eq 0 then diff_range = 100
if n_elements(number) eq 0 then number = 5
if n_elements(n_start) eq 0 then n_start = 0
infil_t = file_list(data_paths(),'sfd*',/cd)
infil   = infil_t(sort(file2time(infil_t))) ;y2k (pgs)
n_fil = n_elements(infil)
fil_start = n_fil - n_start - number
infil = infil(fil_start + indgen(number))
rd_roadmap,infil,rm
th = where(gt_filtb(rm) eq 2, n_th)
dag_ha = where(gt_filtb(rm) eq 3 and gt_res(rm) eq 1)
dag_qu = where(gt_filtb(rm) eq 3 and gt_res(rm) eq 2)
if n_th gt 1 then begin
  i1 = min(th)
  i2 = max(th)
endif else begin
  dag = 1
endelse
if n_elements(dag) ne 0 then begin
  i1 = min(dag_ha)
  i2 = max(dag_ha)
endif
if n_elements(quart) ne 0 then begin
  i1 = min(dag_qu)
  i2 = max(dag_qu)
endif
rd_xda,infil,[i1,i2],index,data
diff = sfd_decomp(data(*,*,1))-sfd_decomp(data(*,*,0))
;wdef,0
tv,bytscl(rebin(diff,512,512,/samp),min=-diff_range,max=diff_range)
charsize=1.5
if !d.name eq 'Z' then charsize=charsize*.6
xyouts,10,10,/dev,gt_filtb(index(0),/str)+': '+fmt_tim(index(1))+$
  ' minus '+fmt_tim(index(0)),charsize=charsize
if keyword_set(scale) then begin
  tv,bytscl(rebin(diff_scale(diff),512,512))
; xyouts,10,10,/dev,gt_filtb(index(0),/str)+': '+fmt_tim(index(1))+$
;   ' minus '+fmt_tim(index(0)),charsi=1.5
endif
if keyword_set(qstop) then stop
end
