;***************************************************************
;>>	various routines needed - here so do not need SSW branch 
;***************************************************************

function dev2data,device,scale
;
;+
;   Name: dev2data
;
;   Purpose: return data coordiates from input device coord and !x.s/!y.s
;
;   Input Parameters:
;	device = device coordinates
;       scale = 4 element floating point scale (!x.s, !y.s)
;
;   History:
;	Origin unknown
;	13-May-02  rdb  Fixed error in header which meant never could work...
;-
;

return,[(float(device(0))/float(!d.x_size) - scale(0))/scale(1), $
	(float(device(1))/float(!d.y_size) - scale(2))/scale(3)]
end


pro eit_colors,table,r,g,b
;
;+
;   Name: eit_colors
;
;   Purpose: load EIT color tables
;
;   Input Parameters:
;      table - EIT table number or associated wavelength
;
;   Output Parameters:
;      r,g,b - optional return RGB
;
;   Calling Examples:
;      eit_colors,0             ; load the first EIT table (relative)
;      eit_colors,41            ; load the first EIT table (absolute)
;      eit_colors,284,r,g,b     ; map wavelenght-> table, return RGB
;
;   Method:
;      call ssw_colors          ; contains links to SSW color table files
;
;   History:
;      18-Feb-1996 (S.L.Freeland)
;
;-

waves=[171,195,284,304]
case 1 of 
   n_elements(table) eq 0: itable=0
   is_member(table(0),waves): itable=(where(table(0) eq waves))(0)+1
   else:itable=table(0)         ; pass table through          (absolute)
endcase

ssw_colors,/eit,itable,r,g,b

return
end


;***************************************************************
;---------------------------------------------------------------
pro plot_sswfov_validfov, info

wset, info.widfov
plot_sswfov_bgimage,info

sidx = *info.sxtp
pok = plot_fovbox(sidx,color=180)
if pok then        xyouts,-1550,-1325,'SXT',charsiz=1.2,color=180

tcat = *info.tcat
pok = plot_fovbox(tcat,color=220)
if pok then        xyouts,-1550,-1200,'TRACE',charsiz=1.2,color=220

end


;***************************************************************
;>>	various plot and zoom routines called as event handlers
;***************************************************************

;---------------------------------------------------------------
pro sswfov_plot_image,event
widget_control, event.top, get_uvalue = info, /no_copy

  message = ['Replot background Synoptic Image', '', $
	'Locations of flares (with known locations) plotted in turquoise', $
        '(locations rotated to time of image)','','** CHECK image rotn. by P angle']
  widget_control,info.textid,set_value=message

wset, info.widfov

   plot_sswfov_bgimage,info,/nar

savesys,/aplot           ;??
*info.widfov_sys = !ys_idlsys_temp       ;??
widget_control, event.top, set_uvalue = info, /no_copy
end


;---------------------------------------------------------------
pro sswfov_fovplot,event

common sswfov_info,sxt_chan

widget_control, event.top, get_uvalue = info, /no_copy
wset, info.widfov

plot_sswfov_bgimage,info

filter=''
sfilter=''
sxt_filter='All available SXT channels'
trace_filter='All available TRACE channels'

loadct,3

widget_control, event.id, get_value = buttonvalue
case buttonvalue of
  'All':        begin
        doing='PLOT all FOVs'

        tstruct = *info.tcat
        sxtp = *info.sxtp
;        ss_tri = indgen(n_elements(tstruct))
     end

  'Selected':   begin
        doing='PLOT previously selected FOVs, etc.'
        print,info.sel_trange
        filter=''
	point_filter='All Pointings' 
 ;              set pointing as first test - common to all instruments
        if total(info.fovlim) ne 0 then begin
           lims = strtrim(string(info.fovlim,format='(i12)'),2)
           pointx='xcen='+lims(0)+'~'+lims(2)
           pointy='ycen='+lims(1)+'~'+lims(3)
           filter=[filter,pointx,pointy]
	   point_filter = string(pointx,pointy,format='(a,t25,a)')
        endif
        sfilter=filter                         ;filter same for SXT as TRACE

;               TRACE
        tstruct = *info.tcat
        help,tstruct	;& help,/st,tstruct
	fmt_timer,tstruct

;               select by time
if datatype(tstruct) eq 'STC' then begin
        sstim = tim2dset(tstruct,info.sel_trange,offset=offset)
        tx0=addtime(info.sel_trange(0),diff=tstruct(0))
        print,'Struct t0 to range t0=',tx0
        tx1=addtime(tstruct(n_elements(tstruct)-1),diff=info.sel_trange(1))
        print,'Range t1 to struct t1=',tx1
        print,sstim
        if (max(sstim) eq 0 and tx0 lt 0) $
           or (min(sstim) eq n_elements(tstruct)-2 and tx1 lt 0) $
           then begin
              box_message,'outside TSTRUCT'
              tstruct=1b
              filter = 'No TRACE records in selected timerange'
           endif else tstruct = tstruct(sstim(0):sstim(1))
endif

if datatype(tstruct) eq 'STC' then begin
;               select by channel, pointing, etc.
        if max(info.timchan_sel gt 0) then begin
           chans = where((info.timchan_sel gt 0 and info.timchan_inst eq 'tri'),nch)
           if nch ge 1 then begin
              chans = info.timchan_txt(chans)
              chan='wave_len='+arr2str(chans,delim=', ')
              filter=[filter,chan]
	      trace_filter = chan
           endif
        endif
        help,filter & print,filter
        if n_elements(filter) gt 1 then begin
           filter = filter(1:*)
           ss_tri = struct_where(tstruct,test=filter)
        endif else ss_tri = indgen(n_elements(tstruct))
        help,ss_tri
        if ss_tri(0) ge 0 then begin
           tstruct = tstruct(ss_tri)
	   trace_nimg = 'No. of TRACE images:'+string(n_elements(ss_tri))
        endif else begin
           tstruct=1b
           trace_nimg = 'No TRACE records selected'
        endelse
           filter = [filter,trace_nimg]
	   trace_filter = [trace_filter,trace_nimg]
endif
help,tstruct

;               SXT??
      sxtp = *info.sxtp
;               select by time
      if datatype(sxtp) eq 'STC' then begin
;;         sstim = tim2dset(sxtp,info.sel_trange,offset=offset)
;;         sxtp = sxtp(sstim(0):sstim(1))
;;      endif
;               select by time
        sstim = tim2dset(sxtp,info.sel_trange,offset=offset)
        tx0=addtime(info.sel_trange(0),diff=sxtp(0))
;        print,'Struct t0 to range t0=',tx0
        tx1=addtime(sxtp(n_elements(sxtp)-1),diff=info.sel_trange(1))
;        print,'Range t1 to struct t1=',tx1
;        print,sstim
        if (max(sstim) eq 0 and tx0 lt 0) $
           or (min(sstim) eq n_elements(sxtp)-2 and tx1 lt 0) $
           then begin
              box_message,'outside SXTP'
              sxtp=1b
              sfilter = 'No SXT records in selected timerange'
           endif else sxtp = sxtp(sstim(0):sstim(1))
      endif

if datatype(sxtp) eq 'STC' then begin
;               select by Filter No., pointing, etc.
;goto, skip
        if max(info.timchan_sel gt 0) then begin
           chans = where((info.timchan_sel gt 0 and info.timchan_inst eq 'sxt'),nch)        ;!!!!!!
           if nch ge 1 then begin
              nsxt_chan = n_elements(sxt_chan)
              filtb_no = bytarr(nsxt_chan)
              for jf = 0,nsxt_chan-1 do $
                 filtb_no(jf) = strpos(sxt_chan(jf),info.timchan_txt(chans))
              filtb_no = where(filtb_no eq 0)+1
              chan=['filtb=['+arr2str(filtb_no,delim=',',/compress,/trim_str)+']','filta=1']
              sfilter=[sfilter,chan]
	      sxt_filter=string(chan,format='(a,5h,    ,a)')
           endif
        endif
skip:
        print,sfilter
        if n_elements(sfilter) gt 1 then begin
           sfilter = sfilter(1:*)
           ss_sxt = struct_where(sxtp,test=sfilter)
        endif else ss_sxt = indgen(n_elements(sxtp))
        help,ss_sxt
        if ss_sxt(0) ge 0 then begin
           sxtp = sxtp(ss_sxt)
           sxt_nimg = 'No. of SXT PFI images:'+string(n_elements(ss_sxt))
        endif else begin
           sxtp=1b
           sxt_nimg = 'No SXT records selected'
        endelse
	sfilter = [sfilter,sxt_nimg]
	sxt_filter = [sxt_filter,sxt_nimg]
endif
help,sxtp


     end
  else: doing='WHATS UP?'
endcase

;   better formatted messages
otfilter = filter
if n_elements(otfilter) gt 1 then otfilter=[point_filter,trace_filter]
osfilter = sfilter
if n_elements(otfilter) gt 1 then osfilter=[point_filter,sxt_filter]

print,doing
message = [doing,'',info.sel_trange(0)+' --> '+info.sel_trange(1), $
        '','TRACE:',otfilter]
if datatype(sxtp) eq 'STC' then message = [message,'','SXT:',osfilter]
widget_control,info.textid,set_value=message

;       now plot any valid FOVs

pok = plot_fovbox(sxtp,color=180)
;if pok then         xyouts,-1200,1100,'SXT',charsiz=1.5,color=180
if pok then        xyouts,-1550,-1325,'SXT',charsiz=1.2,color=180

pok = plot_fovbox(tstruct,color=220)
;if pok then        xyouts,-1200,1225,'TRACE',charsiz=1.5,color=220
if pok then        xyouts,-1550,-1200,'TRACE',charsiz=1.2,color=220

savesys,/aplot
*info.widfov_sys = !ys_idlsys_temp
widget_control, event.top, set_uvalue = info, /no_copy
end
     

;---------------------------------------------------------------
pro sswfov_timplot,event
widget_control, event.top, get_uvalue = info, /no_copy

  times = string(info.trange, format='(a,4h -> ,a)')
  message = ['Plot timeline', '', 'Overall Range:  '+times]
  widget_control,info.textid,set_value=message

  plot_sswfov_timeline,info

widget_control, event.top, set_uvalue = info, /no_copy
end


;---------------------------------------------------------------
pro sswfov_timplot_ROI,event
widget_control, event.top, get_uvalue = info, /no_copy

  times = string(info.trange, format='(a,4h -> ,a)')
  message = ['Plot timeline with times selected by ROI', $
	'Times of images selected in TOI are coloured', '', $
	'Overall Range:  '+times]
  widget_control,info.textid,set_value=message

  plot_sswfov_timeline,info, /roi_sel

widget_control, event.top, set_uvalue = info, /no_copy
end


;---------------------------------------------------------------
pro sswfov_timzoom,event
widget_control, event.top, get_uvalue = info, /no_copy

  plot_sswfov_timeline,info,/zoom

widget_control, event.top, set_uvalue = info, /no_copy
end


;--------------------------------------------------------------------------
pro sswfov_ROIzoom,event

widget_control, event.top, get_uvalue = info, /no_copy
wset,info.widfov

help,info.bkgimg_type,info.bkgimg_used

newimg = 0
if info.bkgimg_type ne info.bkgimg_used then newimg=1
if datatype(*info.map) ne 'STC' then newimg=1
if newimg then begin
  print,'* Reading new image:',info.bkgimg_type
  map = get_bgimage(info.trange(0), context=info.bkgimg_type, remote=info.network)	;do_log=do_log,
  *info.map = map 		;& info.do_log = do_log
  info.bkgimg_used = info.bkgimg_type
endif else map = *info.map

; If ROI not defined, zooms about 0,0
xy = info.fovlim
xc = xy(0) + (xy(2)-xy(0))/2.
yc = xy(1) + (xy(3)-xy(1))/2.
;print,xy
zoom_mess = string('Zoom centered on:',xc,yc, format='(a,i7,1h,,i7)')
print,zoom_mess
;;print,'Zoom centered on:',xc,yc

  title=map.id + '!C' + map.time
  title = str_replace(title,'Rocket Science','SOHO')

  loadct,0 & do_log=0
  if strpos(title,'SOHO EIT') ge 0 then begin
    eit_wave = fix(strmid(title, strpos(title,'SOHO EIT ')+9,3))
    help, eit_wave
    eit_colors, eit_wave
    do_log=1
  endif

  message = ['Zoom on selected Region of Interest', '', zoom_mess]
  widget_control,info.textid,set_value=message

plot_map,*info.map,center=[xc,yc],fov=[8,8],/square,grid=10, $
	log=do_log, title=title

annotate_bkgimg,info

savesys,/aplot
*info.widfov_sys = !ys_idlsys_temp
widget_control, event.top, set_uvalue = info, /no_copy

end


;***************************************************************
;>>	various selection Routines called as event handlers
;***************************************************************

;---------------------------------------------------------------
pro sswfov_trange_sel,event
widget_control, event.top, get_uvalue = info, /no_copy
wset, info.wid
!ys_idlsys_temp=*info.wid_sys
restsys,/aplot

      tss0 = fmt_tim(info.trange(0)) & tss1 = fmt_tim(info.trange(1))
      tss = [tss0,tss1]

;widget_control, event.id, get_value = buttonvalue
;case buttonvalue of

;'Timerange':  begin
      message = ['SELECT Time range    [default is plotted time range]','', $
	          'On the time plot:', $
                  '  use LEFT button to mark Start time', $
                  '  use RIGHT button to mark End time', $
                  '  use MIDDLE button to EXIT    (<CTRL>LEFT on 2 button mouse)','']
      widget_control,info.textid,set_value=message
      mess = message
      print,'* Select Timerange'

      cdone=0
      xs = !x.crange(0) & xe = !x.crange(1)

      while not cdone do begin
         utcursor,ctime,y0,x0,err=button,/data,/quiet
         if info.debug then begin
            print,fmt_tim(ctime),x0,y0,button
            mess = [mess,fmt_tim(ctime)+'  '+string(button)]
   ;         widget_control,info.textid,set_value=mess
         endif
         case 1 of
         button eq 2: cdone=1           ;middle button
         button eq 1: begin             ;left button
               if x0 ge !x.crange(0) and x0 lt xe then begin
                  xs = x0
                  tss0 = fmt_tim(ctime)
               endif else print,'** out of range **'
            end
         button eq 4: begin             ;right button
               if x0 le !x.crange(1) and x0 gt xs then begin
                  xe = x0
                  tss1 = fmt_tim(ctime)
               endif else print,'** out of range **'
            end
         else: print,fmt_tim(ctime),x0,y0,button
         endcase
         tss = [tss0,tss1]
         strang = string('* Start, stop times:',tss,format='(a,2x,a,4x,a)')
         print,strang
         mess = [message,strang]
         widget_control,info.textid,set_value=mess
      endwhile

      strang=string('* Selected time range:',tss,format='(a,2x,a,4x,a)')
      print,''
      print,strang
      mess = [mess,'',strang]
      widget_control,info.textid,set_value=mess

      outplot,[tss(0),tss(0)],!y.crange,linestyle=2
      outplot,[tss(1),tss(1)],!y.crange,linestyle=2
      info.sel_trange = tss

;      end

widget_control, event.top, set_uvalue = info, /no_copy
end


;---------------------------------------------------------------
pro sswfov_channel_sel,event
widget_control, event.top, get_uvalue = info, /no_copy
wset, info.wid
!ys_idlsys_temp=*info.wid_sys
restsys,/aplot

;'Channel':    begin
      message = ['SELECT Channel','','On the time plot:', $
                  '  use LEFT button to select a Channel', $
                  '  use RIGHT button to deselect a Channel', $
                  '  use MIDDLE button to EXIT    (<CTRL>LEFT on 2 button mouse)','']
      widget_control,info.textid,set_value=message
      strang='* Selected Channels: '
      wq = where(info.timchan_sel gt 0)
      if wq(0) ge 0 then strang = strang+arr2str(info.timchan_txt(wq),delim=', ')
      print,strang
      mess = [message,strang]
      widget_control,info.textid,set_value=mess

      mess = message
      print,'* Select channel'

      !p.region=[0,0.4,1.,1.0] & !y.crange=[0,14] & !y.type=0
      cdone=0
      while not cdone do begin
;         utcursor,ctime,y0,x0,err=button,/data,/quiet
         cursor,x0,y0,/data,/down
         button = !err
         if info.debug then begin
            print,fmt_tim(ctime),x0,y0,button
            mess = [mess,fmt_tim(ctime)+'  '+string(button)]
   ;         widget_control,info.textid,set_value=mess
         endif
         case 1 of
         button eq 2: cdone=1           ;middle button
         button eq 1: begin             ;left button, select channel
               chan = fix(y0+0.5)
               if info.timchan_txt(chan) ne '' then info.timchan_sel(chan)=1
            end
         button eq 4: begin             ;right button, deselect channel
               chan = fix(y0+0.5)
               if info.timchan_sel(chan) eq 1  then info.timchan_sel(chan)=0
            end
        else: print,x0,y0,button
         endcase
;          strang = string('* Channel:',chan,format='(a,i5)')
	 strang = '* Channels: '
         wq = where(info.timchan_sel gt 0)
         if wq(0) ge 0 then strang = strang+arr2str(info.timchan_txt(wq),delim=', ')
         print,strang
         mess = [message,strang]
         widget_control,info.textid,set_value=mess
      endwhile

      strang='* Selected Channels: '
      if wq(0) ge 0 then strang = strang+arr2str(info.timchan_txt(wq),delim=', ')
      print,''
      print,strang
      mess = [mess,'',strang]
      widget_control,info.textid,set_value=mess

;      end

;  else:
;endcase

widget_control, event.top, set_uvalue = info, /no_copy
end


;---------------------------------------------------------------
pro sswfov_ROI_sel,event
widget_control, event.top, get_uvalue = info, /no_copy
wset, info.widfov
!ys_idlsys_temp=*info.widfov_sys
restsys,/aplot

message = ['SELECT Region of Interest (ROI)','','On Image:', $
            '  use LEFT button to move centre of ROI,', $
            '  use MIDDLE button to change size of ROI    (<CTRL>LEFT on 2 button mouse),', $
            '  use RIGHT button to EXIT','']
widget_control,info.textid,set_value=message

linecolor,1,'turquoise'
box_cursor2 ,x0,y0,nx,ny	;, thick=2	;, color=1
print,x0,y0,nx,ny               ;DATA coordinates

x1 = x0+nx
y1 = y0+ny
zz0=dev2data([x0,y0],[!x.s,!y.s])
zz1=dev2data([x1,y1],[!x.s,!y.s])
zz = [min([zz0(0),zz1(0)]),min([zz0(1),zz1(1)]),max([zz0(0),zz1(0)]),max([zz0(1),zz1(1)])]
zz = fix(zz+0.5)        ;round-off
print,'X limits:',zz([0,2])
print,'Y limits:',zz([1,3])
info.fovlim = zz

;	selected plot out - in data coords.
oplot,[zz(0),zz(2),zz(2),zz(0),zz(0)],[zz(1),zz(1),zz(3),zz(3),zz(1)],linestyle=2

mess = [message,'Selected X-limits: '+string(zz([0,2]),format='(2i8)'), $
                'Selected Y-limits: '+string(zz([1,3]),format='(2i8)')]
widget_control,info.textid,set_value=mess

widget_control, event.top, set_uvalue = info, /no_copy
end


;--------------------------------------------------------------------------
pro sswfov_BkgImg_sel,event

widget_control, event.top, get_uvalue = info, /no_copy

cdfiles = find_bgimage(info.trange(0),'*',remote=info.network)
help,cdfiles

if cdfiles(0) ne '' then begin

  break_file,cdfiles,aa,bb,cc,dd
  ftypes = all_vals(strmid(cc,0,13))
  help, ftypes		; & print,ftypes,format='(x,a)'

  qq = wmenu_sel(ftypes+'   ',/one)

  if qq(0) gt -1 then begin
    sel_ftype = ftypes(qq(0))
    help, sel_ftype
    info.bkgimg_type = sel_ftype
  endif else message,'** No image file type selected',/info

endif else message,'** No files available -> No selection possible',/info

widget_control, event.top, set_uvalue = info, /no_copy

end


;--------------------------------------------------------------------------
pro sswfov_reset,event
widget_control, event.top, get_uvalue = info, /no_copy

widget_control, event.id,  get_value = buttonvalue
print,'* Resetting: ',buttonvalue

case buttonvalue of
'Time-range':  info.sel_trange = info.trange

'Channel':     info.timchan_sel(*) = 0

'ROI limits':  info.fovlim(*) = 0

'All':         begin
                 info.sel_trange = info.trange
                 info.timchan_sel(*) = 0
                 info.fovlim(*) = 0
               end
else: print,"*** WHAT'S UP DOC ***"
endcase

widget_control, event.top, set_uvalue = info, /no_copy
end


;***************************************************************
;>>	clean up & quit, event handler 
;***************************************************************

;---------------------------------------------------------------
pro sswfov_cleanup,event
widget_control, event, get_uvalue = info, /no_copy

if N_elements(info) ne 0 then begin
;     do all cleanup here rather than in QUIT
   ptr_free, info.map, info.processed
   ptr_free, info.wid_sys, info.widfov_sys
   ptr_free, info.sxtf, info.sxtp, info.tcat, info.cdscat
endif

end


;---------------------------------------------------------------
pro sswfov_quit,event
  widget_control, event.top, /destroy

end


;---------------------------------------------------------------
pro sswfov_event,event
;help,/st,event
widget_control, event.id, draw_button_events=0,draw_motion_events=0
end


;--------------------------------------------------------------------------
pro sswfov_debug,event
widget_control, event.top, get_uvalue = info, /no_copy

;tcat = *info.tcat
sxtp = *info.sxtp

xx='xcen='+strcompress(arr2str(info.fovlim([0,2]),delim='~'),/rem)
yy='ycen='+strcompress(arr2str(info.fovlim([1,3]),delim='~'),/rem)
test=[xx,yy]
print,test
ss = struct_where(sxtp,test=test)
help,sxtp,ss

ans=''
read,'* Pause: ',ans

widget_control, event.top, set_uvalue = info, /no_copy
end


;***************************************************************
;>>	initial setup routine 
;***************************************************************

;---------------------------------------------------------------
function sswfov_init, info, debug=debug, local=local

tlb = widget_base(column=2, mbar = menuid, xsiz=870, $
		title = 'Solar Catalogues, Timelines and FOVs')

;       define menu bar items
fileid = widget_button(menuid, value = 'Control')
   Quitid = widget_button(fileid, value = 'Quit', event_pro = 'sswfov_quit')
;
selid = widget_button(menuid, value = 'Select',/menu)
   cursID = widget_button(selid, value = 'Select Time-range', event_pro = 'sswfov_trange_sel')
   cursID = widget_button(selid, value = 'Select Channel', event_pro = 'sswfov_channel_sel')
   cursID = widget_button(selid, value = 'Select Region of Interest', event_pro = 'sswfov_ROI_sel')
   cursID = widget_button(selid, value = 'Set Context Image Type', event_pro = 'sswfov_BkgImg_sel', /separator)
   ResID = widget_button(selid, value = 'Reset Filters', event_pro = 'sswfov_Reset', /separator,/menu)
      ResetID = widget_button(resid, value = 'Time-range')
      ResetID = widget_button(resid, value = 'Channel')
      ResetID = widget_button(resid, value = 'ROI limits')
      ResetID = widget_button(resid, value = 'All Filters')
;
pointID = widget_button(menuid, value = ' Plot ')
   fovID = widget_button(pointid, value = 'Show Pointings', event_pro = 'sswfov_fovplot', /menu)
      fovssID = widget_button(fovid, value = 'All')
      fovssID = widget_button(fovid, value = 'Selected')
   replotID = widget_button(pointid, value = 'Show Timeline w. ROI', event_pro = 'sswfov_timplot_RoI')
   replotID = widget_button(pointid, value = 'Replot Synop Image', event_pro = 'sswfov_plot_image',/separator)
   replotID = widget_button(pointid, value = 'Replot Timeline', event_pro = 'sswfov_timplot')
   replotID = widget_button(pointid, value = 'Zoom on Time window', event_pro = 'sswfov_timzoom',/separator)
   replotID = widget_button(pointid, value = 'Zoom on ROI center', event_pro = 'sswfov_ROIzoom')
;
;	if started with debug switch set, add extra item on menu bar that allows you to examine things
if keyword_set(debug) then begin
   dbmID = widget_button(menuid, value = ' Debug')
      dbID = widget_button(dbmid, value = 'Pause', event_pro = 'sswfov_debug')
endif

;       define the elements on the widget page

;       on LHS, single window
drawid = widget_draw(tlb, xsize = 400, ysize = 600)      ; time window on LHS

;       on RHS, want plot window over message box
tlb2 = widget_base(tlb, row=2)
drawfov = widget_draw(tlb2, xsize = 450, ysize = 400)    ; image on top
textid = widget_text(tlb2, xsize=70, ysize=14, /scroll)  ; text on bottom

;# drawfov = widget_draw(tlb2, xsize = 495, ysize = 450)

;       realize the widget, get plot window info
widget_control, tlb, /realize
widget_control, drawid, get_value = wid
widget_control, drawfov, get_value = widfov

;	check if we have network connection
if keyword_set(local) then not_local=0 else $
    not_local = have_network('http://www.egso.org')

;	store all info in a structure for passing
imgcolors = !d.table_size - 19
loadct,3,/silent

info = {drawid:drawid, wid:wid, wid_sys:ptr_new(!ys_idlsys_temp), $
          timchan_txt:strarr(20), timchan_sel:intarr(20), timchan_inst:strarr(20), $
          sxtf:ptr_new(!x), sxtp:ptr_new(!x), tcat:ptr_new(!x), cdscat:ptr_new(!x), $
          sec_records:ptr_new(!x), sec_query:'', $
;	qlk data??
          widfov:widfov, widfov_sys: ptr_new(!ys_idlsys_temp), $
          fovlim:fltarr(4), $
          textid:textid, $
;;          trange:[tstart,tstop], sel_trange:[tstart,tstop], $
          trange:['',''], sel_trange:['',''], $
          debug:keyword_set(debug), network: not_local, $
          map: ptr_new(map), colourtable: 5, do_log:0b, $
          bkgimg_type:'', bkgimg_used:'', $
          imgcolors: imgcolors, oldct: 5, processed: ptr_new(image)}


message = 'PLOT_SSWCAT initialization'
widget_control,info.textid,set_value=message

return, tlb
end
