	SUBROUTINE WINDOW(DATA,NPTS,IWIND,TAPER,SIGMA)
C
C	WINDOW DOES WINDOWING ON A TIME SERIES. ALL WINDOWS HAVE BEEN
C	NORMALIZED SO THAT VARIANCE IS PRESERVED FOR PURE SINE WAVES.
C
C	PARAMETERS:
C	        DATA:   (INPUT) THE RAW SERIES OF LENGTH NPTS.
C	                (OUTPUT)THE WINDOWED SERIES.
C	        NPTS:   THE NUMBER OF POINTS IN SERIES DATA.
C	        IWIND:  THE WINDOW NUMBER:
C	                2   COSINE TAPER
C	                3   COSINE**2 (HANNING)
C	                7   GAUSSIAN
C	                9   HAMMING
C	                11  TRIANGULAR (BARTLETT OR FEJER)
C	        TAPER:  THE FRACTION OF THE DATA SERIES TO
C	                BE INCLUDED IN THE TAPER (COSINE TAPER ONLY).
C	        SIGMA:  THE FALLOFF OF THE GAUSSIAN WINDOW. 2.0 IS TYPICAL.
C
	DIMENSION DATA(1)

	DATA PI/3.1415926535/

	IF(IWIND.LE.0)RETURN
	N2=NPTS/2
	HALF=FLOAT(NPTS)/2.0

	GO TO (999,2,3,999,999,999,7,999,9,999,11),IWIND

C         COSINE TAPER:
c
c	cosine taper modified by P. Freitag,  Dec 86.
c	removed cf factor.  Assume it was included to boost
c	total variance of white noise to original value.
c	Program which calls this subr (ie CSPEC) renormalizes
c	spectra by comparing input and output variance so no
c	factor cf is needed.
c
c
2	KWID=TAPER*NPTS+0.5
c	CF=SQRT(1.0/(1.0-1.25*TAPER))
	DO 100 J=1,KWID
c	FACT=(1.0+COS(FLOAT(J-KWID)*PI/FLOAT(KWID)))/2.0 * CF
	FACT=(1.0+COS(FLOAT(J-KWID)*PI/FLOAT(KWID)))/2.0 
	DATA(J)=DATA(J)*FACT
	DATA(NPTS+1-J)=DATA(NPTS+1-J)*FACT
100	CONTINUE
c	J1=KWID+1
c	J2=NPTS-KWID
c	DO 120 J=J1,J2
c120	DATA(J)=CF*DATA(J)
	RETURN

C         COSINE**2 OR HANNING:
3	CF=SQRT(8.0/3.0)
	DO 150 J=1,N2
	FACT=(1.0+COS(PI*(HALF-J)/FLOAT(N2)))/2.0 * CF
	DATA(J)=DATA(J)*FACT
	DATA(NPTS+1-J)=DATA(NPTS+1-J)*FACT
150	CONTINUE
	RETURN

C         GAUSSIAN:
C7	SIG2=(N2/SIGMA)**2/2.0
C	TLIM=HALF-1.0
C	CF=SQRT(1.0/(SQRT(PI*SIG2)/(2.0*TLIM)*ERF(SQRT(2.0/SIG2)*TLIM)))
C	DO 250 J=1,N2
C	FACT=EXP(-(HALF-J)**2/SIG2) * CF
C	DATA(J)=DATA(J)*FACT
C	DATA(NPTS+1-J)=DATA(NPTS+1-J)*FACT
C250	CONTINUE
7	RETURN

C         HAMMING:
9	CF=1.4097
	DO 400 J=1,N2
	FACT=(0.54+0.46*COS(PI*(HALF-J)/FLOAT(N2))) * CF
	DATA(J)=DATA(J)*FACT
	DATA(NPTS+1-J)=DATA(NPTS+1-J)*FACT
400	CONTINUE
	RETURN

C         TRIANGULAR (BARTLETT OR FEJER:)
11	CF=1.732
	DO 500 J=1,N2
	FACT=(1.0-(HALF-J)/FLOAT(N2)) * CF
	DATA(J)=DATA(J)*FACT
	DATA(NPTS+1-J)=DATA(NPTS+1-J)*FACT
500	CONTINUE
999	RETURN
	END
