Ganymed 1.0 User's Guide: Difference between revisions

Bmauer (talk | contribs)
Bmauer (talk | contribs)
Line 284: Line 284:


=== post.rc ===
=== post.rc ===
=== Parser Expression Guide ===
Both the History and ExtData components use the MAPL parser implemented in Ganymed-1.0 and to avoid duplication what constitutes a valid expression for the parser will be documented here.
The MAPL parser evaluates an ESMF field element by element using an expression string which could contain other ESMF fields as variables. For example, an expression such as log(A) would produce a field where each element of the new field is the log of that particular element of A.
The following can appear in the expression string:
# The function string can contain the following mathematical operators +, -, *, /, ^, and ()
# Variable names. See the documentation for the History and ExtData components for what variables names can be used in the particular application of the parser.
# The following single argument functions which are case insensitive: exp, log10, log, sqrt, sinh, cosh, tanh, sin, cos, tan, asin, acos, atah, heav (the Heaviside step function)
# Integers or real constants specified in the following format: [+|-][nnn][.nnn][e|E|d|D[+|-]nnn] where nnn is any number of digits. The mantissa must contain at least one digit before or following an optional deciamal point. Valid exponent identifiers are 'e', 'E', 'd', or 'D'. If they appear they must be followed by a valid exponent!
Operations are evaluated in the following order:
# () expressions in brackets
# -X unary minux
# X^Y exponentiation
# X*Y X/Y multiplication and division
# X+Y X-Y addition and subtraction
There are several logical requirements one must be cognisant of when creating parser expressions. Since the expression is evaluated element by element any fields used in an expression must be conformal. In others words the underlying arrays in every field must have the same dimensions. Thus it is illegal to specify an expression involving two fields that have different vertical levels such as a center and an edge variable. The one exception is operations involving 2D and 3D fields when the first two dimensions of the 3D field are the same as the 2D field. In this case the expression is evaluated between each level of the 3D field and the 2D field resulting in a 3D field. This could be used to scale each level of a 3D field by a 2D field.
The parser also obeys undef arithmetic. Any operation involving the hard coded undef value (MAPL_UNDEF) is undef.
The following are several examples of valid expressions. For the examples it is assumed that A, B, C, and D are conformal fields.
# B*2.0e0
# sqrt(A*A+B*B)
# A*heav(B)
# A^(C+D)-2.0e-3