CMAX: [Version 1.0 (6/22/93)]
CMAX: ----------------------------------------------------
CMAX: Transformation of ZTOT from ztot.f
CMAX: ----------------------------------------------------
c ztot: height (z) to virtual temperaure (t).  takes a 3d array of
c       heights and computes mean layer virtual temperatures
c       corresponding to the thicknesses between each pressure surface.
      SUBROUTINE ztot(z,tv,pmand,pmidm,im,jnp,mlev)
C PHYSICAL CONSTANTS
C -------------------
      COMMON / PHYSIC / BETA, CP, GRAV, OMEGA2, RADE, RGAS, ROCP, CPOG, 
     &GAMMA, ROCP1, GOCP
      REAL BETA, CP, GRAV, OMEGA2, RADE, RGAS, ROCP, CPOG, GAMMA, ROCP1,
     & GOCP
      REAL z (im, jnp, mlev), tv (im, jnp, mlev - 1)
      REAL PMAND (mlev), PMIDM (mlev - 1), PK, DEL, FACTOR
!hpf$ distribute pmand(block)
!hpf$ distribute pmidm(block)
!hpf$ distribute tv(block,block,block)
!hpf$ distribute z(block,block,block)
      REAL  DEL100(mlev)
!hpf$ distribute del100(block)
      REAL  PK100(mlev-1)
!hpf$ distribute pk100(block)
      REAL  FACTOR100(mlev-1)
!hpf$ distribute factor100(block)
      pk100 = pmidm ** rocp
      del100(2:) = pmand(2:) ** rocp - pmand(:mlev - 1) ** rocp
      factor100 = gocp * pk100 / del100(2:)
      DO lev = 1 , mlev - 1
        DO j = 1 , jnp
          DO i = 1 , im
            tv(i,j,lev) = (z(i,j,lev) - z(i,j,lev + 1)) * factor100(lev)
          ENDDO
        ENDDO
      ENDDO
      RETURN
      END
