pro fl_summary, image, r, g, b, distrib=distrib, display=display, ggen=ggen
;
;+
;   Name: fl_summary
;
;   Purpose: combine fl_xxx images into summary image
;
;   History:
;      3-sep-94 (SLF) test one possible summary format
;      6-sep-94 (SLF) call mk_pix to generate 'First_Light' summary image
;      7-sep-94 (SLF) call fl_mktext
;     20-sep-94 (SLF) rearrange, add images
;      5-oct-94 (SLF) new format (small goes, add SXT OR)
;      9-oct-94 (SLF) use relative screen postions, shift some stuff
;                     (make it easier to re-format) add white light
;     12-oct-94 (SLF) add call to fl_nargev
;     18-oct-94 (SLF) restored previous change (heliographic via gt_center)
;     31-oct-94 (SLF) dont label small sxt
;      9-Feb-95 (SLF) scale obs region to max=256 
;     13-feb-95 (SLF) use REBIN=512 in lastsfd call
;      6-apr-95 (SLF) embed congridded OR in 256x256 so tv position will work
;     28-apr-95 (SLF) color table (3 w/reverse SXT)
;     24-sep-95 (SLF) add MK3/SXT composite
;     25-sep-95 (SLF) CaIIK
;     13-oct-95 (SLF) minor cleanup (lower SXT OBs text, ...)
;      7-feb-96 (SLF) Add EIT images
;     18-feb-96 (SLF) Tweak EIT scaling
;     22-feb-96 (SLF) EIT ss protect 
;     12-mar-96 (SLF) invert border line colors (EIT)
;      8-apr-96 (SLF) censored the EIT 171 image due to outside pressure
;     17-apr-96 (SLF) use MEES POI CaKline
;     12-jul-96 (SLF) add some urls.
;-
nodist=1-keyword_set(distrib)
pdev=!d.name

charsize=1.1
; prepare EIT images
eit_wave=['171','195','304']
swaves=strtrim(eit_wave,2)
efiles=file_list('$DIR_GEN_SHOWPIX/eit','EIT_*' + swaves + '*256*')
set_plot,'z'
wdef,xxx,/zbuff,256,256

for i=0, n_elements(eit_wave)-1 do begin
   erase
   restgen,file=efiles(i),eitimg, text=text
   good=where(eitimg gt 0,ccnt)
   if ccnt eq 0 then good=where(eitimg eq 0)
   eitimg=bytscl(eitimg,min=min(eitimg(good)), max=max(eitimg(good)) )
   tv,eitimg
   xyouts,5,5,text(0),charsize=charsize*.7,/device
   exe=execute("eit" + swaves(i) + "=tvrd()")
endfor

; build the CaIIK
caiik=concat_dir('$DIR_SHOWPIX_SC','Last_MSOK.genx')
restgen,file=caiik,caiik,text=text
if n_elements(caiik)  le  1 then caiik=bytarr(256,256)
tv,rebin(caiik,256,256)
xyouts,5,5,'MSO (POI) Ca KLine   ' + strmid(text(1),0,16), $
   charsize=charsize*.7,/device
caiik=tvrd()

; ------------ read in saved images (Created by associated new-data routines)
fl_suntoday,sunt			; read original DA mosaic
fl_goesplot,goes,/small			; read 'small' goes saved file
goesw=(size(goes))(2)			; get the current size
set_plot,'z'				; all Z buffer
loadct,3				; updated
tvlct,r,g,b,/get
lastsfd,/short,/half,/nar,/nogrid,/zbuffer,rebin=512	;
sxt=tvrd()
;---------- update NOAA AR and GOES event text & window ---------
fl_mktext,otext=fltext			; update event/nar text file 
fl_nargev,nargev,/generate
;---------------------------------------------
; slf - do mk3/sxt overlay
lastsfd,sind,sdat,/notv
sxtmk3=sxt_mk3(sind,sdat,diameter=256)

; -----------------------------------------------------------------------
; define collage area
wdef,zz,/zbuff,1024, 768 + goesw	; use z-buffer
tvlct,r,g,b			        ; load colors
;
tv,sxt,0		     	; upper-left, sxt/obs/noaa active regions
tv,goes				; lower-left, goes 3 second light curve

; --------------------- move this to fl_sxtobsnar -----------------
fl_sxtobsnar,/small,dataf
dataf=dataf(0:255,0:255)
; get the most recent, background subtracted and assembled OR data
lastsfd,indexp,datap,/notv,/spd,15
; find the 'best' (100%, AlMg)
best=where(gt_percentd(indexp) eq max(gt_percentd(indexp),bcnt))
bestf=where(gt_filtb(indexp(best)) eq 3,almgcnt)
if almgcnt eq 0 then ss=best else ss=best(bestf)

; all else equal, take the longest exposure
sss=where(gt_dpe(indexp(ss)) eq max(gt_dpe(indexp(ss))),cnt)
ss=ss(sss(cnt-1))

info=get_info(indexp(ss),/non)

infos=str2arr(strcompress(info),' ')
sxtptext='SXT Observing Region ' + infos(3)
; overlay Heliographic coordinates
helio= gt_center(indexp(ss),/helio,/string,/cmd)
helios="Helio: " + strmid(helio,0,3) + ' ' + strmid(helio,3,3)
; ----------------------------------------
; -------------- sxt full frame (Small Version) -------------
tvscl,dataf,8					;SXT FFI (Small)
obsreg=datap(*,*,ss)
sobs=(size(obsreg))(1:2)			; x and y size
zoomfact=256./max(sobs)
; imbed in 256x256 (so tv by positioning will work)
zobs=congrid(obsreg,(sobs(0)*zoomfact)<256,(sobs(1)*zoomfact)<256)
ozobs=bytarr(256,256)
embed=((256 - size(zobs))/2)(1:2)
ozobs(embed(0),embed(1))=temporary(zobs)
tvscl,ozobs,9
xyouts, 276, 5+goesw, sxtptext, /device
xyouts, 276, 25+goesw, helios, /device, charsize=1.2
; ---------------------------------------------------------------
; now display the ground based images 
tv,sunt(0:255,0:255),6				; KP He  - cut&paste sun_today
tv,sunt(594:*,594:*),7				; KP Mag - ditto

tv,eit195,2				        ; EIT 195
tv,eit304,3					; EIT 304

tv,caiik,10					; MSO CaIIK
tv,sxtmk3,11					; SXT/MK3 overlay

; ------------------------------- draw borders ------------------
n0=0 & n1=256 & n2=512 & n3=768 & n4=1024

plots,[n2,n2], [n0,n3]+goesw   ,/device
plots,[n3,n3], [n0,n3]+goesw   ,/device
plots,[n0,n4], [n1,n1]+goesw   ,/device
plots,[n2,n4], [n2,n2]+goesw   ,/device
plots,[n1,n1], [goesw,n1+goesw],/device
plots,[n0,n4], [goesw,goesw]   ,/device

plots,[n2,n2], [n1,n3]+goesw   ,/device	; eit
plots,[n3,n3], [n0,n3]+goesw   ,/device	; eit
plots,[n2,n4], [n1,n1]+goesw   ,/device	; eit
; --------------------------------------------------------------
first_over				; reverse SXT
; read back from z-buffer
image=tvrd()

; If requested, save image to SHOWPIX area and issue a distribution request
if keyword_set(distrib) then begin
   savename='First_Light'
   savepath=concat_dir('$DIR_GEN_SHOWPIX','new_data')
   savefile=concat_dir(savepath,savename)
   fltext= $
      [strjustify(["Recent SXT full disk and observing region movies ", $
          "are now available at: ",                                     $
          "   http://www.space.lockheed.com/SXT/movies/last_movies.html","",   $     
            "Information regarding SOHO/EIT may be found at: ",  $
            "http://umbra.nascom.nasa.gov/eit/"]),"",fltext]
   mk_pix, image, r, g, b, text=fltext, file=savename, subdir='new_data', $
      /replace
endif

if keyword_set(display) then begin
   set_plot,'x'
   wdef,image=image,/ur
   tv,image
   tvlct,r,g,b
endif 

if !d.name ne pdev then begin
   message,/info,"Restoring plot device to: " + pdev
   set_plot,pdev					; restore plot device
endif

return
end
