#!/usr/bin/perl -w

my $op = $ARGV[0];

use strict;
use warnings;

my @descs = (
	[ 0, q{Average} ],
	[ 1, q{Accumulation} ],
	[ 2, q{Maximum} ],
	[ 3, q{Minimum} ],
	[ 4, q{Difference (value at the end of the time range minus value at the beginning)} ],
	[ 5, q{Root Mean Square} ],
	[ 6, q{Standard Deviation} ],
	[ 7, q{Covariance (temporal variance)} ],
	[ 8, q{Difference (value at the beginning of the time range minus value at the end)} ],
	[ 9, q{Ratio} ],
	[ 51, q{Climatological Mean Value} ],
	[ '10-191', q{Reserved} ],
	[ '192-254', q{Reserved for Local Use} ],
	[ 200, q{Vectorial mean} ],
	[ 201, q{Mode} ],
	[ 202, q{Standard deviation vectorial mean} ],
	[ 203, q{Vectorial maximum} ],
	[ 204, q{Vectorial minimum} ],
	[ 205, q{Product with a valid time ranging inside the given period} ],
	[ 254, q{Istantaneous value} ],
);

my @notes = (
	q{Validity time is defined as the time at which the data are measured or at which forecast is valid; for statistical processing data, the validity time is the end of the time interval.},

	q{The reference time is defined as the nominal time for report or model output (start of forecast time).},

	q{For instantaneous values: the date and time in DB-All.e are the validity date and time of a value; P1 and P2 are 0.},

	q{For statistically processed values (for example average, accumulation, extreme values): the date and time in DB-All.e are the date and time of end of the time interval.},
	
	q{P1 is defined as the difference in seconds from validity time and the reference time. For standard forecast it is the positive forecast time. Note that, for observed values, the reference time is the same as the validity time, therefore for observed values P1 is always zero.  P1 < 0 is a valid case for report containing data in the past with respect to the nominal report time},

	q{P2 is defined as the duration of the period over which statistical processing, and is always positive. Note that, for non statistical values, P2 is always zero.},

#	q{The Eta (NAM) vertical coordinate system involves normalizing the pressure at some point on a specific level by the mean sea level pressure at that point.},
);


if ($op eq 'dox')
{
	print q{/**@defgroup trange_table Time range values
@ingroup tables

This table lists the various P indicator, P1, P2 value combinations that can be
used to specify a time range.

They values closely correspond to how a time range is specified in the GRIB
file format.
};

	for my $d (@descs)
	{
		print '\\li \b ', $d->[0], " ";
		my $desc = $d->[1];
		$desc =~ s/\n+/\n/g;
		print $desc;
	}

	print q{
Notes about the time range values:
};

	for my $n (@notes)
	{
		$n =~ s/\n+/\n/g;
		print '\\li ', $n;
	}

	print "*/\n";
}
elsif ($op eq 'tex')
{
	print q( 
\\begin{description}
);

	for my $d (@descs)
	{
		print '\\item [', $d->[0], "]\n";
		print $d->[1];
	}

	print q(\\end{description}

Notes about the time range values:

\\begin{itemize}
);

	for my $n (@notes)
	{
		print '\\item ', $n, "\n";
	}

	print q(\\end{itemize}
);
} else {
	print STDERR "Unknown operation: $op\n";
	exit 1;
}

exit 0;
