".substr($row[0],0,4)."
";
$year = substr($row[0],0,4);
if (!file_exists('./'.$year)) {
mkdir('./'.$year, 0775, true);
}
}
if (ltrim(substr($row[0],5,2),0) != $month) {
echo "
".ltrim(substr($row[0],5,2),0)."
";
if ($month != 0) fclose($fh);
$month = ltrim(substr($row[0],5,2),0);
$myFile = "./".$year."/".$month."_WeatherCatData.cat";
$fh = fopen($myFile, 'w') or die("can't open file");
$top = "WeatherCat data file ***If you modify this file, be sure to delete the relevent .hrs file***.\nt and V are not optional, all other fields are. t is the day, hour and minute (2 digits each), T is outside temperature, Ti is internal temperature, T1 to T8 is auxiliary temperatures, D is dew point, Pr is barometric pressure, W is wind speed,\n Wd is wind direction, Wc is wind chill, Wg is wind gust, Ph is hourly precipitation, P is total precipitation,H is outside humidity, Hi is internal humidity, H1 to H8 are auxiliary humidity sensors, S is solar, \nSm1 to Sm4 is soil moisture, Lw1 to Lw4 is leaf wetness, St1 to St4 is soil temperature, \nLt1 to Lt4 is leaf temperature, U is UV, Pm is monthly precipitation, Py is annual precipitation, Ed is daily ET, Em is monthly ET, Ey is yearly ET, C is current conditions (delimited by double quotes), V is validation. \n\nVERS:3\n\n";
fwrite($fh, $top);
}
$rc = ($day-1)*1440+$hour*60+$min;
$time = sprintf("%02s",$day).sprintf("%02s",$hour).sprintf("%02s",$min);
// $T = sprintf("%01.2f",($row["OutdoorTemperature"]-32)*5/9); // use this line if temp in F
$T = sprintf("%01.2f", $row[1]); // use this line if temp in C
// $D = sprintf("%01.2f",($row["DewPoint"]-32)*5/9); // use this line if temp in F
$D = sprintf("%01.2f", $row[2]); // use this line if temp in C
if ($row[3] == 0) $Pr = 0; else $Pr = sprintf("%01.4f",($row[3]/100)); //convert pascal to milibar
// if ($row[6] == 0) $W = 0; else $W = sprintf("%01.2f",$row[6]*1.60934)); // use this line if speed is MPH
if ($row[6] == 0) $W = 0; else $W = sprintf("%01.2f",$row[6]); // use this line if speed is KPH
$Wd = $row[5];
// $Wc = round((35.74 + 0.6215 * $T - 35.75 * pow($W,0.16) + 0.4275 * $T * pow($W,0.16)), 2); // calc wind chil F
$Wc = round((13.12 + 0.6215 * $T - 11.37 * pow($W,0.16) + 0.3965 * $T * pow($W,0.16)), 2); // calc wind chil C
// if ($row[7] == 0) $Wg = 0; else $Wg = sprintf("%01.2f",($row[7]*1.60934)); // use this if MPH
if ($row[7] == 0) $Wg = 0; else $Wg = sprintf("%01.2f",$row[7]); // use this if KPH
// if ($row[9] == 0) $P = 0; else $Ph = sprintf("%01.2f",($row[9]*25.4)); //use this if rain is in
if ($row[9] == 0) $P = 0; else $Ph = sprintf("%01.2f",$row[9]); //use this if rain is mm
// if ($row[12] == 0) $P = 0; else $P = sprintf("%01.2f",($row[12]*25.4)); //use this if rain is in
if ($row[12] == 0) $P = 0; else $P = sprintf("%01.2f",$row[12]); //use this if rain is mm
$H = $row[8];
$C = $row[10];
// The line below is every item my .cat files have populated by WC. The file says they are optional, but I have problems reading them if they are not all there. If your files to not read, you may have to make the $rec line match what WC wants.
// $rec = $rc." t:".$time." T:".$T." Ti:".$Ti." D:".$D." Pr:".$Pr." W:".$W." Wd:".$Wd." Wc:".$Wc." Wg:".$Wg." Ph:".$Ph." P:".$P." H:".$H." Hi:".$Hi." S:0 U:0.0 Lw4:0.0 Pm:".$Pm." Py:".$Py." Ed:0.00 Em:0.00 Ey:0.00 C:\"".$C."\" V:4\n";
$rec = $rc." t:".$time." T:".$T." D:".$D." Pr:".$Pr." W:".$W." Wd:".$Wd." Wc:".$Wc." Wg:".$Wg." P:".$P." H:".$H." C:\"".$C."\" V:4\n";
fwrite($fh, $rec);
echo $rec."
";
}
fclose($fh);
fclose($file);
?>