      SUBROUTINE CEFTC(N,COMSIG,IOPTC)                                          
C                                                                               
C                                                                               
C  MODULE:         CEFTC                                                        
C  VERSION:        1.0                                                          
C  ROUTINE:        3                                                            
C  LAST MODIFIED:  10/11/81                                                     
C  AUTHOR:         DAVE POWELL                                                  
C                                                                               
C  PARAMETERS                                                                   
C  **********                                                                   
C                                                                               
C  N      I*4  LENGTH OF SIGNAL-MUST BE POWER OF 2                              
C  COMSIG R*4A ARRAY CONTAINING COMPLEX SIGNAL                                  
C  IOPTC  I*4  INTEGER(BETWEEN 0 & 7) DETERMINING OPTIONS                       
C                                                                               
C  OPTIONS FOR A GIVEN IOPTC                                                    
C  *************************                                                    
C                                                                               
C  IOPTC                   OPTIONS                                              
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                                                                               
      COMPLEX COMSIG(N)                                                         
      INTEGER*4 IOPTC,N                                                         
C                                                                               
C                                                                               
C  LOCAL VARIABLES                                                              
C  ***************                                                              
C                                                                               
C  U      C*8     CURRENT INCREMENTAL VALUE OF MULTIPLICATION FACTOR            
C  W      C*8     EXP(-j*PI/LE1)                                                
C  CT     C*8     COMPLEX TEMPORARY STORE                                       
C  PI     R*4     3.14159....                                                   
C  T      R*4     =1/N (FOR SCALING);=1 (FOR NO SCALING)                        
C  M      I*4     =LOG(BASE 2) N                                                
C  NV2    I*4     N/2                                                           
C  NM1    I*4     N-1                                                           
C  IS     I*4     =8,4,2,1 - USED TO EVALUATE B(1),B(2),B(3)                    
C  B      I*4A    INFORMATION ON OPTIONS                                        
C  RTN    I*4     ROUTINE NUMBER                                                
C  IER    I*4     ERROR NUMBER                                                  
C  IOPT   I*4     COPY OF IOPTC                                                 
C  IP     I*4     POINTER AT CURRENT EVALUATION                                 
C  I1-I5  I*4     LOOP COUNTERS                                                 
C  J2-J5  I*4     LOOP COUNTERS                                                 
C  K4,L4  I*4     LOOP COUNTERS                                                 
C                                                                               
      COMPLEX U,W,CT                                                            
      REAL*4 PI,T                                                               
      INTEGER*4 M,NV2,NM1,IS,B(3),K,LE,IP,I1,I2,J2,I3,J3,J4,K4,L4,I5            
      INTEGER*4 J5,IOPT,RTN,IER                                                 
C                                                                               
      DATA PI/3.141592653589793/                                                
      PARAMETER (RTN=3)                                                         
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                                                                               
      M=1                                                                       
C     FORTRAN DO LOOP                                                           
      DO 1002 I1=1,11                                                           
          M=2*M                                                                 
          IF(M.EQ.N) GOTO 1003                                                  
C     ENDDO                                                                     
1002  CONTINUE                                                                  
      GOTO 9002                                                                 
1003  CONTINUE                                                                  
      M=I1                                                                      
      NV2=N/2                                                                   
      NM1=N-1                                                                   
C                                                                               
C                                                                               
C  (2) FIND OPTIONS REQUIRED & TAKE COMPLEX CONJUGATE AS REQUIRED               
C  **************************************************************               
C                                                                               
      IS=8                                                                      
C     FORTRAN DO LOOP                                                           
      DO 2001 I2=1,3                                                            
          IS=IS/2                                                               
          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                                                        
              COMSIG(J2)=CONJG(COMSIG(J2))                                      
C         ENDDO                                                                 
2002      CONTINUE                                                              
      ENDIF                                                                     
C                                                                               
C                                                                               
C  (3) BIT SHUFFLE IF REQUIRED                                                  
C  ***************************                                                  
C                                                                               
      IF (B(1).EQ.1) THEN                                                       
C         BIT SHUFFLE                                                           
          J3=1                                                                  
C         FORTRAN DO LOOP                                                       
          DO 3003 I3=1,NM1                                                      
              IF (I3.LT.J3) THEN                                                
                  CT=COMSIG(J3)                                                 
                  COMSIG(J3)=COMSIG(I3)                                         
                  COMSIG(I3)=CT                                                 
              ENDIF                                                             
              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                                                              
      ENDIF                                                                     
C                                                                               
C                                                                               
C  (4) IN PLACE FFT                                                             
C  ****************                                                             
C                                                                               
C  (a) DECIMATION IN TIME-I/P BIT SHUFFLED,O/P NATURAL ORDER                    
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                                                               
          U=(1.0,0.0)                                                           
          W=CMPLX(COS(PI/LE1),-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                                                     
                  CT=U*COMSIG(IP)                                               
                  COMSIG(IP)=COMSIG(L4)-CT                                      
                  COMSIG(L4)=COMSIG(L4)+CT                                      
C             ENDDO                                                             
4020          CONTINUE                                                          
          U=U*W                                                                 
C         ENDDO                                                                 
4030      CONTINUE                                                              
C     ENDDO                                                                     
4010  CONTINUE                                                                  
      GOTO 5000                                                                 
C                                                                               
C                                                                               
C  (b) DECIMATION IN FREQUENCY-I/P NATURAL ORDER,O/P BIT SHUFFLED               
C                                                                               
4100  CONTINUE                                                                  
      LE=2*N                                                                    
C     FORTRAN DO LOOP                                                           
      DO 4110 J4=1,M                                                            
          LE=LE/2                                                               
          LE1=LE/2                                                              
          U=(1.0,0.0)                                                           
          W=CMPLX(COS(PI/LE1),-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                                                     
                  CT=COMSIG(L4)-COMSIG(IP)                                      
                  COMSIG(L4)=COMSIG(L4)+COMSIG(IP)                              
                  COMSIG(IP)=CT*U                                               
C             ENDDO                                                             
4120          CONTINUE                                                          
              U=U*W                                                             
C         ENDDO                                                                 
4130      CONTINUE                                                              
C     ENDDO                                                                     
4110  CONTINUE                                                                  
C                                                                               
C                                                                               
C  (5) SCALE AND TAKE INVERSE AS REQUIRED                                       
C  **************************************                                       
C                                                                               
5000  CONTINUE                                                                  
      IF(B(3).EQ.0.OR.B(2).EQ.1) THEN                                           
          IF(B(2).EQ.1) THEN                                                    
              T=1.0/FLOAT(N)                                                    
          ELSE                                                                  
              T=1.0                                                             
          ENDIF                                                                 
          IF(B(3).EQ.0) THEN                                                    
C             FORTRAN DO LOOP                                                   
              DO 5001 I5=1,N                                                    
                  COMSIG(I5)=T*CONJG(COMSIG(I5))                                
C             ENDDO                                                             
5001          CONTINUE                                                          
          ELSE                                                                  
C             FORTRAN DO LOOP                                                   
              DO 5002 J5=1,N                                                    
                  COMSIG(J5)=T*COMSIG(J5)                                       
C             ENDDO                                                             
5002          CONTINUE                                                          
          ENDIF                                                                 
      ENDIF                                                                     
      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                                                                       
