Device-WxM2

 view release on metacpan or  search on metacpan

WxM2.pm  view on Meta::CPAN

		    $self->{windChillLo}, 
		    $self->{hiTemp}, 
		    $self->{loTemp}, 
		    $self->{outHum},
		    $self->{avgDewpoint}, 
		    $self->{avgWindSpeed}, 
		    $self->{windGust}, 
		    $self->{avgWindDir},
		    $self->{rainInPrd}, 
		    $self->{baro}, 
		    $self->{avgInTemp}, 
		    $self->{inHum});

    ##
    ## format of data lines in periodic samples log file
    ##
    format LOG =
@<<<<  @>>>>  @>>>>  @>>>> @>>>>>  @>>>>  @>>>>  @>>  @>>>>  @>>>  @>>>  @>>  @>>>>  @<<<<<  @>>>>  @>>
@log_data
.

    my $log = new FileHandle ">> $self->{archiveLogFile}";
    unless (defined $log) {
	carp "Could not open $self->{archiveLogFile}";
    }

    $log->format_name("LOG");
    #$log->format_top_name("LOG_TOP");

    write $log;
    $log->close;

}

################################################################################
# Weather Calculations (windchill, temp humidity index)
################################################################################
#
# New US/Can Wind Chill - 11/01/2001
#
#  temp in degrees F
#  speed in mph
#
sub windChill {
    my $self = shift;
    my $speed = shift;
    my $temp = shift;
    my $chill;

    if (($speed < 4) || ($temp > 50)) {
	$chill = $temp;
    } else {
	my $v016 = $speed ** 0.16;

	$chill = 35.74 + (0.6215 * $temp) - (35.75 * $v016) + 
	    (0.4275 * $temp * $v016);
    }
    return $chill;
}

# old windchill formula
sub oldWindChill {
    my $self = shift;
    my $speed = $self->{windSpeed};
    my $temp = $self->{outTemp};
    my $chill;
    my @chillTableOne = (156, 151, 146, 141, 133, 123, 110, 87, 61, 14, 0);
    my @chillTableTwo = (0, 16, 16, 16, 25, 33, 41, 74, 82, 152, 0);

    $speed = 50 if $speed > 50;

    my $index = int (10 - $speed/5);
    my $cf = $chillTableOne[$index] +
	($chillTableTwo[$index] / 16) * ($speed % 5);
    if ($temp < 91.4) {
	$chill = $cf * (($temp - 91.4) / 256) + $temp;
    } else {
	$chill = $temp;
    }
    return $chill;
}

sub calcDewPoint {
    my $self = shift;
    my $temp = $self->{avgOutTemp};
    my $rh = $self->{outHum};
    printf "rh=%d temp=%1.1f\n", $rh, $temp if $DEBUG > 0;
    my $tempc = (5.0/9.0)*($temp-32.0);
    my $es = 6.11 * 10.0 ** (7.5 * $tempc / (237.7 + $tempc));
    my $e = ($rh * $es) / 100.0;
    my $dewc = (-430.22 + 237.7 * log($e)) / (19.08 - log($e));
    my $dp = (9.0/5.0) * $dewc + 32;
    printf "tempc=%3.1f es=%4.2f e=%4.2f dewc=%3.1f\n",
    $tempc, $es, $e, $dewc if $DEBUG > 1;
    printf " dp=%3.1f\n", $dp if $DEBUG > 0;
    return $dp;
}

my @thiTable = 
    (
     [ 61, 63, 63, 64, 66, 66, 68, 68, 70, 70, 70], #  68
     [ 63, 64, 65, 65, 67, 67, 69, 69, 71, 71, 72], #  69
     [ 65, 65, 66, 66, 68, 68, 70, 70, 72, 72, 74], #  70
     [ 66, 66, 67, 67, 69, 69, 71, 71, 73, 73, 75], #  71
     [ 67, 67, 68, 69, 70, 71, 72, 72, 74, 74, 76], #  72
     [ 68, 68, 69, 71, 71, 73, 73, 74, 75, 75, 77], #  73
     [ 69, 69, 70, 72, 72, 74, 74, 76, 76, 76, 78], #  74
     [ 70, 71, 71, 73, 73, 75, 75, 77, 77, 78, 79], #  75
     [ 71, 72, 73, 74, 74, 76, 76, 78, 79, 80, 80], #  76
     [ 72, 73, 75, 75, 75, 77, 77, 79, 81, 81, 82], #  77
     [ 74, 74, 76, 76, 77, 78, 79, 80, 82, 83, 84], #  78
     [ 75, 75, 77, 77, 79, 79, 81, 81, 83, 85, 87], #  79
     [ 76, 76, 78, 78, 80, 80, 82, 83, 85, 87, 90], #  80
     [ 77, 77, 79, 79, 81, 81, 83, 85, 87, 89, 93], #  81
     [ 78, 78, 80, 80, 82, 83, 84, 87, 89, 92, 96], #  82
     [ 79, 79, 81, 81, 83, 85, 85, 89, 91, 95, 99], #  83
     [ 79, 80, 81, 82, 84, 86, 87, 91, 94, 98,103], #  84
     [ 80, 81, 81, 83, 85, 87, 89, 93, 97,101,108], #  85
     [ 81, 82, 82, 84, 86, 88, 91, 95, 99,104,113], #  86
     [ 82, 83, 83, 85, 87, 90, 93, 97,102,109,120], #  87
     [ 83, 84, 84, 86, 88, 92, 95, 99,105,114,131], #  88



( run in 0.580 second using v1.01-cache-2.11-cpan-d8267643d1d )