#heatindex.cgi by Tim Brice NWS El Paso

&ReadParse(*hi);

#convert celsius to farenheit and vice versa

if ($hi{temp} =~ /-?(\d+)\.?(\d+)|\d+/) {
  if ($hi{corf} eq Fahrenheit) {
    $F = $hi{temp};
    $C = 5/9 * ($hi{temp} - 32);
 
 } else  {
 
    $C = $hi{temp};
    $F = (9/5 * $hi{temp}) + 32;
  }
} else {
  print "An illegal character was entered\n";
  die
}

if ($hi{rh} =~ /(\d+)\.?(\d+)|\d+/) {
  $rh = $hi{rh};

} else {
print "An illegal character was entered";
die
}  

#calculate the heat index

$heati=-42.379 + 2.04901523*$F + 10.14333127*$rh - 0.22475541*$F*$rh - 6.83783e-03*$F**2 - 5.481717e-02*$rh**2 + 1.22874e-03*$F**2*$rh + 8.5282e-04*$F*$rh**2 - 1.99e-06*$F**2*$rh**2;
$heatic= 5/9 * ($heati -32); 

#format the output


$~ = HI1;
write;
  
format HI1 =

With an air temperature of @###.# degrees @<<<<<<<<<< and a relative $hi{temp} $hi{corf} humidity of @##.# percent the heat index is: $rh

@###.# degrees Fahrenheit or @###.# degrees Celsius. $heati $heatic . print "

Please note that the formula used to calculate the heat index is only an approximation of the heat index. Do to the complex nature of human and envirionment interaction it is impossible to come up with a formula that can exactly give you the heat index, but we can come up with a pretty close approximation.";