      SUBROUTINE FFGFW2(GR,LGR,FW,LFW,IR,ILONG,WRKS,NL) 
C 
C     *****   FEB 1976  -  JOHN D. HENDERSON  ****
C     * NOV 24/82 - R.LAPRISE, S.J.LAMBERT. 
C     * JUL 29/94 - F.MAJAESS(FORCE ROUTINE TO ABORT IF IR AND ILONG
C     *                       CONSTRAINTS ARE NOT SATISFIED)
C 
C     * USE THE FORTRAN FAST FOURIER TRANSFORM TO 
C     * PERFORM A WAVE TO GRID FOURIER TRANSFORM OF MULTI-LEVEL FIELD.
C     *  NOTE... GR AND FW ARE GENERALLY EQUIVALENCED IN CALLING ROUTINE
C     * GR = MULTI-LEVEL ARRAY TO RETURN GRID POINT FIELDS. 
C     * LGR = FIRST DIMENSION OF GR.
C     * FW = MULTI-LEVEL COMPLEX ARRAY CARRYING FOURIER AMPLITUDES. 
C     * LFW = FIRST DIMENSION OF FW.
C     * IR = MAXIMUM E.W. WAVENUMBER TO BE USED IN THE TRANSFORM. 
C     * ILONG=NUMBER OF LONGITUDES ON THE TRANSFORM GRID. 
C     * WRKS=WORK FIELD.
C     * NL =   NUMBER OF VERTICAL LEVELS. 
C 
C     * LEVEL 2, GR,FW
      IMPLICIT REAL (A-H,O-Z),
     +INTEGER (I-N)
      COMPLEX FW(LFW,NL),WRKS(1)
      DIMENSION GR(LGR,NL)
      COMPLEX AA,BB,CC
C-----------------------------------------------------------------------
      IRP1=IR+1 
      IF(MOD(ILONG,3).EQ.0) GO TO 100 
C-----------------------------------------------------------------------
C     * CASE 1 - ILONG IS A POWER OF 2. 
C     * MAX IR IS ILONG/2.  WRKS=(ILONG+1) COMPLEX WORDS. 
C 
      IF(IR.GT.ILONG/2) THEN
        WRITE(6,6010) IR,ILONG
        CALL                 XIT('FFGFW2',-1)
        RETURN
      ENDIF
      ILG2=ILONG+2
      NWMAX=ILONG/2  + 1
      WRKS(NWMAX+1)=(0.E0,0.E0) 
C 
      DO 50 L=1,NL
C 
C     * COPY WAVES 0 TO IR TO WRKS. FILL TO WAVE ILONG/2 WITH ZEROS.
C 
      DO 20 J=IRP1,NWMAX
   20 WRKS(J)=(0.E0,0.E0) 
      DO 30 J=1,IRP1
   30 WRKS(J)=FW(J,L) 
C 
C     * PERFORM THE FAST FOURIER TRANSFORM. 
C 
      N=ILONG 
      ISIGN=1 
      NTYP=-1 
      CALL FOUR2(WRKS,N,1,ISIGN,-1) 
C 
C     * COPY ILONG GRID POINTS FROM WRKS TO GR. 
C 
      NX=0
      DO 40 I=1,ILONG,2 
      NX=NX+1 
      GR(I  ,L)= REAL(WRKS(NX)) 
      GR(I+1,L)= IMAG(WRKS(NX)) 
   40 CONTINUE
   50 CONTINUE
      RETURN
C-----------------------------------------------------------------------
C     * CASE 2 - ILONG IS 3 TIMES A POWER OF 2. 
C     * MAX VALUE OF IR IS ILONG/3.  WRKS=(ILONG/6+1)*8 COMPLEX WORDS.
C     * THIS SECTION ADDED BY ROGER DALEY, FEB 1976.
C 
  100 K3 = ILONG/3
      IF(IR.GT.K3) THEN
        WRITE(6,6010) IR,ILONG
        CALL                 XIT('FFGFW2',-2)
        RETURN
      ENDIF
      K6 = K3/2 
      KP6 = K6 + 1
      NWMAX = 2*KP6 
      WRKS(7*KP6+1) = (0.E0,0.E0) 
C 
      CALL PERM(WRKS(2*KP6+1),WRKS(3*KP6+1),AA,BB,KP6,K3) 
C 
      DO 150 L=1,NL 
C 
      DO 120 J=IRP1,NWMAX 
  120 WRKS(J) = (0.E0,0.E0) 
      DO 130 J=1,IRP1 
  130 WRKS(J) = FW(J,L) 
C 
      DO 160 K=1,KP6
      CC = CONJG(WRKS(K3+2-K))
      WRKS(4*KP6+K) = WRKS(K) + CC
      WRKS(5*KP6+K) = (WRKS(K)+BB*CC)*WRKS(2*KP6+K) 
  160 WRKS(6*KP6+K) = (WRKS(K) + AA*CC)*WRKS(3*KP6+K) 
C 
      N=K3
      ISIGN = 1 
      NTYP = -1 
      CALL FOUR2(WRKS(4*KP6+1),N,1,ISIGN,-1)
      CALL FOUR2(WRKS(5*KP6+1),N,1,ISIGN,-1)
      CALL FOUR2(WRKS(6*KP6+1),N,1,ISIGN,-1)
      WRKS(7*KP6) = WRKS(6*KP6+1) 
C 
      DO 170 K=1,K6 
      KP = (K-1)*6
      GR(KP+1,L)= REAL (WRKS(4*KP6+K))
      GR(KP+2,L) =REAL (WRKS(5*KP6+K))
      GR(KP+3,L)=  IMAG(WRKS(6*KP6+K))
      GR(KP+4,L)=  IMAG(WRKS(4*KP6+K))
      GR(KP+5,L)=  IMAG(WRKS(5*KP6+K))
  170 GR(KP+6,L)= REAL(WRKS(6*KP6+K+1)) 
C 
  150 CONTINUE
      RETURN
C-----------------------------------------------------------------------
 6010 FORMAT(' ILLEGAL CALL TO FFGFW2..IR,ILONG=',2I9) 
      END 
