;+ ; ; NAME: help_merge ; ; ; PURPOSE: report the status of the arrays in the merge common ; ; ; CATEGORY: spectral analysis ; ; ; CALLING SEQUENCE: help_merge ; ; ; CALLED BY: spex ; ; ; INPUTS: ; none explicit, only through commons; ; ; OUTPUTS: ; none explicit, only through commons; ; ; COMMON BLOCKS: ; spex_hold_com ; spex_setup_com ; spex_proc_com ; ; MODIFICATION HISTORY: ; ras, 19-oct-94 ;- pro help_merge @spex_commons help, flux_h, eflux_h, edges_h, count_2_flux_h, delta_light_h, e_in_h, det_id_h help, ut_h, drm_h, ltime_h, source_h, edges_drm_h help, flux, eflux, edges, count_2_flux, delta_light, e_in, det_id help, ut, drm, ltime, source, edges_drm end ;+ ; ; NAME: spex_hold ; ; ; PURPOSE: save the current spectrum in common to allow merging of spectra ; ; ; CATEGORY: spectral analysis ; ; ; CALLING SEQUENCE: spex_hold ; ; ; CALLED BY: spex ; ; ; CALLS: ; none ; ; INPUTS: ; none explicit, only through commons; ; ; OPTIONAL INPUTS: ; none ; ; OUTPUTS: ; none explicit, only through commons; ; ; OPTIONAL OUTPUTS: ; none ; ; COMMON BLOCKS: ; spex_hold_com ; spex_setup_com ; spex_proc_com ; SIDE EFFECTS: ; none ; ; RESTRICTIONS: ; none ; ; PROCEDURE: ; none ; ; MODIFICATION HISTORY: ; ras, 19-oct-94 ;- pro spex_hold @spex_commons flux_h = flux eflux_h= eflux edges_h = edges edges_drm_h = edges_drm count_2_flux_h= count_2_flux delta_light_h = delta_light e_in_h = e_in det_id_h = det_id ut_h = ut drm_h = drm ltime_h = ltime source_h= source ;help_merge end ;+ ; ; NAME: spex_delete ; ; ; PURPOSE: remove channels from output spectra ; ; ; CATEGORY: spex, spectral analysis ; ; ; CALLING SEQUENCE: spex_delete, chan_2_delete[, wchan=wchan] ; ; CALLED BY: ; ; ; CALLS: ; none ; ; INPUTS: ; chan_2_delete - indices of channels to delete ; ; OPTIONAL INPUTS: ; wchan - as an alternative to chan_2_delete, the channels to use may ; be given as indices in wchan ; ; OUTPUTS: ; none explicit, only through commons; ; ; OPTIONAL OUTPUTS: ; none ; ; COMMON BLOCKS: ; common spex_proc_com ; ; SIDE EFFECTS: ; none ; ; RESTRICTIONS: ; none ; ; PROCEDURE: ; ; MODIFICATION HISTORY: ; ras, 20-oct-94 ; ;- pro spex_delete, chan_2_delete, wchan=wchan @spex_commons nchan = n_elements(edges(0,*)) w = indgen(nchan) mask1 = intarr(nchan)+1 if n_elements(chan_2_delete) ge 1 then mask1(chan_2_delete)=0 mask = intarr(nchan) if n_elements(wchan) ge 1 then mask(wchan)= 1 else mask = mask*0+1 mask = mask * mask1 chan_2_delete = where( not mask, n_2_delete) if n_2_delete ge 1 then begin w = where( mask, nkp) if nkp eq 0 then begin printx,'You have requested that all of the data channels be deleted. Error!' return endif flux = flux(w,*) eflux = eflux(w,*) edges = edges(*,w) edges_drm = edges_drm(*,w) ltime = ltime(w,*) rate = rate(w,*) if need.back eq 0 then begin back = back(w,*) eback= eback(w,*) endif erate = erate(w,*) count_2_flux = count_2_flux(w,*) delta_light = delta_light(w,*) drm = drm(w,*) source = source(*,w) ;if any channels are deleted then source must be initialized or changed endif iegroup = 0 ;help_merge end ;+ ; ; NAME: spex_merge ; ; ; PURPOSE: merge the current spectrum and drm with the ones in the spex_hold_com ; ; ; CATEGORY: spectral analysis, SPEX ; ; ; CALLING SEQUENCE: spex_merge ; ; ; CALLED BY: spex ; ; ; CALLS: ; none ; ; INPUTS: ; none explicit, only through commons; ; ; OPTIONAL INPUTS: ; ; ; OUTPUTS: ; none explicit, only through commons; ; ; OPTIONAL OUTPUTS: ; none ; ; COMMON BLOCKS: ; spex_hold_com ; spex_setup_com ; spex_proc_com ; ; SIDE EFFECTS: ; none ; ; RESTRICTIONS: ; flux in hold and current areas are defined on the same time range ; ; PROCEDURE: ; none ; ; MODIFICATION HISTORY: ; ras, 19-oct-94 ;- pro spex_merge @spex_commons if n_elements(flux_h) eq 0 then begin printx, 'Nothing to merge. Possible error!!!' return endif ;merge the output channel spectrum edges_drm = [[edges_drm_h], [edges_drm]] ;merge the drms ;if the input photon vector is different from a component of the ;held drm, then add new input components to drm, if they are the ;same, then just add output components ;data_id is an index into the possible data_tipes (see more_types in spex_hold_com) data_id = source(0,0) n_id = 0 where_idout = where( source_h(0,*) eq data_id, n_idout) if n_idout ge 1 then begin where_id = where(total( drm(where_idout,*),1) ne 0, n_id) drm = drm(*, where_id) e_in= e_in(*,where_id) ; ; Look for matches to drm input energies e_in in existing drm_h, e_in_h ; Sort them and return the unique elements, if they are different ; then there won't be an increase in the number of elements! ; imatch = where_id*0 ;imatch(i) of -1 means e_in(*,where_id(i)) wasn't found for i=0,n_id-1 do $ imatch(i) = (where( e_in(0,i) eq e_in_h(0,*) $ and e_in(1,i) eq e_in_h(1,*), nmatch))(0) wnomatch = where( imatch eq -1, nomatch) wmatch_in = where( imatch ge 0, nmatch) if nmatch ge 1 then wmatch_out = imatch(wmatch_in) endif else begin nomatch = n_elements(drm(0,*)) wnomatch= indgen(nomatch) nmatch = 0 endelse if nomatch eq 0 then printx,'All input photon bins found!' else $ printx, 'Some input photon bins not found!' sdrm = size(drm) sdrm_h = size(drm_h) drmc = fltarr(sdrm(1)+sdrm_h(1), sdrm_h(2) + nomatch ) drmc(0:sdrm_h(1)-1,0:sdrm_h(2)-1) = drm_h if nmatch ge 1 then drmc(sdrm_h(1):*,wmatch_out ) = drm(*,wmatch_in) if nomatch ge 1 then begin drmc(sdrm_h(1):*,sdrm_h(2)+nmatch:*) = drm(*,wnomatch) e_in = [[e_in_h],[e_in(*,wnomatch)]] endif else e_in = e_in_h edge_products, e_in, gm=em_in, width=w_in ;The drm edges have specific meaning, edges are just for display and are ;somewhat arbitrary. ;use as centroids the first moment, and for the width the standard ;deviation with a weighting function as a power-law of index -4 e_out_bar = f_div(drmc#(w_in*em_in/(em_in/50.)^4.),drmc#(w_in/(em_in/50.)^4.)) e_out_var_pos = e_out_bar*0.0 e_out_var_neg = e_out_bar*0.0 for i=0,n_elements(e_out_bar)-1 do begin wpos = where( em_in ge e_out_bar(i), npos) wneg = where( em_in le e_out_bar(i), nneg) if npos ge 1 then $ e_out_var_pos(i)= f_div( $ drmc(i,wpos)#((w_in*(em_in-e_out_bar(i))^2./(em_in/50.)^4.))(wpos),$ drmc(i,wpos)#((w_in/(em_in/50.)^4.)) (wpos)) if nneg ge 1 then $ e_out_var_neg(i)= f_div( $ drmc(i,wneg)#((w_in*(em_in-e_out_bar(i))^2./(em_in/50.)^4.))(wneg),$ drmc(i,wneg)#((w_in/(em_in/50.)^4.)) (wneg)) endfor e_out_sdev_pos = sqrt( e_out_var_pos ) e_out_sdev_neg = sqrt( e_out_var_neg ) edges_drm = transpose( [[e_out_bar-e_out_sdev_neg/2.],[e_out_bar+e_out_sdev_pos/2.]] ) ord = sort( e_out_bar ) edges_drm = edges_drm(*,ord) edges = edges_drm delta_light = ([delta_light_h, delta_light])(ord) source= ([[source_h],[source]])(*,ord) ;stop drm = drmc(ord,*) count_2_flux = ([count_2_flux_h, count_2_flux])(ord) flux = ([flux_h, flux])(ord,*) eflux= ([eflux_h, eflux])(ord,*) ltime= ([ltime_h, ltime])(ord,*) rate = flux erate= eflux title = 'MERGED DATA '+atime(ut(0)+getutbase(),/dat,/yoh) need.back = 1 spex_hold end ;+ ; ; NAME: spex_source ; ; ; PURPOSE: initialize source array in spex_hold_com ; ; ; CATEGORY: spex, spectral analysis ; ; ; CALLING SEQUENCE:spex_source_ident ; ; ; CALLED BY: ; ; ; CALLS: ; none ; ; INPUTS: ; none explicit, only through commons; ; ; OPTIONAL INPUTS: ; none ; ; OUTPUTS: ; none explicit, only through commons; ; ; OPTIONAL OUTPUTS: ; none ; ; COMMON BLOCKS: ; spex_hold_com ; spex_setup_com ; spex_proc_com ; ; SIDE EFFECTS: ; none ; ; RESTRICTIONS: ; none ; ; PROCEDURE: ; none ; ; MODIFICATION HISTORY: ; ras, 20-oct-94 ;- pro spex_source, clear=clear @spex_commons if keyword_set(clear) then begin delvarx, flux_h, eflux_h, edges_h, count_2_flux_h, delta_light_h, e_in_h, det_id_h delvarx, ut_h, drm_h, ltime_h, source_h, edges_drm_h return endif data_tipe = spex_current('data_tipe') checkvar, more_types, standard_types data_id = where( more_types eq arr2str(data_tipe,','), n_id) if n_id eq 0 then begin more_types = [standard_types,arr2str(data_tipe,',')] data_id = where( more_types eq arr2str(data_tipe,','), n_id) endif nchan = n_elements(edges(0,*)) w = fcheck(w,indgen(nchan)) source = intarr(3,nchan) source(0,*) = data_id source(1,*) = det_id source(2,*) = indgen(nchan) edges_drm = edges end