pro fl_sxtobsnar, image, R, G, B, generate=generate, nodist=nodist, small=small
;
;+
;   Name: fl_sxtobsnar
;
;   Purpose: return the SXT / NAR / Observing region overlay, 'first_light' style
;
;   History:
;      14-Jul-1994 (SLF) - broke code out from first_light, added z-buffer
;                          support for Back Ground, generate a mkpix file
;                          default read from that file (faster) linked to
;                          mk_sfd phase of go_toban etc...
;       7-Sep-1994 (SLF) - use device,set_colors to make Z-buff look like X
;       5-oct-1994 (SLF) - pick half res, not last (if avail in last file)
;			   use /short title in lastsfd keyword
;       9-oct-1994 (SLF) - dont AR label the small (collage) version
;      31-oct-1994 (SLF) - label small with time
;       8-Feb-1995 (SLF) - change file name to: LAST_SXT_NOAA_AR,
;			   include image info in text section of genx
;      13-feb-1995 (SLF) - add REBIN=512 to lastsfd call (fill FOV)
;      29-aug-1994 (SLF) - tone down stoney-grid on small version
;       1-feb-1996 (SLF) - add MAG parameter to plot_nar call
;-
pdev=!d.name
savename='LAST_SXT_NOAA_AR'
savetext=concat_dir('$DIR_SITE_DOC',savename + '.doc')
savepath=concat_dir('$DIR_GEN_SHOWPIX','new_data')

if keyword_set(small) then begin
   savename='LAST_SXT_NOAA_AR_temp'
   savepath='$DIR_SHOWPIX_SC'
endif

savefile=concat_dir(savepath,savename)

big=1-keyword_set(small)

if keyword_set(generate) or not file_exist(savefile + '.genx') then begin
;  have to generate a new one
   set_plot,'z'
   device,set_colors=240
;
;  recent pfis for overlay
   rd_roadmap,newfiles(/spr,last=3),prmap
   uss=sxt_uniqfov(prmap,uniqss=uniqss)

   if big then begin
      lastsfd,sindex,sdata,/zbuffer,/short,/half,mag=mag
      plot_nar,sindex,/overlay,pfi_index=prmap(uniqss),/zbuffer, $
         pfi_color=!p.color, color=abs(!p.color-45), pfi_lstyle=2,mag=mag(0)
;      helio_foot,sindex
   endif else begin
      lastsfd,sindex,sdata,/zbuffer,rebin=256,mag=mag,/notitle      
      plot_nar,sindex,/overlay,pfi_index=prmap(uniqss),/zbuffer,mag=mag(0), $
         pfi_color=!p.color, color=abs(!p.color-100), pfi_lstyle=2, /nolabel
      xyouts,5,5,'SXT ' + fmt_tim(sindex),/device,charsize=1.1
   endelse

   image=tvrd()
;  now make the showpix file via mk_pix call
   tvlct,rr,gg,bb,/get                  ; save current color table
   loadct,15				; sxt standard
   tvlct,r,g,b,/get
   if get_logenv('DIR_SITE_SITENAME') eq 'ISAS' then begin
      if big then begin 
         mk_pix, suntoday, r, g, b, $
         text=['SXT COMPOSITE IMAGE and NOAA Active Region Overlay','', $
            sxt_img_summary(sindex), '',rd_tfile(savetext)], 		$
         filename=savename, subdir='new_data',/replace, nodist=nodist
         fl_sxtobsnar,/small,/generate
      endif else savegen,file=savefile, image,r,g,b,text='Collage Version'

   endif
   tvlct,rr,gg,bb                       ; restore color table

endif else restgen,file=savefile, image, r, g, b, text=text

set_plot,pdev
return
end


