#! perl #extproc perl.exe -S #!/usr/bin/perl # use Time::Local; # $data_path = "d\:\\data\\lsc\\"; #print $data_path."\n"; Get_date(); Run_yesterday(); Run_current(); Format_numbers(); Print_html(); #Print_test(); # # *** END OF MAIN *** # # # #============================================================================================== sub Get_date { ($seconds, $minute, $hour, $day_month, $month, $year, $weekday, $julianday, $unknown)=localtime; $julianday = sprintf("%03d", ($julianday + 1)); $year = 1900 + $year; $month = $month + 1; $hour=sprintf("%02d", $hour); $minute=sprintf("%02d", $minute); $time_str=join(":", $hour, $minute); } # # #============================================================================================== sub Format_time { my $hr = 0; my $min = 0; if ($_[0] < 10) { $hr = "00"; $min = "0".$_[0]; }elsif ($_[0] < 100) { $hr = 0; $min = $_[0]; }elsif ($_[0] < 1000) { $hr = "0".substr($_[0],0,1); $min= substr($_[0],1,2); }else { $hr = substr($_[0],0,2); $min = substr($_[0],2,2); } return (join(":",$hr,$min)) } # # #============================================================================================== sub Strip_digits { # This should be a simple sprintf statement too!!!! # parameters: first is the number to be adjusted, second is the number of decimal places to trim/pad my $intval = 0; my $digval = 0; if($_[0] =~ /\./) { ($intval, $digval)=split(/\./, $_[0]); if ((length($digval)) > $_[1]) { $digval = substr($digval, 0, $_[1]); }elsif(length($digval) < $_[1]) { while(length($digval) < $_[1]){ $digval=$digval."0"; } } if($intval == 0) { $intval = "0"; } if($_[1] == 0) { return $intval; }else{ return $intval.".".$digval; } }else{ return $_[0]; } } # # #================================================================================================ sub Fix_jdate { # This could probably be replaced with a sprintf() if ($_[0] < 10) { $_[0] = "00".$_[0]; }elsif($_[0] < 100) { $_[0] = "0".$_[0]; } return $_[0]; } # # #============================================================================================== sub Run_yesterday { #This is unnecessary, Create a file at midnight to generate these stats once for each day #initilize variables $y_temp_hi = -80; $y_temp_hi_time = 0; $y_temp_low = 200; $y_temp_low_time = 0; $y_gust = -1; $y_gust_time = 0; $y_precip = 0; $y_temp_sum = 0; $y_temp_ave = 0; $y_wind_sum = 0; $y_wind_ave = 0; $counter = 0; # $yester_jday=sprintf("%03d", ($julianday - 1)); $yesterday_file = $data_path.$year."\\".$year.".".$yester_jday.".data"; open(YSTD, "<$yesterday_file") || die "cannot open file $yesterday_file : $!\n"; while($line2 = ) { chomp($line2); ($datacode, $data_year, $data_jdate, $data_hr, $data_min, $precip, $t_low, $t_hi, $rh_low, $rh_hi, $vpa1, $vpa2, $gust, $wind_sample, $wind_ave, $wind_vect, $wind_stdev, $ten_temp_low, $ten_temp_high, $press_low, $press_hi) = split(/:/, $line2); #check & average temp if($t_low < $y_temp_low) { $y_temp_low = $t_low; $y_temp_low_time = join(":", $data_hr, $data_min); } if($t_hi > $y_temp_hi) { $y_temp_hi = $t_hi; $y_temp_hi_time = join(":", $data_hr, $data_min); } $y_temp_sum = $y_temp_sum + $t_hi + $t_low; # end of temp processing # proc wind if($gust > $y_gust) { $y_gust = $gust; $y_gust_time = join(":", $data_hr, $data_min); } $y_wind_sum = $y_wind_sum + $wind_ave; #end wind begin precip $y_precip = $y_precip + $precip; $counter++; } close(YSTD) || die "cannot close file: $!\n"; $y_temp_ave = $y_temp_sum / ($counter * 2); $y_wind_ave = $y_wind_sum / $counter; $y_precip=sprintf("%2.2f", $y_precip); } # # #============================================================================================== sub Run_current { $today_temp_hi = -80; $today_temp_hi_time = 0; $today_temp_low = 200; $today_temp_low_time = 0; $today_gust = -10; $today_gust_time = 0; $today_precip = 0; $today_temp_sum = 0; $today_temp_ave = 0; $today_wind_sum = 0; $today_wind_ave = 0; $counter = 0; open(ZZ, "){ chomp($line); #$counter++ if ($line =~ /^111/) { #$output = $line; #Split_line(); #($code, $data_year, $data_jdate, $data_time, $precip, $t_low, $t_hi, $rh_low, $rh_hi, $vpa1, $vpa2, # $gust, $wind_ave, $wind_ave2, $wind_dir, $press_low, $press_hi) = split(/,/, $line); ($code, $data_year, $data_jdate, $data_time, $precip, $t_low, $t_hi, $rh_low, $rh_hi, $vpa1, $vpa2, $gust, $wind_samp, $wind_ave, $wind_vect, $wind_stderr, $ten_temp_low, $ten_temp_hi) = split(/,/, $line); if($data_jdate == $julianday) { if($t_low < $today_temp_low) { $today_temp_low = $t_low; $today_temp_low_time = $data_time; } if($t_hi > $today_temp_hi) { $today_temp_hi = $t_hi; $today_temp_hi_time = $data_time; } $today_temp_sum = $today_temp_sum + $t_hi + $t_low; # end of temp processing # process 10m Temp if($ten_temp_low < $today_ten_low) { $today_ten_low = $ten_temp_low; $today_ten_low_time = $data_time; } if($ten_temp_hi > $today_ten_hi) { $today_ten_hi = $ten_temp_hi; $today_ten_hi_time = $data_time; } $today_ten_sum = $today_ten_sum + $ten_temp_hi + $ten_temp_low; # proc wind if($gust > $today_gust) { $today_gust = $gust; $today_gust_time = $data_time; } $today_wind_sum = $today_wind_sum + $wind_ave; #end wind begin precip $today_precip = $today_precip + $precip; $counter++; } }elsif($line =~ /^222/) { ($code, $data_year, $data_jdate, $data_time, $press_low, $press_hi) = split(/,/, $line); } } close(ZZ) || die "cannot close file: $!\n"; #Split_line(); $today_precip=sprintf("%2.2f", $today_precip); $today_wind_ave = $today_wind_sum/$counter; $today_temp_ave = $today_temp_sum/($counter * 2); $today_ten_ave = $today_ten_sum/($counter * 2); $dewpt_f = get_dewpt($t_hi, $rh_hi, "F", "F"); $dewpt_c = sprintf("%3.1f", ($dewpt_f - 32)/1.8); $t_hi_c = sprintf("%3.1f", ($t_hi -32)/1.8); $ten_temp_hi_c = sprintf("%3.1f", ($ten_temp_hi -32)/1.8); } # # #============================================================================================== sub Split_line { ($code, $data_year, $data_jdate, $data_time, $precip, $t_low, $t_hi, $rh_low, $rh_hi, $vpa1, $vpa2, $gust, $wind_samp, $wind_ave2, $wind_dir, $wind_vect, $wind_stderr, $ten_temp_low, $ten_temp_hi) = split(/,/, $_[0]); #print $output."\n"; } # # #================================================================================================ sub Uptime_str { my @uptime = 0; @uptime = split(/\s+/, `uptime`); return ($uptime[3].' days, '.$uptime[5].' hours'); } # # #============================================================================================== sub Format_numbers { # trim & format data for printing. $data_jdate=sprintf("%03d", $data_jdate); # $data_time=Format_time($data_time); $today_temp_hi_time=Format_time($today_temp_hi_time); $today_temp_low_time=Format_time($today_temp_low_time); $today_gust_time=Format_time($today_gust_time); # $t_hi=Strip_digits($t_hi, 1); $t_hi_c=Conv_f2c($t_hi); $rh_hi=Strip_digits($rh_hi, 1); $wind_ave=Strip_digits($wind_ave, 1); $wind_ave_knots=sprintf("%3.1f", ($wind_ave * .8696)); $gust=Strip_digits($gust, 1); $gust_knots=sprintf("%3.1f", ($gust * .8696)); # $today_temp_hi=Strip_digits($today_temp_hi, 1); $today_temp_hi_c=Conv_f2c($today_temp_hi); $today_temp_low=Strip_digits($today_temp_low, 1); $today_temp_low_c=Conv_f2c($today_temp_low); $today_temp_ave=Strip_digits($today_temp_ave, 1); $today_temp_ave_c=Conv_f2c($today_temp_ave); $today_gust=Strip_digits($today_gust, 0); $today_gust_knots=sprintf("%3.1f", ($today_gust * .8696)); $today_wind_ave=Strip_digits($today_wind_ave, 1); $today_wind_ave_knots=sprintf("%3.1f", ($today_wind_ave * .8696)); # $y_temp_hi=Strip_digits($y_temp_hi, 1); $y_temp_hi_c=Conv_f2c($y_temp_hi); $y_temp_low=Strip_digits($y_temp_low, 1); $y_temp_low_c=Conv_f2c($y_temp_low); $y_temp_ave=Strip_digits($y_temp_ave, 1); $y_temp_ave_c=Conv_f2c($y_temp_ave); $y_gust=Strip_digits($y_gust, 0); $y_gust_knots=sprintf("%3.1f", ($y_gust * .8696)); $y_wind_ave=Strip_digits($y_wind_ave, 1); $y_wind_ave_knots=sprintf("%3.1f", ($y_wind_ave * .8696)); if($ten_temp_hi < -500) { $ten_temp_hi = "Temporarily\Unavailable"; $ten_temp_hi_c = "n/a"; } $ten_temp_hi = sprintf("%02.1f", $ten_temp_hi); #$wind_vect = 2 * $wind_vect; get_wind_dir(); $wind_vect = sprintf("%03.0f", $wind_vect); # convert mb to Hg. $press_hi_hg =sprintf("%2.2f", ($press_hi/33.85185)); } # # #================================================================================================ sub Print_html { $uptime=Uptime_str(); $yesterday=join("/", $month, ($day_month - 1), $year); if($ten_temp_hi > $t_hi) { $ten_temp_hi = ''.$ten_temp_hi.''; $ten_temp_hi_c = ''.$ten_temp_hi_c.''; } print < Current Conditions at LSC
Current Observations
$month/$day_month/$year $time_str
Data recorded from the past 5 minutes


Data Date (Year, Julian Day) $data_year, $data_jdate
Data Time (EST5EDT) $data_time
Temperature (2 meter/6.5 ft.) $t_hi F
$t_hi_c C
Temperature (10 meter/32.5 ft.) $ten_temp_hi F
$ten_temp_hi_c C
Dew Point $dewpt_f F
$dewpt_c C
Relative Humidity $rh_hi %
Precipitation $precip inches
Average Wind Speed $wind_ave mph
$wind_ave_knots knots
Wind Gust $gust mph
$gust_knots knots
Wind Direction $compass
$wind_vect Deg.
Barometric Pressure $press_hi mb
$press_hi_hg inches Hg
$press_trend



Today's Weather as of $data_time
$month/$day_month/$year
Measured in 5 Minute Intervals


High Temperature $today_temp_hi F
$today_temp_hi_c C
Measured at $today_temp_hi_time
Low Temperature $today_temp_low F
$today_temp_low_c C
Measured at $today_temp_low_time
Average Temperature $today_temp_ave F
$today_temp_ave_c C
Total Precipitation $today_precip inches
Highest Wind $today_gust mph
$today_gust_knots knots
Measured at $today_gust_time
Average Wind $today_wind_ave mph
$today_wind_ave_knots knots



Yesterday's Weather
$yesterday
Measured in 5 Minute Intervals

High Temperature $y_temp_hi F
$y_temp_hi_c C
Measured at $y_temp_hi_time
Low Temperature $y_temp_low F
$y_temp_low_c C
Measured at $y_temp_low_time
Average Temperature $y_temp_ave F
$y_temp_ave_c C
Total Precipitation $y_precip inches
Highest Wind $y_gust mph
$y_gust_knots knots
Measured at $y_gust_time
Average Wind $y_wind_ave mph
$y_wind_ave_knots knots


Now, you may search our archived data for LSC, Sutton, West Burke, and Granby by clicking HERE.

Questions, comments or suggestions about this page should be directed to the webmaster.

This machine's uptime is: $uptime EOP } # # #================================================================================================ sub Print_test { # this is a text test of output variables before beating the HTML into obedience. print <Current Conditions at LSC

    Current conditions
    
    Data date:   $data_year $data_jdate
    Data time:   $data_time
    Temperature: $t_hi
    Precip:      $precip
    Wind:        $wind_ave
    Gust:        $gust
    Pressure:    $press_hi

    Today's stats

    Hi temp     \t\t$thi at $thi_time
    Low temp    \t\t$tlow at $tlow_time
    Average Temp\t\t$tave
    hi wind     \t\t$t_gust at $t_gust_time
    precip today\t\t$t_precip
    avg. wind   \t\t$windave
    
    Yesterday's stats
    
    High temperature \t\t$y_thi at $y_thi_time
    Low temperature  \t\t$y_tlow at $y_tlow_time 
    Average temp     \t\t$y_tave
    High windw       \t\t$y_gust at $y_gust_time 
    average winds    \t\t$y_windave
    Total precip     \t\t$y_precip
    
EOP # EOP must start in column 1 !! } # ============================================================================================= # # sub get_wind_dir { %compdir = qw ( 348.75 N 326.25 NNW 303.75 NW 281.25 WNW 258.75 W 236.25 WSW 213.75 SW 191.25 SSW 168.75 S 146.25 SSE 123.75 SE 101.25 ESE 78.75 E 56.25 ENE 33.75 NE 11.25 NNE 0 N ); foreach $key (sort {$b <=> $a} keys %compdir) { #print "$key $compdir{$key} \n"; if($wind_vect > $key) { $compass = $compdir{$key}; #print "set at $compass\n"; last; } } } # ============================================================================================= # # sub get_dewpt { # passing TEMP, RH, input_UNITS (C,F), output_units (C,F) my $temp; my $dpt; if ($_[2] eq "F") { $temp = (($_[0] - 32)/1.8) + 273.15; }elsif($_[2] eq "C") { $temp = $_[0] + 273.15; }else{ print "You need to tell me what units we're using\n"; return ("Junk value"); } $dpt = ((1/$temp) - (1/5412 * log($_[1]/100) ))**-1; if ($_[3] eq "F") { $dpt = (($dpt - 273.15) * 1.8) + 32; return(sprintf("%3.1f", $dpt)); }elsif($_[3] eq "C") { $dpt = $dpt - 273.15; return(sprintf("%3.1f", $dpt)); } } # ============================================================================================= # # sub Conv_f2c { return(sprintf("%3.1f", (($_[0] -32)/1.8))); }