C$$$  SUBPROGRAM DOCUMENTATION BLOCK
C                .      .    .                                       .
C SUBPROGRAM:    MSATRTBL    GET MADIS SATRAD VARIABLES TABLE
C   PRGMMR: L. BENJAMIN      ORG: FSL        DATE: 05-10-25
C
C ABSTRACT: READ TABLE TO GET PARAMETERS SPECIFYING WHAT WE NEED TO
C   KNOW TO READ NETCDF VARIABLES AND PROCESS THEM FOR SATRAD DATASETS.
C
C PROGRAM HISTORY LOG:
C   05-10-25  L. BENJAMIN  ORIGINAL VERSION
C
C USAGE:    CALL MSATRADTBL (SATRADTBL,STATUS)
C
C   INPUT ARGUMENT LIST:
C
C     SATRADTBL- C       FILENAME OF THE SATRAD TABLE
C
C   OUTPUT ARGUMENT LIST:
C     STATUS   - I       SUCCESS_P OR ERROR CODE
C
C   INPUT FILES:
C     SATRADTBL- FILE SPECIFYING THE VARIABLES
C
C SUBPROGRAMS CALLED:
C     UNIQUE:    MERROR, M_GETLUN, M_LSTCHR
C
C REMARKS:
C   - LIMITED ERROR CHECKING IS DONE ON THE TABLE, AS IT'S MEANT TO
C     BE STATIC AND CREATED AT CODE DEVELOPMENT TIME.
C   - THIS ROUTINE REQUIRES SPECIFIC, HARD-WIRED LOGIC CONCERNING
C     DATASETS/DATABASES THAT DO NOT HAVE QC INFO AVAILABLE (E.G.,
C     EVERYTHING EXCEPT HDW1H IN THE AWIPS DATABASE).  WHENEVER THOSE
C     OPTIONS CHANGE, THIS ROUTINE WILL NEED TO BE CHANGED.
C
C ATTRIBUTES:
C   LANGUAGE: FORTRAN-77 + EXTENSIONS
C   MACHINE:  UNIX
C$$$

      SUBROUTINE MSATRADTBL(SATRADTBL,STATUS)

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

C     -----------------------------------------------------------------
C     ARGUMENTS
C     -----------------------------------------------------------------
      CHARACTER*(*) SATRADTBL
      INTEGER       STATUS

C     -----------------------------------------------------------------
C     LOCAL
C     -----------------------------------------------------------------
      INTEGER       LUN,IOSTAT,I,J,K,N,LINE_NUM
      INTEGER       M_LSTCHR
      CHARACTER*70  LINE
      CHARACTER*3   CLINE

C     -----------------------------------------------------------------
C     INITIALIZE DATA STRUCTURES.
C     -----------------------------------------------------------------
      K = MAX_SFCDSET_P + MAX_UAPTDSET_P + MAX_HYDRODSET_P + 
     1     MAX_SATWDSET_P + MAX_SATSDSET_P
      DO 1 I = 1, MAX_VARCOD_P
         DO 2 J = 1, MAX_SATRDSET_P
            VLEN(I,K+J) = 0
 2       CONTINUE
 1    CONTINUE

C     -----------------------------------------------------------------
C     OPEN THE TABLE.  READ IN LINES UNTIL NO MORE.  IF THE FIRST THREE
C     CHARACTERS OF THE LINE ARE AN INTEGER NUMBER, AND THE NEXT FIELD
C     MATCHES ONE OF THE SATRAD DATASET NAMES, PROCESS THE LINE AS A 
C     RECORD DEFINING A VARIABLE.  FIELDS BEING FILLED IN IN MADISCOM 
C     INCLUDE:
C
C     - VDTYPE      NETCDF VARIABLE TYPE ("b" - NCBYTE, "c" - NCCHAR,
C                   "l" or "i" - NCLONG, "s" - NCSHORT, "f" - NCFLOAT,
C                   "d" - NCDOUBLE)
C     - VCLEN       LENGTH OF ONE RECORD IN CHARACTER VARIABLE ARRAYS
C                   TO BE *RETURNED* TO THE CALLER (NOT THE ACTUAL
C                   SIZE OF THE INDIVIDUAL VARIABLE'S RECORD, BUT THE
C                   LARGEST RECORD SIZE OF ANY DATASET WITH THIS
C                   VARIABLE)
C     - VNAME       NETCDF VARIABLE NAME
C     - VLEN        LENGTH OF VARIABLE NAME
C     - VQC         'Q' - HAS QC, ' ' - DOESN'T HAVE QC
C     - VQCSTG      QC STAGE AVAILABLE (O THROUGH 3)
C     - VDB         LOGICAL FLAGS INDICATING WHICH DATABASES MAY HAVE
C                   THE INDIVIDUAL VARIABLES
C     -----------------------------------------------------------------
      CALL M_GETLUN(LUN,1)
      OPEN(UNIT=LUN,FILE=SATRADTBL,STATUS='OLD',IOSTAT=IOSTAT)
      IF(IOSTAT.NE.0)THEN
         CALL MERROR('MSATRADTBL: BIF - OPEN ERROR - SATRADTBL')
         STATUS = BAD_FILE_P
         GO TO 999
      ENDIF

      LINE_NUM = 0

 100  READ(LUN,10,IOSTAT=IOSTAT,END=900)LINE
 10   FORMAT(A)
      LINE_NUM = LINE_NUM + 1
      IF(IOSTAT.NE.0)THEN
         CALL MERROR('MSATRADTBL: BIF - READ ERROR - SATRADTBL')
         STATUS = BAD_FILE_P
         GO TO 999
      ENDIF
      IF(LINE(1:3).NE.'   ')THEN
         DO 3 N = K+1, K+MAX_SATRDSET_P
            IF(LINE(7:26).EQ.SATRDSET_NAME(N-K))THEN

               READ(LINE(1:3),11,IOSTAT=IOSTAT)I
 11            FORMAT(I3)
               IF(IOSTAT.NE.0)GO TO 100
               IF(I.GT.MAX_VARCOD_P)THEN
                  WRITE(CLINE,12,IOSTAT=IOSTAT)LINE_NUM
 12               FORMAT(I3)
                  CALL MERROR('MSATRADTBL: INTV - INVALID VARIABLE '//
     1                        'CODE AT SATRADTBL LINE '//CLINE)
                  STATUS = INV_INTV_P
                  GO TO 999
               ENDIF

               VDTYPE(I,N) = LINE(28:28)
               IF(VDTYPE(I,N).NE.'b'.AND.VDTYPE(I,N).NE.'c'.AND.
     1            VDTYPE(I,N).NE.'l'.AND.VDTYPE(I,N).NE.'i'.AND.
     2            VDTYPE(I,N).NE.'s'.AND.VDTYPE(I,N).NE.'f'.AND.
     3            VDTYPE(I,N).NE.'d')THEN
                  WRITE(CLINE,12,IOSTAT=IOSTAT)LINE_NUM
                  CALL MERROR('MSATRADTBL: INTV - INVALID VARIABLE '//
     1                        'TYPE AT SATRADTBL LINE '//CLINE)
                  STATUS = INV_INTV_P
                  GO TO 999
               ENDIF
               IF(VDTYPE(I,N).EQ.'c')THEN
                  READ(LINE(33:35),11,IOSTAT=IOSTAT)VCLEN(I,N)
                  IF(IOSTAT.NE.0)GO TO 100
               ELSE
                  VCLEN(I,N) = 0
               ENDIF

               VLEN(I,N) = M_LSTCHR(LINE(42:65),24)
               IF(VLEN(I,N).EQ.0)THEN
                  WRITE(CLINE,12,IOSTAT=IOSTAT)LINE_NUM
                  CALL MERROR('MSATRADTBL: INTV - INVALID VARIABLE '//
     1                        'NAME AT SATRADTBL LINE '//CLINE)
                  STATUS = INV_INTV_P
                  GO TO 999
               ENDIF
               VNAME(I,N) = LINE(42:65)

               VQC(I,N) = LINE(67:67)
               IF(VQC(I,N).NE.' '.AND.VQC(I,N).NE.'Q')THEN
                  WRITE(CLINE,12,IOSTAT=IOSTAT)LINE_NUM
                  CALL MERROR('MSATRADTBL: INTV - INVALID QC '//
     1                        'CHARACTER AT SATRADTBL LINE '//CLINE)
                  STATUS = INV_INTV_P
                  GO TO 999
               ENDIF
               READ(LINE(70:70),101,IOSTAT=IOSTAT)VQCSTG(I,SATR_DS_P)
 101           FORMAT(I1)
               IF(IOSTAT.NE.0.OR.VQCSTG(I,SATR_DS_P).LT.0.OR.
     1            VQCSTG(I,SATR_DS_P).GT.MAX_QC_STAGE_P)THEN
                  WRITE(CLINE,12,IOSTAT=IOSTAT)LINE_NUM
                  CALL MERROR('MSATRADTBL: INTV - INVALID QC STAGE '//
     1                        'AT SATRADTBL LINE '//CLINE)
                  STATUS = INV_INTV_P
                  GO TO 999
               ENDIF

C     -----------------------------------------------------------------
C     NOW WIPE OUT THE VQC FLAG FOR ANY DATASETS/DATABASES THAT DON'T
C     HAVE QC.
C     -----------------------------------------------------------------
               IF(CDBTYPE.EQ.AWIPS_DB_P.AND.N.NE.HDW1H_DS_P)
     1            VQC(I,N) = ' '

               GO TO 100

            ENDIF
 3       CONTINUE
      ENDIF
      GO TO 100

 900  STATUS = SUCCESS_P

 999  CALL M_GETLUN(LUN,2)
      CLOSE(UNIT=LUN,IOSTAT=IOSTAT)

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