      SUBROUTINE RFFTC(N,Z,IOPT)                                                
C        FIVE                                                                   
C                                                                               
C   MODULE        RFFTC                                                         
C   VERSION       1.0                                                           
C   LAST MODIFIED 25/11/81                                                      
C   AUTHOR        DAVE POWELL                                                   
C                                                                               
C   PARAMETERS                                                                  
C   **********                                                                  
C                                                                               
C   N     I*4   LENGTH OF ORIGINAL SEQUENCE                                     
C   Z     C  A  COMPLEX ARRAY CONTAINING BOTH I/P & O/P SEQUENCES               
C   IOPT  I*4   CONTAINS OPTIONS REQUIRED                                       
C                                                                               
C   THIS PROGRAM TAKES A REAL FOURIER TRANSFORM BY SPLITING                     
C   THE ORIGINAL SEQUENCE AND CALLING CFFTC - A COMPLEX FFT .                   
C   THE SEQUENCE IS THEN MANIPULATED AND FINALLY RETURNED                       
C   AS A COMPLEX ARRAY .                                                        
C                                                                               
      INTEGER*4 N,IOPT                                                          
      COMPLEX Z(N/2)                                                            
C                                                                               
      INTEGER*4 I1,I2,M,MP2,J2,MV2,MV22,BS,LASTN                                
      COMPLEX Y,CT,XE(1024),XO(1024),TEMP,Y1,THETA                              
      REAL*4 PI,A,B,C                                                           
      COMMON/RFFT/BS(1024),LASTN                                                
      DATA PI/3.141592653589793/                                                
C                                                                               
      M=N/2                                                                     
      MP2=M+2                                                                   
      CALL CFFTC(M,Z,IOPT)                                                      
C                                                                               
      IF (N.NE.LASTN) THEN                                                      
          J4=1                                                                  
          DO 4003 I4=1,M-1                                                      
              IF (I4.LT.J4) THEN                                                
                  BS(I4)=J4                                                     
                  BS(J4)=I4                                                     
              ENDIF                                                             
              K=M/2                                                             
4001          CONTINUE                                                          
              IF (K.GE.J4) GOTO 4002                                            
              J4=J4-1                                                           
              K=K/2                                                             
              GOTO 4001                                                         
4002          CONTINUE                                                          
              J4=J4+K                                                           
4003      CONTINUE                                                              
      ENDIF                                                                     
      WRITE(6,600)                                                              
600   FORMAT(20X,'ARRAY Z - BEFORE ANY MANIPULATION',/,20X,33('*'),//)          
      DO 10 I=1,32                                                              
      WRITE(6,610)I,Z(I)                                                        
610   FORMAT(10X,I2,2(5X,E14.7))                                                
10    CONTINUE                                                                  
C                                                                               
C                                                                               
C   (1) CALCULATIONS OF ODD AND EVEN TRANSFORMS                                 
C   *******************************************                                 
C                                                                               
      CT=CONJG(Z(1))                                                            
      XO(1)=(Z(1)-CT)/(0.0,2.0)                                                 
      XE(1)=(Z(1)+CT)/2.0                                                       
      IF(IOPT.GE.4)THEN                                                         
          DO 1000 I1=2,M/2+1                                                    
              CT=CONJG(Z(MP2-I1))                                               
              XE(I1)=(Z(I1)+CT)/2.0                                             
              XO(I1)=(Z(I1)-CT)/(0.0,2.0)                                       
1000      CONTINUE                                                              
      ELSE                                                                      
          DO 1100 I1=2,M/2+1                                                    
              CT=CONJG(Z(BS(MP2-I1)))                                           
              XE(I1)=(Z(BS(I1))+CT)/2.0                                         
              XO(I1)=(Z(BS(I1))-CT)/(0.0,2.0)                                   
1100      CONTINUE                                                              
      ENDIF                                                                     
      WRITE(6,620)                                                              
620   FORMAT(//,20X,'ARRAYS XO & XE',/,20X,14('*'),/)                           
      WRITE(6,630)                                                              
630   FORMAT(12X,'ARRAY XO',20X,'ARRAY XE',/,12X,8('*'),20X,8('*'))             
      DO 20 I=1,17                                                              
      WRITE(6,640)XO(I),XE(I)                                                   
640   FORMAT(2X,2(E14.7,X,E14.7,4X))                                            
20    CONTINUE                                                                  
C                                                                               
C                                                                               
C   (2) COMBINATION OF ODD AND EVEN TRANSFORMS                                  
C   ******************************************                                  
C                                                                               
      THETA=(0.0,-2.0)*PI/FLOAT(N)                                              
      MV2=M/2                                                                   
      MV22=MV2+2                                                                
      DO 2000 I2=1,MV2                                                          
          J2=MV22-I2                                                            
          Y=CEXP(THETA*FLOAT(I2-1))                                             
          Y1=CEXP(-THETA*FLOAT(J2-1))                                           
          Z(I2)=2.0*(XE(I2)+XO(I2)*Y)                                           
          Z(I2+MV2)=2.0*(CONJG(XE(J2))-CONJG(XO(J2))*Y1)                        
2000  CONTINUE                                                                  
      Y=CEXP((0.0,-2.0)*PI*FLOAT(M-1)/FLOAT(N))                                 
      TEMP=2.0*(CONJG(XE(1))-CONJG(XO(1))*Y)                                    
      A=REAL(TEMP)                                                              
      B=REAL(Z(1))                                                              
      Z(1)=CMPLX(B,A)                                                           
C                                                                               
C                                                                               
C   (3) END                                                                     
C   *******                                                                     
C                                                                               
      RETURN                                                                    
      END                                                                       
