@BeginModule
@Name      = Vargen
@Title     = Generate a field
@Section   = Miscellaneous
@Arguments = ofile
@Operators = const random stdatm

@BeginDescription
Generates a dataset with one or more fields. The field size
is specified by the user given grid description.
According to the chosen operator all field elements
are constant or filled with random numbers.
@EndDescription
@EndModule


@BeginOperator_const
@Title     = Create a constant field
@Parameter = const grid

@BeginDescription
Creates a constant field. All field elements of the grid
have the same value.
@EndDescription
@EndOperator


@BeginOperator_random
@Title     = Create a field with random numbers
@Parameter = grid [seed]

@BeginDescription
Creates a field with rectangularly distrubuted random numbers in the interval [0,1].
@EndDescription
@EndOperator


@BeginOperator_stdatm
@Title     = Create values for pressure and temperature for hydrostatic atmosphere
@Parameter = levels

@BeginDescription
Creates pressure and temperature values for the given list of vertical levels.
The formulars are:

@IfMan
P(z) = P_0 * exp(-1 * g/R * H/T_0 * log( (exp(z/H)*T_0 + T_Delta)/(T_0 + T_Delta))
@EndifMan
@IfMan
T(z) = T_0 + T_Delta * exp(-z/H)
@EndifMan
@IfDoc
@BeginMath
P(z) = P_0 \exp \left(- \frac{g}{R} \frac{H}{T_0} \log \left( \frac{\exp \left( \frac{z}{H} \right) T_0 + \Delta T}{T_0 + \Delta T} \right) \right)
@EndMath
@BeginMath
T(z) = T_0 + \Delta T \exp \left(- \frac{z}{H} \right)
@EndMath
@EndifDoc

with the following constants

@IfMan
T_0     = 213 K           Offset to get a surface temperature of 288K
T_Delta = 75 K            Temperature lapse rate for 10Km
P_0     = 1013.25 hPa     Surface pressure
H       = 10000.0 m       Scale height
g       = 9.80665 m/s**2  Earth gravity
R       = 287.05 J/kg*K   Gas constant for air
@EndifMan
@IfDoc
@BeginEqnAry
 T_0     =& 213 \mbox{K} &: \mbox{offset to get a surface temperature of 288K} \\
 \Delta T=& 75 \mbox{K} &: \mbox{Temperature lapse rate for 10Km} \\
 P_0     =& 1013.25 \mbox{hPa} &: \mbox{surface pressure} \\
 H       =& 10000.0 \mbox{m} &: \mbox{scale height} \\
 g       =& 9.80665 \frac{\mbox{m}}{\mbox{s}^2}   &: \mbox{earth gravity} \\
 R       =& 287.05 \frac{\mbox{J}}{\mbox{kgK}} &: \mbox{gas constant for air} \\
@EndEqnAry
@EndifDoc

This is the solution for the hydrostatic equations and is only valid for the
troposphere (constant positive lapse rate). The temperature increase in the
stratosphere and other effects of the upper atmosphere are not taken into
account.
@EndDescription

@BeginExample
To create a standard atmosphere dataset on a given horizontal grid:
@BeginVerbatim
   cdo enlarge,gridfile -stdatm,10000,8000,5000,3000,2000,1000,500,200,0 ofile
@EndVerbatim
@EndExample
@EndOperator

@BeginParameter
@Item = const
FLOAT   Constant
@Item = seed
INTEGER The seed for a new sequence of pseudo-random numbers [default: 1]
@Item = grid
STRING  Target grid description file or name
@Item = levels
FLOAT   Target levels in metre above surface
@EndParameter
