      SUBROUTINE MHEXP (QF,DF,UF,VF,TF,ESF,PSDLF,PSDPF,PRESSF,ILH,
     1                  LON,P,C,T,ES,PS,LA,LSR,LM,ILEV,LEVS,P2,LEVT,
     2                  FVORT,ALP,DALP,DELALP,WRKS,IFAX,TRIGS,LVECT)
C 
C     * JUL 14/92 - E. CHAN (ADD REAL*8 DECLARATIONS)
C     * JAN 26/84 - B.DUGAS.
C     * JUL 20/83 - R.LAPRISE.
C     * CONVERTS GLOBAL SPECTRAL ARRAYS OF STREAMFUNCTION (P) AND 
C     * VELOCITY POTENTIAL (C) TO GRID POINT SLICES OF VORTICITY (QF),
C     * DIVERGENCE (DF), AND WINDS (UF,VF). 
C     * ALSO CONVERTS LN(SURFACE PRESSURE) AND ITS DERIVATIVES. 
C     * ALSO CONVERTS TEMPERATURE (T) AND DEW POINT DEPRESSION (ES).
C 
C     *    ALP = LEGENDRE POLYNOMIALS AT GIVEN LATITUDE.
C     *   DALP = COS(LAT) TIMES N-S DERIVATIVE OF ALP.
C     * DELALP = -N(N+1)*ALP
C     * ILH = FIRST DIMENSION OF COMPLEX FOURIER ARRAYS.
C     * ILG = ILH*2 = FIRST DIMENSION OF REAL GRID ARRAYS.
C     * LON = NUMBER OF DISTINCT LONGITUDES.
C 
      IMPLICIT REAL (A-H,O-Z),
     +INTEGER (I-N)
      COMPLEX QF(ILH,1),DF(ILH,1),UF(ILH,1),VF(ILH,1) 
      COMPLEX TF(ILH,1),ESF(ILH,1)
      COMPLEX PSDLF(1),PSDPF(1),PRESSF(1) 
      COMPLEX P(LA,1),C(LA,1),T(LA,1),ES(LA,1),PS(1)
      REAL*8 ALP(1),DALP(1),DELALP(1) 
      REAL WRKS(1)
      INTEGER LSR(2,1)
      COMPLEX P2(ILEV)
      REAL IFAX(1),TRIGS(LON) 
C 
C     * SWITCK TO CONTROL VECTORIZATION ACROSS VARIABLES. 
C 
      LOGICAL LVECT 
C-------------------------------------------------------------------- 
C     * PART 1 - LEGENDRE TRANSFORMS FROM SPECTRAL TO FOURIER.
C 
      IR=LM-1 
      ILG=2*ILH 
C 
C     * DO ALL THE LEGENDRE TRANSFORMS AT ONCE IF LVECT IS .TRUE. 
C     * THIS PRESUMES THAT GRID SLICES AND SPECTRAL FIELDS ARE
C     * LINED UP IN MEMORY, WITH PS AS THE FIRST OF THE SERIES. 
C     * NUMBER = ILEV * 2 (FOR P,C) 
C               +LEVT * 1  (FOR T)
C     *         +LEVS * 1 (FOR ES)
C     *         +  1  * 1 (FOR PS). 
C 
      IF(LVECT) THEN
      NUMBER = 2*ILEV+LEVT+LEVS+1 
      CALL STAF (PRESSF,PS,LSR,LM,LA,ILH,NUMBER,ALP)
C 
      ELSE
C 
      CALL STAF (QF    ,P ,LSR,LM,LA,ILH,ILEV,ALP)
      CALL STAF (DF    ,C ,LSR,LM,LA,ILH,ILEV,ALP)
      IF(LEVT.EQ.0) GO TO 100 
      CALL STAF (TF    ,T ,LSR,LM,LA,ILH,LEVT,ALP)
  100 IF(LEVS.EQ.0) GO TO 110 
      CALL STAF (ESF   ,ES,LSR,LM,LA,ILH,LEVS,ALP)
  110 CALL STAF (PRESSF,PS,LSR,LM,LA,ILH,  1 ,ALP)
      ENDIF 
C-----------------------------------------------------------------------
C     * E-W DERIVATIVES OF PS AND P,C (IN QF,DF). 
C 
      DO 200 M=1,LM 
      FMS =FLOAT(M-1) 
      PSDLF (M)=CMPLX(-FMS* IMAG(PRESSF(M)), FMS*REAL(PRESSF(M))) 
      DO 200 L=1,ILEV 
      QF  (M,L)=CMPLX(-FMS* IMAG(QF  (M,L)), FMS*REAL(QF  (M,L))) 
      DF  (M,L)=CMPLX(-FMS* IMAG(DF  (M,L)), FMS*REAL(DF  (M,L))) 
  200 CONTINUE
C-----------------------------------------------------------------------
C     * N-S DERIVATIVES OF PS AND P,C (IN UF,VF). 
C     * ALL THE TRANSFORMS ARE DONE AT ONCE IF LVECT IS .TRUE.
C     * THIS PRESUMES THAT ALL ARRAYS ARE LINED UP IN MEMORY
C     * WITH PS AS THE FIRST OF THE SERIES. 
C     * NUMBER = ILEV *2 (FOR P,C)
C     *         +  1  *1 (FOR PS).
C 
      IF(LVECT) THEN
      NUMBER = 2*ILEV+1 
      CALL STAF (PSDPF ,PS,LSR,LM,LA,ILH,NUMBER,DALP) 
C 
      ELSE
C 
      CALL STAF (UF    ,P ,LSR,LM,LA,ILH,ILEV,DALP) 
      CALL STAF (VF    ,C ,LSR,LM,LA,ILH,ILEV,DALP) 
      CALL STAF (PSDPF ,PS,LSR,LM,LA,ILH,  1 ,DALP) 
      ENDIF 
C-----------------------------------------------------------------------
C     * U,V IN UF,VF. 
C 
      DO 270 L=1,ILEV 
      DO 270 M=1,LM 
      UF(M,L)=DF(M,L)-UF(M,L) 
  270 VF(M,L)=QF(M,L)+VF(M,L) 
C-----------------------------------------------------------------------
C     * FOURIER COEFF OF Q,D IN QF,DF.
C     * NOTE USE OF ABSOLUTE VORTICITY. 
C     * THE TWO SETS OF TRANSFORM CAN BE DONE AT ONCE IF LVECT IS .TRUE.
C 
      FPSI=-0.5E0*FVORT
      DO 290 L=1,ILEV 
      P2(L)=P(2,L)
      P(2,L)=P(2,L)+CMPLX(FPSI,0.E0)
  290 CONTINUE
C 
      IF(LVECT) THEN
      NUMBER = 2*ILEV 
      CALL STAF (QF    ,P ,LSR,LM,LA,ILH,NUMBER,DELALP) 
C 
      ELSE
C 
      CALL STAF (QF    ,P ,LSR,LM,LA,ILH,ILEV,DELALP) 
      CALL STAF (DF    ,C ,LSR,LM,LA,ILH,ILEV,DELALP) 
      ENDIF 
C 
      DO 295 L=1,ILEV 
      P(2,L) = P2(L)
  295 CONTINUE
C-----------------------------------------------------------------------
C     * PART 2 - THE FOURIER TRANSFORMS FROM FOURIER TO GRID. 
C 
C     * ALL THE FFT ARE DONE AT ONCE IF LVECT IS .TRUE. 
C     * THIS PRESUMES THAT ALL GRID SLICES ARE LINED UP 
C     * IN MEMORY, AND THAT  PRESSG  IS THE FIRST OF THE
C     * SERIES. 
C     * NUMBER EQUALS  ILEV*4 (FOR Q,D,U,V) 
C                     +LEVT*1 (FOR T) 
C     *               +LEVS*1 (FOR ES)
C     *               +  1 *3 (FOR PS,PSDL,PSDP). 
C 
      IF(LVECT) THEN
      NUMBER = 4*ILEV+LEVT+LEVS+3 
      CALL FFGFW (PRESSF, ILG,PRESSF,ILH,IR,LON,WRKS,NUMBER,IFAX,TRIGS) 
C 
      ELSE
C 
      CALL FFGFW (    QF,ILG,    QF,ILH,IR,LON,WRKS,ILEV,IFAX,TRIGS)
      CALL FFGFW (    DF,ILG,    DF,ILH,IR,LON,WRKS,ILEV,IFAX,TRIGS)
      CALL FFGFW (    UF,ILG,    UF,ILH,IR,LON,WRKS,ILEV,IFAX,TRIGS)
      CALL FFGFW (    VF,ILG,    VF,ILH,IR,LON,WRKS,ILEV,IFAX,TRIGS)
      CALL FFGFW (PRESSF,ILG,PRESSF,ILH,IR,LON,WRKS,   1,IFAX,TRIGS)
      CALL FFGFW ( PSDLF,ILG, PSDLF,ILH,IR,LON,WRKS,   1,IFAX,TRIGS)
      CALL FFGFW ( PSDPF,ILG, PSDPF,ILH,IR,LON,WRKS,   1,IFAX,TRIGS)
      IF(LEVT.EQ.0) GO TO 300 
      CALL FFGFW (    TF,ILG,    TF,ILH,IR,LON,WRKS,LEVT,IFAX,TRIGS)
  300 IF(LEVS.EQ.0) GO TO 310 
      CALL FFGFW (   ESF,ILG,   ESF,ILH,IR,LON,WRKS,LEVS,IFAX,TRIGS)
      ENDIF 
  310 CONTINUE
C 
      RETURN
C-------------------------------------------------------------------
      END 
