High-level interface
Getting information
#
NetCDF.ncinfo
— Function
ncinfo(filename)
prints information on the variables, dimension and attributes conatained in the file
Reading data
#
NetCDF.ncread
— Function
ncread(filename, varname)
reads the values of the variable varname
from file filename
and returns the values in an array.
Keyword arguments
-
start
Vector of lengthndim(v)
setting the starting index for each dimension -
count
Vector of lengthndim(v)
setting the count of values to be read along each dimension. The value -1 is treated as a special case to read all values along the dimension
Example
To read the second slice of a 3D NetCDF variable, you can write:
ncread("filename","varname", start=[1,1,2], count = [-1,-1,1])
#
NetCDF.ncread!
— Function
ncread!(filename, varname, d)
reads the values of the variable varname from file filename and writes the results to the pre-allocated array d
Keyword arguments
-
start
Vector of lengthndim(v)
setting the starting index for each dimension -
count
Vector of lengthndim(v)
setting the count of values to be read along each dimension. The value -1 is treated as a special case to read all values from this dimension
Example
To read the second slice of a 3D NetCDF variable one can write:
d = zeros(10,10,1) ncread!("filename","varname", d, start=[1,1,2], count = [-1,-1,1])
Writing data
#
NetCDF.ncwrite
— Function
ncwrite(x::Array,fil::AbstractString,vname::AbstractString)
Writes the array x
to the file fil
and variable vname
.
Keyword arguments
-
start
Vector of lengthndim(v)
setting the starting index for writing for each dimension -
count
Vector of lengthndim(v)
setting the count of values to be written along each dimension. The value -1 is treated as a special case to write all values along the dimension. This is usually inferred by the given array size.
Reading attributes
#
NetCDF.ncgetatt
— Function
ncgetatt(filename, varname, attname)
This reads a NetCDF attribute attname
from the specified file and variable. To read global attributes, set varname to Global
.
Writing attributes
#
NetCDF.ncputatt
— Function
ncputatt(nc::String,varname::String,atts::Dict)
Writes the attributes defined in atts
to the variable varname
for the given NetCDF file name nc
. Existing attributes are overwritten. If varname is not a valid variable name, a global attribute will be written.
Creating files
#
NetCDF.nccreate
— Function
nccreate (filename, varname, dimensions ...)
Creates a variable in an existing NetCDF file or generates a new file. filename
and varname
are strings. After that follows a list of dimensions. Each dimension entry starts with a dimension name (a String), and may be followed by a dimension length, an array with dimension values or a Dict containing dimension attributes. Then the next dimension is entered and so on. Have a look at examples/high.jl for an example use.
Keyword arguments
-
atts Dict of attribute names and values to be assigned to the variable created
-
gatts Dict of attribute names and values to be written as global attributes
-
compress Integer [0..9] setting the compression level of the file, only valid if
mode=NC_NETCDF4
-
t variable type, currently supported types are: const
NC_BYTE
,NC_CHAR
,NC_SHORT
,NC_INT
,NC_FLOAT
,NC_LONG
,NC_DOUBLE
-
mode file creation mode, only valid when new file is created, choose one of:
NC_NETCDF4
,NC_CLASSIC_MODEL
,NC_64BIT_OFFSET