Log.xml

Revision as of 17:35, 31 May 2020 by Sfws (talk | contribs)

File holding entries created in 'Weather Diary' assessed from Cumulus 1 View menu.

Editing this log =

The file can be edited within Cumulus 1 (Weather Diary on Edit menu), and can be viewed (but not edited) using a XML viewer.

Using in your own scripts

There is a web page using this code written by Czech author Miloš Jirík (https://pocasi.ok5aw.cz) available on the support forum at https://cumulus.hosiene.co.uk/viewtopic.php?p=83888#p83888 and that will display all the snow records on a web page.


Taking that script as a starting point, the following code snippet is a piece of PHP code that can read this file and put what it reads (for onr particular day) into PHP variables. Since this diary can hold several entries for the same day, a decision has to be made as to which to report. For snow falling, lying, and depth, this code saves the "worst case" of all the entries for that day. For the "entry" field, the one with latest time is retained.

//====================================================
//   This snippet is used for Cumulus 1 with XML based diary
// =======================================================
$fh = fopen($snowDiary, 'r');  // $snowDiary has to contain full path based on root or relative to where your script is 
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);	// 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: