#include <math.h>

/* 
   Sample code for absolute humidity, dewpoint and heat index 
   originally for Sensiron's sht21/sht25.

   Snippets taken from: 
   Sensiron Note: Humidity at a Glance. Aug. 20 2008. Rev 1.0 
   Free to use, 2014 Robert Olsson <robert@radio-sensors.com>
*/

double ah(double rh, double t)
{
  return 216.7*(rh/100.0*6.112*exp(17.62*t/(243.12+t))/(273.15+t));
}

double t_dewpoint(double rh, double t)
{
  double h = (log10(rh)-2.0)/0.4343+(17.62*t)/(243.12+t);
  return 243.12*h/(17.62-h);
}

double t_heat_index(double rh, double t)
{
  double p = rh/100.0*exp(17.62*t/(243.12+t));
  return t+5.0/9.0*(p-10.0); // this is the heat index in Celsius
  // return HIF = 9.0/5.0*HIC+32.0; // this is the heat index in Fahrenheit 
}
