CMAX: [Version 1.0 (6/22/93)]
CMAX: ----------------------------------------------------
CMAX: Transformation of IPLEV from iplev.f
CMAX: ----------------------------------------------------
      INTEGER FUNCTION iplev(pr)
C  FINDS CLOSEST MANDATORY PRESSURE LEVEL TO A GIVEN PRESSURE IN TERMS
C  OF ALOG(PRESSURE).
      REAL ALOGPR
      INTEGER HIGH
      INTEGER LOW
      INTEGER MID
C     REAL              PR
      COMMON / GRIDXX / IM, JNP, MLEV
      COMMON / PMH / PMAND (18)
!hpf$ distribute pmand(block)
      low = 1
      high = mlev
      mid = (low + high) / 2
C  CHECK WHETHER THE PRESSURE IS WITHIN THE RANGE OF THE ANALYSIS LEVELS
      IF (pr .LT. (pmand(low) - 0.001) .OR. pr .GT. 1050.0) THEN
        iplev = 999
      ELSE
        alogpr = alog(pr)
  100   CONTINUE
        IF (low .LE. high) THEN
          mid = (low + high) / 2
          IF (alogpr .LT. alog(pmand(mid))) THEN
            high = mid - 1
            GOTO 100
          ELSEIF (alogpr .GT. alog(pmand(mid))) THEN
            low = mid + 1
            GOTO 100
          ELSE
            iplev = mid
          ENDIF
        ELSE
          iplev = mid
          IF (mid .LT. mlev) THEN
            IF (abs(alog(pmand(mid + 1)) - alogpr) 
     &            .LT. abs(alog(pmand(mid)) - alogpr)) THEN
              iplev = mid + 1
            ENDIF
          ENDIF
        ENDIF
      ENDIF
      RETURN
      END
