5,838
edits
mNo edit summary |
mNo edit summary |
||
Line 16: | Line 16: | ||
echo 'ERROR - cannot access weather diary'; | echo 'ERROR - cannot access weather diary'; | ||
}else{ | }else{ | ||
if($debug) echo 'Success, database ' . $snowDiary . ' is open' . PHP_EOL; | |||
$data = fread($fh, filesize($snowDiary)); | |||
fclose($fh); // close diary, now contents in $data | |||
$converted = iconv("Windows-1250", "UTF-8//IGNORE", $data); // Convert from windows format that Cumulus uses to UTF-8 to match what most scripts now use | |||
$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']; | |||
$oldFalling = $falling; | |||
$oldLying = $lying; | |||
$oldDepth = $depth; | |||
$oldKey = $key; | |||
} // end of loop through XML records | |||
if($key == $rowMetDayStamp) | |||
{ | |||
$snowKnown = true; | |||
goto snowDone; | |||
} | |||
$snowKnown = false; | |||
$Entry = Null; // Other variables were previously set to values appropriate for the lowest temperature | |||
goto snowDone; | |||
} | } | ||
snowDone:</pre> | snowDone:</pre> |
edits