C$$$  SUBPROGRAM DOCUMENTATION BLOCK
C                .      .    .                                       .
C SUBPROGRAM:    MSATWNDRDSTA READ SATWND COORDS & METADATA 
C   PRGMMR: M. BARTH         ORG: FSL        DATE: 03-09-25
C
C ABSTRACT: INPUT SATWND COORDINATES AND METADATA FROM A SINGLE, OPEN 
C   NETCDF FILE.
C
C PROGRAM HISTORY LOG:
C   03-09-25  M. BARTH    ORIGINAL VERSION
C   05-11-29  L. BENJAMIN ADDED DTIME COMMON BETWEEN DATASETS
C   06-02-13  L. BENJAMIN CHANGED MEMORY MAP LOCATION
C   
C
C USAGE:    CALL MSATWNDRDSTA (SOURCE,NCID,RECDIM,STARTR,NRECS,NDREC,
C                              OBTIME,PROVDR,LAT,LON,P,SUBSRC,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     P        - RA      PRESSURES 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, MERROR, MRDDBL, MRDNUM
C
C REMARKS:
C   NONE
C
C ATTRIBUTES:
C   LANGUAGE: FORTRAN-77 + EXTENSIONS
C   MACHINE:  UNIX
C$$$






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

C     ------------------------------------------------------------------
C     INCLUDES AND COMMONS
C     ------------------------------------------------------------------
      INCLUDE 'IMPLICIT'
      INCLUDE 'MADISCON'
      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          P(NDREC)
      REAL          LAT(NDREC)
      REAL          LON(NDREC)
      INTEGER       STATUS

C     ------------------------------------------------------------------
C     LOCAL
C     ------------------------------------------------------------------
      DOUBLE PRECISION DTIME(MXSATW_P)
      REAL SATID(MXSATW_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

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('obLat',NCID,RECDIM,STARTR,NRECS,MISS_P,LAT,
     1     STATUS)
      IF(STATUS.NE.SUCCESS_P)GO TO 900

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

      CALL MRDNUM('pressure',NCID,RECDIM,STARTR,NRECS,MISS_P,P,
     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     'GOES-XX'.
C     ------------------------------------------------------------------
      IF(CD.EQ.HDW_DS_P.OR.CD.EQ.HDW1H_DS_P)THEN

         IF(CD.EQ.HDW_DS_P)THEN
            PROVDRL = 'GOES-XX-O'
         ELSE
            PROVDRL = 'GOES-XX-X'
         ENDIF

         DO I = 1, NRECS

            J = SATID(I) - 244
            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 PROVIDER 
C     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**---------------------------------------------------------------------
