Viewing contents of file '../idllib/ghrs/pro/bck_smooth.pro'
pro bck_smooth,median_width,mean_width,poly_order,data
;*********************************************************************
;+
;*NAME:
;			bck_smooth.pro
;*PURPOSE:
; Routine to smooth background spectra by a median filter followed
; by a mean filter.
;
;*CALLING SEQUENCE:
;	bck_smooth,median_width,mean_width,poly_order,data
;
;*PARAMETERS:
; INPUTS:
;	median_width - median filter width
;	mean_width - mean filter width
;	poly_order - width of polynomial (-1 do not use)
;
; INPUT/OUTPUTS:
;	data - data vector
;*HISTORY:
;	DJL
;	DJL	MAR'91	- added option for polynomial fitting.
;-
;-------------------------------------------------------------------------

	n=n_elements(data)

;
;  MEDIAN FILTER
;
	if median_width gt 1 then vmedian,data,median_width,x	$ ;median filter
			     else x=data			  ;no median filter
;
;  MEAN FILTER
;
	if mean_width gt 1 then begin
		data=smooth(x,mean_width)
;
; extend first and last filtered points to the endpoints
;
		hw=fix(mean_width)/2	;half width
		first=hw		;first point filtered
		last=n-hw-1		;last point filtered
		data(0:first-1)=data(first)
		data(last+1:n-1)=data(last)
	   end else begin
		data=x			;no mean filter
	end
;
; POLYNOMIAL FIT
;
	case 1 of
	    (poly_order eq 0) : data(*) = total(data)/500	;use average
	    (poly_order gt 0) : c = $
			poly_fit(findgen(n),double(data),poly_order,data)
	    else:
	end
return
end