2012 Unidata NetCDF Workshop > NetCDF-4 Programming
16.1 Backward Compatibility
Backward compatibility was the first requirement of the netCDF-4 project.
To create netCDF files using different format variants:
- Create a classic netCDF file
nc_create("file.nc", 0, &ncid);
- Create a (classic) 64-bit offset netCDF file
nc_create("file.nc", NC_64BIT_OFFSET, &ncid);
- Create a netCDF-4 file (a kind of HDF5 file)
nc_create("file.nc", NC_NETCDF4, &ncid);
- Create a netCDF-4 classic model file (a netCDF-4 file with restrictions)
nc_create("file.nc", NC_NETCDF4 | NC_CLASSIC_MODEL, &ncid);
Classic binary format is still the default output
format. NetCDF-4 files must be specified
at create-time. If netCDF-4 allows multiple unlimited
dimensions (for example), how to ensure code
compatibility in all cases?
- to provide same behavior in existing code, netCDF-4 files can be
created with a special flag: NC_CLASSIC_MODEL
- This is a backward compatibility flag that restricts
what is allowed in the file.
- An attempt to (for example) create two
unlimited dimensions in such a file will result in a error, just as
with classic format.
- NetCDF-4 files produced without this flag can have any number of
unlimited dimensions.
- You don't need the NC_CLASSIC_MODEL
flag for code compatibility, it just makes netCDF-4 more strict to
ensure compatibility, producingor example same error when you try to define
multiple unlimited dimensions
- The data format is still HDF5, and no different
from the same file created without
CLASSIC_MODEL, except the
CLASSIC_MODEL file will always reject any
enhanced model feature, such as groups, user-defined types, and
other new features.
2012 Unidata NetCDF Workshop > NetCDF-4 Programming