      SUBROUTINE CDFTC (N,C,IOPTC)                                              
C                                                                               
C  -------------------------------------------------------------                
C  MODULE        CDFTC                                                          
C  VERSION       1.0                                                            
C  LAST MODIFIED 23/10/81                                                       
C  AUTHOR        DAVE POWELL                                                    
C                                                                               
C  -------------------------------------------------------------                
C                                                                               
C  PARAMETERS                                                                   
C  **********                                                                   
C                                                                               
C  N    I*4  LENGTH OF SIGNAL                                                   
C  C    C A  COMPEX ARRAY CONTAINING BOTH I/P & O/P SIGNALS                     
C  IOPTCI*4  CARRIES INFORMATION ABOUT OPTIONS REQUIRED                         
C                                                                               
      INTEGER*4 N,IOPTC                                                         
      COMPLEX C(N)                                                              
C                                                                               
C                                                                               
C       IOPTC    B(1)   B(2)    MEANING                                         
C       -----    ----   ----    -------                                         
C                                                                               
C         4       0      0      REVERSE TRANSFORM,NO SCALING                    
C         5       0      1      FORWARD TRANSFORM,NO SCALING                    
C         6       1      0      REVERSE TRANSFORM,SCALING                       
C         7       1      1      FORWARD TRANSFORM,SCALING                       
C                                                                               
C  ------------------------------------------------------------                 
C                                                                               
C                                                                               
C  LOCAL VARIABLES                                                              
C  ***************                                                              
C                                                                               
C                                                                               
C  MAXLEN   I*4   MAXIMUM SIGNAL LENGTH                                         
C  B(2)     I*4   =1 OR 0 (1-FORWARD TRANSFORM,0-INVERSE TRANSFORM)             
C  B(1)     I*4   =1 OR 0 (1-SCALLING,0-NO SCALLING)                            
C  IS       I*4   USED TO CALCUATE B(1)&B(2) FROM IOPT                          
C  I2,I3,J3 I*4   COUNTERS                                                      
C  THETA    R*4   =2*PI/N                                                       
C  T        R*4   =MULT. FACTOR (=1 IF NO SCALING,=1/N IF SCALING)              
C  PI       R*4   =3.14159265.........                                          
C  Y        C*8   =-j IF FORWARD,+j IF REVERSE                                  
C  W        C*8   =EXP(-j*THETA)                                                
C  WK       C*8   =W**(I3)                                                      
C  WKL      C*8   =W**(I3*J3)                                                   
C  COMSIG   C*8A  COMPLEX SIGNAL                                                
C  IOPT     I*4   COPY OF IOPTC                                                 
C  RTN      I*4   ROUTINE NUMBER (=5)                                           
C  IER      I*4   ERROR NUMBER                                                  
C                                                                               
      INTEGER*4 I2,I3,J3,IS,B(2),MAXLEN,RTN,IER                                 
      REAL*4 THETA,T,PI                                                         
      COMPLEX Y,W,WK,WKL,COMSIG(2048)                                           
      DATA PI/3.141592653589793/                                                
      PARAMETER (RTN=5)                                                         
C                                                                               
C  ------------------------------------------------------------                 
C                                                                               
C  (1) CHECK PARAMETERS                                                         
C  ********************                                                         
C                                                                               
      IOPT=IOPTC-4                                                              
      MAXLEN=2048                                                               
      IF (N.GT.MAXLEN.OR.N.LT.2) GOTO 9002                                      
      IF (IOPTC.GT.7.OR.IOPTC.LT.4) GOTO 9001                                   
C                                                                               
C                                                                               
C  (2) SELECT OPTIONS                                                           
C  ******************                                                           
C                                                                               
      IS=4                                                                      
      DO 2001 I2=1,2                                                            
          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                                                               
2001  CONTINUE                                                                  
C                                                                               
C                                                                               
C  (3) DISCRETE FOURIER TRANSFORM                                               
C  ******************************                                               
C                                                                               
      THETA=2.0*PI/FLOAT(N)                                                     
      IF (B(2).EQ.0) THEN                                                       
          Y=(0.0,1.0)                                                           
      ELSE                                                                      
          Y=(0.0,-1.0)                                                          
      ENDIF                                                                     
C                                                                               
      W=CEXP(THETA*Y)                                                           
      WK=(1.0,0.0)                                                              
      DO 3001 I3=1,N                                                            
          COMSIG(I3)=0                                                          
          WKL=(1.0,0.0)                                                         
          DO 3000 J3=1,N                                                        
              COMSIG(I3)=COMSIG(I3)+C(J3)*WKL                                   
              WKL=WKL*WK                                                        
3000      CONTINUE                                                              
          WK=WK*W                                                               
3001  CONTINUE                                                                  
C                                                                               
C                                                                               
C  (4) SCALE (IF REQUIRED) & PLACE TRANSFORMED SIGNAL IN C                      
C  *******************************************************                      
C                                                                               
      IF (B(1).EQ.1) THEN                                                       
          T=1.0/FLOAT(N)                                                        
      ELSE                                                                      
          T=1.0                                                                 
      ENDIF                                                                     
      DO 4000 I4=1,N                                                            
          C(I4)=T*COMSIG(I4)                                                    
4000  CONTINUE                                                                  
      RETURN                                                                    
C                                                                               
C                                                                               
C  (5) END AND CALL ERROR ROUTINES IF REQUIRED                                  
C  *******************************************                                  
C                                                                               
9001  CONTINUE                                                                  
      IER=4                                                                     
      GOTO 9999                                                                 
C                                                                               
9002  CONTINUE                                                                  
      IER=5                                                                     
      GOTO 9999                                                                 
C                                                                               
9999  CONTINUE                                                                  
C                                                                               
      CALL UERERR('SIGPROC',RTN,IER,0,'E')                                      
      CALL UERREP('SIGREP',RTN,.FALSE.)                                         
C                                                                               
      RETURN                                                                    
      END                                                                       
