X-Git-Url: http://dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=Geo%2FTAF%2Fexample%2Fcmd_chunks.pl;fp=Geo%2FTAF%2Fexample%2Fcmd_chunks.pl;h=642bf41003e3302ab5b8a787f218a1664a9df2b5;hb=b4ab8d50203bcb77dc2fa09d3339ad6ec07304a8;hp=0000000000000000000000000000000000000000;hpb=a6627ef7afbee6ab015d9f8b75e96cd59809bb59;p=spider.git diff --git a/Geo/TAF/example/cmd_chunks.pl b/Geo/TAF/example/cmd_chunks.pl new file mode 100755 index 00000000..642bf410 --- /dev/null +++ b/Geo/TAF/example/cmd_chunks.pl @@ -0,0 +1,68 @@ +#!/usr/bin/perl +# +# This example takes METARs and TAFs from the standard input, parses them +# and prints them out in a (sort of readable) normalised form +# +# Note that this is a state machine which can take any old rubbish and looks +# for a start of a forecast in the input. It then searches for a blank line +# before looking for the next. +# +# You can get METARs from ftp://weather.noaa.gov/data/observations/metar +# TAFs from ftp://weather.noaa.gov/data/forecasts/taf/ and +# from ftp://weather.noaa.gov/data/forecasts/shorttaf/ +# directories. This program will parse these files directly +# +# You will need to press twice to get any output if you are entering +# stuff manually. +# +# $Id$ +# +# Copyright (c) 2003 Dirk Koopman G1TLH +# + +use strict; +use Geo::TAF; + +my $in; +my $t; + +while () { + chomp; + if (/^\s*$/) { + if ($in) { + $t = new Geo::TAF; + if ($in =~ /(?:METAR|TAF)/) { + $t->decode($in); + } elsif ($in =~ /[QA]\d\d\d\d/) { + $t->metar($in); + } else { + $t->taf($in); + } + print_taf($t); + undef $in; + undef $t ; + } + } else { + if ($in) { + $in .= $_; + } else { + next unless Geo::TAF::is_weather($_); + $in = $_; + } + } +} + +print_taf($t) if $t; + +sub print_taf +{ + my $t = shift; + + print $t->raw, "\n\n"; + + my $spc = ""; + foreach my $c ($t->chunks) { + print $c->as_chunk, "\n"; + } + print "\n\n"; +}