C$$$  SUBPROGRAM DOCUMENTATION BLOCK
C                .      .    .                                       .
C SUBPROGRAM:    MUAPTMOI    GET UPPER-AIR-POINT MOISTURE VARIABLE
C   PRGMMR: M. BARTH         ORG: FSL        DATE: 00-03-27
C
C ABSTRACT: GET UPPER-AIR-POINT DEWPOINT OR DPD OBS FOR ALL STATIONS IN
C   ONE NETCDF FILE FOR ONE TIME AND RETURN AS DEWPOINT, DPD, RH, Q OR 
C   WVMR.
C
C PROGRAM HISTORY LOG:
C   00-03-27  M. BARTH    ORIGINAL VERSION
C   01-05-03  M. BARTH    - CHANGED MRDNUM/MRDCHR TO MGTNUM/MGTCHR
C                         - REMOVED FORCED-CORRECTION OF T OBS BEFORE
C                           USING THEM TO CREATE THE MOISTURE VARIABLE.
C                           WE NOW SIMPLY HONOR THE USER'S CORRECTION
C                           CHOICE AND LET MGTNUM WORRY ABOUT IT.
C   01-07-03  M. BARTH    - HONOR VQC TO SEE IF T_QCD SHOULD BE READ OR
C                           FILLED WITH 'Z'S (NO QC).
C                         - ADDED Q (SPECIFIC HUMIDITY).
C                         - DON'T RETURN A CONVERTED VARIABLE IF THE
C                           *STORED* VARIABLE IS BAD 
C   02-05-29  M. BARTH    RESTRUCTURED TEMPORARY MEMORY ARRAY USAGE
C   03-06-06  M. BARTH    ADDED VALIDITY CHECK BEFORE DOING CONVERSIONS.
C                         (SEE REMARKS BELOW).
C   03-07-03  M. BARTH    - ADDED ABSOLUTE HUMIDITY VARIABLE.
C                         - ADDED RDMTR DATASET.
C   03-10-10  M. BARTH    ADDED ACARS AWIPS DATABASE PROCESSING -- RH
C                         IS THE STORED VARIABLE, NOT TD AS WITH FSL.
C   04-06-17  M. BARTH    ADDED ACARSP DATASET.
C   04-10-16  L. BENJAMIN ADDED NO SUCH VARIABLE CHECK FOR QCA CHECKS
C   05-06-01  L. BENJAMIN ADDED WVMR AND SPLIT ACARS RH VARIABLES FOR 
C                         TAMAR AND NON-TAMDAR DATA SETS
C                         FOR FSL DATA FROM ACARS AND NOPN-TAMDAT, USE
C                         THE RAW WVMR DATA IF IT IS AVAILABLE.  
C   05-09-14  L. BENJAMIN CALULATE Q FOR ACARS DATA FROM WVMR VALUE 
C                         IF AVAILABLE.  NON-TAMDAR ACARS SITES DEFAULT 
C                         VARIABLE IS WVMR.
C   06-07-20  L. BENJAMIN ADDED NO SUCH VARIABLE CHECK FOR SOLE DD 
C                         CHECKS
C   07-11-16  L. BENJAMIN CLEANED UP COMMENTED OUT CODE
C   08-08-13  L. BENJAMIN REMOVED UNUSED FUNCTION
C   08-08-15  L. BENJAMIN ADDED MISS_P AS MISSING DATA ARGUMENT FOR
C                         M_ZTOPSA.
C   09-09-28  M. BARTH    TAMDAR DATA NOW IDENTIFIED AS TYPE 4,7,8;
C                         BEFORE IT WAS ONLY TYPE 4.
C
C USAGE:    CALL MUAPTMOI (VCN,DSN,FNUM,NV,OB,QCDESC,QCAPP,QCRES,STATUS)
C
C   INPUT ARGUMENT LIST:
C     VCN      - I       VARIABLE CODE NUMBER FOR DPD, TD, OR RH
C     DSN      - I       DATASET CODE NUMBER
C     FNUM     - I       FILE NUMBER (INDEX IN COMMON) OF NETCDF FILE
C     NV       - I       NUMBER OF ELEMENTS DIMENSIONED FOR THE VARIABLE
C
C   OUTPUT ARGUMENT LIST:
C     OB       - RA      OBSERVATIONS IN M/K/S UNITS
C     QCDESC   - CA      QC DATA DESCRIPTORS
C     QCAPP    - RA      QC APPLIED WORD (SHOWS CHECKS APPLIED)
C     QCRES    - RA      QC RESULTS WORD (GOOD/BAD FOR EACH CHECK)
C     STATUS   - I       SUCCESS_P OR ERROR CODE
C
C   INPUT FILES:
C     NETCDF FILE OPENED USING DATA STRUCTURES FOR FNUM IN STRCCOM
C
C SUBPROGRAMS CALLED:
C     UNIQUE:    MGTNUM, MGTCHR, M_RH, M_SSH, M_ZTOPSA, M_TD2AH,
C                M_DEWPNT, MUAPTHTP, M_WMR, M_TMR2
C
C REMARKS:
C   - THE RAOB MOISTURE VARIABLE IS STORED AS DPD, THE FSL ACARS
C     MOISTURE VARIABLE IS DEWPOINT, THE AWIPS ACARS DATABASE HAS
C     RH, THE RDMTR DATASET HAS RH AND AH.  WHATEVER IS STORED, 
C     THE CALLER CAN REQUEST THAT DPD, DEWPOINT, RH, Q, WVMR, OR 
C     AH BE RETURNED.
C   - WHEN CALCULATING Q OR WVMR FOR FSL ACARS & RDMTR, NOTE THAT 
C     THE PRESSURE USED IS CALCULATED USING THE STANDARD ATMOSPHERE 
C     CALCULATION.
C   - THE QC INFO THAT'S USED IS FROM THE STORED VARIABLE, EVEN IF
C     WE CONVERT.
C   - IF CONVERSIONS ARE REQUIRED, AND ANY OF THE VARIABLES
C     NEEDED IN THE CONVERSIONS FAILED QC, A MISSING VALUE WILL BE
C     RETURNED.
C   - A VALIDITY CHECK IS PERFORMED BEFORE DOING CERTAIN CONVERSIONS.
C     THIS IS NEEDED TO COVER THE CASE OF *REALLY* BAD DATA FROM THE
C     AWIPS DATABASE, WHICH DOESN'T HAVE ANY QC DONE ON IT, FROM 
C     BLOWING UP A CALCULATION.  THE VALIDITY CHECK LIMITS ARE VERY
C     GROSS, AND ARE DESIGNED SIMPLY TO KEEP CALCULATIONS FROM 
C     BLOWING UP.
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   - SEE madistmp.f FOR AN EXPLANATION OF HOW TEMPORARY STORAGE
C     IS HANDLED (ALL ARRAYS NAMED *TMP*).
C   - ACARS(P)'s WVMR UNITS ARE G/KG WHILE OTHER DATA SETS ARE KG/KG.
C
C ATTRIBUTES:
C   LANGUAGE: FORTRAN-77 + EXTENSIONS
C   MACHINE:  UNIX
C$$$

      SUBROUTINE MUAPTMOI (VCN,DSN,FNUM,NV,OB,QCDESC,QCAPP,QCRES,STATUS)

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

C     ------------------------------------------------------------------
C     ARGUMENTS
C     ------------------------------------------------------------------
      INTEGER VCN,DSN,FNUM,NV,STATUS
      REAL OB(*),QCAPP(*),QCRES(*)
      CHARACTER*1 QCDESC(*)

C     ------------------------------------------------------------------
C     LOCAL
C     ------------------------------------------------------------------
      INTEGER MXTMP
      PARAMETER (MXTMP = MXRAOB_P * MXRAOBLEV_P)
      REAL OBTMP(MXTMP),TTMP(MXTMP),PTMP(MXTMP),TMP,TMP1,E
      REAL M_DEWPNT,M_RH,M_SSH,M_ZTOPSA,M_TD2AH,TD,M_WMR,M_TMR2,MTD,MT
      INTEGER I,LVCN,LEN1REC,CD,DUMMY
      CHARACTER*1 TTMP_QCD(MXTMP),PTMP_QCD(MXTMP)
      REAL DATASRC(MXTMP)
      REAL ACARRLRH(MXTMP)
      REAL ACARWVMR(MXTMP)
      INTEGER N4,NN4


C     ------------------------------------------------------------------
C     TEMPORARY STORAGE DEFINITIONS
C     ------------------------------------------------------------------
      EQUIVALENCE(OBTMP,TMP_L3_N1)
      EQUIVALENCE(TTMP,TMP_L3_N2)
      EQUIVALENCE(PTMP,TMP_L3_N3)
      EQUIVALENCE(TTMP_QCD,TMP_L3_C1)
      EQUIVALENCE(PTMP_QCD,TMP_L3_C2)

C     ------------------------------------------------------------------
C     IF THE REQUESTED VARIABLE IS THE ONE STORED IN THE DATASET, READ
C     IT AND WE'RE DONE.
C     ------------------------------------------------------------------
      CD = DSN - MAX_SFCDSET_P

      IF(VCN.EQ.ACARSRH_VN_P.AND.CD.EQ.ACARS_DS_P
     2     .AND.CDBTYPE.EQ.FSL_DB_P)THEN
         CALL MGTNUM(
     1        VNAME(UAPTRH_VN_P,DSN)(1:VLEN(UAPTRH_VN_P,DSN)),
     1        UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2        UAPT_NRECS(FNUM,CD),MISS_P,ACARRLRH,STATUS)
         IF(STATUS.NE.SUCCESS_P)RETURN

         DO I = 1, UAPT_NRECS(FNUM,CD) * NV
            OB(I) = MISS_P
            IF(ACARRLRH(I).NE.MISS_P)OB(I) = ACARRLRH(I)*100
         ENDDO

C     SET QC TO MISSING
         QCSTATUS = EQCOK_P
         DO 1 I = 1, UAPT_NRECS(FNUM,CD) * NV
            QCAPP(I) = 0
            QCRES(I) = 0
            QCDESC(I) = 'Z'
 1       CONTINUE
C     ------------------------------------------------------------------
C     RETURN downloadRH DATA WITH NO QC.
C     ------------------------------------------------------------------
      ELSE IF(VCN.EQ.UAPTRH_VN_P.AND.CD.EQ.ACARS_DS_P
     2        .AND.CDBTYPE.EQ.FSL_DB_P)THEN
C     ------------------------------------------------------------------
C     FOR ACARS RH DETERMINE WHICH VARIABLE WE USE: downloadRH FOR 
C     TAMDAR AND OR watervaporMR FOR NON-TAMDAR DATA.  GET THE DATA 
C     SOURCE, downloadRH, AND watervaporMR DATA.  POPULATE THE OB
C     VARIABLE DEPENDING ON THE DATA SOURCE.  USE TD QC.
C     ------------------------------------------------------------------


C     ------------------------------------------------------------------
C     GET DATA SOURCE
C     ------------------------------------------------------------------
         CALL MGTNUM(
     1        VNAME(ACARSDSRC_VN_P,DSN)(1:VLEN(ACARSDSRC_VN_P,DSN)),
     2        UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2        UAPT_NRECS(FNUM,CD),MISS_P,DATASRC,STATUS)
         IF(STATUS.NE.SUCCESS_P)RETURN
C     ------------------------------------------------------------------
C     downloadRH (TAMDAR)
C     ------------------------------------------------------------------
         CALL MGTNUM(
     1        VNAME(UAPTRH_VN_P,DSN)(1:VLEN(UAPTRH_VN_P,DSN)),
     1        UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2        UAPT_NRECS(FNUM,CD),MISS_P,ACARRLRH,STATUS)
         IF(STATUS.NE.SUCCESS_P)RETURN

C     ------------------------------------------------------------------
C     waterVaporMR (NON-TAMDAR)
C     NEEDS PRESSURE TO MAKE TD AND TEMPERATURE TO MAKE RH
C     ------------------------------------------------------------------
         CALL MGTNUM(
     1        VNAME(UAPTMR_VN_P,DSN)(1:VLEN(UAPTMR_VN_P,DSN)),
     1        UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2        UAPT_NRECS(FNUM,CD),MISS_P,ACARWVMR,STATUS)
         IF(STATUS.NE.SUCCESS_P)RETURN

         CALL MGTNUM(VNAME(ACARSP_VN_P,DSN)(1:VLEN(ACARSP_VN_P,DSN)),
     1        UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2        UAPT_NRECS(FNUM,CD),MISS_P,PTMP,STATUS)
         IF(STATUS.NE.SUCCESS_P)RETURN

         CALL MGTNUM(VNAME(UAPTT_VN_P,DSN)(1:VLEN(UAPTT_VN_P,DSN)),
     1               UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2               UAPT_NRECS(FNUM,CD),MISS_P,TTMP,STATUS)
         IF(STATUS.NE.SUCCESS_P)RETURN


C     ------------------------------------------------------------------
C     USE DATA SOURCE TO DETERMINE WHICH VALUES TO USE PER STATION
C     ------------------------------------------------------------------
         DO I = 1, UAPT_NRECS(FNUM,CD) * NV
            OB(I) = MISS_P
            IF(DATASRC(I).EQ.4.OR.DATASRC(I).EQ.(7).OR.
     1         DATASRC(I).EQ.(8))THEN
               IF(ACARRLRH(I).NE.MISS_P)OB(I) = ACARRLRH(I)*100
            ELSE
               IF(ACARWVMR(I).NE.MISS_P.AND.PTMP(I).NE.MISS_P.AND.
     1              TTMP(I).NE.MISS_P)THEN
C     ------------------------------------------------------------------
C     CREATE DEW POINT   MR & P --> TD 
C     MR (convert to kg/kg to g/kg)
C     P (convert meters to mB)
C     ------------------------------------------------------------------
                  TMP = M_TMR2(ACARWVMR(I)*1000,M_ZTOPSA(PTMP(I),MISS_P)
     1                 )

                  IF(TMP.NE.MISS_P)TMP = TMP + 273.15
C CREATE RH
                  IF(TMP.NE.MISS_P)OB(I) = M_RH(TTMP(I),TMP,MISS_P)
     1                 * 100.0
               ENDIF
            ENDIF
         ENDDO


C     ASSUME QC OK, SET FOR DIFFERNET CONDITIONS
         QCSTATUS = EQCOK_P

C     ------------------------------------------------------------------
C     USE TD'S QC
C     ------------------------------------------------------------------
         IF(VQC(UAPTTD_VN_P,DSN).EQ.'Q')THEN

            CALL MGTNUM(VNAME(UAPTTD_VN_P,DSN)(1:VLEN(UAPTTD_VN_P,DSN))
     1           //'QCA',UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2           UAPT_NRECS(FNUM,CD),MISS_P,QCAPP,STATUS)
            IF(STATUS.EQ.VAR_NOTINDB_P)THEN
               QCSTATUS = EQCFAILED_P
               STATUS = SUCCESS_P
               DO I = 1, UAPT_NRECS(FNUM,CD) * NV
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ENDDO
            ELSE IF(STATUS.NE.SUCCESS_P)THEN
               RETURN
            ELSE
               CALL MGTNUM(
     1              VNAME(UAPTTD_VN_P,DSN)(1:VLEN(UAPTTD_VN_P,DSN))
     1              //'QCR',UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2              UAPT_NRECS(FNUM,CD),MISS_P,QCRES,STATUS)
               IF(STATUS.NE.SUCCESS_P)RETURN

               CALL MGTCHR(
     1              VNAME(UAPTTD_VN_P,DSN)(1:VLEN(UAPTTD_VN_P,DSN))
     1              //'DD',UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2              UAPT_NRECS(FNUM,CD),QCDESC,LEN1REC,STATUS)
               IF(STATUS.NE.SUCCESS_P)RETURN
            ENDIF
         ELSE
            QCSTATUS = EQCFAILED_P

            DO 11 I = 1, UAPT_NRECS(FNUM,CD) * NV
               QCAPP(I) = 0
               QCRES(I) = 0
               QCDESC(I) = 'Z'
 11          CONTINUE

         ENDIF

      ELSE IF((VCN.EQ.UAPTDPD_VN_P.AND.CD.EQ.RAOB_DS_P).OR.
     1   (VCN.EQ.UAPTTD_VN_P.AND.(CD.EQ.ACARS_DS_P.OR.
     2   CD.EQ.ACARSP_DS_P).AND.CDBTYPE.EQ.FSL_DB_P).OR.
     3   (VCN.EQ.UAPTRH_VN_P.AND.(CD.EQ.ACARS_DS_P.OR.CD.EQ.ACARSP_DS_P)
     4    .AND.CDBTYPE.EQ.AWIPS_DB_P).OR.
     5   (VCN.EQ.UAPTRH_VN_P.AND.CD.EQ.RDMTR_DS_P).OR.
     6       (VCN.EQ.UAPTAH_VN_P.AND.CD.EQ.RDMTR_DS_P))THEN


         CALL MGTNUM(VNAME(VCN,DSN)(1:VLEN(VCN,DSN)),UAPT_NCID(FNUM,CD),
     1               UAPT_RECDIM(FNUM,CD),1,UAPT_NRECS(FNUM,CD),MISS_P,
     2               OB,STATUS)
         IF(STATUS.NE.SUCCESS_P)RETURN

C     ASSUME QC OK, SET FOR DIFFERNET CONDITIONS
         QCSTATUS = EQCOK_P

         IF(VQC(VCN,DSN).EQ.'Q')THEN

            CALL MGTNUM(VNAME(VCN,DSN)(1:VLEN(VCN,DSN))//'QCA',
     1                  UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2                  UAPT_NRECS(FNUM,CD),MISS_P,QCAPP,STATUS)
            IF(STATUS.EQ.VAR_NOTINDB_P)THEN
               QCSTATUS = EQCFAILED_P
               STATUS = SUCCESS_P
               DO I = 1, UAPT_NRECS(FNUM,CD) * NV
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ENDDO
            ELSE IF(STATUS.NE.SUCCESS_P)THEN
               RETURN
            ELSE
               CALL MGTNUM(VNAME(VCN,DSN)(1:VLEN(VCN,DSN))//'QCR',
     1                  UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2                  UAPT_NRECS(FNUM,CD),MISS_P,QCRES,STATUS)
               IF(STATUS.NE.SUCCESS_P)RETURN

               CALL MGTCHR(VNAME(VCN,DSN)(1:VLEN(VCN,DSN))//'DD',
     1                  UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2                  UAPT_NRECS(FNUM,CD),QCDESC,LEN1REC,STATUS)
               IF(STATUS.NE.SUCCESS_P)RETURN
            ENDIF
         ELSE
            QCSTATUS = EQCFAILED_P

            DO 21 I = 1, UAPT_NRECS(FNUM,CD) * NV
               QCAPP(I) = 0
               QCRES(I) = 0
               QCDESC(I) = 'Z'
 21          CONTINUE

         ENDIF

      ELSE

C     ------------------------------------------------------------------
C     THE REQUESTED VARIABLE IS NOT WHAT'S STORED.  READ IN THE ONE
C     THAT'S STORED, ALSO GET THE TEMPERATURE AND/OR PRESSURE, MAKE
C     THEN CONVERT.  NOTE THAT IF ANY OF THE VARIABLES ARE BAD,
C     WE'LL RETURN MISSING VALUES.
C     ------------------------------------------------------------------

C     ------------------------------------------------------------------
C     GET THE STORED VARIABLE AND ITS QC.
C     ------------------------------------------------------------------
         IF(CD.EQ.RAOB_DS_P)THEN
            LVCN = UAPTDPD_VN_P
         ELSE IF((CD.EQ.ACARS_DS_P.OR.CD.EQ.ACARSP_DS_P).AND.
     1           CDBTYPE.EQ.FSL_DB_P)THEN
            LVCN = UAPTTD_VN_P
         ELSE IF((CD.EQ.ACARS_DS_P.OR.CD.EQ.ACARSP_DS_P).AND.
     1           CDBTYPE.EQ.AWIPS_DB_P)THEN
            LVCN = UAPTRH_VN_P
         ELSE IF(CD.EQ.RDMTR_DS_P)THEN
            LVCN = UAPTRH_VN_P
         ENDIF
         CALL MGTNUM(VNAME(LVCN,DSN)(1:VLEN(LVCN,DSN)),
     1               UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2               UAPT_NRECS(FNUM,CD),MISS_P,OBTMP,STATUS)
         IF(STATUS.NE.SUCCESS_P)RETURN

C     ASSUME QC OK, SET FOR DIFFERNET CONDITIONS
         QCSTATUS = EQCOK_P

         IF(VQC(LVCN,DSN).EQ.'Q')THEN

            CALL MGTNUM(VNAME(LVCN,DSN)(1:VLEN(LVCN,DSN))//'QCA',
     1                  UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2                  UAPT_NRECS(FNUM,CD),MISS_P,QCAPP,STATUS)
            IF(STATUS.EQ.VAR_NOTINDB_P)THEN
               QCSTATUS = EQCFAILED_P
               STATUS = SUCCESS_P
               DO I = 1, UAPT_NRECS(FNUM,CD) * NV
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ENDDO
            ELSE IF(STATUS.NE.SUCCESS_P)THEN
               RETURN
            ELSE
               CALL MGTNUM(VNAME(LVCN,DSN)(1:VLEN(LVCN,DSN))//'QCR',
     1                  UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2                  UAPT_NRECS(FNUM,CD),MISS_P,QCRES,STATUS)
               IF(STATUS.NE.SUCCESS_P)RETURN

               CALL MGTCHR(VNAME(LVCN,DSN)(1:VLEN(LVCN,DSN))//'DD',
     1                  UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2                  UAPT_NRECS(FNUM,CD),QCDESC,LEN1REC,STATUS)
               IF(STATUS.NE.SUCCESS_P)RETURN
            ENDIF
         ELSE
            QCSTATUS = EQCFAILED_P

            DO 6 I = 1, UAPT_NRECS(FNUM,CD) * NV
               QCAPP(I) = 0
               QCRES(I) = 0
               QCDESC(I) = 'Z'
 6          CONTINUE

         ENDIF

C     ------------------------------------------------------------------
C     GET THE TEMPERATURE AND ITS QC.
C     ------------------------------------------------------------------
         CALL MGTNUM(VNAME(UAPTT_VN_P,DSN)(1:VLEN(UAPTT_VN_P,DSN)),
     1               UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2               UAPT_NRECS(FNUM,CD),MISS_P,TTMP,STATUS)
         IF(STATUS.NE.SUCCESS_P)RETURN

         IF(VQC(UAPTT_VN_P,DSN).EQ.'Q')THEN

            CALL MGTCHR(VNAME(UAPTT_VN_P,DSN)(1:VLEN(UAPTT_VN_P,DSN))//
     1                  'DD',UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2                  UAPT_NRECS(FNUM,CD),TTMP_QCD,LEN1REC,STATUS)

            IF(STATUS.EQ.VAR_NOTINDB_P)THEN
               QCSTATUS = EQCFAILED_P
               STATUS = SUCCESS_P
               DO 26 I = 1, UAPT_NRECS(FNUM,CD) * NV
                  TTMP_QCD(I) = 'Z'
 26            CONTINUE
            ELSE IF(STATUS.NE.SUCCESS_P)THEN
               RETURN
            ENDIF

         ELSE

            DO 125 I = 1, UAPT_NRECS(FNUM,CD) * NV
               TTMP_QCD(I) = 'Z'
 125        CONTINUE

         ENDIF

C     ------------------------------------------------------------------
C     IF WE'VE READ RH INTO OBTMP, CONVERT IT TO TD, WHICH IS WHAT'S
C     NEEDED FOR ALL THE POSSIBLE CONVERSIONS.
C     ------------------------------------------------------------------
         IF(LVCN.EQ.UAPTRH_VN_P)THEN

            DO I = 1, UAPT_NRECS(FNUM,CD) * NV

               IF(TTMP_QCD(I).EQ.'B'.OR.TTMP_QCD(I).EQ.'X'.OR.
     1            TTMP_QCD(I).EQ.'Q'.OR.TTMP(I).EQ.MISS_P.OR.
     2            QCDESC(I).EQ.'B'.OR.QCDESC(I).EQ.'X'.OR.
     3            QCDESC(I).EQ.'Q'.OR.OBTMP(I).EQ.MISS_P.OR.
     4            TTMP(I).LT.89.0.OR.TTMP(I).GT.422.0.OR.
     5            OBTMP(I).LT.0.0.OR.OBTMP(I).GT.100.0)THEN
                  OBTMP(I) = MISS_P
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ELSE
                  OBTMP(I) = M_DEWPNT(TTMP(I),OBTMP(I),MISS_P)
               ENDIF

            ENDDO

         ENDIF

C     ------------------------------------------------------------------
C     HANDLE CONVERSIONS TO RH.
C     ------------------------------------------------------------------
         IF(VCN.EQ.UAPTRH_VN_P.AND.CDBTYPE.EQ.FSL_DB_P.AND.
     1      (CD.EQ.ACARS_DS_P.OR.CD.EQ.ACARSP_DS_P))THEN

C     ------------------------------------------------------------------
C     FSL ACARS:  T, TD --> RH
C     ------------------------------------------------------------------
            DO 2 I = 1, UAPT_NRECS(FNUM,CD) * NV

               IF(TTMP_QCD(I).EQ.'B'.OR.TTMP_QCD(I).EQ.'X'.OR.
     1            TTMP_QCD(I).EQ.'Q'.OR.TTMP(I).EQ.MISS_P.OR.
     2            QCDESC(I).EQ.'B'.OR.QCDESC(I).EQ.'X'.OR.
     3            QCDESC(I).EQ.'Q'.OR.OBTMP(I).EQ.MISS_P.OR.
     4            TTMP(I).LT.89.0.OR.TTMP(I).GT.422.0.OR.
     5            OBTMP(I).LT.89.0.OR.OBTMP(I).GT.422.0)THEN
                  OB(I) = MISS_P
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ELSE
                  OB(I) = M_RH(TTMP(I),OBTMP(I),MISS_P) * 100.0
               ENDIF

 2          CONTINUE

         ELSE IF(VCN.EQ.UAPTRH_VN_P.AND.CD.EQ.RAOB_DS_P)THEN

C     ------------------------------------------------------------------
C     RAOB:  1) DPD --> TD   2) T, TD --> RH
C     ------------------------------------------------------------------
            DO 3 I = 1, UAPT_NRECS(FNUM,CD) * NV

               IF(TTMP(I).NE.MISS_P.AND.OBTMP(I).NE.MISS_P.AND.
     1            TTMP_QCD(I).NE.'B'.AND.TTMP_QCD(I).NE.'X'.AND.
     2            TTMP_QCD(I).NE.'Q'.AND.QCDESC(I).NE.'B'.AND.
     3            QCDESC(I).NE.'X'.AND.QCDESC(I).NE.'Q'.AND.
     4            TTMP(I).GE.89.0.AND.TTMP(I).LE.422.0.AND.
     5            TTMP(I)-OBTMP(I).GE.89.0.AND.
     6            TTMP(I)-OBTMP(I).LE.422.0)THEN
                  OBTMP(I) = TTMP(I) - OBTMP(I)
                  OB(I) = M_RH(TTMP(I),OBTMP(I),MISS_P) * 100.0
               ELSE
                  OB(I) = MISS_P
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ENDIF

 3          CONTINUE

C     ------------------------------------------------------------------
C     HANDLE CONVERSIONS TO TD.
C     ------------------------------------------------------------------
         ELSE IF(VCN.EQ.UAPTTD_VN_P.AND.CD.EQ.RAOB_DS_P)THEN

C     ------------------------------------------------------------------
C     RAOB:  DPD, T --> TD
C     ------------------------------------------------------------------
            DO 4 I = 1, UAPT_NRECS(FNUM,CD) * NV

               IF(TTMP(I).NE.MISS_P.AND.OBTMP(I).NE.MISS_P.AND.
     1            TTMP_QCD(I).NE.'B'.AND.TTMP_QCD(I).NE.'X'.AND.
     2            TTMP_QCD(I).NE.'Q'.AND.QCDESC(I).NE.'B'.AND.
     3            QCDESC(I).NE.'X'.AND.QCDESC(I).NE.'Q')THEN
                  OB(I) = TTMP(I) - OBTMP(I)
               ELSE
                  OB(I) = MISS_P
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ENDIF

 4          CONTINUE

         ELSE IF(VCN.EQ.UAPTTD_VN_P.AND.LVCN.EQ.UAPTRH_VN_P)THEN

C     ------------------------------------------------------------------
C     WE ALREADY CONVERTED RH->TD ABOVE, JUST MOVE OBTMP TO OB.
C     ------------------------------------------------------------------
            DO I = 1, UAPT_NRECS(FNUM,CD) * NV
               OB(I) = OBTMP(I)
            ENDDO

         ELSE IF(VCN.EQ.UAPTDPD_VN_P)THEN

C     ------------------------------------------------------------------
C     HANDLE CONVERSIONS TO DPD.  T, TD --> DPD
C     ------------------------------------------------------------------
            DO 5 I = 1, UAPT_NRECS(FNUM,CD) * NV

               IF(TTMP(I).NE.MISS_P.AND.OBTMP(I).NE.MISS_P.AND.
     1            TTMP_QCD(I).NE.'B'.AND.TTMP_QCD(I).NE.'X'.AND.
     2            TTMP_QCD(I).NE.'Q'.AND.QCDESC(I).NE.'B'.AND.
     3            QCDESC(I).NE.'X'.AND.QCDESC(I).NE.'Q'.AND.
     4            TTMP(I).GE.89.0.AND.TTMP(I).LE.422.0.AND.
     5            OBTMP(I).GE.89.0.AND.OBTMP(I).LE.422.0)THEN
                  OB(I) = TTMP(I) - OBTMP(I)
               ELSE
                  OB(I) = MISS_P
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ENDIF

 5          CONTINUE

C     ------------------------------------------------------------------
C     HANDLE CONVERSIONS TO Q.
C     ------------------------------------------------------------------

         ELSE IF(VCN.EQ.UAPTQ_VN_P.AND.CD.EQ.RAOB_DS_P)THEN

C     ------------------------------------------------------------------
C     RAOB:  1) DPD --> TD, 2) P, TD --> Q
C     ------------------------------------------------------------------

C     ------------------------------------------------------------------
C     GET THE PRESSURE AND ITS QC.
C     ------------------------------------------------------------------
            CALL MGTNUM(VNAME(RAOBP_VN_P,DSN)(1:VLEN(RAOBP_VN_P,DSN)),
     1                  UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2                  UAPT_NRECS(FNUM,CD),MISS_P,PTMP,STATUS)
            IF(STATUS.NE.SUCCESS_P)RETURN

            IF(VQC(RAOBP_VN_P,DSN).EQ.'Q')THEN

               CALL MGTCHR(VNAME(RAOBP_VN_P,DSN)
     1                     (1:VLEN(RAOBP_VN_P,DSN))//'DD',
     2                     UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2                     UAPT_NRECS(FNUM,CD),PTMP_QCD,LEN1REC,STATUS)

            IF(STATUS.EQ.VAR_NOTINDB_P)THEN
               QCSTATUS = EQCFAILED_P
               STATUS = SUCCESS_P
               DO 22 I = 1, UAPT_NRECS(FNUM,CD) * NV
                  PTMP_QCD(I) = 'Z'
 22            CONTINUE
            ELSE IF(STATUS.NE.SUCCESS_P)THEN
               RETURN
            ENDIF

            ELSE

               DO 1125 I = 1, UAPT_NRECS(FNUM,CD) * NV
                  PTMP_QCD(I) = 'Z'
 1125          CONTINUE

            ENDIF

C     ------------------------------------------------------------------
C     MAKE SURE WE HAVE TD.
C     ------------------------------------------------------------------
            DO 61 I = 1, UAPT_NRECS(FNUM,CD) * NV

               IF(TTMP(I).NE.MISS_P.AND.OBTMP(I).NE.MISS_P.AND.
     1            TTMP_QCD(I).NE.'B'.AND.TTMP_QCD(I).NE.'X'.AND.
     2            TTMP_QCD(I).NE.'Q'.AND.QCDESC(I).NE.'B'.AND.
     3            QCDESC(I).NE.'X'.AND.QCDESC(I).NE.'Q')THEN
                  TD = TTMP(I) - OBTMP(I)
               ELSE
                  TD = MISS_P
               ENDIF

C     ------------------------------------------------------------------
C     NOW TRY TO CONVERT.
C     ------------------------------------------------------------------
               IF(QCDESC(I).EQ.'B'.OR.QCDESC(I).EQ.'X'.OR.
     1            QCDESC(I).EQ.'Q'.OR.TD.EQ.MISS_P.OR.
     2            PTMP_QCD(I).EQ.'B'.OR.PTMP_QCD(I).EQ.'X'.OR.
     3            PTMP_QCD(I).EQ.'Q'.OR.PTMP(I).EQ.MISS_P.OR.
     4            PTMP(I).LE.0.0.OR.PTMP(I).GT.110000.0.OR.
     5            TD.LT.89.0.OR.TD.GT.422.0)THEN
                  OB(I) = MISS_P
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ELSE

C     ------------------------------------------------------------------
C     THE M_SSH FUNCTION EXPECTS P IN MB, TD IN C, AND RETURNS Q IN 
C     G/KG.  WE, ON THE OTHER HAND, ARE "SI-CORRECT", SO WE USE PASCALS, 
C     K, AND KG/KG RESPECTIVELY.  (THIS EXPLAINS THE RIGARAMOLE BELOW.)
C     ------------------------------------------------------------------
                  OB(I) = M_SSH(PTMP(I)/100.,TD-273.15)/1000.
               ENDIF

 61         CONTINUE

C     ------------------------------------------------------------------
C     HANDLE CONVERSIONS TO WVMR.
C     ------------------------------------------------------------------

         ELSE IF(VCN.EQ.UAPTMR_VN_P.AND.CD.EQ.RAOB_DS_P)THEN

C     ------------------------------------------------------------------
C     RAOB:  1) DPD --> TD, 2) P, TD --> WVMR
C     ------------------------------------------------------------------

C     ------------------------------------------------------------------
C     GET THE PRESSURE AND ITS QC.
C     ------------------------------------------------------------------
            CALL MGTNUM(VNAME(RAOBP_VN_P,DSN)(1:VLEN(RAOBP_VN_P,DSN)),
     1                  UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2                  UAPT_NRECS(FNUM,CD),MISS_P,PTMP,STATUS)
            IF(STATUS.NE.SUCCESS_P)RETURN

            IF(VQC(RAOBP_VN_P,DSN).EQ.'Q')THEN

               CALL MGTCHR(VNAME(RAOBP_VN_P,DSN)
     1                     (1:VLEN(RAOBP_VN_P,DSN))//'DD',
     2                     UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2                     UAPT_NRECS(FNUM,CD),PTMP_QCD,LEN1REC,STATUS)
               IF(STATUS.EQ.VAR_NOTINDB_P)THEN
                  QCSTATUS = EQCFAILED_P
                  STATUS = SUCCESS_P
                  DO 23 I = 1, UAPT_NRECS(FNUM,CD) * NV
                     PTMP_QCD(I) = 'Z'
 23               CONTINUE
               ELSE IF(STATUS.NE.SUCCESS_P)THEN
                  RETURN
               ENDIF



            ELSE

               DO 1129 I = 1, UAPT_NRECS(FNUM,CD) * NV
                  PTMP_QCD(I) = 'Z'
 1129          CONTINUE

            ENDIF


C     ------------------------------------------------------------------
C     MAKE SURE WE HAVE TD.
C     ------------------------------------------------------------------
            DO 68 I = 1, UAPT_NRECS(FNUM,CD) * NV

               IF(TTMP(I).NE.MISS_P.AND.OBTMP(I).NE.MISS_P.AND.
     1            TTMP_QCD(I).NE.'B'.AND.TTMP_QCD(I).NE.'X'.AND.
     2            TTMP_QCD(I).NE.'Q'.AND.QCDESC(I).NE.'B'.AND.
     3            QCDESC(I).NE.'X'.AND.QCDESC(I).NE.'Q')THEN
                  TD = TTMP(I) - OBTMP(I)
               ELSE
                  TD = MISS_P
               ENDIF

C     ------------------------------------------------------------------
C     NOW TRY TO CONVERT.
C     ------------------------------------------------------------------
               IF(QCDESC(I).EQ.'B'.OR.QCDESC(I).EQ.'X'.OR.
     1            QCDESC(I).EQ.'Q'.OR.TD.EQ.MISS_P.OR.
     2            PTMP_QCD(I).EQ.'B'.OR.PTMP_QCD(I).EQ.'X'.OR.
     3            PTMP_QCD(I).EQ.'Q'.OR.PTMP(I).EQ.MISS_P.OR.
     4            PTMP(I).LE.0.0.OR.PTMP(I).GT.110000.0.OR.
     5            TD.LT.89.0.OR.TD.GT.422.0)THEN
                  OB(I) = MISS_P
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ELSE

C     ------------------------------------------------------------------
C     THE M_WMR FUNCTION EXPECTS P IN MB, TD IN C, AND RETURNS WVMR IN 
C     G/KG.  WE, ON THE OTHER HAND, ARE "SI-CORRECT", SO WE USE PASCALS, 
C     K, AND KG/KG RESPECTIVELY.  (THIS EXPLAINS THE RIGARAMOLE BELOW.)
C     ------------------------------------------------------------------
                  OB(I) = M_WMR(PTMP(I)/100.,TD-273.15)/1000.

               ENDIF

 68         CONTINUE

         ELSE IF(VCN.EQ.UAPTQ_VN_P.AND. CD.EQ.ACARS_DS_P.AND.
     1           CDBTYPE.EQ.FSL_DB_P)THEN
C     ------------------------------------------------------------------
C     FSL ACARS:
C                TAMDAR 
C                          1) ALTITUDE --> P, 
C                          2) P, TD --> Q
C                NON-TAMDAR 
C                          1) WVMR --> Q
C     
C     ------------------------------------------------------------------


C     ------------------------------------------------------------------
C     GET DATA SOURCE
C     ------------------------------------------------------------------
         CALL MGTNUM(
     1        VNAME(ACARSDSRC_VN_P,DSN)(1:VLEN(ACARSDSRC_VN_P,DSN)),
     2        UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2        UAPT_NRECS(FNUM,CD),MISS_P,DATASRC,STATUS)
         IF(STATUS.NE.SUCCESS_P)RETURN

C     ------------------------------------------------------------------
C     waterVaporMR (NON-TAMDAR)
C     NEEDS PRESSURE TO MAKE TD AND TEMPERATURE TO MAKE RH
C     ------------------------------------------------------------------
            CALL MGTNUM(
     1           VNAME(UAPTMR_VN_P,DSN)(1:VLEN(UAPTMR_VN_P,DSN)),
     1           UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2           UAPT_NRECS(FNUM,CD),MISS_P,ACARWVMR,STATUS)


C     ------------------------------------------------------------------
C     GET THE ALTITUDE AND ITS QC.  WE'LL CONVERT IT TO P WHEN WE USE
C     IT IN THE Q CONVERSION LOOP.
C     ------------------------------------------------------------------
            CALL MGTNUM(VNAME(ACARSALT_VN_P,DSN)
     1                  (1:VLEN(ACARSALT_VN_P,DSN)),UAPT_NCID(FNUM,CD),
     2                  UAPT_RECDIM(FNUM,CD),1,UAPT_NRECS(FNUM,CD),
     3                  MISS_P,PTMP,STATUS)
            IF(STATUS.NE.SUCCESS_P)RETURN

            IF(VQC(ACARSALT_VN_P,DSN).EQ.'Q')THEN

               CALL MGTCHR(VNAME(ACARSALT_VN_P,DSN)
     1                     (1:VLEN(ACARSALT_VN_P,DSN))//'DD',
     2                     UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2                     UAPT_NRECS(FNUM,CD),PTMP_QCD,LEN1REC,STATUS)

               IF(STATUS.EQ.VAR_NOTINDB_P)THEN
                  QCSTATUS = EQCFAILED_P
                  STATUS = SUCCESS_P
                  DO 24 I = 1, UAPT_NRECS(FNUM,CD) * NV
                     PTMP_QCD(I) = 'Z'
 24               CONTINUE
               ELSE IF(STATUS.NE.SUCCESS_P)THEN
                  RETURN
               ENDIF


            ELSE

               DO 2225 I = 1, UAPT_NRECS(FNUM,CD) * NV
                  PTMP_QCD(I) = 'Z'
 2225          CONTINUE

            ENDIF

            DO 171 I = 1, UAPT_NRECS(FNUM,CD) * NV

               OB(I) = MISS_P

               IF(QCDESC(I).EQ.'B'.OR.QCDESC(I).EQ.'X'.OR.
     1              QCDESC(I).EQ.'Q')THEN
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'

               ELSE IF(DATASRC(I).EQ.4.OR.DATASRC(I).EQ.7.OR.
     1                 DATASRC(I).EQ.8)THEN
C     ------------------------------------------------------------------
C     THE M_SSH FUNCTION EXPECTS P IN MB, TD IN C, AND RETURNS Q IN G/G.
C     WE, ON THE OTHER HAND, ARE "SI-CORRECT", USING K FOR TD AND KG/KG
C     FOR Q.  (THIS EXPLAINS THE RIGARAMOLE BELOW.)
C     ------------------------------------------------------------------
                  IF(OBTMP(I).EQ.MISS_P.OR.
     2                 PTMP_QCD(I).EQ.'B'.OR.PTMP_QCD(I).EQ.'X'.OR.
     3                 PTMP_QCD(I).EQ.'Q'.OR.PTMP(I).EQ.MISS_P.OR.
     4                 PTMP(I).LT.-99999.0.OR.OBTMP(I).LT.89.0.OR.
     5                 OBTMP(I).GT.422.0)THEN
                     QCAPP(I) = 0
                     QCRES(I) = 0
                     QCDESC(I) = 'Z'
                  ELSE
                     PTMP(I) = M_ZTOPSA(PTMP(I),MISS_P)
                     OB(I) = M_SSH(PTMP(I),OBTMP(I)-273.15)/1000.
                  ENDIF

               ELSE IF(ACARWVMR(I).NE.MISS_P)THEN
C     ------------------------------------------------------------------
C     COMPUTE THE DIMENSIONLESS SATURATION SPECIFIC HUMIDITY.
C     NO UNITS CONVERSIONS ARE NEEDED, SO NO RIGARAMOLE NEEDED
C     ------------------------------------------------------------------
                  OB(I) = ACARWVMR(I)/(1.+ACARWVMR(I))
               ELSE
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ENDIF

 171        CONTINUE

         ELSE IF(VCN.EQ.UAPTQ_VN_P.AND. CD.EQ.ACARSP_DS_P)THEN

C     ------------------------------------------------------------------
C     FSL/AWIPS ACARSP:
C                          1) ALTITUDE --> P, 
C                          2) P, TD --> Q
C     ------------------------------------------------------------------



C     ------------------------------------------------------------------
C     GET THE ALTITUDE AND ITS QC.  WE'LL CONVERT IT TO P WHEN WE USE
C     IT IN THE Q CONVERSION LOOP.
C     ------------------------------------------------------------------
            CALL MGTNUM(VNAME(ACARSALT_VN_P,DSN)
     1                  (1:VLEN(ACARSALT_VN_P,DSN)),UAPT_NCID(FNUM,CD),
     2                  UAPT_RECDIM(FNUM,CD),1,UAPT_NRECS(FNUM,CD),
     3                  MISS_P,PTMP,STATUS)
            IF(STATUS.NE.SUCCESS_P)RETURN

            IF(VQC(ACARSALT_VN_P,DSN).EQ.'Q')THEN

               CALL MGTCHR(VNAME(ACARSALT_VN_P,DSN)
     1                     (1:VLEN(ACARSALT_VN_P,DSN))//'DD',
     2                     UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2                     UAPT_NRECS(FNUM,CD),PTMP_QCD,LEN1REC,STATUS)

               IF(STATUS.EQ.VAR_NOTINDB_P)THEN
                  QCSTATUS = EQCFAILED_P
                  STATUS = SUCCESS_P
                  DO 25 I = 1, UAPT_NRECS(FNUM,CD) * NV
                     PTMP_QCD(I) = 'Z'
 25               CONTINUE
               ELSE IF(STATUS.NE.SUCCESS_P)THEN
                  RETURN
               ENDIF

            ELSE

               DO 2125 I = 1, UAPT_NRECS(FNUM,CD) * NV
                  PTMP_QCD(I) = 'Z'
 2125          CONTINUE

            ENDIF

            DO 71 I = 1, UAPT_NRECS(FNUM,CD) * NV

               IF(QCDESC(I).EQ.'B'.OR.QCDESC(I).EQ.'X'.OR.
     1            QCDESC(I).EQ.'Q'.OR.OBTMP(I).EQ.MISS_P.OR.
     2            PTMP_QCD(I).EQ.'B'.OR.PTMP_QCD(I).EQ.'X'.OR.
     3            PTMP_QCD(I).EQ.'Q'.OR.PTMP(I).EQ.MISS_P.OR.
     4            PTMP(I).LT.-99999.0.OR.OBTMP(I).LT.89.0.OR.
     5            OBTMP(I).GT.422.0)THEN
                  OB(I) = MISS_P
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ELSE




C     ------------------------------------------------------------------
C     THE M_SSH FUNCTION EXPECTS P IN MB, TD IN C, AND RETURNS Q IN G/G.
C     WE, ON THE OTHER HAND, ARE "SI-CORRECT", USING K FOR TD AND KG/KG
C     FOR Q.  (THIS EXPLAINS THE RIGARAMOLE BELOW.)
C     ------------------------------------------------------------------
                  PTMP(I) = M_ZTOPSA(PTMP(I),MISS_P)
                  OB(I) = M_SSH(PTMP(I),OBTMP(I)-273.15)/1000.
               ENDIF

 71         CONTINUE

         ELSE IF(VCN.EQ.UAPTMR_VN_P.AND.CD.EQ.ACARS_DS_P.AND.
     1           CDBTYPE.EQ.FSL_DB_P)THEN

C     ------------------------------------------------------------------
C     GET DATA SOURCE
C     ------------------------------------------------------------------
         CALL MGTNUM(
     1        VNAME(ACARSDSRC_VN_P,DSN)(1:VLEN(ACARSDSRC_VN_P,DSN)),
     2        UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2        UAPT_NRECS(FNUM,CD),MISS_P,DATASRC,STATUS)
         IF(STATUS.NE.SUCCESS_P)RETURN

C     ------------------------------------------------------------------
C     waterVaporMR (NON-TAMDAR)
C     NEEDS PRESSURE TO MAKE TD AND TEMPERATURE TO MAKE RH
C     ------------------------------------------------------------------
            CALL MGTNUM(
     1           VNAME(UAPTMR_VN_P,DSN)(1:VLEN(UAPTMR_VN_P,DSN)),
     1           UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2           UAPT_NRECS(FNUM,CD),MISS_P,ACARWVMR,STATUS)

C     ------------------------------------------------------------------
C     FSL ACARS: 
C                TAMDAR 
C                          1) ALTITUDE --> P, 
C                          2) P, TD --> WVMR
C                NON-TAMDAR 
C                          1) WVMR
C     
C     ------------------------------------------------------------------

C     ------------------------------------------------------------------
C     GET THE ALTITUDE AND ITS QC.  WE'LL CONVERT IT TO P WHEN WE USE
C     IT IN THE WVMR CONVERSION LOOP.
C     ------------------------------------------------------------------
            CALL MGTNUM(VNAME(ACARSALT_VN_P,DSN)
     1                  (1:VLEN(ACARSALT_VN_P,DSN)),UAPT_NCID(FNUM,CD),
     2                  UAPT_RECDIM(FNUM,CD),1,UAPT_NRECS(FNUM,CD),
     3                  MISS_P,PTMP,STATUS)
            IF(STATUS.NE.SUCCESS_P)RETURN

            IF(VQC(ACARSALT_VN_P,DSN).EQ.'Q')THEN

               CALL MGTCHR(VNAME(ACARSALT_VN_P,DSN)
     1                     (1:VLEN(ACARSALT_VN_P,DSN))//'DD',
     2                     UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2                     UAPT_NRECS(FNUM,CD),PTMP_QCD,LEN1REC,STATUS)
               IF(STATUS.EQ.VAR_NOTINDB_P)THEN
                  QCSTATUS = EQCFAILED_P
                  STATUS = SUCCESS_P
                  DO 27 I = 1, UAPT_NRECS(FNUM,CD) * NV
                     PTMP_QCD(I) = 'Z'
 27               CONTINUE
               ELSE IF(STATUS.NE.SUCCESS_P)THEN
                  RETURN
               ENDIF

            ELSE

               DO 2129 I = 1, UAPT_NRECS(FNUM,CD) * NV
                  PTMP_QCD(I) = 'Z'
 2129          CONTINUE

            ENDIF

            DO 81 I = 1, UAPT_NRECS(FNUM,CD) * NV

               OB(I) = MISS_P

               IF(QCDESC(I).EQ.'B'.OR.QCDESC(I).EQ.'X'.OR.
     1              QCDESC(I).EQ.'Q')THEN
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ELSE IF(DATASRC(I).EQ.4.OR.DATASRC(I).EQ.7.OR.
     1                 DATASRC(I).EQ.8)THEN

                  IF(OBTMP(I).EQ.MISS_P.OR.
     2                 PTMP_QCD(I).EQ.'B'.OR.PTMP_QCD(I).EQ.'X'.OR.
     3                 PTMP_QCD(I).EQ.'Q'.OR.PTMP(I).EQ.MISS_P.OR.
     4                 PTMP(I).LT.-99999.0.OR.OBTMP(I).LT.89.0.OR.
     5                 OBTMP(I).GT.422.0)THEN
                     QCAPP(I) = 0
                     QCRES(I) = 0
                     QCDESC(I) = 'Z'
                  ELSE
C     ------------------------------------------------------------------
C     THE WVMR FUNCTION EXPECTS P IN MB, TD IN C, AND RETURNS WVMR IN 
C     G/KG.  WE, ON THE OTHER HAND, USE K FOR TD AND STORE THE RAW 
C     WVMR UNITS IN KG/KG.  THE ACARS STORED PROCESSED WVMR UNITS ARE 
C     G/KG.  (THIS EXPLAINS THE RIGARAMOLE BELOW.)
C     ------------------------------------------------------------------
                     PTMP(I) = M_ZTOPSA(PTMP(I),MISS_P)
                     OB(I) = M_WMR(PTMP(I),OBTMP(I)-273.15)
                  ENDIF

               ELSE IF(ACARWVMR(I).NE.MISS_P)THEN
C     ------------------------------------------------------------------
C     COMPUTE THE DIMENSIONLESS SATURATION SPECIFIC HUMIDITY.
C     NO UNITS CONVERSIONS ARE NEEDED, SO NO RIGARAMOLE NEEDED
C     ------------------------------------------------------------------
                  OB(I) = ACARWVMR(I)*1000
               ELSE
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ENDIF

 81         CONTINUE

         ELSE IF(VCN.EQ.UAPTMR_VN_P.AND.CD.EQ.ACARSP_DS_P.AND.
     1           CDBTYPE.EQ.FSL_DB_P)THEN

C     ------------------------------------------------------------------
C     GET THE ALTITUDE AND ITS QC.  WE'LL CONVERT IT TO P WHEN WE USE
C     IT IN THE WVMR CONVERSION LOOP.
C     ------------------------------------------------------------------
            CALL MGTNUM(VNAME(ACARSALT_VN_P,DSN)
     1                  (1:VLEN(ACARSALT_VN_P,DSN)),UAPT_NCID(FNUM,CD),
     2                  UAPT_RECDIM(FNUM,CD),1,UAPT_NRECS(FNUM,CD),
     3                  MISS_P,PTMP,STATUS)
            IF(STATUS.NE.SUCCESS_P)RETURN

            IF(VQC(ACARSALT_VN_P,DSN).EQ.'Q')THEN

               CALL MGTCHR(VNAME(ACARSALT_VN_P,DSN)
     1                     (1:VLEN(ACARSALT_VN_P,DSN))//'DD',
     2                     UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2                     UAPT_NRECS(FNUM,CD),PTMP_QCD,LEN1REC,STATUS)

               IF(STATUS.EQ.VAR_NOTINDB_P)THEN
                  QCSTATUS = EQCFAILED_P
                  STATUS = SUCCESS_P
                  DO 28 I = 1, UAPT_NRECS(FNUM,CD) * NV
                     PTMP_QCD(I) = 'Z'
 28               CONTINUE
               ELSE IF(STATUS.NE.SUCCESS_P)THEN
                  RETURN
               ENDIF


            ELSE

               DO 2130 I = 1, UAPT_NRECS(FNUM,CD) * NV
                  PTMP_QCD(I) = 'Z'
 2130          CONTINUE

            ENDIF

            DO 82 I = 1, UAPT_NRECS(FNUM,CD) * NV

               IF(QCDESC(I).EQ.'B'.OR.QCDESC(I).EQ.'X'.OR.
     1            QCDESC(I).EQ.'Q'.OR.OBTMP(I).EQ.MISS_P.OR.
     2            PTMP_QCD(I).EQ.'B'.OR.PTMP_QCD(I).EQ.'X'.OR.
     3            PTMP_QCD(I).EQ.'Q'.OR.PTMP(I).EQ.MISS_P.OR.
     4            PTMP(I).LT.-99999.0.OR.OBTMP(I).LT.89.0.OR.
     5            OBTMP(I).GT.422.0)THEN
                  OB(I) = MISS_P
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ELSE

C     ------------------------------------------------------------------
C     THE WVMR FUNCTION EXPECTS P IN MB, TD IN C, AND RETURNS WVMR IN 
C     G/KG.  WE, ON THE OTHER HAND, USE K FOR TD.  
C     (THIS EXPLAINS THE RIGARAMOLE BELOW.)
C     ------------------------------------------------------------------
                  PTMP(I) = M_ZTOPSA(PTMP(I),MISS_P)
                  OB(I) = M_WMR(PTMP(I),OBTMP(I)-273.15)
               ENDIF

 82         CONTINUE


         ELSE IF(VCN.EQ.UAPTQ_VN_P.AND.CD.EQ.ACARS_DS_P.AND.
     1           CDBTYPE.EQ.AWIPS_DB_P)THEN


C     ------------------------------------------------------------------
C     AWIPS ACARS:  P, TD --> Q
C     ------------------------------------------------------------------

C     ------------------------------------------------------------------
C     GET THE PRESSURE AND ITS QC.  
C     ------------------------------------------------------------------
            CALL MGTNUM(VNAME(ACARSP_VN_P,DSN)
     1                  (1:VLEN(ACARSP_VN_P,DSN)),UAPT_NCID(FNUM,CD),
     2                  UAPT_RECDIM(FNUM,CD),1,UAPT_NRECS(FNUM,CD),
     3                  MISS_P,PTMP,STATUS)
            IF(STATUS.NE.SUCCESS_P)RETURN

            IF(VQC(ACARSP_VN_P,DSN).EQ.'Q')THEN

               CALL MGTCHR(VNAME(ACARSP_VN_P,DSN)
     1                     (1:VLEN(ACARSP_VN_P,DSN))//'DD',
     2                     UAPT_NCID(FNUM,CD),UAPT_RECDIM(FNUM,CD),1,
     2                     UAPT_NRECS(FNUM,CD),PTMP_QCD,LEN1REC,STATUS)

               IF(STATUS.EQ.VAR_NOTINDB_P)THEN
                  QCSTATUS = EQCFAILED_P
                  STATUS = SUCCESS_P
                  DO 29 I = 1, UAPT_NRECS(FNUM,CD) * NV
                     PTMP_QCD(I) = 'Z'
 29               CONTINUE
               ELSE IF(STATUS.NE.SUCCESS_P)THEN
                  RETURN
               ENDIF


            ELSE

               DO I = 1, UAPT_NRECS(FNUM,CD) * NV
                  PTMP_QCD(I) = 'Z'
               ENDDO

            ENDIF

            DO I = 1, UAPT_NRECS(FNUM,CD) * NV

               IF(QCDESC(I).EQ.'B'.OR.QCDESC(I).EQ.'X'.OR.
     1            QCDESC(I).EQ.'Q'.OR.OBTMP(I).EQ.MISS_P.OR.
     2            PTMP_QCD(I).EQ.'B'.OR.PTMP_QCD(I).EQ.'X'.OR.
     3            PTMP_QCD(I).EQ.'Q'.OR.PTMP(I).EQ.MISS_P.OR.
     4            PTMP(I).LT.-99999.0.OR.OBTMP(I).LT.89.0.OR.
     5            OBTMP(I).GT.422.0)THEN
                  OB(I) = MISS_P
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ELSE

C     ------------------------------------------------------------------
C     THE M_SSH FUNCTION EXPECTS P IN MB, TD IN C, AND RETURNS Q IN G/G.
C     WE, ON THE OTHER HAND, ARE "SI-CORRECT", USING K FOR TD AND KG/KG
C     FOR Q.  (THIS EXPLAINS THE RIGARAMOLE BELOW.)
C     ------------------------------------------------------------------
                  OB(I) = M_SSH(PTMP(I)/100.,OBTMP(I)-273.15)/1000.
               ENDIF

            ENDDO

         ELSE IF(VCN.EQ.UAPTQ_VN_P.AND.CD.EQ.RDMTR_DS_P)THEN

C     ------------------------------------------------------------------
C     RDMTR:  1) HEIGHT --> P, 2) P, TD --> Q
C     ------------------------------------------------------------------

C     ------------------------------------------------------------------
C     GET P, CONVERTED FROM HEIGHT.
C     ------------------------------------------------------------------
            CALL MUAPTHTP(RDMTRP_VN_P,DSN,FNUM,.FALSE.,NV,PTMP,PTMP_QCD,
     1                    DUMMY,DUMMY,STATUS)
            IF(STATUS.NE.SUCCESS_P)RETURN

            DO I = 1, UAPT_NRECS(FNUM,CD) * NV

               IF(QCDESC(I).EQ.'B'.OR.QCDESC(I).EQ.'X'.OR.
     1            QCDESC(I).EQ.'Q'.OR.OBTMP(I).EQ.MISS_P.OR.
     2            PTMP_QCD(I).EQ.'B'.OR.PTMP_QCD(I).EQ.'X'.OR.
     3            PTMP_QCD(I).EQ.'Q'.OR.PTMP(I).EQ.MISS_P.OR.
     4            PTMP(I).LT.0.0.OR.PTMP(I).GT.110000.0.OR.
     5            OBTMP(I).LT.89.0.OR.OBTMP(I).GT.422.0)THEN
                  OB(I) = MISS_P
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ELSE

C     ------------------------------------------------------------------
C     THE M_SSH FUNCTION EXPECTS P IN MB, TD IN C, AND RETURNS Q IN G/G.
C     WE, ON THE OTHER HAND, ARE "SI-CORRECT", USING K FOR TD AND KG/KG
C     FOR Q.  (THIS EXPLAINS THE RIGARAMOLE BELOW.)
C     ------------------------------------------------------------------
                  OB(I) = M_SSH(PTMP(I)/100.,OBTMP(I)-273.15)/1000.
               ENDIF

            ENDDO

         ELSE IF(VCN.EQ.UAPTMR_VN_P.AND.CD.EQ.RDMTR_DS_P)THEN

C     ------------------------------------------------------------------
C     RDMTR:  1) HEIGHT --> P, 2) P, TD --> WVMR
C     ------------------------------------------------------------------

C     ------------------------------------------------------------------
C     GET P, CONVERTED FROM HEIGHT.
C     ------------------------------------------------------------------
            CALL MUAPTHTP(RDMTRP_VN_P,DSN,FNUM,.FALSE.,NV,PTMP,PTMP_QCD,
     1                    DUMMY,DUMMY,STATUS)
            IF(STATUS.NE.SUCCESS_P)RETURN

            DO I = 1, UAPT_NRECS(FNUM,CD) * NV

               IF(QCDESC(I).EQ.'B'.OR.QCDESC(I).EQ.'X'.OR.
     1            QCDESC(I).EQ.'Q'.OR.OBTMP(I).EQ.MISS_P.OR.
     2            PTMP_QCD(I).EQ.'B'.OR.PTMP_QCD(I).EQ.'X'.OR.
     3            PTMP_QCD(I).EQ.'Q'.OR.PTMP(I).EQ.MISS_P.OR.
     4            PTMP(I).LT.0.0.OR.PTMP(I).GT.110000.0.OR.
     5            OBTMP(I).LT.89.0.OR.OBTMP(I).GT.422.0)THEN
                  OB(I) = MISS_P
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ELSE

C     ------------------------------------------------------------------
C     THE M_WMR FUNCTION EXPECTS P IN MB, TD IN C, AND RETURNS WVMR IN 
C     G/G.  WE, ON THE OTHER HAND, ARE "SI-CORRECT", USING K FOR TD AND 
C     KG/KG FOR WVMR.  (THIS EXPLAINS THE RIGARAMOLE BELOW.)
C     ------------------------------------------------------------------
                  OB(I) = M_WMR(PTMP(I)/100.,OBTMP(I)-273.15)/1000.
               ENDIF

            ENDDO

C     ------------------------------------------------------------------
C     HANDLE CONVERSIONS TO AH.
C     ------------------------------------------------------------------
         ELSE IF(VCN.EQ.UAPTAH_VN_P.AND.(CD.EQ.ACARS_DS_P.OR.
     1           CD.EQ.ACARSP_DS_P))THEN

C     ------------------------------------------------------------------
C     ACARS:  T, TD --> AH
C     ------------------------------------------------------------------
            DO I = 1, UAPT_NRECS(FNUM,CD) * NV

               IF(TTMP_QCD(I).EQ.'B'.OR.TTMP_QCD(I).EQ.'X'.OR.
     1            TTMP_QCD(I).EQ.'Q'.OR.TTMP(I).EQ.MISS_P.OR.
     2            QCDESC(I).EQ.'B'.OR.QCDESC(I).EQ.'X'.OR.
     3            QCDESC(I).EQ.'Q'.OR.OBTMP(I).EQ.MISS_P.OR.
     4            TTMP(I).LT.89.0.OR.TTMP(I).GT.422.0.OR.
     5            OBTMP(I).LT.89.0.OR.OBTMP(I).GT.422.0)THEN
                  OB(I) = MISS_P
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ELSE
                  OB(I) = M_TD2AH(OBTMP(I),TTMP(I),MISS_P)
               ENDIF

            ENDDO

         ELSE IF(VCN.EQ.UAPTAH_VN_P.AND.CD.EQ.RAOB_DS_P)THEN

C     ------------------------------------------------------------------
C     RAOB:  1) DPD --> TD   2) T, TD --> AH
C     ------------------------------------------------------------------
            DO I = 1, UAPT_NRECS(FNUM,CD) * NV

               IF(TTMP(I).NE.MISS_P.AND.OBTMP(I).NE.MISS_P.AND.
     1            TTMP_QCD(I).NE.'B'.AND.TTMP_QCD(I).NE.'X'.AND.
     2            TTMP_QCD(I).NE.'Q'.AND.QCDESC(I).NE.'B'.AND.
     3            QCDESC(I).NE.'X'.AND.QCDESC(I).NE.'Q'.AND.
     4            TTMP(I).GE.89.0.AND.TTMP(I).LE.422.0.AND.
     5            TTMP(I)-OBTMP(I).GE.89.0.AND.
     6            TTMP(I)-OBTMP(I).LE.422.0)THEN
                  OBTMP(I) = TTMP(I) - OBTMP(I)
                  OB(I) = M_TD2AH(OBTMP(I),TTMP(I),MISS_P)
               ELSE
                  OB(I) = MISS_P
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'
               ENDIF

            ENDDO

         ENDIF

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