NCL expressions overview

Expressions are anything that results in a value. Variable references are expressions as well as functions and literal values. Multiple expressions can occur on a single line joined together by operators and the are group by terms and operator precedence.

Algebraic

Algebraic expressions operate on arrays of basic numeric types. There are nine main algebraic operators: multiply, divide, exponent, plus, minus, modulus, less-than selection, greater-than selection, and negative. All of the operators except negative take two operands. Also, in general, both operands should be the same type. If they are not, NCL attempts to coerce them to identical types. If this fails, a type mismatch error is generated. Additionally, either the operands must have the same number of dimensions and dimension sizes, or one operand can be a scalar value. The operators operate on the entire array of data.

The following is a list of the operator characters. The operators are listed in order of precedence: the first one has the highest precedence. The precedence rules can be circumvented by using parentheses '(' ')' around expression that should be computed first.

		-	Negative
		^	Exponent
		*	Multiply
		/	Divide
		%	Modulus
		+	Plus
		-	Minus
		<	Less-than selection
		>	Greater-than selection

Logical

Logical expressions are formed by relational operators. There are ten relational operators: less-than-or-equal, greater-than-or-equal, less-than, greater-than, equal, not-equal, and, or, exclusive-or, not. All of these operators yield logical type results. And, or, exclusive-or, and not require logical operands, and the rest accept any type.

All of the logical expressions function similarly with respect to comparisons between arrays and arrays, arrays and scalars, and scalars and scalars. For array operands, each corresponding element is compared and the result is an array of logical values the size of the operands. A single scalar can be compared against each element in an array. The result is an array of logical values the size of the array operand. Finally, when two scalars are compared, the result is a scalar logical value.

The following is a list of the logical operators and their precedence.

		.le. 	Less-than-or-equal
		.lt.	Less-than
		.ge.	Greater-than-or-equal
		.gt.	Greater-than
		.ne.	Not-equal
		.eq.	Equal
		.and.	And
		.xor.	Exclusive-or
		.or.	Or
		.not.	Not