NCL Website header
NCL Home > Documentation > Functions > File I/O

getfiledimsizes

Returns an array of dimension sizes on the given file.

Prototype

	function getfiledimsizes (
		thefile [1] : file   
	)

	return_val [*] :  integer or long

Arguments

thefile

A reference to a file created from a call to addfile or addfiles. The file referenced must be one in the supported file format list.

Description

This function returns a list of dimension sizes for the given file opened with addfile or addfiles. It will return type "long" if any of the individual file dimension sizes is greater than or equal to 2 GB.

Note: since addfiles returns a variable of type "list", you must subscript the list before calling this function. See the examples below.

If the dimension names are also desired, then getfiledimnames returns the dimension names in the same order.

See Also

getfileatts, getfiledims, getfiledimnames, getfilepath, addfile, addfiles

Examples

Example 1

Consider a netCDF file where "ncdump -h Tstorm.nc" yields:

netcdf Tstorm {
dimensions:
        timestep = 64 ;
        lat = 33 ;
        lon = 36 ;
        timelen = 20 ;
variables:
        float t(timestep, lat, lon) ;
                t:_FillValue = -9999.f ;
        int timestep(timestep) ;
        float lat(lat) ;
        float lon(lon) ;
        char reftime(timelen) ;
                reftime:units = "text_time" ;
                reftime:long_name = "reference time" ;
}
To retrieve the sizes of named dimensions in the file, you can use the following code snippet:

   f      = addfile ("$NCARG_ROOT/lib/ncarg/data/cdf/Tstorm.cdf" , "r")
   dSizes = getfiledimsizes(f)  
   print (dSizes)
This produces the output:

Variable: dSizes
Type: integer
Total Size: 16 bytes
            4 values
Number of Dimensions: 1
Dimensions and sizes:   [4]
Coordinates: 
(0)     64
(1)     33
(2)     36
(3)     20
Additionally, if the associated dimension names are desired, getfiledimnames returns the dimension names in the same order as the dimension sizes returned by getfiledimsizes:

   dSizes = getfiledimsizes(f)  
   dNames = getfiledimnames(f)   ; NCL V6.5.0 or later
;  dNames = getvardims(f)        ; NCL V6.4.0 or earlier
   print(dSizes+"   "+dNames)

Output:

(0)     64   timestep
(1)     33   lat
(2)     36   lon
(3)     20   timelen

Example 2

Consider a list of WRF output files starting with the prefix "wrfout_d01_2008-09". To retrieve the dimension sizes and names associated with one of the files, you must subscript the list variable returned by addfiles:

  wrf_files = systemfunc("ls wrfout_d01_2008-09*")
  f = addfiles(wrf_files+".nc","r")
  print(getfiledimsizes(f[0]) + " : " + getfiledimnames(f[0]))    ; NCL V6.5.0 or later

; print(getfiledimsizes(f[0]) + " : " + getvardims(f[0]))    ; NCL V6.4.0 or earlier

Output:

(0)     1 : Time
(1)     19 : DateStrLen
(2)     206 : west_east
(3)     197 : south_north
(4)     32 : bottom_top
(5)     33 : bottom_top_stag
(6)     5 : soil_layers_stag
(7)     207 : west_east_stag
(8)     8 : force_layers
(9)     198 : south_north_stag