;+
;                REF_DAY_PLOT
;
;  Procedure to do summary plot of a day's worth of reformatted CaXIX data
;
;   cdp    May 92
;
;  Input:
;          infil              The generic file name for the day of interest
;                             eg. YDB:[BDA]BDA920401.*
;
;  Use:
;          IDL>  ref_day_plot,infil
;
;-

pro ref_day_plot,infil

common utcommon,a,b,c,d
;
;  stretch if postscript plotter
;
if !d.name eq 'PS' then device,ysiz=25.,yoffset=3.

;
;  4 on a page
;
!p.multi = [0,0,4]
;
;  get all file names for this day
;
ff = findfile(infil)
if ff(0) eq '' then begin
   plot,[0,0],[0,0],/nodata
   erase
   xyouts,0.4,0.5,'NO DATA ON THIS DAY',charsize=2,/normal
   xyouts,0.8,0.95,strmid(infil,9,11),/normal,charsize=2
   xyouts,0.8,0.0,strmid(infil,9,11),/normal,charsize=2
   return
endif
;
;  read the roadmap
;
rd_roadmap,ff,roadmap
;
;  split times into 4 x 6 hr segments
;
tt = roadmap.time/3600./1000. + (roadmap.day - roadmap(0).day)*24.0
t1 = max(where(tt lt 6.0))
t2 = where(tt ge 6.0  and tt lt 12.0)
t3 = where(tt ge 12.0 and tt lt 18.0)
t4 = where(tt ge 18.0 and tt lt 24.0)

;
;  set up for title
;
break_file,ff(0),disk,dir,fil,ext
!mtitle = 'Reformatted data for files '+fil+'.*'
!y.title = 'Ca XIX counts/sec'

;
;  split and load all file names
;
break_file,ff,disk,dir,fil,ext
fil = strmid(fil,3,6)
q1 = where(ext lt 0.06)
q2 = where(ext ge 0.06 and ext lt 0.12)
q3 = where(ext ge 0.12 and ext lt 0.18)
q4 = where(ext ge 0.18 and ext lt 0.235)

;
;  plot first 0-6 hours
;

st = fid2ex(fil(0)+'.0000')

if t1 gt 0 then begin
   s = int2secarr(st)
   e = s + 6.0*3600.
   cnts = (roadmap(0:t1).total_cnts(2)*10.)/(roadmap(0:t1).dgi*0.125)
   pmax = min([5000.,max(cnts)])
   utplot,roadmap(0:t1),cnts,st,psym=3,xrange=[s,e],xstyle=1,yrange=[0.,pmax]
   for i=0,n_elements(q1)-1 do begin
      xval = int2secarr(fid2ex(fil(q1(i))+ext(q1(i))),d)
      xyouts,xval+500.,pmax*0.9,ext(q1(i))
      outplot,[xval,xval],[0,2.*pmax],st
   endfor
;
;  clear main title
;
   !mtitle = ' '
endif else begin
   if t1 eq 0 then begin
      !p.multi(0) = 3
      xyouts,0.4,0.85,'Only one datum in this interval',$
                        charsize=1.2,/normal
   endif else begin
      !p.multi(0) = 3
      xyouts,0.4,0.85,'NO DATA',charsize=3,/normal
   endelse
endelse
;
;  second 6-12 hours
;
if n_elements(t2) gt 1 then begin
   s = int2secarr(fid2ex(fil(0)+'.0600'),st)
   e = s + 6.0*3600.
   cnts = (roadmap(t2).total_cnts(2)*10.)/(roadmap(t2).dgi*0.125)
   pmax = min([5000.,max(cnts)])
   utplot,roadmap(t2),cnts,st,psym=3,xrange=[s,e],xstyle=1,yrange=[0.,pmax]
   if q2(0) gt 0 then begin
       for i=0,n_elements(q2)-1 do begin
          xval = int2secarr(fid2ex(fil(q2(i))+ext(q2(i))),d)
          xyouts,xval+500.,pmax*0.9,ext(q2(i))
          outplot,[xval,xval],[0,2.*pmax],st
       endfor
   endif
endif else begin
   if t2(0) gt 0 then begin
      !p.multi(0) = 2
      xyouts,0.4,0.6,'Only one datum in this interval',$
                charsize=1.2,/normal
   endif else begin
      !p.multi(0) = 2
      xyouts,0.4,0.6,'NO DATA',charsize=3,/normal
   endelse
endelse
;
;  third 12-18 hours
;
if n_elements(t3) gt 1 then begin
   s = int2secarr(fid2ex(fil(0)+'.1200'),st)
   e = s + 6.0*3600.
   cnts = (roadmap(t3).total_cnts(2)*10.)/(roadmap(t3).dgi*0.125)
   pmax = min([5000.,max(cnts)])
   utplot,roadmap(t3),cnts,st,psym=3,xrange=[s,e],xstyle=1,yrange=[0.,pmax]
   if q3(0) gt 0 then begin
       for i=0,n_elements(q3)-1 do begin
          xval = int2secarr(fid2ex(fil(q3(i))+ext(q3(i))),d) 
          xyouts,xval+500.,pmax*0.9,ext(q3(i))
          outplot,[xval,xval],[0,2.*pmax],st
       endfor
   endif
endif else begin
   if t3(0) gt 0  then begin
      !p.multi(0) = 1
      xyouts,0.4,0.35,'Only one datum in this interval',$
                       charsize=1.2,/normal
   endif else begin
      !p.multi(0) = 1
      xyouts,0.4,0.35,'NO DATA',charsize=3,/normal
   endelse
endelse
;
;  fourth 18-24 hours
;
if n_elements(t4) gt 1 then begin
   s = int2secarr(fid2ex(fil(0)+'.1800'),st)
   e = s + 6.0*3600.
   cnts = (roadmap(t4).total_cnts(2)*10.)/(roadmap(t4).dgi*0.125)
   pmax = min([5000.,max(cnts)])
   utplot,roadmap(t4),cnts,st,psym=3,xrange=[s,e],xstyle=1,yrange=[0.,pmax]
   if q4(0) gt 0 then begin
       for i=0,n_elements(q4)-1 do begin
          xval = int2secarr(fid2ex(fil(q4(i))+ext(q4(i))),d)
          xyouts,xval+500.,pmax*0.9,ext(q4(i))
          outplot,[xval,xval],[0,2.*pmax],st
       endfor
   endif
endif else begin
   if t4(0) gt 0 then begin
      xyouts,0.4,0.1,'Only one datum in this interval',$
                      charsize=1.2,/normal
   endif else begin
      xyouts,0.4,0.1,'NO DATA',charsize=3,/normal
   endelse
endelse
;
;  re-emphasize the name
;   
xyouts,0.80,0.0,strmid(fmt_tim(roadmap(0)),0,10),/normal,charsize=1.5
;
;  reset display parameters
;
!p.multi = 0
!y.title = ' '
if !d.name eq 'PS' then device,/inches,ysiz=5.,yoffset=5.


end
