      SUBROUTINE FFTidim (A, B, iw,al,bl,r,trigs,idim,idimp2,
     &                    mwave2,lot,isign)
C
C Re-written to use NEC FFT routines
C 
C Chris Peters, GSC      February 6, 1996
C
      SAVE
      DIMENSION A( idim )
      DIMENSION B( idim )
C
      DIMENSION TRIGS( idim*3)
C
      DIMENSION IW(15), AL(0:idim/2), BL(idim/2), R(idim)
C                                                                       
       DATA ITEST/0/                                                    
       n1 = idim/2
       JUMP = n1
C                                                                       
C                                                                       
      IF (ISIGN .EQ.  1)  THEN                                          
C                                                                       
C  MULTIPLE FAST FOURIER TRANSFORM - SYNTHESIS.  ISIGN=1                
C  GOOD FOR ZONAL WAVE NUMBER  126 .                                     
C                                                                       
C     DIMENSION A( idim ,LOT)                                           
C                                                                       
C   INPUT - LOT SETS OF COMPLEX COEFFICIENTS IN                         
C           A(1,J), A(2,J), ..., A( mwavep *2,J), J=1,...,LOT.          
C           A( mwavep *2+1,J), ..., A( idim ,J), J=1,...,LOT ARE NOT SET
C           BEFORE CALL FFT idim .                                      
C                                                                       
C  OUTPUT - LOT SETS OF GRID VALUES IN                                  
C           A(1,J), A(2,J), ..., A( idim ,J), J=1,...,LOT.              
C                                                                       
C-CP
C-CP Note:  Due to differences between NEC FFT math library calls
C-CP and those on the NMC Cray, some reformatting of the array AL
C-CP containing spectral coefficients is necessary.  What is called
C-CP a "forward" transform on the cray is actually a "backward" 
C-CP transform on the NEC.  It is necessary to split the array A
C-CP containing coefficients into two arrays to prepare it for the NEC 
C-CP routines RFRFBT/RFRFTB.
C-CP
C-CP This 360 loop is not really needed since lot=1 !
C-CP
      JCOUNT=0
      KCOUNT=1 
      DO 360 J=1, lot
      DO 320 L=1, mwave2                                                
            IF (MOD(L,2).NE.0) THEN
             AL(JCOUNT) = 2.0*A(L)                                       
             JCOUNT = JCOUNT + 1
            ELSE IF (L.GT.2) THEN
             BL(KCOUNT) = -2.0*A(L)
             KCOUNT = KCOUNT + 1
            ENDIF
320   CONTINUE                                                          
      DO 340 L= mwave2/2 , jump                                         
             AL(L) = 0.0                                          
             BL(L) = 0.0
340   CONTINUE                                                          
360   CONTINUE                                                          
C                                                                       
C-CP  CALL CRAY FFT FOR SYNTHESIS.                                      
C-CP  CALL RFFTMLT (AL,WORK,TRIGS,IFAX,1,JUMP, idim ,LOT,1)             
C-CP
C-CP  CALL NEC FFT FOR SYNTHESIS
C-CP
      IF (ITEST.ne.idim)  THEN                                           
        ITEST=idim                                                     
        CALL RFRFBT(AL,BL,JUMP,R,idim,IW,TRIGS,IERR)
        PRINT 140                                                   
      ELSE
        CALL RFRFTB(AL,BL,JUMP,R,idim,IW,TRIGS,IERR)
      ENDIF
      IF (IERR .NE. 0 ) WRITE(6,*) IERR
120   FORMAT (' ERROR IN FFT ROUTINE RFRFBT/RFRFTB:  IERR =  ',I4)    
140   FORMAT (' RFRFBT CALLED IN FFT idim .  LONF =  idim  ')     
C                                                                       
      DO 440 J=1,lot
      DO 420 L=1, idim                                                  
             A(L) = R(L)                                       
420   CONTINUE                                                          
440   CONTINUE                                                          
460   CONTINUE                                                          
C                                                                       
      ENDIF                                                             
C                                                                       
C                                                                       
      IF (ISIGN .EQ. -1)  THEN                                          
C                                                                       
C  MULTIPLE FAST FOURIER TRANSFORM - ANALYSIS.  ISIGN=-1                
C  GOOD FOR ZONAL WAVE NUMBER  126 .                                     
C                                                                       
C     DIMENSION A( idim ,LOT), B( idim ,LOT)                            
C                                                                       
C   INPUT - LOT SETS OF GRID VALUES IN                                  
C           A(1,J), A(2,J), ..., A( idim ,J), J=1,...,LOT.              
C           A ARRAY IS NOT CHANGED BY SUBROUTINE FFT idim .             
C                                                                       
C  OUTPUT - LOT SETS OF COMPLEX COEFFICIENTS IN                         
C           B(1,J), B(2,J), ..., B( mwavep *2,J), J=1,...,LOT.          
C           B( mwavep *2+1,J), ..., B( idim ,J), J=1,...,LOT ARE NOT SET
C                                                                       
C-CP
C-CP This branch of the subroutine was re-written but not tested.  It
C-CP never gets executed by gesprep, since we are going from spectral to
C-CP grid.
C-CP Again, this 560 loop is unnecessary since we have only lot = 1
C-CP set of complex coefficients
C-CP
      DO 560 J=1, lot
      DO 520 L=1, idim                                                  
             R(L) = A(L)                                       
520   CONTINUE                                                          
560   CONTINUE                                                          
C                                                                       
C     CALL CRAY FFT FOR ANALYSIS.                                       
C-CP  CALL RFFTMLT (AL,WORK,TRIGS,IFAX,1,JUMP, idim ,LOT,-1)            
C-CP
C-CP CALL NEC FFT FOR ANALYSIS
C-CP
      IF (ITEST.ne.idim) THEN
        TEST=idim
        CALL RFRFFT(R,idim,AL,BL,JUMP,IW,TRIGS,IERR)
        PRINT 240                                                   
      ELSE
        CALL RFRFTF(R,idim,AL,BL,JUMP,IW,TRIGS,IERR)
      ENDIF
      IF (IERR .NE. 0 ) WRITE(6,*) IERR
220   FORMAT (' ERROR IN FFT :  IERR =  ',I4)    
240   FORMAT (' RFRFFT CALLED IN FFT idim .  LONF =  idim  ')     
C                                                                       
      DO 640 J=1, lot
      DO 620 L=1, mwave2                                                
             B(L) = AL(L)                                       
620   CONTINUE                                                          
640   CONTINUE                                                          
660   CONTINUE                                                          
C                                                                       
      ENDIF                                                             
C                                                                       
      RETURN                                                            
      END                                                               
