NCL Website header
NCL Home > Documentation > Functions > Metadata routines


Returns a list of attribute names on the given file.

Available in version 6.5.0 and later.


	function getvaratts (
		thefile  : file   

	return_val [*] :  string



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.


This function returns a list of global attribute names on a given supported file that was opened with addfile or addfiles.

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

This function an alias for getvaratts. It was created for consistency and meaningfulness with other getfilexxxx functions. See the NCL file I/O list for a full list of functions and procedures associated with file input/output.

See Also

Functions marked with * indicate ones added in NCL V6.5.0.

addfile, addfiles, getfiledimsizes, getfiledimnames, getfilevarnames, getfilevardimsizes, getfilevardimnames, getfilevaratts, getfilevartypes, getvaratts


Example 1

Assume you have a netCDF file where "ncdump -h" yields:

 file global attributes:
   title : U,V,T: January 1988
   source : Climate Analysis Section, NCAR
   history : Dataset uvt.hs from EZPLOT demo dataset
   Conventions : None
   creation_date : Wed Jun  2 09:39:22 MDT 1999
   references : 

To retrieve the global attributes on the file, you can use the following code snippet:

  f      = addfile ("" , "r")
  fAtts = getfileatts(f)       ; NCL V6.5.0 and later
; fAtts = getvaratts(f)        ; NCL V6.4.0 and earlier
  print (fAtts)
This produces the output:
(0)     title
(1)     source
(2)     history
(3)     Conventions
(4)     creation_date
(5)     references

Example 2

To print the value of each global attribute on a file, use a "do" loop. You must use the special $...$ syntax when accessing the attribute value using a variable name that contains the attribute name:

  f      = addfile ("" , "r")
  fAtts = getfileatts(f)       ; NCL V6.5.0 and later

  do na=0,dimsizes(fAtts)-1
    print ("f@" + fAtts(na) + " = " + f@$fAtts(na)$)
  end do
This produces the output:
  (0)    fAtts@title = U,V,T: January 1988
  (0)    fAtts@source = Climate Analysis Section, NCAR
  (0)    fAtts@history = Dataset uvt.hs from EZPLOT demo dataset
  (0)    fAtts@Conventions = None
  (0)    fAtts@creation_date = Wed Jun  2 09:39:22 MDT 1999
  (0)    fAtts@references = 
EZPLOT for Publication Quality Plots
Christian Guillemot
NCAR-TN 414   1995
Note the "references" attribute consists of several lines.

Example 3

Consider a list of WRF output files starting with the prefix "wrfout_d01_2008-09". To retrieve the file attributes 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")

(0)     TITLE
(1)     START_DATE
. . .
(73)    ISWATER
(74)    ISLAKE
(75)    ISICE
(76)    ISURBAN