C$$$  SUBPROGRAM DOCUMENTATION BLOCK
C                .      .    .                                       .
C SUBPROGRAM:    M_MKDESC    SUMMARIZE QC RESULTS INTO QC DESCRIPTOR
C   PRGMMR: M. BARTH         ORG: FSL        DATE: 99-10-19
C
C ABSTRACT: SUMMARIZE QC RESULTS INTO DESCRIPTORS
C
C PROGRAM HISTORY LOG:
C   99-10-19  M. BARTH    ORIGINAL VERSION (COPIED FROM MSAS & CHANGED)
C   00-03-27  M. BARTH    ADDED UPPER-AIR-POINT DATASET QC CHECKS.
C   04-08-05  M. BARTH    ADDED PROVIDER QC CHECK.
C   08-08-19  L. BENJAMIN CHANGED FMC_P TO MC_P
C
C USAGE:    CALL M_MKDESC (QCAPP,QCRES,QCDESC)
C
C   INPUT ARGUMENT LIST:
C     QCAPP    - I       QC APPLIED WORD
C     QCRES    - I       QC RESULTS WORD
C
C   OUTPUT ARGUMENT LIST:
C     QCDESC   - C       QC DESCRIPTOR SUMMARIZING THE RESULTS
C
C SUBPROGRAMS CALLED:
C     UNIQUE:  - M_CHCKQC
C
C REMARKS:
C     NONE
C
C ATTRIBUTES:
C   LANGUAGE: FORTRAN-77 + EXTENSIONS
C   MACHINE:  UNIX
C$$$






      SUBROUTINE M_MKDESC (QCAPP,QCRES,QCDESC)





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


C     ------------------------------------------------------------------
C     ARGUMENTS
C     ------------------------------------------------------------------
      INTEGER       QCAPP
      INTEGER       QCRES
      CHARACTER*1   QCDESC


C     ------------------------------------------------------------------
C     LOCAL
C     ------------------------------------------------------------------
      INTEGER K,STATUS,NSTAGES
      LOGICAL FAIL(3),APP(3)
      PARAMETER (NSTAGES = 3)


C     *****************************************************************
C     ******************* BEGIN OF MKSMRY *****************************
C     *****************************************************************

C     ------------------------------------------------------------------
C     CREATE SINGLE-CHARACTER QC DESCRIPTORS.
C     ------------------------------------------------------------------
      QCDESC = 'Z'

C     ------------------------------------------------------------------
C     DETERMINE WHICH QC STAGES WERE APPLIED AND FAILED.
C     ------------------------------------------------------------------
      DO 25 K = 1, NSTAGES
         FAIL(K) = .FALSE.
         APP(K) = .FALSE.
 25   CONTINUE

C     ------------------------------------------------------------------
C     STAGE 1:  VALIDITY AND POSITION CONSISTENCY CHECKS
C     ------------------------------------------------------------------
      CALL M_CHCKQC(QCAPP,VC_P,K,STATUS)
      IF(K.NE.0)APP(1) = .TRUE.
      CALL M_CHCKQC(QCRES,VC_P,K,STATUS)
      IF(K.NE.0)FAIL(1) = .TRUE.

      CALL M_CHCKQC(QCAPP,PCC_P,K,STATUS)
      IF(K.NE.0)APP(1) = .TRUE.
      CALL M_CHCKQC(QCRES,PCC_P,K,STATUS)
      IF(K.NE.0)FAIL(1) = .TRUE.


C     ------------------------------------------------------------------
C     STAGE 2:  INTERNAL CONSISTENCY, TEMPORAL CONSISTENCY (BOTH TYPES),
C               MODEL CONSISTENCY (BOTH TYPES), HYDROSTATIC,
C               SUPER ADIABATIC LAPSE RATE, WIND SHEAR,
C               TIME-HEIGHT CONSISTENCY, PROVIDER QUALITY CONTROL
C     ------------------------------------------------------------------
      CALL M_CHCKQC(QCAPP,IC_P,K,STATUS)
      IF(K.NE.0)APP(2) = .TRUE.
      CALL M_CHCKQC(QCRES,IC_P,K,STATUS)
      IF(K.NE.0)FAIL(2) = .TRUE.

      CALL M_CHCKQC(QCAPP,TC_P,K,STATUS)
      IF(K.NE.0)APP(2) = .TRUE.
      CALL M_CHCKQC(QCRES,TC_P,K,STATUS)
      IF(K.NE.0)FAIL(2) = .TRUE.

      CALL M_CHCKQC(QCAPP,TCM_P,K,STATUS)
      IF(K.NE.0)APP(2) = .TRUE.
      CALL M_CHCKQC(QCRES,TCM_P,K,STATUS)
      IF(K.NE.0)FAIL(2) = .TRUE.

      CALL M_CHCKQC(QCAPP,MC_P,K,STATUS)
      IF(K.NE.0)APP(2) = .TRUE.
      CALL M_CHCKQC(QCRES,MC_P,K,STATUS)
      IF(K.NE.0)FAIL(2) = .TRUE.

      CALL M_CHCKQC(QCAPP,PVC_P,K,STATUS)
      IF(K.NE.0)APP(2) = .TRUE.
      CALL M_CHCKQC(QCRES,PVC_P,K,STATUS)
      IF(K.NE.0)FAIL(2) = .TRUE.

      CALL M_CHCKQC(QCAPP,SMC_P,K,STATUS)
      IF(K.NE.0)APP(2) = .TRUE.
      CALL M_CHCKQC(QCRES,SMC_P,K,STATUS)
      IF(K.NE.0)FAIL(2) = .TRUE.

      CALL M_CHCKQC(QCAPP,HC_P,K,STATUS)
      IF(K.NE.0)APP(2) = .TRUE.
      CALL M_CHCKQC(QCRES,HC_P,K,STATUS)
      IF(K.NE.0)FAIL(2) = .TRUE.

      CALL M_CHCKQC(QCAPP,SAC_P,K,STATUS)
      IF(K.NE.0)APP(2) = .TRUE.
      CALL M_CHCKQC(QCRES,SAC_P,K,STATUS)
      IF(K.NE.0)FAIL(2) = .TRUE.

      CALL M_CHCKQC(QCAPP,WSC_P,K,STATUS)
      IF(K.NE.0)APP(2) = .TRUE.
      CALL M_CHCKQC(QCRES,WSC_P,K,STATUS)
      IF(K.NE.0)FAIL(2) = .TRUE.

      CALL M_CHCKQC(QCAPP,THC_P,K,STATUS)
      IF(K.NE.0)APP(2) = .TRUE.
      CALL M_CHCKQC(QCRES,THC_P,K,STATUS)
      IF(K.NE.0)FAIL(2) = .TRUE.

C     ------------------------------------------------------------------
C     STAGE 3:  SPATIAL CONSISTENCY
C     ------------------------------------------------------------------
      CALL M_CHCKQC(QCAPP,SC_P,K,STATUS)
      IF(K.NE.0)APP(3) = .TRUE.
      CALL M_CHCKQC(QCRES,SC_P,K,STATUS)
      IF(K.NE.0)FAIL(3) = .TRUE.


C     ------------------------------------------------------------------
C     NOW HANDLE THIS CASE:  WITH THE DESCRIPTORS AS CURRENTLY DEFINED
C     IF STAGE 3 HAS BEEN APPLIED, WE HAVE TO ASSUME THAT STAGES
C     1 AND 2 HAVE BEEN APPLIED AS WELL.  THIS CAN ALSO BE THE CASE
C     WITH STAGE 2 AND 1, WHERE 2 HAS BEEN APPLIED BUT 1 HASN'T.
C     THEREFORE, MAKE SURE THAT THE HIGHEST STAGE APPLIED INCLUDES
C     THE PREVIOUS STAGES AS WELL.
C     ------------------------------------------------------------------
      IF(APP(2))APP(1) = .TRUE.
      IF(APP(3))APP(2) = .TRUE.


C     ------------------------------------------------------------------
C     CONSOLIDATE THE RESULTS OF THE AUTOMATED QC:
C     - V = PASSED 1,2,3
C     - Q = PASSED 1, FAILED 2 OR 3
C     - S = PASSED 1, 2
C     - C = PASSED 1
C     - X = FAILED 1
C     - Z = NO QC
C
C     * NOTE THAT THE SUBJECTIVE TESTS SHOULD BE DONE BY THE CALLER,
C     AS THEY OVERRIDE THE OTHERS.  OTHERWISE, NO ATTEMPT HAS BEEN MADE
C     TO LOGICALLY TRAVERSE DOWN THIS TREE.  THUS, THE CODE CAN BE
C     MODIFIED WITHOUT WORRYING ABOUT PRECEDENCE OF THE TESTS.
C     ------------------------------------------------------------------
      IF(APP(1).AND.APP(2).AND.APP(3).AND..NOT.FAIL(1).AND.
     1   .NOT.FAIL(2).AND..NOT.FAIL(3))THEN

         QCDESC = 'V'

      ELSE IF(APP(1).AND..NOT.FAIL(1).AND.((APP(2).AND.FAIL(2))
     1        .OR.(APP(3).AND.FAIL(3))))THEN

         QCDESC = 'Q'

      ELSE IF(APP(1).AND.APP(2).AND..NOT.APP(3).AND..NOT.FAIL(1).AND.
     1        .NOT.FAIL(2))THEN

         QCDESC = 'S'

      ELSE IF(APP(1).AND..NOT.APP(2).AND..NOT.APP(3).AND.
     1        .NOT.FAIL(1))THEN

         QCDESC = 'C'

      ELSE IF(APP(1).AND.FAIL(1))THEN

         QCDESC = 'X'

      ELSE IF(.NOT.APP(1).AND..NOT.APP(2).AND..NOT.APP(3))THEN

         QCDESC = 'Z'

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