      SUBROUTINE MAPDVR(UNITNM,DELTIME,FCSTYM,ERROR)
      implicit none
C**********************************************************************
C
C   NAME- MAPDVR
C
C   LANGUAGE- FORTRAN 77     TYPE- SUBROUTINE     COMPUTER- CRAY    
C
C   VERSION- 1.0    DATE- 09/13/91   PROGRAMMER- JEFFREY JONES, 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, ALL L*4 TO LOGICAL, AND ALL R*4 DECLARATIONS TO REAL.
C   VERSION- 3.1    DATE- 10/07/97   PROGRAMMER- LEAH WILSON, HSTX   
C   VERSION- 3.2    DATE- 11/03/98   PROGRAMMER- BRIAN BARIL, RAYTHEON
C   VERSION- 3.3    DATE- 02/05/99   PROGRAMMER- LEAH WILSON, RAYTHEON
C   VERSION- 3.4    DATE- 06/26/02   PROGRAMMER- A. ALLEGRINO, RAYTHEON
C   VERSION- 3.5    DATE- 12/28/06   PROGRAMMER- FRANK TILLEY, IMSG
C
C   FUNCTION- THIS ROUTINE ACTS AS THE INTERFACE BETWEEN THE
C             SOUNDINGS PRODUCT GENERATION SUBSYSTEM AND THE MAP
C             MANAGER.   IT TAKES AS INPUT, A SATELLITE'S INSTRUMENT
C             CONFIGURATION FROM THE COMMON BLOCK ERINFO AND FILLS EACH
C             INSTRUMENT'S ANCILLARY DATA BUFFER FIELDS IN THE COMMON
C             BLOCK INSCOM WITH VALUES RETRIEVED BY THE MAP MANAGER.
C
C   VERSION- 3.1 RTOVS UPGRADE TO GET POTENTIAL TEMPERATURE TIME MINUS
C                NCEP FORECAST TIME FROM POTTEM, AND TO GET FORECAST
C                TIME.
C   VERSION- 3.2 REMOVED REFERENCE TO OLD FAU'S ("MAPPARM", FILEWS).
C                CHANGED CALLS TO POTTEM AND MAPRET TO HANDLE THE 
C                8-BYTE CDB FILE UTILITIES.
C   VERSION- 3.3 REMOVE ALL REFERENCES TO AMSU-B.
C   VERSION- 3.4 ADDED CAPTURE OF SEA SURFACE TEMPERATURE AT THE AMSU FOV
C                AND STORED IT IN ELEMENT 15 OF AMAANC. (WR#197)
C   VERSION- 3.5 ADDED CAPTURE OF TERRAIN TYPE AND TERRAIN HEIGHT FOR
C                MHS.
C
C   CALLING SEQUENCE PARAMETERS-
C
C      VARIABLE                TYPE I/O FUNCTION
C      --------                ---- --- --------
C      UNITNM                  INT  I/O THIS IS THE MAPPARM UNIT NUMBER
C
C      DELTIME                 REAL  O  POTENTIAL TEMPERATURE TIME MINUS
C                                       NCEP FORECAST TIME.
C
C      FCSTYM                  INT   O  FORECAST TIME AS YYMM,DDHH.
C
C      ERROR                   INT   O  THE ERROR RETURN CODE.
C                                            0 - SUCCESSFUL COMPLETION.
C                                           10 - A NON-FATAL ERROR
C                                                OCCURRED.
C                                           77 - NO FORECAST MAP
C                                                FOUND.
C                                           99 - A FATAL ERROR OCCURRED.
C
C   COMMON AREAS PARAMETERS-
C
       INCLUDE 'ERPARM'
       INCLUDE 'ERINFO'
       INCLUDE 'INPARM'
       INCLUDE 'INSPARM'
       INCLUDE 'INSCOM'
       INCLUDE 'FRMINF'
C
C   LOCAL PARAMETERS-
C
C      VARIABLE   TYPE   FUNCTION
C      --------   ----   --------
C      COAST      REAL   A CONSTANT PARAMETER HOLDING THE SURFACE TYPE
C                        FOR AN AREA WITH COASTAL FEATURES.
C
C      HIRFLG     LOG    HOLDS TRUE IF HIRS INSTRUMENT IS ON.
C
C      HIRMAX     INT    HOLDS THE HIGHEST INDEX OF THE HIRS INSTRUMENT
C                        IN THE LATS, LONGS, VALUES ARRAYS.
C
C      HIRMIN     INT    HOLDS THE LOWEST INDEX OF THE HIRS INSTRUMENT
C                        IN THE LATS, LONGS, VALUES ARRAYS.
C
C      AMAFLG     LOG    HOLDS TRUE IF AMSU-A INSTRUMENT IS ON.
C
C      AMAMAX     INT    HOLDS THE HIGHEST INDEX OF THE AMSU-A
C                        INSTRUMENT IN THE LATS, LONGS, VALUES ARRAYS.
C
C      AMAMIN     INT    HOLDS THE LOWEST INDEX OF THE AMSU-A INSTRUMENT
C                        IN THE LATS, LONGS, VALUES ARRAYS.
C
C      I          INT    INDEX FOR DO LOOPS.
C
C      INDEX      INT    THE INDEX FOR THE LOCATIONS.
C
C      LAND       REAL   A CONSTANT PARAMETER HOLDING THE SURFACE TYPE
C                        FOR AN AREA WITH LAND FEATURES.
C
C      LATS       REAL   ARRAY HOLDING ALL NEEDED LATITUDES IN DEGREES.
C                        DIMENSION ((HTOTLN*HNSPOT)+(ATOTLN*ANSPOT)+
C                        (BTOTLN*BNSPOT)).
C
C      LINNUM     INT    HOLDS THE CURRENT LINE NUMBER.
C
C      LONGS      REAL   ARRAY HOLDING ALL NEEDED LONGITUDES IN DEGREES.
C                        DIMENSION ((HTOTLN*HNSPOT)+(ATOTLN*ANSPOT)+
C                        (BTOTLN*BNSPOT)).
C
C      PTINDX     INT    INDEX INTO THE ARRAYS OF POTENTIAL TEMPERATURE,
C                        SURFACE PRESSURE, RELATIVE HUMIDITY AND
C                        FORECAST SURFACE TEMPERATURE MAP NAMES.
C
C      PTSTAT     INT    STATUS FROM CALL TO POTTEM.
C
C      PTMAP     CH*8    ARRAY OF 4 POTENTIAL TEMPERATURE MAP NAMES.
C
C      SPMAP     CH*8    ARRAY OF 4 SURFACE PRESSURE MAP NAMES.
C
C      RHMAP     CH*8    ARRAY OF 4 RELATIVE HUMIDITY MAP NAMES.
C
C      FSMAP     CH*8    ARRAY OF 4 FORECAST SURFACE TEMPERATURE MAP
C                        NAMES.
C
C      SEAICE     REAL   A CONSTANT PARAMETER HOLDING THE SURFACE TYPE
C                        FOR AN AREA WITH SEA ICE/SNOW FEATURES.
C
C      LANICE     REAL   A CONSTANT PARAMETER HOLDING THE SURFACE TYPE
C                        FOR AN AREA WITH LAND ICE/SNOW FEATURES.
C
C      SPTNUM     INT    HOLDS THE CURRENT SPOT NUMBER.
C
C      TYPE       REAL   ARRAY HOLDING SURFACE TYPE VALUES.
C                        DIMENSION ((HTOTLN*HNSPOT)+(ATOTLN*ANSPOT)+
C                        (BTOTLN*BNSPOT)).
C
C      VALUE      REAL   ARRAY HOLDING VALUES OF REQUESTED PARAMETER.
C                        DIMENSION ((HTOTLN*HNSPOT)+(ATOTLN*ANSPOT)+
C                        (BTOTLN*BNSPOT)).
C
C      WATER      REAL   CONSTANT PARAMETER HOLDING THE SURFACE TYPE FOR
C                        AN AREA WITH WATER FEATURES.
C
C   SUBPROGRAMS CALLED- MAPRET, POTTEM
C
C   FUNCTIONS USED-  BTEST, MAX
C
      INTRINSIC BTEST, MAX
C
C   EXIT STATES-
C         0 - NORMAL COMPLETION.
C        10 - A NON-FATAL ERROR OCCURRED.
C        77 - NO POTENTIAL TEMPERATURE FORECAST RETRIEVED.
C        99 - A FATAL ERROR OCCURRED.
C
C   COMMENTS-
C      1.  THIS ROUTINE ASSUMES ALL VARIABLES ASSOCIATED WITH THE
C          SATELLITE'S INSTRUMENTS HAVE BEEN SET CORRECTLY.
C
C      2.  IF NO POTENTIAL TEMPERATURE FORECAST MAP CAN BE FOUND
C          FOR THE DATA FRAME DATE AND TIME, ERROR CODE 77 IS RETURNED
C          TO SPGDVR TO INDICATE THAT THERE IS NOTHING TO RETRIEVE AND
C          WRITE TO THE OPERATIONAL DATA BASE FOR EITHER FORECAST
C          POTENTIAL TEMPERATURE FORECAST OR FORECAST SURFACE PRESSURE.
C
C**********************************************************************
C
      INTEGER     ERROR, FCSTYM(2),UNITNM
C
      CHARACTER*8 PTMAP(4), SPMAP(4), RHMAP(4), FSMAP(4)
      REAL       LATS((HTOTLN*HNSPOT)+(ATOTLN*ANSPOT)+(BTOTLN*BNSPOT))
      REAL       LONGS((HTOTLN*HNSPOT)+(ATOTLN*ANSPOT)+(BTOTLN*BNSPOT))
      REAL       VALUE((HTOTLN*HNSPOT)+(ATOTLN*ANSPOT)+(BTOTLN*BNSPOT))
      REAL       TYPE((HTOTLN*HNSPOT)+(ATOTLN*ANSPOT)+(BTOTLN*BNSPOT))
      REAL       COAST, LAND, SEAICE, WATER, LANICE, DELTIME
      INTEGER    INDEX, LINNUM, SPTNUM, I
      INTEGER    HIRMIN, HIRMAX, PTINDX
      INTEGER    AMAMIN, AMAMAX, AMBMIN, AMBMAX
      INTEGER    PTSTAT, IDUM
      LOGICAL    HIRFLG, AMAFLG, AMBFLG
C
C   DEFINE SURFACE TYPE PARAMETERS.
C
      PARAMETER (WATER=0.0,LAND=1.0,COAST=2.0,SEAICE=10.0,LANICE=11.0)
C
      INCLUDE 'SPVAL'
C
C*********************************************************************
C
C   INITIALIZE VARIABLES.
C
C*********************************************************************
C
      DATA PTMAP /'POTEMP00','POTEMP06','POTEMP12','POTEMP18'/
      DATA SPMAP /'SFCPRS00','SFCPRS06','SFCPRS12','SFCPRS18'/
      DATA RHMAP /'RELHUM00','RELHUM06','RELHUM12','RELHUM18'/
      DATA FSMAP /'SFTEMP00','SFTEMP06','SFTEMP12','SFTEMP18'/
C
      ERROR = 0
      LINNUM = 0
      SPTNUM = 0
      INDEX = 0
      I = 0
ccft  HIRMIN = 0
      HIRMIN = 1
      HIRMAX = 0
      HIRFLG = .FALSE.
      AMAMIN = 0
      AMAMAX = 0
      AMAFLG = .FALSE.
      AMBMIN = 0
      AMBMAX = 0
      PTINDX = 0
      PTSTAT = 0

C
      IDUM = (HTOTLN*HNSPOT)+(ATOTLN*ANSPOT)+(BTOTLN*BNSPOT)
      DO 10, I = 1,IDUM
          VALUE(I) = R4SPV
          TYPE(I) = R4SPV
   10 CONTINUE
C
C********************************************************************
C
C   DETERMINE IF THE HIRS AND AMSU-A INSTRUMENTS ARE ON AND
C   LOAD THE LATITUDES AND LONGITUDES INTO TEMPORARY STORAGE.
C
C********************************************************************
C
      IF (BTEST(FRMCNF,31)) THEN
C
C       HIRS INSTRUMENT ON.
C
          HIRFLG = .TRUE.
C
C       GET HIRS LATITUDES, LONGITUDES FROM ANCILLARY DATA BUFFERS.
C
          DO 30,LINNUM = 1, HTOTLN
C
C           CHECK SCAN LINE TO SEE IF DUMMY.
C
              IF (HGOODL(LINNUM)) THEN
C
C               SCAN LINE IS NOT A DUMMY, GET EACH SPOT'S INFO.
C
                  DO 20, SPTNUM = 1,HNSPOT
C
                      INDEX = INDEX + 1
                      LATS(INDEX) = HIRANC(SPTNUM, LINNUM, 1)
                      LONGS(INDEX) = HIRANC(SPTNUM, LINNUM, 2)
C
   20             CONTINUE
C
              END IF
C
   30     CONTINUE
C
          HIRMIN = 1
          HIRMAX = INDEX
C
      END IF
C
      IF (BTEST(FRMCNF,30)) THEN
C
C       AMSU-A INSTRUMENT ON.
C
          AMAFLG = .TRUE.
C
C       GET AMSU-A LATITUDES AND LONGITUDES FROM ANCILLARY DATA BUFFERS.
C
          AMAMIN = HIRMAX + 1
C
          DO 50,LINNUM = 1, ATOTLN
C
C           SEE IF SCAN LINE IS GOOD.
C
              IF (AGOODL(LINNUM)) THEN
C
C               SCAN LINE IS NOT A DUMMY, GET EACH SPOT'S INFO.
C
                  DO 40, SPTNUM = 1,ANSPOT
C
                      INDEX = INDEX + 1
                      LATS(INDEX) = AMAANC(SPTNUM, LINNUM, 1)
                      LONGS(INDEX) = AMAANC(SPTNUM, LINNUM, 2)
C
   40             CONTINUE
C
              END IF
C
   50    CONTINUE
C
         AMAMAX = INDEX
C
      END IF
C
      IF (BTEST(FRMCNF,29)) THEN
C
C       AMSU-B INSTRUMENT ON.
C
          AMBFLG = .TRUE.
C
C       GET AMSU-B LATITUDES AND LONGITUDES FROM ANCILLARY DATA BUFFERS.
C
          AMBMIN = AMAMAX + 1
C
          DO LINNUM = 1, BTOTLN
C
C           SEE IF SCAN LINE IS GOOD.
C
              IF (BGOODL(LINNUM)) THEN
C
C               SCAN LINE IS NOT A DUMMY, GET EACH SPOT'S INFO.
C
                  DO SPTNUM = 1,BNSPOT
C
                      INDEX = INDEX + 1
                      LATS(INDEX) = AMBANC(SPTNUM, LINNUM, 1)
                      LONGS(INDEX) = AMBANC(SPTNUM, LINNUM, 2)
C
                  END DO
C
              END IF
C
         END DO
C
         AMBMAX = INDEX
C
      END IF
C
C
C**********************************************************************
C
C   GET VALUES FROM SURFACE ELEVATION MAP.
C
C**********************************************************************
C
      IF ((HIRFLG) .OR. (AMAFLG) ) THEN
C
          CALL MAPRET(UNITNM, LATS, LONGS, MAX(HIRMAX,AMAMAX,AMBMAX),
     1                                'SURFELEV', VALUE, ERROR)
          IF(ERROR.NE.0) GO TO 400
C
C       FILL HIRS ANCILLARY DATA BUFFERS WITH RETRIEVED VALUES.
C
          IF (HIRFLG) THEN
C
              INDEX = HIRMIN
C
C           HIRS INSTRUMENT ON, FILL HIRS ANCILLARY DATA BUFFER.
C
              DO 90,LINNUM = 1, HTOTLN
C
C               CHECK SCAN LINE TO SEE IF DUMMY.
C
                  IF (HGOODL(LINNUM)) THEN
C
C                   SCAN LINE IS NOT A DUMMY, STORE EACH SPOT'S INFO.
C
                      DO 80, SPTNUM = 1,HNSPOT
C
C                          THE HEIGHTS ARE STORED IN THE CDB MAP AS
C                          DECAMETERS.  CONVERT TO METERS FOR SPGS USE.
C
                           HIRANC(SPTNUM,LINNUM,8) = VALUE(INDEX) * 10.0
C
                           INDEX = INDEX + 1
C
   80                 CONTINUE
C
                  END IF
C
   90         CONTINUE
C
          END IF
C
C       FILL AMSU-A ANCILLARY DATA BUFFERS WITH RETRIEVED VALUES.
C
          IF (AMAFLG) THEN
C
              INDEX = AMAMIN
C
C           AMSU-A INSTRUMENT ON. FILL AMSU-A ANCILLARY DATA BUFFERS.
C
              DO 110,LINNUM = 1, ATOTLN
C
                  IF (AGOODL(LINNUM)) THEN
C
C                   SCAN LINE IS NOT A DUMMY, STORE EACH SPOT'S INFO.
C
                      DO 100, SPTNUM = 1,ANSPOT
C
C                          THE HEIGHTS ARE STORED IN THE CDB MAP AS
C                          DECAMETERS.  CONVERT TO METERS FOR SPGS USE.
C
                          AMAANC(SPTNUM, LINNUM,7) = VALUE(INDEX) * 10.0
C
                          INDEX = INDEX + 1
C
  100                 CONTINUE
C
                  END IF
C
  110         CONTINUE
C
          END IF
C
C       FILL MHS ANCILLARY DATA BUFFERS WITH RETRIEVED VALUES.
C
          IF (AMBFLG) THEN
C
              INDEX = AMBMIN
C
C           MHS INSTRUMENT ON. FILL MHS ANCILLARY DATA BUFFERS.
C
              DO LINNUM = 1, BTOTLN
C
                  IF (BGOODL(LINNUM)) THEN
C
C                   SCAN LINE IS NOT A DUMMY, STORE EACH SPOT'S INFO.
C
                      DO SPTNUM = 1,BNSPOT
C
C                          THE HEIGHTS ARE STORED IN THE CDB MAP AS
C                          DECAMETERS.  CONVERT TO METERS FOR SPGS USE.
C
                          AMBANC(SPTNUM, LINNUM,7) = VALUE(INDEX) * 10.0
C
                          INDEX = INDEX + 1
C
                      END DO
C
                  END IF
C
              END DO
          END IF
C
      END IF
C
C**********************************************************************
C
C   GET VALUES FROM SURFACE TYPE MAP.
C
C**********************************************************************
C
      IF ((HIRFLG) .OR. (AMAFLG) ) THEN
C
          CALL MAPRET(UNITNM, LATS, LONGS, MAX(HIRMAX,AMAMAX,AMBMAX),
     1                                'SURFTYPE', TYPE, ERROR)
          IF(ERROR.NE.0) GO TO 400
C
C       FILL HIRS ANCILLARY DATA BUFFERS WITH RETRIEVED VALUES.
C
          IF (HIRFLG) THEN
C
              INDEX = HIRMIN
C
C           HIRS INSTRUMENT ON, FILL HIRS ANCILLARY DATA BUFFER.
C
              DO 150,LINNUM = 1, HTOTLN
C
C               CHECK SCAN LINE TO SEE IF DUMMY.
C
                  IF (HGOODL(LINNUM)) THEN
C
C                   SCAN LINE IS NOT A DUMMY, STORE EACH SPOT'S INFO.
C
                      DO 140, SPTNUM = 1,HNSPOT
C
                           HIRANC(SPTNUM,LINNUM,9) = TYPE(INDEX)
C
                           INDEX = INDEX + 1
C
  140                 CONTINUE
C
                  END IF
C
  150         CONTINUE
C
          END IF
C
C       FILL AMSU-A ANCILLARY DATA BUFFERS WITH RETRIEVED VALUES.
C
          IF (AMAFLG) THEN
C
              INDEX = AMAMIN
C
C           AMSU-A INSTRUMENT ON. FILL AMSU-A ANCILLARY DATA BUFFERS.
C
              DO 170,LINNUM = 1, ATOTLN
C
                  IF (AGOODL(LINNUM)) THEN
C
C                   SCAN LINE IS NOT A DUMMY, STORE EACH SPOT'S INFO.
C
                      DO 160, SPTNUM = 1,ANSPOT
C
                          AMAANC(SPTNUM, LINNUM,8) = TYPE(INDEX)
C
                          INDEX = INDEX + 1
C
  160                 CONTINUE
C
                  END IF
C
  170         CONTINUE
C
          END IF
C
C       FILL MHS ANCILLARY DATA BUFFERS WITH RETRIEVED VALUES.
C
          IF (AMBFLG) THEN
C
              INDEX = AMBMIN
C
C           MHS INSTRUMENT ON. FILL MHS ANCILLARY DATA BUFFERS.
C
              DO LINNUM = 1, BTOTLN
C
                  IF (BGOODL(LINNUM)) THEN
C
C                   SCAN LINE IS NOT A DUMMY, STORE EACH SPOT'S INFO.
C
                      DO SPTNUM = 1,BNSPOT
C
                          AMBANC(SPTNUM, LINNUM,8) = TYPE(INDEX)
C
                          INDEX = INDEX + 1
C
                      END DO
C
                  END IF
C
              END DO
C
          END IF
C
      END IF
C
C
C**********************************************************************
C
C   GET VALUES FROM THE SEA SURFACE TEMPERATURE MAP
C
C**********************************************************************
C

      IF ((HIRFLG) .OR. (AMAFLG) ) THEN
C
C         RESET THE 'VALUE' ARRAY TO MISSING VALUES.  THE SEA
C         SURFACE TEMPERATURE MAP WILL ONLY FILL IN TEMPERATURE
C         VALUES FOR LOCATIONS OVER OPEN WATER (NO SEA ICE).
C
          DO 200 I = 1,(HTOTLN*HNSPOT + ATOTLN*ANSPOT)
C
             VALUE(I) = R4SPV
C
  200     CONTINUE
C
          DO 210,I = 1, AMAMAX
C
C           CHECK SURFACE TYPE TO INSURE LOCATION IS OVER WATER.
C
              IF (TYPE(I) .EQ. WATER) THEN
C
C               LOCATION OVER WATER.
C
                  CALL MAPRET(UNITNM,LATS(I),LONGS(I),1,'SEASURFT',
     1                                          VALUE(I),ERROR)
                  IF(ERROR.NE.0) GO TO 400
C
             END IF
C
  210     CONTINUE
C
C       FILL HIRS ANCILLARY DATA BUFFERS WITH RETRIEVED VALUES.
C
          INDEX = HIRMIN
C
          DO 230,LINNUM = 1, HTOTLN
C
C           CHECK SCAN LINE TO SEE IF DUMMY.
C
              IF (HGOODL(LINNUM)) THEN
C
C               SCAN LINE IS NOT A DUMMY, STORE SEA SURFACE
C               TEMPERATURE FOR EACH SPOT.
C
                  DO 220, SPTNUM = 1,HNSPOT
C
                       HIRANC(SPTNUM,LINNUM,10) = VALUE(INDEX)
C
                       INDEX = INDEX + 1
C
  220             CONTINUE
C
              END IF
C
  230     CONTINUE
C
C
C       FILL AMSU-A ANCILLARY DATA BUFFERS WITH RETRIEVED VALUES.
C
          INDEX = AMAMIN
C
C           AMSU-A INSTRUMENT ON. FILL AMSU-A ANCILLARY DATA BUFFERS.
C
              DO 410,LINNUM = 1, ATOTLN
C
                  IF (AGOODL(LINNUM)) THEN
C
C                   SCAN LINE IS NOT A DUMMY, STORE EACH SPOT'S INFO.
C
                      DO 420, SPTNUM = 1,ANSPOT
C
                          AMAANC(SPTNUM, LINNUM,15) = VALUE(INDEX)
C
                          INDEX = INDEX + 1
C
  420                 CONTINUE
C
                  END IF
C
  410         CONTINUE
C


      END IF
C
C**********************************************************************
C
C   GET VALUES FROM ENVELOPE TOPOGRAPHY MAP.
C
C**********************************************************************
C
      IF (HIRFLG) THEN
C
          DO 240, I = 1, HIRMAX
C
C       FILL HIRS ANCILLARY DATA BUFFERS WITH RETRIEVED VALUES.
C
             CALL MAPRET(UNITNM, LATS(I), LONGS(I), 1, 'ENVTOPOG',
     1                   TYPE(I), ERROR)
             IF(ERROR.NE.0) GO TO 400
C
  240     CONTINUE
C
          INDEX = HIRMIN
C
C         HIRS INSTRUMENT ON, FILL HIRS ANCILLARY DATA BUFFER.
C
          DO 260, LINNUM = 1, HTOTLN
C
C            CHECK SCAN LINE TO SEE IF DUMMY.
C
             IF (HGOODL(LINNUM)) THEN
C
C               SCAN LINE IS NOT A DUMMY, STORE EACH SPOT'S INFO.
C
                DO 250, SPTNUM = 1,HNSPOT
C
                   HIRANC(SPTNUM,LINNUM,16) = TYPE(INDEX)
C
                   INDEX = INDEX + 1
C
  250           CONTINUE
C
             END IF
C
  260     CONTINUE
C
      END IF
C
C**********************************************************************
C
C   GET VALUES FROM POTENTIAL TEMPERATURE, SURFACE PRESSURE, RELATIVE
C   HUMIDITY AND FORECAST SURFACE TEMPERATURE MAPS.
C
C**********************************************************************
C
      IF (HIRFLG) THEN
C
C    DETERMINE WHICH POTENTIAL TEMPERATURE FORECAST MAP TO USE.
C
         CALL POTTEM(UNITNM,PTINDX,DELTIME,FCSTYM,PTSTAT)
         IF(PTSTAT.NE.0) GO TO 400
C
C          IF NO FORECAST MAP WAS FOUND TO MATCH THE DATA FRAME DATE
C          AND TIME, DO NOT ATTEMPT TO RETRIEVE POTENTIAL TEMPERATURE
C          OR SURFACE PRESSURE VALUES.
C
         IF (PTSTAT .NE. 77) THEN
C
C           READ THE POTENTIAL TEMPERATURE FORECAST VALUES FROM THE
C           CDB.
C
            DO 270,I = 1, HIRMAX
C
               CALL MAPRET(UNITNM,LATS(I),LONGS(I),1,PTMAP(PTINDX),
     1                                        VALUE(I),ERROR)
               IF(ERROR.NE.0) GO TO 400
C
  270       CONTINUE
C
C           FILL HIRS ANCILLARY DATA BUFFER WITH RETRIEVED VALUES.
C
            INDEX = HIRMIN
C
            DO 290,LINNUM = 1, HTOTLN
C
C              CHECK SCAN LINE TO SEE IF DUMMY.
C
               IF (HGOODL(LINNUM)) THEN
C
C                 SCAN LINE IS NOT A DUMMY, STORE EACH SPOT'S INFO.
C
                  DO 280, SPTNUM = 1,HNSPOT
C
                     HIRANC(SPTNUM,LINNUM,11) = VALUE(INDEX)
C
                     INDEX = INDEX + 1
C
  280             CONTINUE
C
               END IF
C
  290       CONTINUE
C
C           READ THE SURFACE PRESSURE FORECAST VALUES FROM THE
C           CDB FOR THE SAME HOUR AS THE POTENTIAL TEMPERATURE
C           FORECAST.
C
            DO 300 I = 1, HIRMAX
C
               CALL MAPRET(UNITNM,LATS(I),LONGS(I),1,SPMAP(PTINDX),
     1                                          VALUE(I),ERROR)
               IF(ERROR.NE.0) GO TO 400
C
  300       CONTINUE
C
C
C           FILL HIRS ANCILLARY DATA BUFFER WITH RETRIEVED VALUES.
C
            INDEX = HIRMIN
C
            DO 320,LINNUM = 1, HTOTLN
C
C              CHECK SCAN LINE TO SEE IF DUMMY.
C
               IF (HGOODL(LINNUM)) THEN
C
C                 SCAN LINE IS NOT A DUMMY, STORE EACH SPOT'S INFO.
C
                  DO 310, SPTNUM = 1,HNSPOT
C
                     HIRANC(SPTNUM,LINNUM,12) = VALUE(INDEX)
C
                     INDEX = INDEX + 1
C
  310             CONTINUE
C
               END IF
C
  320       CONTINUE
C
C           READ THE RELATIVE HUMIDITY FORECAST VALUES FROM THE
C           CDB FOR THE SAME HOUR AS THE POTENTIAL TEMPERATURE
C           FORECAST.
C
            DO 330 I = 1, HIRMAX
C
               CALL MAPRET(UNITNM,LATS(I),LONGS(I),1,RHMAP(PTINDX),
     1                                          VALUE(I),ERROR)
               IF(ERROR.NE.0) GO TO 400
C
  330       CONTINUE
C
C           FILL HIRS ANCILLARY DATA BUFFER WITH RETRIEVED VALUES.
C
            INDEX = HIRMIN
C
            DO 350,LINNUM = 1, HTOTLN
C
C              CHECK SCAN LINE TO SEE IF DUMMY.
C
               IF (HGOODL(LINNUM)) THEN
C
C                 SCAN LINE IS NOT A DUMMY, STORE EACH SPOT'S INFO.
C
                  DO 340, SPTNUM = 1,HNSPOT
C
                     HIRANC(SPTNUM,LINNUM,20) = VALUE(INDEX)
C
                     INDEX = INDEX + 1
C
  340             CONTINUE
C
               END IF
C
  350       CONTINUE
C
C           READ THE FORECAST SURFACE TEMPERATURE VALUES FROM THE
C           CDB FOR THE SAME HOUR AS THE POTENTIAL TEMPERATURE
C           FORECAST.
C
            DO 370 I = 1, HIRMAX
C
               CALL MAPRET(UNITNM,LATS(I),LONGS(I),1,FSMAP(PTINDX),
     1                                          VALUE(I),ERROR)
               IF(ERROR.NE.0) GO TO 400
C
  370       CONTINUE
C
C           FILL HIRS ANCILLARY DATA BUFFER WITH RETRIEVED VALUES.
C
            INDEX = HIRMIN
C
            DO 390,LINNUM = 1, HTOTLN
C
C              CHECK SCAN LINE TO SEE IF DUMMY.
C
               IF (HGOODL(LINNUM)) THEN
C
C                 SCAN LINE IS NOT A DUMMY, STORE EACH SPOT'S INFO.
C
                  DO 380, SPTNUM = 1,HNSPOT
C
                     HIRANC(SPTNUM,LINNUM,22) = VALUE(INDEX)
C
                     INDEX = INDEX + 1
C
  380             CONTINUE
C
               END IF
C
  390       CONTINUE
C
         END IF
C
      END IF
C
C   SUCCESSFUL COMPLETION.
C
      IF (PTSTAT .LT. 99) ERROR = PTSTAT
C
      RETURN
C
C   ERROR RETURN.
C
  400 IF (PTSTAT .EQ. 99) ERROR = PTSTAT
      RETURN
C
      END
