      SUBROUTINE NMC2RT (NFIRST,SLAT, SLON, NMCFIL, HI8NMC)
      IMPLICIT NONE
C
C********************************************************************
C
C   NAME- NMC2RT
C
C   LANGUAGE- FORTRAN 77     TYPE- SUBROUTINE      COMPUTER- CRAY
C
C   VERSION- 1.0    DATE- 01/19/95   PROGRAMMER- LEAH CASEY (HUGHES STX)
C   VERSION- 2.0    DATE- 07/18/95   PROGRAMMER- ALEX POZDNYAK (SMSRC)
C   VERSION- 3.0    DATE- 05/14/96   PROGRAMMER- ALEX POZDNYAK, FDC
C           FOR REHOSTING TO THE CRAY, CHANGED ALL I*4 DECLARATIONS TO
C           INTEGER AND ALL R*4 DECLARATIONS TO REAL.
C   VERSION- 3.1    DATE- 05/18/98   PROGRAMMER- BRIAN BARIL (RSTX)
C                   REPLACED RLAT2J WITH SLAT2J AND RLON2I WITH SLNG2I
C   VERSION- 3.2    DATE- 07/15/98   PROGRAMMER- BRIAN BARIL  (RSTX)
C                   RESTRUCTURED TO IMPROVE EXECUTION TIME.
C     
C   FUNCTION- THIS ROUTINE INTERPOLATES NMC GEOPOTENTIAL HEIGHTS TO THE
C             RETRIEVAL LOCATION.
C
C
C   CALLING SEQUENCE PARAMETERS-
C     VARIABLE      TYPE    I/O   DESCRIPTION
C     --------      ----    ---   -----------
C     SLAT          REAL     I    RETRIEVAL LATITUDE.
C     SLON          REAL     I    RETRIEVAL LONGITUDE.
C     GLOBEG        INT      I    ARRAY (DIM 5 X 4 X 2 X 145 X 37) OF
C                                 GLOBAL GRIDDED NMC GEOPOTENTIAL
C                                 HEIGHTS.
C     NMCFIL        INT      I    FLAG DENOTING WHICH FORECAST FILE IS
C                                 CHOSEN.
C     HI8NMC        REAL     O    ARRAY (DIM 4) OF NMC GEOPOTENTIAL
C                                 HEIGHTS INTERPOLATED TO THE RETRIEVAL
C                                 LOCATION.
C
C
C   COMMON AREA PARAMETERS- NONE
C
C
C   LOCAL PARAMETERS-
C     VARIABLE      TYPE      DESCRIPTION
C     --------      ----      -----------
C     FIELD         REAL      VALUE RETURNED BY CALLS TO BILINR.
C     GBUFFR        REAL      DUMMY HOLDING ARRAY, DIM 145 X 37.
C     GLAT          REAL      GRID EQUIVALENT OF RETRIEVAL LATITUDE.
C     GLONG         REAL      GRID EQUIVALENT OF RETRIEVAL LONGITUDE.
C     IMAP          INT       2=SOUTHERN HEMISPHERE, 1=NORTHERN.
C     I, J, K       INT       DO LOOP VARIABLES.
C
C   SUBROUTINES USED- BILINR
C
C   FUNCTIONS USED- SLNG2I, SLAT2J
C
C   EXIT STATES- NONE
C
C********************************************************************
C
      INCLUDE 'STBCOM'

      REAL    SLAT, SLON,  HI8NMC(4)
      INTEGER NMCFIL
C
      REAL    GBUFF1(145,37),GBUFF2(145,37),GBUFF3(145,37)
      REAL    GBUFF4(145,37),GBUFF5(145,37),GBUFF6(145,37)
      REAL    GBUFF7(145,37),GBUFF8(145,37)
      REAL    GLONG, GLAT
      REAL    SLNG2I, SLAT2J, FIELD
      INTEGER IMAP, I, J, K, FFCHCK
      LOGICAL NFIRST
      DATA FFCHCK/0/

      SAVE GBUFF1,GBUFF2,GBUFF3,GBUFF4,GBUFF5,GBUFF6,GBUFF7,GBUFF8
      SAVE FFCHCK
C
C     DETERMINE HEMISPHERE OF RETRIEVAL LOCATION.
C
      IF(SLAT .LT. 0.0) THEN
         IMAP = 2
      ELSE
         IMAP = 1
      ENDIF
C
C     CONVERT RETRIEVAL LOCATION FROM LATITUDE,LONGITUDE CONVENTION
C     TO NMC GRID POINT VALUES.
C
      GLONG = SLNG2I(SLON)
      GLAT = SLAT2J(SLAT)
C
C     IF THIS IS THE FIRST CALL OR THE FORCAST FILE HAS CHANGED, FILL
C     THE GRID BUFFER ARRAYS FOR EACH PRESSURE LEVEL AND HEMISPHERE
C
 
      IF (NFIRST.OR.FFCHCK.NE.NMCFIL) THEN
         DO J = 1, 145
            DO K = 1, 37
               GBUFF1(J,K) = GLOBEG(NMCFIL,1,1,J,K)
               GBUFF2(J,K) = GLOBEG(NMCFIL,2,1,J,K)
               GBUFF3(J,K) = GLOBEG(NMCFIL,3,1,J,K)
               GBUFF4(J,K) = GLOBEG(NMCFIL,4,1,J,K)
               GBUFF5(J,K) = GLOBEG(NMCFIL,1,2,J,K)
               GBUFF6(J,K) = GLOBEG(NMCFIL,2,2,J,K)
               GBUFF7(J,K) = GLOBEG(NMCFIL,3,2,J,K)
               GBUFF8(J,K) = GLOBEG(NMCFIL,4,2,J,K)
            ENDDO
         ENDDO
         FFCHCK = NMCFIL
         NFIRST = .FALSE.
      ENDIF
C
C     CHECK FOR GRID VALUES ON THE EDGE.  ADJUST THE VALUE FOR THESE
C     CASES SINCE NMC DOES NOT CORRECT FOR THIS IN THEIR INTERPOLATION.
C
         IF(GLONG.GE.145.0) GLONG = 144.9
         IF(GLONG.LE.1.0) GLONG = 1.0009
         IF(GLAT.GE.37) GLAT = 36.9
         IF(GLAT.LE.1.0) GLAT = 1.0009
C
C     INTERPOLATE NMC HEIGHTS TO TOVS LEVELS
C

      IF(IMAP.EQ.1) THEN  
         CALL BILINR(GBUFF1, 145, 37, GLONG, GLAT, FIELD)
         HI8NMC(1) = FIELD
         CALL BILINR(GBUFF2, 145, 37, GLONG, GLAT, FIELD)
         HI8NMC(2) = FIELD
         CALL BILINR(GBUFF3, 145, 37, GLONG, GLAT, FIELD)
         HI8NMC(3) = FIELD
         CALL BILINR(GBUFF4, 145, 37, GLONG, GLAT, FIELD)
         HI8NMC(4) = FIELD
       ELSE
         CALL BILINR(GBUFF5, 145, 37, GLONG, GLAT, FIELD)
         HI8NMC(1) = FIELD
         CALL BILINR(GBUFF6, 145, 37, GLONG, GLAT, FIELD)
         HI8NMC(2) = FIELD
         CALL BILINR(GBUFF7, 145, 37, GLONG, GLAT, FIELD)
         HI8NMC(3) = FIELD
         CALL BILINR(GBUFF8, 145, 37, GLONG, GLAT, FIELD)
         HI8NMC(4) = FIELD
       ENDIF

C
C
C      RETURN TO CALLING PROGRAM
C
      RETURN
      END
