C$$$  SUBPROGRAM DOCUMENTATION BLOCK
C                .      .    .                                       .
C SUBPROGRAM:    MSFCMOI     GET SFC MOISTURE VARIABLE
C   PRGMMR: M. BARTH         ORG: FSL        DATE: 99-09-20
C
C ABSTRACT: GET SFC MOISTURE OBS FOR ALL STATIONS IN ONE NETCDF
C   FILE FOR ONE TIME, IN THE FORM DESIRED BY THE CALLER.
C
C PROGRAM HISTORY LOG:
C   99-09-20  M. BARTH    ORIGINAL VERSION
C   00-01-25  M. BARTH    FIXED BUG:  QCAPP & QCRES WERE DECLARED
C                         AS INTEGER, NEEDED TO BE REAL.
C   00-03-22  M. BARTH    - RENAMED MXST_P TO MXSFC_P.
C                         - DON'T RETURN OB WHEN TEMPERATURE NEEDED
C                           FOR TD/RH CALCULATION HAS BAD QC.
C   01-05-03  M. BARTH    CHANGED MRDNUM/MRDCHR TO MGTNUM/MGTCHR.
C   01-06-29  M. BARTH    - REMOVED PSOS AND GSOS DATASETS.
C                         - HONOR VQC TO SEE IF T_QCD SHOULD BE READ
C                           OR FILLED WITH 'Z'S (NO QC).
C                         - FOR MESO, ASSIGN RESULTS OF TD QC TO RH
C                           (IF AVAIL) EVEN IF RH IS THE STORED
C                           VARIABLE (SEE REMARKS).
C                         - DON'T RETURN A CONVERTED VARIABLE IF THE
C                           *STORED* VARIABLE IS BAD 
C
C   01-07-20  M. BARTH    RENAMED FROM MSFCTDRH AND ADDED Q & DPD FORMS.
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   04-03-22  M. BARTH    ADDED COOP DATASET AND ITS HOURLY-AVERAGED
C                         MOISTURE VARIABLES (AS WELL AS THE REGULAR
C                         ONES).
C   04-10-16  L. BENJAMIN ADDED NO SUCH VARIABLE CHECK FOR QCA CHECKS
C   05-06-01  L. BENJAMIN ADDED WVMR
C   06-07-20  L. BENJAMIN ADDED NO SUCH VARIABLE CHECK FOR SOLE DD 
C                         CHECKS
C   06-08-01  L. BENJAMIN ADDED URBANET MOI VARIABLES
C   07-11-21  L. BENJAMIN REMOVED COMMENTED OUT CODE
C   09-08-31  L. BENJAMIN ADDED ARCHIVE TEMPERATURE PROCESSING
C   10-08-05  M. BARTH    FIXED BUG WHERE CRN RH WAS RETURNED WHEN
C                         THE USER ASKED FOR TD
C
C USAGE:    CALL MSFCMOI (VCN,DSN,FNUM,OB,QCDESC,QCAPP,QCRES,STATUS)
C
C   INPUT ARGUMENT LIST:
C     VCN      - I       VARIABLE CODE NUMBER FOR TD, RH, Q, DPD, AH,
C                        OR HOURLY AVERAGED VERSIONS OF THOSE
C     DSN      - I       DATASET CODE NUMBER
C     FNUM     - I       FILE NUMBER (INDEX IN COMMON) OF NETCDF FILE
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:    M_DEWPNT, MGTNUM, MGTCHR, M_RH, MSFCPRS, M_SSH,
C                M_RH2AH, M_TD2AH, M_WMR
C
C REMARKS:
C   - THE STAGE 3 SPATIAL CONSISTENCY CHECK IS ONLY APPLIED TO TD,
C     SO IF THAT VARIABLE IS AVAILABLE, ITS QC WILL BE USED 
C     REGARDLESS OF THE FORM REQUESTED BY THE USER.
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   - WHEN CALCULATING Q FOR COOP, NOTE THAT THE PRESSURE 
C     USED IS CALCULATED USING THE STANDARD ATMOSPHERE CALCULATION.
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
C ATTRIBUTES:
C   LANGUAGE: FORTRAN-77 + EXTENSIONS
C   MACHINE:  UNIX
C$$$

      SUBROUTINE MSFCMOI (VCN,DSN,FNUM,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,STATUS
      REAL OB(*),QCAPP(*),QCRES(*)
      CHARACTER*1 QCDESC(*)

C     ------------------------------------------------------------------
C     LOCAL
C     ------------------------------------------------------------------
      REAL OBTMP(MXSFC_P,2),TTMP(MXSFC_P),PTMP(MXSFC_P)
      REAL TTMP_QCA(MXSFC_P),TTMP_QCR(MXSFC_P)
      REAL M_DEWPNT,M_RH,M_SSH,TD,M_RH2AH,M_TD2AH,M_WMR
      INTEGER I,LVCN,LEN1REC,TVCN
      REAL QCATMP(MXSFC_P,2),QCRTMP(MXSFC_P,2)
      REAL PTMP_QCA(MXSFC_P),PTMP_QCR(MXSFC_P)
      REAL OBL,OBH
      CHARACTER*1 QCDTMP(MXSFC_P,2)
      CHARACTER*1 TTMP_QCD(MXSFC_P),PTMP_QCD(MXSFC_P)

      LOGICAL COOP1H

C     ------------------------------------------------------------------
C     TEMPORARY STORAGE DEFINITIONS
C     ------------------------------------------------------------------
      EQUIVALENCE(OBTMP,TMP_L3_N1)
      EQUIVALENCE(QCATMP,TMP_L3_N2)
      EQUIVALENCE(QCRTMP,TMP_L3_N3)
      EQUIVALENCE(QCDTMP,TMP_L3_C1)
      EQUIVALENCE(TTMP,TMP_L3_N1(MXSFC_P*2+1))
      EQUIVALENCE(TTMP_QCA,TMP_L3_N2(MXSFC_P*2+1))
      EQUIVALENCE(TTMP_QCR,TMP_L3_N2(MXSFC_P*3+1))
      EQUIVALENCE(PTMP,TMP_L3_N1(MXSFC_P*3+1))
      EQUIVALENCE(PTMP_QCA,TMP_L3_N2(MXSFC_P*2+1))
      EQUIVALENCE(PTMP_QCR,TMP_L3_N2(MXSFC_P*3+1))
      EQUIVALENCE(TTMP_QCD,TMP_L3_C1(MXSFC_P*2+1))
      EQUIVALENCE(PTMP_QCD,TMP_L3_C1(MXSFC_P*3+1))

C     ------------------------------------------------------------------
C     IF THE DATASET ISN'T MESONET, AND THE REQUESTED VARIABLE IS THE
C     ONE STORED IN THE DATASET, READ IT AND WE'RE DONE.
C     ------------------------------------------------------------------
      IF((VCN.EQ.SFCTD_VN_P.AND.DSN.NE.MESONET_DS_P.AND.
     1    DSN.NE.COOP_DS_P.AND.DSN.NE.URBANET_DS_P.AND.
     2    DSN.NE.CRN_DS_P).OR.(DSN.EQ.COOP_DS_P.AND.
     3    (VCN.EQ.SFCRH_VN_P.OR.VCN.EQ.RH1H_VN_P)).OR.
     4     (DSN.EQ.URBANET_DS_P.AND.
     5    (VCN.EQ.SFCRH_VN_P.OR.VCN.EQ.RH15M_VN_P
     6     .OR.VCN.EQ.RH1HCHG_VN_P)).OR.(VCN.EQ.SFCRH_VN_P.AND.
     7     DSN.EQ.CRN_DS_P))THEN

         CALL MGTNUM(VNAME(VCN,DSN)(1:VLEN(VCN,DSN)),SFC_NCID(FNUM),
     1               SFC_RECDIM(FNUM),1,SFC_NRECS(FNUM),MISS_P,OB,
     2               STATUS)
         IF(STATUS.NE.SUCCESS_P)RETURN

C     ASSUME QC FAILED, SET FOR DIFFERNET CONDITIONS
         QCSTATUS = EQCFAILED_P
         IF(VQC(VCN,DSN).EQ.'Q')THEN

            CALL MGTNUM(VNAME(VCN,DSN)(1:VLEN(VCN,DSN))//'QCA',
     1                  SFC_NCID(FNUM),SFC_RECDIM(FNUM),1,
     2                  SFC_NRECS(FNUM),MISS_P,QCAPP,STATUS)
            IF(STATUS.EQ.VAR_NOTINDB_P)THEN
               STATUS = SUCCESS_P
               DO I = 1, SFC_NRECS(FNUM)
                  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                  SFC_NCID(FNUM),SFC_RECDIM(FNUM),1,
     2                  SFC_NRECS(FNUM),MISS_P,QCRES,STATUS)
               IF(STATUS.NE.SUCCESS_P)RETURN

               CALL MGTCHR(VNAME(VCN,DSN)(1:VLEN(VCN,DSN))//'DD',
     1                  SFC_NCID(FNUM),SFC_RECDIM(FNUM),1,
     2                  SFC_NRECS(FNUM),QCDESC,LEN1REC,STATUS)
               IF(STATUS.NE.SUCCESS_P)RETURN
               QCSTATUS = EQCOK_P
            ENDIF
         ELSE

            DO 1 I = 1, SFC_NRECS(FNUM)
               QCAPP(I) = 0
               QCRES(I) = 0
               QCDESC(I) = 'Z'
 1          CONTINUE

         ENDIF

      ELSE IF(DSN.NE.MESONET_DS_P)THEN

C     ------------------------------------------------------------------
C     THE REQUESTED VARIABLE IS NOT WHAT'S STORED (TD FOR ALL BUT COOP,
C     CRN AND URBANET.  FOR COOP EITHER RH OR RH1H, FOR CRN RH, AND FOR 
C     URBANET EITHER RH OR RH15M OR RHCHG ).  READ IN THE ONE THAT'S 
C     STORED, ALSO GET THE TEMPERATURE, AND GET THE PRESSURE IF Q IS 
C     THE DESIRED FORM, THEN CONVERT.  NOTE THAT IF THE TEMPERATURE (OR 
C     P) IS BAD, WE'LL RETURN A MISSING FLAG FOR THE MOISTURE VARIABLE.
C     ------------------------------------------------------------------
C
C     ------------------------------------------------------------------
C     GET TD (ALL BUT COOP, CRN AND URBANET) 
C     OR RH/RH1H FOR COOP, RH FOR CRN, AND ITS QC.
C     OR RH/RH15M/RHCHG FOR URBANET AND ITS QC.
C     ------------------------------------------------------------------
         IF(DSN.NE.COOP_DS_P.AND.DSN.NE.URBANET_DS_P.AND.
     1      DSN.NE.CRN_DS_P)THEN
            LVCN = SFCTD_VN_P
            TVCN = SFCT_VN_P
            OBL = 89.0
            OBH = 422.0

         ELSE IF(DSN.EQ.COOP_DS_P)THEN
            IF(VCN.EQ.TD1H_VN_P.OR.VCN.EQ.Q1H_VN_P.OR.
     1           VCN.EQ.DPD1H_VN_P.OR.VCN.EQ.AH1H_VN_P)THEN
               LVCN = RH1H_VN_P
               TVCN = T1H_VN_P
               COOP1H = .TRUE.
               OBL = 0.0
               OBH = 100.0
            ELSE
               LVCN = SFCRH_VN_P
               TVCN = SFCT_VN_P
               COOP1H = .FALSE.
               OBL = 0.0
               OBH = 100.0
            ENDIF
         ELSE IF(DSN.EQ.CRN_DS_P)THEN
            LVCN = SFCRH_VN_P
            TVCN = SFCT_VN_P
            OBL = 0.0
            OBH = 100.0
         ELSE IF(DSN.EQ.URBANET_DS_P)THEN
            IF(VCN.EQ.TD15M_VN_P.OR.VCN.EQ.Q15M_VN_P.OR.
     1           VCN.EQ.DPD15M_VN_P.OR.VCN.EQ.AH15M_VN_P
     2           .OR.VCN.EQ.WVMR15M_VN_P)THEN
               LVCN = RH15M_VN_P
               TVCN = T15M_VN_P
               OBL = 0.0
               OBH = 100.0
            ELSE IF(VCN.EQ.TD1HCHG_VN_P.OR.VCN.EQ.Q1HCHG_VN_P.OR.
     1           VCN.EQ.DPD1HCHG_VN_P.OR.VCN.EQ.AH1HCHG_VN_P
     2           .OR.VCN.EQ.WVMR1HCHG_VN_P
     3           )THEN
               LVCN = RH1HCHG_VN_P
               TVCN = T1HCHG_VN_P
               OBL = 0.0
               OBH = 100.0
            ELSE
               LVCN = SFCRH_VN_P
               TVCN = SFCT_VN_P
               OBL = 0.0
               OBH = 100.0
            ENDIF
         ENDIF

         CALL MGTNUM(VNAME(LVCN,DSN)(1:VLEN(LVCN,DSN)),SFC_NCID(FNUM),
     1           SFC_RECDIM(FNUM),1,SFC_NRECS(FNUM),MISS_P,OBTMP,
     1           STATUS)
         IF(STATUS.NE.SUCCESS_P)RETURN

C     ASSUME QC FAILED, SET FOR DIFFERNET CONDITIONS
         QCSTATUS = EQCFAILED_P

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

            CALL MGTNUM(VNAME(LVCN,DSN)(1:VLEN(LVCN,DSN))//'QCA',
     1           SFC_NCID(FNUM),SFC_RECDIM(FNUM),1,
     2           SFC_NRECS(FNUM),MISS_P,QCAPP,STATUS)
            IF(STATUS.EQ.VAR_NOTINDB_P)THEN
               STATUS = SUCCESS_P
               DO I = 1, SFC_NRECS(FNUM)
                  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              SFC_NCID(FNUM),SFC_RECDIM(FNUM),1,
     2              SFC_NRECS(FNUM),MISS_P,QCRES,STATUS)
               IF(STATUS.NE.SUCCESS_P)RETURN
               
               CALL MGTCHR(VNAME(LVCN,DSN)(1:VLEN(LVCN,DSN))//'DD',
     1              SFC_NCID(FNUM),SFC_RECDIM(FNUM),1,
     2              SFC_NRECS(FNUM),QCDESC,LEN1REC,STATUS)
               IF(STATUS.NE.SUCCESS_P)RETURN
               QCSTATUS = EQCOK_P
            ENDIF
         ELSE
               
            DO 6 I = 1, SFC_NRECS(FNUM)
               QCAPP(I) = 0
               QCRES(I) = 0
               QCDESC(I) = 'Z'
 6          CONTINUE
            
         ENDIF
         

C     ------------------------------------------------------------------
C     UNLESS WE'RE HERE TO GET Q OR WVMR - AND WE ALREADY HAVE TD (E.G., 
C     NOT COOP, CRN OR URBANET), GET T AND ITS QC (ONLY NEED THE 
C     DESCRIPTORS).  
C     ------------------------------------------------------------------
         IF((VCN.NE.SFCQ_VN_P.AND.VCN.NE.SFCMR_VN_P).OR.
     2        DSN.EQ.COOP_DS_P.OR.DSN.EQ.CRN_DS_P.OR.
     3        DSN.EQ.URBANET_DS_P)THEN

C     ------------------------------------------------------------------
C     SPECIAL CASE FOR TEMPERATURE PROCESSING
C     ------------------------------------------------------------------
            IF(TVCN.EQ.SFCT_VN_P.AND.(DSN.EQ.CRN_DS_P.OR.
     3           DSN.EQ.HCN_DS_P))THEN
               CALL MSFCART (TVCN,DSN,FNUM,TTMP,TTMP_QCD,TTMP_QCA,
     1              TTMP_QCR,STATUS)
               IF(STATUS.NE.SUCCESS_P)RETURN
            ELSE
               CALL MGTNUM(VNAME(TVCN,DSN)(1:VLEN(TVCN,DSN)),
     1              SFC_NCID(FNUM),SFC_RECDIM(FNUM),1,
     2              SFC_NRECS(FNUM),MISS_P,TTMP,STATUS)
               IF(STATUS.NE.SUCCESS_P)RETURN

               IF(VQC(TVCN,DSN).EQ.'Q')THEN
               
                  CALL MGTCHR(VNAME(TVCN,DSN)(1:VLEN(TVCN,DSN))//
     1                 'DD',SFC_NCID(FNUM),SFC_RECDIM(FNUM),1,
     2                 SFC_NRECS(FNUM),TTMP_QCD,LEN1REC,STATUS)

                  IF(STATUS.EQ.VAR_NOTINDB_P)THEN
                     QCSTATUS = EQCFAILED_P
                     STATUS = SUCCESS_P
                     DO  23 I = 1, SFC_NRECS(FNUM)
                        TTMP_QCD(I) = 'Z'
 23                  CONTINUE
                  ELSE IF(STATUS.NE.SUCCESS_P)THEN
                     RETURN
                  ENDIF

               ELSE

                  DO 125 I = 1, SFC_NRECS(FNUM)
                     TTMP_QCD(I) = 'Z'
 125              CONTINUE

               ENDIF
            ENDIF

         ENDIF

C     ------------------------------------------------------------------
C     HANDLE THE CONVERSION FOR RH.
C     ------------------------------------------------------------------
         IF(VCN.EQ.SFCRH_VN_P.OR.VCN.EQ.RH15M_VN_P.OR.
     1        VCN.EQ.RH1HCHG_VN_P)THEN

            DO 2 I = 1, SFC_NRECS(FNUM)

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

 2          CONTINUE

C     ------------------------------------------------------------------
C     HANDLE THE CONVERSION FOR DPD.
C     ------------------------------------------------------------------
         ELSE IF((VCN.EQ.SFCDPD_VN_P.OR.VCN.EQ.DPD1H_VN_P.OR.
     1           VCN.EQ.DPD15M_VN_P.OR.VCN.EQ.DPD1HCHG_VN_P).AND.
     2           DSN.NE.CRN_DS_P)THEN

            DO 3 I = 1, SFC_NRECS(FNUM)

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

 3          CONTINUE

         ELSE IF(DSN.EQ.CRN_DS_P.AND.VCN.EQ.SFCDPD_VN_P)THEN

            DO I = 1, SFC_NRECS(FNUM)

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

C     TTMP HAS T, OBTMP HAS RH, CREATE DEWPOINT THEN DEPRESSION.

                  OB(I) = TTMP(I) - M_DEWPNT(TTMP(I),OBTMP(I,1),MISS_P)

               ENDIF

            ENDDO

C     ------------------------------------------------------------------
C     HANDLE THE CONVERSION FOR TD.
C     ------------------------------------------------------------------
         ELSE IF(VCN.EQ.SFCTD_VN_P.OR.VCN.EQ.TD1H_VN_P.OR.
     1           VCN.EQ.TD15M_VN_P.OR.VCN.EQ.TD1HCHG_VN_P)THEN

            DO I = 1, SFC_NRECS(FNUM)

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

            ENDDO

C     ------------------------------------------------------------------
C     HANDLE THE CONVERSION FOR Q.  FIRST, GET P AND ITS QC.  NOTE THAT 
C     WE HAVE TO CALL MSFCPRS BECAUSE P MAY NEED TO BE CONVERTED FROM 
C     ALT, AND FOR COOP, P IS CALCULATED FROM STATION ELEVATION.  ALSO,
C     IF THIS IS COOP, WE HAVE TO GET TD INTO OBTMP FIRST.
C     ------------------------------------------------------------------
         ELSE IF(VCN.EQ.SFCQ_VN_P.OR.VCN.EQ.Q1H_VN_P.OR.
     1           VCN.EQ.Q15M_VN_P.OR.VCN.EQ.Q1HCHG_VN_P)THEN

            CALL MSFCPRS(SFCP_VN_P,DSN,FNUM,PTMP,PTMP_QCD,PTMP_QCA,
     1                   PTMP_QCR,STATUS)
            IF(STATUS.NE.SUCCESS_P)RETURN

            IF(DSN.EQ.COOP_DS_P.OR.DSN.EQ.URBANET_DS_P
     1         .OR.DSN.EQ.CRN_DS_P)THEN

               DO I = 1, SFC_NRECS(FNUM)

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

               ENDDO

            ENDIF

            DO 4 I = 1, SFC_NRECS(FNUM)

               IF(QCDESC(I).EQ.'B'.OR.QCDESC(I).EQ.'X'.OR.
     1            QCDESC(I).EQ.'Q'.OR.OBTMP(I,1).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            OBTMP(I,1).LT.89.0.OR.OBTMP(I,1).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.,OBTMP(I,1)-273.15)/1000.

               ENDIF

 4          CONTINUE

C     ------------------------------------------------------------------
C     HANDLE THE CONVERSION FOR WVMR.  FIRST, GET P AND ITS QC.  NOTE 
C     THAT  WE HAVE TO CALL MSFCPRS BECAUSE P MAY NEED TO BE CONVERTED 
C     FROM  ALT, AND FOR COOP/CRN, P IS CALCULATED FROM STATION 
C     ELEVATION.  ALSO, IF THIS IS COOP/CRN, WE HAVE TO GET TD INTO 
C     OBTMP FIRST.
C     ------------------------------------------------------------------
         ELSE IF(VCN.EQ.SFCMR_VN_P.OR.VCN.EQ.WVMR15M_VN_P.OR.
     1           VCN.EQ.WVMR1HCHG_VN_P)THEN

            CALL MSFCPRS(SFCP_VN_P,DSN,FNUM,PTMP,PTMP_QCD,PTMP_QCA,
     1                   PTMP_QCR,STATUS)
            IF(STATUS.NE.SUCCESS_P)RETURN

            IF(DSN.EQ.COOP_DS_P.OR.DSN.EQ.URBANET_DS_P
     1         .OR.DSN.EQ.CRN_DS_P)THEN

               DO I = 1, SFC_NRECS(FNUM)

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

               ENDDO

            ENDIF

            DO 14 I = 1, SFC_NRECS(FNUM)

               IF(QCDESC(I).EQ.'B'.OR.QCDESC(I).EQ.'X'.OR.
     1            QCDESC(I).EQ.'Q'.OR.OBTMP(I,1).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            OBTMP(I,1).LT.89.0.OR.OBTMP(I,1).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_WMR(PTMP(I)/100.,OBTMP(I,1)-273.15)/1000.

               ENDIF

 14          CONTINUE

C     ------------------------------------------------------------------
C     HANDLE THE CONVERSION FOR AH.  IF COOP/CRN, GET TD INTO OBTMP 
C     FIRST.
C     ------------------------------------------------------------------
         ELSE IF(VCN.EQ.SFCAH_VN_P.OR.VCN.EQ.AH1H_VN_P.OR.
     1            VCN.EQ.AH15M_VN_P.OR.VCN.EQ.AH1HCHG_VN_P)THEN

            IF(DSN.EQ.COOP_DS_P.OR.DSN.EQ.URBANET_DS_P.OR.
     1         DSN.EQ.CRN_DS_P)THEN

               DO I = 1, SFC_NRECS(FNUM)

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

               ENDDO

            ENDIF

            DO 5 I = 1, SFC_NRECS(FNUM)

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

 5          CONTINUE

         ENDIF

      ELSE

C     ------------------------------------------------------------------
C     FOR MESONET, WE'LL READ BOTH TD & RH, AND THEIR QC STRUCTURES.
C     THEN, WE'LL RETURN EITHER THE READ-IN VALUE OR THE CALCULATED
C     VALUE FOR THE FORM OF THE VARIABLE DESIRED BY THE CALLER.  BECAUSE
C     THE TD VARIABLE GET'S THE STAGE 3 SPATIAL CONSISTENCY CHECK
C     APPLIED TO IT, IF THE TD QC RESULTS ARE AVAILABLE WE'LL USE THOSE.
C     ------------------------------------------------------------------
         CALL MGTNUM(VNAME(SFCTD_VN_P,DSN)(1:VLEN(SFCTD_VN_P,DSN)),
     1               SFC_NCID(FNUM),SFC_RECDIM(FNUM),1,SFC_NRECS(FNUM),
     2               MISS_P,OBTMP(1,1),STATUS)
         IF(STATUS.NE.SUCCESS_P)RETURN

         CALL MGTNUM(VNAME(SFCRH_VN_P,DSN)(1:VLEN(SFCRH_VN_P,DSN)),
     1               SFC_NCID(FNUM),SFC_RECDIM(FNUM),1,SFC_NRECS(FNUM),
     2               MISS_P,OBTMP(1,2),STATUS)
         IF(STATUS.NE.SUCCESS_P)RETURN

C     ------------------------------------------------------------------
C     SPECIAL CASE FOR TEMPERATURE PROCESSING
C     ------------------------------------------------------------------
c$$$         CALL MSFCART (VCN,SFCT_VN_P,FNUM,TTMP,TTMP_QCD,TTMP_QCA,
         CALL MSFCART (SFCT_VN_P,DSN,FNUM,TTMP,TTMP_QCD,TTMP_QCA,
     1        TTMP_QCR,STATUS)


C     ASSUME QC FAILED, SET FOR DIFFERNET CONDITIONS
         QCSTATUS = EQCFAILED_P

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

            CALL MGTNUM(VNAME(SFCTD_VN_P,DSN)(1:VLEN(SFCTD_VN_P,DSN))//
     1                  'QCA',SFC_NCID(FNUM),SFC_RECDIM(FNUM),1,
     2                  SFC_NRECS(FNUM),MISS_P,QCATMP(1,1),STATUS)
            IF(STATUS.EQ.VAR_NOTINDB_P)THEN
               STATUS = SUCCESS_P
               DO I = 1, SFC_NRECS(FNUM)
                  QCATMP(I,1) = 0
                  QCRTMP(I,1) = 0
                  QCDTMP(I,1) = 'Z'
               ENDDO
            ELSE IF(STATUS.NE.SUCCESS_P)THEN
               RETURN
            ELSE
               CALL MGTNUM(VNAME(SFCTD_VN_P,DSN)(1:VLEN(SFCTD_VN_P,DSN))
     1              //'QCR',SFC_NCID(FNUM),SFC_RECDIM(FNUM),1,
     2              SFC_NRECS(FNUM),MISS_P,QCRTMP(1,1),STATUS)
               IF(STATUS.NE.SUCCESS_P)RETURN

               CALL MGTCHR(VNAME(SFCTD_VN_P,DSN)(1:VLEN(SFCTD_VN_P,DSN))
     1              //'DD',SFC_NCID(FNUM),SFC_RECDIM(FNUM),1,
     2              SFC_NRECS(FNUM),QCDTMP(1,1),LEN1REC,STATUS)
               IF(STATUS.NE.SUCCESS_P)RETURN
               QCSTATUS = EQCOK_P
            ENDIF
         ELSE

            DO 11 I = 1, SFC_NRECS(FNUM)
               QCATMP(I,1) = 0
               QCRTMP(I,1) = 0
               QCDTMP(I,1) = 'Z'
 11         CONTINUE

         ENDIF

C     QCSTATUS IS SET TO FAILED OR OK, ONLY SET IF FAILED

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

            CALL MGTNUM(VNAME(SFCRH_VN_P,DSN)(1:VLEN(SFCRH_VN_P,DSN))//
     1                  'QCA',SFC_NCID(FNUM),SFC_RECDIM(FNUM),1,
     2                  SFC_NRECS(FNUM),MISS_P,QCATMP(1,2),STATUS)
            IF(STATUS.EQ.VAR_NOTINDB_P)THEN
               STATUS = SUCCESS_P
               QCSTATUS = EQCFAILED_P
               DO I = 1, SFC_NRECS(FNUM)
                  QCATMP(I,1) = 0
                  QCRTMP(I,1) = 0
                  QCDTMP(I,1) = 'Z'
               ENDDO
            ELSE IF(STATUS.NE.SUCCESS_P)THEN
               QCSTATUS = EQCFAILED_P
               RETURN
            ELSE

               CALL MGTNUM(VNAME(SFCRH_VN_P,DSN)(1:VLEN(SFCRH_VN_P,DSN))
     1              //'QCR',SFC_NCID(FNUM),SFC_RECDIM(FNUM),1,
     2              SFC_NRECS(FNUM),MISS_P,QCRTMP(1,2),STATUS)
               IF(STATUS.NE.SUCCESS_P)THEN
                  QCSTATUS = EQCFAILED_P
                  RETURN
               ENDIF
               CALL MGTCHR(VNAME(SFCRH_VN_P,DSN)(1:VLEN(SFCRH_VN_P,DSN))
     1              //'DD',SFC_NCID(FNUM),SFC_RECDIM(FNUM),1,
     2              SFC_NRECS(FNUM),QCDTMP(1,2),LEN1REC,STATUS)
               IF(STATUS.NE.SUCCESS_P)THEN
                  QCSTATUS = EQCFAILED_P
                  RETURN
               ENDIF
            ENDIF
         ELSE

            QCSTATUS = EQCFAILED_P
            DO 21 I = 1, SFC_NRECS(FNUM)
               QCATMP(I,2) = 0
               QCRTMP(I,2) = 0
               QCDTMP(I,2) = 'Z'
 21         CONTINUE

         ENDIF

C     ------------------------------------------------------------------
C     HANDLE TD.
C     ------------------------------------------------------------------
         IF(VCN.EQ.SFCTD_VN_P)THEN

            DO 31 I = 1, SFC_NRECS(FNUM)

               IF(OBTMP(I,1).NE.MISS_P)THEN

                  OB(I) = OBTMP(I,1)
                  QCAPP(I) = QCATMP(I,1)
                  QCRES(I) = QCRTMP(I,1)
                  QCDESC(I) = QCDTMP(I,1)

               ELSE IF(OBTMP(I,2).NE.MISS_P.AND.QCDTMP(I,2).NE.'B'.AND.
     1                 QCDTMP(I,2).NE.'X'.AND.QCDTMP(I,2).NE.'Q'.AND.
     2                 TTMP_QCD(I).NE.'B'.AND.TTMP_QCD(I).NE.'X'.AND.
     3                 TTMP_QCD(I).NE.'Q'.AND.TTMP(I).NE.MISS_P.AND.
     4                 TTMP(I).GE.89.0.AND.TTMP(I).LE.422.0.AND.
     5                 OBTMP(I,2).GE.0.0.AND.OBTMP(I,2).LE.100.0)THEN

                  OB(I) = M_DEWPNT(TTMP(I),OBTMP(I,2),MISS_P)
                  QCAPP(I) = QCATMP(I,2)
                  QCRES(I) = QCRTMP(I,2)
                  QCDESC(I) = QCDTMP(I,2)

               ELSE

                  OB(I) = MISS_P
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'

               ENDIF

 31         CONTINUE

C     ------------------------------------------------------------------
C     HANDLE RH.
C     ------------------------------------------------------------------
         ELSE IF(VCN.EQ.SFCRH_VN_P)THEN

            DO 41 I = 1, SFC_NRECS(FNUM)

               IF(OBTMP(I,2).NE.MISS_P)THEN

                  OB(I) = OBTMP(I,2)

C     ------------------------------------------------------------------
C     HERE'S WHERE WE USE THE TD QC, IF AVAILABLE, WHEN RETURNING RH.
C     ------------------------------------------------------------------
                  IF(OBTMP(I,1).NE.MISS_P)THEN
                     QCAPP(I) = QCATMP(I,1)
                     QCRES(I) = QCRTMP(I,1)
                     QCDESC(I) = QCDTMP(I,1)
                  ELSE
                     QCAPP(I) = QCATMP(I,2)
                     QCRES(I) = QCRTMP(I,2)
                     QCDESC(I) = QCDTMP(I,2)
                  ENDIF

               ELSE IF(OBTMP(I,1).NE.MISS_P.AND.QCDTMP(I,1).NE.'B'.AND.
     1                 QCDTMP(I,1).NE.'X'.AND.QCDTMP(I,1).NE.'Q'.AND.
     2                 TTMP(I).NE.MISS_P.AND.TTMP_QCD(I).NE.'B'.AND.
     3                 TTMP_QCD(I).NE.'X'.AND.TTMP_QCD(I).NE.'Q'.AND.
     4                 TTMP(I).GE.89.0.AND.TTMP(I).LE.422.0.AND.
     5                 OBTMP(I,1).GE.89.0.AND.
     6                 OBTMP(I,1).LE.422.0)THEN

                  OB(I) = M_RH(TTMP(I),OBTMP(I,1),MISS_P) * 100.0
                  QCAPP(I) = QCATMP(I,1)
                  QCRES(I) = QCRTMP(I,1)
                  QCDESC(I) = QCDTMP(I,1)

               ELSE

                  OB(I) = MISS_P
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'

               ENDIF

 41         CONTINUE

C     ------------------------------------------------------------------
C     HANDLE THE CONVERSION FOR DPD.
C     ------------------------------------------------------------------
         ELSE IF(VCN.EQ.SFCDPD_VN_P)THEN

            DO 51 I = 1, SFC_NRECS(FNUM)

               IF(OBTMP(I,1).NE.MISS_P.AND.QCDTMP(I,1).NE.'B'.AND.
     1            QCDTMP(I,1).NE.'X'.AND.QCDTMP(I,1).NE.'Q'.AND.
     2            TTMP(I).NE.MISS_P.AND.TTMP_QCD(I).NE.'B'.AND.
     3            TTMP_QCD(I).NE.'X'.AND.TTMP_QCD(I).NE.'Q'.AND.
     4            OBTMP(I,1).GE.89.0.AND.OBTMP(I,1).LE.422.0.AND.
     5            TTMP(I).GE.89.0.AND.TTMP(I).LE.422.0)THEN

                  OB(I) = TTMP(I) - OBTMP(I,1)
                  QCAPP(I) = QCATMP(I,1)
                  QCRES(I) = QCRTMP(I,1)
                  QCDESC(I) = QCDTMP(I,1)

               ELSE IF(OBTMP(I,2).NE.MISS_P.AND.QCDTMP(I,1).NE.'B'.AND.
     1                 QCDTMP(I,2).NE.'X'.AND.QCDTMP(I,2).NE.'Q'.AND.
     2                 TTMP(I).NE.MISS_P.AND.TTMP_QCD(I).NE.'B'.AND.
     3                 TTMP_QCD(I).NE.'X'.AND.TTMP_QCD(I).NE.'Q'.AND.
     4                 TTMP(I).GE.89.0.AND.TTMP(I).LE.422.0.AND.
     5                 OBTMP(I,2).GE.0.0.AND.OBTMP(I,2).LE.100.0)THEN

                  OB(I) = TTMP(I) - M_DEWPNT(TTMP(I),OBTMP(I,2),MISS_P)
                  QCAPP(I) = QCATMP(I,2)
                  QCRES(I) = QCRTMP(I,2)
                  QCDESC(I) = QCDTMP(I,2)

               ELSE

                  OB(I) = MISS_P
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'

               ENDIF

 51         CONTINUE

C     ------------------------------------------------------------------
C     HANDLE THE CONVERSION FOR Q.  FIRST, GET P AND ITS QC.  NOTE THAT 
C     WE HAVE TO CALL MSFCPRS BECAUSE P MAY NEED TO BE CONVERTED FROM 
C     ALT.
C     ------------------------------------------------------------------
         ELSE IF(VCN.EQ.SFCQ_VN_P)THEN

            CALL MSFCPRS(SFCP_VN_P,DSN,FNUM,PTMP,PTMP_QCD,PTMP_QCA,
     1                   PTMP_QCR,STATUS)
            IF(STATUS.NE.SUCCESS_P)RETURN

            DO 61 I = 1, SFC_NRECS(FNUM)

C     ------------------------------------------------------------------
C     MAKE SURE WE HAVE TD.
C     ------------------------------------------------------------------
               IF(OBTMP(I,1).NE.MISS_P)THEN
                  TD = OBTMP(I,1)
                  QCAPP(I) = QCATMP(I,1)
                  QCRES(I) = QCRTMP(I,1)
                  QCDESC(I) = QCDTMP(I,1)
               ELSE IF(OBTMP(I,2).NE.MISS_P.AND.QCDTMP(I,2).NE.'B'.AND.
     1                 QCDTMP(I,2).NE.'X'.AND.QCDTMP(I,2).NE.'Q'.AND.
     2                 TTMP_QCD(I).NE.'B'.AND.TTMP_QCD(I).NE.'X'.AND.
     3                 TTMP_QCD(I).NE.'Q'.AND.TTMP(I).NE.MISS_P.AND.
     4                 TTMP(I).GE.89.0.AND.TTMP(I).LE.422.0.AND.
     5                 OBTMP(I,2).GE.0.0.AND.OBTMP(I,2).LE.100.0)THEN
                  TD = M_DEWPNT(TTMP(I),OBTMP(I,2),MISS_P)
                  QCAPP(I) = QCATMP(I,2)
                  QCRES(I) = QCRTMP(I,2)
                  QCDESC(I) = QCDTMP(I,2)
               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 G/G.
C     WE, ON THE OTHER HAND, ARE "SI-CORRECT", SO WE USE PASCALS, K,
C     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 THE CONVERSION FOR WVMR.  FIRST, GET P AND ITS QC.  NOTE 
C     THAT WE HAVE TO CALL MSFCPRS BECAUSE P MAY NEED TO BE CONVERTED 
C     FROM ALT.
C     ------------------------------------------------------------------
         ELSE IF(VCN.EQ.SFCMR_VN_P)THEN

            CALL MSFCPRS(SFCP_VN_P,DSN,FNUM,PTMP,PTMP_QCD,PTMP_QCA,
     1                   PTMP_QCR,STATUS)
            IF(STATUS.NE.SUCCESS_P)RETURN

            DO 81 I = 1, SFC_NRECS(FNUM)

C     ------------------------------------------------------------------
C     MAKE SURE WE HAVE TD.
C     ------------------------------------------------------------------
               IF(OBTMP(I,1).NE.MISS_P)THEN
                  TD = OBTMP(I,1)
                  QCAPP(I) = QCATMP(I,1)
                  QCRES(I) = QCRTMP(I,1)
                  QCDESC(I) = QCDTMP(I,1)
               ELSE IF(OBTMP(I,2).NE.MISS_P.AND.QCDTMP(I,2).NE.'B'.AND.
     1                 QCDTMP(I,2).NE.'X'.AND.QCDTMP(I,2).NE.'Q'.AND.
     2                 TTMP_QCD(I).NE.'B'.AND.TTMP_QCD(I).NE.'X'.AND.
     3                 TTMP_QCD(I).NE.'Q'.AND.TTMP(I).NE.MISS_P.AND.
     4                 TTMP(I).GE.89.0.AND.TTMP(I).LE.422.0.AND.
     5                 OBTMP(I,2).GE.0.0.AND.OBTMP(I,2).LE.100.0)THEN
                  TD = M_DEWPNT(TTMP(I),OBTMP(I,2),MISS_P)
                  QCAPP(I) = QCATMP(I,2)
                  QCRES(I) = QCRTMP(I,2)
                  QCDESC(I) = QCDTMP(I,2)
               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 WVMR IN 
C     G/G.  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

 81         CONTINUE



C     ------------------------------------------------------------------
C     HANDLE THE CONVERSION FOR AH.
C     ------------------------------------------------------------------
         ELSE IF(VCN.EQ.SFCAH_VN_P)THEN

            DO 71 I = 1, SFC_NRECS(FNUM)

               IF(OBTMP(I,1).NE.MISS_P.AND.QCDTMP(I,1).NE.'B'.AND.
     1            QCDTMP(I,1).NE.'X'.AND.QCDTMP(I,1).NE.'Q'.AND.
     2            TTMP(I).NE.MISS_P.AND.TTMP_QCD(I).NE.'B'.AND.
     3            TTMP_QCD(I).NE.'X'.AND.TTMP_QCD(I).NE.'Q'.AND.
     4            OBTMP(I,1).GE.89.0.AND.OBTMP(I,1).LE.422.0.AND.
     5            TTMP(I).GE.89.0.AND.TTMP(I).LE.422.0)THEN

                  OB(I) = M_TD2AH(OBTMP(I,1),TTMP(I),MISS_P)
                  QCAPP(I) = QCATMP(I,1)
                  QCRES(I) = QCRTMP(I,1)
                  QCDESC(I) = QCDTMP(I,1)

               ELSE IF(OBTMP(I,2).NE.MISS_P.AND.QCDTMP(I,1).NE.'B'.AND.
     1                 QCDTMP(I,2).NE.'X'.AND.QCDTMP(I,2).NE.'Q'.AND.
     2                 TTMP(I).NE.MISS_P.AND.TTMP_QCD(I).NE.'B'.AND.
     3                 TTMP_QCD(I).NE.'X'.AND.TTMP_QCD(I).NE.'Q'.AND.
     4                 TTMP(I).GE.89.0.AND.TTMP(I).LE.422.0.AND.
     5                 OBTMP(I,2).GE.0.0.AND.OBTMP(I,2).LE.100.0)THEN

                  OB(I) = M_RH2AH(OBTMP(I,2),TTMP(I),MISS_P)
                  QCAPP(I) = QCATMP(I,2)
                  QCRES(I) = QCRTMP(I,2)
                  QCDESC(I) = QCDTMP(I,2)

               ELSE

                  OB(I) = MISS_P
                  QCAPP(I) = 0
                  QCRES(I) = 0
                  QCDESC(I) = 'Z'

               ENDIF

 71         CONTINUE

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