Kirk Wythers wrote:
Sorry for the "not sure where to even begin" nature of this email, but I
am stuck. I am trying to put together a aggregating script that takes
daily climate data and produces monthly averages. For example, the input
file has the form:
---8<--- snip
I need to step through 50 years of data, returning a single line of
monthly averages. SOmething like:
year month doy tmax tmin par precip NH4
NO3 O3 CO2 V1 V2 V3 V4
1949 1 15 5.45 -3.1 346 1.3
0 0 0 0 0 0 0 0
1949 2 61 4.6 1.2 421 2.1
0 0 0 0 0 0 0 0
etc....
So far I can not seem to get past reading in the data and printing it
out with something like:
#! /usr/bin/perl -w
use strict;
$, = ' '; # set output field separator
$\ = "\n"; # set output record separator
# These are the default values, no need to change them.
my %days = map +($_, 1),
qw/ 15 46 76 107 137 168 229 259 290 321 351 /;
while (<>) {
my @data = split;
# How about?
my ( $year, $month, $doy, $tmax, $tmin, $par, $precip, $NH4, $NO3, $O3, $CO2,
$V1, $V2, $V3, $V4 ) = split;
# You can now store your totals by month as:
$totals{$year}{$month}{tmax} += $tmax;
...
# and the count
$totals{$year}{$month}{count} ++;
# After you read all the input, you can calculate the averages.
--
Just my 0.00000002 million dollars worth,
Shawn
"For the things we have to learn before we can do them, we learn by doing them."
Aristotle
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/