      SUBROUTINE FFT ( Z1, Z2, N, INZEE ) 
CONSTRUCTS THE DISCRETE FOURIER TRANSFORM OF  Z1 (OR Z2) IN THE COOLEY- 
C  TUKEY WAY, BUT WITH A TWIST.     
      INTEGER INZEE,N,   AFTER,BEFORE,NEXT,NEXTMX,NOW,PRIME(12)   
      COMPLEX Z1(N),Z2(N)     
C******  I N P U T  ******    
C  Z1, Z2  COMPLEX N-VECTORS  
C  N  LENGTH OF  Z1  AND  Z2  
C  INZEE  INTEGER INDICATING WHETHER  Z1  OR  Z2  IS TO BE TRANSFORMED  
C     = 1 , TRANSFORM  Z1     
C     = 2 , TRANSFORM  Z2     
C******  W O R K  A R E A S  ****** 
C  Z1, Z2  ARE BOTH USED AS WORKARRAYS    
C******  O U T P U T  ******  
C  Z1  OR  Z2  CONTAINS THE DESIRED TRANSFORM (IN THE CORRECT ORDER)    
C  INZEE  INTEGER INDICATING WHETHER  Z1 OR Z2  CONTAINS THE TRANSFORM, 
C     = 1 , TRANSFORM IS IN  Z1     
C     = 2 , TRANSFORM IS IN  Z2     
C******  M E T H O D  ******  
C     THE INTEGER  N  IS DIVIDED INTO ITS PRIME FACTORS (UP TO A POINT).
C  FOR EACH SUCH FACTOR  P , THE P-TRANSFORM OF APPROPRIATE P-SUBVECTORS
C  OF  Z1 (OR Z2) IS CALCULATED IN  F F T S T P  AND STORED IN A SUIT-  
C  ABLE WAY  IN  Z2 (OR Z1).  SEE TEXT FOR DETAILS.   
C     
      DATA NEXTMX,PRIME / 12, 2,3,5,7,11,13,17,19,23,29,31,37 /   
      AFTER = 1   
      BEFORE = N  
      NEXT = 1    
C     
   10 IF ((BEFORE/PRIME(NEXT))*PRIME(NEXT) .LT. BEFORE) THEN
         NEXT = NEXT + 1
         IF (NEXT .LE. NEXTMX) THEN 
                                        GO TO 10
         ELSE     
            NOW = BEFORE
            BEFORE = 1  
         END IF   
      ELSE  
         NOW = PRIME(NEXT)    
         BEFORE = BEFORE/PRIME(NEXT)
      END IF
C     
      IF (INZEE .EQ. 1)  THEN 
         CALL FFTSTP( Z1, AFTER, NOW, BEFORE, Z2 )    
      ELSE  
         CALL FFTSTP( Z2, AFTER, NOW, BEFORE, Z1 )    
      END IF
      INZEE = 3 - INZEE 
      IF (BEFORE .EQ. 1)                RETURN  
      AFTER = AFTER*NOW 
                                        GO TO 10
      END   
