C***************************************************************
C
C WINDOW FUNCTIONS
C
C Written by Victor De Pinto
C Revised Jan. 22, 1982
C
      SUBROUTINE WIND ( DAT )
      LOGICAL FN1(11), FN2(11)
      DIMENSION DAT(2,1024)
1     WRITE (1,4)
4     FORMAT (' -- WINDOW MENU --'/
     X  ' This routine performs a window function on the'/
     X  ' source file and puts the result in the destination'/
     X  ' file. Select the desired window.'/
     X  ' 1  RECTANGLE'/
     X  ' 2  EXTENDED COSINE BELL'/
     X  ' 3  HALF CYCLE SINE'/
     X  ' 4  TRIANGLE (Bartlett)'/
     X  ' 5  COSINE (Hanning)'/
     X  ' 6  HALF CYCLE SINE CUBED'/
     X  ' 7  HAMMING'/
     X  ' 8  COSINE SQUARED'/
     X  ' 9  PARZEN'/
     X  ' 10 BACK TO MAIN MENU >> ')
      READ (1,5) ISEL
5     FORMAT (I2)
      GO TO (7,7,7,7,7,7,7,7,7,6), ISEL
      GO TO 1
6     RETURN
7     WRITE (1,10)
10    FORMAT (' Source filename,')
      CALL NAME ( FN1 )
      WRITE (1,12)
12    FORMAT (' Destination filename,')
      CALL NAME ( FN2 )
      WRITE (1,20)
20    FORMAT (' Enter first data point of window (0-1023): ')
      READ (1,22) IFIRST
22    FORMAT (I4)
      WRITE (1,25)
25    FORMAT ('+Enter last data point of window (0-1023): ')
      READ (1,22) LAST
C Compute the width of the window
      WIDTH = LAST - IFIRST
C Read the source file
      CALL OPEN (3, FN1, 0)
      READ (3) DAT
      ENDFILE 3
C
C Do the window operation.
C All points outside the range of the window are zeroed.
C
      DO 200 J=0,1023
C If point is outside the range, the amplitude is zero.
      IF (J .LT. IFIRST .OR. J .GT. LAST) GO TO 120
C The point is in range, so compute the amplitude.
C TIME varies from 0.0 to 1.0
      TIME = (J - IFIRST) / WIDTH
      GO TO (101,102,103,104,105,106,107,108,109), ISEL
101   CALL RECTAN (AMP, TIME)
      GO TO 130
102   CALL COSBEL (AMP, TIME)
      GO TO 130
103   CALL HAFSIN (AMP, TIME)
      GO TO 130
104   CALL TRIANG (AMP, TIME)
      GO TO 130
105   CALL HANNIN (AMP, TIME)
      GO TO 130
106   CALL HFSIN3 (AMP, TIME)
      GO TO 130
107   CALL HAMMIN (AMP, TIME)
      GO TO 130
108   CALL COSSQR (AMP, TIME)
      GO TO 130
109   CALL PARZEN (AMP, TIME)
      GO TO 130
120   AMP = 0.0
130   DAT (1,J+1) = DAT(1,J+1) * AMP
200   DAT (2,J+1) = DAT(2,J+1) * AMP
C
C Windowing is complete. Write to output file.
C
      CALL OPEN (4, FN2, 0)
      WRITE (4) DAT
      ENDFILE 4
      GO TO 1
      END
C
C RECTANGULAR WINDOW
C
      SUBROUTINE RECTAN (AMP, TIME)
      AMP = 1.0
      RETURN
      END
C
C EXTENDED COSINE BELL WINDOW
C
      SUBROUTINE COSBEL (AMP, TIME)
      DATA TENPI / 31.41592654 /
      IF (TIME .LE. 0.1 .OR. TIME .GE. 0.9) GOTO 10
      AMP = 1.0
      RETURN
10    AMP = 0.5 * (1.0 - COS(TENPI*TIME) )
      RETURN
      END
C
C HALF CYCLE SINE WINDOW
C
      SUBROUTINE HAFSIN (AMP, TIME)
      DATA PI / 3.141592654 /
      AMP = SIN (PI * TIME)
      RETURN
      END
C
C TRIANGLE WINDOW
C
      SUBROUTINE TRIANG (AMP, TIME)
      IF (TIME .LE. 0.5) AMP = 2.0 * TIME
      IF (TIME .GT. 0.5) AMP = 2.0 - 2.0 * TIME
      RETURN
      END
C
C COSINE (HANNING) WINDOW
C
      SUBROUTINE HANNIN (AMP, TIME)
      DATA TWOPI / 6.283185307 /
      AMP = 0.5 * (1.0-COS(TWOPI*TIME))
      RETURN
      END
C
C HALF CYCLE SINE CUBED WINDOW
C
      SUBROUTINE HFSIN3 (AMP, TIME)
      CALL HAFSIN (AMP, TIME)
      AMP = AMP**3
      RETURN
      END
C
C HAMMING WINDOW
C
      SUBROUTINE HAMMIN (AMP, TIME)
      CALL HANNIN (AMP, TIME)
      AMP = 0.08 + 0.92 * AMP
      RETURN
      END
C
C COSINE SQUARED WINDOW
C
      SUBROUTINE COSSQR (AMP, TIME)
      CALL HANNIN (AMP, TIME)
      AMP = AMP**2
      RETURN
      END
C
C PARZEN WINDOW
C
      SUBROUTINE PARZEN (AMP, TIME)
      A = 2.0 * TIME - 1.0
      IF (TIME .GT. 0.25 .AND. TIME .LT. 0.75) GO TO 7
      AMP = 2.0 * (1.0- ABS(A))**3
      RETURN
7     AMP = 1.0 - 6.0 * A**2 + 6.0 * ABS(A)**3
      RETURN
      END
C
