Skip to content

Instantly share code, notes, and snippets.

@mc3k
Last active June 5, 2025 12:32
Show Gist options
  • Select an option

  • Save mc3k/9832124baef7b52e8d496bc61889151a to your computer and use it in GitHub Desktop.

Select an option

Save mc3k/9832124baef7b52e8d496bc61889151a to your computer and use it in GitHub Desktop.
Creates a function in MariaDB for the computation of the heat index
CREATE OR REPLACE FUNCTION CalcHeatIndex(IN T FLOAT, IN RH FLOAT) RETURNS FLOAT
BEGIN
# https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml
DECLARE HI, HI2, HI2a, HI3 float;
SET T = ((T*9/5)+32 ); # convert C to F
SET HI = (0.5*(T + 61.0 + ((T-68.0)*1.2) + (RH*0.094)));
SET HI2 = (-42.379 + 2.04901523*T + 10.14333127*RH - 0.22475541*T*RH - 0.00683783*T*T - 0.05481717*RH*RH + 0.00122874*T*T*RH + 0.00085282*T*RH*RH - 0.00000199*T*T*RH*RH);
SET HI2a = - ((13-RH)/4)*sqrt((17-abs(T-95))/17);
SET HI3 = CASE WHEN (HI < 80) THEN HI
WHEN (RH > 85 AND T > 80 AND T < 87) THEN HI2-HI2a
ELSE HI2 END;
SET HI3 = (HI3-32)*5/9;
RETURN HI3;
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment