Name Last modified Size Description
Parent Directory - Geo-CCF-0.04.tar.gz 2004-03-23 16:04 8.5K current source archive
Newsflash (Dec. 4, 2004) — this may be obsolete -- check this out: NDFD XML!
(Also, some hints on using the new format.)
Geo::CCF - decode National Weather Service Coded Cities Forecast data
use Geo::CCF; my $forecast = new Geo::CCF;
my $station = "BOS";
$forecast->ccf($ccf_data_downloaded_from_noaa);
die("Can't find info for $station") if !$forecast->{$station};
for (my $i=0; $i<Geo::CCF::NUM_FORECAST_PERIODS; $i++) { print $forecast->{$station}{CONDITION}[$i]; $forecast->{$station}{HIGH}[$i] and print ", high $forecast->{$station}{HIGH}[$i]"; $forecast->{$station}{LOW}[$i] and print ", low $forecast->{$station}{LOW}[$i]"; $forecast->{$station}{PROBPRECIP}[$i] and print ", $forecast->{$station}{PROBPRECIP}[$i]% " . "chance of precipitation."; print "\n"; }
Decodes the National Weather Service's CCF data files into a simple Perl object.
There's a lot of U.S. weather information available from the National Weather Service (and the larger National Oceanic and Atmospheric Administration). There are other CPAN modules for parsing some of this data, most notably the METAR reports on current aviation weather. And there's modules for scraping information from various commercial web sites. But, I couldn't find anything that could read the forecast information made available in the form of “CCF” — Coded City Forecast — files. This twice-daily forecast data is designed to be processed by computers, and indeed provides a lot of information in very little space.
Unfortunately, the format is a bit obtuse, so it's handy to have a Perl module to understand it for you. I couldn't find one, so here's mine.
You can download various CCF files for different locations from <http://weather.noaa.gov/pub/data/raw/fp/>. (Beware — a long and sometimes slow directory listing.) Each ccf file (named something like fpus41.kbox.ccf.bos.txt) contains the entries for several stations. Find the one that has the station you want to find the forecast for, and feed it to this module.
You'll get back a hash of the various stations in the report, with each station containing the forcast data for the next fourteen seven-hour periods. (Or, sometimes, only thirteen.) You'll have the predicted condition — rain, snow, dust, or whatever, high or low temperature, and chance of precipitation for each time slice.
First, create a new Geo::CCF object. Then, feed it CCF data as a single string. Then, simply look at the data you want to know for the station you want.
ccf()
ccf()
is the main thing. Give it a CCF file as a string, and
it'll parse it so you can access the forecast data in a sane way.
The important thing to realize is that these values are all stored on a per-station basis — the top-level hash is an index of all of the stations decoded from the given CCF data.
Furthermore, much of the data is contained in arrays, with each element corresponding to a future 12-hour period. In order, of course. There's usually 14, but sometimes the last value is missing — nothing to be done about that! You can use the Geo::CCF::NUM_FORECAST_PERIODS constant as a loop index as in the example above, but in actual practice, it may be nicer to just check the arrays to see if the forecast for the desired future period is defined.
You won't see the parenthetical letter in the results — that's the code in the original file. Some are mnemonic (C or R or S or T) and some are not quite so (J or P or pretty much all the rest). Anyway, you have this module so you don't have to worry about that.
Also of note: the source data is in 24-hour periods, but this array provides entries for each 12-hour block, to match the temperature and precipitation forecasts. There's no extrapolation or any magic — each entry is simply doubled. Don't be fooled.
ccf()
method, it'll put that
info here. Otherwise, it'll be undefined.
Anyway, CCFDATE is a two-digit number, and CCFTIME is four digits for HHMM.
None that I know, but I haven't done widespread testing. It's possible that there's some data-format glitches which I haven't covered. If you find any problems, please e-mail me.
No attempt is made to validate incoming data. If you give ccf()
garbage, it
will return with nothing, at best. And if you give slightly weird data, you
won't get any clue back about what's wrong. That ought to be fixed.
The two-line format is apparently an expansion of the earlier one line. This module won't cope with missing second lines.
There also aren't any test cases. Tests are good to have.
Web site: <http://www.mattdm.org/misc/perl-Geo-CCF/>
CCF info: <http://www.crh.noaa.gov/lmk/product_guide/products/forecast/ccf.htm>
Other modules: Geo::METAR, Geo::WeatherNOAA, Geo::Weather
Matthew Miller, <(get e-mail)>
Copyright © 2004 by Matthew Miller
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.