So you want to decode METAR data?

Here's how I did it:

0. Download the data from NOAA's site.  download_observation() in
   tclweather.tcl handles this.  Note how the URL requires a 4 character
   location code.  One may download the original location database (as
   seen in file utils/Locations).  I found the format inconvenient to
   parse, so I wrote a helper program, location_scanner.f, to rewrite
   the database into a nicer format -- see locations.cache.

1. Now that I have the observation as straight text, send it to
   utils/tclweather_scanner.f.  This file is written as a fickle
   specification file.  See http://mini.net/tcl/fickle for information
   on this program.

2. The original METAR observation is passed to parse_weather() in
   utils/tclweather_scanner.f.  It does a bunch of <insert magic here>
   and writes it to the array pointed to by 'target_loc'.  The data is
   internally represented in metric form.  *** HERE IS WHERE THE REAL
   WORK IS DONE. *** It is necessary to know how fickle operates to
   understand these routines.

3. TclWeather stores the new data into the global array 'latest_data'.
   If you bring up the console for TclWeather (e.g., in Windows, hit
   <F2>) type in 'parray latest_data' to see the array.  Here's an
   example output:

      (tclweather) 1 % parray latest_data
      latest_data(cloud,alt)   = 7620.0
      latest_data(cloud,amt)   = 40
      latest_data(cloud,type)  = Partly cloudy
      latest_data(cond)        = Mist
      latest_data(pres)        = 764.032
      latest_data(temp,air)    = 20
      latest_data(temp,dew)    = 20
      latest_data(temp,relhum) = 100.0
      latest_data(time,hour)   = 09
      latest_data(time,min)    = 54
      latest_data(vis)         = 9.656064
      latest_data(wind,dir)    = 0
      latest_data(wind,gust)   = 0
      latest_data(wind,speed)  = 0.0

4. This array is then scanned through.  TclWeather converts to imperial
   units as necessary.  It adds the relevant color tags, +/- indicators,
   and then sends the data to the ticker.

Easy as 3.14159.

Jason Tang / tang@jtang.org
