pro first_light, generate=generate, summary=summary, xmasx=xmasx
;+
; NAME:
;	FIRST_LIGHT
; PURPOSE:
;	routine to give a quick look at SXT conditions.
;	(thought to be useful for an indolent chief observer)
;
; CATEGORY:
;	Yohkoh stuff
;
; CALLING SEQUENCE:
;	first_light [,/generate]
;
; INPUTS:
; OPTIONAL (KEYWORD) INPUT PARAMETERS:
;   generate - if set, force routines to update - default is to read from
;              showpix files if available (almost always, the same data)
;
; OUTPUTS:
; COMMON BLOCKS:
; SIDE EFFECTS:
; RESTRICTIONS:
; MODIFICATION HISTORY:
;	HSH, written July 1993
;	HSH mods 24-Aug-93
;	HSH mods 31-Aug-93, pr_evn and Christmas calculation
;	HSH mods  7-Dec-93, evt_grid
;	SLF       8-Dec-93, evt_grid refinements
;	SLF      14-Dec-93, chk_pointing call
;	slf	 10-jan-94, HH requested minor mods
;	slf       4-Mar-94, some protection (no goes, no spd)
;	gal	  7-Mar-94, quick fix for typo-err 
;	hsh	 13-Apr-94, Add KittPeak He10830 display
;       da,hsh   16-Apr-94, Scales gb Image + Ulysses overlay
;       da       30-Apr-94, Produces collage of SXT + 4 GBO images
;	BNH	  1-Jul-94, Time stamp on collage and liberalized 
;			    offpoint test
;       BNH       6-Jul-94, Changed display stuff for collage to 
;			    (hopefully) better deal with varying
;                           background in gki, gkm images
;       SLF      14-Jul-94, Made it a procedure - default is to read from
;			    data files generated during go_toban
;                           Got rid of some slow stuff which was not used
;                           Dont clobber windows (use wdef) / broke out code
;       SLF	 15-Jul-94, Allow it to run at any showpix site
;       SLF      30-Aug-94, Add users UTTIME to collage image
;       SLF       5-Oct-94, Add SUMMARY switch (read showpix version)
;       SLF       7-oct-94, window number in summary window border
;       SLF       9-oct-94, split into 2 windows for small screens
;       SLF      20-nov-94, dont return immediately with /summary logic
;       SLF      11-May-95, remove the 'Keith' message, various improves
;-
print,' '
qtemp=!quiet
!quiet=1			; suppress compilar messages
xmas = (days_2_xmas(!stime))(0)
if xmas lt 30 or keyword_set(xmasx) then begin
   print,'there are only ' + strtrim(xmas,2)+ ' days until Christmas'
   if xmas(0) lt 10 then print,'I hope you have all your xmas shopping done'
endif else tim2pass

summary=keyword_set(summary)
if summary then begin
   summ_img= $
   concat_dir(concat_dir('$DIR_GEN_SHOWPIX','new_data'),'First_Light.genx')
   if not file_exist(summ_img) then begin
      message,/info,"/SUMMARY not currently supported at your site...
   endif else begin
      restgen,file=summ_img,image,R,G,B,text=text
      goesy=200				;** may change **
      ; get screensize assume ok in x, may be small in y
      device,get_screen=xy            
      if xy(1) lt (size(image))(2) then begin
         message,/info,"Small Screen, Sumimasen, have to break into two..."
         goes=image(*,0:goesy-1)
         image=temporary(image(*,200:*))
         wdef,zzz,image=goes,/lr,title='UT TIME: ' + ut_time() + $
            string(replicate(32b,10)) + next_window(/free,/label)
         tv,goes
      endif
      wdef,zz,image=image,/uright,title='UT TIME: ' + ut_time() + $
         string(replicate(32b,10)) + next_window(/free,/label)
      tv,image
      tvlct,r,g,b
      prstr,text(0:80<(n_elements(text)-1))
   endelse
endif else begin

   if keyword_set(generate) then $
      prstr,['','Grab a cup of coffee, this will take a minute...']
   pr_evn
;  slf - 14-July-1994, showpix (genx) files are saved durint go_toban
;       or GOES data copy - if these are available, use them 
;       (see mk_newdata.pro for generation)

;  SAVE FILE #1 = $DIR_GEN_SHOWPIX/The_SUN_Today	; SXT and GBO collage
;  SAVE FILE #2 = $DIR_GEN_SHOWPIX/SXT_OBS_NAR   ; SXT w/NAR and Observing regio
;  SAVE FILE #3 = $DIR_GEN_SHOWPIX/GOES_DATA_24h ; goes 3 minute data light 

;  ------- slf - break sxt/nar/obs overlay code -> fl_sxtobsnar.pro
   fl_sxtobsnar, image, R, G, B, generate=generate
   loadct,15
   wdef,xxx,image=image,/uright
   tv,image
;  --------------------------------------------------------------

;  ------- slf - break goes plot / evt_grid overlay -> fl_goesplot.pro
   fl_goesplot, image, R, G, B, generate=generate
   wdef,yyy, image=image,/ul
   tv,image
;  --------------------------------------------------

;  read the SXT / GBO collage from a file by default
; 
   fl_suntoday, collage, R,G,B, generate=generate
   set_plot,'x'
   if n_elements(collage) ne 0 then begin
      wdef,zzz,image=collage,/uright
      tv,collage
;     add current uttime to image
      xyouts,335,120,'!6Current UT Time',/device,size=2.
      xyouts,310,80,ut_time(),/device,size=2.
   endif 
endelse

; -------------------------------------------------
isas=get_logenv('$DIR_SITE_SITENAME') eq 'ISAS'

if isas then begin
   rd_roadmap,newfiles(/sfr,last=5),rmap,ndsets
   print,' '
   partial=where(gt_percentd(rmap) lt 100, pcnt)
   fract= float(pcnt)/total(ndsets)
   print,"Fraction of FFI's in this interval with gaps was: ",fix(fract*100),$
      ' percent
   fmt_timer,rmap,t1,t2
   tabtime=rmap(total(ndsets)-1)
   prstr,['','***** Terminators *****']
   range=anytim2ints(!stime,off=[-7,7]*86400)
   times=term_times(range(0),range(1),/type,/one_page)

   lastsfd,sindex,sdata,/notv,/half
   flux = total(sfd_decomp(sdata))
   if(gt_filtb(sindex) eq 3) then flux = 2*flux
   if(gt_res(sindex) eq 2) then flux = 4*flux

   ; slf - replace 8 if statments with a where....
   levels=['Solar Minimum??','LOW','MEDIUM','HIGH','Damned High']
   cutoff=[-1,3e6,1e7,3e7,1e8,1e20]
   chk=where(flux gt cutoff,cutcnt)
   outbuf=['','Total Flux Check...','','Total thin Al flux is ', $
      strtrim(flux,2) + ' SFD units, and...','',                 $
      'Solar Activity is... ' + levels(cutcnt-1),'']
   prstr,strjustify(outbuf,/box)   
   
endif else tabtime=!stime

; ------------------- contacts, general observer info ------------
; slf, 11-may-1995 - use pr_visible instead of contacts 
print,' '
pr_visible,timegrid(jst(),day=-1),timegrid(jst(),day=+1),/now,/noprint,out=out
prstr,strjustify(out,/box)
aa = gtab_entry(tabtime)
prstr,['',' ' + aa(0:2),'']
; --------------------------------------------------------------------

!quiet=qtemp
restsys,/aplot,/init		; restore plot 
return
end
