Dimensions define the shape and size of a variable. A variable can have up to 32 dimensions, and they can be any size. Variable dimensions can also have names.
The variable dimension names are referenced using the "!" character following the variable name, and variable dimension numbers start at 0. So, for example, the first dimension name of a variable called t is referenced in NCL as t!0, the second dimension name as t!1, and the third dimension name as t!2. The ordering of the dimensions of a variable reflect the ordering of the data in row/column order.
For example, if we create a variable, t, with three dimensions of size 31, 40, and 50, that contains temperature data for a 31 day period, then the first dimension might be named "day", the second dimension "lat", and the third dimension "lon".
t = new(/31, 40, 50/), float) t!0 = "day" t!1 = "lat" t!2 = "lon"The dimension sizes of a variable are referenced using the dimsizes function as shown in the following example. The dimension sizes are stored in the variable n, and then printed with the print statement.
n = dimsizes (t) print(n)Data files can store named dimensions that are used by file variables. A file's dimensions are the dimension names and sizes that are stored in the file and used by data variables in the file. For example, a data file called file1 could have four dimensions named lat, lon, day, and year, and two variables called t and p. The t and p variables use the file's dimensions to define their shapes and sizes.
The file dimension names are referenced using the "!" symbol: file1!0, file1!1, file1!2, and file1!3. The order of a file's dimensions does not reflect any type of data ordering. The order only represents the order in which the dimensions were defined.
The following NCL example would read a netCDF file called file1.cdf and print out the first two dimension names defined in the file.
file1 = addfile ("file1.cdf", "r") dim1=file1!0 dim2=file1!1 print(dim1) print(dim2)The size of the dimensions, as well as lists of all the variables, dimensions, coordinates, and attributes in a file, can be seen by printing the file.
NG4.1 Home, Index, Examples, Glossary, Feedback, UG Contents, UG WhereAmI?