      SUBROUTINE DZTOUV(D,Z,U,V,MEND1,IROMB,MWVD2,MUWVD2)
C
C  THIS ROUTINE PERFORMS CONVERSION OF TRUE SCALAR RELATIVE
C  VORTICITY (Z), DIVERGENCE (D) TO PSEUDO SCALAR U AND V
C  IN SPECTRAL SPACE.
C
C  CALL DZTOUV(D,Z,U,V,MEND1,IROMB,MWVD2,MUWVD2)
C
C  D      ..... DIVERGENCE
C  Z      ..... RELATIVE VORTICITY
C  U      ..... OUTPUT PSEUDO SCALAR ZONAL WIND (=UCOS(PHI))
C  V      ..... OUTPUT PSEUDO SCALAR MERID WIND (=VCOS(PHI))
C  MEND1  ..... ZONAL WAVENUMBER + 1
C  IROMB  ..... TRUNCATION INDICATOR (=1 RHOMBOIDAL, =0 TRIANGULAR)
C  MWVD2  ..... DIMENSION OF Z AND D
C  MUWVD2 ..... DIMENSION OF U AND V
C
C  HUA-LU PAN   27 FEBRUARY 1989
C   MODIFIED TO RUN ON THE CRAY
C
      DIMENSION U(MUWVD2), V(MUWVD2), Z(MWVD2), D(MWVD2)
      DATA ER /6.3712E6/
      EPS(N,M) = SQRT(FLOAT(N*N-M*M)/FLOAT(4*N*N-1))
      U(MUWVD2-1) = 0.
      U(MUWVD2  ) = 0.
      V(MUWVD2-1) = 0.
      V(MUWVD2  ) = 0.
C
C  HANDLE M = 0 SEPERATELY
C
      NM = 0
      NMU = 0
      MM = 1
      M = 0
      NEND1 = MEND1
      IF(IROMB.EQ.1) NEND1 = MM + MEND1 - 1
C
C  DO M = 0 AND N = 0 CASE
C
      D2 = 0.
      NN = 1
      NM = NM + 1
      NMU = NMU + 1
      NMT2 = NM * 2
      NMUT2 = NMU * 2
      N = NN - 1
      D1 = D2
      D2 = EPS(N+1,M)
      FAC1 = ER * D2 / FLOAT(N+1)
      U(NMUT2-1) =  Z(NMT2+1) * FAC1
      U(NMUT2  ) =  Z(NMT2+2) * FAC1
      V(NMUT2-1) = -D(NMT2+1) * FAC1
      V(NMUT2  ) = -D(NMT2+2) * FAC1
C
C  DO THE PARAMETERIZABLE PART
C
      DO 100 NN = MM+1, NEND1-1
      NM = NM + 1
      NMU = NMU + 1
      NMT2 = NM * 2
      NMUT2 = NMU * 2
      N = NN - 1
      D1 = D2
      D2 = EPS(N+1,M)
      FAC1 = ER * D2 / FLOAT(N+1)
      FAC2 = ER * D1 / FLOAT(N)
      U(NMUT2-1) =  Z(NMT2+1) * FAC1 - Z(NMT2-3) * FAC2
      U(NMUT2  ) =  Z(NMT2+2) * FAC1 - Z(NMT2-2) * FAC2
      V(NMUT2-1) = -D(NMT2+1) * FAC1 + D(NMT2-3) * FAC2
      V(NMUT2  ) = -D(NMT2+2) * FAC1 + D(NMT2-2) * FAC2
 100  CONTINUE
C
C  DO N = NEND1 - 1
C
      NN = NEND1
      IF(NN.GT.1) THEN
        NM = NM + 1
        NMU = NMU + 1
        NMT2 = NM * 2
        NMUT2 = NMU * 2
        N = NN - 1
        D1 = D2
        D2 = EPS(N+1,M)
        FAC1 = ER * D2 / FLOAT(N+1)
        FAC2 = ER * D1 / FLOAT(N)
        U(NMUT2-1) = -Z(NMT2-3) * FAC2
        U(NMUT2  ) = -Z(NMT2-2) * FAC2
        V(NMUT2-1) =  D(NMT2-3) * FAC2
        V(NMUT2  ) =  D(NMT2-2) * FAC2
C
C  DO N = NEND1
C
        NN = NEND1 + 1
        NM = NM + 1
        NMU = NMU + 1
        NMT2 = NM * 2
        NMUT2 = NMU * 2
        N = NN - 1
        D1 = D2
        D2 = EPS(N+1,M)
        FAC1 = ER * D2 / FLOAT(N+1)
        FAC2 = ER * D1 / FLOAT(N)
        U(NMUT2-1) = -Z(NMT2-3) * FAC2
        U(NMUT2  ) = -Z(NMT2-2) * FAC2
        V(NMUT2-1) =  D(NMT2-3) * FAC2
        V(NMUT2  ) =  D(NMT2-2) * FAC2
      ENDIF
      NM = NM - 1
C
C  REST OF ZONAL WAVENUMBERS
C
      IF(IROMB.EQ.0) THEN
C
C  DO TRIANGULAR OPTION
C
        DO 300 MM = 2, MEND1
        M = MM - 1
        NEND1 = MEND1
        IF(IROMB.EQ.1) NEND1 = MM + MEND1 - 1
        D2 = 0.
        if(mm.lt.mend1) then
C
C  DO NN = MM PART
C
          NN = MM
          NM = NM + 1
          NMU = NMU + 1
          NMT2 = NM * 2
          NMUT2 = NMU * 2
          N = NN - 1
          D1 = D2
          D2 = EPS(N+1,M)
          FAC1 = ER * D2 / FLOAT(N+1)
          FAC2 = ER * D1 / FLOAT(N)
          FAC3 = ER * FLOAT(M) / FLOAT(N * (N+1))
          IF(N.LT.NEND1-1) THEN
            U(NMUT2-1) =  Z(NMT2+1) * FAC1 + D(NMT2  ) * FAC3
            U(NMUT2  ) =  Z(NMT2+2) * FAC1 - D(NMT2-1) * FAC3
            V(NMUT2-1) = -D(NMT2+1) * FAC1 + Z(NMT2  ) * FAC3
            V(NMUT2  ) = -D(NMT2+2) * FAC1 - Z(NMT2-1) * FAC3
          ELSE
            U(NMUT2-1) =  D(NMT2  ) * FAC3
            U(NMUT2  ) = -D(NMT2-1) * FAC3
            V(NMUT2-1) =  Z(NMT2  ) * FAC3
            V(NMUT2  ) = -Z(NMT2-1) * FAC3
          ENDIF
          if(mm.lt.nend1-1) then
            DO 200 NN = MM + 1, NEND1-1
            NM = NM + 1
            NMU = NMU + 1
            NMT2 = NM * 2
            NMUT2 = NMU * 2
            N = NN - 1
            D1 = D2
            D2 = EPS(N+1,M)
            FAC1 = ER * D2 / FLOAT(N+1)
            FAC2 = ER * D1 / FLOAT(N)
            FAC3 = ER * FLOAT(M) / FLOAT(N * (N+1))
            U(NMUT2-1) =  Z(NMT2+1) * FAC1 - Z(NMT2-3) * FAC2
     &                  + D(NMT2  ) * FAC3
            U(NMUT2  ) =  Z(NMT2+2) * FAC1 - Z(NMT2-2) * FAC2
     &                  - D(NMT2-1) * FAC3
            V(NMUT2-1) = -D(NMT2+1) * FAC1 + D(NMT2-3) * FAC2
     &                  + Z(NMT2  ) * FAC3
            V(NMUT2  ) = -D(NMT2+2) * FAC1 + D(NMT2-2) * FAC2
     &                  - Z(NMT2-1) * FAC3
 200        CONTINUE
          endif
        endif
C
C  DO N = NEND1 - 1 PART
C
        NN = NEND1
        NM = NM + 1
        NMU = NMU + 1
        NMT2 = NM * 2
        NMUT2 = NMU * 2
        N = NN - 1
        D1 = D2
        D2 = EPS(N+1,M)
        FAC1 = ER * D2 / FLOAT(N+1)
        FAC2 = ER * D1 / FLOAT(N)
        FAC3 = ER * FLOAT(M) / FLOAT(N * (N+1))
        U(NMUT2-1) = -Z(NMT2-3) * FAC2 + D(NMT2  ) * FAC3
        U(NMUT2  ) = -Z(NMT2-2) * FAC2 - D(NMT2-1) * FAC3
        V(NMUT2-1) =  D(NMT2-3) * FAC2 + Z(NMT2  ) * FAC3
        V(NMUT2  ) =  D(NMT2-2) * FAC2 - Z(NMT2-1) * FAC3
C
C  DO N = NEND1  PART
C
        NN = NEND1 + 1
        NM = NM + 1
        NMU = NMU + 1
        NMT2 = NM * 2
        NMUT2 = NMU * 2
        N = NN - 1
        FAC3 = ER * FLOAT(M) / FLOAT(N * (N+1))
        U(NMUT2-1) = -Z(NMT2-3) * FAC2
        U(NMUT2  ) = -Z(NMT2-2) * FAC2
        V(NMUT2-1) =  D(NMT2-3) * FAC2
        V(NMUT2  ) =  D(NMT2-2) * FAC2
        NM = NM - 1
 300    CONTINUE
C
C  DO THE RHOMBOIDAL OPTION
C
      ELSE
      DO 500 MM = 2, MEND1
      M = MM - 1
      NEND1 = MEND1
      IF(IROMB.EQ.1) NEND1 = MM + MEND1 - 1
      D2 = 0.
C
C  DO NN = MM PART
C
      NN = MM
      NM = NM + 1
      NMU = NMU + 1
      NMT2 = NM * 2
      NMUT2 = NMU * 2
      N = NN - 1
      D1 = D2
      D2 = EPS(N+1,M)
      FAC1 = ER * D2 / FLOAT(N+1)
      FAC2 = ER * D1 / FLOAT(N)
      FAC3 = ER * FLOAT(M) / FLOAT(N * (N+1))
      U(NMUT2-1) =  Z(NMT2+1) * FAC1 + D(NMT2  ) * FAC3
      U(NMUT2  ) =  Z(NMT2+2) * FAC1 - D(NMT2-1) * FAC3
      V(NMUT2-1) = -D(NMT2+1) * FAC1 + Z(NMT2  ) * FAC3
      V(NMUT2  ) = -D(NMT2+2) * FAC1 - Z(NMT2-1) * FAC3
      DO 400 NN = MM + 1, NEND1-1
      NM = NM + 1
      NMU = NMU + 1
      NMT2 = NM * 2
      NMUT2 = NMU * 2
      N = NN - 1
      D1 = D2
      D2 = EPS(N+1,M)
      FAC1 = ER * D2 / FLOAT(N+1)
      FAC2 = ER * D1 / FLOAT(N)
      FAC3 = ER * FLOAT(M) / FLOAT(N * (N+1))
      U(NMUT2-1) =  Z(NMT2+1) * FAC1 - Z(NMT2-3) * FAC2
     &            + D(NMT2  ) * FAC3
      U(NMUT2  ) =  Z(NMT2+2) * FAC1 - Z(NMT2-2) * FAC2
     &            - D(NMT2-1) * FAC3
      V(NMUT2-1) = -D(NMT2+1) * FAC1 + D(NMT2-3) * FAC2
     &            + Z(NMT2  ) * FAC3
      V(NMUT2  ) = -D(NMT2+2) * FAC1 + D(NMT2-2) * FAC2
     &            - Z(NMT2-1) * FAC3
 400  CONTINUE
C
C  DO N = NEND1 - 1 PART
C
      NN = NEND1
      NM = NM + 1
      NMU = NMU + 1
      NMT2 = NM * 2
      NMUT2 = NMU * 2
      N = NN - 1
      D1 = D2
      D2 = EPS(N+1,M)
      FAC2 = ER * D1 / FLOAT(N)
      FAC3 = ER * FLOAT(M) / FLOAT(N * (N+1))
        U(NMUT2-1) = -Z(NMT2-3) * FAC2 + D(NMT2  ) * FAC3
        U(NMUT2  ) = -Z(NMT2-2) * FAC2 - D(NMT2-1) * FAC3
        V(NMUT2-1) =  D(NMT2-3) * FAC2 + Z(NMT2  ) * FAC3
        V(NMUT2  ) =  D(NMT2-2) * FAC2 - Z(NMT2-1) * FAC3
C
C  DO N = NEND1  PART
C
      NN = NEND1 + 1
      NM = NM + 1
      NMU = NMU + 1
      NMT2 = NM * 2
      NMUT2 = NMU * 2
      N = NN - 1
      D1 = D2
      D2 = EPS(N+1,M)
      FAC2 = ER * D1 / FLOAT(N)
      U(NMUT2-1) = -Z(NMT2-3) * FAC2
      U(NMUT2  ) = -Z(NMT2-2) * FAC2
      V(NMUT2-1) =  D(NMT2-3) * FAC2
      V(NMUT2  ) =  D(NMT2-2) * FAC2
      NM = NM - 1
 500  CONTINUE
      ENDIF
      RETURN
      END
