Implement all required conversion functions

This commit is contained in:
2024-09-19 17:28:41 +02:00
parent d18b6072ba
commit b3fda53036

View File

@@ -1,43 +1,56 @@
#include "common.h"
#include <math.h>
// https://bmcnoldy.earth.miami.edu/Humidity.html
// https://onlinelibrary.wiley.com/doi/abs/10.1002/andp.18280890511
// https://onlinelibrary.wiley.com/doi/abs/10.1002/andp.18441370202
// NOTE: EXP and LN are exponential and natural logarithm functions
// TODO: Make sure all results for conversion functions are correct.
// Conversion constants
static const float C1 = 100.0f;
static const float C2 = 243.04f;
static const float C3 = 17.625f;
// Dewpoint TD
// 243.04*(LN(RH/100)+((17.625*T)/(243.04+T)))/
// (17.625-LN(RH/100)-((17.625*T)/(243.04+T)))
float Dewp(float t, float rh)
{
// TODO
UNUSED(tc);
UNUSED(rh);
float a, b;
return 0.0f;
a = log(rh / C1);
b = C3 * t / (C2 + t);
// 243.04*(LN(RH/100)+((17.625*T)/(243.04+T)))/
// (17.625-LN(RH/100)-((17.625*T)/(243.04+T)))
return C2 * (a + b) / (C3 - a - b);
}
// Temperature T
// 243.04*(((17.625*TD)/(243.04+TD))-LN(RH/100))/
// (17.625+LN(RH/100)-((17.625*TD)/(243.04+TD)))
float Temp(float td, float rh)
{
// TODO
UNUSED(dc);
UNUSED(rh);
float a, b;
return 0.0f;
a = log(rh / C1);
b = C3 * td / (C2 + td);
// 243.04*(((17.625*TD)/(243.04+TD))-LN(RH/100))/
// (17.625+LN(RH/100)-((17.625*TD)/(243.04+TD)))
return C2 * (b - a) / (C3 + a - b);
}
// Relative Humidity RH
// 100*(EXP((17.625*TD)/(243.04+TD))/
// EXP((17.625*T)/(243.04+T)))
float Rhum(float t, float td)
{
// TODO
UNUSED(tc);
UNUSED(dc);
float a, b;
return 0.0f;
a = C3 * td / (C2 + td);
b = C3 * t / (C2 + t);
// 100*(EXP((17.625*TD)/(243.04+TD))/
// EXP((17.625*T)/(243.04+T)))
return C1 * (exp(a) / exp(b));
}