spechum_to_hr.c File Reference

Compute relative humidity from specific humidity. More...

#include <utils.h>
Include dependency graph for spechum_to_hr.c:

Go to the source code of this file.

Functions

void spechum_to_hr (double *hur, double *tas, double *hus, double *pmsl, double fillvalue, int ni, int nj)
 Compute relative humidity from specific humidity.

Detailed Description

Compute relative humidity from specific humidity.

Definition in file spechum_to_hr.c.


Function Documentation

void spechum_to_hr ( double *  hur,
double *  tas,
double *  hus,
double *  pmsl,
double  fillvalue,
int  ni,
int  nj 
)

Compute relative humidity from specific humidity.

Parameters:
[out] hur Relative humidity (%)
[in] tas Input 2D temperature (K)
[in] hus Input 2D specific humidity (kg/kg)
[in] pmsl Input 2D mean sea-level pressure (hPa)
[in,out] fillvalue Missing Value for temperature and relative humidity
[in] ni First dimension
[in] nj Second dimension

Definition at line 58 of file spechum_to_hr.c.

References K_MD, K_MW, and K_TKELVIN.

Referenced by output_downscaled_analog().

00058                                                                                                      {
00059 
00070   int i; /* Loop counter */
00071 
00072   double curtas; /* Current temperature value */
00073   double curhus; /* Current specific humidity value */
00074   double mixr; /* Mixing ratio */
00075   double es; /* Saturation vapor pressure */
00076   double fact; /* Factor */
00077 
00078   for (i=0; i<(ni*nj); i++) {
00079 
00080     curtas = tas[i];
00081     if (curtas != fillvalue) {
00082       curhus = hus[i] * 1000.0;
00083       
00084       /* Begin by calculating the mixing ratio Q/(1.-Q/1000.) */
00085       mixr = curhus / (1.0 - (curhus / 1000.0));
00086       /* Compute relative humidity from the mixing ratio */
00087       /*                    ;                                     Mw*e              e
00088                             ;  W (mixing ratio) = m_h2o/m_dry = -------- = Mw/Md * ---
00089                             ;                                   Md*(p-e)           p-e
00090                             ;
00091                             ;  RH (rel. hum.)    = e/esat(T)*100.
00092       */
00093       /* Compute saturation vapor pressure in hPa */
00094       /* ; Formula with T = temperature in K
00095          ;    esat = exp( -6763.6/(T+T0) - 4.9283*alog((T+T0)) + 54.2190 )
00096          
00097          ; Formula close to that of Magnus, 1844 with temperature TC in Celsius
00098          ;    ESAT = 6.1078 * EXP( 17.2693882 * TC / (TC + 237.3) ) ; TC in Celsius
00099          
00100          ; or Emanuel's formula (also approximation in form of Magnus' formula,
00101          ; 1844), which was taken from Bolton, Mon. Wea. Rev. 108, 1046-1053, 1980.
00102          ; This formula is very close to Goff and Gratch with differences of
00103          ; less than 0.25% between -50 and 0 deg C (and only 0.4% at -60degC)    
00104          ;    esat=6.112*EXP(17.67*TC/(243.5+TC))
00105          
00106          ; WMO reference formula is that of Goff and Gratch (1946), slightly
00107          ; modified by Goff in 1965:
00108       */
00109       es = 1013.250 * pow( 10.0, ( 10.79586* (1.0-K_TKELVIN/curtas) -
00110                                    5.02808 * log10(curtas/K_TKELVIN) +
00111                                    1.50474 * 0.0001 *
00112                                    (1.0 - pow(10.0, (-8.29692*((curtas/K_TKELVIN)-1.0))) ) +
00113                                    0.42873 * 0.001 *
00114                                    (pow(10.0, (4.76955*(1.0-K_TKELVIN/curtas)))-1.0) - 2.2195983) );
00115       fact = mixr / 1000.0 * (K_MD/K_MW);
00116       /* Use Standard Pressure for now, given altitude.
00117          For more precise values we should use instead a pressure field close to the weather type... */
00118       hur[i] = pmsl[i] / es * fact / (1.0 + fact) * 100.0;
00119       if (hur[i] > 100.0) hur[i] = 100.0;
00120       if (hur[i] < 0.0) hur[i] = 0.0;
00121     }
00122     else
00123       hur[i] = fillvalue;
00124   }
00125 }


Generated on 12 May 2016 for DSCLIM by  doxygen 1.6.1