      SUBROUTINE PREENV( X, N )

C     Forms the pre-envelope of the function
C     Real( X( N ) ) is the input time series
C     The output vector is complex
C     N must be a power of 2 and <16384

      COMPLEX X( * )

C     Check N is a power of 2

      IF ( N .LE. 0 )
     &   STOP 'FATAL ERROR in BNDPAS: N must be positive'

      NT = 2**( INT( LOG10(REAL(N)) / 0.30104 ) +1 )
      IF ( NT .NE. N )
     &   STOP 'FATAL ERROR in BNDPAS: N must be a power of 2'

C     *** Fourier transform ***

      CALL CFFT( X, N, 1 )
      CALL CFFTSC( X, N )

C     *** Zero-out the negative spectrum (the upper N/2 positions) ***

      DO I = N/2+1, N
         X( I ) = 0.0
      END DO

C      CALL VCLR( X(N/2+1), 1, N )  ! VCLR expects a real vector

C     *** Inverse Fourier transform ***

      CALL CFFT( X, N, -1 )

      RETURN
      END
