C$$$  SUBPROGRAM DOCUMENTATION BLOCK
C                .      .    .                                       .
C SUBPROGRAM:    MRDNUM      READ A NUMERIC NETCDF VARIABLE
C   PRGMMR: M. BARTH         ORG: FSL        DATE: 99-09-16
C
C ABSTRACT: READ A NUMERIC NETCDF VARIABLE ON AN OPEN NETCDF FILE.
C
C PROGRAM HISTORY LOG:
C   99-09-16  M. BARTH    ORIGINAL VERSION
C   00-02-01  M. BARTH    REMOVED UNNEEDED DECLARATION OF STRCCOM.
C   00-02-09  M. BARTH    CHANGED LOCAL ARRAY DIMENSIONS TO USE
C                         MXDATA_P.
C   00-06-29  M. BARTH    CHECK FOR 99999 UNDOCUMENTED MISSING
C                         VALUES IN ACARS TURBULENCE VARIABLES.
C   01-07-06  M. BARTH    - ADDED VAR_NOTINDB_P ERROR RETURN.
C                         - RENAMED VNAME TO VRNAM SO MADISCOM
C                           COULD BE INCLUDED.
C                         - CHECK FOR -99999 UNDOCUMENTED MISSING
C                           VALUES IN AWIPS RAOB DATA.
C                         - CHECK FOR -1 UNDOCUMENTED MISSING
C                           VALUES IN AWIPS PROFILER DATA.
C                         - CHANGED HANDLING OF VRNAM IN MERROR CALLS
C                           TO CONFORM WITH G77 COMPILER
C   02-05-07  M. BARTH    CHECK FOR -9999 UNDOCUMENTED MISSING
C                         VALUES IN AWIPS MAP DATA.
C   02-05-29  M. BARTH    RESTRUCTURED TEMPORARY MEMORY ARRAY USAGE
C   02-07-29  M. BARTH    KEEP NAN'S OUT OF VARIABLES FOR FILLVALS.
C   03-10-10  M. BARTH    - CHECK FOR -99999 IN ALL AWIPS DATABASE
C                           FILES.
C                         - CHECK FOR 99999 UNDOCUMENTED MISSING
C                           VALUE IN ALL FSL AWIPS VARIABLES...
C   05-04-18  L. BENJAMIN REMOVED WRITING ERROR MESSAGE FOR
C                         QCR AND QCA "VAR_NOTINDB_P" CASES.
C   08-06-01  L. BENJAMIN TESTING, MOVED PROCESSING TO MRDNUM1.  CALL 
C                         IT AND RETURN RESULTS WITHOUT THE "N" 
C                         VARIABLE.  KEPT THE CONVERTING AWIPS POES 
C                         SOUNDING TO 40 LEVELS FROM 50 IN THIS 
C                         ROUTINE.

C
C USAGE:    CALL MRDNUM (VRNAM,NCID,RECDIM,STARTR,NRECS,SPVAL,
C                        VDATA,STATUS)
C
C   INPUT ARGUMENT LIST:
C     VRNAM    - C       NETCDF VARIABLE NAME
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     SPVAL    - R       DESIRED MISSING DATA FLAG
C
C   OUTPUT ARGUMENT LIST:
C     VDATA    - RA      REAL ARRAY WITH DATA AND SPVALS FILLED IN
C     STATUS   - I       SUCCESS_P OR ERROR CODE
C
C   INPUT FILES:
C     WHATEVER NETCDF FILE'S OPEN ON NCID.
C
C SUBPROGRAMS CALLED:
C     UNIQUE:    MERROR, M_LSTCHR
C     NETCDF:    NCVID, NCVINQ, NCDINQ, NCVGT, NCAGT, NCAINQ
C
C REMARKS:
C   - THE EXTENDED FORTRAN BYTE DATA TYPE IS USED.  IF THIS DOESN'T
C     COMPILE ON YOUR MACHINE, SEE IF INTEGER*1 IS AVAILABLE
C     AND CHANGE THIS ROUTINE TO USE THAT INSTEAD (THE PROBLEM
C     EXISTS WITH IRIX FORTRAN 90, AND THIS WILL SOLVE IT.)
C   - THIS ROUTINE IS ASSUMED TO BE CALLED BY A HIGHER-LEVEL MADIS
C     ROUTINE, SO NO ERROR CHECKING IS DONE ON THE INPUT VARIABLES.
C   - WHATEVER THE DATA TYPE OF THE VARIABLE, IT'S CONVERTED TO REAL.
C     THEREFORE, THIS ROUTINE SHOULDN'T BE USED FOR DOUBLE PRECISION
C     VARIABLES.
C   - THE TEST FOR -999 AS A MISSING VALUE IS NEEDED BECAUSE SOME
C     MESONET VARIABLES MISTAKENLY HAVE THIS VALUE (INSTEAD OF
C     THE LEGITIMATE MISSING_VALUE ATTRIBUTE).  ALSO NOTE THAT
C     AS THERE ARE NO BYTE DATA TYPES IN MESONET FILES WHERE THIS
C     BUG MAY BE EXTANT, WE DON'T BOTHER WITH THIS LOGIC IN THE
C     BYTE HANDLING BELOW.
C   - YET ANOTHER MESONET BUG CAUSES THE FUNKY USE OF DMISS BELOW.
C     THE MISSING_VALUE ATTRIBUTE MENTIONED IN THE PREVIOUS
C     REMARK ISN'T QUITE AS "LEGITIMATE" AS IT OUGHT TO BE...
C     INSTEAD, FOR FLOAT TYPES IT HAS BEEN SPECIFIED WITH A DOUBLE
C     PRECISION CONSTANT WHEN IT SHOULD BE A FLOAT TYPE.  THE
C     CODE IN THIS ROUTINE SHOULD HANDLE EITHER VERSION.
C   - LOCAL ARRAYS ARE DIMENSIONED TO MXDATA_P.  IF THIS NUMBER
C     PROVES TOO LARGE FOR A GIVEN COMPUTER, THEN PORTIONS OF THE
C     MADIS API (E.G., RAOB) THAT RELY ON THIS VOLUME OF DATA
C     BEING HANDLED IN A SINGLE NETCDF CALL MAY NEED TO BE
C     RESTRUCTURED!
C   - SEE madistmp.f FOR AN EXPLANATION OF HOW TEMPORARY STORAGE
C     IS HANDLED (ALL ARRAYS NAMED *TMP*).
C   - THE TEST FOR -99999 IN ALL AWIPS DATABASE FILES IS TO
C     COMPENSATE FOR THE COMMONLY-USED, UNDOCUMENTED MISSING DATA
C     FLAG THAT SHOWS UP ALL THE TIME IN AWIPS FILES...
C
C ATTRIBUTES:
C   LANGUAGE: FORTRAN-77 + EXTENSIONS
C   MACHINE:  UNIX
C$$$

      SUBROUTINE MRDNUM(VRNAM,NCID,RECDIM,STARTR,NRECS,SPVAL,VDATA,
     1                  STATUS)

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

C     ------------------------------------------------------------------
C     ARGUMENTS
C     ------------------------------------------------------------------
      CHARACTER*(*) VRNAM
      INTEGER NCID,RECDIM,STARTR,NRECS,STATUS
      REAL SPVAL,VDATA(*)

C     ------------------------------------------------------------------
C     LOCAL
C     ------------------------------------------------------------------
      INTEGER N
      INTEGER I,J,K,L,M_LSTCHR
      INTEGER I40,I50

      REAL RDATA(MXDATA_P)
      INTEGER IDATA(MXDATA_P)
      INTEGER*2 I2DATA(MXDATA_P)
      BYTE BDATA(MXDATA_P)

      EQUIVALENCE(RDATA,IDATA,I2DATA,BDATA,TMP_L0_N1)


      CALL MRDNUM1(VRNAM,NCID,RECDIM,STARTR,NRECS,SPVAL,VDATA,
     1     MXDATA_P,RDATA,IDATA,I2DATA,BDATA,N,STATUS)

C     ------------------------------------------------------------------
C     CONVERT AWIPS POES SOUNDING TO 40 LEVELS FROM 50.  THERE IS ONLY 
C     DATA IN THE FIRST 40 LEVELS.
C     ------------------------------------------------------------------
         IF(CDBTYPE.EQ.AWIPS_DB_P .AND. CDTYPE.EQ.SATS_DS_P)THEN
            J = LEN(VRNAM)
            L = M_LSTCHR(VRNAM,J)
            IF(VRNAM(1:L).EQ.'mixingRatio'.OR.
     1        VRNAM(1:L).EQ.'temperature'.OR.
     2        VRNAM(1:L).EQ.'pressure')THEN
               I40 = 0
               DO I = 1, NRECS
                  I50 = (I-1)*50
                  DO K = 1,40
                     I40 = I40 + 1
                     I50 = I50 + 1
                     VDATA(I40) = VDATA(I50)
                  ENDDO
               ENDDO
               DO I = I40+1, N
                  VDATA(I) = SPVAL
               ENDDO

            ENDIF
         ENDIF


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