;+
; Name:
; pro ratesdump
; Purpose:
; Dumps BATSE rates data between selected times.
;
; History:
; Kim Tolbert   10/8/91
;
; Mod. 8/18/94 by AES to use getenv instead of trnlog
;      4/5/95 by AES - usefdb had been left out of dumpcom declaration -
;      added it so it would work with rawdump.
; Version 4, ras, 27-mar-1996, removed setup_arrays (now setup_batse_arrays)
;	not needed.
; VERSION 5, richard.schwartz@gsfc.nasa.gov, 26-aug-1997,
; used loc_file with path_dir('batse') to locate help files.
; Version 6 - eva@kano.nascom.nasa.gov, 09-Feb-2000
;			 - Increased default time-range from 10s to 15s
;-

;********************************************************************

pro ratesdump,x
!quiet = 1
;
common dumpcom, usefdb, dd_open, dd_type, sec_st, sec_to, sec_en, det_arr, $
  prcounts, prposition, prhouse, outprint

hxrbs_format, old_format=old_time_format
;
; Set defaults for operator communications.
;
dd_type = 1
; 
; If sys$login = [ANNE] set file type to BDB.
;test = trnlog("sys$login",trans,/full)
;if strpos(trans(0), 'ANNE') gt 0 then dd_type = 0
test=getenv('USER')
if test eq 'ANNE' then dd_type = 0
;
;setup_arrays, removed by ras, 27-mar-1996, fs_read_dd initializes.
;
sec_st = 0.d0
sec_to = 15.d0	; eva -- 28-Jan-2000 -> incresed time interval
sec_en = sec_st + sec_to
det_arr = [0,1,2,3,4,5,6,7] ; not used in ratesdump
prposition = 1 ; not used in ratesdump
prhouse = 1 ; not used in ratesdump
outprint = 0 ; 0/1/2 means output to terminal/printer/file
;
; Print operator communications on screen.
;
listoc = 1
op_com:
ratesdumpoc, cmnd, listoc
;
; Determine command specified and act accordingly.
;
case 1 of
cmnd eq 'DUM': begin
  if (size(dd_open))(0) eq 0 then begin
    print,'Please set an input file before attempting to dump.'
    listoc = 1
    goto,op_com
  endif
  print, ' '
  print, 'Dumping ', sec_en-sec_st, ' seconds of rates data.'
  print, ' '
  if sec_en le sec_st then begin
    print,'Error--end time is less than or equal to start time.'
    goto,op_com
  endif
  print, ' '
  if sec_st eq 0.0 then begin
     sec_st = dd_open.startsec
     sec_en = sec_st + sec_to
  endif
  ascii_rates, file=dd_open.filename, starttime=sec_st, endtime=sec_en, $
              output = outprint, error = error
  if error then goto,op_com
  if outprint eq 1 then begin
     spawn,'print/setup=port batse_rates.out'
  endif 
end
;
cmnd eq 'FIL': begin
  filelist, dd_type
end
;
cmnd eq 'HEL': begin
   helpname  = 'help_ratesdump.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
   mailfile, helpfile
end
;
cmnd eq 'PRI': begin
  print,' '
   print, $
 'NOTE: If you haven''t issued the Dump command yet, Print prints the dump'
   print, $
 'file resulting from the last dump made on this account.'
   print,' '
   case outprint of
      0: spawn,'type/page batse_rates.out'
      1: spawn,'print/setup=port batse_rates.out'
      else:
   endcase
;
   mailfile,'batse_rates.out'
end
;
else: goto,getout ; Command is exit.
;
endcase
;
goto,op_com
;
getout:
if n_elements(dd_open) gt 0 then free_lun, dd_open.lun
;
if old_time_format eq 'YOHKOH' then yohkoh_format

return&end
