6.14 Define Endianness of a Variable: nc_def_var_endian
The function nc_def_var_endian sets the endianness for a variable in a
netCDF-4 file.
This function must be called after the variable is defined, but before
nc_enddef is called.
By default, netCDF-4 variables are in native endianness. That is, they
are big-endian on a big-endian machine, and little-endian on a little
endian machine.
In some cases a user might wish to change from native endianness to
either big or little-endianness. This function allows them to do that.
Usage
nc_def_var_endian(int ncid, int varid, int endian);
ncid- NetCDF ID, from a previous call to nc_open or nc_create.
varid- Variable ID.
endian- Set to NC_ENDIAN_NATIVE for native endianness. (This is the
default). Set to NC_ENDIAN_LITTLE for little endian, or NC_ENDIAN_BIG
for big endian.
Errors
nc_def_var_endian returns the value NC_NOERR if no errors
occurred. Otherwise, the returned status indicates an error.
Possible return codes include:
NC_NOERR- No error.
NC_BADID- Bad ncid.
NC_ENOTNC4- Not a netCDF-4 file.
NC_ENOTVAR- Can't find this variable.
NC_ELATEDEF- This variable has already been the subject of a nc_enddef call. In
netCDF-4 files nc_enddef will be called automatically for any data
read or write. Once enddef has been called, it is impossible to set
the endianness of a variable.
NC_ENOTINDEFINE- Not in define mode. This is returned for netCDF classic or 64-bit
offset files, or for netCDF-4 files, when they were been created with
NC_STRICT_NC3 flag, and the file is not in define mode. (see nc_create).
NC_EPERM- Attempt to create object in read-only file.
Example