NCL Home > Documentation > Functions > Metadata routines

getvardims

Returns a list of dimension names for the given variable.

Prototype

	function getvardims (
		var       
	)

	return_val [*] :  string

Arguments

var

Any NCL variable.

Description

This function returns a list of dimension names for a given NCL variable. If a dimension is not named, then this function returns the default missing value for a string for that dimension.

This function can be used to retrieve the dimension names from a supported file that was opened with addfile or addfiles.

In NCL version 6.5.0, in order to make the various getvarxxxx and getfilexxxx function names more meaningful and consistent, we added a getvardimnames function that is an alias for this function.

If the dimension sizes are also desired, then getvardimsizes (alias for dimsizes) returns the dimension sizes in the same order as the dimension names returned from this function.

See Also

getvardimnames, getvardimsizes, getvaratts, dimsizes

Examples

Example 1

The following script:

  w = (/(/ (/1.,2.,3/), (/4.,5.,6./) /), (/ (/6.,5.,4/), (/3.,2.,1./) /)/)
  w!0 = "z"
  w!1 = "y"
  w!2 = "x"
  dimNames = getvardims(w)
; dimNames = getvardimnames(w)   ; use in NCL V6.5.0 or later
  print(dimNames)

will result the following output:

Variable: dimNames
Type: string                    
Total Size: 12 bytes
            3 values
Number of Dimensions: 1
Dimensions and sizes:   [3]
Coordinates: 
Number Of Attributes: 1
  _FillValue :  missing

(0)     z
(1)     y
(2)     x

Example 2

Assume you have a netCDF file where "ncdump -h 0360-01.nc" yields:

  netcdf 0360-01 {
  dimensions:
    time = UNLIMITED ; // (1 currently)
    nlon = 320 ;
    nlat = 384 ;
    z_t = 40 ;
    z_w = 40 ;
    tracers = 2 ;
    nchar = 80 ;
    d2 = 2 ;
    [SNIP]

To retrieve the dimension names from the file, you can use the following code snippet. In the following, the reference to the file (here, f) is also a variable. In NCL V6.5.0 you can use the equivalent function, getfiledimnames:

  f      = addfile ("0360-01.nc" , "r")
  dNames = getvardims(f)  
; dNames = getfiledimnames(f)     ; use in NCL V6.5.0 or later
  dSizes = getfiledimsizes(f)  
  print (dNames+"   "+dSizes)
This produces the output:
   time       1
   nlon     320
   nlat     384
   z_t       40
   z_w       40
   tracers    2
   nchar     80
   d2         2

Example 3

Retrieve the dimension names of a variable and use these returned names to reorder (reshape) the variable. Note from Example 1 that getvardims returns a variable of type "string". To use these "string" names for reordering, a variable string reference must be used. This is accomplished by enclosing a string with dollar signs ($).

   dims = getvardims(x)        ; dimension names
;  dims = getvardimnames(x)    ; use in NCL V6.5.0 or later
   rank = dimsizes(dims)
   if (rank.eq.3) then
       xNew = dim_rmvmean_Wrap($dims(1)$|:,$dims(2)$|:,$dims(0)$|:)
   end if

   if (rank.eq.4) then
       xNew = dim_rmvmean_Wrap($dims(1)$|:,$dims(2)$|:,$dims(3)$|:,$dims(0)$|:)
   end if

   printVarSummary(xNew)