CNS Language Description

The CNS data language is a simplistic functional language designed to provide greater flexibility for data input and interpolation than was possible in previous CNS versions.

Language Definition

A function consists of a single expression. Expressions are any of the following:

Form

Description

Examples

Meaning

number

one or more digits, followed optionally by a decimal point and one or more digits

2

A number

variable

a dollar-sign ('$') followed by an identifier (any number of letters, digits, or underscores)

$foo

the value stored in the variable

array element

a dollar-sign followed by an identifier, followed by up to four indices, of the form '[' expression ']'

$awry[0][2]

the value stored in the given element of the array

expression operator expression

two expressions with an operator (*, /, +, -, <, <=, =, >=, >, and, or) between them

1+2

the value yielded by evaluating the operator on the two expressions

( expression )

an expression in parentheses

(1+2)

the value of the expression in the parentheses

conditional

if expression1 then expression2 else expression3 end

if $foo>$bar then 3 else 5 end

null if expression1 evaluates to null, expression3 if expression1 evaluates to 0, expression2 otherwise

function call

an identifier which does not begin with a digit followed by a parenthetized argument list

myFunction($foo,6)

the value of the body of the function, evaluated after setting the arguments to their corresponding values

aggregate

an aggregate name (either sum or prod) followed by a bounds list of the form '(' variable '=' expression1 to expression2 ')', followed by an expression enclosed in curly braces ({ and })

sum($i=0 to 10){ $awry[$i] }

the sum (or product) of the consecutive evaluations of the body yielded by setting the variable to each value between expression1 and expression2 (inclusive), incrementing (or decrementing, if expression2 is less than expression1) by 1 each time

Predefined Variables

General

Variable

Value

$null

null

$today

Current date index

$now

Current time index

Processing

Variable

Value

$1

First column of current data row

$2

Second column of current data row

...

...

$n

Nth column of current data row

Interpolation

Variable

Value

$numstns

number of stations

$here

current station index

$lat[station]

latitude (North, in degrees) of selected station

$lon[station]

longitude (West, in degrees) of selected station

$elev[station]

elevation (in meters) of selected station

$closest[station][n]

the index of the nth closest station to selected station

$type

index of the current column type (maximum, minimum, mean, or accumulated); used for index to arrays below

$sensor_name[station][date][time][type]

value of selected column type of selected sensor at selected station for selected date and time

Examples

Expression

Value

$null

null

3.1415

3.1415

$pi

3.141593

$Temperature[$station_index][$date_index][$time_index][0]

74.3 (maximum value of the Temperature sensor at the given station, date, and time)

$closest[$station_index][$n]

3 (index of the nth closest station to the given station)

$Temperature[$closest[$here][$n]][$today][$now][0]

82.7 (maximum value of the Temperature sensor at the nth closest station to here, for today and now)

(sum($i=1 to 20){if $Temperature[$closest[$here][$i]][$today][$now][0]=$null then 0 else $Temperature[$closest[$here][$i]][$today][$now][0] end})/20

76.8 (average of maximum Temperature values at the 20 closest stations to here, for today and now)

(sum($i=1 to 20){if $Temperature[$closest[$here][$i]][$today][$now][0]=$null then 0 else $Temperature[$closest[$here][$i]][$today][$now][0] end})/(sum($i=1 to 20){if $Temperature[$closest[$here][$i]][$today][$now][0]=$null then 0 else 1 end})

76.8 (average of maximum non-null Temperature values at the 20 closest stations to here, for today and now)

((sum($i=1 to 20){if $Temperature[$closest[$here][$i]][$today][$now][$type]=$null then 0 else $Temperature[$closest[$here][$i]][$today][$now][$type]+(0.0196*$elev[$closest[$here][$i]]) end})/ (sum($i=1 to 20){if $Temperature[$closest[$here][$i]][$today][$now][$type]=$null then 0 else 1 end}))-(0.0196*$elev[$here])

78.2 (average of maximum non-null Temperature values at the 20 closest stations to here, scaled based on elevation)

Nmcc_Wiki: CNS/Language (last edited 2008-12-22 23:47:33 by Stan)