met office severe weather warning data structures

Sun, Dec 3, 2006

So following on from the previous post about the severe weather warnings broken, I sat down to have a good look at what they did to the site. I used to parse the raw HTML of the page detailing the severe weather warnings for the Highlands and Islands but now it seems that they’ve moved all the warning data into javascript files and the HTML pages just process this and display it. The upshot is that all the processing is now client-side, in the browser, rather than the previous server-side. So just reading the URL using PHP doesn’t work any more as you can’t invoke the client-side javascript.

So after much trawling through HTML and script links in HEAD, I found the two files that matter:

The javascript processing page that displays the warning data: http://www.metoffice.gov.uk/weather/javascript/warncontrol.js The javascript file that holds the actual warning data: http://www.metoffice.gov.uk/weather/javascript/warndata.js

To parse that lot to find out if there are any severe weather warnings for an area of the UK, it’s best to do a worked example. Let’s try and find out if there are any warnings for the Highlands and Eilean Siar area:

http://www.metoffice.gov.uk/weather/uk/he/he_forecast_warnings.html

The first thing to do is look at the source of this page and find the script variable that defines the regionnumber for Highland and Eilean Siar:

<script type=“text/javascript”>regionnumber=2</script>

as you can see, we have a regionnumber of 2 for this area. Next we must look in warncontrol.js to find out what sub regions this region contains, using the wlocations array:

wlocations[2]=[“Eilean Siar|1”,“Highland|2”]

so we have two sub regions in Highland and Eilean Siar, each with their own sub_regionnumber:

Eilean Siar = 1 Highland = 2

So now we have enough information to proceed with the severe weather warning search and to do this, we must now delve into warndata.js. What we have to do is cycle through the wcity array to satisfy the condition:

wcity[c][regionnumber] & sub_regionnnumber > 0

i.e.

for (c=0; c < wcity.length; c++) { if (wcity[c][regionnumber] & sub_regionnnumber > 0) { warningName = wname[c] warningMessage = message[c] } }

Let’s see how that applies to our two sub regions. Here’s some real data from a real warndata.js. I’ve truncated the message[0] for clarity:

wname[0] = “Severe Gales & Heavy Rain” message[0] = “The Met Office is still predicting very windy weather … “ wcity[0] = [“65534”,“0”,“2”,“3”,“4095”,“127”,“63”,“63”,“4194303”,“511”,“255”,“255”,“255”,“511”,“1023”,“32767”,“1048575”,]

Do we have any warnings for Eilean Siar? wcity[0][2] = 2

so severe weather for Eilean Siar = (1 & 2) = 0 = no warning

and severe weather for Highland = 2 & 2 = 2 = there is a warning, in this case: wname[0] = “Severe Gales & Heavy Rain” message[0] = ““The Met Office is still predicting very windy weather … “

So we can apply those rules to warndata.js based on the regionnumber for the HTML page for the main area and the sub regions for that area which are defined in warncontrol.js

Now all I have to do is code it!

comments powered by Disqus