NCL Home >
Documentation >
Functions >
File IO
getfilevarnames
Returns an array of file variable names in the specified supported file.
Prototype
function getfilevarnames ( the_file [1] : file ) return_val [*] : string
Arguments
the_filereference to a file. It is created using addfile or addfiles. Thus, it must be a supported file format.
Return value
This function returns an array of strings with each element containing the name of a variable. The length of this array is equal to the number of variables in the file.
Description
This function is useful when accessing file variables by string name. (See Files.)
Examples
The following example gets all the variables names from a netCDF file but it will also work for any file referenced by addfile. The dollar sign syntax used in this example is described at "NCL Variables".
f = addfile ("X.nc" , "r") ; could also have ccm, grb or hdf suffux
vNames = getfilevarnames (f) ; get names of all variables on file
nNames = dimsizes (vNames) ; number of variables on the file
print (vNames) ; print all variable names on file
do n=0,nNames-1 ; loop thru each variable
v = f->$vNames(n)$ ; read the varible to memory
dimv = dimsizes(v) ; dimension size of the variable
rank = dimsizes(dimv) ; rank [ie: number of dimensions]
[SNIP]
delete (v)
delete (rank)
end do