      SUBROUTINE GPFLTR( FT, FFT, NPTS, WTS, NPF, NSKIP,NCDM,xbad,nbad) 
C***********************************************************************
C 
C                              PGM = GPFLTR 
C 
C                              PROGRAMMER = R.B.LUKAS 
C 
C                              27 JULY 1982 
C 
C***********************************************************************
C 
C   GPFLTR IS A GENERAL PURPOSE FILTER ROUTINE FOR SYMMETRIC, MOVING
C   AVERAGE FILTERS. THE INPUT TIME SERIES, FT, IS FILTERED AND RETURNED
C   IN FFT. NPTS IS THE LENGTH OF THE INPUT TIME SERIES. WTS IS THE 
C   VECTOR CONTAINING THE WEIGHTS OF THE FILTER; THE CENTRAL WEIGHT IS
C   WTS(1), AND WTS(2) THROUGH WTS(NWTS) CONTAIN THE WEIGHTS OF THE RIGH
C   HAND SIDE OF THE FILTER. NPF IS THE NUMBER OF POINTS IN THE FILTER, 
C   AND NWTS = (NPF+1)/2. 
C 
C***********************************************************************
c
c	modified to flag sums with nbad or more points with value xbad
c	if nbad>0	
c
c
      DIMENSION FT(1), FFT(1), WTS(1) 
      DATA BIG / 1.E35 /
      IF( NPTS .LT. NPF ) THEN
        WRITE(6,*) '*** GPFLTR ***' 
        WRITE(6,*) 'NUMBER OF PTS IN TIME SERIES IS LESS THAN THE'
        WRITE(6,*) 'NUMBER OF PTS IN THE FILTER'
        STOP
      END IF
      NWTS = (NPF+1)/2
      NLOST = NWTS - 1
      NCDM=0
	if (nbad.gt.0) then
      DO 30 I = NLOST+1, NPTS-NLOST,NSKIP 
	if(ft(i).eq.xbad) then
	wsum=0.0
	t=0.0
	ng=0
	else
        T = FT(I) * WTS(1)
	wsum=wts(1)
	ng=1
	endif
        DO 20 J = 2, NWTS 
          K = J - 1 
	fl=ft(i-k)
	fr=ft(i+k)
	if(fl.eq.xbad) then
	fl=0.0
	else
	ng=ng+1
	wsum=wsum+wts(j)
	endif
	if(fr.eq.xbad) then
	fr=0.0
	else
	ng=ng+1
	wsum=wsum+wts(j)
	endif
20        T = T + ( fr + fl ) * WTS(J)
      NCDM=NCDM+1 
	nout=npf-ng
	if(nout.eq.0) go to 30
	if(nout.ge.nbad) then
	t=xbad
	else
	t=t/wsum
	endif
30      FFT(NCDM) = T 
	else
      DO 50 I = NLOST+1, NPTS-NLOST,NSKIP 
        T = FT(I) * WTS(1)
        DO 40 J = 2, NWTS 
          K = J - 1 
40        T = T + ( FT(I+K) + FT(I-K) ) * WTS(J)
      NCDM=NCDM+1 
50      FFT(NCDM) = T 
	endif
      RETURN
      END 
