<?
include("./functions.php");
$db db_connect();

if ( empty(
$station_id) )
    
$station_id="wiscoy";


$q1 mysql_query("SELECT * FROM weather WHERE station_id='$station_id' ORDER BY time_recieved DESC LIMIT 1",$db);
$cur_wx = @mysql_fetch_array($q1);
$title_message "Current Weather at " ucwords($cur_wx[station_id]);
require(
"wxsrv.head.php");
?>

<TABLE BORDER=0 CELLPADDING=1 CELLSPACING=0 ALIGN=CENTER>
<TR BGCOLOR=d0d0d0><TD>
<TABLE BGCOLOR=WHITE BORDER=0 CELLSPACING=1 CELLPADDING=1>
<TR BGCOLOR=d0d0d0>
    <TD COLSPAN=3 ALIGN='center'>
        <B><A HREF = "raw.php?station_id=<?echo $station_id?>"><FONT COLOR="#006633"><? echo ucwords($cur_wx[station_id]); ?></FONT></A></B>
    </TD>
</TR>

<TR>
    <TD ALIGN="right">Outside Temperature&nbsp;</TD>
<? 
printf
("\t<TD ALIGN=\"right\">%s</TD>\n"pad(temperature(2,$cur_wx[temp_outside]),1,1));
printf("\t<TD ALIGN=\"right\">%s</TD>\n"pad(temperature(1,$cur_wx[temp_outside]),1,1));    
?>
</TR>

<TR>
    <TD ALIGN="right">Inside Temperature&nbsp;</TD>
<? 
printf
("\t<TD ALIGN=\"right\">%s</TD>\n"pad(temperature(2,$cur_wx[temp_inside]),1,1));
printf("\t<TD ALIGN=\"right\">%s</TD>\n"pad(temperature(1,$cur_wx[temp_inside]),1,1));
?>
</TR>

<TR>
    <TD ALIGN="right">&nbsp;Atmospheric Pressure&nbsp;</TD>
<? 
printf
("\t<TD ALIGN=\"right\">%s\" mercury&nbsp;</TD>\n"pad(sprintf("%2.3f",$cur_wx[pressure]*0.02953),1,0));
printf("\t<TD ALIGN=\"right\">%s millibars</TD>\n"pad($cur_wx[pressure],1,1));
?>
</TR>

<TR>
    <TD ALIGN="right">Battery Voltage&nbsp;</TD>
<?
printf
("\t<TD COLSPAN=2 ALIGN='center'>%s</TD>\n"pad($cur_wx[batt_volts] . " volts " batt_percent($cur_wx[batt_volts]) . " Charge",1,1));
?>
</TR>

<TR>
    <TD ALIGN="right">Wind Direction&nbsp;</TD>
<?
printf
("\t<TD COLSPAN=2 ALIGN='center'>%s</TD>\n"pad($cur_wx[wind_dir] . "° " degrees_cardinal($cur_wx[wind_dir]),1,1));
?>
</TR>

<TR>
    <TD ALIGN="right">Wind Gust&nbsp;</TD>
<? 
printf
("\t<TD ALIGN='right'>%s</TD>\n"pad(speed_convert(1,$cur_wx[wind_gust]),1,1));
printf("\t<TD ALIGN='right'>%s</TD>\n"pad(speed_convert(2,$cur_wx[wind_gust]),1,1));
?>
</TR>

<TR>
    <TD ALIGN="right">Wind Speed&nbsp;</TD>
<? 
printf
("\t<TD ALIGN=\"right\">%s</TD>\n"pad(speed_convert(1,$cur_wx[wind_speed]),1,1));
printf("\t<TD ALIGN=\"right\">%s</TD>\n"pad(speed_convert(2,$cur_wx[wind_speed]),1,1));
?>
</TR>

<!--
<TR>
    <TD ALIGN="right">Wind Chill&nbsp;</TD>
<?
$wind_speed_mph 
speed_convert(1,$cur_wx[wind_speed]);
$wind_chill_f 91.4 - (0.474677 0.020425 $wind_speed_mph 0.303107 sqrt($wind_speed_mph) ) * (91.4 temperature(2,$cur_wx[temp_outside]));

printf("\t<TD COLSPAN=2 ALIGN=\"right\">%s</TD>\n",pad(round($wind_chill_f),1,1));
?>
</TR>
-->

<TR>
    <TD ALIGN="right">Rain Fall (24 Hour)&nbsp;</TD>
<? 
printf
("\t<TD ALIGN=\"right\">%s</TD>\n"pad(rain_in_24($station_id,1,$cur_wx[rain],1),1,1));
printf("\t<TD ALIGN=\"right\">%s</TD>\n"pad(rain_in_24($station_id,2,$cur_wx[rain],1),1,1));

?>
</TR>

<TR>
    <TD ALIGN="right">Rain Fall (1 Hour)&nbsp;</TD>
<? 
printf
("\t<TD ALIGN=\"right\">%s</TD>\n"pad(rain_in_1($station_id,1,$cur_wx[rain],1),1,1));
printf("\t<TD ALIGN=\"right\">%s</TD>\n"pad(rain_in_1($station_id,2,$cur_wx[rain],1),1,1));

?>
</TR>

<TR>
    <TD ALIGN="right">Relative Humidity&nbsp;</TD>
<?
    printf
("\t<TD COLSPAN=2 ALIGN=\"right\">%s</TD>\n"pad(sprintf("%2d%%",$cur_wx[humidity_2]),1,1));
?>
</TR>

<TR>
<TD ALIGN="right">Time of Measurement&nbsp;</TD>
<?
printf
("\t<TD COLSPAN=2 ALIGN=\"right\">%s</TD>\n"pad(datetime_to_string($cur_wx[time_recieved]),1,1));
?>
</TR>
<TR>
<TD ALIGN="right">Current Local Time&nbsp;</TD>
<?
printf
("\t<TD COLSPAN=2 ALIGN=\"right\">%s</TD>\n"pad(date("g:i A, M j Y"),1,1));
?>
</TR>
</TABLE>
</TD></TR>
</TABLE>
<P>
View plots of the following parameters:
<?
function get_gnuplot_link($column,$date="today") {
    global 
$station_id;


    if ( 
$date == "yesterday" ) {
        
$time time();
    } else {
        
$time time() + 86400;
    }

    
$year date("Y",$time);
    
$month date("m",$time);
    
$day date("d",$time);


    
$link sprintf("gnuplot.php?station_id=%s&amp;column=%s&amp;date=%04d-%02d-%02d",$station_id,$column,$year,$month,$day);

    switch ( 
$column ) {
        case 
"temp_outside":    
            
$col="Outside Temperature";
            break;
        case 
"temp_inside";
            
$col="Temperature Inside Enclosure";
            break;
        case 
"batt_volts";
            
$col="Battery Voltage";
            break;
        case 
"wind_speed";
            
$col="Wind Speed";
            break;
        default:
            return(
"Bad column!");
    }

    
printf("<A HREF=\"%s\">%s (%s)</A>&nbsp;&nbsp;",$link,$col,$date);

}

get_gnuplot_link("temp_outside");
get_gnuplot_link("temp_outside","yesterday");
get_gnuplot_link("temp_inside");
get_gnuplot_link("temp_inside","yesterday");
get_gnuplot_link("wind_speed");
get_gnuplot_link("wind_speed","yesterday");
get_gnuplot_link("batt_volts");
get_gnuplot_link("batt_volts","yesterday");

?>
<P>
<? require("news"); ?>
<? 
require("wxsrv.foot.php"); ?>