pro ratesdumpoc,cmnd,listoc
;+
;  Name:
;       RATESDUMPOC
; pro ratesdumpoc
; Operator communications for the task to dump BATSE rates data.
;
; Kim Tolbert   10/8/91
;
; Modified 4/5/95 by AES - usefdb had been left out of dumpcom declaration -
;	   		   added it so it works with rawdump
; Version 2 		 - eva@kano.nascom.nasa.gov, 09-Feb-2000
;			 - Increased default time-range from 10s to 15s
;	   
;********************************************************************
;-
common dumpcom, usefdb, dd_open, dd_type, sec_st, sec_to, sec_en, det_arr, $
  prcounts, prposition, prhouse, outprint
;
@remotecom
;
;
commands = 'DUMEXIFILPRIHELRETQUI'
comma=','
inline = ' '
abdbfdb = ['BDB', 'FDB']
aenab = ['DISABLE', 'ENABLE']
aoutprint =['Terminal','Printer','File']
;
;
list:
if listoc eq 0 then goto,read
listoc=0
a_stime = atime(sec_st,/hxr)
a_etime = atime(sec_en,/hxr)
alpha_page
;
; Display current values for parameters and menu of commands.
;
print, $
 '---------------------------------------------------------------------------'
print, $
 'Batse Rates Dump Program - Produces ASCII output of rates (counts/sec) that'
print, $
 'have been corrected for livetime and counter overflow in the four channels'
print, $
 'and the CPD in each 1.024 second sample, as well as livetime and angle from'
print, $
 'the Sun for 8 LAD''s.'
print, $
 '---------------------------------------------------------------------------'
print,' '
print,'Change options by entering first 3 letters of item, comma, new value.'
print, $
'(To select input file, type  INP,FILENAME   INP,T,time   INP,F,flare#   or'
print,'INP,J,tjd or YY/MM/DD,secsofday(optional) .)' ;CHANGE*******!!!!!!
print,'After setting options, enter one of the available commands.'
print,'  '
file = ' '
if (size(dd_open))(0) ne 0 then file = dd_open.filename
print,format='("Input file",T27,A)',file
print,format='("Database  BDB/FDB",T39,A3)',abdbfdb(dd_type)
print,format='("Start time of dump",T21,A)',a_stime
print,format='("Total time (seconds)",T28,F14.3)',sec_to
print,format='("End time of dump",T21,A)',a_etime 
print,format='("Outprint   Terminal/Printer/File",T39,A8)',$
      aoutprint(outprint)
addrexist = size(mailaddr)
if addrexist(1) ne 0 then print,format='("Email address", T39, A)', mailaddr
print,'  '
print,'Commands: ListMenu, Dump, Print, Filelist, Help, Exit'
print,'Change parameters or enter a command'
;
; Prompt for input and read response form operator.
;
on_ioerror,errorinput
on_error,3
read:
read,inline
inline = batse_time_input( inline, ['STA','END','INP'])
inline = strupcase(inline)
inline = strcompress (inline, /remove_all)
;
; Compare commands.
;
cmnd = strmid(inline, 0, 3)
if cmnd eq 'LIS' then begin
  listoc = 1
  goto,list
endif
for j=0,6 do begin
   if cmnd eq strmid(commands, j*3, 3) then goto,getout
endfor
;
; Compare parameters.
;
param = strmid(inline, 0, 3)
strt = strpos(inline, comma) + 1
if strt eq 0 then goto, errorinput
case 1 of
  param eq 'INP': begin
    find_dbfile, inline, strt, dd_open, dd_type, sec_st, sec_to, sec_en
;    sec_to = 10. 
    sec_to = 15.  ; eva - initialize total to 15 seconds else time interval too small
    sec_en = sec_st + sec_to
  end
;
  param eq 'DAT': begin
    strng = strmid(inline,strt,3)
    case 1 of
      strng eq 'FDB': dd_type = 1
      strng eq 'BDB': begin
;         test = trnlog("sys$login",trans,/full)
;         if trans(0) eq 'SYS$USER:[BATSE]' then begin
          test=getenv('USER')
          if test eq 'BATSE' then begin
            print,'Only FDB files can be accessed through this account.'
            goto,read
         endif
         dd_type = 0
      end
      else: print,'Enter either ''BDB'' or ''FDB'', try again'
    endcase
  end        
;
  param eq 'STA': begin
    strng = strmid(inline,strt,21)
    setut,utbase=strng, utstart=strng, error = error
    getut,utstart=sec_st
    sec_en = sec_st + sec_to
    setut,utend=atime(sec_en),error = error
    if error then print,'error =',error
  end
;
  param eq 'TOT': begin
    strng = strmid(inline,strt,21)
    sec_to = double(strng)
    sec_en = sec_st + sec_to
    setut,utend=atime(sec_en), error = error
    if error then print,'error =',error
  end
;
  param eq 'END': begin
    strng = strmid(inline,strt,21)
    getut,utend=sav_en_sec
    setut,utend=strng, error = error
    getut,utend=en_sec
    if en_sec lt sec_st then begin
      print,'End time can not be before start time. Please reenter.'
      setut,utend=atime(sav_en_sec), error=error
      goto,read
    endif
    sec_en = en_sec
    sec_to = sec_en - sec_st
    if error then print,'error =',error
  end
;
  param eq 'OUT': begin
    strng = strmid (inline, strt, 3)
    case 1 of
      strng eq 'TER': outprint = 0
      strng eq 'PRI': outprint = 1
      strng eq 'FIL': outprint = 2
      else: begin
        print,'Enter ''Terminal'', ''Printer'', or ''File''.  Try again'
      end
    endcase
  end        
;
  param eq 'EMA': begin
    mailaddr = strmid (inline, strt, 100)
  end
;
  else: begin
    errorinput:
    print,'Error in input -- please reenter.'
    goto,read
  end
endcase
goto,read
;
getout:
;
return&end
