C$$$  SUBPROGRAM DOCUMENTATION BLOCK
C                .      .    .                                       .
C SUBPROGRAM:    MUAPTRDSTA  READ UPPER-AIR-POINT DATA STATION INFO
C   PRGMMR: M. BARTH         ORG: FSL        DATE: 00-03-23
C
C ABSTRACT: INPUT UPPER-AIR-POINT DATA STATION INFO FROM A SINGLE,
C   OPEN NETCDF FILE.
C
C PROGRAM HISTORY LOG:
C   00-03-23  M. BARTH    ORIGINAL VERSION
C   00-06-13  M. BARTH    CHANGES FOR ACARS
C   01-05-03  M. BARTH    CHANGES FOR AWIPS-FORMATTED RAOBS
C   01-07-26  M. BARTH    STAID CHANGED FROM 8 TO 10 CHARACTERS
C   02-04-30  M. BARTH    ADDED MAP DATASET AND PROVDR,SUBSRC ARGS
C   03-07-01  M. BARTH    ADDED RDMTR DATASET
C   03-10-10  M. BARTH    CHANGES FOR AWIPS-FORMATTED ACARS
C   04-06-16  M. BARTH    ADDED ACARSP DATASET
C   05-11-29  L. BENJAMIN ADDED DTIME COMMON BETWEEN DATASETS
C   06-02-13  L. BENJAMIN CHANGED MEMORY LOCATION FOR LOCAL VARIABLES
C
C USAGE:    CALL MUAPTRDSTA (SOURCE,NCID,FNUM,RECDIM,STARTR,NRECS,NDSTA,
C                            OBTIME,STAID,WMOID,PROVDR,LAT,LON,ELEV,
C                            SUBSRC,NLEVELS,STATUS)
C
C   INPUT ARGUMENT LIST:
C     SOURCE   - I       DATASET CODE NUMBER
C     NCID     - I       ID OF THE OPEN NETCDF QC FILE
C     FNUM     - I       INDEX OF THE FILE IN STRCCOM
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     NDSTA    - I       SIZE TO USE FOR STATION DIMENSION IN ARRAYS
C
C   OUTPUT ARGUMENT LIST:
C     OBTIME   - IA      TIMES FOR THE OB RECORDS
C     STAID    - CA      STATION NAMES FOR THE OB RECORDS
C     WMOID    - IA      WMO IDS 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      STATION ELEVATIONS FOR THE OB RECORDS
C     SUBSRC   - IA      SUBSRC NUMBERS FOR THE OB RECORDS
C     NLEVELS  - IA      NUM LEVELS 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     LIBRARY: - NETCDF LIBRARY:
C                NCAGT
C                NCDINQ
C                NCINQ
C                NCVGT
C                NCVGTC
C                NCVID
C                NCVINQ
C     UNIQUE:  - MGTCHR
C                MRAOBINT
C                M_IDSUBSRC
C                M_LSTCHR
C                M_UPDSRCIN
C                MERROR
C
C REMARKS:
C   - SOME OF THE RETURNED ARRAYS ONLY HAVE INFO FOR SOME SOURCES.
C   - CHARACTER ARRAYS ARE BLANK-FILLED TO THE RIGHT
C   - THE CN (E.G. C6) ARRAYS SHOULD BE DIMENSIONED TO THE LARGEST 
C     'MAXSTA' PARAMETER FOR ANY DATASET THAT USES THAT SIZE STATION 
C     NAMES.
C
C ATTRIBUTES:
C   LANGUAGE: FORTRAN-77 + EXTENSIONS
C   MACHINE:  UNIX
C$$$






      SUBROUTINE MUAPTRDSTA(SOURCE,NCID,FNUM,RECDIM,STARTR,NRECS,NDSTA,
     1                      OBTIME,STAID,WMOID,PROVDR,LAT,LON,ELEV,
     2                      SUBSRC,NLEVELS,STATUS)





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


C     ------------------------------------------------------------------
C     ARGUMENTS
C     ------------------------------------------------------------------
      INTEGER       SOURCE
      INTEGER       NCID
      INTEGER       FNUM
      INTEGER       RECDIM
      INTEGER       STARTR
      INTEGER       NRECS
      INTEGER       NDSTA
      INTEGER       OBTIME(NDSTA)
      CHARACTER*10  STAID(NDSTA)
      REAL          ELEV(NDSTA)
      REAL          LAT(NDSTA)
      REAL          LON(NDSTA)
      INTEGER       WMOID(NDSTA)
      CHARACTER*10  PROVDR(NDSTA)
      INTEGER       SUBSRC(NDSTA)
      INTEGER       NLEVELS(NDSTA)
      INTEGER       STATUS

C     ------------------------------------------------------------------
C     LOCAL
C     ------------------------------------------------------------------
      INTEGER       I,J,K,N
      INTEGER       M_LSTCHR
      INTEGER       RCODE
      CHARACTER*(MAXNCNAM) VARNAM,DIMNAM
      INTEGER       VDIMS(MAXVDIMS),DIMSIZ,NVDIMS,LENSTR
      INTEGER       VARTYP,NVATTS,START(MAXVDIMS),COUNT(MAXVDIMS)
      CHARACTER*15  TIMNAM
      CHARACTER*6   C6(MXMAP_P)
      CHARACTER*9   C9(MXACARS_P)
      CHARACTER*50  C50(MXRAOB_P)
      REAL          ELEV_FILL
      INTEGER       WMOID_FILL
      REAL          LAT_FILL
      REAL          LON_FILL
      LOGICAL       HAVE_FILL
      DOUBLE PRECISION DTIME(MXUAPT_P),DTIME_FILL
      CHARACTER*12  EN_TAIL(MXACARS_P)
      CHARACTER*11  DPNAME(MXMAP_P)
      CHARACTER*24  DPNAMEA(MXMAP_P)

      EQUIVALENCE   (C6,C50,C9,TMP_L2_C1)
      EQUIVALENCE   (DTIME,TMP_L2_N1)
      EQUIVALENCE   (DPNAMEA,EN_TAIL,TMP_L2_C2)
      EQUIVALENCE   (DPNAME,TMP_L2_C1(MXACARS_P*9+1))


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

      STATUS = NC_READ_P

C     ------------------------------------------------------------------
C     FILL IN DATA STRUCTURES NEEDED TO READ MOST OF THE VARIABLES
C     FROM NETCDF FILES, DEPENDING ON THE SOURCE.  ALSO HANDLE ANY
C     SOURCE-SPECIFIC INITIALIZATION.
C     ------------------------------------------------------------------
      IF(CDTYPE .NE. RAOB_DS_P .AND. CDTYPE .NE. MAP_DS_P .AND.
     1   CDTYPE .NE. RDMTR_DS_P .AND. CDTYPE .NE. ACARSP_DS_P)THEN
         TIMNAM = 'timeObs'
      ELSE IF(CDTYPE .EQ. RAOB_DS_P)THEN
         TIMNAM = 'synTime'
      ELSE IF(CDTYPE .EQ. ACARSP_DS_P)THEN
         TIMNAM = 'profileTime'
      ELSE
         TIMNAM = 'observationTime'
      ENDIF

C     ------------------------------------------------------------------
C     READ THE STATION NAMES INTO THE PROPER SIZE CHARACTER ARRAY, PUT
C     BLANKS AT THE END OF THE STRING, THEN TRANSFER TO CALLER'S ARRAY.
C     ------------------------------------------------------------------
      IF(.NOT. (CDTYPE .EQ. ACARS_DS_P .AND. CDBTYPE .EQ. FSL_DB_P))THEN

         J = NCVID(NCID,
     1            VNAME(STANAM_VN_P,SOURCE)(1:VLEN(STANAM_VN_P,SOURCE)),
     2            RCODE)
         IF(RCODE.NE.0)THEN
            CALL MERROR('MUAPTRDSTA: BAD NCVID - STATION NAME'//
     1                  ' - '//UAPTDSET_NAME(CDTYPE))
            GO TO 900
         ENDIF
         CALL NCVINQ(NCID,J,VARNAM,VARTYP,NVDIMS,VDIMS,NVATTS,RCODE)
         IF(RCODE.NE.SUCCESS_P)THEN
            CALL MERROR('MUAPTRDSTA: BAD NCVINQ - STATION NAME'//
     1                  ' - '//UAPTDSET_NAME(CDTYPE))
            GO TO 900
         ENDIF
         LENSTR = 1
         DO 52 K = 1, NVDIMS
            CALL NCDINQ(NCID,VDIMS(K),DIMNAM,DIMSIZ,RCODE)
            IF(RCODE.NE.SUCCESS_P)THEN
               CALL MERROR('MUAPTRDSTA: BAD NCDINQ - STATION NAME'//
     1                     ' - '//UAPTDSET_NAME(CDTYPE))
               GO TO 900
            ENDIF
            IF(K.LT.NVDIMS.OR.(NVDIMS.EQ.K.AND.VDIMS(K).NE.RECDIM))THEN
               START(K) = 1
               COUNT(K) = DIMSIZ
               LENSTR = LENSTR * DIMSIZ
            ELSE
               START(K) = STARTR
               COUNT(K) = NRECS
               LENSTR = LENSTR * NRECS
            ENDIF
 52      CONTINUE

         IF(CDTYPE.EQ.NPN_DS_P.OR.CDTYPE.EQ.MAP_DS_P.OR.
     1      CDTYPE.EQ.RDMTR_DS_P.OR.CDTYPE.EQ.ACARSP_DS_P)THEN

            CALL NCVGTC(NCID,J,START,COUNT,C6,LENSTR,RCODE)
            IF(RCODE.NE.SUCCESS_P)THEN
               CALL MERROR('MUAPTRDSTA: BAD NCVGTC - STATION NAME'//
     1                     ' - '//UAPTDSET_NAME(CDTYPE))
               GO TO 900
            ENDIF
            DO 63 I = 1, NRECS
               N = M_LSTCHR(C6(I),6)
               IF(N .NE. 6)THEN
                  DO 64 K = N+1, 6
                     C6(I)(K:K) = ' '
 64               CONTINUE
               ENDIF
               STAID(I) = C6(I)(1:6)//'    '
 63         CONTINUE

         ELSE IF(CDTYPE.EQ.ACARS_DS_P)THEN

            CALL NCVGTC(NCID,J,START,COUNT,C9,LENSTR,RCODE)
            IF(RCODE.NE.SUCCESS_P)THEN
               CALL MERROR('MUAPTRDSTA: BAD NCVGTC - STATION NAME'//
     1                     ' - '//UAPTDSET_NAME(CDTYPE))
               GO TO 900
            ENDIF
            DO I = 1, NRECS
               N = M_LSTCHR(C9(I),9)
               IF(N .NE. 9)THEN
                  DO K = N+1, 9
                     C9(I)(K:K) = ' '
                  ENDDO
               ENDIF
               STAID(I) = C9(I)(1:9)//' '
            ENDDO

         ELSE IF(CDTYPE.EQ.RAOB_DS_P)THEN

C     ------------------------------------------------------------------
C     THE RAOB STANAMES ARE A RIDICULOUSLY-LONG 50 CHARACTERS.  BECAUSE
C     WE'RE SMART ENOUGH TO KNOW IT'S NEVER MORE THAN 5, WE'LL STICK TO
C     THAT (PLUS A BLANK AT THE END).
C     ------------------------------------------------------------------
            CALL NCVGTC(NCID,J,START,COUNT,C50,LENSTR,RCODE)
            IF(RCODE.NE.SUCCESS_P)THEN
               CALL MERROR('MUAPTRDSTA: BAD NCVGTC - STATION NAME'//
     1                     ' - '//UAPTDSET_NAME(CDTYPE))
               GO TO 900
            ENDIF
            DO 73 I = 1, NRECS
               N = M_LSTCHR(C50(I),6)
               IF(N .LT. 6)THEN
                  DO 74 K = N+1, 6
                     C50(I)(K:K) = ' '
 74               CONTINUE
               ENDIF
               STAID(I) = C50(I)(1:6)//'    '
 73         CONTINUE

         ENDIF

      ELSE

C     ------------------------------------------------------------------
C     GET ACARS FSL-ENCODED TAIL NUMBERS, AND EXTRACT ONLY THE NUMERAL
C     PORTION TO BE RETURNED (E.G., "FSL12345678" BECOMES "12345678").
C     ------------------------------------------------------------------
         CALL MGTCHR('en_tailNumber',NCID,RECDIM,STARTR,NRECS,EN_TAIL,I,
     1               RCODE)
         IF(RCODE.NE.0)GO TO 900
         DO 700 I = 1, NRECS
            STAID(I) = EN_TAIL(I)(4:11)//'  '
 700     CONTINUE

      ENDIF

C     ------------------------------------------------------------------
C     GET THE WMO ID'S.
C     ------------------------------------------------------------------
      IF(CDTYPE.NE.ACARS_DS_P.AND..NOT.((CDTYPE.EQ.MAP_DS_P.OR.
     1   CDTYPE.EQ.ACARSP_DS_P).AND.
     2   UAPT_DBTYPE(CDTYPE).NE.FSL_DB_P))THEN

         J = NCVID(NCID,
     1             VNAME(WMOID_VN_P,SOURCE)(1:VLEN(WMOID_VN_P,SOURCE)),
     2             RCODE)
         IF(RCODE.NE.0)THEN
            CALL MERROR('MUAPTRDSTA: BAD NCVID - WMO ID'//
     1                  ' - '//UAPTDSET_NAME(CDTYPE))
            GO TO 900
         ENDIF
         CALL NCVINQ(NCID,J,VARNAM,VARTYP,NVDIMS,VDIMS,NVATTS,RCODE)
         IF(RCODE.NE.SUCCESS_P)THEN
            CALL MERROR('MUAPTRDSTA: BAD NCVINQ - WMO ID'//
     1                  ' - '//UAPTDSET_NAME(CDTYPE))
            GO TO 900
         ENDIF
         DO 551 K = 1, NVDIMS
            CALL NCDINQ(NCID,VDIMS(K),DIMNAM,DIMSIZ,RCODE)
            IF(RCODE.NE.SUCCESS_P)THEN
               CALL MERROR('MUAPTRDSTA: BAD NCDINQ - WMO ID'//
     1                     ' - '//UAPTDSET_NAME(CDTYPE))
               GO TO 900
            ENDIF
            IF(K.LT.NVDIMS.OR.(NVDIMS.EQ.K.AND.VDIMS(K).NE.RECDIM))THEN
               START(K) = 1
               COUNT(K) = DIMSIZ
            ELSE
               START(K) = STARTR
               COUNT(K) = NRECS
            ENDIF
 551     CONTINUE
         CALL NCVGT(NCID,J,START,COUNT,WMOID,RCODE)
         IF(RCODE.NE.SUCCESS_P)THEN
            CALL MERROR('MUAPTRDSTA: BAD NCVGT - WMO ID'//
     1                  ' - '//UAPTDSET_NAME(CDTYPE))
            GO TO 900
         ENDIF
         CALL NCAGT(NCID,J,'_FillValue',WMOID_FILL,RCODE)
         IF(RCODE.NE.SUCCESS_P)THEN
            HAVE_FILL = .FALSE.
         ELSE
            HAVE_FILL = .TRUE.
         ENDIF

         IF(HAVE_FILL)THEN

            DO 549 I = 1, NRECS
               IF(WMOID(I).EQ.WMOID_FILL)WMOID(I) = MISS_P
 549        CONTINUE

         ENDIF

      ELSE

         DO 750 I = 1, NRECS

            WMOID(I) = MISS_P

 750     CONTINUE

      ENDIF

C     ------------------------------------------------------------------
C     GET THE LATITUDES AND LONGITUDES.
C     ------------------------------------------------------------------
      J = NCVID(NCID,VNAME(LAT_VN_P,SOURCE)(1:VLEN(LAT_VN_P,SOURCE)),
     1          RCODE)
      IF(RCODE.NE.0)THEN
         CALL MERROR('MUAPTRDSTA: BAD NCVID - LATITUDE'//
     1               ' - '//UAPTDSET_NAME(CDTYPE))
         GO TO 900
      ENDIF
      CALL NCVINQ(NCID,J,VARNAM,VARTYP,NVDIMS,VDIMS,NVATTS,RCODE)
      IF(RCODE.NE.SUCCESS_P)THEN
         CALL MERROR('MUAPTRDSTA: BAD NCVINQ - LATITUDE'//
     1               ' - '//UAPTDSET_NAME(CDTYPE))
         GO TO 900
      ENDIF
      DO 8551 K = 1, NVDIMS
         CALL NCDINQ(NCID,VDIMS(K),DIMNAM,DIMSIZ,RCODE)
         IF(RCODE.NE.SUCCESS_P)THEN
            CALL MERROR('MUAPTRDSTA: BAD NCDINQ - LATITUDE'//
     1                  ' - '//UAPTDSET_NAME(CDTYPE))
            GO TO 900
         ENDIF
         IF(K.LT.NVDIMS.OR.(NVDIMS.EQ.K.AND.VDIMS(K).NE.RECDIM))THEN
            START(K) = 1
            COUNT(K) = DIMSIZ
         ELSE
            START(K) = STARTR
            COUNT(K) = NRECS
         ENDIF
 8551 CONTINUE
      CALL NCVGT(NCID,J,START,COUNT,LAT,RCODE)
      IF(RCODE.NE.SUCCESS_P)THEN
         CALL MERROR('MUAPTRDSTA: BAD NCVGT - LATITUDE'//
     1               ' - '//UAPTDSET_NAME(CDTYPE))
         GO TO 900
      ENDIF
      CALL NCAGT(NCID,J,'_FillValue',LAT_FILL,RCODE)
      IF(RCODE.EQ.SUCCESS_P)THEN
         DO 8552 I = 1, NRECS
            IF(LAT(I).EQ.LAT_FILL)LAT(I) = MISS_P
 8552    CONTINUE
      ENDIF

      J = NCVID(NCID,VNAME(LON_VN_P,SOURCE)(1:VLEN(LON_VN_P,SOURCE)),
     1          RCODE)
      IF(RCODE.NE.0)THEN
         CALL MERROR('MUAPTRDSTA: BAD NCVID - LONGITUDE'//
     1               ' - '//UAPTDSET_NAME(CDTYPE))
         GO TO 900
      ENDIF
      CALL NCVINQ(NCID,J,VARNAM,VARTYP,NVDIMS,VDIMS,NVATTS,RCODE)
      IF(RCODE.NE.SUCCESS_P)THEN
         CALL MERROR('MUAPTRDSTA: BAD NCVINQ - LONGITUDE'//
     1               ' - '//UAPTDSET_NAME(CDTYPE))
         GO TO 900
      ENDIF
      DO 9551 K = 1, NVDIMS
         CALL NCDINQ(NCID,VDIMS(K),DIMNAM,DIMSIZ,RCODE)
         IF(RCODE.NE.SUCCESS_P)THEN
            CALL MERROR('MUAPTRDSTA: BAD NCDINQ - LONGITUDE'//
     1                  ' - '//UAPTDSET_NAME(CDTYPE))
            GO TO 900
         ENDIF
         IF(K.LT.NVDIMS.OR.(NVDIMS.EQ.K.AND.VDIMS(K).NE.RECDIM))THEN
            START(K) = 1
            COUNT(K) = DIMSIZ
         ELSE
            START(K) = STARTR
            COUNT(K) = NRECS
         ENDIF
 9551 CONTINUE
      CALL NCVGT(NCID,J,START,COUNT,LON,RCODE)
      IF(RCODE.NE.SUCCESS_P)THEN
         CALL MERROR('MUAPTRDSTA: BAD NCVGT - LONGITUDE'//
     1               ' - '//UAPTDSET_NAME(CDTYPE))
         GO TO 900
      ENDIF
      CALL NCAGT(NCID,J,'_FillValue',LON_FILL,RCODE)
      IF(RCODE.EQ.SUCCESS_P)THEN
         DO 9552 I = 1, NRECS
            IF(LON(I).EQ.LON_FILL)LON(I) = MISS_P
 9552    CONTINUE
      ENDIF

C     ------------------------------------------------------------------
C     READ IN ELEVATION.
C     ------------------------------------------------------------------
      IF(CDTYPE.NE.ACARS_DS_P.AND..NOT.(CDTYPE.EQ.ACARSP_DS_P.AND.
     1   UAPT_DBTYPE(CDTYPE).NE.FSL_DB_P))THEN

         J = NCVID(NCID,
     1             VNAME(ELEV_VN_P,SOURCE)(1:VLEN(ELEV_VN_P,SOURCE)),
     1             RCODE)
         IF(RCODE.NE.0)THEN
            CALL MERROR('MUAPTRDSTA: BAD NCVID - ELEVATION'//
     1                  ' - '//UAPTDSET_NAME(CDTYPE))
            GO TO 900
         ENDIF
         CALL NCVINQ(NCID,J,VARNAM,VARTYP,NVDIMS,VDIMS,NVATTS,RCODE)
         IF(RCODE.NE.SUCCESS_P)THEN
            CALL MERROR('MUAPTRDSTA: BAD NCVINQ - ELEVATION'//
     1                  ' - '//UAPTDSET_NAME(CDTYPE))
            GO TO 900
         ENDIF
         DO 153 K = 1, NVDIMS
            CALL NCDINQ(NCID,VDIMS(K),DIMNAM,DIMSIZ,RCODE)
            IF(RCODE.NE.SUCCESS_P)THEN
               CALL MERROR('MUAPTRDSTA: BAD NCDINQ - ELEVATION'//
     1                     ' - '//UAPTDSET_NAME(CDTYPE))
               GO TO 900
            ENDIF
            IF(K.LT.NVDIMS.OR.(NVDIMS.EQ.K.AND.VDIMS(K).NE.RECDIM))THEN
               START(K) = 1
               COUNT(K) = DIMSIZ
            ELSE
               START(K) = STARTR
               COUNT(K) = NRECS
            ENDIF
 153     CONTINUE

         CALL NCVGT(NCID,J,START,COUNT,ELEV,RCODE)
         IF(RCODE.NE.SUCCESS_P)THEN
            CALL MERROR('MUAPTRDSTA: BAD NCVGT - ELEVATION'//
     1                  ' - '//UAPTDSET_NAME(CDTYPE))
            GO TO 900
         ENDIF

         CALL NCAGT(NCID,J,'_FillValue',ELEV_FILL,RCODE)
         IF(RCODE.NE.SUCCESS_P)THEN
            HAVE_FILL = .FALSE.
         ELSE
            HAVE_FILL = .TRUE.
         ENDIF

         IF(HAVE_FILL)THEN

            DO 154 I = 1, NRECS
               IF(ELEV(I).EQ.ELEV_FILL)ELEV(I) = MISS_P
 154        CONTINUE

         ENDIF

      ELSE IF(CDTYPE.EQ.ACARSP_DS_P)THEN

         DO I = 1, NRECS

            ELEV(I) = MISS_P

         ENDDO

      ENDIF

C     ------------------------------------------------------------------
C     READ THE DOUBLE PRECISION TIME & ITS FILL VALUE, IF THE TIME ISN'T
C     MISSING, TRANSLATE TO I4TIME (UNIX TIME + 10 YEARS IN SECONDS),
C     AND TRANSFER TO CALLER'S INTEGER ARRAY.
C     ------------------------------------------------------------------
      J = NCVID(NCID,TIMNAM,RCODE)
      IF(RCODE.NE.0)THEN
         CALL MERROR('MUAPTRDSTA: BAD NCVID - OBTIME'//
     1               ' - '//UAPTDSET_NAME(CDTYPE))
         GO TO 900
      ENDIF
      CALL NCVINQ(NCID,J,VARNAM,VARTYP,NVDIMS,VDIMS,NVATTS,RCODE)
      IF(RCODE.NE.SUCCESS_P)THEN
         CALL MERROR('MUAPTRDSTA: BAD NCVINQ - OBTIME'//
     1               ' - '//UAPTDSET_NAME(CDTYPE))
         GO TO 900
      ENDIF
      DO 152 K = 1, NVDIMS
         CALL NCDINQ(NCID,VDIMS(K),DIMNAM,DIMSIZ,RCODE)
         IF(RCODE.NE.SUCCESS_P)THEN
            CALL MERROR('MUAPTRDSTA: BAD NCDINQ - OBTIME'//
     1                  ' - '//UAPTDSET_NAME(CDTYPE))
            GO TO 900
         ENDIF
         IF(K.LT.NVDIMS.OR.(NVDIMS.EQ.K.AND.VDIMS(K).NE.RECDIM))THEN
            START(K) = 1
            COUNT(K) = DIMSIZ
         ELSE
            START(K) = STARTR
            COUNT(K) = NRECS
         ENDIF
 152  CONTINUE

      CALL NCVGT(NCID,J,START,COUNT,DTIME,RCODE)
      IF(RCODE.NE.SUCCESS_P)THEN
         CALL MERROR('MUAPTRDSTA: BAD NCVGT - OBTIME'//
     1               ' - '//UAPTDSET_NAME(CDTYPE))
         GO TO 900
      ENDIF
      CALL NCAGT(NCID,J,'_FillValue',DTIME_FILL,RCODE)
      IF(RCODE.NE.SUCCESS_P)THEN
         HAVE_FILL = .FALSE.
      ELSE
         HAVE_FILL = .TRUE.
      ENDIF

      DO 600 I = 1, NRECS
         IF((.NOT.HAVE_FILL) .OR. (DTIME(I).NE.DTIME_FILL))THEN
            OBTIME(I) = DTIME(I)
            OBTIME(I) = OBTIME(I) - 1325376000
         ELSE
            OBTIME(I) = MISS_P
         ENDIF
 600  CONTINUE

C     ------------------------------------------------------------------
C     IF RAOBS, READ IN ALL THE DATA INTO COMMON AND CREATE INTEGRATED
C     SOUNDINGS.
C     ------------------------------------------------------------------
      IF(CDTYPE.EQ.RAOB_DS_P)THEN

         CALL MRAOBINT(NCID,FNUM,RECDIM,STARTR,NRECS,NLEVELS,STATUS)

C     ------------------------------------------------------------------
C     FOR MAP AND RDMTR, GET THE DATA PROVIDER NAMES AND TRANSLATE THEM 
C     INTO SUBSRC NUMBERS.
C
C     NOTE THAT THE MAP AWIPS DATA PROVIDER NAMES ARE 24 CHARACTERS AND
C     THE FSL NAMES ARE 11 -- WE'LL TRUNCATE THE AWIPS ONES...
C     ------------------------------------------------------------------
      ELSE IF(CDTYPE.EQ.MAP_DS_P.OR.CDTYPE.EQ.RDMTR_DS_P)THEN

         J = NCVID(NCID,'dataProvider',RCODE)
         IF(RCODE.NE.0)THEN
            CALL MERROR('MUAPTRDSTA: BAD NCVID - DPNAME'//
     1                  ' - '//UAPTDSET_NAME(CDTYPE))
            GO TO 900
         ENDIF
         CALL NCVINQ(NCID,J,VARNAM,VARTYP,NVDIMS,VDIMS,NVATTS,RCODE)
         IF(RCODE.NE.SUCCESS_P)THEN
            CALL MERROR('MUAPTRDSTA: BAD NCVINQ - DPNAME'//
     1                  ' - '//UAPTDSET_NAME(CDTYPE))
            GO TO 900
         ENDIF
         LENSTR = 1
         DO 51 K = 1, NVDIMS
            CALL NCDINQ(NCID,VDIMS(K),DIMNAM,DIMSIZ,RCODE)
            IF(RCODE.NE.SUCCESS_P)THEN
               CALL MERROR('MUAPTRDSTA: BAD NCDINQ - DPNAME'//
     1                     ' - '//UAPTDSET_NAME(CDTYPE))
               GO TO 900
            ENDIF
            IF(K.LT.NVDIMS.OR.(NVDIMS.EQ.K.AND.VDIMS(K).NE.RECDIM))THEN
               START(K) = 1
               COUNT(K) = DIMSIZ
               LENSTR = LENSTR * DIMSIZ
            ELSE
               START(K) = STARTR
               COUNT(K) = NRECS
               LENSTR = LENSTR * NRECS
            ENDIF
 51      CONTINUE
         IF(LENSTR/NRECS.EQ.11)THEN
            CALL NCVGTC(NCID,J,START,COUNT,DPNAME,LENSTR,RCODE)
         ELSE
            CALL NCVGTC(NCID,J,START,COUNT,DPNAMEA,LENSTR,RCODE)
            DO K = 1, NRECS
               DPNAME(K) = DPNAMEA(K)(1:11)
            ENDDO
         ENDIF
         IF(RCODE.NE.SUCCESS_P)THEN
            CALL MERROR('MUAPTRDSTA: BAD NCVGTC - DPNAME'//
     1                  ' - '//UAPTDSET_NAME(CDTYPE))
            GO TO 900
         ENDIF

C     ------------------------------------------------------------------
C     MOVE THE DATA PROVIDER NAMES INTO THE CALLER'S ARRAY, WITH
C     BLANKS AT THE END OF THE STRINGS.
C     ------------------------------------------------------------------
         DO 100 K = 1, NRECS
            N = M_LSTCHR(DPNAME(K),10)
            IF(N.NE.10)THEN
               DO 101 J = N+1, 10
                  DPNAME(K)(J:J) = ' '
 101           CONTINUE
            ENDIF
            PROVDR(K) = DPNAME(K)(1:10)
 100     CONTINUE

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

         CALL M_IDSUBSRC(NRECS,PROVDR,SUBSRC,STATUS)

      ELSE

         STATUS = SUCCESS_P

      ENDIF

 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**---------------------------------------------------------------------
