The above example illustrates how multi-dimensional arrays are handled in NCL expressions. The above statement c = a * b is equivalent to looping through both dimensions of a and b, multiplying each element and assigning it to the respective element in c. The following code segment is equivalent to the above example. This shows how NCL's syntax saves a lot of typing.; ; Define two [2]x[2] arrays ;a = (/ (/ 1, 2 /), (/ 3, 4 /) /) b = (/ (/ .1, .01 /), (/ .001, .0001 /) /); ; Multiplication of two [2]x[2] arrays ; c = a * bprint(c) Variable: c Type: float Total Size: 16 bytes 4 values Number of Dimensions: 2 Dimensions and sizes: [2] x [2] Coordinates: (0,0) 0.1 (0,1) 0.02 (1,0) 0.003 (1,1) 0.0004

dims = dimsizes(a) c = new(dims,float) do i = 0,dims(0) - 1 do j = 0, dims(1) - 1 c(i,j) = a(i,j) * b(i,j) end do end do

a = (/ (/ 1, 2 /), (/ 3, 4 /) /); ; Multiplication of an entire array by a single scalar ; b = a * 2print(b) Variable: b Type: float Total Size: 16 bytes 4 values Number of Dimensions: 2 Dimensions and sizes: [2] x [2] Coordinates: (0,0) 2 (0,1) 4 (1,0) 6 (1,1) 8

; ; Assign three variables values and missing values. Each variable's ; missing value is different. ;a = (/1, 2, -99/) a@_FillValue = -99 b = (/4, -999, 5/) b@_FillValue = -999 c = (/-9999, 7, 8/) c@_FillValue = -9999; ; Assignment to variable d of an expression containing all ; three variables with different missing values. ; d = a * b * c ; ; Assignment to variable of an expression containing two ; variables with different missing values. e = b * c; ; Results of first assignment. Note resulting missing value. ;print(d) Variable: d Type: integer Total Size: 12 bytes 3 values Number of Dimensions: 1 Dimensions and sizes: [3] Coordinates: Number Of Attributes: 1 _FillValue : -99 (0) -99 (1) -99 (2) -99; ; Results of second assignment. Note resulting missing value. ;print(e) Variable: e Type: integer Total Size: 12 bytes 3 values Number of Dimensions: 1 Dimensions and sizes: [3] Coordinates: Number Of Attributes: 1 _FillValue : -999 (0) -999 (1) -999 (2) 40

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 expressions that should be computed first.

- Negative

^ Exponent

* Multiply / Divide % Modulus # Matrix multiply

+ Plus - Minus

< Less than selection > Greater than selection

All of the logical operators function similar to algebraic operators with respect to operations 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 or missing values, the size and dimensionality 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 ordered by 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

The following are examples of array expressions.

(/ 1, 2, 3, 4, 5 /) (/ (/ 1, 2, 3 /)^2, (/ 4, 5, 6 /)^3,(/ 7, 8, 9 /)^4 /) (/ a - b, b + c, c / d /)

If a single variable is enclosed in array designator characters '(/' and '/)', only the variable's value is referenced and not its associated attributes, dimension names, and coordinates. The array designator characters are useful in performing value only assignment.

Functions can be defined to restrict parameters to be specific types, to have specific numbers of dimensions, and to have specific dimension sizes. If a parameter must be a certain type, then the coercion rules are applied to it.

One very important thing to
note is that all parameters are **passed by reference** in NCL, meaning a change
of a value in a variable within the function changes the value of the parameter.

However, if a parameter is coerced before the function is called, changes within the
function ** will not** be reflected in the parameter, because
coercion can only be applied in a single direction. A warning message is given in this
instance.

Expression results can also be passed to functions as parameters. However, since expression results are not referenced by a variable, there is no way that changes made to the parameter can be passed out from the function, unless it is returned by the function.

NG4.1 Home, Index, Examples, Glossary, Feedback, Ref Contents, Ref WhereAmI?