;+ ; Name: ; GRABFLARE ; This procedure is run on node SDAC from MSFC to extract continuous ; and discsp data from their jukebox for flares in the SDAC BATSE ; archive that have FDB files, but no corresponding cont and discsp ; file. It finds a list of needed flares from SDAC. For each needed ; flare, it selects a time interval from 2 minutes before the earliest ; flare or background to 2 minutes after the latest (times are found by ; reading the BATSE flare catalog on SDAC over the network from GIBSON), ; and runs QAA to extract that time interval. It then renames the files ; (QAA names them continous_data.dat and discsp_data.dat) to ; flare_xxx.cont_msfc and flare_xxx.discsp_msfc and copies them to SDAC, ; then deletes them from GIBSON. ; ; Kim Tolbert 3/94 (original) ; ; Modified 9/21/94 Amy Skowronek: Now accepts list of flares we need, ; copied over from SDAC. Added keywords for seconds of background wanted ; before and after flare. Standard is 120 seconds. If more is desired, ; for instance five minutes before, then add keywords before=180.d0, ; after=180.d0 ; example call: grabflare, before=120.d0, after=120.d0 ; This calls grabflare with a total of four minutes of data on either side ; of the flare. Must be in xxx.dx format. ; Modified 1/4/95 by AES copies previous log to sdac rather than current, ; because current log is open by user. ; Mod 3/21/95 by AES corrected documentation to reflect the fact that ; the routine is run from SDAC, rather than from GIBSON. ; Mod 4/3/95 by AES - included alternate statements to use pscratch ; space on gibson, rather than giscratch space, for when giscratch is ; full. routine check_disk now checks animaldsk1, and if it's not ; working right, for whatever reason, assigns usrdk9 to the diskname ; instead. ; 11-oct-1995, ras, get passwords from environment variables ; needed software installed on gibson for speed ;- pro grabflare, before=before, after=after @flare_catalog diskname='animaldsk1:[giscratch.schwartz.kim]' check_disk,diskname batse_read_cat flares=intarr(num_flares+1) openr,unit,'[schwartz]flares.tmp',/get_lun ;print,'just opened flares.tmp' files=strarr(100) files(*)='' valid=0 while valid eq 0 do begin errchk=0 on_ioerror,errout readf,unit,files errchk=1 errout: if errchk eq 0 then valid = 1 endwhile free_lun,unit ; spawn,'rename flares.lis tempflares.lis' index=where(files ne '',counter) if counter ne 0 then need=files(index) else goto, getout need=file2flare(need) ;contflares = -1 & discspflares = -1 ; contdir = findfile ('sdac::BATSE_CONT:9*.cont_*') ; contflares = file2flare(contdir) ; ; discspdir = findfile ('sdac::BATSE_DISCSP:9*.discsp_*') ; discspflares = file2flare(discspdir) ; flares (contflares) = 1 ; flares (discspflares) = flares(discspflares) + 1 ; need = where(flares lt 2, kneed) ; if kneed eq 1 then begin ; print,'No cont or discsp files are missing.' ; goto, getout ; endif else need = need(1:*) ; get rid of the zero at the beginning softp = getenv('softpsw')& visp = getenv('vstrpsw')& annep = getenv('annepsw') ndone = 0 nneed = n_elements(need) for ifl = 0,nneed-1 do begin flare = need(ifl) ind = where(fldata.flare_num eq flare) print, ' ' print, '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^' print, 'Doing flare ', flare if keyword_set(before) then beforeset=',before=before' else $ beforeset='' if keyword_set(after) then afterset=' ,after=after' else $ afterset='' interval=beforeset+afterset qaaresult=execute('setup_qaa, fldata(ind), error, diskname '+ $ interval) if error then goto, getout ndone = ndone + 1 if ndone gt 20 then begin ;if we've done 20 flares, copy to SDAC copy_to_gsfc, softp, diskname, error=error if error then goto, getout ndone = 0 endif next: endfor copy_to_gsfc,softp, diskname, error=error if error then goto, getout getout: spawn, 'copy/lo [schwartz]grabflare.log;-1 sdac"anne ' + annep + '"::user_disk0:'+ $ '[anne.gibson]',result print,result return&end pro check_disk, diskname spawn, 'copy/lo [schwartz.kim]grabdata.sav ' + diskname, result print,result if strpos(result(0),'COPY-S-COPIED') eq -1 then $ diskname='usrdk9:[pscratch.schwartz.amy]' $ else spawn, 'del ' + diskname + 'grabdata.sav;*' return&end pro copy_to_gsfc,ppp,diskname,error=error error = 0 print,'===========================================================' spawn, 'copy/lo '+ diskname + '*.cont_msfc ' + $ ' sdac"soft ' + ppp + '"::BATSE_CONT:',result print,result ; check for no files to copy or bad error message if strpos(result(0),'COPY-E-OPENIN') ne -1 then goto, copy_discsp if strpos(result(0),'COPY-S-COPIED') eq -1 then goto, error_exit spawn, 'dele ' + diskname + '*.cont_msfc;*' copy_discsp: spawn, 'copy/lo '+ diskname + '*.discsp_msfc ' + $ ' sdac"soft ' + ppp + '"::BATSE_DISCSP:',result print,result if strpos(result(0),'COPY-E-OPENIN') ne -1 then goto, getout if strpos(result(0),'COPY-S-COPIED') eq -1 then goto, error_exit spawn, 'dele ' + diskname + '*.discsp_msfc;*' goto, getout error_exit: error = 1 getout: return&end ; setup_qaa figures out the time interval of data we need to get for this ; flare, calls run_qaa to write a .com file, and then submit it. ; ; fldata contains the structure (directly from the flare catalog) ; for the current flare. ; ; added keywords for longer time intervals 9/21/94 AES pro setup_qaa, fldata, error, diskname, before=before, after=after print,'just called setup_qaa' error = 0 if not keyword_set(before) then before=0.d0 if not keyword_set(after) then after=0.d0 flare = fldata.flare_num stimes = [fldata.start_secs, $ fldata.bkg1_start_secs, $ fldata.bkg2_start_secs] etimes = [fldata.start_secs + fldata.duration, $ fldata.bkg1_start_secs + fldata.bkg1_duration, $ fldata.bkg2_start_secs + fldata.bkg2_duration] ; Start and end time to grab in seconds. grab_start = min (stimes (where(stimes ne 0.d))) - 120.d0 - before grab_end = max (etimes (where (etimes ne 0.d))) + 120.d0 + after ; Start and end TJD of times to grab tjd_start = ymd2tjd(atime(grab_start)) tjd_end = ymd2tjd(atime(grab_end)) ; Start and end seconds of day to grab. sod_start = long(grab_start - tjd2ymd(tjd_start)) sod_end = long(grab_end - tjd2ymd(tjd_end)) if tjd_end ne tjd_start then begin tjd_start2 = tjd_end tjd_end2 = tjd_end tjd_end = tjd_start sod_start2 = 0 sod_end2 = sod_end sod_end = 86400 endif else tjd_start2 = 0 run_qaa, flare,tjd_start,tjd_end,sod_start,sod_end,(tjd_start2 gt 0),diskname if tjd_start2 gt 0 then run_qaa, flare, tjd_start2, tjd_end2,$ sod_start2, sod_end2, 2, diskname return&end pro run_qaa, flare, tjd_start, tjd_end, sod_start, sod_end, twofiles, diskname print,'just called run_qaa' flarestr = strtrim(flare,2) file = 'grab_' + flarestr + '.com' openw, lun, file, /get_lun ; printf, lun, '$ run bdas$executables:qaa' printf, lun, '$ run bdas$test:qaa' printf, lun, 'Y' printf, lun, '3' printf, lun, 'file.list' printf, lun, 'N' printf, lun, strtrim(tjd_start,2) printf, lun, strtrim(tjd_end,2) printf, lun, strtrim(sod_start,2) printf, lun, strtrim(sod_end,2) printf, lun, 'Y' printf, lun, '80,A0' printf, lun, '-1' printf, lun, '-1' printf, lun, '-1' printf, lun, 'BDISP0' printf, lun, diskname printf, lun, '100' free_lun, lun print,'Submitting file ',file spawn, '@ ' + file, result print,result suffix = '' if twofiles eq 1 then suffix = '_a' if twofiles eq 2 then suffix = '_b' renamestr = $ '$ rename/lo ' + diskname + 'continuous_data.dat '+$ ' ' + diskname + 'flare_' + $ flarestr + suffix + '.cont_msfc' spawn, renamestr, renamemsg if (where(strpos(strupcase(renamemsg), 'SYSTEM-F-') ne -1))(0) ne -1 $ then begin print,renamemsg error = 1 endif renamestr = $ '$ rename ' + diskname + 'discsp_data.dat ' + $ ' ' + diskname + 'flare_' + $ flarestr + suffix + '.discsp_msfc' spawn, renamestr, renamemsg if (where(strpos(strupcase(renamemsg), 'SYSTEM-F-') ne -1))(0) ne -1 $ then begin print,renamemsg error = 1 endif spawn, 'delete grab_*.com;*,file.list;*' getout: return&end