CMAX: [Version 1.0 (6/22/93)]
CMAX: ----------------------------------------------------
CMAX: Transformation of PREFAC from prefac.f
CMAX: ----------------------------------------------------
      SUBROUTINE prefac(l,px,ns,lqu,pwt)
C  SETS INTERPOLATION FACTORS FOR LINEAR-IN-LOG(PRESSURE) VERTICAL
C  INTERPOLATION BY ROUTINE TERPV3
      REAL ALOG1100
      PARAMETER (ALOG1100 = 7.0036953)
      REAL ALOGPX
      REAL APDAPD
      REAL APDAPU
      INTEGER II
      INTEGER L
      REAL LQU (NS)
      INTEGER NS
      DIMENSION PWT (NS)
      DIMENSION PX (NS)
      REAL RCDAPD
      REAL RCDAPU
      COMMON / GRIDXX / IM, JNP, MLEV
      COMMON / PMH / PMAND (18)
!hpf$ distribute lqu(block)
!hpf$ distribute pmand(block)
!hpf$ distribute pwt(block)
!hpf$ distribute px(block)
      LOGICAL lif(ns)
!hpf$ distribute lif(block)
      REAL  ALOGPX101(ns)
!hpf$ distribute ALOGPX101(block)
      REAL  ALOGPX10 (ns)
!hpf$ distribute ALOGPX10 (block)
      IF (l .EQ. mlev) THEN
        rcdapd = 1.0 / (alog1100 - alog(pmand(mlev)))
        apdapd = rcdapd * alog1100
      ELSE
        rcdapd = 1.0 / (alog(pmand(l + 1)) - alog(pmand(l)))
        apdapd = rcdapd * alog(pmand(l + 1))
      ENDIF
      rcdapu = 1.0 / (alog(pmand(l)) - alog(pmand(l - 1)))
      apdapu = rcdapu * alog(pmand(l - 1))
      FORALL (ii = 1:ns) alogpx10 (ii) = px(ii)
      alogpx101(1:ns) = alog(alogpx10 (1:ns))
      FORALL (ii = 1:ns, alogpx101(ii) .LT. alog(pmand(l))) pwt(ii) = 
     &    alogpx101(ii) * rcdapu - apdapu
      DO ii = 1 , ns
        lif(ii) = alogpx101(ii) .LT. alog(pmand(l))
        IF (alogpx101(ii) .LT. alog(pmand(l))) THEN
          lqu(ii) = l - 1
        ENDIF
      ENDDO
      FORALL (ii = 1:ns, .NOT.lif(ii)) pwt(ii) = -alogpx101(ii) * rcdapd
     &    +apdapd
      DO ii = 1 , ns
        IF (.NOT.lif(ii)) THEN
          lqu(ii) = l
        ENDIF
      ENDDO
      RETURN
      END
