#!/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{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 between the time in DB-All.e ( validity date and time or end of the time interval ) and the reference time. It can be negative only when the time in DB-All.e is earlier than the reference time. In other words, Note that, for observed values, the reference time is the same as the time in DB-All.e, therefore for observed values P1 is always zero.},

	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;
