Still Cold eh!

Well you might of read my recent post on 'Temperature-Windchill' and as I have a few mins I think I will use this post to create and send in a patch to this mod so us Canuck's can us it to on near calm days.

Well I should first provide a little background to justify my patch so here is a link NOAA Wind chill calculatior

and the formula as stolen from the Canadian website

wind <= 5 ) ) {
chill=(temp +((-1.59+0.1345*temp)/5)*wind) ;

and for good measure checking the the US version seem they are a little more lazy and just set the wind chill to be the Ambient temperature if it is about that like this

WindChill = ( 35.74 + 0.6215*TempF - 35.75*Math.pow(WindMph,0.16) + 0.4275*TempF*Math.pow(WindMph,0.16) );
if ( WindChill > Temp) WindChill = Temp;

So as this is Canadian wind chill I will add it in (with some pod as I love that part) as its own function


=head2 windchill_ca( $temperature, $windspeed )
 
Calculates the windchill in International ("SI") units, i.e. temperature in
degrees Celsius and windspeed in kilometers per hour but extends down to 1 kph which is customary to do in Canada.
 
Example:
 
    # what's the windchill at -5 C and 20 KPH?
    my $chill = windchill_si( -5, 20 );
    print "the windchill is: $chill C";
 
=cut
 
sub windchill_ca {
    my ($temp, $windspeed) = @_;
    return windchill_si($temp, $windspeed)
         if $windspeed >5;
    return ($temp +((-1.59+0.1345*$temp)/5)*$windspeed) ; 
}

Also remembering to add it into the export as well first

@EXPORT_OK = qw( windchill_si windchill_us windchill_ca);

As it is not my Mod I will leave all the version and other admin stuff up to the maintainer.

Now it is also nice to send along some tests as well so I came up with


#!perl -T

use Test::More tests => 17;

use_ok('Temperature::Windchill', 'windchill_ca');

# check a range of valid values
{
my $wc = sub {
return 0 + sprintf('%.1f' , windchill_ca(@_))
};
my @valid = (
# temperature, windspeed, windchill
[ 5, 1, 4.8 ],
[ 0, 2, -0.6 ],
[ -5, 3, -6.4 ],
[ -10, 4, -12.3 ],
[ -15, 5, -18.6 ],
[ -20, 1, -20.9 ],
[ -25, 2, -27.0 ],
[ -30, 3, -33.4 ],
[ -35, 4, -40.0 ],
[ -40, 5, -47.0 ],
[ -45, 1, -46.5 ],
[ -10, 2, -11.2 ],
[ -10, 3, -11.8 ],
[ -10, 4, -12.3 ],
[ -10, 5, -12.9 ],
[ -45, 20, -62.0],
);

for (@valid) {
my ($temp, $speed, $chill) = @$_;
is($wc->($temp, $speed), $chill);
}
}

No need to test anything above 5c as it is just a call out to windchill_si for those but I added one in for good measure.

Now this does not seem to have a repo anywhere so off I go to rt.cpan and add in a ticket and lets see what happens

And for every one else here is a funny dog picture

hC2D48441.jpg

Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations