CMAX: [Version 1.0 (6/22/93)]
CMAX: ----------------------------------------------------
CMAX: Transformation of TERP from terp.f
CMAX: ----------------------------------------------------
      SUBROUTINE terp(im,jm,lat,lon,f,fint)
c     Program Name: TERP
c     Date:         August 29, 1990
c     Language:     Fortran 77
c     Computer:     Cray YMP
c
c     TERP interpolates horizontally from earth coordinates (gridded).
c     Input values "lat" and "lon" are the latitude and longitude of
c     a point, "f" is the field to be interpolated. The output value,
c     "fint", contains the value at the point.
      REAL lat, lon, f (im, jm), fint, yx (2)
!hpf$ distribute f(block,block)
!hpf$ distribute yx(block)
      yx(1) = (lat + 90.) / (180. / (float(jm - 1))) + 1.
      yx(2) = (180. + lon) / (360. / (float(im))) + 1.
      IF (yx(2) .GE. (im + 1)) THEN
        yx(2) = yx(2) - im
      ENDIF
      j0 = yx(1)
c   Protect j1 from being equal to jm+1, which can occur at the north po
      IF (j0 .LT. jm) THEN
        j1 = j0 + 1
      ELSE
        j1 = j0
      ENDIF
      wt_j1 = yx(1) - j0
      wt_j0 = 1. - wt_j1
      i0 = yx(2)
      i1 = i0 + 1
      wt_i1 = yx(2) - i0
      wt_i0 = 1 - wt_i1
      IF (i1 .GT. im) THEN
        i1 = i1 - im
      ENDIF
      fint = wt_j1 * wt_i1 * f(i1,j1) + wt_j1 * wt_i0 * f(i0,j1) + wt_j0
     &    *wt_i1 * f(i1,j0) + wt_j0 * wt_i0 * f(i0,j0)
      RETURN
      END
