Weather Diary: Difference between revisions

From Cumulus Wiki
Jump to navigationJump to search
m
==How to view the contents on a web page==
 
The php script included in [[File:Cumulus 1 Weather Diary PHP reader.zip]] will read the Cumulus 1 weather diary and output it to a web page. Although that script is not in English, it is possible to translate the text, and it is possible to modify the script in various ways. For example, in one modification I made it combine the multiple entries possible for one day into a single "worst case" output and in another modification I supply it with a date and it only outputs records for that date. as shown below:
<pre>$fh = fopen($snowDiary, 'r');
if ($fh == FALSE)
{
echo 'ERROR - cannot access weather diary';
}else{
if($debug) echo 'Success, database ' . $snowDiary . ' is open' . PHP_EOL;
$data = fread($fh, filesize($snowDiary));
fclose($fh);
$converted = iconv("Windows-1250", "UTF-8//IGNORE", $data);
$xml = simplexml_load_string($converted);
$dayArray = array();
$oldKey = '';
foreach ($xml->xpath('//ROW') as $item)
{
$key = substr($item['EntryDate'],0,4) . '-' . substr($item['EntryDate'],4,2) . '-' . substr($item['EntryDate'],6,2);
if($key > $rowMetDayStamp) break;
$falling = $item['SnowFalling'] == 'TRUE' ? 1 : 0;
$lying = $item['SnowLying'] == 'TRUE' ? 1 : 0;
$depth = $item['SnowDepth'];
if($key == $oldKey) // update to another record for same day, retain worse boolean for falling and lying
{
$falling = $oldFalling == 1 ? 1 : $falling;
$lying = $oldLying == 1 ? 1 : $lying;
$depth = ($depth - $oldDepth) > 0 ? $depth : $oldDepth;
}
$Entry = $item['Entry'];
// novel to SPAWS
$oldFalling = $falling;
$oldLying = $lying;
$oldDepth = $depth;
$oldKey = $key;
} // end of loop through XML records
if($key == $rowMetDayStamp)
{
$snowKnown = true;
if ($debug)
{
echo ' ----- Found entry in weather diary for ' . $englishProcessingDate . $lf;
}
goto snowDone;
}
if($debug) echo ' ----- NO entry in Cumulus 1 weather diary for ' . $englishProcessingDate . $lf . '============================' . $lf;
$snowKnown = false;
$Entry = Null; // Other variables were previously set to values appropriate for the lowest temperature
goto snowDone;
}// end snow diary file processing</pre>
 
==How to edit the contents==
5,838

edits

Navigation menu