;***************************************************************** ; mxrat_to_rh.pro converts mixing ratio to relative humidity ; ; INPUT ; temp = temperature in Kelvin ; press = pressure in Pascals ; mxrat = mixing ratio in g/kg ; ; OUTPUT ; rh = relative humidity in % ;**************************************************************** pro mxrat_to_rh_1d,mxrat,temp,press,rh ; Get the dimensions of the 1d mxrat variable s=size(mxrat,/dimensions) num_heights=s[0] ; Create an array for saturation vapor pressure (hPa) svp=make_array(/float,num_heights) ; Create an array for saturation mixing ratio smxrat=make_array(/float,num_heights) ; Create an array for relative humidity rh=make_array(/float,num_heights) ; Calculate relative humidity for k=0,num_heights-1 do begin ;loop through height if temp[k] le -8888 or press[k] le -8888 or mxrat[k] le -8888 then begin rh[k]=-9999 endif else begin ; Saturation vapor pressure ; Source: Bolton, D., The computation of equivalent potential temperature, ; Monthly Weather Review, 108, 1046-1053, 1980. equation (10) ; Psat=6.112 * EXP(17.67 * Temp / (Temp+243.5)) ; Temp=Celcius ; Psat=hPa=mb svp[k]=6.112*exp((17.67*(temp[k]-273.15))/((temp[k]-273.15)+243.5)) ; Relationship between vapor pressure and mixing ratio ; w=(0.622 * e)/(P-e) ; w=mixing ratio in kg/kg ; e=vapor pressure in millibars ; P=pressure in millibars ; 1mb=100Pascals ; 1mb=1hPa smxrat[k]=1000.*(0.622*(svp[k]/((press[k]/100.)-svp[k]))) ; Relative Humidity=100*w/ws ; w=mixing ratio ; ws=saturation mixing ratio rh[k]=100.*(mxrat[k]/smxrat[k]) endelse endfor ; Replace rh values greater than 100 with 100 ;result=where(rh gt 100.0,count) ;if count gt 0 then rh[result]=100.0 return end