C$$$  SUBPROGRAM DOCUMENTATION BLOCK
C                .      .    .                                       .
C SUBPROGRAM:    MSATSNDRDSTA READ SATSND COORDS & METADATA 
C   PRGMMR: L. BENJAMIN      ORG: FSL        DATE: 04-09-27
C
C ABSTRACT: INPUT SATSND COORDINATES AND METADATA FROM A SINGLE, OPEN 
C   NETCDF FILE.
C
C PROGRAM HISTORY LOG:
C   04-09-27  L. BENJAMIN ORIGINAL VERSION
C   05-11-29  L. BENJAMIN ADDED DTIME COMMON BETWEEN DATASETS
C   06-02-13  L. BENJAMIN CHANGED MEMORY MAP LOCATION
C   07-11-21  L. BENJAMIN REMOVED COMMENTED OUT CODE
C   13-04-13  L. BENJAMIN FIXED NOAA-19
C
C USAGE:    CALL MSATSNDRDSTA (SOURCE,NCID,RECDIM,STARTR,NRECS,NDREC,
C                              OBTIME,PROVDR,LAT,LON,ELEV,SUBSRC,
C                              STATUS)
C
C   INPUT ARGUMENT LIST:
C     SOURCE   - I       DATASET CODE NUMBER
C     NCID     - I       ID OF THE OPEN NETCDF QC FILE
C     RECDIM   - I       DIMENSION ID OF THE FILE'S RECORD DIMENSION
C     STARTR   - I       STARTING RECORD TO READ
C     NRECS    - I       NUMBER OF RECORDS TO READ
C     NDREC    - I       SIZE TO USE FOR RECORD DIMENSION IN ARRAYS
C
C   OUTPUT ARGUMENT LIST:
C     OBTIME   - IA      TIMES FOR THE OB RECORDS
C     PROVDR   - CA      PROVIDER NAMES FOR THE OB RECORDS
C     LAT      - RA      LATITUDES FOR THE OB RECORDS
C     LON      - RA      LONGITUDES FOR THE OB RECORDS
C     ELEV     - RA      ELEVATION FOR THE OB RECORDS
C     SUBSRC   - IA      SUBSRC NUMBERS FOR THE OB RECORDS
C     STATUS   - I       SUCCESS_P OR ERROR CODE
C
C   INPUT FILES:
C     NETCDF FILE OPEN WITH NCID ID
C
C SUBPROGRAMS CALLED:
C     UNIQUE:  - M_IDSUBSRC, M_UPDSRCIN, MRDDBL, MRDNUM
C
C REMARKS:
C   NONE
C
C ATTRIBUTES:
C   LANGUAGE: FORTRAN-77 + EXTENSIONS
C   MACHINE:  UNIX
C$$$





      SUBROUTINE MSATSNDRDSTA(SOURCE,NCID,RECDIM,STARTR,NRECS,NDREC,
     1                        OBTIME,PROVDR,LAT,LON,ELEV,SUBSRC,STATUS)

C     -----------------------------------------------------------------
C     INCLUDES AND COMMONS
C     -----------------------------------------------------------------
      INCLUDE 'IMPLICIT'
      INCLUDE 'MADISCON'
      INCLUDE 'MADISCOM'
      INCLUDE 'MADISTMP'

C     -----------------------------------------------------------------
C     ARGUMENTS
C     -----------------------------------------------------------------
      INTEGER       SOURCE
      INTEGER       NCID
      INTEGER       RECDIM
      INTEGER       STARTR
      INTEGER       NRECS
      INTEGER       NDREC
      INTEGER       OBTIME(NDREC)
      INTEGER       SUBSRC(NDREC)
      CHARACTER*10  PROVDR(NDREC)
      REAL          ELEV(NDREC)
      REAL          LAT(NDREC)
      REAL          LON(NDREC)
      INTEGER       STATUS

C     -----------------------------------------------------------------
C     LOCAL
C     -----------------------------------------------------------------
      DOUBLE PRECISION DTIME(MXSATS_P)
      REAL SATID(MXSATS_P)
      INTEGER I,J,CD
      CHARACTER*10 PROVDRL
      EQUIVALENCE(DTIME,TMP_L2_N1)
      EQUIVALENCE(SATID,TMP_L2_N2)

C     *****************************************************************
C     ******************* BEGIN OF MODULE *****************************
C     *****************************************************************

      CD = SOURCE - MAX_SFCDSET_P - MAX_UAPTDSET_P - MAX_HYDRODSET_P
     1     - MAX_SATWDSET_P

C     -----------------------------------------------------------------
C     READ IN THE VARIABLES.  ALSO CONVERT DOUBLE PRECISION UNIX TIME
C     TO INTEGER I4TIME.
C     -----------------------------------------------------------------
      CALL MRDDBL('validTime',NCID,RECDIM,STARTR,NRECS,MISS_P,DTIME,
     1            STATUS)
      IF(STATUS.NE.SUCCESS_P)GO TO 900
      DO I = 1, NRECS
         OBTIME(I) = DTIME(I)
         IF(OBTIME(I).NE.MISS_P)OBTIME(I) = OBTIME(I) - 1325376000
      ENDDO

      CALL MRDNUM('staLat',NCID,RECDIM,STARTR,NRECS,MISS_P,LAT,
     1     STATUS)
      IF(STATUS.NE.SUCCESS_P)GO TO 900

      CALL MRDNUM('staLon',NCID,RECDIM,STARTR,NRECS,MISS_P,LON,
     1     STATUS)
      IF(STATUS.NE.SUCCESS_P)GO TO 900

      CALL MRDNUM('staElev',NCID,RECDIM,STARTR,NRECS,MISS_P,ELEV,
     1     STATUS)
      IF(STATUS.NE.SUCCESS_P)GO TO 900

      CALL MRDNUM('satelliteID',NCID,RECDIM,STARTR,NRECS,MISS_P,SATID,
     1            STATUS)
      IF(STATUS.NE.SUCCESS_P)GO TO 900

C     -----------------------------------------------------------------
C     CREATE THE PROVIDER NAME BASED ON THE SATELLITE ID NUMBER AND THE
C     CD NUMBER OF THE DATASET.  NOTE THAT THE AWIPS DB MAY HAVE A BUG
C     WHERE THE SATELLITE ID ISN'T FILLED IN.  IN THAT CASE, WE'LL USE
C     'NOAA-XX'.
C     -----------------------------------------------------------------
      IF(CD.EQ.POES_DS_P)THEN

         PROVDRL = 'NOAA-XX'

         DO I = 1, NRECS

C     -----------------------------------------------------------------
C     MAGIC NUMBERS, MAYBE SOME DAY THIS SHOULD BE A TABLE.
C     NOAA-17 =< (ID - 191)
C     NOAA-18 =  (ID - 205)
C     NOAA-19 =  (ID = 19 for 223)
C     -----------------------------------------------------------------
            IF(SATID(I).EQ.223)THEN
               J = 19
            ELSEIF(SATID(I).LE.209)THEN
               J = SATID(I) - 191
            ELSE
               J = 0
            ENDIF
            IF(J.GT.0.AND.J.LT.100)THEN
               WRITE(PROVDRL(6:7),1)J
 1             FORMAT(I2)
               IF(PROVDRL(6:6).EQ.' ')PROVDRL(6:6) = '0'
            ELSE
               PROVDRL(6:7) = 'XX'
            ENDIF
            
            PROVDR(I) = PROVDRL

         ENDDO

      ENDIF

C     -----------------------------------------------------------------
C     UPDATE THE SUBSRCIN TABLE BASED ON THE TABLE CONTAINED IN THE
C     DATA FILE (IF APPLICABLE FOR THE DATASET), THEN TRANSLATE 
C     PROVIDER NAMES INTO SUBSRC NUMBERS.
C     -----------------------------------------------------------------
      CALL M_UPDSRCIN(NCID,RECDIM,STATUS)
      IF(STATUS.NE.SUCCESS_P)GO TO 900

      CALL M_IDSUBSRC(NRECS,PROVDR,SUBSRC,STATUS)

 900  RETURN
      END
C**--------------------------------------------------------------------
C**REQUIRED STANDARD FSL DISCLAIMER (NOVEMBER 2000)
C**--------------------------------------------------------------------
C**  OPEN SOURCE LICENSE/DISCLAIMER,  FORECAST SYSTEMS LABORATORY
C**  NOAA/OAR/FSL, 325 BROADWAY BOULDER, CO 80305
C**
C**  THIS SOFTWARE IS DISTRIBUTED UNDER THE OPEN SOURCE DEFINITION, 
C**  WHICH MAY BE FOUND AT http://www.opensource.org/osd.html.
C**
C**  IN PARTICULAR, REDISTRIBUTION AND USE IN SOURCE AND BINARY FORMS,
C**  WITH OR WITHOUT MODIFICATION, ARE PERMITTED PROVIDED THAT THE 
C**  FOLLOWING CONDITIONS ARE MET:
C**
C**  - REDISTRIBUTIONS OF SOURCE CODE MUST RETAIN THIS NOTICE, THIS LIST
C**    OF CONDITIONS AND THE FOLLOWING DISCLAIMER.
C**
C**  - REDISTRIBUTIONS IN BINARY FORM MUST PROVIDE ACCESS TO THIS 
C**    NOTICE, THIS LIST OF CONDITIONS AND THE FOLLOWING DISCLAIMER, AND
C**    THE UNDERLYING SOURCE CODE.
C**
C**  - ALL MODIFICATIONS TO THIS SOFTWARE MUST BE CLEARLY DOCUMENTED, 
C**    AND ARE SOLELY THE RESPONSIBILITY OF THE AGENT MAKING THE 
C**    MODIFICATIONS.
C**
C**  - IF SIGNIFICANT MODIFICATIONS OR ENHANCEMENTS ARE MADE TO THIS
C**    SOFTWARE, THE FSL SOFTWARE POLICY MANAGER 
C**    (softwaremgr.fsl@noaa.gov) BE NOTIFIED.
C**
C**  THIS SOFTWARE AND ITS DOCUMENTATION ARE IN THE PUBLIC DOMAIN AND 
C**  ARE FURNISHED "AS IS."  THE AUTHORS, THE UNITED STATES GOVERNMENT,
C**  ITS INSTRUMENTALITIES, OFFICERS, EMPLOYEES, AND AGENTS MAKE NO 
C**  WARRANTY, EXPRESS OR IMPLIED, AS TO THE USEFULNESS OF THE SOFTWARE
C**  AND DOCUMENTATION FOR ANY PURPOSE.  THEY ASSUME NO RESPONSIBILITY 
C**  (1) FOR THE USE OF THE SOFTWARE AND DOCUMENTATION; OR (2) TO 
C**  PROVIDE TECHNICAL SUPPORT TO USERS.
C**--------------------------------------------------------------------
