C********************************************************************
C   CHANGES 90/03/12
C               DECYBERIZED VERSION (FROM O89)
C********************************************************************
C**********************************************************************
C  Data parallel implementation (CM Fortran) : M. Makivic (NPAC)      *
C  Date:       4/94                                                   *
C**********************************************************************


      SUBROUTINE tdrybulb(tv,rmix,tdry,pmand,pmidm,nlevoi)
      include 'processors.h'
C ANALYSIS CONTROL VARIABLES
C --------------------------
      LOGICAL STRAT, SLP, FDCOS, FEXP, SAVEAE, SIGDAT
      integer nlevoi
      COMMON / CONTRL / IM, JNP, NB, NDALT, NHMS, NLAY, NLAYM1, NLAYP1, 
     &NYMD, STRAT, IDIMEN, SLP, FDCOS, FEXP, SAVEAE, SIGDAT, MAXREP
C VERTICAL INDEX COMMON
C ----------------------
      COMMON / MLAY / MLEV, MLEVM1, MMIX, MMIXM1, LS, LSM1
C PRODUCTS OF GRID LIMITS
C -----------------------
      COMMON / PRODLIM / IJMLEV, IJMLEVM1, ILBELOW, IMJNP, IMLSM1, IMMLE
     &V, IMMLEVM1, IMMLEVP1, IMNLAY, IMNLAYP1
C SUBROUTINE ARGUMENTS AND LOCAL VARIABLES
C ----------------------------------------
      DIMENSION pmidm(nlevoi-1),pmand(nlevoi),
     &    tdry(im,jnp,mlev),rmix(im,jnp,mlev),tv(im,jnp,mlev)
      REAL fill
      DATA fill / 1.e10 /

!hpf$ distribute tdry(*,block,*) onto PROC_ARRAY_1D
!hpf$ distribute tv(*,block,*) onto PROC_ARRAY_1D
!hpf$ distribute rmix(*,block,*) onto PROC_ARRAY_1D
      real shmand(im,jnp)
!hpf$ align shmand(i,k) with rmix(i,k,1)

C INTERPOLATE MID MANDATORY VIRTUAL TEMPERATURES TO MANDATORY LEVELS
C ------------------------------------------------------------------
      DO mandlev = 1 , mlev
        IF (mandlev .EQ. 1) THEN
          midmlevb = 2
        ELSEIF (mandlev .EQ. mlev) THEN
          midmlevb = mlevm1
        ELSE
          midmlevb = mandlev
        ENDIF
        midmleva = midmlevb - 1
        factora = alog(pmidm(midmlevb) / pmand(mandlev)) / 
     &      alog(pmidm(midmlevb) / pmidm(midmleva))
        factorb = 1.0 - factora
        tdry(:,:,mandlev) = factora
     &          * tv(:,:,midmleva) + factorb * tv(:,:,midmlevb)
     
      ENDDO
C CONVERT VIRTUAL TEMPS ON MANDATORY LEVELS TO DRY BULB TEMPS
C -----------------------------------------------------------
      DO 400 mandlev = 1 , mlev
C OBTAIN SPECIFIC HUMIDITIES FROM MIXING RATIOS (KEEP BETWEEN 0 AND 1)
C --------------------------------------------------------------------
            shmand=0.0
C CONVERT VIRTUAL TEMPERATURES TO DRY BULB TEMPERATURES
C -----------------------------------------------------
            WHERE (rmix(:,:,mandlev) .NE. fill) 
              shmand = rmix(:,:,mandlev) / 1000.0
              shmand = shmand / (1.0 + shmand)
              shmand=amax1(amin1(shmand,1.0),0.0)
              tdry(:,:,mandlev) =tdry(:,:,mandlev)/(1.0+0.61*shmand)
            ENDWHERE
400   CONTINUE
      RETURN
      END
