# Advice on approcah for humidity conversions in c#

• a_programmer
In summary, a new member is seeking advice on implementing humidity conversions in code. They have been unsuccessful in finding helpful psychometric functions and only have a few variables to work with. They are open to using the Sonntag or Magnus formula but are struggling as a software engineer. Another colleague suggests using the formula for calculating relative humidity and the original poster eventually finds success with a recursive search.
a_programmer
Hello all,

First off, I would just like to say hello, as I am a new member :)

I was hoping for some advice on implementing humidity conversions in code.
I have spent about 4-5 days trawling the internet for helpful psychometric functions to help convert relative humidity to absolute humidity and back.

Despite numerous attempts, I have failed in implementing anything that will output anything but garbage values. While I may appreciate some of you are thinking that this is a programming problem, i assure you it isn't.

The only variables I have to play around with are the dry bulb temperature of the air, the altitude, the pressure at that altitude and the absolute humidity for the relative humidity calculation ( and vice versa ). I do not have the dew point.

At this juncture, I would be happy to use something like the Sonntag or Magnus formula.
As a software engineer, this is very much out of my league. Thus, if anyone could give some advice on appropriate approaches, I would be most appreciative.

A Programmer

Hello, colleague :)

//Saturated vapor pressure knowledge (by Sonntag or Magnus formula) is quite enough.

double RelativeHumidity(double AbsoluteHumidity, double Temperature)
{
return AbsoluteHumidity / SaturatedVaporPressure(Temperature);
}

Hi Graniar,

Thanks very much for the help. I got it cracked in the end; i used the exact same formula you quoted to get AH, and i just did a recursive search with an increasingly narrow search to provide a decently accurate estimation for the RH.

Thanks again,

A_Programmer

## 1. How do I convert relative humidity to absolute humidity in C#?

To convert relative humidity to absolute humidity in C#, you can use the following formula: absolute humidity = relative humidity * saturation vapor pressure / atmospheric pressure. You will need to have the saturation vapor pressure and atmospheric pressure values for your specific location.

## 2. What is the difference between relative humidity and absolute humidity?

Relative humidity is a measure of the amount of water vapor present in the air compared to the maximum amount of water vapor that the air can hold at a given temperature. Absolute humidity, on the other hand, is a measure of the actual amount of water vapor present in the air.

## 3. How do I convert humidity units from percentage to grams per cubic meter in C#?

To convert from percentage to grams per cubic meter in C#, you will first need to convert the percentage value to a decimal. Then, you can use the following formula: grams per cubic meter = (relative humidity * saturation vapor pressure * 1000) / (gas constant * temperature). You will need to have the saturation vapor pressure, gas constant, and temperature values for your specific location.

## 4. Can I use a library or API to convert humidity units in C#?

Yes, there are several libraries and APIs available for converting humidity units in C#. Some popular options include the National Oceanic and Atmospheric Administration (NOAA) National Centers for Environmental Information (NCEI) API and the MathNet.Numerics library.

## 5. How can I account for temperature in humidity conversions in C#?

To account for temperature in humidity conversions in C#, you will need to have both the temperature and humidity values for your specific location. Then, you can use the appropriate formula for converting between relative and absolute humidity, taking into account the temperature value. You can also use a library or API that includes temperature in its humidity conversion calculations.

Replies
2
Views
2K
Replies
2
Views
1K
Replies
8
Views
10K
Replies
8
Views
7K
Replies
4
Views
321
Replies
8
Views
1K
Replies
2
Views
3K
Replies
11
Views
2K
Replies
5
Views
2K
Replies
3
Views
1K