#!/usr/bin/perl ######################################################################## # metaf2xml.pl -- wrapper script for parsing and printing reports # # copyright (c) metaf2xml 2006-2007 # # 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, write to the Free Software # Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA ######################################################################## ######################################################################## # some things strictly perl ######################################################################## use strict; use warnings; =head1 NAME metaf2xml.pl -- wrapper script for parsing and printing reports =head1 SYNOPSIS metaf2xml.pl [C]... [C]... =head1 DESCRIPTION Note: This manual is valid for version 1.29 of metaf2xml. This script is an example interface to the modules C and C. Messages (per default: METAR) can be given on the command line (in single or double quotes) or read from C, one message per line. C expects complete messages, as specified by WMO-Nr. 306, without additions or contractions as done for distribution (e.g. the SYNOP section 0 is given only once for several messages, or a trailing "=" (equal sign)). It also recognises the keywords B, B, and B. If a message consists only of such a keyword, all messages after it are expected to be of the corresponding type. The keyword can also be prepended to a message. =head1 DEPENDENCIES The modules C, C, and C are required. =head1 OPTIONS =over =item -t given message is a TAF message =item -s given message is a SYNOP message =item -x F write result as XML to F =item -X with B<-x>, produce XML file with C<> and C<> section, to be used for the user interface =item -D with B<-X>, add DOCTYPE and reference to DTD =item -S F with B<-X>, add reference to stylesheet F, to be used for the user interface =item -O F with B<-S>, add F to XML file =back =head1 EXAMPLES Parse a METAR message and write the XML section C<> to C: metaf2xml.pl -x- 'YUDO 090600Z 00000KT CAVOK 22/15 Q1021 NOSIG' Parse several METAR, TAF, and SYNOP messages and write the XML to the file F: metaf2xml.pl -x metar-taf-synop.xml <metaf2xml::parser(3pm), metaf2xml::XML(3pm), metaf(1), L =head1 COPYRIGHT, LICENSE, DISCLAIMER copyright (c) 2006-2007 metaf2xml @ L 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, write to the Free Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA =cut use Getopt::Std; # path may be changed by install use lib '/opt/metaf2xml/lib'; # METAF2XML_LIB use metaf2xml::parser qw(parseReport); use metaf2xml::XML qw(startXML printReport finishXML); my ($VERSION_ID, %report_data, %opts, $is_taf, $is_synop, $output); $VERSION_ID = 'metaf2xml.pl: $Id: metaf2xml.pl,v 1.16 2007/09/11 13:04:33 metaf2xml Exp $'; sub go { my $msg = shift; if ($msg eq 'METAR') { $is_taf = 0; $is_synop = 0; return; } if ($msg eq 'TAF') { $is_taf = 1; $is_synop = 0; return; } if ($msg eq 'SYNOP') { $is_taf = 0; $is_synop = 1; return; } %report_data = parseReport $msg, $is_taf, $is_synop; printReport \%report_data if exists $opts{x}; } sub usage { print STDERR (shift) . "Usage: metaf2xml.pl [ ] [ ]\n" . " Options:\n" . " -t given message is a TAF message\n" . " -s given message is a SYNOP message\n" . " -x write result as XML to \n" . " -X with -x, produce XML file with and section\n" . " -D with -X, add DOCTYPE and reference to DTD\n" . " -S with -X, add reference to stylesheet \n" . " -O with -S, add to XML file\n"; exit 1; } # get and check options usage '' unless getopts('tsx:XDS:O:', \%opts); # check dependencies of options usage "option -X requires option -x\n" if exists $opts{X} && !exists $opts{x}; usage "option -D requires option -X\n" if exists $opts{D} && !exists $opts{X}; usage "option -S requires option -X\n" if exists $opts{S} && !exists $opts{X}; usage "option -O requires option -S\n" if exists $opts{O} && !exists $opts{S}; $is_taf = exists $opts{t}; $is_synop = exists $opts{s}; startXML \%opts, [ $VERSION_ID, $metaf2xml::parser::VERSION_ID ] if exists $opts{x}; if ($#ARGV >= 0) { for (@ARGV) { for (split /\n/, $_) { go $_; } } } else { while () { chomp(); go $_; } } finishXML;