C$$$  SUBPROGRAM DOCUMENTATION BLOCK
C                .      .    .                                       .
C SUBPROGRAM:    MMAPEXT     EXTRACT DESIRED LEVELS FOR MAP PROFILES
C   PRGMMR: M. BARTH         ORG: FSL        DATE: 02-05-01
C
C ABSTRACT: EXTRACT THE DESIRED LEVEL TYPES FOR MAP PROFILES
C
C PROGRAM HISTORY LOG:
C   02-05-01  M. BARTH    ORIGINAL VERSION
C   06-09-06  L. BENJAMIN CHANGED MAP RASS LEVELS TO 30 FROM 15.
C
C USAGE:    CALL MMAPEXT (VCN,SPT,NRECS,NLEVS,OB,QCDESC,QCAPP,QCRES,
C                         NLEVELS)
C
C   INPUT ARGUMENT LIST:
C     VCN      - I       VARIABLE CODE NUMBER
C     SPT      - I       PROFILE TYPE CODE NUMBER
C     NRECS    - I       NUMBER OF RECORDS (STATIONS)
C     NLEVS    - I       NUMBER OF LEVELS IN DESIRED PROFILE TYPE
C
C   INPUT/OUTPUT ARGUMENT LIST:
C     OB       - RA      OBS
C     QCDESC   - CA      QC DATA DESCRIPTORS
C     QCAPP    - RA      QC APPLIED WORD
C     QCRES    - RA      QC RESULTS WORD
C
C   OUTPUT ARGUMENT LIST:
C     NLEVELS  - IA      ACTUAL NUMBER OF LEVELS IN DESIRED PROFILE
C
C REMARKS:
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   - THIS ROUTINE IS ONLY CALLED WHEN THE USER WANTS ONE MAP MODE
C     AND NOT THE INTEGRATED DATA.
C
C ATTRIBUTES:
C   LANGUAGE: FORTRAN-77 + EXTENSIONS
C   MACHINE:  UNIX
C$$$

      SUBROUTINE MMAPEXT (VCN,SPT,NRECS,NLEVS,OB,QCDESC,QCAPP,QCRES,
     1                    NLEVELS)

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

C     ------------------------------------------------------------------
C     ARGUMENTS
C     ------------------------------------------------------------------
      INTEGER VCN,SPT,NRECS,NLEVS
      REAL OB(*),QCAPP(*),QCRES(*)
      CHARACTER*1 QCDESC(*)
      INTEGER NLEVELS(*)

C     ------------------------------------------------------------------
C     LOCAL
C     ------------------------------------------------------------------
      INTEGER I,J,N,NIN,NOUT,MODE

C     ------------------------------------------------------------------
C     WE HAVE TO DO THIS IN PLACE BY KEEPING ONLY THE DESIRED LEVELS,
C     AND CHANGE THE ACTUAL 2-D ARRAY FROM (MXMAPLEV_P,NRECS) TO
C     (NLEVS,NRECS).
C
C     FIRST OFF, DECIDE WHAT MODE WE WANT AND HOW MANY LEVELS THAT
C     GIVES US.  (MODES 1-N ARE WIND MODES, WITH 50 LEVELS.  MODE
C     4 IS TEMPERATURE, WHICH HAS 15 LEVELS.)
C     ------------------------------------------------------------------
      MODE = ABS(SPT) - 10
      IF(MODE.LE.3)THEN
         NLEVS = 50
      ELSE IF(MODE.EQ.4)THEN
         NLEVS = 30
      ENDIF

      DO 1 J = 1, NRECS

         NLEVELS(J) = NLEVS

         NOUT = (J - 1) * NLEVS
         NIN = (J - 1) * MXMAPLEV_P
         N = 0

         DO 2 I = 1, MXMAPLEV_P

            NIN = NIN + 1

            IF(MAP_LT(I,J).EQ.MODE)THEN

               NOUT = NOUT + 1
               N = N + 1
               OB(NOUT) = OB(NIN)
               QCAPP(NOUT) = QCAPP(NIN)
               QCRES(NOUT) = QCRES(NIN)
               QCDESC(NOUT) = QCDESC(NIN)
               
            ENDIF

 2       CONTINUE

C     ------------------------------------------------------------------
C     FILL MISSING FLAGS INTO THE REST OF THE MODE.
C     ------------------------------------------------------------------
         DO 3 I = N + 1, NLEVS

            NOUT = NOUT + 1
            OB(NOUT) = MISS_P
            QCAPP(NOUT) = 0
            QCRES(NOUT) = 0
            QCDESC(NOUT) = 'Z'
            
 3       CONTINUE

 1    CONTINUE

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