;+
;
; NAME: 
;       DO_PSPLOTS
;
; PURPOSE:
;
;
; CATEGORY:
;       BATSE
;
; CALLING SEQUENCE:
;
;
; CALLS:
;	none
;
; INPUTS:
;       none explicit, only through commons;
;
; OPTIONAL INPUTS:
;	none
;
; OUTPUTS:
;       none explicit, only through commons;
;
; OPTIONAL OUTPUTS:
;	none
;
; KEYWORDS:
;	none
; COMMON BLOCKS:
;	none
;
; SIDE EFFECTS:
;	none
;
; RESTRICTIONS:
;	none
;
; PROCEDURE:
;	none
;
; MODIFICATION HISTORY:
;
;-
pro do_psplots
;
; Makes PostScript plots of flares between first and last and saves the
; plot file as BATSE_PSPLOTS:BATSE_NNN.PS.  
; 
; Kim Tolbert 2/94
; Modified 5/25/94 by AKT to copy files temporarily to BATSE_PSPLOTS, and then 
; ftp them to umbra /service/ftp/pub/batse/batseplots.  Creates a .com file, 
; and spawns to @ it to do the ftp, then spawns to delete the .com file and the
; .ps files on BATSE_PSPLOTS.  Doing this so we no longer need to NFS mount
; the SDAC disk on umbra.
; Modified 8/17/94 by AES to use concat_dir on directory logicals to get
; correct format for VMS or UNIX
; Mod 4/1/96 by AES  get hxrbs password elsewhere
;
;****************************************************************************
!quiet = 1
;
@fscom
@fs_saveplot
@fs_saveaccum
common catalog_file, cunit  

hxrbs_format, old_format = old_time_format
;
hxps=get_hxp()


redocat = keyword_set(redocatalog) 
;
; get symbols for first and last flare to do and convert to numbers (by *1)
first = get_symbol("first")*1
last = get_symbol("last")*1
;
print, ' '
print, '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
print, 'Creating ps files for flares ', $
   first, ' - ', last
print, ' '
;
set_graphics, screen='null', printer='PS'
;
fsdef,x
olddevice=!d.name & set_plot,'ps' & device,/portrait & set_plot,olddevice
dd_type = 1 ; set input database type to FDB
noscreen = 1
;
; First read catalog into common flare_catalog.
batse_read_cat

; Loop through requested flares, making plot file and copying it to
; BATSE_PSPLOTS

for iflare = first,last do begin

   ; ps files have combined channels to save disk space
   noplotfile = 0  ; means do create plot file
   plot_flare, flare=iflare
   olddevice=!d.name & set_plot,'ps' & device,/close & set_plot,olddevice

   ; copy the ps file (fsplot.ps) to BATSE_PSPLOTS into a file
   ; called batse_xxx.ps. Then delete fsplot.ps
   psfile = 'batse_' + strtrim(iflare,2) + '.ps' 
   spawn, 'copy /log fsplot.ps '+ concat_dir((chklog('BATSE_PSPLOTS'))(0) , psfile) 
   spawn, 'delete/log fsplot.ps;*'
next:
endfor


print,' '
print, '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
print, 'Completed flares ', first, ' - ', last
print, 'Copying PostScript files to umbra via ftp.'
print, ' '


; Write a .com file with the commands needed to ftp the plot files to umbra.
; Then delete the plot files and and the .com file.

files = findfile(concat_dir((chklog('BATSE_PSPLOTS'))(0),'batse_*.ps'), count=kfile)

if kfile gt 0 then ftp_batseplots,hxps else print,'No files to ftp.'

; Leave a record of the flarenumber of the last ps plot created.

record_latest_number,last=last,/ps

getout:


set_graphics, screen='X', printer='PS'
if old_time_format eq 'YOHKOH' then yohkoh_format
return&end
