4caster.net

defining prediction
  • Home
  • About
  • Contact

Integrated Development Environments

October 27, 2008

Not a specific post about weather here, but more about programming in general. If you’re like me, then writing code in something like notepad and compiling it at the command line is just too much pain. I prefer using an IDE. This will give you multiple benefits such as…

  • Ability to view and manage all your application code from a single place
  • Ability to debug and run your code and watch application flow and variables
  • A great editor with code completion, error highlighting and more

I do most of my application development in either C# or PHP. In my opinion PHP is better suited to writing web applications which blend code and html. C# is better for writing typical “Windows” applications that run on a users desktop. So here are some helpful ideas for each…

  • For C#, you can download a free express edition from the Microsoft Visual Studio site. C# is a very easy language to pickup and there are lots of developer resources around the internet such as Code Project and Code Guru to name just two (note that both of these sites have information for PHP as well). C# comes complete with it’s own very powerful IDE and debugger.
  • For PHP, you’re a bit more limited on IDE’s. I really recommend NuSphere’s PHPed. Unfortunately it’s not free but they do have a trial edition. It will give you the ability to write code, access documentation, upload to websites all from a single environment. One of the other key advantages is that you can integrate both PHP4 and PHP5 at the same time and test your application on a variety of web browsers. Like C#, there is a ton of information out there on the internet such as PHPBuilder and of course the excellent PHP homepage.

Hope this short post has helped!

Comments
No Comments »
Categories
Code
Tags
c#, coding, php
Comments rss Comments rss
Trackback Trackback

More code snippets!

October 27, 2008

If you’ve done any Googling about weather data then it should be clear that the National Weather Service provides one of the largest and most comprehensive sources of weather data.

This posting is to discuss the Current Conditions page on the NWS website and in particular the XML formatted data that is available. As I’m sure you know, one of the advantages of XML is that is strongly structures data so that there is no doubt what each element specifically is. To process XML in any language it’s always best to use inbuilt code or existing library extensions that will parse the XML data allowing you to extract just the information you require. For this example we’ll use PHP (specifically version 5) as it’s a very popular language….

So, we’ll start with working out which site we require weather data for. On the NWS page there is a link to a large zip file that covers all known weather data sites… it’s worth downloading that now.

Unfortunately you’ll just end up with approx 2800 files with obscure four character names! These are known as ICAO codes (International Civil Aviation Organization) and you’ll need to check around on the internet for a site that allows you to match a code to a particular site. For example, the Airline Industry Update site has a handy facility (as of November 2008) that allows you to match a code with a location.

So, now you should have worked out which locations you’re interested in current observations for. Let’s choose KJFK – Kennedy International Airport in New York.

Next we can see from the website that the correct xml address for each of the weather data sites looks like…

http://www.weather.gov/xml/current_obs/XXXX.xml

Of course, where XXXX is the 4 letter ICAO code! So to retrieve the current observations for JFK we’d use the following address…

http://www.weather.gov/xml/current_obs/KJFK.xml

Now if you load that into a browser you get a wealth of weather data… but not in an easily readable format. Next we need to create an XML object in our PHP application like this…

$webAddress = 'http://www.nws.noaa.gov/data/current_obs/KJFK.xml';
$xmlResults = simplexml_load_file($webAddress);

If this works, you’ll end up with a new variable called $xmlResults that you can now extract key pieces of information for. Let’s look at a couple of examples…

echo $xmlResults->weather, ' : Current Weather Summary';
echo '<br>';
echo $xmlResults->temperature_string, ' : Current Temperature Information';
echo '<br>';
echo $xmlResults->wind_string, ' : Wind Information';
echo '<br>';

Pretty great!

Comments
No Comments »
Categories
Code, Weather Data
Tags
national weather service, php, xml
Comments rss Comments rss
Trackback Trackback

pxWeather

September 24, 2008

pxWeather isn’t a full blown (there is no pun here, promise) weather data site, but just a small amount of PHP code that is easy to integrate into an existing website or application to retrieve weather data.

It’s open source and simple to integrate into an application as this snippet shows…

<?php
require_once("pxweather.class.php");
$w = new Weather($city = "Miami");
$w->load();
echo $w->getCurrent("temp.string");
? >

The downside about pxWeather is that it doesn’t seem to have been updated since 2005 so you might want to take a cached copy of the website and any documentation. However it does still work and is a good starting point if you plan on writing your own application code.

Comments
No Comments »
Categories
Code, Weather Data
Tags
php, pxweather
Comments rss Comments rss
Trackback Trackback

About

4caster.net aims to consolidate information about weather data as well as analyse and predict weather forecasts more accurately based on historical data.

Archives

  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008

Tags

bbc c# coding data geo::metar metar metcheck national weather service perl php pxweather rss rssweather site information weather weather2u Weather Data world meteorological organization world weather information service xml
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox