NCL variables overview

Variable names must begin with an alphabetic character, but they can contain any mix of numbers and alphabetic characters. The underscore ('_') is also allowed. Variable names are also case sensitive. The maximum variable name length is currently 256 characters. Variables reference arrays of multi-dimensional data. These data can be described by variable attributes, named dimensions, and coordinate variables. Variables can also reference files and graphical objects.

The following are examples of unique variable names:

	a
	A
	forecast_time
	s092389
	__t__

Variables can be created by the assignment statement, or by the new statement.

Creating variables

Variables of all numeric data types, strings, characters, and logical and graphical types can be created using the new intrinsic statement. There are two types of new calls, one that creates the array of data with a specific missing value assigned to each element, and one that creates the array of data using the default missing value. The new statement takes, as parameters, an array of dimension sizes, the keyword representing the type to create, and optionally a missing value to assign to each element of the new data array. The following creates a three-dimensional float array:
        a = new((/5,6,7/),float)

The following is an example of how to assign a specific missing value:

        a = new((/5,6,7/),float,-1e12)

File data types are created differently. Files are only created by the intrinsic addfile. Arrays of type graphic can be created with new, but none of the elements of the array will actually reference an existing HLU object. Each element will contain a missing value.

Attributes

Attributes are descriptive pieces of information that can be associated with an already existing variable, file, or file variable. Attributes can be assigned single-dimensioned arrays or strings, but not files or graphical objects. Variable attributes are referenced by entering the variable name, followed by '@', followed by the name to be used to reference the attribute. If the attribute is not defined, then an error message is displayed. An attribute is created by referencing it on the left side of an assignment statement and assigning a value to it. The following is an example of creating the attributes units, long_name, and _FillValue in the variable named temperature:
	temperature@units = "Degrees C"
	temperature@long_name = "Temperature at Tropopause"
	temperature@_FillValue = -9999.0
	temperature@scale_factors = (/ .233, .452, .434, .621 /)

Attributes can be treated just like variables. They can be used in expressions and subscripted in the same fashion as variables. The attribute _FillValue is a special reserved attribute name that denotes what values in the variable are missing or filled values. Missing values are significant when evaluating expressions. In the above examples, if the attributes were already defined, they are reassigned the new value. In the case of the _FillValue attribute, every occurrence of the previous value in the variable temperature is replaced with the new _FillValue. The _FillValue attribute must be the same type as the data type referenced by the variable.

Dimensions

Dimensions define the shape and size of the data referenced by variables. In NCL, dimensions are ordered using row x column ordering which is identical to the C programming language. By convention, dimensions are numbered from 0 to n-1 where n is the number of dimensions of the data referenced. The dimension numbers are significant because NCL allows names to be associated with dimensions. This in turn facilitates coordinate subscripting. A variable dimension is referenced by entering the variable name, followed by the '!' character, followed by the dimension number being referenced. If the dimension has been assigned a name, then this reference returns the name. To assign or change a name to a dimension, simply assign a string to the dimension number in the following fashion:
	temperature!0 = "frtime"
	temperature!1 = "lat"
	temperature!2 = "lon"
The previous example is valid only if temperature has three or more dimensions.

Coordinate variables

Coordinate variables are single-dimension arrays that have the same name and size as their dimension. Additionally, the values in these arrays must be monotonically increasing or decreasing. Non-monotonic values can be assigned, but coordinate subscripting will not work. When a non-monotonic array is assigned, a warning message is printed. These arrays represent the data coordinates for each index in the named dimension. Coordinate variables support the concept of coordinate subscripting. The '&' operator is used to reference and assign coordinate variables. In order to assign a coordinate variable to a dimension, the dimension must have a name. These examples show assignment of variables to coordinate variables:
	temperature&frtime = forecast_times
	temperature&lat = lat_points
	temperature&lon = lon_points

Subscripts

There are three types of subscripting in NCL. Standard is similar to the array subscripting available in FORTRAN 90. One very important item to note is that NCL dimension indexes start at 0 and end at n-1. Second, coordinate subscripting uses the data in the coordinate variables for determining subsections of the array to select. Third, named subscripting uses the names of the dimensions to allow for array reordering operations.

Files and file variables

It is very important to understand the distinction between a variable that references a file and a file variable. When a file is opened with the addfile command, a reference to the file is assigned to a variable. The type of the variable's data type is file. This variable is a variable that references a file. On the other hand, a file variable is a variable that is contained within a file.

Variables that reference files have a few special exceptions. First, dimension names and numbers do not represent the shape of the file variable; they are the dimensions used by the variables stored in the file. Coordinate variables are handled similarly. Attributes, coordinate variables, and dimension names, when assigned to a variable referencing a file, are written into the file rather than saved in memory as with normal variables.

Furthermore, when a variable references a file, the '->' operator is used to select variables stored in the file.

	file->variable1
The above demonstrates referencing the file variable name variable1 in the file reference by the variable file. This type of referencing can occur either on the left or the right side of an assignment. However, if on the left side, the file must be opened with write permissions.

File variables can be operated on and subscripted in the exact same fashion that standard variables can be with the '!', '&' and '@' operators. Dimensions and coordinate variables are not unique to individual file variables; they are shared by all variables in the file with the same dimensions. This means that adding or modifying dimension names and coordinate variables for one file variable changes them for all variables with the same dimension.

Variables that reference files are created by the addfile intrinsic function.


Reference Manual Control Panel

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


$Revision: 1.10 $ $Date: 1995/07/26 23:31:33 $