Parsers and variables
The XML configuration file is evaluated by two parsers. In a first step a text parser is applied.
In the second step mathematical expressions are resolved to a number.
Variables (see section variables) can be referenced via their
name directly for the expression parser or in the form {name}
for the text parser.
Mathematical expression parser
In all input fields that accept numbers (int, uint, double, angle, time) numerical expressions are also allowed. Declared variables can be accessed via their name. The following operations and functions are defined:
- Constants:
pi()
,rho()=180/pi()
,nan()
,c()
: light velocity,G()
: gravitational constant,GM()
: gravitational constant of the Earth,R()
: reference radius of the Earth -
Mathematical:
+
,-
,*
,/
,^
-
Comparison:
==
,!=
,<
,<=
,>
,>=
, result is 1 or 0 -
Logical: not
!
, and&&
,||
, orisnan(x)
, result is 1 or 0 -
Functions:
sqrt(x)
,exp(x)
,sin(x)
,cos(x)
,tan(x)
,asin(x)
,acos(x)
,atan(x)
,abs(x)
,round(x)
,ceil(x)
,floor(x)
,deg2rad(x)
,rad2deg(x)
-
Functions with 2 arguments:
atan2(y,x)
,min(x,y)
,max(x,y)
,mod(x,y)
-
Time functions:
now()
: local time in MJD,date2mjd(year, month, day)
,gps2utc(mjd)
,utc2gps(mjd)
,dayofyear(mjd)
,decimalyear(mjd)
-
Condition:
if(c,x,y)
: If the first argument is true (not 0), the second argument is evaluated, otherwise the third.
Text parser
Before the mathematical expression parser evaluates the expression, a simple text parser is applied.
The text parser is used for all input fields (also file names). It scans the text for terms like
{variable}
and replaces it by the text content of the variable
.
A literal '{
' character must be escaped with '#{
'.
The text parser allows regex replacements in the form {text/regex/replace}
.
All matches of regex
in the text
are replaced by replace
.
Possible {variables}
in the three parts are evaluated beforehand.
Capturing groups ()
can be accessed by $1
, $2
,
… in the replacement ($0
is the complete match). Additional escape sequences are:
\l
lowercase next char,-
\u
uppercase next char, -
\L
lowercase until\E
, -
\U
uppercase until\E
, -
\Q
quote (disable) pattern metacharacters until\E
, -
\E
end either case modification or quoted section.
Examples:
{{variable}/test/text}
replaces all occurrences oftest
bytext
.-
{TEXT/.+/\L$0}
converts text to lower case. -
{012345/.#{2}(.#{3}).*/$1}
extracts the substring at index 2 and length 3 resulting in234
. Note the escaping#{
.
The text parser also evaluates terms in the form {expression:format}
and replaces it by a formatted
output. In order not to get confused with the regex replacements, the '/
' character must be escaped
with '#/
' in the expression. The format
contains the text to be written as output.
It can contain embedded format specifiers that are replaced by the value of the expression and formatted
as requested (also multiple times). In the following, the resulting formatted output is given in the
brackets for an expression with the example value of 57493.8:
%i
: Integer [57494]-
%f
: Decimal floating point [57493.800000] -
%e
: Scientific notation [5.749380e+04] -
%g
: Use the shortest representation:%e
or%f
[57493.8] -
%c
: Interpret number as ASCII character -
%%
: Write a single literal%
character
%y
: Four digit year [2016]-
%Y
: Two digit year [16] -
%m
: Month [04] -
%d
: Day of month [15] -
%H
: Hour [19] -
%M
: Minute [12] -
%S
: Second [00] -
%D
: Date (same as%y-%m-%d
) [2016-04-15] -
%T
: Time (same as%H-%M-%S
) [19-12-00] -
%W
: GPS week [1892] -
%w
: Day of GPS week (0..6) [5] -
%O
: Day of year (1..366)
%[width][.precision]specifier
,
where [width]
is the minimum number of characters to be printed.
If the value to be printed is shorter than this number, the result is padded with blank spaces
(or zeros if [width]
starts with a zero).
The [.precision]
defines the number of digits after the period (for %g
the number of
significant digits instead).Example:
Two variables time=57493+19/24+12/1440
and satellite=swarm
are
set in the global section. The inputfile=data/{time:%y}/{satellite}_{time:%D}.dat
is expanded to "data/2016/swarm_2016-04-15.dat"
.
Example:
The variable x=3+5
is set in the global section.
The expression number=2*x
is evaluated by the expression parser to =16
.
In contrast if we use brackets like in number=2*{x}
the expression is first evaluated
by the text parser to "2*3+5"
and the expression parser now gives the result =11
.
Variables for data
Some programs (e.g. FunctionsCalculate, InstrumentArcCalculate,
GriddedDataCalculate, or the plot programs)
read data (matrix) or gridded data
and evaluate input/output expressions for each data row.
For these kind of expressions additional variables are automatically defined for each data column
(X
stands for the data column number: $0\ldots n$):
index
: the row number, starting with zero-
dataX
: the value itself -
dataXcount
: number of rows -
dataXmin
-
dataXmax
-
dataXsum
-
dataXmean
-
dataXrms
: root mean square -
dataXstd
: standard deviation -
dataXmedian
-
dataXmad
: median absolute deviation -
dataXstep
: the minimal difference between two neighboring data points in the column
longitude
in degrees-
latitude
in degrees -
height
in meters -
cartesianX
coordinate in meters -
cartesianY
coordinate in meters -
cartesianZ
coordinate in meters -
area
of the unit sphere -
dataXwmean
: area-weighted mean -
dataXwrms
: area-weighted root mean square -
dataXwstd
: area-weighted standard deviation