NCL variables are symbolic representations of multidimensional arrays. Scalar variables are represented as a single dimension array of size 1. Variables can have any of the following types: float, double, short, long, integer, byte, character, or string.
Variable names are case sensitive and must begin with a letter or an underscore '_'. Any combination of characters and numbers can make up the rest of the name. The maximum length of a variable name is 256 characters.
File variables are stored in an external file and are referenced using a file record. File records contain pointers to file variables in an external file and metadata information, such as coordinate variables, dimension definitions, and attributes. Attributes, coordinate variables, and dimension names, when assigned to a file variable, are automatically written into the file when write permissions are available.
In-memory variables, on the other hand, are variables that are dynamically created using the "new" operation and assignment statements; they are not read from an external file. Attributes, coordinate variables, dimension names, etc. are assigned using NCL statements.
File variables are operated on and subscripted in the same way as in-memory variables using 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 dimension names. This means that adding or modifying dimensions and coordinate variables for one file variable may change the dimensions and coordinates for all the variables in the file.
For example, if memvar is a two-dimensional float in-memory variable, and filevar is a file record that references an external file that contains a file variable called precip, then you could reference the dimensions in the following fashion:
; Assign a name to the first dimension of the memvar variable. memvar!0 = "latitude" ; Assign a name to the first dimension defined in the file ; referenced by filevar. filevar!0 = "latitude"To reference a variable that is stored in an external file, the '->' operator must be used.
; Assign a name to the first dimension of the precip variable ; that is stored in the external file. filevar->precip!0 = "latitude"Note that when file variables are changed, the external file is automatically and immediately updated if the file was opened with write permission.
var_1 = 5A float variable is created by adding a decimal point to the value, and string variables are created by enclosing the value in quotes.
var_2 = 5.894 var_3 = "This is a string variable"Logical variables are created by using the keywords "True" and "False".
var_4 = TrueTo create variables of type double, long, short, byte, and character, you can use the intrinsic operation called "new". The "new" operation takes two required arguments to specify the dimensions and type, and one optional argument to specify the missing or fill value in a variable.
new ( dimension_array, type, optional_missing_value )dimension_array is an array argument of dimension sizes such as:
optional_missing_value is the fill value that each element is assigned to in your variable array.
The following NCL commands create variables of various dimensions and types.
;var1 is a three-dimensional float variable of size 22x33x44. var1 = new((/22, 33, 44/), float) ;var2 is a scalar byte variable. var2 = new ((1), byte) ;var3 is a single dimensioned integer variable of size 100. ;The elements in this array will all be pre-assigned the value of -999. var3= new ((100), integer, -999)
delete(var1)File variables are a special type of variable and can not be deleted using the delete procedure. This is primarily because the netCDF and HDF formats do not allow the deletion of variable in a file. One way to accomplish this is to create another file and only assign the variable you would like to it leaving out the ones you wish to delete.
So, for example, if you have a two-dimensional temperature variable that contains data that is mapped over an area defined in terms of latitude and longitude, two coordinate variables (one-dimensional arrays) would define the latitude and longitude points of the data. One coordinate variable would define all the latitude points of the temperature data, and one coordinate variable would define all the longitude points. The sizes and names of these variables would be equal to the sizes of their corresponding dimensions.
The values in a coordinate variable array must be monotonically increasing or decreasing. For example, the following are valid coordinate arrays:
For example, the following NCL statements assign two coordinate variables to a temperature variable.
; create the temperature variable ( a 5x4 array of data) temp = new((/5,4/), float) ; assign dimension names temp!0 = "lon" temp!1 = "lat" ; initialize the values in the coordinate arrays lon_coordinates = (/-90, -85, -80, -75, -70/) lat_coordinates = (/0, 20, 40, 60/) ; assign the coordinate arrays to the variable ; Note that the coordinate variables must have the same name and ; size as their corresponding dimension. temp&lon = lon_coordinates temp&lat = lat_coordinates
NG4.1 Home, Index, Examples, Glossary, Feedback, UG Contents, UG WhereAmI?