netcdf

manual
Login

manual

Tcl netcdf library

netcdf - Tcl extension for reading and writing NetCDF files

SYNOPSIS

package require Tcl 8.5 9.0
package require netcdf 0.1
netcdf attribute subcommand arg ...
netcdf dataset subcommand arg ...
netcdf define subcommand arg ...
netcdf dimension subcommand arg ...
netcdf group subcommand arg ...
netcdf type subcommand arg ...
netcdf variable subcommand arg ...

DESCRIPTION

The netcdf command provides methods for reading and writing NetCDF files. Most methods operate on an ncid. There are three ways to obtain an ncid:
  • Opening a dataset with the netcdf dataset open or dataset data methods. The dataset ncid is actually equivalent to the ncid of the root group.
  • Finding the ncid for an existing group within an open dataset using the netcdf group ncid method.
  • Creating a new group using the netcdf define group method.

Methods that take attribute, dimension, or variable arguments will accept either a name or an index for these items.

For a type argument, valid values are: byte, char, double, float, int, int64, short, string, ubyte, uint, uint64, and ushort.

COMMANDS

netcdf attribute subcommand arg ...

Where subcommand is delete, get, list, rename, or type.

netcdf attribute delete ncid variable ?attribute?
Delete an attribute from a variable.
netcdf attribute get ncid variable ?attribute?
Retrieve the value of an attribute of a variable. If attribute is not specified, the command returns a dict of all attributes for that variable. To access global attributes, specify an empty string for variable.
netcdf attribute list ncid variable
List the names of all attributes for a variable. To access global attributes, specify an empty string for variable.
netcdf attribute rename ncid variable attribute newname
Change the name of an attribute. To access global attributes, specify an empty string for variable.
netcdf attribute type ncid variable attribute
Find the type of an attribute. To access global attributes, specify an empty string for variable.
netcdf dataset subcommand arg ...

Where subcommand is close, data, mode, or open.

netcdf dataset close ncid
Close an open netCDF dataset.
netcdf dataset data string ?access?
Open an in-memory dataset contained in string and return a channel identifier that may be used in future invocations of commands for accessing the dataset. String should normally be a byte array (such as that returned from reading a binary encoded channel). The access argument, if present, indicates the way in which the dataset is to be accessed. Access consists of a list of any of the following flags:
RDONLY
Open the dataset for reading only.
RDWR
Open the dataset for both reading and writing.
64BIT
Use 64-bit offset values to allow very large dataset files (over 2 GB).
NETCDF4
Create a netCDF-4/HDF5 file.
CDF5
Create a CDF-5 file.
CLASSIC
Enforce netCDF classic mode on netCDF-4/HDF5 files.
Access defaults to RDONLY.
netcdf dataset mode ncid ?mode?
Returns the current dataset mode. If mode is specified, then change the mode of the dataset. Valid modes are data and define. Pure netCDF4 datasets automatically switch between modes. For datasets in other formats, the dataset must be in define mode to be able to add or rename dimensions, variables, and attributes and delete attributes.
netcdf dataset open file ?access?
Open a netCDF file and return a channel identifier that may be used in future invocations of commands for accessing the dataset. The access argument, if present, indicates the way in which the dataset is to be accessed. Access consists of a list of any of the following flags:
RDONLY
Open the dataset for reading only.
RDWR
Open the dataset for both reading and writing.
CREAT
Create the dataset file if it does not already exist (without this flag it is an error for the file not to exist).
EXCL
If CREAT is also specified, an error is returned if the dataset file already exists.
SHARE
When one process may be writing the dataset and one or more other processes reading the dataset concurrently, the SHARE flag ensures that dataset accesses are not buffered and caching is limited.
PERSIST
Force DISKLESS data from memory to a file when the dataset is closed.
DISKLESS
Read the complete dataset into memory.
64BIT
Use 64-bit offset values to allow very large dataset files (over 2 GB).
NETCDF4
Create a netCDF-4/HDF5 file.
CDF5
Create a CDF-5 file.
CLASSIC
Enforce netCDF classic mode on netCDF-4/HDF5 files.
Access defaults to RDONLY.
netcdf define subcommand arg ...

Where subcommand is attribute, group, dimension, or variable.

netcdf define attribute ncid variable name type value ...
Define a new attribute for a variable.
netcdf define group ncid name
Define a new group within the dataset or another group. The command returns a channel identifier that may be used in future invocations of commands for accessing information related to the group.
netcdf define dimension ncid name ?length?
Define a new dimension. If the length argument is not specified, the dimension's length is unlimited. In a netCDF classic or 64-bit offset file, at most one dimension can have the unlimited length. In a netCDF-4 file multiple unlimited dimensions are supported.
netcdf define variable ncid name type ?dimensions? ?-option value ...?
Create a new variable within the dataset or a group. Dimensions is a list specifying the dimensions of the variable. If not specified or empty, the variable will be dimensionless.

The following options may also be present to specify additional information about the variable:

-checksum
Set whether to use a checksum for a variable. Valid values are: nochecksum and fletcher32. Checksums require chunked data. If checksums are switched on for a variable with contiguous data, then the data is changed to chunked data, with default chunksizes. Use the -chunked option to tune performance with user-defined chunksizes.
-chunked
Use chunked storage for the variable. The value must be a list specifying the chunk size to use for each dimension. Specifying an empty list switches off chunking.
-compact
Define whether to use compact storage. Compact storage means the variable is stored in the header record of the file. Compact storage is only available for variables whose data are 64 KB or less.
-deflate
Set the zlib compression level for the variable. Valid levels are 0 (no compression) through 9 (maximum compression). Deflate compression requires chunked data. If compression is switched on for a variable with contiguous data, then the data is changed to chunked data, with default chunksizes. Use the -chunked option to tune performance with user-defined chunksizes.
-endianness
Set the endianness of a variable. Valid values are: big, little, and native. By default, the endianness is the same as the default endianness of the platform.
-fillvalue
Set the fill value for a variable. The provided value must match the specified type. If not specified, a type-dependent default is used. If specified as the empty string, fill mode is turned off for this variable.
-quantize
Set the quantization for a variable. The value must be a list specifying the quantization mode, bitgroom, bitround, or granular, followed by the number of significant digits. These are binary digits for bitround quantization, and decimal digits for bitgroom and granular quantization. Pass an empty list to explicitly switch off quantization. none
-shuffle
Configure the shuffle filter. The shuffle filter can assist with the compression of data by changing the byte order in the data stream. If the -deflate option is not also specified, this will turn on deflate compression at the default level of 6.
-szip
Set szip compression on a variable. The value must be a list specifying the compression method, ec (entropy coding) or nn (nearest neighbor), followed by the number of pixels per block. Pixels per block must be even and not greater than 32, with typical values being 8, 10, 16, or 32. This parameter affects compression ratio; the more pixel values vary, the smaller this number should be to achieve better performance. If no value is provided for pixels per block, it defaults to 8. Pass an empty list to explicitly switch off szip compression.
netcdf dimension subcommand arg ...

Where subcommand is get, list, rename, or unlimited.

netcdf dimension get ncid ?dimension?
Find the length of a dimension. If dimension is not specified, returns a dict of dimension names and lengths. The length for an unlimited dimension, is the number of records written so far.
netcdf dimension list ncid
Get a list of existing dimension names.
netcdf dimension rename ncid dimension newname
Change a dimension name.
netcdf dimension unlimited ncid
Return a list of unlimited dimensions.
netcdf group subcommand arg ...

Where subcommand is fullname, info, list, open, parent, or rename.

netcdf group fullname ncid
Get the full path name of a group.
netcdf group info ncid ?option?
Provide information about a group. The following options are available:
attributes
The number of global attributes of the group.
dimensions
The number of dimensions accessible to the group. This includes dimensions accessible to the parent group.
groups
The number of subgroups of the group.
unlimited
A list of dimensions with unlimited length.
variables
The number of variables in the group.
netcdf group list ncid
List the groups within a dataset or other group.
netcdf group name ncid
Get the name of a group, based on its handle.
netcdf group open ncid name
Get the handle for a named group. The name may be specified as a relative path by specifying the ncid of the parent group, or as a full path, in which case the ncid of the dataset must be used.
netcdf group parent ncid
Get the ID of the parent group.
netcdf group rename ncid newname
Change the name of a group.
netcdf type subcommand arg ...

Where subcommand is compound, enum, opaque, or vlen.

netcdf type compound ncid name struct
Create a user-defined compound type. The struct argument must be a dict mapping field names to a type. The type name may be followed by one ore more comma separated numbers in parentheses to specify an array with the indicated dimesnions.
netcdf type enum ncid name type map
Create a user-defined enum type. The type argument must be one of: byte, ubyte, short, ushort, int, uint, int64, uint64. The map argument must be a dict mapping integers to labels.
netcdf type opaque ncid name size
Create a user-defined opaque type. The size argument specifies the size of each opaque object in bytes.
netcdf type vlen ncid name type
Create a user-defined variable length array type. Type specifies the type of the array elements,
netcdf variable subcommand arg ...

Where subcommand is get, info, list, lset, rename, or set.

netcdf variable get ncid variable ?start? ?count? ?stride?
Read one or more values from a variable. The start, count, and stride arguments can be used to specify a Hyperslab. Start is a list specifying the start vector with one element for each dimension. Count is a list specifying the count vector with one element for each dimension. Stride is a list specifying the stride vector with one element for each dimension. If none of the optional arguments are specified, the command returns all values of the variable. I.e, for each dimension start is 0, count is each dimension's length, and stride is 1. In contrast, if only start is specified, count is 1 for each dimension. This results in a single value being returned.

Whenever multiple values are requested, they are returned as a nested list with the number of nesting levels equal to the number of dimensions of the variable. Missing values (actually values equal to the fill value) are represented by empty list elements.

netcdf variable info ncid variable ?option?
Get low-level information about a variable. The following options are available:
checksum
The checksum settings for the variable. Either fletcher32 or nochecksum.
deflate
The deflation level of the variable. 0 means no compression.
dimensions
A list with the dimensions of the variable.
endianness
The endianness of a variable. Either little, big, or native.
fill
The fill value for the variable.
id
The variable's ID.
name
The name of the variable.
storage
The type of storage for the variable. Either contiguous, chunked, or compact.
shuffle
Indicates whether the shuffle filter is on.
type
The type of the variable.
netcdf variable list ncid variable
Get a list of names of existing variables.
netcdf variable lset ncid variable index ?stride? values
Store multiple values into a variable. Index is a list with one element for each dimension, forming an index vector pointing at the first slot to be filled. If provided, stride must be a list with one element per dimension, specifying the amount with which the index will be incremented for each subsequent value in the corresponding dimension. Values must be a nested list with one level for each dimension. Empty list elements set the corresponding slot to the fill value.
netcdf variable rename ncid variable newname
Change the name of a variable.
netcdf variable set ncid variable index ?value?
Store a single value into a variable. Index is a list with one element for each dimension, forming an index vector pointing at the slot to be changed. If no value is specified, the slot is set to the fill value. In this situation an error is thrown if fill mode is turned off for the variable.

COPYRIGHT

Copyright © 2025 Schelte Bron