Next: , Previous: CDL Notation for Data Constants, Up: NetCDF Utilities


5.4 ncgen

The ncgen tool generates a netCDF file or a C or FORTRAN program that creates a netCDF dataset. If no options are specified in invoking ncgen, the program merely checks the syntax of the CDL input, producing error messages for any violations of CDL syntax.

UNIX syntax for invoking ncgen:

     ncgen [-b] [-o netcdf-file] [-c] [-f] [-k kind] [-x] [input-file]

where:

-b
Create a (binary) netCDF file. If the '-o' option is absent, a default file name will be constructed from the netCDF name (specified after the netcdf keyword in the input) by appending the '.nc' extension. Warning: if a file already exists with the specified name it will be overwritten.
-o netcdf-file
Name for the netCDF file created. If this option is specified, it implies the '-b' option. (This option is necessary because netCDF files are direct-access files created with seek calls, and hence cannot be written to standard output.)
-c
Generate C source code that will create a netCDF dataset matching the netCDF specification. The C source code is written to standard output. This is only useful for relatively small CDL files, since all the data is included in variable initializations in the generated program.
-f
Generate FORTRAN source code that will create a netCDF dataset matching the netCDF specification. The FORTRAN source code is written to standard output. This is only useful for relatively small CDL files, since all the data is included in variable initializations in the generated program.
-k kind
The generated netCDF file or program will be of the specified kind, one of “classic”, “64-bit-offset”, “hdf5”, or “hdf5-nc3”. The default kind is “classic”, the original variant of the netCDF file format with 32-bit offsets, limiting file sizes in most cases to 2 GiB or less. The kind “64-bit-offset” specifies the second version of the file format with 64-bit offsets, to allow for the creation of very large files. These files are not as portable as classic format netCDF files, because they require version 3.6.0 or later of the netCDF library. Specifying “hdf5” will produce a file using the netCDF-4 programming interfaces (not yet implemented), and is required if the CDL input includes features of the netCDF-4 data model, such as Groups or compound types. Specifying “hdf5-nc3” will create an HDF5 file using the netCDF-4 interfaces (not yet implemented), but restricted to the netCDF-3 data model, so that the file can be accessed and manipulated by unmodified netCDF-2 or netCDF-3 programs and utilities that have been relinked with the netCDF-4 library. These four kinds of files may also be specified numerically using “1”, “2”, “3”, or “4”, respectively. For backward comapatibility, `-v kind' is also accepted.
-x
Use “no fill” mode, omitting the initialization of variable values with fill values. This can make the creation of large files much faster, but it will also eliminate the possibility of detecting the inadvertent reading of values that haven't been written.

Examples

Check the syntax of the CDL file foo.cdl:

     ncgen foo.cdl

From the CDL file foo.cdl, generate an equivalent binary netCDF file named bar.nc:

     ncgen -o bar.nc foo.cdl

From the CDL file foo.cdl, generate a C program containing netCDF function invocations that will create an equivalent binary netCDF dataset:

     ncgen -c foo.cdl > foo.c