Viewing contents of file '../idllib/iuedac/iuelib/pro/filter.pro'
;*****************************************************************
;+
;*NAME:
;
;    FILTER  (General IDL Library 01)   MAY 31,1981
;
;*CLASS:
;
;    Smoothing
;
;*CATEGORY:
;
;*PURPOSE:  
;
;    PERFORM AN ARBITRARY SYMMETRICAL FILTERING.
;
;*CALLING SEQUENCE:
;
;    FILTER,DATA,FILTR,RESULT
;
;*PARAMETERS: 
;
;    DATA   (REQ) (I) (1) (F D)
;           required input vector containing the data to be smoothed
;
;    FILTR  (REQ) (I) (0 1) (I L F D)
;           if scalar, this parameter contains the width of the box filter.
;           if vector, this parameter contains the filter values where
;           FILTR(0)=center of filter.
;
;    RESULT (REQ) (O) (1) (F D)
;           Required output vector containing the filtered data.
;
;*EXAMPLES:
;
;        To filter data with a 5 point triangular filter
;                FILTR = FLTARR(3)
;                FILTR(0)= 3.0 & FILTR(1)= 2.0 & FILTR(2)= 1.0
;                FILTER,DATA,FILTR,RESULT
;
;*SYSTEM VARIABLES USED:
;
;*INTERACTIVE INPUT:
;
;*SUBROUTINES CALLED:
;
;     PARCHECK
;
;*FILES USED:
;
;*SIDE EFFECTS:
;
;*RESTRICTIONS:
;
;*NOTES:
;        The DATA array is effectively extended
;        1/2 the filter width with the value of
;        the first and last point of DATA before
;        filtering in the case of vector filters.
;             
;        The scalar filters do not filter the 
;        halfwidth of the filter at each end
;        of the data.
;
;	tested with IDL Version 2.1.0 (sunos sparc)  	20 Jun 91
;	tested with IDL Version 2.1.0 (ultrix mispel)	N/A
;	tested with IDL Version 2.1.0 (vms vax)      	21 Jun 91
;
;*PROCEDURE: 
;
;        For scalar FILTR, filtering done by
;            RESULT = SMOOTH ( DATA, FILTR )
;             
;        For vector FILTR:
;            (1) each data term is multiplied by 
;                 the center of the filter: FILTR(0).
;            (2) the previous (n-1) and next (n+1)
;                 data terms are multiplied by the
;                 filter value and summed with the
;                 value calculated in (1).
;            (3) filter is normalized by taking the
;                 ratio of the summed values (2),
;                 and twice the sum of the filter 
;                 values. ( NOTE: center of filter
;                 used only once )
;
;*MODIFICATION HISTORY:
;
;     May 31 1981  FHS3  GSFC  initial version
;     Jun  8 1987  RWT   GSFC  add PARCHECK
;     Mar  9 1988  CAG   GSFC  add VAX RDAF-style prolog
;     jul 19 1989  jtb   gsfc  converted to sun/unix idl
;     Jun 21 1991  PJL   GSFC  cleaned up; tested on SUN and VAX; 
;			       updated prolog
;
;-
;********************************************************************
 pro filter,data,filtr,result
;
 npar = n_params(0)
 if npar eq 0 then begin
    print,' FILTER,DATA,FILTR,RESULT'
    retall
 endif  ; npar
 parcheck,npar,3,'FILTER'
 s=size(filtr)
 if s(0) lt 1 then begin ; use smooth for scalar
    result = smooth(data,filtr)
    return
 endif  ; s(0)
;
 ind= make_array(size=size(data),/index)     ;index to extract data
;
 sum= data*filtr(0)
 npnts= fix(s(1))
 for i=1,npnts-1 do $
    sum= sum + (data(ind+i) + data(ind-i))*filtr(i)
;
; normalize filter
;
 result= sum/(total(filtr)*2 - filtr(0))    ;center is used only once
;
;
 return
 end    ;filter