#windchill.cgi by Tim Brice NWS El Paso
#convert celsius to fahrenheit and vice versa
if ($wc{temp} =~ /-?(\d+)\.?(\d+)|-?(\d+)$/) {
if ($wc{corf} eq Fahrenheit) {
$F = $wc{temp};
$C = 5/9 * ($wc{temp} - 32);
} else {
$F = (9/5 * $wc{temp}) + 32;
$C = $wc{temp};
}
} else {
print "An illegal character was entered\n";
die
}
#convert the wind units
if ($wc{wind} =~ /(\d+)\.?(\d+)|^\d+$/) {
if ($wc{units} eq mph) {
$MPH = $wc{wind};
} elsif ($wc{units} eq knots) {
$Knts = $wc{wind};
$MPH = $Knts/0.868391;
} elsif ($wc{units} eq KperH) {
$KPH = $wc{wind};
$MPH = 0.621371 * $KPH;
} else {
$MperS = $wc{wind};
$MPH = $MperS/0.44704;
}
} else {
print "An illegal charatcer was entered\n";
die
}
#finally, calculate the wind chill
$windc=0.0817*(3.71*$MPH**0.5 + 5.81 - 0.25*$MPH)*($F - 91.4) + 91.4;
$windcc = 5/9 * ($windc - 32);
#For our Canadian friends
$MperS = $MPH * 0.44704;
$watts = (12.1452 + 11.6222 * sqrt($MperS) - 1.16222 * $MperS) * (33 - $C);
#its output format time
if ($wc{corf} eq Fahrenheit) {
$~ = WC1;
write;
format WC1 =
With an air temperature of @###.# degrees Fahrenheit and a
$F
.
} else {
$~ = WC2;
write;
format WC2 =
With an air temperature of @###.# degrees Celsius and a
$C
.
}
if ($wc{units} eq mph) {
$~ = WC3;
write;
format WC3 =
wind speed of @##.# Miles per Hour, you get a wind chill of:
$MPH
.
} elsif ($wc{units} eq knots) {
$~ = WC4;
write;
format WC4 =
wind speed of @##.# Knots, you get a wind chill of:
$Knts
.
} elsif ($wc{units} eq KperH) {
$~ = WC5;
write;
format WC5 =
wind speed of @##.# Kilometers per Hour, you get a wind chill of:
$KPH
.
} else {
$~ = WC6;
write;
format WC6 =
wind speed of @##.# Meters per Second, you get a wind chill of:
$MperS
.
}
print "";
$~ = WC7;
write;
format WC7 =
@###.# degrees Fahrenheit or @###.# degrees Celsius.
$windc $windcc
.
$~ = WC8;
write;
format WC8 =
For our Canadian viewers that also equals @### watts per meter squared.
$watts
.
print "
Please note that the formula used to calculate the wind chill
factor is only an approximation of the wind chill factor. Do to the
complex nature of human and environment interaction it is impossible to come
up with a formula that can exactly give you the wind chill factor, but we
can come up with a pretty close approximation.";