Log.xml

From Cumulus Wiki

Introduction

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

Content of file

The structure Steve Loft created (and I think he regretted this later) is a bit more complicated than that shown below. Each <ROWDATA/> actually has another field not shown that is set by a somewhat complicated algorithm that I eventually worked out but will not fully describe here. Putting it as simply as I can, there is an extra code field, so that when an extra record is created for the same date, the code records how many times each individual field has been changed (since it is tracking several fields, each of these has a different multiplier, so just a single number represents everything). Since any external XML editor does not understand this extra field, it cannot edit it, and without that field being correct the weather diary feature in Cumulus 1 cannot read it, and consequently will either not start or will crash out (depending on whether it is stopped or running at time of external edit).

Here is the incomplete structure as detected by "XML Notepad 2007":

<DATAPACKET Version="2.0">
<METADATA>
<FIELDS>
 <FIELD attrname="EntryDate" fieldtype="date"/>
 <FIELD attrname="Entry" fieldtype="string" WIDTH="1024"/>
 <FIELD attrname="SnowLying" fieldtype="boolean"/>
 <FIELD attrname="SnowFalling" fieldtype="boolean"/>
 <FIELD attrname="SnowDepth" fieldtype="i4"/>
 </FIELDS>
 <PARAMS/>
 </METADATA>
 <ROWDATA/>
 </DATAPACKET>

Editing this log =

The file can be edited within Cumulus 1 (Weather Diary on Edit menu), and can be viewed (but not edited for reason explained earlier) using any XML viewer. However, most viewers (including your browser will struggle without a template telling them the complete format (not just what is shown above).

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: