pro sp_group,sfname,bfname,ch,ff,ffe,chl,chh,ctonth=ctonth,fout=fout,fnorm=fnorm ;+ ; ; Adaptively calculate the boundary channel numbers for a constant ; signal to noise ratio spectrum ; ;*Input ; sfname, bfname - source and background file names ; ;*optional output: ; ch - mean channel number of the output spectrum bins ; ff, ffe - output spectrum and its erro bars ; chl, chh - the lower and upper channel numbers of the output spectrum bins ; ; ctonth - the signal to noise threshold; def=3 ; fnorm - adjusting factor for the background normalization; def= 1. ; This parameter is useful when background needs to be scaled by a factor ; (fnorm > 1, higher). ; fout - the output file name (to be used by grppha for example) ; which can be used in the program grppha for grouping. ;*Note ; the keywords, exposure and backscal in the fits headers of the source and ; background files must have been defined correctly. ; ;*Example: ; sp_group,'halo2.pi','bgnd_halo2.pi',cton=2,fout='test.grp' ; ; written by wqd, Feb 22, 2001 ; ;- if n_params() eq 0 then begin print,'CALLING SEQUENCE -- sp_group,sfname,bfname,ch,ff,ffe,chl,chh,ctonth=ctonth,fout=fout' return endif if n_elements(fnorm) eq 0 then fnorm=1. ; input source data tab=readfits(sfname,ext=1,hdr) snrow=sxpar(hdr,'naxis2') sc=tbget(hdr,tab,'counts',lindgen(snrow)) sexpt=sxpar(hdr,'exposure',count=count) if count ne 1 then stop,'stop: count not = 1' sarea=sxpar(hdr,'backscal',count=count) if count ne 1 then stop,'stop: count not = 1' ; input background data tab=readfits(bfname,ext=1,hdr) bnrow=sxpar(hdr,'naxis2') if bnrow ne snrow then stop,'stop: snrow ne bnrow!' bc=tbget(hdr,tab,'counts',lindgen(bnrow)) bexpt=sxpar(hdr,'exposure',count=count) if count ne 1 then stop,'stop: count not = 1' barea=sxpar(hdr,'backscal',count=count) if count ne 1 then stop,'stop: count not = 1' ;normalization of the background into the source region with the ; correct exposure bnorm=fnorm*sexpt*sarea/(bexpt*barea) ;calculate the grouping and output into the file. get_group,sc,bc*bnorm,ch,ff,ffe,chl,chh,ctonth=ctonth,fout=fout ;------------------------------- return end