Output to netCDFThis page shows various ways you can write data to a netCDF file. There are four types of NetCDF files currently supported by NCL: classic, 64-bit offset, netCDF-4 classic, and netCDF-4. See the NetCDF FAQ for more information.
If you have a newer version of NetCDF installed on your system, you can use "ncdump -k" to determine the type of NetCDF file you have. It will output either "classic", "64-bit offset", or "netCDF-4" for the various types of NetCDF files.
Some of the examples below make use of the setfileoption procedure for setting options before you write to a file.
NetCDF-3, NetCDF-3 64-bit offset, NetCDF-4 classic
For NetCDF-3, 64-bit offset, and NetCDF-4 classic files, there are two ways to write the data.
Method 1 - possibly inefficient, but simple to use.
- Sends the data to the output file without any file predefinition
- Speed depends on number of variables, dimension sizes of variables, presence of an UNLIMITED dimension etc
Method 2 - more efficient method, can be faster, but requires more coding. Recommended for large files and/or files with lots of variables.
- Enter "Define Mode" prior to predefining file contents
- User explicitly predefines the coordinate variables of the output file, the dimension sizes of the output variables, and optionally, the attributes of the output variables.
Available in version 6.1.1 and later.
Since support for NetCDF-4 files is in beta-testing for V6.1.1, we encourage people to test it out and give us feedback on our ncl-talk email list.
Here are some examples on creating NetCDF-4 files: