;+ ; Name: ; MERGE_BURSTS ; ; Procedure: ;MERGE_BURSTS reads first three columns of information from a BATSE Burst ;Trigger List with a format like the following : ; ; Burst Trunc Sec Comments ; No. JD of day ; 146 8380 65642 Single peak lasting 30 s, with some structure. Channel 3. ; GOES C flare. ; 151 8382 58292 Single peak with structure lasting 15 seconds. Channel 2. ; GOES C flare. ; 155 8382 84146 Multiple. Triggered on precursor lasting about 20 s. Main ; peak lasting 300 s, came 200 s later. Channel 2. ; ; The file does not have to be manually edited to get rid of header and footer ; material, including the column labels. The program simply finds the first ; occurrence of day 146 and only uses that and the following lines. ; WARNING: ASSUMES NO MORE THAN 5000 LINES IN INPUT FILE!!!!!!!!!!!!!!!!!!! ; MERGE_BURSTS also reads our BATSE flare catalog, and then decides which bursts ; correspond to which flares (the burst time falls within the flare start time ; minus 5 minutes and the flare end time), and adds the burst number, the ; TJD, and the trigger seconds to our flare catalog. It writes the new ; catalog in a temporary file called new_batse.cat, and then copies this ; file to the standard catalog files - BATSE_DATA:BATSE_FLARE.CAT and ; BATSE_DATA:BATSE_LOG.CAT. There are two files, the first is the general ; catalog that all users read from and the second, batse_data:batse_log.cat ; is the file that is written to when flares are logged from Anne's account. ; Inputs: ; None ; Keywords: ; QUIET: ; B_NUM_ARR ; B_TJD_ARR ; B_TRIG_SECS_ARR ; ; History: ; ; Written by Erika Lin, 8/92, Modified by AKT. ; Mod. 8/30/93 by KT - After found the flare that a burst corresponds to, ; check if there are more bursts that might correspond to the same flare, ; and if so, only use the one that is closest to the start time of the ; flare. Write a message for the ones not used. ; ; mod, 12-apr-95, ras, writes stream files ; Mod. 4/26/95 by AES - They corrected the spelling of "Unclassified" in the ; burst trigger list, so corrected it in our strpos statement which is ; looking for the end of the file. ; Mod 5/25/95 by AES - Marshall changed the summary again - now look for ; "Unclassified Trigger" rather than "Unclassified Events" ; ras, 11-dec-95, uses extract_triggers.pro ; Mod 11/19/96 AES - use file_delete instead of delete_file. delete_file ; migrated to another tree, which is not in our path at this time. ;**************************************************************************** ; ;- pro merge_bursts, quiet=quiet, b_num_arr=b_num_arr, $ b_tjd_arr=b_tjd_arr, b_trig_secs_arr=b_trig_secs_arr ; ; @log_hdr_struct @flare_catalog batse_read_cat ; first zero out burst information that's alread in our flare catalog since ; we'll merge the complete burst list into the flare catalog each time. fldata.burst_num = 0 fldata.burst_tjd = 0 fldata.burst_trig_secs = 0 ; checkvar, quiet, !quiet ; extract_triggers, b_num_arr, b_tjd_arr, b_trig_secs_arr, error=error if error then message,'Error reading database file' ; ;Elements of the three arrays are sorted into their proper places in the ;flare catalog ; ;NEW_B_TRIG_SECS_ARR is array of triggertime secs after being converted to ;secs relative to 79/1/1,0000 ; new_b_trig_secs_arr = (b_tjd_arr-3874)*86400.d0 + b_trig_secs_arr n = n_elements(b_num_arr) fl_end_secs = fldata.start_secs + fldata.duration ; Flare end times for i = 0,n-1 do begin vf = -1 ; First look for bursts that occurred between flare start and end time. v = where((new_b_trig_secs_arr(i) ge fldata.start_secs) and $ (new_b_trig_secs_arr(i) le fl_end_secs),count) if count gt 0 then begin ; If found more than 1, we have overlapping flares, which isn't ; allowed. Print message and stop. if count gt 1 then begin print, 'Error - Overlapping BATSE flares: ' print, 'Stopping. Better check these flares: ',fldata(v).flare_num stop endif ;print,'Found within flare: ', fldata(v).flare_num vf = v(0) ; Now see if there are any other bursts that also lie within this ;flare. q = where((new_b_trig_secs_arr ge fldata(vf).start_secs) and $ (new_b_trig_secs_arr le fl_end_secs(vf)),count) if count gt 1 then begin first = min (new_b_trig_secs_arr(q) - fldata(vf).start_secs, iclosest) if i ne q(iclosest) then begin print, 'More than one burst found in flare ',$ fldata(vf).flare_num print, 'Burst ',b_num_arr(i), ' was not the closest to the start.' goto, nextburst endif endif endif else begin ; Now look for bursts that occurred up to 5 minutes before flare start. v = where((new_b_trig_secs_arr(i) ge fldata.start_secs-300) and $ (new_b_trig_secs_arr(i) le fldata.start_secs),count) if count gt 0 then begin print,'Found before flare: ', fldata(v).flare_num vf = v(0) endif endelse if vf ne -1 then begin fldata(vf).burst_num = b_num_arr(i) fldata(vf).burst_tjd = b_tjd_arr(i) fldata(vf).burst_trig_secs = b_trig_secs_arr(i) print,'MERGED: (entry=',vf, 'Burst = ', fldata(vf).burst_num, $ ' flare = ',fldata(vf).flare_num endif else begin temp = min(abs(new_b_trig_secs_arr(i)-fldata.start_secs),where_id) print,'NOMATCH: burst: ', atime(new_b_trig_secs_arr(i),/hxr),' ',$ 'flare: ',atime(fldata(where_id).start_secs,/hxr), ' ', $ string(new_b_trig_secs_arr(i)-fldata(where_id).start_secs,'(f8.1)'),$ ' s' endelse nextburst: endfor ; Get header record from original catalog file, update number of flares, ; and write it in new file. openr,unit,'BATSE_FLARE_CATALOG',/get_lun header = loghead readu, unit, header header = conv_vax_unix( use_vax_float(/old2new, header)) num_flares = header.last_flare free_lun,unit openw,outlun,'new_batse.cat',/stream,/get_lun writeu, outlun, use_vax_float( /new2old, header ) writeu, outlun, use_vax_float( /new2old, fldata ) free_lun,outlun print, 'Merged catalog written in file NEW_BATSE.CAT' print, ' ' ;goto,getout ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! error = 0 spawn, 'COPY/LO NEW_BATSE.CAT '+ concat_dir('BATSE_DATA','batse_flare.cat'), $ result print,result if strpos(result(0), 'COPY-S-COPIED') eq -1 then begin print,' ' print,'WARNING!!!. NOT COPIED TO BATSE_DATA:BATSE_FLARE.CAT' print,' ' error = 1 endif spawn, 'COPY/LO NEW_BATSE.CAT '+ concat_dir('BATSE_DATA','batse_log.cat'), $ result print,result if strpos(result(0), 'COPY-S-COPIED') eq -1 then begin print,' ' print,'WARNING!!!. NOT COPIED TO BATSE_DATA:BATSE_LOG.CAT' print,' ' error = 1 endif if error then begin print,' ' print, 'NOTIFY KIM THAT THERE IS A PROBLEM.' print,' ' endif else begin print, ' ' ; delete_file,'new_batse.cat' ; Mod 11/19/96 AES - use yohkoh routine to replace old delete_file.pro file_delete,'new_batse.cat' ;spawn, 'DELETE/LO NEW_BATSE.CAT;' print, ' ' print, 'Burst list was merged into a new version of the flare catalog,',$ 'called ' print, 'NEW_BATSE.CAT, and then this file was copied to the two standard ',$ 'files - ' print, 'BATSE_DATA:BATSE_FLARE.CAT and BATSE_DATA:BATSE_LOG.CAT. The ',$ 'temporary file, ' print, 'NEW_BATSE.CAT was then deleted.' endelse getout: end