No distinction is made between integer or real numbers. All numbers are internally coded as double precision floating point reals.
number ( number
op
number )
Operation between two numbers. op
is one of the operators below. These either return a number :
+ Addition | - Subtraction |
* Multiplication | / Division |
^ Power |
or return 1 (result is true) or 0 (result is false)
string ( string op string )
...
:
> Larger Than | < Smaller Than |
>= Larger or Equal | <= Smaller or Equal |
= Equal | <> Not Equal |
Smaller, greater, equal applied to strings refer to lower, higher, same alphabetical order. The comparison is case sensitive and is done using the ASCII code of each letter, hence the following expression is true (returns 1) :
"ABC" < "abc"
Type man ascii at the UNIX prompt to know more about the ASCII encoding of characters.
string ( string & string & ... )
string ( string & number & ... )
string ( number & string & ... )
string ( string & date & ... )
string ( date & string & ... )
Returns a string equal to the concatenation of strings or strings and numbers and/or dates. If concatenating a date, the date is first converted to a string using the default string date format.
string ascii( number )
Returns a string consisting of one character whose ASCII code has been provided as the single parameter to the function. For example:
linefeed = ascii (10)
number length( string )
This function returns the length of a string
word = "hello"
print (word " is ", length(word), "characters long")
string lowercase( string )
Returns a lowercase copy of the input string.
...
This function splits the first input string at each occurrence of any of the field separators specified as the second string. It returns a list whose elements are the split tokens of the input string.
Macro assigns a type to each of these components (i.e. number or string) unless a third parameter is supplied which gives the desired type to be returned; currently 'string'
is the only allowed option. Space (" ") is the default separator when none is specified by the user, but any combination of characters can be specified as the set of separators.
# specify a comma and space as separator
s = "test1, 512.0, 498.0, 10.0"
f = parse(s, ", ")
# now access each retrieved element by indexing the list
print ("result of ", f[1], " : ", (f[2]-f[3])/f[4])
this prints :
result of test1 : 1.4
Supplying an empty string as the second parameter causes a complete list of the string's characters to be returned. For example :
parse ("Metview", "")
number ( number
and
number )
number ( number or
number )
number ( not
number )
Conjunction, Disjunction and Negation. Boolean operators consider all null values to be false and all non null values to be true. Result is either 1 or 0.
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
|
Returns absolute value of a number.
Anchor | ||||
---|---|---|---|---|
|
Anchor | ||||
---|---|---|---|---|
|
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
number |
Return the arc trigonometric function of a number. Result is in radians.
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
number |
Return the cosine of a number (angle in radians).
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
|
Returns the exponential of a number
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
|
Returns integer part of a number (no rounding, e.g. int(1.999)=1.0 )
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
number |
Takes the integer part of the first number and extracts a specified bit (or number of bits if a third number parameter is specified), where bit number 1 is the least significant bit (lsb). A single bit will always be returned as 1 or 0, regardless of its position in the integer. A group of bits will be treated as if the first bit is the least significant bit of the result A few examples illustrate.
To extract the 1st, 2nd and 3rd bits from a number separately:
n = 6 # in bit-form, this is `00000110' with the lsb at the right
flag = intbits (n, 1) # flag is now 0
flag = intbits (n, 2) # flag is now 1
flag = intbits (n, 3) # flag is now 1
To extract the 1st and 2nd bits together to make a single number:flag = intbits (n, 1, 2) # flag is now 2
To extract the 2nd and 3rd bits together to make a single number:flag = intbits (n, 2, 2) # flag is now 3
To extract the 3rd and 4th bits together to make a single number:flag = intbits (n, 3, 2) # flag is now 1
The number of bits available depends on the machine architecture and Metview's compilation options, but at the time of writing it should be either 32 or 64.
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
number |
Returns the natural logarithm of a number.
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
number |
Returns the logarithm base 10 of a number.
Anchor | ||||
---|---|---|---|---|
|
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
number |
Returns maximum / minimum of the input values.
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
|
Returns the remainder of the division of the first value by the second. If the second number is larger than the first, it returns the integer part of the first number. Note that only the integer parts of the inputs are considered in the calculation, meaning that a second parameter of 0.5 would cause a division by zero.
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
|
Returns the negative of a number. The same as (- number).
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
|
returns a list :
[M,e,t,v,i,e,w]
The parse()
function is useful to parse text input when reading ASCII files within a macro program. Note that for ASCII data structured in columns (such as CSV files), Metview has some specific tools available - see ASCII Tables for more information.
string search (string,string)
Searches the first string for the second string. The return value is the index of the first occurrence of the second string in the first. If the search fails, then it returns -1. Note that the comparison is case- sensitive.
For example :
filename = 'z_t2m_u_v_20060717.grib'
t2m_index = search (filename, 't2m')
returns the value 3.
string substring (string,number,number)
Returns a substring of the input string. The second parameter specifies the index of the first character to be retrieved (1 is the first character). The third parameter specifies the index of the last character to be retrieved. For example :
substring ("Metview", 2, 4)
returns the string "
etv
"
.
...
|
Converts a date to a
...
number according to the
...
number date format specified as the second input
...
argument.
If date = 1997-04-01 02:03:04 (say), the available
...
number date formats result in :
- yy gives 97
- yyyy gives 1997
- m gives 4
mm gives 04
mmm gives Apr
mmmm gives April
d gives 1
dd gives 01
ddd gives Tue
dddd gives Tuesday
D gives - or mm give 4
- d or dd give 1
- D or DDD give 91 (4th of April = julian day 91; 92 for a leap
- is the 91st day of the year).
DDD gives 091
H gives 2
HH gives 02
M gives 3
MM gives 03
S gives 4
SS gives 04
Any other character is copied as such.
...
Returns an uppercase copy of the input string.
- H or HH give 2
- M or MM give 3
- S or SS gives 4
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
|
Sets the printing precision for floating point values, i.e. how many significant digits are used when printing or writing to a file. The value returned is the current precision value. Called with no arguments, it resets the precision to its default value, i.e. 12. Examples of printed output for print(1234.56789) :
precision( 12 ) gives 1234.56789
precision( 6 ) gives 1234.57
precision( 4 ) gives 1235
precision( 2 ) gives 1.2e+03
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
number |
Returns a randomly selected non-negative double-precision floating-point value. The return values are uniformly distributed between [0.0, 1.0). There is no need to `seed' this random function, as this is done automatically the first time it is called.
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
number |
Rounds off spurious decimals in a value. The first number is the value to be rounded, the second is the number of decimal places to leave. Examples of values returned by round(v,n) for v = 1234.56789 :
round( v, 1 ) gives 1234.6
round( v, 3 ) gives 1234.568
round( v, -2 ) gives 1200
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
number |
Returns the sign of a number as a number : -1 for negative values, 1 for positive and 0 for null values.
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
number |
Return the sine of a number (angle in radians).
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
number |
Returns the square root of a number.
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
string |
Returns the string equivalent of a number.
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
number |
Returns the sum of the input values.
Anchor | ||||
---|---|---|---|---|
|
Excerpt |
---|
|
Return the tangent of a number (angle in radians).
...