Attributes
The NetCDF dataset (as returned by NCDataset
or NetCDF groups) and the NetCDF variables (as returned by getindex
, variable
or defVar
) have the field attrib
which has the type NCDatasets.Attributes
and behaves like a julia dictionary.
Base.getindex
— Methodgetindex(a::Attributes,name::SymbolOrString)
Return the value of the attribute called name
from the attribute list a
. Generally the attributes are loaded by indexing, for example:
ds = NCDataset("file.nc")
-title = ds.attrib["title"]
Base.setindex!
— MethodBase.setindex!(a::Attributes,data,name::SymbolOrString)
Set the attribute called name
to the value data
in the attribute list a
. data
can be a vector or a scalar. A scalar is handeld as a vector with one element in the NetCDF data model.
Generally the attributes are defined by indexing, for example:
ds = NCDataset("file.nc","c")
+title = ds.attrib["title"]
Base.setindex!
— MethodBase.setindex!(a::Attributes,data,name::SymbolOrString)
Set the attribute called name
to the value data
in the attribute list a
. data
can be a vector or a scalar. A scalar is handeld as a vector with one element in the NetCDF data model.
Generally the attributes are defined by indexing, for example:
ds = NCDataset("file.nc","c")
ds.attrib["title"] = "my title"
close(ds)
If data
is a string, then attribute is saved as a list of NetCDF characters (NC_CHAR
) with the appropriate length. To save the attribute as a string (NC_STRING
) you can use the following:
ds = NCDataset("file.nc","c")
ds.attrib["title"] = ["my title"]
-close(ds)
Base.keys
— MethodBase.keys(a::Attributes)
Return a list of the names of all attributes.
Base.delete!
— MethodBase.delete!(a::Attributes, name)
Delete the attribute name
from the attribute list a
.
Loading all attributes as a Dict
can be achieved by passing ds.attrib
(where ds
is the NCDataset
) as argument to Dict
.
using NCDatasets
+close(ds)