pro fl_goesplot, image, R, G, B, generate=generate, text=text, nodist=nodist, $
    sindex=sindex, small=small, colors=colors, low=low, high=high, test=test
common fl_goesplot_blk, sfrs, sprs , prmap, frmap

generate=keyword_set(low) or keyword_set(generate) or keyword_set(colors)

if not keyword_set(test) then test=0

low=1
case n_elements(colors) of 
   0: colors=[6,120,200]   
   3: colors=colors
   else: colors=replicate(colors(0),3)
endcase

gcolor=colors(0)
ncolor=colors(1)
scolor=colors(2)

savename='GOES_PLOT_24h'
savetext=concat_dir('$DIR_SITE_DOC',savename + '.doc')
savepath=concat_dir('$DIR_GEN_SHOWPIX','new_data')
psize=[1024,256]

small=keyword_set(small) or keyword_set(test)

xmar=!x.margin
ymar=!y.margin                  ; defaults for full size

ftickp=.73
ptickp=.86
ticklen=.07

; [6,120,200]
if small then begin             ; parameters for small plot
   ftickp=.84
   ptickp=.84
   ticklen=.05
   nodist=1
   savepath='$DIR_SHOWPIX_SC'
   savename='GOES_PLOT_24h_temp'
   xmar=[4,.2]              ; fill the plot area
   ymar=[2,2]
   if test gt 1 then psize = [1024,test] else psize=[1024,200]
   print,'psize=',psize
endif

savefile=concat_dir(savepath,savename)

message,/info,"Savefile name: " + savefile

pdev=!d.name

if test gt 0 then savefile=savefile+'x'
if keyword_set(generate) or not file_exist(savefile + '.genx') then begin
   tt2=ut_time()
   tt1=fmt_tim(gt_day(tt2)-1)           ; time logic from first light

   if test gt 0 then begin
      rd_roadmap,newfiles(/spr,last=3),rmap
      fmt_timer,rmap,tt1,tt2
   endif

;  use 3 second if available            ; (more succinctly stated)
   set_plot,'Z'                 ; use Z buffer
   device,set_colors=240
   wdef,zz,/z,psize(0),psize(1)         ; first light size
;  plot the goes data
   titles=(['','GOES 9 Start: ' + tt1 + ' UT'])(small) 

   if small then xtitle=''
   nodeftitle=keyword_set(titles)

   plot_goes,tt1, tt2, gcolor=gcolor, ymargin=ymar, xmargin=[0,0], $
      low=low, high=high, title=titles, nodeft=nodeftitle, /intlab,/one_min

   if total(abs(!x.crange)) eq 0 then begin
      plot_goes,tt1, tt2, gcolor=gcolor, ymargin=ymar, xmargin=[0,0], $
      low=low, high=high, title=titles, nodeft=nodeftitle, /intlab, /three
      if total(abs(!x.crange)) eq 0 then begin
         message,/info,"Problem with previous goes plot (no data?) aborting"
         return
      endif
   endif

   fem_grid,ncolor=ncolor,scolor=scolor,/fillsaa,yrange=!y.crange

;  --------------- overlay 'events' --------------------------
   if n_elements(sfrs) eq 0 then begin          ; use common?
      sfrs=newfiles(/sfr,last=10)
      sprs=newfiles(/spr,last=10)
      if sfrs(0) ne '' then rd_roadmap,sfrs,frmap
      if sprs(0) ne '' then rd_roadmap,sprs, prmap              ;
   endif

   quietcolor=110
   flarecolor=15

   if data_chk(prmap,/struct) then begin
      evt_grid,prmap,tickpos=ptickp, ticklen=ticklen,label=(['!3PFI',''])(small), $
         color=quietcolor,labsize=1.5, labcolor=230, /align

      flaress=where(gt_dp_mode(prmap) eq 9,fss)
      if fss gt 0 then $
         evt_grid,prmap(flaress),tickpos=ptickp,ticklen=ticklen, color=flarecolor
   endif

   if data_chk(frmap,/struct) then $
      evt_grid,frmap,tickpos=ftickp,ticklen=ticklen,label=(['!3FFI',''])(small), $
         color=quietcolor,labsize=1.5, labcolor=230, /align

   if data_chk(sindex,/struct) then $
      evt_grid,sindex,line=3,thick=2,label='!3SFD',labpos=.6,color=220,labsize=1.5
;  -----------------------------------------------------------
   image=tvrd()
;  Running at ISAS? then save the 'showpix' version via mk_pix

   tvlct,rr,gg,bb,/get          ; save current color table
   loadct,15
   tvlct,r,g,b,/get
   if get_logenv('$DIR_SITE_SITENAME') eq 'ISAS' then begin
      if not small then begin 
         mk_pix, image, r, g, b, text=savetext, $
             filename=savename, subdir='new_data',/replace,/nodist
         fl_goesplot, /generate, /small, sindex=sindex, /nodist
      endif else begin
         savegen, file=savefile, image,r,g,b,text='Collage Version'
         fl_summary,/distrib
      endelse
   endif
   tvlct,rr,gg,bb           ; restore color table

endif else restgen,file=savefile, image, R, G, B, text=text

set_plot,pdev
return
end