metaf.pl - download and display METAR/TAF/SYNOP/BUOY/AMDAR messages
metaf.pl can be run from the command line like this:
metaf.pl 'type_metaf=...&type_synop=...&type_buoy=...&type_amdar=...&lang=...&unit_temp=...&format=...&src_metaf=...&src_synop=...&src_buoy=...&src_amdar=...&mode=...&hours=...&msg_metaf=...&msg_synop=...&msg_buoy=...&msg_amdar=...'
or like this:
metaf.pl type_metaf=... type_synop=... type_buoy=... type_amdar=... lang=... unit_temp=... format=... src_metaf=... src_synop=... src_buoy=... src_amdar=... mode=... hours=... msg_metaf='...' msg_synop='...' msg_buoy='...' msg_amdar='...'
It can also be used as a CGI script via an HTML form like this:
<form method=GET action=metaf.pl>
<input name=type_metaf value=... >
<input name=type_synop value=... >
<input name=type_buoy value=... >
<input name=type_amdar value=... >
<input name=lang value=... >
<input name=unit_temp value=... >
<input name=format value=... >
<input name=src_metaf value=... >
<input name=src_synop value=... >
<input name=src_buoy value=... >
<input name=src_amdar value=... >
<input name=mode value=... >
<input name=hours value=... >
<input name=msg_metaf value="..." >
<input name=msg_synop value="..." >
<input name=msg_buoy value="..." >
<input name=msg_amdar value="..." >
</form>
This script can download and display in plain language up-to-date or historical weather information (METAR, TAF, SYNOP, BUOY or AMDAR messages) from Internet servers, an SQL database, or a local file. It can be used from the command line, or executed as a CGI script by a web server with HTTP GET requests via an HTML form.
If the script is executed by a web server and the file $CGI_LOG_FILE is writable by the user running the web server (e.g. "wwwrun"), metaf.pl will log the requests there.
The Perl modules CGI
, metaf2xml::parser
and metaf2xml::src2raw
are required.
The Perl module DBI
and the module DBD
(for the configured type of data source) are required if an SQL database is used as the data source.
The program curl
is required to download weather messages from Internet servers.
The program xsltproc
is required if the script is to convert the XML to HMTL or text.
National Oceanic and Atmospheric Administration
the National Weather Service department of the NOAA
the Internet Weather Source of the NWS
the Text Data Server API service of the Aviation Weather Center of the NOAA
College of DuPage
print version of metaf.pl and exit
The following variables can be set from CGI parameters or on the command line:
type of content in msg_metaf
:
METAR/SPECI/SAO message (default)
TAF message
ICAO id(s)
If msg_metaf
starts with METAR
, SPECI
or TAF
, type_metaf
is set to metar or taf, respectively.
If msg_metaf
is not a list of ICAO id(s), type_metaf
is set to metar.
If type_metaf
is icao and one or more ICAO ids are given, messages for the specified airports are fetched from src_metaf
.
type of content in msg_synop
:
SYNOP message (default)
WMO SYNOP id(s)
national id(s) STATION-COUNTRY
SYNOP SHIP id(s)
SYNOP MOBIL id(s)
If msg_synop
starts with AAXX
, BBXX
or OOXX
or is not a list of SYNOP ids, type_synop
is set to synop.
If type_synop
is wmo, ship, mobil or nat and one or more SYNOP ids are given, messages for the specified stations are fetched from src_synop
.
type of content in msg_buoy
:
BUOY message (default)
WMO buoy id(s)
If msg_buoy
is not a list of WMO buoy ids, type_buoy
is set to buoy.
If type_buoy
is wmo and one or more WMO buoy ids are given, messages for the specified buoys are fetched from src_buoy
.
type of content in msg_amdar
:
AMDAR message (default)
aircraft id(s)
If msg_amdar
starts with AMDAR
or ARP
, or is not a list of aircraft ids, type_amdar
is set to amdar.
If type_amdar
is ac and one or more aircraft ids are given, messages for the specified aircrafts are fetched from src_amdar
.
language for output of script and display of parsed message: de (default), en, es
If lang
is not set the first allowed value of the HTTP header Accept-Language
is used.
unit for temperatures in summary mode: C (default), F
output format: html (default), text, xml (with style sheet reference)
source for METAR/TAF messages to be fetched: noaa (NOAA/IWS)[1] (default), addsds[2], ogimet[2], nws[1], cod[1] (no TAF). It is ignored if a source in DB_DATA_SOURCES
[3] could be opened or $CGI_DATA_DIR/metaf.txt[4] exists.
Note: cod is not available in the web-based interfaces.
source for SYNOP messages to be fetched: nws[1] (default), ogimet[2], cod[1]. It is ignored if a source in DB_DATA_SOURCES
[3] could be opened or $CGI_DATA_DIR/synop.txt[4] exists.
source for BUOY messages to be fetched: nws[1] (default), ogimet[2]. It is ignored if a source in DB_DATA_SOURCES
[3] could be opened or $CGI_DATA_DIR/buoy.txt[4] exists.
source for AMDAR messages to be fetched: nws[1] (default). It is ignored if a source in DB_DATA_SOURCES
[3] could be opened or $CGI_DATA_DIR/amdar.txt[4] exists.
which messages to show and how to show them:
show all messages in selected time period, show one row per message (TAF: one row per forecast period, AMDAR: one row per observation)
show only latest message for each station in selected time period, show values in detail
for mode summary: number of hours to fetch messages for (0..72, default: 24)
Note: The exact time range for which data can be fetched depends on the source of messages.
METAR/TAF message to be processed, or ICAO id(s)
SYNOP message to be processed, or WMO id(s)
BUOY message to be processed, or WMO id(s)
AMDAR message to be processed, or aircraft id(s)
[1]: Files will be fetched from the server and searched. Note: The parameter hours is used to select files by their time stamp or name; the selected files do not necessarily contain only messages for the chosen hours.
[2]: the HTML form provided by the server will be used
[3]: For the description of the configuration variable $DB_DATA_SOURCES see the USAGE NOTES for DB_DATA_SOURCES
below.
[4]: For the format required for the files in $CGI_DATA_DIR see the USAGE NOTES for CGI_DATA_DIR
below.
The length of the body of the POST request (not the length of query string of the URL) is restricted to 600 bytes.
The following variables can be adapted to local needs; this is typically done during the installation:
directory for the XSL style sheets
directory for files with pre-processed METAR/TAF/SYNOP/BUOY/AMDAR messages
The messages in these files must have the format specified by the WMO Manual No. 306, without modifications due to distribution like providing the initial part of messages only once for several messages or appending an "=" (equal sign) to terminate a message, with the data type T1T2
prepended. This format can be obtained using:
metafsrc2raw.pl -F<FORMAT> -H1 [FILE] ...
complete path for log file
full path for curl
options for curl
path and options for curl
options for curl
if an HTTP proxy should be used
full path for xsltproc
space delimited strings to describe possible data sources
If the string sqlite
is in the list, the file $CGI_DATA_DIR/sqlite.db is used as database. For other strings, the file $CGI_DATA_DIR/string
.db should contain the Data Source Name (DBI:
...) in the first line. If the second line starts with user=
, the rest of the line is used as user name for the authentication. If a user name was given and the third line starts with pass=
, the rest of the line is used as password for the authentication.
The first data source which can be opened is used. If the last data source fails to open or DB_DATA_SOURCES
is empty, the parameters src_
* are used.
However, if a string ends in /f
, this is the last data source to try and the parameters src_
* are not used, either. If this source fails to open, an error will be reported.
The Perl module DBI
and the module DBD
for the configured data source are required if a database is to be used.
If there are any CGI errors the type of error is reported and the script terminates.
The parameters msg_
* are truncated to 3000 characters. Letters are converted to upper case. Any characters that are not allowed in a message are removed.
If an invalid option was provided, the script will exit with status 1, otherwise it will exit with status 0.
Parse a METAR message and print the result as HTML:
metaf.pl msg_metaf="QUDO 090600Z 00000KT CAVOK 22/15 Q1021"
Fetch up-to-date METAR and TAF messages (from NOAA/IWS), SYNOP messages (from NOAA/NWS land) for Rio (SBGL, 83746), New York (KJFK, 74486), and Tokyo (RJTT, 47662) and BUOY messages from a buoy nearby (from NOAA/NWS) and print the result as XML:
metaf.pl format=xml type_metaf=icao type_synop=wmo type_buoy=wmo msg_metaf="SBGL KJFK RJTT" msg_synop="83746 74486 47662" msg_buoy="31550 41997 53596"
metaf2xml::parser(3pm), metaf2xml::src2raw(3pm), metafsrc2raw(1), https://metaf2xml.sourceforge.io/
copyright (c) 2006-2023 metaf2xml @
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.