TclMetar
TclMetar is a library of procedures for decoding Metar reports in Tcl scripts, thus making available the extensive processing capabilities of Tcl to manipulate the results.
Requirements
In addition to Tcl, Tclmetar requires Tcllib but it has no further requirements.
Downloading the software
The source ``tclmetar-version.tgz'' of the tclmetar library can be downloaded from the software area of this site The distribution comes with an INSTALL file that contains the installation instructions, a set of examples to illustrate the basic functionality, and with a README file that lists the available procedures and their usage.
In addition there are binary packages for FreeBSD, CentOS and Debian, in tbz, rpm and deb formats respectively, that can be installed with the native package management tools (e.g., pkg_add, rpm, dpkg).
Installation
Requirements
The following are required and must be installed:
Tcl
Tcllib
Installing from Packages
Binary packages exist for FreeBSD (tbz), CentOS (rpm) and Debian (deb). Since tclmetar is written entirely in Tcl and no compilation is involved, the rpm packages should work anywhere rpm is the package management tool.
The packages, available from the software section, can be installed with the native package management tools:
pkg_add tclmetar-version.tbz
rpm -i tclmetar-version.rpm
dpkg -i tclmetar-version.deb
Installation using the Makefile
This boils down to executing
./configure.sh
make install-dirs
make installinside the tclmetar distribution directory.
Manual installation
Tclmetar is written entirely in Tcl, so there is no compilation involved. The package consists of single file ``metar.tcl'' and the accompanying index file ``pkgIndex.tcl''.
Perhaps the best option is to create a directory ``tclmetar'' at the same as the tcllib directory, and put both of the above files in that directory.
The files can be saved anywhere, for example
/usr/local/lib/tcl_siteAny script that will use the package can then add the lines
lappend auto_path "/usr/local/lib/tcl_site" package require metarand it will be found.
Usage
A script will typically be of the form
#!/usr/local/bin/tclsh8.4 package require metar; <load data> foreach line $data { metar::decode $line; foreach param_name [lsort [::metar::get_param_list]] { set param_val [::metar::get_param $param_name] <do something with the value> } }
The complete set of procedures contained in the package are listed and described in the README file mentioned above, and here we mention a few, taken from the examples that are provided with the distribution and the packages.
Examples
Example 1
This script will decode the data and print the parameter name and value for every parameter that appears in the data. When the data does not contain a value for a given parameter, the value is to the empty string. The data string below has been broken in three lines for easy reading.
set data "METAR KFHU 022336Z 33011G25KT 35SM TS \ VCSH FEW040 SCT060CB BKN100 BKN250 31/14 A3003 \ RMK WSHFT 27 FRQ LTGICCG TS N MOV W SHRA N AND NE-SE=" metar::decode $line; foreach param_name [lsort [metar::get_param_list]] { set param_value [::metar::get_param $param_name]; if {$param_value ne ""} { puts "$param_name = $param_value"; } }
The output from this script is
alt = 30.03 date.dd = 02 date.hhmm = 23:36 dewp_c = 14 dewp_f = 57.2 sky = {few clouds 4000 ft} {scattered clouds cumulonumbus 6000 ft} {broken clouds 10000 ft} {broken clouds 25000 ft} station = kfhu temp_c = 31 temp_f = 87.8 type = Routine Weather Report visibility = 35 weather = moderate showers rain wind.dir = 330 wind.gust_kt = 25 wind.gust_mph = 28.77 wind.speed_kt = 11 wind.speed_mph = 12.6588
Example 2
As the ``sky'' line above shows, the value of the ``sky'' parameter is actually a tcl list. So, for example, if the ``puts'' statement above is substituted by the following
if {$param_value ne ""} { if {$param_name eq "sky"} { puts "$param_name = [join $param_value {, }]"; } else { puts "$param_name = $param_value"; } }that line would be
sky = few clouds 4000 ft, scattered clouds cumulonumbus 6000 ft, broken clouds 10000 ft, broken clouds 25000 ft