Skip to content

Commit 093fbf0

Browse files
committed
+ version 0.1.00 (initial)
1 parent 07534d7 commit 093fbf0

2 files changed

Lines changed: 129 additions & 0 deletions

File tree

libraries/Temperature/readme.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
Small collection of temperature related functions
3+
4+
TODO:
5+
- make all celsius variants of them
6+
- Class with option F / K / C ?
7+
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
//
2+
// FILE: temperature.h
3+
// VERSION: 0.1.00
4+
// PURPOSE: temperature functions
5+
//
6+
// HISTORY:
7+
// see temperature.cpp file
8+
//
9+
10+
#ifndef TEMPERATURE
11+
#define TEMPERATURE
12+
13+
#include "WProgram.h"
14+
15+
#define TEMPERATURE_VERSION "0.1.00"
16+
17+
//Celsius to Fahrenheit conversion
18+
double Fahrenheit(double celsius)
19+
{
20+
return 1.8 * celsius + 32;
21+
}
22+
23+
//Celsius to Kelvin conversion
24+
double Kelvin(double celsius)
25+
{
26+
return celsius + 273.15;
27+
}
28+
29+
// dewPoint function NOAA
30+
// reference: http://wahiduddin.net/calc/density_algorithms.htm
31+
double dewPoint(double celsius, double humidity)
32+
{
33+
double A0= 373.15/(273.15 + celsius);
34+
double SUM = -7.90298*(A0-1);
35+
SUM += 5.02808 * log10(A0);
36+
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
37+
SUM += 8.1328e-3*(pow(10,(-3.49149*(A0-1)))-1) ;
38+
SUM += log10(1013.246);
39+
double VP = pow(10, SUM-3) * humidity;
40+
double T = log(VP/0.61078); // temp var
41+
return (241.88*T) / (17.558-T);
42+
}
43+
44+
// delta max = 0.6544
45+
// 5x faster than dewPoint()
46+
// reference: http://en.wikipedia.org/wiki/Dew_point
47+
double dewPointFast(double celsius, double humidity)
48+
{
49+
double a = 17.271;
50+
double b = 237.7;
51+
double temp = (a * celsius) / (b + celsius) + log(humidity/100);
52+
double Td = (b * temp) / (a - temp);
53+
return Td;
54+
}
55+
56+
// http://www.ccacac.com/wp-content/uploads/2010/06/Humidex-Graph.pdf -
57+
double humidex(double celsius, double DewPoint)
58+
{
59+
double e = 19.833625 - 5417.753 /(273.16 + DewPoint);
60+
double h = celsius + 3.3941 * exp(e) - 5.555;
61+
return h;
62+
}
63+
64+
65+
// TF = temp in F
66+
// R = humidity in %
67+
double heatIndex(double TF, double R)
68+
{
69+
const double c1 = -42.379;
70+
const double c2 = 2.04901523;
71+
const double c3 = 10.14333127;
72+
const double c4 = -0.22475541;
73+
const double c5 = -0.00683783;
74+
const double c6 = -0.05481717;
75+
const double c7 = 0.00122874;
76+
const double c8 = 0.00085282;
77+
const double c9 = -0.00000199;
78+
79+
double A = (( c5 * TF) + c2) * TF + c1;
80+
double B = (((c7 * TF) + c4) * TF + c3) * R;
81+
double C = (((c9 * TF) + c8) * TF + c6) * R * R;
82+
83+
return A + B + C;
84+
}
85+
86+
// less constants => faster but slightly inaccurate
87+
// TF = temp in F
88+
// R = humidity in %
89+
double heatIndexFast(double TF, double R)
90+
{
91+
const double c1 = -42.379;
92+
const double c2 = 2.04901523;
93+
const double c3 = 10.14333127;
94+
const double c4 = -0.22475541;
95+
96+
double A = c2 * TF + c1;
97+
double B = (c4 * TF + c3) * R;
98+
99+
return A + B;
100+
}
101+
102+
// integer version
103+
// TF = temp in F
104+
// R = humidity in %
105+
int heatIndexFastInt(int TF, int R)
106+
{
107+
// consts multiplied by 1024
108+
long c1 = -43396;
109+
long c2 = 2098;
110+
long c3 = 10387;
111+
long c4 = -230;
112+
113+
long A = c2 * TF + c1; // so A is x 1024
114+
long B = (c4 * TF + c3) * R; // and B too
115+
116+
return (A + B + 512) / 1024; // division becomes a shift; +512 is for rounding
117+
}
118+
119+
#endif
120+
//
121+
// END OF FILE
122+
//

0 commit comments

Comments
 (0)