      SUBROUTINE CEFTF(N,AR,AI,IOPTC)                                           
C                                                                               
C  MODULE        CEFTF                                                          
C  VERSION       1.0                                                            
C  LAST MODIFIED 11/11/81                                                       
C  AUTHOR        DAVE POWELL                                                    
C  ----------------------------------------------------------------             
C                                                                               
C  PARAMETERS                                                                   
C  **********                                                                   
C                                                                               
C  N      I*4  LENGTH OF SIGNAL MUST BE POWER OF 2                              
C  AR     R*4A REAL PART OF SIGNAL                                              
C  AI     R*4A IMAGINARY PART OF SIGNAL                                         
C  IOPTC  I*4  DEFINES OPTIONS REQUIRED                                         
C                                                                               
C  OPTIONS FOR A GIVEN IOPTC                                                    
C  *************************                                                    
C                                                                               
C  IOPTC               OPTIONS                                                  
C  -----               --------                                                 
C                                                                               
C   0      REVERSE,NO SCALING,NO BIT SHUFFLE (D.I.T.)                           
C   1      FORWARD,     "    ,      "        (D.I.F.)                           
C   2      REVERSE,SCALING   ,      "        (D.I.T.)                           
C   3      FORWARD,    "     ,      "        (D.I.F.)                           
C   4      REVERSE,NO SCALING,BIT SHUFFLE    (D.I.T.)                           
C   5      FORWARD,     "    ,    "          (D.I.T.)                           
C   6      REVERSE,SCALING   ,    "          (D.I.T.)                           
C   7      FORWARD,    "     ,    "          (D.I.T.)                           
C                                                                               
C                                                                               
      REAL*4 C                                                                  
      REAL*4 AR(N),AI(N)                                                        
      INTEGER*4 N,IOPTC                                                         
C                                                                               
C  ---------------------------------------------------------------              
C                                                                               
C  LOCAL VARIABLES                                                              
C  ***************                                                              
C                                                                               
C  M      I*4  =LOG(N) BASE 2                                                   
C  NV2    I*4  =N/2                                                             
C  NM1    I*4  =N-1                                                             
C  IS     I*4  REPRESENTS POWER OF TWO                                          
C  B      I*4A BIT REPRESENTATION                                               
C  LE     I*4  2**L                                                             
C  LE1    I*4  LE/2                                                             
C  IP     I*4  POINTER TO OTHER HALF OF BUTTERFLY                               
C  T,T1   R*4  DUMPS                                                            
C  I1-I3  I*4  DO LOOP COUNTERS                                                 
C  J2,J4  I*4       "                                                           
C  K4     I*4       "                                                           
C  L4     I*4       "                                                           
C  J3-J4  I*4 POINTERS                                                          
C  FR     I*4 INDICATES DIRECTION OF FFT                                        
C  IOPT   I*4 LOCAL COPY OF IOPTC                                               
C  RTN    I*4 ROUTINE NUMBER                                                    
C  IER    I*4 ERROR NUMBER                                                      
C                                                                               
      REAL*4 T,UR,UI,T1,WR,WI                                                   
      INTEGER*4 NV2,NM1,IS,IP,B,LE,LE1,M,FR,RTN,IER                             
      INTEGER*4 I1,I2,J2,I3,J3,K,J4,K4,L4,I5                                    
      DIMENSION B(3)                                                            
      DATA PI/3.141592653589793/                                                
      PARAMETER (RTN=4)                                                         
C                                                                               
C                                                                               
C  ----------------------------------------------------------                   
C  (1) CHECK PARAMETERS & SET M=LOG(N) BASE 2                                   
C  ******************************************                                   
C                                                                               
      IOPT=IOPTC                                                                
      MAXLEN=2048                                                               
      IF(N.GT.MAXLEN.OR.N.LT.4)GOTO 9003                                        
      IF(IOPT.LT.0.OR.IOPT.GT.7) GOTO 9001                                      
C                                                                               
C                                                                               
      DO 1002 I1=1,11                                                           
          M=I1                                                                  
          IF(2**M.EQ.N) GOTO 1003                                               
C     ENDDO                                                                     
1002  CONTINUE                                                                  
      GOTO 9002                                                                 
1003  CONTINUE                                                                  
      NV2=N/2                                                                   
      NM1=N-1                                                                   
C                                                                               
C                                                                               
C  (2) OPTIONS REQUIRED & TAKE CONJUGATE IF INVERSE REQUIRED                    
C  *********************************************************                    
C                                                                               
C     FORTRAN DO LOOP                                                           
      DO 2001 I2=1,3                                                            
          IS=4/2**(I2-1)                                                        
          IOPT=IOPT-IS                                                          
          IF(IOPT.GE.0) GOTO 2000                                               
          IOPT=IOPT+IS                                                          
          B(I2)=0                                                               
          GOTO 2001                                                             
2000      CONTINUE                                                              
          B(I2)=1                                                               
C     ENDDO                                                                     
2001  CONTINUE                                                                  
C                                                                               
      IF (B(3).EQ.0) THEN                                                       
C         FORTRAN DO LOOP                                                       
          DO 2002 J2=1,N                                                        
              AI(J2)=(-1)*AI(J2)                                                
C         ENDDO                                                                 
2002      CONTINUE                                                              
      ENDIF                                                                     
C                                                                               
C                                                                               
C                                                                               
C  (3) BIT SHUFFLE IF REQUIRED                                                  
C  ***************************                                                  
C                                                                               
      IF(B(1).NE.1)GOTO 3004                                                    
      J3=1                                                                      
C     FORTRAN DO LOOP                                                           
      DO 3003 I3=1,NM1                                                          
          IF(I3.GE.J3)GOTO 3000                                                 
          T=AR(J3)                                                              
          AR(J3)=AR(I3)                                                         
          AR(I3)=T                                                              
          T=AI(J3)                                                              
          AI(J3)=AI(I3)                                                         
          AI(I3)=T                                                              
3000      CONTINUE                                                              
          K=NV2                                                                 
3001      CONTINUE                                                              
          IF(K.GE.J3) GOTO 3002                                                 
          J3=J3-K                                                               
          K=K/2                                                                 
          GOTO 3001                                                             
3002      CONTINUE                                                              
          J3=J3+K                                                               
C     ENDDO                                                                     
3003  CONTINUE                                                                  
3004  CONTINUE                                                                  
C                                                                               
C                                                                               
C  (4) IN PLACE FFT                                                             
C  ****************                                                             
C                                                                               
C   (a) DECIMATION IN TIME-I/P BIT SHUFFLED,0/P NATURAL ORDER                   
C                                                                               
C                                                                               
      IF(B(1).EQ.0.AND.B(3).EQ.1) GOTO 4100                                     
      LE=1                                                                      
C     FORTRAN DO LOOP                                                           
      DO 4010 J4=1,M                                                            
          LE1=LE                                                                
          LE=2*LE                                                               
          UR=1.0                                                                
          UI=0.0                                                                
          WR=COS(PI/LE1)                                                        
          WI=SIN(PI/LE1)                                                        
C         FORTRAN DO LOOP                                                       
          DO 4030 K4=1,LE1                                                      
C             FORTRAN DO LOOP                                                   
              DO 4020 L4=K4,N,LE                                                
                  IP=L4+LE1                                                     
                  T=AR(IP)*UR-AI(IP)*UI                                         
                  T1=AR(IP)*UI+AI(IP)*UR                                        
                  AR(IP)=AR(L4)-T                                               
                  AI(IP)=AI(L4)-T1                                              
                  AR(L4)=AR(L4)+T                                               
                  AI(L4)=AI(L4)+T1                                              
C             ENDDO                                                             
4020          CONTINUE                                                          
              T=UR*WR+UI*WI                                                     
              UI=UI*WR-UR*WI                                                    
              UR=T                                                              
C         ENDDO                                                                 
4030      CONTINUE                                                              
C     ENDDO                                                                     
4010  CONTINUE                                                                  
      GOTO 5000                                                                 
C                                                                               
C   (b) DECIMATION IN FREQ-I/P NATURAL ORDER,O/P BIT SHUFFLED                   
C                                                                               
C                                                                               
4100  CONTINUE                                                                  
      LE=2*N                                                                    
C     FORTRAN DO LOOP                                                           
      DO 4110 J4=1,M                                                            
          LE=LE/2                                                               
          LE1=LE/2                                                              
          UR=1.0                                                                
          UI=0.0                                                                
          WR=COS(PI/LE1)                                                        
          WI=SIN(PI/LE1)                                                        
C         FORTRAN DO LOOP                                                       
          DO 4130 K4=1,LE1                                                      
C             FORTRAN DO LOOP                                                   
              DO 4120 L4=K4,N,LE                                                
                  IP=L4+LE1                                                     
                  T=AR(L4)-AR(IP)                                               
                  T1=AI(L4)-AI(IP)                                              
                  AR(L4)=AR(L4)+AR(IP)                                          
                  AI(L4)=AI(L4)+AI(IP)                                          
                  AR(IP)=T*UR-T1*UI                                             
                  AI(IP)=T1*UR+T*UI                                             
C             ENDDO                                                             
4120          CONTINUE                                                          
              T=UR*WR+UI*WI                                                     
              UI=UI*WR-UR*WI                                                    
              UR=T                                                              
C         ENDDO                                                                 
4130      CONTINUE                                                              
C     ENDDO                                                                     
4110  CONTINUE                                                                  
C                                                                               
C                                                                               
C  (5) SCALE AND TAKE INVERSE AS REQUIRED                                       
C  **************************************                                       
C                                                                               
5000  CONTINUE                                                                  
      IF(B(2).EQ.0.AND.B(3).EQ.1) GOTO 5004                                     
      IF(B(2).EQ.0) GOTO 5001                                                   
      T=1.0/FLOAT(N)                                                            
      GOTO 5002                                                                 
5001  CONTINUE                                                                  
      T=1.00                                                                    
5002  CONTINUE                                                                  
      FR=(-1)**(B(3)+1)                                                         
C     FORTRAN DO LOOP                                                           
      DO 5003 I5=1,N                                                            
          AR(I5)=AR(I5)*T                                                       
          AI(I5)=FR*AI(I5)*T                                                    
C     ENDDO                                                                     
5003  CONTINUE                                                                  
5004  CONTINUE                                                                  
      RETURN                                                                    
C                                                                               
C  (6) END AND CALL OF ERROR ROUTINES                                           
C  **********************************                                           
C                                                                               
9001  CONTINUE                                                                  
      IER=1                                                                     
      GOTO 9999                                                                 
C                                                                               
9002  CONTINUE                                                                  
      IER=2                                                                     
      GOTO 9999                                                                 
C                                                                               
9003  CONTINUE                                                                  
      IER=3                                                                     
      GOTO 9999                                                                 
C                                                                               
9999  CONTINUE                                                                  
C                                                                               
      CALL UERERR('SIGPROC',RTN,IER,0,'E')                                      
      CALL UERREP('SIGREP',RTN,.FALSE.)                                         
C                                                                               
      RETURN                                                                    
      END                                                                       
