Radiative Transfer and Surface Property Modelling

Units Conversion

Subprogram Descriptions

SA_TO_MR

 NAME:
       SA_to_MR

 PURPOSE:
       Function to convert gas specific amounts to mass mixing ratio

 CALLING SEQUENCE:
       Mixing_Ratio = SA_to_MR( Specific_Amount,         &  ! Input
                                Water_Vapor=Water_Vapor, &  ! Optional input
                                Message_Log=Message_Log  )  ! Error messaging

 INPUT ARGUMENTS:
       Specific_Amount:   Gas specific amount comcentration.
                          UNITS:      g/kg
                          TYPE:       REAL(fp)
                          DIMENSION:  Scalar or Rank-1 (K x 1)
                          ATTRIBUTES: INTENT(IN)

 OPTIONAL INPUT ARGUMENTS:
       Water_Vapor:       Water vapor mass mixing ratio. If this argument is
                          not supplied, the mandatory input SPECIFIC_AMOUNT
                          argument is assumed to be water vapor.
                          UNITS:      g/kg
                          TYPE:       REAL(fp)
                          DIMENSION:  Scalar or Rank-1 (K x 1)
                          ATTRIBUTES: INTENT(IN)

       Message_Log:       Character string specifying a filename in which any
                          Messages will be logged. If not specified, or if an
                          error occurs opening the log file, the default action
                          is to output Messages to standard output.
                          UNITS:      N/A
                          TYPE:       CHARACTER(*)
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

 FUNCTION RESULT:
       Mixing_Ratio:      The gas mass mixing ratio. If an error occurs,
                          the value -1.0 is returned.
                          UNITS:      g/kg
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as input Specific_Amount

 PROCEDURE:
       The specific amount is defined as the ratio of the mass of gas
       to the total mass of air and water vapor in a given volume:

                  Mg
         SA = ---------   .......(1)
               Md + Mw

       where Mg = mass of gas
             Mw = mass of water vapor
             Md = mass of dry air (including Mg).

       The gas mass mixing ratio is defined as the ratio of the mass
       of the gas to the mass of dry air in a given volume:

                Mg
         MRg = ----    .......(2)
                Md

       Rearranging (1) and substituting in (2) gives,

          1      Md + Mw
         ---- = ---------
          SA       Mg

                 Md     Mw
              = ---- + ----
                 Mg     Mg

                 Md     Mw   Md                                      Md
              = ---- + ----.----    ( multiplying the second term by ---- )
                 Mg     Md   Mg                                      Md

                  1 
              = ----- ( 1 + MRw )
                 MRg

       therefore,

         MRg = SA ( 1 + MRw )

       for input units of g/g or kg/kg. For input units of g/kg then,

         MRg = SA ( 1 + 0.001*MRw )   .......(3)

       If the input specific amount is for water vapor (specific humidity) 
       then (3) becomes,

         MRw = SA ( 1 + 0.001*MRw )

       i.e.

         MRw = SA + 0.001*MRw*SA

       i.e.

         MRw( 1 - 0.001*SA ) = SA

       therefore,

                      SA
         MRw = ------------------   .......(4)
                ( 1 - 0.001*SA )


 CREATION HISTORY:
       Written by:     Paul van Delst, CIMSS/SSEC 05-Dec-2003
                       paul.vandelst@ssec.wisc.edu

MR_TO_SA

 NAME:
       MR_to_SA

 PURPOSE:
       Function to convert gas concentrations from mass mixing ratio to
       specific amounts.

 CATEGORY:
       Profile Utility

 LANGUAGE:
       Fortran-95

 CALLING SEQUENCE:
       Specific_Amount = MR_to_SA( Mixing_Ratio,            &  ! Input
                                   Water_Vapor=Water_Vapor, &  ! Optional input
                                   Message_Log=Message_Log  )  ! Error messaging

 INPUT ARGUMENTS:
       Mixing_Ratio:      Gas mass mixing ratio.
                          UNITS:      g/kg
                          TYPE:       REAL(fp)
                          DIMENSION:  Scalar or Rank-1 (K x 1)
                          ATTRIBUTES: INTENT(IN)

 OPTIONAL INPUT ARGUMENTS:
       Water_Vapor:       Water vapor specific humidity. If this argument is
                          not supplied, the mandatory input MIXING_RATIO
                          argument is assumed to be water vapor.
                          UNITS:      g/kg
                          TYPE:       REAL(fp)
                          DIMENSION:  Scalar or Rank-1 (K x 1)
                          ATTRIBUTES: INTENT(IN)

       Message_Log:       Character string specifying a filename in which any
                          Messages will be logged. If not specified, or if an
                          error occurs opening the log file, the default action
                          is to output Messages to standard output.
                          UNITS:      N/A
                          TYPE:       CHARACTER(*)
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

 FUNCTION RESULT:
       Specific_Amount:   The gas specific amount. If an error occurs,
                          the value -1.0 is returned.
                          UNITS:      g/kg
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as input Mixing_Ratio

 PROCEDURE:
       From the SA_to_MR conversion, we know that for input units of
       g/kg that,

         MRg = SAg ( 1 + 0.001*MRw )   .......(1)

       and 
                      SAw
         MRw = -------------------   .......(2)
                ( 1 - 0.001*SAw )

       where MRg = mass mixing ratio of gas
             MRw = mass mixing ratio of water vapor
             SAg = specific amount of gas
             SAw = specific amount of water vapor (specific humidity)

       Rearranging (1) and (2) gives,

         SAg = MRg ( 1 - 0.001*SAw )

       and for water vapor only,

                       MRw
         SAw = -------------------
                ( 1 + 0.001*MRw )

 CREATION HISTORY:
       Written by:     Paul van Delst, CIMSS/SSEC 05-Dec-2003
                       paul.vandelst@ssec.wisc.edu

RH_TO_MR

NAME:
RH_to_MR

PURPOSE:
Function to convert relative humidity to water vapor mixing ratio

CALLING SEQUENCE:
Mixing_Ratio = RH_to_MR( Pressure, & ! Input
Temperature, & ! Input
Relative_Humidity, & ! Input
Ice_Temperature=Ice_Temperature, & ! optional input
Min_Pressure =Min_Pressure, & ! Optional input
Message_Log =Message_Log ) ! Error messaging

INPUT ARGUMENTS:
Pressure: Total atmospheric pressure.
UNITS: hectoPascals, hPa
TYPE: REAL(fp)
DIMENSION: Scalar or Rank-1 (K x 1)
ATTRIBUTES: INTENT(IN)

Temperature: Atmospheric temperature.
UNITS: Kelvin, K
TYPE: REAL(fp)
DIMENSION: Same as pressure
ATTRIBUTES: INTENT(IN)

Relative_Humidity: Atmospheric relative humidity.
UNITS: %
TYPE: REAL(fp)
DIMENSION: Same as pressure
ATTRIBUTES: INTENT(IN)

OPTIONAL INPUT ARGUMENTS:
Ice_Temperature: Temperature below which the saturation vapor
pressure over ice is used in the conversion.
By default, only the saturation vapor pressure
over water is used.
UNITS: Kelvin, K
TYPE: REAL(fp)
DIMENSION: Scalar
ATTRIBUTES: OPTIONAL, INTENT(IN)

Min_Pressure: Pressure value below which the saturation
mixing ratio is not calculated. The default
is 50mb. Saturation mixing ratios below the
minimum pressure are set to zero. This is
because at pressures less than 50mb, the
saturation vapour Pressure, which is based
only on temperature, can exceed the total
air Pressure.
UNITS: hectoPascals, hPa
TYPE: REAL(fp)
DIMENSION: Scalar
ATTRIBUTES: OPTIONAL, INTENT(IN)

Message_Log: Character string specifying a filename in which any
Messages will be logged. If not specified, or if an
error occurs opening the log file, the default action
is to output Messages to standard output.
UNITS: N/A
TYPE: CHARACTER(*)
DIMENSION: Scalar
ATTRIBUTES: OPTIONAL, INTENT(IN)

FUNCTION RESULT:
Mixing_Ratio: Water vapor mass mixing ratio. If an error occurs,
-1.0 is returned.
UNITS: g/kg
TYPE: REAL(fp)
DIMENSION: Same as input Pressure

PROCEDURE:
Once the saturation mixing ratio is calculated the mixing ratio
corresponding to the input relative humidity is determined using:

Relative_Humidity * Saturation_Mixing_Ratio
Mixing_Ratio = ———————————————
100

CREATION HISTORY:
Written by: Paul van Delst, CIMSS/SSEC 02-Mar-1999
paul.vandelst@ssec.wisc.edu


MR_TO_RH

 NAME:
       MR_to_RH

 PURPOSE:
       Function to convert water vapor mixing ratio to relative humidity

 CALLING SEQUENCE:
       Relative_Humidty = MR_to_RH( Pressure,                        &  ! Input
                                    Temperature,                     &  ! Input
                                    Mixing_Ratio,                    &  ! Input
                                    Ice_Temperature=Ice_Temperature, &  ! optional input
                                    Min_Pressure   =Min_Pressure,    &  ! Optional input
                                    Message_Log    =Message_Log      )  ! Error messaging

 INPUT ARGUMENTS:
       Pressure:          Total atmospheric pressure.
                          UNITS:      hectoPascals, hPa
                          TYPE:       REAL(fp)
                          DIMENSION:  Scalar or Rank-1 (K x 1)
                          ATTRIBUTES: INTENT(IN)

       Temperature:       Atmospheric temperature.
                          UNITS:      Kelvin, K
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as pressure
                          ATTRIBUTES: INTENT(IN)

       Mixing_Ratio:      Water vapor mixing ratio.
                          UNITS:      g/kg
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as pressure
                          ATTRIBUTES: INTENT(IN)
   
 OPTIONAL INPUT ARGUMENTS:
       Ice_Temperature:   Temperature below which the saturation vapor
                          pressure over ice is used in the conversion.
                          By default, only the saturation vapor pressure
                          over water is used.
                          UNITS:      Kelvin, K
                          TYPE:       REAL(fp)
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)
   
       Min_Pressure:      Pressure value below which the saturation
                          mixing ratio is not calculated. The default
                          is 50mb. Saturation mixing ratios below the
                          minimum pressure are set to zero. This is
                          because at pressures less than 50mb, the
                          saturation vapour Pressure, which is based
                          only on temperature, can exceed the total
                          air Pressure.
                          UNITS:      hectoPascals, hPa
                          TYPE:       REAL(fp)
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)
   
       Message_Log:       Character string specifying a filename in which any
                          Messages will be logged. If not specified, or if an
                          error occurs opening the log file, the default action
                          is to output Messages to standard output.
                          UNITS:      N/A
                          TYPE:       CHARACTER(*)
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

 FUNCTION RESULT:
       Relative_Humidity: Relative humidity. If an error occurs,
                          -1.0 is returned.
                          UNITS:      %
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as input Pressure

 PROCEDURE:
       Once the saturation mixing ratio is calculated the relative humidity
       corresponding to the input mixing ratio is determined using:

                                         Mixing_Ratio
       Relative_Humidity = 100.0 * -------------------------
                                    Saturation_Mixing_Ratio

 CREATION HISTORY:
       Written by:     Paul van Delst, CIMSS/SSEC 02-Mar-1999
                       paul.vandelst@ssec.wisc.edu

MR_TO_PPMV

NAME:
MR_to_PPMV

PURPOSE:
Function to convert gas concentrations from mass mixing ratio in g/kg
to volume mixing ratio in ppmv

CALLING SEQUENCE:
ppmv = MR_to_PPMV( Mixing_Ratio, & ! Input
Molecule_ID=Molecule_ID, & ! Input
Message_Log=Message_Log ) ! Error messaging

INPUT ARGUMENTS:
Mixing_Ratio: Mass mixing ratio of gas.
UNITS: g/kg
TYPE: REAL(fp)
DIMENSION: Scalar or Rank-1 (K x 1)
ATTRIBUTES: INTENT(IN)

OPTIONAL INPUT ARGUMENTS:
Molecule_ID: HITRAN molecular designation identifying the
molecule for which the concentration units
conversion is required. If not specified, the
default value is that for water vapor.
Valid values are:
1: H2O 9: SO2 17: HI 25: H2O2
2: CO2 10: NO2 18: ClO 26: C2H2
3: O3 11: NH3 19: OCS 27: C2H6
4: N2O 12: HNO3 20: H2CO 28: PH3
5: CO 13: OH 21: HOCl 29: COF2
6: CH4 14: HF 22: N2 30: SF6
7: O2 15: HCl 23: HCN 31: H2S
8: NO 16: HBr 24: CH3Cl 32: HCOOH
UNITS: N/A
TYPE: INTEGER
DIMENSION: Scalar
ATTRIBUTES: OPTIONAL, INTENT(IN)

Message_Log: Character string specifying a filename in which any
Messages will be logged. If not specified, or if an
error occurs opening the log file, the default action
is to output Messages to standard output.
UNITS: N/A
TYPE: CHARACTER(*)
DIMENSION: Scalar
ATTRIBUTES: OPTIONAL, INTENT(IN)

FUNCTION RESULT:
ppmv: Volume mixing ratio of gas. If an error occurs,
-1.0 is returned.
UNITS: ppmv
TYPE: REAL(fp)
DIMENSION: Same as input Mixing_Ratio

PROCEDURE:
To convert mixing ratio in g/kg to parts-per-million, the following
is used:
MW(Dry Air)
ppmv(MOL) = 1000 . Mixing_Ratio(MOL) . ————-
MW(MOL)

where MW(Dry Air) = Average molecular weight of dry air
MW(MOL) = Molecular weight of the gas in question.

The factor of 1000 derives from the product of the g/kg to g/g
scale factor (0.001) and the “parts-per” to “parts-per-million”
scale factor (1.0e+06)

CREATION HISTORY:
Written by: Paul van Delst, CIMSS/SSEC 03-May-2000
paul.vandelst@ssec.wisc.edu


PPMV_TO_MR

 NAME:
       PPMV_to_MR

 PURPOSE:
       Function to convert gas concentrations from volume mixing ratio in
       ppmv to mass mixing ratio in g/kg.

 CALLING SEQUENCE:
       Mixing_Ratio = PPMV_to_MR( ppmv,                    &  ! Input
                                  Molecule_ID=Molecule_ID, &  ! Input
                                  Message_Log=Message_Log  )  ! Error messaging

 INPUT ARGUMENTS:
       ppmv:          Volume mixing ratio of gas.
                      UNITS:      ppmv
                      TYPE:       REAL(fp)
                      DIMENSION:  Scalar or Rank-1 (K x 1)
                      ATTRIBUTES: INTENT(IN)

 OPTIONAL INPUT ARGUMENTS:
       Molecule_ID:   HITRAN molecular designation identifying the
                      molecule for which the concentration units
                      conversion is required. If not specified, the
                      default value is that for water vapor.
                      Valid values are:
                        1: H2O       9: SO2      17: HI       25: H2O2
                        2: CO2      10: NO2      18: ClO      26: C2H2
                        3: O3       11: NH3      19: OCS      27: C2H6
                        4: N2O      12: HNO3     20: H2CO     28: PH3
                        5: CO       13: OH       21: HOCl     29: COF2
                        6: CH4      14: HF       22: N2       30: SF6
                        7: O2       15: HCl      23: HCN      31: H2S
                        8: NO       16: HBr      24: CH3Cl    32: HCOOH
                      UNITS:      N/A
                      TYPE:       INTEGER
                      DIMENSION:  Scalar
                      ATTRIBUTES: OPTIONAL, INTENT(IN)

       Message_Log:   Character string specifying a filename in which any
                      Messages will be logged. If not specified, or if an
                      error occurs opening the log file, the default action
                      is to output Messages to standard output.
                      UNITS:      N/A
                      TYPE:       CHARACTER(*)
                      DIMENSION:  Scalar
                      ATTRIBUTES: OPTIONAL, INTENT(IN)

 FUNCTION RESULT:
       Mixing_Ratio:  Mass mixing ratio of gas. If an error occurs,
                      -1.0 is returned.
                      UNITS:      g/kg
                      TYPE:       REAL(fp)
                      DIMENSION:  Same as input ppmv

 PROCEDURE:
       To convert ppmv to mixing ratio, the following is used:

                                          MW(MOL)
         mr(MOL) = 0.001 . ppmv(MOL) . -------------
                                        MW(Dry Air)

       where MW(Dry Air) = Average molecular weight of dry air
             MW(MOL)     = Molecular weight of the gas in question.

       The factor of 0.001 derives from the product of the g/g to g/kg
       scale factor (1000) and the "parts-per-million" to "parts-per"
       scale factor (1.0e-06)

 CREATION HISTORY:
       Written by:     Paul van Delst, CIMSS/SSEC 03-May-2000
                       paul.vandelst@ssec.wisc.edu

PPMV_TO_PP

 NAME:
       PPMV_to_PP

 PURPOSE:
       Function to convert gas concentrations from ppmv to partial pressure

 CALLING SEQUENCE:
       Partial_Pressure = PPMV_to_PP( Pressure,                &  ! Input
                                      ppmv,                    &  ! Input
                                      Water_Vapor=Water_Vapor, &  ! Optional Input
                                      Message_Log=Message_Log  )  ! Error messaging

 INPUT ARGUMENTS:
       Pressure:          Total atmospheric pressure.
                          UNITS:      hectoPascals, hPa
                          TYPE:       REAL(fp)
                          DIMENSION:  Scalar or Rank-1 (K x 1)
                          ATTRIBUTES: INTENT(IN)

       ppmv:              Gas volume mixing ratio in ppmv.
                          UNITS:      ppmv
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as Pressure
                          ATTRIBUTES: INTENT(IN)
   
 OPTIONAL INPUT ARGUMENTS:
       Water_Vapor:       Water vapor partial pressure. If this argument is
                          not supplied, the mandatory input PPMV argument is
                          assumed to be water vapor.
                          UNITS:      hectoPascals, hPa
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as input Pressure
                          ATTRIBUTES: INTENT(IN)

       Message_Log:       Character string specifying a filename in which any
                          Messages will be logged. If not specified, or if an
                          error occurs opening the log file, the default action
                          is to output Messages to standard output.
                          UNITS:      N/A
                          TYPE:       CHARACTER(*)
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

 FUNCTION RESULT:
       Partial_Pressure:  Gas partial pressure. If an error occurs,
                          -1.0 is returned.
                          UNITS:      hectoPascals, hPa
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as input Pressure

 PROCEDURE:
       To convert volume mixing ratio in ppmv of a molecular species, 
       designated by MOL, to partial pressure, the following is used,

         pp(MOL) = 1.0e-06 . ppmv(MOL) . ( Pressure - pp(H2O) )

       If the input molecule is water vapor, the partial pressure is
       determined using,
                                                                 1
         pp(H2O) = 1.0e-06 . ppmv(H2O) . Pressure . -----------------------------
                                                     1 + ( 1.0e-06 . ppmv(H20) )

       This is based on the same methods used in the LBLRTM conversion code
       in its lblatm.f module where molecular mixing ratios (either ppmv or
       g/kg) are always with respect to DRY AIR.

 CREATION HISTORY:
       Written by:     Paul van Delst, CIMSS/SSEC 03-May-2000
                       paul.vandelst@ssec.wisc.edu

PP_TO_PPMV

 NAME:
       PP_to_PPMV

 PURPOSE:
       Function to convert gas concentrations from partial pressure to 
       volume mixing ratio in ppmv

 CALLING SEQUENCE:
       ppmv = PP_to_PPMV( Pressure,                &  ! Input
                          Partial_Pressure,        &  ! Input
                          Water_Vapor=Water_Vapor, &  ! Optional Input
                          Message_Log=Message_Log  )  ! Error messaging

 INPUT ARGUMENTS:
       Pressure:          Total atmospheric pressure.
                          UNITS:      hectoPascals, hPa
                          TYPE:       REAL(fp)
                          DIMENSION:  Scalar or Rank-1 (K x 1)
                          ATTRIBUTES: INTENT(IN)

       Partial_Pressure:  Gas partial pressure
                          UNITS:      hectoPascals, hPa
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as pressure
                          ATTRIBUTES: INTENT(IN)
   
 OPTIONAL INPUT ARGUMENTS:
       Water_Vapor:       Water vapor volume mixing ratio. If this argument is
                          not supplied, the mandatory Partial_Pressure argument
                          is assumed to be water vapor.
                          UNITS:      ppmv
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as Pressure
                          ATTRIBUTES: INTENT(IN)

       Message_Log:       Character string specifying a filename in which any
                          Messages will be logged. If not specified, or if an
                          error occurs opening the log file, the default action
                          is to output Messages to standard output.
                          UNITS:      N/A
                          TYPE:       CHARACTER(*)
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

 FUNCTION RESULT:
       ppmv:              Gas volume mixing ratio. If an error occurs,
                          -1.0 is returned.
                          UNITS:      ppmv
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as input Pressure

 PROCEDURE:
       To convert the partial pressure of a molecular species, designated
       by MOL, to volume mixing ratio in ppmv, the following is used,

                                     pp(MOL)
         ppmv(MOL) = 1.0e+06 . ------------------
                                Dry_Air_Pressure

       where
                                                     1
         Dry_Air_Pressure = Pressure . ----------------------------
                                        1 + ( ppmv(H2O) . 1.0e-6 )

       If the input molecule is water vapor, the dry air pressure is
       determined simply using,

         Dry_Air_Pressure = Pressure - pp(H2O)

       This is based on the same methods used in the LBLRTM conversion code
       in its lblatm.f module where molecular mixing ratios (either ppmv or
       g/kg) are always with respect to DRY AIR.

 CREATION HISTORY:
       Written by:     Paul van Delst, CIMSS/SSEC 03-May-2000
                       paul.vandelst@ssec.wisc.edu


MR_TO_PP

 NAME:
       MR_to_PP

 PURPOSE:
       Function to convert gas concentrations from mixing ratio in g/kg
       to partial pressure in hectoPascals.

 CALLING SEQUENCE:
       Partial_Pressure = MR_to_PP( Pressure,                &  ! Input
                                    Mixing_Ratio,            &  ! Input
                                    Molecule_ID=Molecule_ID, &  ! Optional Input
                                    Water_Vapor=Water_Vapor, &  ! Optional Input
                                    Message_Log=Message_Log  )  ! Error messaging

 INPUT ARGUMENTS:
       Pressure:          Total atmospheric pressure.
                          UNITS:      hectoPascals, hPa
                          TYPE:       REAL(fp)
                          DIMENSION:  Scalar or Rank-1 (K x 1)
                          ATTRIBUTES: INTENT(IN)

       Mixing_Ratio:      Mass mixing ratio of gas.
                          UNITS:      g/kg
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as pressure
                          ATTRIBUTES: INTENT(IN)

 OPTIONAL INPUT ARGUMENTS:
       Molecule_ID:       HITRAN molecular designation identifying the
                          molecule for which the concentration units
                          conversion is required. If not specified, the
                          default value is that for water vapor.
                          Valid values are:
                            1: H2O       9: SO2      17: HI       25: H2O2
                            2: CO2      10: NO2      18: ClO      26: C2H2
                            3: O3       11: NH3      19: OCS      27: C2H6
                            4: N2O      12: HNO3     20: H2CO     28: PH3
                            5: CO       13: OH       21: HOCl     29: COF2
                            6: CH4      14: HF       22: N2       30: SF6
                            7: O2       15: HCl      23: HCN      31: H2S
                            8: NO       16: HBr      24: CH3Cl    32: HCOOH
                          UNITS:      N/A
                          TYPE:       INTEGER
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

       Water_Vapor:       Water vapor partial pressure. If this argument is
                          not supplied, the mandatory MIXING_RATIO argument
                          is assumed to be water vapor.
                          This argument is ignored if the specified or default
                          molecule ID is set to 1.
                          UNITS:      hectoPascals, hPa
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as Pressure
                          ATTRIBUTES: INTENT(IN)

       Message_Log:       Character string specifying a filename in which any
                          Messages will be logged. If not specified, or if an
                          error occurs opening the log file, the default action
                          is to output Messages to standard output.
                          UNITS:      N/A
                          TYPE:       CHARACTER(*)
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

 FUNCTION RESULT:
       Partial_Pressure:  Gas partial pressure. If an error occurs,
                          -1.0 is returned.
                          UNITS:      hectoPascals, hPa
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as input Pressure

 PROCEDURE:
       First a definition. In this routine, the mass mixing ratio of a gas
       is defined to be, for a given volume, the ratio of the mass of the gas 
       in question to that of DRY air.

       The ideal gas equation can be written as,
 
         p = n.R0.T     ................................................(1)

       for unit volume, where 
         n  = number of moles of gas,
         R0 = universal gas constant
         T  = temperature.

       The mass mixing ratio of a gas is defined as the mass of the gas with
       respect to the mass of dry air in the same volume. If we use eqn(1)
       to construct expressions for the partial pressures of a particular
       gas and dry air, we get,

         pp(MOL)    = n(MOL).R0.T     .................................(2a)

       and

         pp(DryAir) = n(DryAir).R0.T     ..............................(2b)


       Dividing eqn(2a) by (2b) and rearranging we get,

                     n(MOL) 
         pp(MOL) = ----------- . pp(DryAir)     ........................(3)
                    n(DryAir)

       Replacing the expssion for the number of moles of a substance into
       eqn(3) gives us,

                     m(MOL)     MW(DryAir)
         pp(MOL) = --------- . ------------ . pp(DryAir)
                    MW(MOL)      m(DryAir)

                     m(MOL)       MW(DryAir)
                 = ----------- . ------------ . pp(DryAir)
                    m(DryAir)      MW(MOL)

                                     MW(DryAir)
                 = 0.001 . w(MOL) . ------------ . pp(DryAir)     ......(4)
                                      MW(MOL)

       where m(MOL)     = mass of gas MOL in grams,
             m(DryAir)  = mass of dry air in grams,
             MW(MOL)    = molecular weight of of gas MOL in grams,
             MW(DryAir) = effective molecular weight of dry air in grams,
             w(MOL)     = mass mixing ratio of gas MOL in g/kg.

       The factor of 0.001 in eqn(4) is to convert the units of the mixing
       ratio from g/kg to g/g.

       Two cases need to be addressed:


       -------------
       1) MOL == H2O
       -------------

       If the gas for which the mixing ratio is to be converted is water
       vapor, then eqn(4) can be written as,

                   
         pp(H2O) = WX . ( p(Total) - pp(H2O) )     .....................(5)

                                    MW(DryAir)
       where WX = 0.001 . w(H2O) . ------------
                                     MW(H2O)

       Expanding eqn(5) further, we get
                   
         pp(H2O) = ( WX . p(Total) ) - ( WX . pp(H2O) )

       and,

         pp(H2O) . ( 1 + WX ) = WX . p(Total)

       and finally,

                        WX
         pp(H2O) = ------------ . p(Total)     .........................(6)
                    ( 1 + WX )

       Eqn(6) is used to determine the partial pressure for water vapor
       input in this routine.


       -------------------
       2) MOL is *not* H2O
       -------------------

       Using eqn(4) to determine an expression for the non-water vapor
       gases, we get,

         pp(MOL) = WX . p(DryAir)     ..................................(7)

                                    MW(DryAir)
       where WX = 0.001 . w(MOL) . ------------
                                     MW(MOL)

       and w(MOL) is still defined as in eqn(4).


       This is based on the same methods used in the LBLRTM conversion code
       in its lblatm.f module where molecular mixing ratios (either ppmv or
       g/kg) are always with respect to DRY AIR.

 CREATION HISTORY:
       Written by:     Paul van Delst, CIMSS/SSEC 20-Sep-2002
                       paul.vandelst@ssec.wisc.edu

PP_TO_MR

 NAME:
       PP_to_MR

 PURPOSE:
       Function to convert gas concentrations from partial pressure in
       hectoPascals to mass mixing ratio in g/kg.

 CALLING SEQUENCE:
       Mixing_Ratio = PP_to_MR( Pressure,                &  ! Input
                                Partial_Pressure,        &  ! Input
                                Molecule_ID=Molecule_ID, &  ! Optional Input
                                Water_Vapor=Water_Vapor, &  ! Optional Input
                                Message_Log=Message_Log  )  ! Error messaging

 INPUT ARGUMENTS:
       Pressure:          Total atmospheric pressure.
                          UNITS:      hectoPascals, hPa
                          TYPE:       REAL(fp)
                          DIMENSION:  Scalar or Rank-1 (K x 1)
                          ATTRIBUTES: INTENT(IN)

       Partial_Pressure:  Partial pressure of gas.
                          UNITS:      g/kg
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as Pressure
                          ATTRIBUTES: INTENT(IN)

 OPTIONAL INPUT ARGUMENTS:
       Molecule_ID:       HITRAN molecular designation identifying the
                          molecule for which the concentration units
                          conversion is required. If not specified, the
                          default value is that for water vapor.
                          Valid values are:
                            1: H2O       9: SO2      17: HI       25: H2O2
                            2: CO2      10: NO2      18: ClO      26: C2H2
                            3: O3       11: NH3      19: OCS      27: C2H6
                            4: N2O      12: HNO3     20: H2CO     28: PH3
                            5: CO       13: OH       21: HOCl     29: COF2
                            6: CH4      14: HF       22: N2       30: SF6
                            7: O2       15: HCl      23: HCN      31: H2S
                            8: NO       16: HBr      24: CH3Cl    32: HCOOH
                          UNITS:      N/A
                          TYPE:       INTEGER
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

       Water_Vapor:       Water vapor mass mixing ratio. If this argument is
                          not supplied, the mandatory PARTIAL_PRESSURE argument
                          is assumed to be water vapor.
                          This argument is ignored if the specified or default
                          molecule ID is set to 1.
                          UNITS:      hectoPascals, hPa
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as Pressure
                          ATTRIBUTES: INTENT(IN)

       Message_Log:       Character string specifying a filename in which any
                          messages will be logged. If not specified, or if an
                          error occurs opening the log file, the default action
                          is to output messages to standard output.
                          UNITS:      N/A
                          TYPE:       CHARACTER(*)
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

 FUNCTION RESULT:
       Mixing_Ratio:      Mass mixing ratio of gas. If an error occurs,
                          -1.0 is returned.
                          UNITS:      g/kg
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as input Pressure

 PROCEDURE:
       First a definition. In this routine, the mass mixing ratio of a gas
       is defined to be, for a given volume, the ratio of the mass of the gas 
       in question to that of DRY air.

       The ideal gas equation can be written as,
 
         p = n.R0.T     ................................................(1)

       for unit volume, where 
         n  = number of moles of gas,
         R0 = universal gas constant
         T  = temperature.

       The mass mixing ratio of a gas is defined as the mass of the gas with
       respect to the mass of dry air in the same volume. If we use eqn(1)
       to construct expressions for the partial pressures of a particular
       gas and dry air, we get,

         pp(MOL)    = n(MOL).R0.T     .................................(2a)

       and

         pp(DryAir) = n(DryAir).R0.T     ..............................(2b)


       Dividing eqn(2a) by (2b) and rearranging we get,

                     n(MOL) 
         pp(MOL) = ----------- . pp(DryAir)     ........................(3)
                    n(DryAir)

       Replacing the expssion for the number of moles of a substance into
       eqn(3) gives us,

                     m(MOL)     MW(DryAir)
         pp(MOL) = --------- . ------------ . pp(DryAir)
                    MW(MOL)      m(DryAir)

                     m(MOL)       MW(DryAir)
                 = ----------- . ------------ . pp(DryAir)
                    m(DryAir)      MW(MOL)

                                     MW(DryAir)
                 = 0.001 . w(MOL) . ------------ . pp(DryAir)     ......(4)
                                      MW(MOL)

       where m(MOL)     = mass of gas MOL in grams,
             m(DryAir)  = mass of dry air in grams,
             MW(MOL)    = molecular weight of of gas MOL in grams,
             MW(DryAir) = effective molecular weight of dry air in grams,
             w(MOL)     = mass mixing ratio of gas MOL in g/kg.

       The factor of 0.001 in eqn(4) is to convert the units of the mixing
       ratio from g/kg to g/g.

       Thus to determine the mixing ratio of the gas in question from its
       partial pressure, eqn(4) is rearranged to give,

                            MW(MOL)        pp(MOL)
         w(MOL) = 1000 . ------------ . ------------     ...............(5)
                          MW(DryAir)     pp(DryAir)


       Two cases need to be addressed:


       -------------
       1) MOL == H2O
       -------------

       If the gas for which the partial pressure is to be converted is water
       vapor, then the dry air partial pressure required in eqn(5) is simply
       computed using,

         pp(DryAir) = p(Total) - pp(H2O)

       which is then used in eqn(5) to compute the water vapour mixing ratio.


       -------------------
       2) MOL is *not* H2O
       -------------------

       For this gas, the dry air partial pressure must be computed using the 
       water vapor mixing ratio supplied in the optional Water_Vapor argument.

       Eqn(4) above can be rewritten as,

         pp(H2O) = WX . p(DryAir)     ..................................(6)

                                    MW(DryAir)
       where WX = 0.001 . w(H2O) . ------------
                                     MW(H2O)

       Rearranging eqn(6), we then get,

                      pp(H2O)
         p(DryAir) = ---------     .....................................(7)
                        WX

       But, eqn(6) can also be written as,

         pp(H2O) = WX . ( p(Total) - pp(H2O) )

                 = ( WX . p(Total) ) - ( WX . pp(H2O) )

       and thus,

         pp(H2O) . ( 1 + WX ) = WX . p(Total)

       with finally,

                        WX
         pp(H2O) = ------------ . p(Total)     .........................(8)
                    ( 1 + WX )

       Substituting eqn(8) into eqn(7) gives,

                      p(Total)
         p(DryAir) = ----------     ....................................(9)
                      1 + WX 

       Eqn(9) is used to compute the dry air partial pressure which is then
       used in enq(5) to compute the mixing ratio of the gas in question.


       This is based on the same methods used in the LBLRTM conversion code
       in its lblatm.f module where molecular mixing ratios (either ppmv or
       g/kg) are always with respect to DRY AIR.

 CREATION HISTORY:
       Written by:     Paul van Delst, CIMSS/SSEC 20-Sep-2002
                       paul.vandelst@ssec.wisc.edu

PP_TO_MD

 NAME:
       PP_to_MD

 PURPOSE:
       Function to convert gas concentrations in pressure units to 
       mass density.

 CALLING SEQUENCE:
       Mass_Density = PP_to_MD( Pressure,                &  ! Input
                                Temperature,             &  ! Input
                                Molecule_ID=Molecule_ID, &  ! Optional Input
                                Message_Log=Message_Log  )  ! Error messaging

 INPUT ARGUMENTS:
       Pressure:          Total or partial pressure to provide number
                          density of air or specific gas species.
                          UNITS:      hectoPascals, hPa
                          TYPE:       REAL(fp)
                          DIMENSION:  Scalar or Rank-1
                          ATTRIBUTES: INTENT(IN)
   
       Temperature:       Atmospheric temperature
                          UNITS:      Kelvin, K
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as pressure
                          ATTRIBUTES: INTENT(IN)
   
 OPTIONAL INPUT ARGUMENTS:
       Molecule_ID:       HITRAN molecular designation identifying the
                          molecule for which the concentration units
                          conversion is required. If not specified, the
                          default value is that for water vapor.
                          Valid values are:
                            1: H2O       9: SO2      17: HI       25: H2O2
                            2: CO2      10: NO2      18: ClO      26: C2H2
                            3: O3       11: NH3      19: OCS      27: C2H6
                            4: N2O      12: HNO3     20: H2CO     28: PH3
                            5: CO       13: OH       21: HOCl     29: COF2
                            6: CH4      14: HF       22: N2       30: SF6
                            7: O2       15: HCl      23: HCN      31: H2S
                            8: NO       16: HBr      24: CH3Cl    32: HCOOH
                          UNITS:      N/A
                          TYPE:       INTEGER
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

       Message_Log:       Character string specifying a filename in which any
                          Messages will be logged. If not specified, or if an
                          error occurs opening the log file, the default action
                          is to output Messages to standard output.
                          UNITS:      N/A
                          TYPE:       CHARACTER(*)
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

 FUNCTION RESULT:
       Mass_Density:      Number density of gas. If an error occurs,
                          -1.0 is returned.
                          UNITS:      g/m^3
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as input Pressure

 PROCEDURE:
       The ideal gas law is

         p.V = n.R.T

       where,
         p = Pressure
         V = volume
         n = number of moles of the gas,
         R = molar gas constant,
         T = Temperature.

       This can be written in terms of the number of molecules, N,

                 N
         p.V = ---- . R.T                  ..............(1)
                NA

       where NA = Avogadro's constant (number of molecules in 1 mole.)

       Eqn.(1) can be recast to provide the number of molecules in the 
       volume, the number density, nd,

               N     p.NA
         nd = --- = ------  molecules/m^3  ..............(2)
               V     R.T

       The mass density is related to the number density by the simple
       relation,

                    MW
         md = nd . ----                    ..............(3)
                    NA

       Substituting equation (2) into (3) gives,

               p.MW
         md = ------  g/m^3                ..............(4)
               R.T

       The value of p0 used in this routine is expressed in pascals (Pa) whereas
       the input partial Pressure is expected to be hPa (more common unit). Thus
       there is a factor of 100 to include,

               100.p.MW
         md = ----------  g/m^3
                 R.T

 UNITS ANALYSIS:
       p  :  kg.m^-1.s^-2  (Pascals)
       MW :  g.mol^-1
       R  :  J.mol^-1.K^-1 == kg.m^2.s^-2.mol^-1.K^-1
       T  :  K

                  kg       g      s^2.mol.K     1
         md == ------- . ----- . ----------- . ---
                m.s^2     mol      kg.m^2       K

                 g
            == -----
                m^3

 CREATION HISTORY:
       Written by:     Paul van Delst, CIMSS/SSEC 08-Nov-2004
                       paul.vandelst@ssec.wisc.edu

MD_TO_PP

 NAME:
       MD_to_PP

 PURPOSE:
       Function to convert gas concentration mass density to partial
       pressure.

 CALLING SEQUENCE:
       Pressure = MD_to_PP( Mass_Density,            &  ! Input
                            Temperature,             &  ! Input
                            Molecule_ID=Molecule_ID, &  ! Optional Input
                            Message_Log=Message_Log  )  ! Error messaging

 INPUT ARGUMENTS:
       Mass_Density:      Number density of gas.
                          UNITS:      g/m^3
                          TYPE:       REAL(fp)
                          DIMENSION:  Scalar or Rank-1
                          ATTRIBUTES: INTENT(IN)
   
       Temperature:       Atmospheric temperature
                          UNITS:      Kelvin, K
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as Mass_Density
                          ATTRIBUTES: INTENT(IN)
   
 OPTIONAL INPUT ARGUMENTS:
       Molecule_ID:       HITRAN molecular designation identifying the
                          molecule for which the concentration units
                          conversion is required. If not specified, the
                          default value is that for water vapor.
                          Valid values are:
                            1: H2O       9: SO2      17: HI       25: H2O2
                            2: CO2      10: NO2      18: ClO      26: C2H2
                            3: O3       11: NH3      19: OCS      27: C2H6
                            4: N2O      12: HNO3     20: H2CO     28: PH3
                            5: CO       13: OH       21: HOCl     29: COF2
                            6: CH4      14: HF       22: N2       30: SF6
                            7: O2       15: HCl      23: HCN      31: H2S
                            8: NO       16: HBr      24: CH3Cl    32: HCOOH
                          UNITS:      N/A
                          TYPE:       INTEGER
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

       Message_Log:       Character string specifying a filename in which any
                          Messages will be logged. If not specified, or if an
                          error occurs opening the log file, the default action
                          is to output Messages to standard output.
                          UNITS:      N/A
                          TYPE:       CHARACTER(*)
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

 FUNCTION RESULT:
       Pressure:          Partial pressure for specified gas species.
                          UNITS:      hectoPascals, hPa
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as input Mass_Density

 PROCEDURE:
       The ideal gas law is

         p.V = n.R.T

       where,
         p = Pressure
         V = volume
         n = number of moles of the gas,
         R = molar gas constant,
         T = Temperature.

       This can be written in terms of the number of molecules, N,

                 N
         p.V = ---- . R.T                  ..............(1)
                NA

       where NA = Avogadro's constant (number of molecules in 1 mole.)

       Eqn.(1) can be recast to provide the number of molecules in the 
       volume, the number density, nd,

               N     p.NA
         nd = --- = ------  molecules/m^3  ..............(2)
               V     R.T

       The mass density is related to the number density by the simple
       relation,

                    MW
         md = nd . ----                    ..............(3)
                    NA

       Substituting equation (2) into (3) gives,

               p.MW
         md = ------  g/m^3                ..............(4)
               R.T

       and inverting equation (4) gives,

              md.R.T
         p = -------- Pa
                MW

       The pressure result above is determined in units of Pascals, so there
       is a factor of 100 to include to return the pressure in units of
       hectoPascals,

              md.R.T
         p = -------- hPa
              100.MW

 UNITS ANALYSIS:
       md :  g.m^-3
       R  :  J.mol^-1.K^-1 == kg.m^2.s^-2.mol^-1.K^-1
       T  :  K
       MW :  g.mol^-1

                g        kg.m^2          mol
         p == ----- . ----------- . K . -----
               m^3     s^2.mol.K          g

                 kg
           == -------
               m.s^2

               kg.m.s^-2      F
           == ----------- == --- == pressure.
                  m^2         A

 CREATION HISTORY:
       Written by:     Paul van Delst, CIMSS/SSEC 08-Nov-2004
                       paul.vandelst@ssec.wisc.edu

PP_TO_ND

 NAME:
       PP_to_ND

 PURPOSE:
       Function to convert gas concentrations in pressure units to 
       number density.

 CALLING SEQUENCE:
       Number_Density = PP_to_ND( Pressure,                 &  ! Input
                                  Temperature,              &  ! Input
                                  Message_Log=Message_Log )  ! Error messaging

 INPUT ARGUMENTS:
       Pressure:          Total or partial pressure to provide number
                          density of air or specific gas species.
                          UNITS:      hectoPascals, hPa
                          TYPE:       REAL(fp)
                          DIMENSION:  Scalar or Rank-1 (K x 1)
                          ATTRIBUTES: INTENT(IN)
   
       Temperature:       Atmospheric temperature
                          UNITS:      Kelvin, K
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as Pressure
                          ATTRIBUTES: INTENT(IN)
   
 OPTIONAL INPUT ARGUMENTS:
       Message_Log:       Character string specifying a filename in which any
                          Messages will be logged. If not specified, or if an
                          error occurs opening the log file, the default action
                          is to output Messages to standard output.
                          UNITS:      N/A
                          TYPE:       CHARACTER(*)
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

 FUNCTION RESULT:
       Number_Density:    Number density of gas. If an error occurs,
                          -1.0 is returned.
                          UNITS:      molecules/m^3
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as input Pressure

 PROCEDURE:
       The ideal gas law is

         p.V = n.R.T

       where,
         p = Pressure
         V = volume
         n = number of moles of the gas,
         R = molar gas constant,
         T = Temperature.

       This can be written in terms of the number of molecules, N,

                 N
         p.V = ---- . R.T                  ..............(1)
                NA

       where NA = Avogadro's constant (number of molecules in 1 mole.)

       Eqn.(1) can be recast to provide the number of molecules in the 
       volume, the number density, nd,

               N     p.NA
         nd = --- = ------  molecules/m^3  ..............(2)
               V     R.T

       At standard Temperature and Pressure (T0=273.15K, p0=101325Pa), this
       number density is know as the Loschmidt constant, L0, the molecular
       density of 1 mole of an ideal gas. Thus we have the generic form of
       eqn.(2) and the STP form,

               p0.NA
         L0 = -------  molecules/m^3       ..............(3)
               R.T0

       Taking the ratio of eqns.(2) and (3) gives,
       
         nd    p.NA     R.T0
         -- = ------ . -------
         L0    R.T      p0.NA

       and rearranging gives,

                    p      T0
         nd = L0 . ---- . ----  molecules/m^3
                    p0     T 

       The value of p0 used in this routine is expressed in pascals (Pa) whereas
       the input partial Pressure is expected to be hPa (more common unit). Thus
       there is a factor of 100 to include,

                    100.p     T0
         nd = L0 . ------- . ----  molecules/m^3
                     p0       T 

 CREATION HISTORY:
       Written by:     Paul van Delst, CIMSS/SSEC 15-Nov-2001
                       paul.vandelst@ssec.wisc.edu

ND_TO_PP

 NAME:
       ND_to_PP

 PURPOSE:
       Function to convert gas concentrations from number density to
       pressure units.

 CALLING SEQUENCE:
       Partial_Pressure = ND_to_PP( Number_Density,         &  ! Input
                                    Temperature,            &  ! Input
                                    Message_Log=Message_Log )  ! Error messaging

 INPUT ARGUMENTS:
       Number_Density:    Molecular density.
                          UNITS:      molecules/m^3
                          TYPE:       REAL(fp)
                          DIMENSION:  Scalar or Rank-1 (K x 1)
                          ATTRIBUTES: INTENT(IN)
   
       Temperature:       Atmospheric Temperature
                          UNITS:      Kelvin, K
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as Number_Density
                          ATTRIBUTES: INTENT(IN)
   
 OPTIONAL INPUT ARGUMENTS:
       Message_Log:       Character string specifying a filename in which any
                          Messages will be logged. If not specified, or if an
                          error occurs opening the log file, the default action
                          is to output Messages to standard output.
                          UNITS:      N/A
                          TYPE:       CHARACTER(*)
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

 FUNCTION RESULT:
       Partial_Pressure:  Gas partial pressure. If an error occurs,
                          -1.0 is returned.
                          UNITS:      hectoPascals, hPa
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as input Number_Density

 PROCEDURE:
       The ideal gas law is

         p.V = n.R.T

       where,
         p = Pressure
         V = volume
         n = number of moles of the gas,
         R = molar gas constant,
         T = Temperature.

       This can be written in terms of the number of molecules, N,

                 N
         p.V = ---- . R.T                  ..............(1)
                NA

       where NA = Avogadro's constant (number of molecules in 1 mole.)

       Recasting eqn.(1) to provide the Pressure,

              nd
         p = ---- . R.T  Pa                ..............(2)
              NA

       where nd = the number density in molecules/m^3 = N/V.

       At standard Temperature and Pressure (T0=273.15K, p0=101325Pa), the
       number density of eqn.(2) is known as the Loschmidt constant, L0,
       the molecular density of 1 mole of an ideal gas. Thus we have the
       generic form of eqn.(2) and the STP form,

               L0
         p0 = ---- . R.T0  Pa              ..............(3)
               NA

       Taking the ratio of eqns.(2) and (3) gives,
       
          p      nd     T
         ---- = ---- . ----  Pa
          p0     L0     T0

       and rearranging gives,

                   nd      T
         p = p0 . ---- . ----  Pa
                   L0     T0 

       The value of p0 used in this routine is expressed in pascals (Pa) whereas
       the output Pressure is returned as hPa (more common unit). Thus there
       is a factor of 100 to include,

                          nd      T
         p = 0.01 . p0 . ---- . ----  hPa
                          L0     T0 

 CREATION HISTORY:
       Written by:     Paul van Delst, CIMSS/SSEC 15-Nov-2001
                       paul.vandelst@ssec.wisc.edu

PPMV_TO_ND

 NAME:
       PPMV_to_ND

 PURPOSE:
       Function to convert volume mixing ratio in ppmv to number density.

 CALLING SEQUENCE:
       Number_Density = PPMV_to_ND( Pressure,                &  ! Input
                                    Temperature,             &  ! Input
                                    ppmv,                    &  ! Input
                                    Water_Vapor=Water_Vapor, &  ! Optional Input
                                    Message_Log=Message_Log  )  ! Error messaging

 INPUT ARGUMENTS:
       Pressure:         Total atmospheric pressure.
                         UNITS:      hectoPascals, hPa
                         TYPE:       REAL(fp)
                         DIMENSION:  Scalar or Rank-1 (K x 1)
                         ATTRIBUTES: INTENT(IN)

       Temperature:      Atmospheric temperature
                         UNITS:      Kelvin, K
                         TYPE:       REAL(fp)
                         DIMENSION:  Same as Pressure
                         ATTRIBUTES: INTENT(IN)

       ppmv:             Volume mixing ratio.
                         UNITS:      ppmv
                         TYPE:       REAL(fp)
                         DIMENSION:  Same as Pressure
                         ATTRIBUTES: INTENT(IN)

 OPTIONAL INPUT ARGUMENTS:
       Water_Vapor:      Water vapor number density. If this argument is
                         not supplied, the mandatory PPMV input argument
                         is assumed to be water vapor.
                         UNITS:      molecules/m^3
                         TYPE:       REAL(fp)
                         DIMENSION:  Scalar or Rank-1 (K x 1)
                         ATTRIBUTES: INTENT(IN)

       Message_Log:      Character string specifying a filename in which any
                         Messages will be logged. If not specified, or if an
                         error occurs opening the log file, the default action
                         is to output Messages to standard output.
                         UNITS:      N/A
                         TYPE:       CHARACTER(*)
                         DIMENSION:  Scalar
                         ATTRIBUTES: OPTIONAL, INTENT(IN)

 FUNCTION RESULT:
       Number_Density:   Number density of gas. If an error occurs,
                         -1.0 is returned.
                         UNITS:      molecules/m^3
                         TYPE:       REAL(fp)
                         DIMENSION:  Same as input Pressure

 PROCEDURE:
       To convert the volume mixing ratio of a molecular species, designated
       by MOL, to number density, the following is used,

         nd(MOL) = 1.0e-06 . ppmv(MOL) . ( nd(TOT) - nd(H2O) )     .....(1)

       where
                         Pressure          T0
         nd(TOT) = L0 . ---------- . -------------  molecules/m^3
                            p0        Temperature 

       and L0 = Loschmidt number,
           p0 = Standard pressure,
           T0 = Standard temperature.

       If the input molecule is water vapor, the number density is
       determined using,

                        ppmv(H2O) . 1.0e-06
         nd(H2O) = ----------------------------- . nd(TOT)     .....(2)
                    1 + ( ppmv(H2O) . 1.0e-06 )

       Rearranging eqn.(2) gives the same form as eqn.(1).

       This is based on the same methods used in the LBLRTM conversion code
       in its lblatm.f module where molecular mixing ratios (either ppmv or
       g/kg) are always with respect to DRY AIR.

 CREATION HISTORY:
       Written by:     Paul van Delst, CIMSS/SSEC 15-Nov-2001
                       paul.vandelst@ssec.wisc.edu

ND_TO_PPMV

 NAME:
       ND_to_PPMV

 PURPOSE:
       Function to convert gas concentrations from number density to volume
       mixing ratio in ppmv.

 CALLING SEQUENCE:
       ppmv = ND_to_PPMV( Pressure,                &  ! Input
                          Temperature,             &  ! Input
                          Number_Density,          &  ! Input
                          Water_Vapor=Water_Vapor, &  ! Optional Input
                          Message_Log=Message_Log  )  ! Error messaging

 INPUT ARGUMENTS:
       Pressure:          Total atmospheric pressure.
                          UNITS:      hectoPascals, hPa
                          TYPE:       REAL(fp)
                          DIMENSION:  Scalar or Rank-1 (K x 1)
                          ATTRIBUTES: INTENT(IN)
   
       Temperature:       Atmospheric temperature
                          UNITS:      Kelvin, K
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as Pressure
                          ATTRIBUTES: INTENT(IN)
   
       Number_Density:    Molecular number density.
                          UNITS:      molecules/m^3
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as Pressure
                          ATTRIBUTES: INTENT(IN)
   
 OPTIONAL INPUT ARGUMENTS:
       Water_Vapor:       Water vapor volume mixing ratio. If this argument is
                          not supplied, the mandatory NUMBER_DENSITY input
                          argument is assumed to be water vapor.
                          UNITS:      ppmv
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as Pressure
                          ATTRIBUTES: INTENT(IN)

       Message_Log:       Character string specifying a filename in which any
                          Messages will be logged. If not specified, or if an
                          error occurs opening the log file, the default action
                          is to output Messages to standard output.
                          UNITS:      N/A
                          TYPE:       CHARACTER(*)
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

 FUNCTION RESULT:
       ppmv:              Gas volume mixing ratio. If an error occurs,
                          -1.0 is returned.
                          UNITS:      ppmv
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as input Pressure

 PROCEDURE:
       To convert the number density of a molecular species, designated
       by MOL, to volume mixing ratio, the following is used,

                                  nd(MOL)
         ppmv(MOL) = 1.0e+06 . -------------
                                nd(DRY_AIR)

       where

         nd(DRY_AIR) = nd(TOT) - nd(H2O)

       and
                         Pressure          T0
         nd(TOT) = L0 . ---------- . -------------  molecules/m^3
                            p0        Temperature 

       with L0 = Loschmidt number,
            p0 = Standard pressure,
            T0 = Standard temperature, and

       If the input molecule is NOT water vapor, the dry air number density
       is determined using,

                                     1
         nd(DRY_AIR) = ----------------------------- . nd(TOT)
                        1 + ( ppmv(H2O) . 1.0e-06 )

       This is based on the same methods used in the LBLRTM conversion code
       in its lblatm.f module where molecular mixing ratios (either ppmv or
       g/kg) are always with respect to DRY AIR.


 CREATION HISTORY:
       Written by:     Paul van Delst, CIMSS/SSEC 15-Nov-2001
                       paul.vandelst@ssec.wisc.edu

PPMV_TO_KMOL

 NAME:
       PPMV_to_KMOL

 PURPOSE:
       Function to convert layer gas concentrations from volume mixing ratio
       in ppmv to column density in kmol.cm^-2.

 CALLING SEQUENCE:
       kmol_per_cm2 = PPMV_to_KMOL( Pressure,                &  ! Input
                                    Temperature,             &  ! Input
                                    Delta_Z,                 &  ! Input
                                    ppmv,                    &  ! Input
                                    Water_Vapor=Water_Vapor, &  ! Optional Input
                                    Message_Log=Message_Log  )  ! Error messaging

 INPUT ARGUMENTS:
       Pressure:          Average layer pressure.
                          UNITS:      hectoPascals, hPa
                          TYPE:       REAL(fp)
                          DIMENSION:  Scalar or Rank-1 (K x 1)
                          ATTRIBUTES: INTENT(IN)

       Temperature:       Average layer temperature
                          UNITS:      Kelvin, K (K)
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as Pressure
                          ATTRIBUTES: INTENT(IN)

       Delta_Z:           Layer thickness
                          UNITS:      metres, m
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as Pressure
                          ATTRIBUTES: INTENT(IN)

       ppmv:              Average layer gas concentration
                          UNITS:      ppmv
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as Pressure
                          ATTRIBUTES: INTENT(IN)
   
 OPTIONAL INPUT ARGUMENTS:
       Water_Vapor:       Water vapor column density. If this argument is
                          not supplied, the mandatory PPMV input
                          argument is assumed to be water vapor.
                          UNITS:      kmol.cm^-2
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as Pressure
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

       Message_Log:       Character string specifying a filename in which any
                          Messages will be logged. If not specified, or if an
                          error occurs opening the log file, the default action
                          is to output Messages to standard output.
                          UNITS:      N/A
                          TYPE:       CHARACTER(*)
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

 FUNCTION RESULT:
       kmol_per_cm2:      Layer gas concentration. If an error occurs,
                          -1.0 is returned.
                          UNITS:      kmol.cm^-2
                          TYPE:       REAL(fp)
                          DIMENSION:  Same input Pressure

 PROCEDURE:
       The column density of a particular molecular species, designated
       by MOL, given its volume mixing ratio is then given by,

         cd(MOL) = 1.0e-06 . ppmv(MOL) . cd(DRY_AIR)  kmol.cm^-2

       First, the total number density is calculated using,

                         p      T0
         nd(TOT) = L0 . ---- . ----  molecules.m^-3
                         p0     T 

       and L0 = Loschmidt number,
           p0 = Standard pressure,
           T0 = Standard temperature.

       The total column density is calculated by multiplying the number
       density by the layer thickness in metres, dz,

         cd(TOT) = dz . nd(TOT)  molecules.m^-2

       This result is scaled by:
         a) 10^-4 to convert molecules.m^-2 to molecules.cm^-2
         b) 1/Na to convert molecules.cm^-2 to mol.cm^-2, and
         c) 10^-3 to convert mol.cm^-2 to kmol.cm^-2
       giving,
                    1.0e-07
         cd(TOT) = --------- . dz . nd(TOT)  kmol.cm^-2
                      Na
      
       The dry air column density is then calculated using,

                                    1
         cd(DRY_AIR) = ----------------------------- . cd(TOT)  kmol.cm^-2
                        1 + ( ppmv(H2O) . 1.0e-06 )

       for water vapor ppmv input or,

         cd(DRY_AIR) = cd(TOT) - cd(H2O)

       if cd(H2O) is supplied via the optional Water_Vapor argument.

 CREATION HISTORY:
       Written by:     Paul van Delst, CIMSS/SSEC 04-Jan-2001
                       paul.vandelst@ssec.wisc.edu

KMOL_TO_PPMV

 NAME:
       KMOL_to_PPMV

 PURPOSE:
       Function to convert layer gas concentrations from column density in
       kmol.cm^-2 to volume mixing ratio in ppmv.

 CALLING SEQUENCE:
       ppmv = KMOL_to_PPMV( Pressure,                &  ! Input
                            Temperature,             &  ! Input
                            Delta_Z,                 &  ! Input
                            kmol_per_cm2,            &  ! Input
                            Water_Vapor=Water_Vapor, &  ! Optional Input
                            Message_Log=Message_Log  )  ! Error messaging

 INPUT ARGUMENTS:
       Pressure:          Average layer pressure.
                          UNITS:      hectoPascals, hPa
                          TYPE:       REAL(fp)
                          DIMENSION:  Scalar or Rank-1 (K x 1)
                          ATTRIBUTES: INTENT(IN)

       Temperature:       Average layer temperature
                          UNITS:      Kelvin, K
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as Pressure
                          ATTRIBUTES: INTENT(IN)

       Delta_Z:           Layer thickness
                          UNITS:      metres, m
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as Pressure
                          ATTRIBUTES: INTENT(IN)

       kmol_per_cm2:      Column density for molecular species.
                          UNITS:      kmol.cm^-2
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as Pressure
                          ATTRIBUTES: INTENT(IN)
   
 OPTIONAL INPUT ARGUMENTS:
       Water_Vapor:       Water vapor volume mixing ratio. If this argument
                          is not supplied, the mandatory KMOL_PER_CM2 input
                          argument is assumed to be water vapor.
                          UNITS:      ppmv
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as pressure
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

       Message_Log:       Character string specifying a filename in which any
                          Messages will be logged. If not specified, or if an
                          error occurs opening the log file, the default action
                          is to output Messages to standard output.
                          UNITS:      N/A
                          TYPE:       CHARACTER(*)
                          DIMENSION:  Scalar
                          ATTRIBUTES: OPTIONAL, INTENT(IN)

 FUNCTION RESULT:
       ppmv:              Layer gas volume mixing ratio. If an error occurs,
                          -1.0 is returned.
                          UNITS:      ppmv
                          TYPE:       REAL(fp)
                          DIMENSION:  Same as input Pressure

 PROCEDURE:
       The volume mixing ratio of a particular molecular species, designated
       by MOL, given it's column density is given by,

                                  cd(MOL)
         ppmv(MOL) = 1.0e-06 . -------------
                                cd(DRY_AIR)

       First, the total number density is calculated using,

                         p      T0
         nd(TOT) = L0 . ---- . ----  molecules.m^-3
                         p0     T 

       and L0 = Loschmidt number,
           p0 = Standard pressure,
           T0 = Standard temperature.

       The total column density is calculated by multiplying the number
       density by the layer thickness in metres, dz,

         cd(TOT) = dz . nd(TOT)  molecules.m^-2

       This result is scaled by:
         a) 10^-4 to convert molecules.m^-2 to molecules.cm^-2
         b) 1/Na to convert molecules.cm^-2 to mol.cm^-2, and
         c) 10^-3 to convert mol.cm^-2 to kmol.cm^-2
       giving,
                    1.0e-07
         cd(TOT) = --------- . dz . nd(TOT)  kmol.cm^-2
                      Na
      
       The dry air column density is then calculated using,

                                    1
         cd(DRY_AIR) = ----------------------------- . cd(TOT)  kmol.cm^-2
                        1 + ( ppmv(H2O) . 1.0e-06 )

       for water vapor ppmv input or,

         cd(DRY_AIR) = cd(TOT) - cd(H2O)

       if cd(H2O) is supplied via the optional Water_Vapor argument.

 CREATION HISTORY:
       Written by:     Paul van Delst, CIMSS/SSEC 04-Jan-2001
                       paul.vandelst@ssec.wisc.edu