C$$$  SUBPROGRAM DOCUMENTATION BLOCK
C                .      .    .                                       .
C SUBPROGRAM:    MRAOBNUM    GET A RAOB NUMERIC NETCDF VARIABLE
C   PRGMMR: M. BARTH         ORG: FSL        DATE: 01-05-04
C
C ABSTRACT: GET A RAOB NUMERIC NETCDF VARIABLE FROM COMMON OR FROM
C   AN OPEN NETCDF FILE.
C
C PROGRAM HISTORY LOG:
C   01-05-04  M. BARTH    ORIGINAL VERSION
C   01-07-26  M. BARTH    CHANGED INV_VCN_P STATUS TO INV_INTV_P
C   02-05-30  M. BARTH    ONLY DEAL WITH THE MASTER_P QC CHECK
C                         VALUES IN THE QCDEP ARRAYS
C
C USAGE:    CALL MRAOBNUM (VNAME,NCID,RECDIM,STARTR,NRECS,SPVAL,
C                          VDATA,STATUS)
C
C   INPUT ARGUMENT LIST:
C     VNAME    - 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
C
C REMARKS:
C   ALL RAOB VARIABLES THAT HAVE A LEVEL DIMENSION HAVE ALREADY BEEN
C   READ INTO THE STRCCOM COMMON.  WE'LL PULL OUT THE DESIRED VARIABLE
C   FOR THE FILE CURRENTLY BEING PROCESSED FOR ALL RECORDS.
C
C   IF THE VARIABLE DOESN'T HAVE A LEVEL DIMENSION, WE'LL CALL MRDNUM
C   TO READ IT IN FROM THE FILE.
C
C   THE VARIABLE NAMES SPECIFIED BY THE CALLER ARE FOUND IN RAOBTBL.TXT
C   AND ARE HARD-WIRED INSIDE THIS ROUTINE.
C
C ATTRIBUTES:
C   LANGUAGE: FORTRAN-77 + EXTENSIONS
C   MACHINE:  UNIX
C$$$

      SUBROUTINE MRAOBNUM(VNAME,NCID,RECDIM,STARTR,NRECS,SPVAL,VDATA,
     1                    STATUS)

C     ------------------------------------------------------------------
C     INCLUDES AND COMMONS
C     ------------------------------------------------------------------
      INCLUDE 'IMPLICIT'
      INCLUDE 'MADISCON'
      INCLUDE 'STRCCOM'

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

C     ------------------------------------------------------------------
C     LOCAL PARAMETERS:
C
C     - MAXVAR    NUMBER OF VARIABLES HANDLED BY THIS ROUTINE
C     - MAXCOM    NUMBER OF VARIABLES KEPT IN COMMON (MUST BE IN SLOTS
C                 1-MAXCOM OUT OF 1-MAXVAR)
C     - LTVAR     INDEX OF THE LEVEL TYPE VARIABLE (1-MAXVAR)
C     - NLVAR     INDEX OF THE NUMBER OF LEVELS VARIABLE (1-MAXVAR)
C
C     ALSO NOTE THAT THE FIRST 6 VARIABLES OF VNAMES MUST MATCH THE
C     ORDER OF PROCESSING IN MRAOBINT (E.G., P_RAOB_P=1, HT_RAOB_P=2,
C     ETC.)
C     ------------------------------------------------------------------
      INTEGER MAXVAR,MAXCOM,LTVAR,NLVAR
      PARAMETER (MAXVAR = 10)
      PARAMETER (MAXCOM = 8)
      PARAMETER (LTVAR = 7)
      PARAMETER (NLVAR = 8)

C     ------------------------------------------------------------------
C     LOCAL
C     ------------------------------------------------------------------
      INTEGER IVAR,I,J,K,N,JLAST,VNC(MAXVAR)
      CHARACTER*11 VNAMES(MAXVAR)

C     ------------------------------------------------------------------
C     DATA STATEMENTS (KEEP AT BOTTOM OF DECLARATIONS)
C     ------------------------------------------------------------------
      DATA VNAMES/'pressure','height','temperature','dpd','windDir',
     1            'windSpeed','levelType','numLev','sondTyp','staLon'/
      DATA VNC/8,6,11,3,7,9,9,6,7,6/


C     ------------------------------------------------------------------
C     MAKE SURE THIS IS A VARIABLE HANDLED BY THIS ROUTINE.  THEN IF
C     IT ISN'T IN COMMON, HAVE MRDNUM DO THE WORK.
C     ------------------------------------------------------------------
      DO 1 IVAR = 1, MAXVAR

         IF(VNAME(1:VNC(IVAR)).EQ.VNAMES(IVAR)(1:VNC(IVAR)))GO TO 2

 1    CONTINUE

      STATUS = INV_INTV_P
      CALL MERROR('MRAOBNUM: INTV - INVALID RAOB VARIABLE')
      GO TO 900

 2    IF(IVAR.GT.MAXCOM)THEN

         CALL MRDNUM(VNAME,NCID,RECDIM,STARTR,NRECS,SPVAL,VDATA,STATUS)
         GO TO 900

      ENDIF

C     ------------------------------------------------------------------
C     IF THE VARIABLE IS LEVEL TYPE OR NUMBER OF LEVELS, WE CAN FILL
C     IT IN NOW.  OTHERWISE, WE HAVE TO DECIDE WHETHER THE USER WANTS
C     THE OBS OR ONE OF THE QC STRUCTURES FOR THE VARIABLE.  ALSO NOTE
C     THAT FOR SOUNDINGS (EVERYTHING EXCEPT NUMBER OF LEVELS) WE HAVE
C     TO FILL IN MISSING FLAGS ABOVE THE LAST ACTUAL DATA LEVEL.
C     ------------------------------------------------------------------
      N = LEN(VNAME)
      JLAST = 0

      IF(IVAR.EQ.NLVAR)THEN

         DO 5 I = STARTR, NRECS

            VDATA(I) = RAOB_NLEVELS(I,RAOB_FNUM)

 5       CONTINUE

      ELSE IF(IVAR.EQ.LTVAR)THEN

         J = JLAST + 1

         DO 10 I = STARTR, NRECS

            DO 11 K = 1, RAOB_NLEVELS(I,RAOB_FNUM)

               VDATA(J) = RAOB_LT(K,I,RAOB_FNUM)
               J = J + 1

 11         CONTINUE

            DO 12 K = RAOB_NLEVELS(I,RAOB_FNUM) + 1, MXRAOBLEV_P

               VDATA(J) = MISS_P
               J = J + 1

 12         CONTINUE

            JLAST = JLAST + MXRAOBLEV_P

 10      CONTINUE

      ELSE IF(VNAME(N-2:N).EQ.'QCA')THEN

         J = JLAST + 1

         DO 20 I = STARTR, NRECS

            DO 21 K = 1, RAOB_NLEVELS(I,RAOB_FNUM)

               VDATA(J) = RAOB_QCA(K,I,IVAR,RAOB_FNUM)
               J = J + 1

 21         CONTINUE

            DO 22 K = RAOB_NLEVELS(I,RAOB_FNUM) + 1, MXRAOBLEV_P

               VDATA(J) = MISS_P
               J = J + 1

 22         CONTINUE

            JLAST = JLAST + MXRAOBLEV_P

 20      CONTINUE

      ELSE IF(VNAME(N-2:N).EQ.'QCR')THEN

         J = JLAST + 1

         DO 30 I = STARTR, NRECS

            DO 31 K = 1, RAOB_NLEVELS(I,RAOB_FNUM)

               VDATA(J) = RAOB_QCR(K,I,IVAR,RAOB_FNUM)
               J = J + 1

 31         CONTINUE

            DO 32 K = RAOB_NLEVELS(I,RAOB_FNUM) + 1, MXRAOBLEV_P

               VDATA(J) = MISS_P
               J = J + 1

 32         CONTINUE

            JLAST = JLAST + MXRAOBLEV_P

 30      CONTINUE

      ELSE IF(VNAME(N-2:N).EQ.'QCD')THEN

         J = JLAST + 1

         DO 40 I = STARTR, NRECS

            DO 41 K = 1, RAOB_NLEVELS(I,RAOB_FNUM)

               VDATA(J) = RAOB_QCDEP(K,I,IVAR,RAOB_FNUM)
               J = J + 1

 41         CONTINUE

            DO 42 K = RAOB_NLEVELS(I,RAOB_FNUM) + 1, MXRAOBLEV_P

               VDATA(J) = MISS_P
               J = J + 1

 42         CONTINUE

            JLAST = JLAST + MXRAOBLEV_P

 40      CONTINUE

      ELSE

         J = JLAST + 1

         DO 50 I = STARTR, NRECS

            DO 51 K = 1, RAOB_NLEVELS(I,RAOB_FNUM)

               VDATA(J) = RAOB_OB(K,I,IVAR,RAOB_FNUM)
               J = J + 1

 51         CONTINUE

            DO 52 K = RAOB_NLEVELS(I,RAOB_FNUM) + 1, MXRAOBLEV_P

               VDATA(J) = MISS_P
               J = J + 1

 52         CONTINUE

            JLAST = JLAST + MXRAOBLEV_P

 50      CONTINUE

      ENDIF

      STATUS = SUCCESS_P

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