;
;+
;PROJECT:
;  SDAC
;NAME:  
;  batse_menu
;
;PURPOSE:
; batse_menu provides a menu for getting at the batse flare catalog and
; fdb and bdb data files.  On entry, it automatically enters the flist program
; and lists any flares identified in the most recent 24 hours.  This it
; displays a menu of the options available.
;
;INPUT:
; opt - menu option you wish to reach without going through the menu
;     for or 0- select screen and printer formats
;     cat or 1- display flare catalog entries
;     qlo or 2- display archived quicklook orbital plots
;     fla or 3- display archived flare plots
;     plo or 4- run interactive plot
;     vie or 5- display solar viewing times
;     asc or 6- create ascii files
;     lis or 7- list menu
;     gen or 8- access general help
;     hql or 9- access quicklook help
;     hfl or 10- access flare plot help
;     hca or 11- access catalog help
;     ann or 12- access old announcements 
;     qui or 13- quit batse_menu
;
;CATEGORY:
;    BATSE
;
;KEYWORDS:
;  nosave - if nosave is set, system variables are not restored to
;           their values from before when batse_menu is run.
;COMMON BLOCKS
;	TEK_COMMON, FLISTCOM2
;HISTORY:
;  Kim Tolbert  3/26/91
;
; Mod. 8/9/94 by Amy Skowronek to accept a variable when starting up.  This
; enables the user to skip the menu and go directly to the option of choice.
; When done with original option, user is directed to main menu. 
; Mod. 8/9/94 by AES to include concat_dir in calls to files with directory
; designations, so as not to confuse UNIX.
; Mod. 8/10/94 by AES to accept number instead of abbreviation for menu
; option variable.
; Mod. 8/15/94 by AES to record user's name, date of use, and host
; Mod. 8/22/94 by AES to accept keyword nosave.  nosave stops batse_menu
; from reassigning to system variables the values they had before batse_menu
; was run.  to be used when, for instance, one wishes to overplot a BATSE plot
; with a non-BATSE plot.
; Mod. 8/23/94 by AES to use execute on the spawn to check the user's
; node.  If not enough virtual memory is available to complete the spawn,
; error messages are printed and the routine proceeds.
; Mod, 12/18/95, ras, checks system before attempting to write to userlog file
; VERSION 9, richard.schwartz@gsfc.nasa.gov, 26-aug-1997,
; used loc_file with path_dir('batse') to locate help files.
;  Version 10, eva@kano.nascom.nasa.gov, 13-May-1999.
;	Added keyword EXTEND in fsplot -- when set, will expand the time interval
;	that software searches through to find pointing info when event is omni 
;	flare. Search changes from original 3x15 min intervals to 4x60min intervals.
;-
pro batse_menu, opt, nosave=nosave, EXTEND=EXTEND
!quiet = 1
;
save_bangp=!p
save_bangy=!y
save_bangx=!x
; record name of user and time of use
local_user=getenv('USER')
if local_user ne 'ANNE' and local_user ne 'AMY' and local_user ne 'KIM'  $
  and !version.os eq 'vms' then begin
 openw,lunit,'user_disk0:[batse]local_userlog.txt',/append,/get_lun
 com="spawn,'write sys$output f$getdvi(""tt"", ""tt_accpornam"")',result"
 r=0
 result=''
 tt_accpornam=''
 tt=''
 r=execute(com)
 if not r then print,'This error message concerns SDAC statistical '+$
                      'information only.  It may be ignored.'
 writeu,lunit,local_user+'   '+systime(0)+'     '+result
 free_lun,lunit
; print,local_user+'   '+systime(0)+'     '+result
endif
;
common tek_common, lun, tekfile, use_screen, sc_device, hard_device, queue

@flistcom

hxrbs_format, old_format = old_time_format
set_graphics, screen=sc_device, printer='PS'
;
; option variable checked here to see if user wants to skip menu and go
; right to a menu option
if n_elements(opt) ne 0 then begin 
 opt=strupcase(strcompress(opt,/remove_all))
 opt=strmid(opt,0,3)
words=['FOR','CAT','QLO','FLA','PLO','VIE','ASC','LIS','GEN','HQL','HFL',$
       'HCA','ANN','QUI']
numbers=['0','1','2','3','4','5','6','7','8','9','10','11','12','13']
num=where(numbers eq opt)
word=where(words eq opt)
if num(0) ge 0 then choice=numbers(num(0)) else $
 if word(0) ge 0 then choice=word(0) else goto, start
 goto,choose
endif
;
print, ' '
print, ' '
print, ' '
print, $
 'GRO BATSE Solar Flare Data Subsystem maintained by SMM/HXRBS group at GSFC'
print, ' '
;
; List events catalogued in last four days
;
; get current time in seconds relative to 79/1/1,0
flist,/latest
;
start:
alpha_page
print, '  '
print, 'GRO BATSE Solar Data Menu'
print, 'Options are:'
print, '  0.  Select screen and printer formats'
print, '  1.  Display flare catalog entries'
print, '  2.  Display archived quicklook orbital plots' 
print, '  3.  Display archived flare plots' 
print, '  4.  Run interactive plot program'
print, '  5.  Display BATSE solar viewing times'
print, '  6.  Enter program to create ASCII files of BATSE data'
print, '  7.  List this menu'
print, '  8.  Type general help information'
print, '  9.  Type help information on quicklook plots'
print, '  10. Type help information on flare plots'
print, '  11. Type help information on flare catalog'
print, '  12. Access announcements'
print, '  13. Quit (and logout)'
print, ' '
print, 'Current screen and printer devices are ',sc_device, ', ', hard_device
print, 'To change devices, select option 0.'
print, ' '
;
;
choice = ' '
read,'Enter number of option: ',choice
choice = strcompress (choice, /remove_all)
choice = strmid(strupcase(choice), 0, 3)
;
choose:
case 1 of 
;
choice eq '0': begin
   select_dev
   goto,start
end
;
; Choice was 1 - display flare catalog entries
choice eq '1': begin
   flist
   goto,start
end
;
choice eq '2': begin
   qldisplay
   goto,start
end
;
choice eq '3': begin
   fldisplay
   goto,start
end
;
choice eq '4': begin
   fsplot, EXTEND=EXTEND		; 13-MAY-1999 -- eva
;   fsplot
   goto,start
end
;
choice eq '5': begin
   batse_ontimes
   goto,start
end
;
choice eq '6': begin
dumpoptions:
   print, ''
   print, ''
   print, 'There are two types of ASCII output files:'
   print, ''
   print, 'RAW -   Contains raw counts in the 4 channels, NaI, and the ', $
          'CPD in each'
   print, '        1.024 s sample for 8 LAD''s, as well as pointing, ', $
          'position, and '
   print, '        housekeeping information.'
   print, ''
   print, 'RATES - Contains rates (counts/sec) that have been corrected for ', $
          'livetime and '
   print, '        counter overflow in the 4 channels and the CPD in each ', $
          '1.024 s sample'
   print, '        as well as livetime and angle from the Sun for 8 LAD''s.'
   print, ''
   type = ' '
   read, 'Enter type (RAW or RATES) or press return to cancel:  ', type
   if type eq '' then goto,start
   type = strupcase(type)
   type = strcompress (type, /remove_all)
   print, ''
   case type of
      'RAW': rawdump
      'RATES': ratesdump
      else: goto,dumpoptions
   endcase
   goto,start
end
;
choice eq '7': begin
   goto,start
end
;
choice eq '8' or choice eq '9' or choice eq '10' or choice eq '11': begin
   helpname  = (['help_general','help_quicklook','help_flareplot','help_catalog'])(fix(choice)-8)+'.txt'
   helpfile=loc_file(path=[curdir(), path_dir('batse'),'BATSE_DATA'],helpname) 
   if helpfile ne '' then read_seqfile, morebf, helpfile else print,'Unable to find '+helpname
   more, morebf
   print, ' '
   print, ' '
   mailfile, helpfile
   goto,start
end
;
choice eq '12': begin
   announcements
   goto,start
end
;
choice eq '13': begin
   goto,done
end
;
choice eq 'EXI': begin
   goto,done
end
;
choice eq 'QUI': begin
   goto,done
end
;
choice eq 'RET': begin
   goto,done
end
;
else: goto,start
endcase
;
done:
if not keyword_set(nosave) then begin
!x=save_bangx
!y=save_bangy
!p=save_bangp
endif
if old_time_format eq 'YOHKOH' then yohkoh_format
return&end
