C$$$  SUBPROGRAM DOCUMENTATION BLOCK
C                .      .    .                                       .
C SUBPROGRAM:    MRDVCODE    READ MADIS VARIABLE CODE NAMES & NUMBERS
C   PRGMMR: M. BARTH         ORG: FSL        DATE: 01-07-26
C
C ABSTRACT: READ TABLE TO GET THE VARIABLE CODE NAMES & NUMBERS FOR
C   AN INDIVIDUAL DATA TYPE
C
C PROGRAM HISTORY LOG:
C   01-07-26  M. BARTH    ORIGINAL VERSION
C
C USAGE:    CALL MRDVCODE (CD, VCNTBL, STATUS)
C
C   INPUT ARGUMENT LIST:
C
C     CD       - I       CURRENT DATA TYPE
C     VCNTBL   - C       FILENAME OF THE VCN TABLE
C
C   OUTPUT ARGUMENT LIST:
C     STATUS   - I       SUCCESS_P OR ERROR CODE
C
C   INPUT FILES:
C     VCNTBL   - FILE SPECIFYING THE VARIABLE NAMES VS. THEIR NUMBERS
C
C SUBPROGRAMS CALLED:
C     UNIQUE:    MERROR, M_GETLUN
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   - THE VARIABLE NAMES ARE USED BY CALLERS TO MGET*, THE NUMBERS
C     ("VCN"S) ARE USED INTERNALLY.
C
C ATTRIBUTES:
C   LANGUAGE: FORTRAN-77 + EXTENSIONS
C   MACHINE:  UNIX
C$$$

      SUBROUTINE MRDVCODE(CD,VCNTBL,STATUS)

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

C     ------------------------------------------------------------------
C     ARGUMENTS
C     ------------------------------------------------------------------
      INTEGER CD,STATUS
      CHARACTER*(*) VCNTBL

C     ------------------------------------------------------------------
C     LOCAL
C     ------------------------------------------------------------------
      INTEGER       LUN,IOSTAT,I,LINE_NUM
      CHARACTER*7   NAME
      CHARACTER*1   TYPE
      CHARACTER*3   CLINE

C     ------------------------------------------------------------------
C     INITIALIZE THE VARIABLE COUNT.
C     ------------------------------------------------------------------
      NVCODE(CD) = 0

C     ------------------------------------------------------------------
C     OPEN THE TABLE.  READ IN LINES UNTIL NO MORE.  FIELDS BEING FILLED
C     IN IN MADISCOM INCLUDE:
C
C     - NVCODE      NUMBER OF VARIABLES FOR THE DATA TYPE            
C     - VCNAME      NAME OF THE VARIABLE (USED BY MGET*)             
C     - VTYPE       TYPE OF THE VARIABLE ('N' - NUMBER, 'C' - CHARACTER)
C     - VCVCN       VARIABLE CODE NUMBER ("VCN") (USED INTERNALLY)
C     ------------------------------------------------------------------
      CALL M_GETLUN(LUN,1)
      OPEN(UNIT=LUN,FILE=VCNTBL,STATUS='OLD',IOSTAT=IOSTAT)
      IF(IOSTAT.NE.0)THEN
         CALL MERROR('MRDVCODE: BIF - OPEN ERROR - VCNTBL')
         STATUS = BAD_FILE_P
         GO TO 999
      ENDIF

      LINE_NUM = 0

 100  READ(LUN,10,IOSTAT=IOSTAT,END=900)NAME,I,TYPE
 10   FORMAT(A7,8X,I3,3X,A1)
      LINE_NUM = LINE_NUM + 1
      IF(IOSTAT.NE.0)THEN
         WRITE(CLINE,12,IOSTAT=IOSTAT)LINE_NUM
 12      FORMAT(I3)
         CALL MERROR('MRDVCODE: BIF - READ ERROR IN VCNTBL AT '//
     1               'LINE '//CLINE)
         STATUS = BAD_FILE_P
         GO TO 999
      ENDIF

      IF(I.LE.0.OR.I.GT.MAX_VARCOD_P)THEN
         WRITE(CLINE,12,IOSTAT=IOSTAT)LINE_NUM
         CALL MERROR('MRDVCODE: INTV - INVALID VARIABLE CODE AT '//
     1               'VCNTBL LINE '//CLINE)
         STATUS = INV_INTV_P
         GO TO 999
      ELSE IF(TYPE.NE.'N'.AND.TYPE.NE.'C')THEN
         WRITE(CLINE,12,IOSTAT=IOSTAT)LINE_NUM
         CALL MERROR('MRDVCODE: INTV - INVALID VARIABLE TYPE AT '//
     1               'VCNTBL LINE '//CLINE)
         STATUS = INV_INTV_P
         GO TO 999
      ENDIF

      NVCODE(CD) = NVCODE(CD) + 1
      VCNAME(NVCODE(CD),CD) = NAME
      VTYPE(NVCODE(CD),CD) = TYPE
      VCVCN(NVCODE(CD),CD) = I

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