Viewing contents of file '../idllib/ghrs/pro/bin_spec.pro'
pro bin_spec,npts,wave,flux,bin_wave,bin_flux
;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;+
;
;*NAME: BIN_SPEC
;
;*CLASS:
;
;*CATEGORY:
;
;*PURPOSE:
; Procedure to bin a GHRS spectrum by summing over a specified (NPTS)
; number of datapoints to produce an effective low resolution spectrum
;
;*CALLING SEQUENCE:
; bin_spec,npts,wave,flux,bin_wave,bin_flux
;
;*PARAMETERS:
; INPUT:
; npts - number of points per bin.
; wave - wavelength vector
; flux - flux vector
;
; OUTPUT:
; bin_wave - binned wavelength vector
; bin_flux - binned flux vector
;
;*EXAMPLES:
; 1) Sum spectrum over 5 datapoints (assumes WAVE and FLUX exist)
; npts=5
; bin_spec,npts,wave,flux,bin_wave,bin_flux
; plot,bin_wave,bin_flux,psym=0
; oplot,wave,flux,psym=3
;
; 2) Average spectrum over 5 datapoints (assumes WAVE and FLUX exist)
; npts=5
; bin_spec,npts,wave,flux,bin_wave,bin_flux
; bin_flux = bin_flux/npts
; plot,wave,flux,psym=3
; oplot,bin_wave,bin_flux,psym=0
;
;*MODIFICATION HISTORY:
; R Robinson - Version 1.
; 23-apr-1992 JKF/ACC - moved to GHRS DAF.
;-
;-------------------------------------------------------------------------------
on_error,2
if n_params(0) lt 1 then $
message,'Calling Sequence: bin_spec,npts,wave,flux,bin_wave,bin_flux'
tot = long(n_elements(wave))
fnum = long(tot/npts>1.0) ; number of bins
if fnum le 1 then return
;
; resize output to integral # of bins.
;
bin_wave = fltarr(fnum)
bin_flux = bin_wave
;
; Sum up the points in each bin.
;
for i =0, fnum-1 do begin
bin_wave(i) = total(wave( i*npts: i*npts + (npts-1)))
bin_flux(i) = total(flux( i*npts: i*npts + (npts-1)))
endfor
bin_wave = bin_wave/npts ; calculate center wavelengths of each bin.
return
end