NEP 4.3.0
NetCDF Expansion Pack
Loading...
Searching...
No Matches
nep.h File Reference

NetCDF Expansion Pack (NEP) - Public API. More...

#include <stdio.h>
#include <stdint.h>
#include <netcdf.h>
#include <netcdf_filter.h>

Go to the source code of this file.

Macros

#define NEP_HAVE_NATIVE_BFLOAT16   0
#define NEP_HAVE_NATIVE_FLOAT16   0
#define NEP_UDF_GEOTIFF_BIGTIFF   NC_UDF0
#define NEP_UDF_GEOTIFF_STANDARD   NC_UDF1
#define NEP_UDF_GRIB2   NC_UDF2
#define NEP_UDF_CDF   NC_UDF4
#define NEP_UDF_FITS   NC_UDF3
#define NEP_UDF_PDS4   NC_UDF5
#define NEP_UDF_DICOM   NC_UDF6
#define NEP_UDF_PDB   NC_UDF7
#define NEP_UDF_MMCIF   NC_UDF8
#define NEP_UDF_NXCDF   NC_UDF9
#define NEP_MAGIC_GEOTIFF_STANDARD   "II*"
#define NEP_MAGIC_GEOTIFF_BIGTIFF   "II+"
#define NEP_MAGIC_CDF   "\xCD\xF3\x00\x01"
#define NEP_MAGIC_GRIB2   "GRIB"
#define NEP_MAGIC_FITS   "SIMPLE"
#define NEP_MAGIC_PDS4   "<?xml"
#define NEP_MAGIC_DICOM   "DICM"
#define NEP_MAGIC_PDB   "HEADER"
#define NEP_MAGIC_MMCIF   "data_"
#define NEP_FORMAT_NAME_GEOTIFF   "GeoTIFF"
#define NEP_FORMAT_NAME_CDF   "NASA CDF"
#define NEP_FORMAT_NAME_GRIB2   "GRIB2"
#define NEP_FORMAT_NAME_FITS   "FITS"
#define NEP_FORMAT_NAME_PDS4   "PDS4"
#define NEP_FORMAT_NAME_DICOM   "DICOM"
#define NEP_FORMAT_NAME_PDB   "PDB"
#define NEP_FORMAT_NAME_MMCIF   "mmCIF"

Typedefs

typedef uint16_t nc_bfloat16_t
typedef uint16_t nc_float16_t

Functions

int nep_set_log_level (int new_level)
int nc_get_var1_bfloat16 (int ncid, int varid, const size_t *indexp, nc_bfloat16_t *ip)
 Read one value from a variable as bfloat16.
int nc_put_var1_bfloat16 (int ncid, int varid, const size_t *indexp, const nc_bfloat16_t *op)
 Write one value to a variable as bfloat16.
int nc_get_var_bfloat16 (int ncid, int varid, nc_bfloat16_t *ip)
 Read a whole variable as bfloat16.
int nc_put_var_bfloat16 (int ncid, int varid, const nc_bfloat16_t *op)
 Write a whole variable from bfloat16 values.
int nc_get_vars_bfloat16 (int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, nc_bfloat16_t *ip)
 Read a strided hyperslab of a variable as bfloat16.
int nc_put_vars_bfloat16 (int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, const nc_bfloat16_t *op)
 Write a strided hyperslab of a variable from bfloat16 values.
int nc_get_vara_bfloat16 (int ncid, int varid, const size_t *startp, const size_t *countp, nc_bfloat16_t *ip)
 Read a hyperslab of a variable as bfloat16.
int nc_put_vara_bfloat16 (int ncid, int varid, const size_t *startp, const size_t *countp, const nc_bfloat16_t *op)
 Write a hyperslab of a variable from bfloat16 values.
int nc_get_var1_float16 (int ncid, int varid, const size_t *indexp, nc_float16_t *ip)
 Read one value from a variable as IEEE 754 float16.
int nc_put_var1_float16 (int ncid, int varid, const size_t *indexp, const nc_float16_t *op)
 Write one value to a variable as IEEE 754 float16.
int nc_get_var_float16 (int ncid, int varid, nc_float16_t *ip)
 Read a whole variable as IEEE 754 float16.
int nc_put_var_float16 (int ncid, int varid, const nc_float16_t *op)
 Write a whole variable from IEEE 754 float16 values.
int nc_get_vars_float16 (int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, nc_float16_t *ip)
 Read a strided hyperslab of a variable as IEEE 754 float16.
int nc_put_vars_float16 (int ncid, int varid, const size_t *startp, const size_t *countp, const ptrdiff_t *stridep, const nc_float16_t *op)
 Write a strided hyperslab of a variable from IEEE 754 float16 values.
int nc_get_vara_float16 (int ncid, int varid, const size_t *startp, const size_t *countp, nc_float16_t *ip)
 Read a hyperslab of a variable as IEEE 754 float16.
int nc_put_vara_float16 (int ncid, int varid, const size_t *startp, const size_t *countp, const nc_float16_t *op)
 Write a hyperslab of a variable from IEEE 754 float16 values.

Detailed Description

NetCDF Expansion Pack (NEP) - Public API.

Defines NEP logging and the centralized mapping of file formats to NetCDF User-Defined Format (UDF) slot numbers.

UDF Slot Allocation

Current netcdf-c main provides 64 UDF slots (UDF0-UDF63). NEP occupies UDF0-UDF9:

  • UDF0: GeoTIFF BigTIFF (magic: "II+")
  • UDF1: GeoTIFF standard TIFF (magic: "II*")
  • UDF2: GRIB2 meteorological data (magic: "GRIB")
  • UDF3: FITS astronomical data (magic: "SIMPLE")
  • UDF4: NASA CDF format (magic: 0nxCDF30001)
  • UDF5: PDS4 planetary data system (magic: "<?xml")
  • UDF6: DICOM medical imaging data (magic: "DICM")
  • UDF7: Legacy PDB protein structure data (magic: "HEADER")
  • UDF8: PDBx/mmCIF protein structure data (magic: "data_")
  • UDF9: nxCDF HDF5 backend
Author
Edward Hartnett
Date
Nov 13, 2025

Macro Definition Documentation

◆ NEP_HAVE_NATIVE_BFLOAT16

#define NEP_HAVE_NATIVE_BFLOAT16   0

1 when nc_bfloat16_t is the compiler's __bf16 type, 0 when it is uint16_t.

◆ NEP_HAVE_NATIVE_FLOAT16

#define NEP_HAVE_NATIVE_FLOAT16   0

1 when nc_float16_t is the compiler's _Float16 type, 0 when it is uint16_t.

Typedef Documentation

◆ nc_bfloat16_t

typedef uint16_t nc_bfloat16_t

One bfloat16 value in memory: 2 bytes holding the bfloat16 bit pattern either way. With __bf16, C casts convert numerically, so code that holds raw bits in uint16_t passes them by casting the pointer ((nc_bfloat16_t *)(void *)bits), not by assigning values.

◆ nc_float16_t

typedef uint16_t nc_float16_t

One IEEE 754 binary16 value in memory: 2 bytes holding the float16 bit pattern either way. With _Float16, C casts convert numerically, so code that holds raw bits in uint16_t passes them by casting the pointer ((nc_float16_t *)(void *)bits), not by assigning values.

Function Documentation

◆ nc_get_var1_bfloat16()

int nc_get_var1_bfloat16 ( int ncid,
int varid,
const size_t * indexp,
nc_bfloat16_t * ip )

Read one value from a variable as bfloat16.

Parameters
ncidNetCDF file ID.
varidVariable ID.
indexpElement coordinates (NULL reads element 0).
ipReturned bfloat16 value.
Returns
NC_NOERR on success; error as in nc_get_vara_bfloat16().
See also
nc_get_vara_bfloat16()
Author
Edward Hartnett, Intelligent Data Design, Inc.

Read one value from a variable as bfloat16. See nep.h for the variable types accepted and the conversion rules.

Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_get_var1_float16()

int nc_get_var1_float16 ( int ncid,
int varid,
const size_t * indexp,
nc_float16_t * ip )

Read one value from a variable as IEEE 754 float16.

Parameters
ncidNetCDF file ID.
varidVariable ID.
indexpElement coordinates (NULL reads element 0).
ipReturned float16 value.
Returns
NC_NOERR on success; error as in nc_get_vara_float16().
See also
nc_get_vara_float16()
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_get_var_bfloat16()

int nc_get_var_bfloat16 ( int ncid,
int varid,
nc_bfloat16_t * ip )

Read a whole variable as bfloat16.

Parameters
ncidNetCDF file ID.
varidVariable ID.
ipReturned bfloat16 values, one per element.
Returns
NC_NOERR on success; error as in nc_get_vara_bfloat16().
See also
nc_get_vara_bfloat16()
Author
Edward Hartnett, Intelligent Data Design, Inc.

Read a whole variable as bfloat16. See nep.h for the variable types accepted and the conversion rules.

Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_get_var_float16()

int nc_get_var_float16 ( int ncid,
int varid,
nc_float16_t * ip )

Read a whole variable as IEEE 754 float16.

Parameters
ncidNetCDF file ID.
varidVariable ID.
ipReturned float16 values, one per element.
Returns
NC_NOERR on success; error as in nc_get_vara_float16().
See also
nc_get_vara_float16()
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_get_vara_bfloat16()

int nc_get_vara_bfloat16 ( int ncid,
int varid,
const size_t * startp,
const size_t * countp,
nc_bfloat16_t * ip )

Read a hyperslab of a variable as bfloat16.

Works on any file the netCDF API can open. An NC_BFLOAT16 variable returns its raw bit patterns with no conversion. An NC_FLOAT or NC_DOUBLE variable is read with the corresponding typed call and every value is converted to bfloat16 by NEP, rounding to nearest with ties to even (a single rounding from double); the bfloat16-to-float/double direction is exact. An NC_CHAR variable returns NC_ECHAR; every other variable type (including NC_FLOAT16) returns NC_EBADTYPE, and nothing is read.

Parameters
ncidNetCDF file ID.
varidVariable ID (NC_BFLOAT16, NC_FLOAT or NC_DOUBLE).
startpStart index in each dimension.
countpEdge count in each dimension.
ipReturned bfloat16 values.
Returns
NC_NOERR on success; NC_ERANGE if a finite value overflowed to ±inf (all values are still converted); NC_EBADTYPE, NC_ECHAR, NC_EINVAL, NC_ENOMEM or other errors from the underlying netCDF call.
Author
Edward Hartnett, Intelligent Data Design, Inc.

Read a hyperslab of a variable as bfloat16. See nep.h for the variable types accepted and the conversion rules.

Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_get_vara_float16()

int nc_get_vara_float16 ( int ncid,
int varid,
const size_t * startp,
const size_t * countp,
nc_float16_t * ip )

Read a hyperslab of a variable as IEEE 754 float16.

Works on any file the netCDF API can open. An NC_FLOAT16 variable returns its raw bit patterns with no conversion. An NC_FLOAT or NC_DOUBLE variable is read with the corresponding typed call and every value is converted to float16 by NEP, rounding to nearest with ties to even (a single rounding from double); the float16-to-float/double direction is exact. An NC_CHAR variable returns NC_ECHAR; every other variable type (including NC_BFLOAT16) returns NC_EBADTYPE, and nothing is read.

Parameters
ncidNetCDF file ID.
varidVariable ID (NC_FLOAT16, NC_FLOAT or NC_DOUBLE).
startpStart index in each dimension.
countpEdge count in each dimension.
ipReturned float16 values.
Returns
NC_NOERR on success; NC_ERANGE if a finite value overflowed to ±inf (all values are still converted); NC_EBADTYPE, NC_ECHAR, NC_EINVAL, NC_ENOMEM or other errors from the underlying netCDF call.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_get_vars_bfloat16()

int nc_get_vars_bfloat16 ( int ncid,
int varid,
const size_t * startp,
const size_t * countp,
const ptrdiff_t * stridep,
nc_bfloat16_t * ip )

Read a strided hyperslab of a variable as bfloat16.

Parameters
ncidNetCDF file ID.
varidVariable ID.
startpStart index in each dimension.
countpEdge count in each dimension.
stridepStride in each dimension.
ipReturned bfloat16 values.
Returns
NC_NOERR on success; error as in nc_get_vara_bfloat16().
See also
nc_get_vara_bfloat16()
Author
Edward Hartnett, Intelligent Data Design, Inc.

Read a strided hyperslab of a variable as bfloat16. See nep.h for the variable types accepted and the conversion rules.

Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_get_vars_float16()

int nc_get_vars_float16 ( int ncid,
int varid,
const size_t * startp,
const size_t * countp,
const ptrdiff_t * stridep,
nc_float16_t * ip )

Read a strided hyperslab of a variable as IEEE 754 float16.

Parameters
ncidNetCDF file ID.
varidVariable ID.
startpStart index in each dimension.
countpEdge count in each dimension.
stridepStride in each dimension.
ipReturned float16 values.
Returns
NC_NOERR on success; error as in nc_get_vara_float16().
See also
nc_get_vara_float16()
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_put_var1_bfloat16()

int nc_put_var1_bfloat16 ( int ncid,
int varid,
const size_t * indexp,
const nc_bfloat16_t * op )

Write one value to a variable as bfloat16.

Parameters
ncidNetCDF file ID.
varidVariable ID.
indexpElement coordinates (NULL writes element 0).
opThe bfloat16 value to write.
Returns
NC_NOERR on success; error as in nc_put_vara_bfloat16().
See also
nc_put_vara_bfloat16()
Author
Edward Hartnett, Intelligent Data Design, Inc.

Write one value to a variable as bfloat16. See nep.h for the variable types accepted and the conversion rules.

Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_put_var1_float16()

int nc_put_var1_float16 ( int ncid,
int varid,
const size_t * indexp,
const nc_float16_t * op )

Write one value to a variable as IEEE 754 float16.

Parameters
ncidNetCDF file ID.
varidVariable ID.
indexpElement coordinates (NULL writes element 0).
opThe float16 value to write.
Returns
NC_NOERR on success; error as in nc_put_vara_float16().
See also
nc_put_vara_float16()
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_put_var_bfloat16()

int nc_put_var_bfloat16 ( int ncid,
int varid,
const nc_bfloat16_t * op )

Write a whole variable from bfloat16 values.

Parameters
ncidNetCDF file ID.
varidVariable ID.
opThe bfloat16 values to write, one per element.
Returns
NC_NOERR on success; error as in nc_put_vara_bfloat16().
See also
nc_put_vara_bfloat16()
Author
Edward Hartnett, Intelligent Data Design, Inc.

Write a whole variable from bfloat16 values. See nep.h for the variable types accepted and the conversion rules.

Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_put_var_float16()

int nc_put_var_float16 ( int ncid,
int varid,
const nc_float16_t * op )

Write a whole variable from IEEE 754 float16 values.

Parameters
ncidNetCDF file ID.
varidVariable ID.
opThe float16 values to write, one per element.
Returns
NC_NOERR on success; error as in nc_put_vara_float16().
See also
nc_put_vara_float16()
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_put_vara_bfloat16()

int nc_put_vara_bfloat16 ( int ncid,
int varid,
const size_t * startp,
const size_t * countp,
const nc_bfloat16_t * op )

Write a hyperslab of a variable from bfloat16 values.

Works on any file the netCDF API can open. An NC_BFLOAT16 variable stores the raw bit patterns with no conversion. An NC_FLOAT or NC_DOUBLE variable is written with the corresponding typed call after every value is widened exactly to float or double by NEP; puts never overflow. An NC_CHAR variable returns NC_ECHAR; every other variable type (including NC_FLOAT16) returns NC_EBADTYPE, and nothing is written.

Parameters
ncidNetCDF file ID.
varidVariable ID (NC_BFLOAT16, NC_FLOAT or NC_DOUBLE).
startpStart index in each dimension.
countpEdge count in each dimension.
opThe bfloat16 values to write.
Returns
NC_NOERR on success; NC_EBADTYPE, NC_ECHAR, NC_EINVAL, NC_ENOMEM or other errors from the underlying netCDF call.
Author
Edward Hartnett, Intelligent Data Design, Inc.

Write a hyperslab of a variable from bfloat16 values. See nep.h for the variable types accepted and the conversion rules.

Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_put_vara_float16()

int nc_put_vara_float16 ( int ncid,
int varid,
const size_t * startp,
const size_t * countp,
const nc_float16_t * op )

Write a hyperslab of a variable from IEEE 754 float16 values.

Works on any file the netCDF API can open. An NC_FLOAT16 variable stores the raw bit patterns with no conversion. An NC_FLOAT or NC_DOUBLE variable is written with the corresponding typed call after every value is widened exactly to float or double by NEP; puts never overflow. An NC_CHAR variable returns NC_ECHAR; every other variable type (including NC_BFLOAT16) returns NC_EBADTYPE, and nothing is written.

Parameters
ncidNetCDF file ID.
varidVariable ID (NC_FLOAT16, NC_FLOAT or NC_DOUBLE).
startpStart index in each dimension.
countpEdge count in each dimension.
opThe float16 values to write.
Returns
NC_NOERR on success; NC_EBADTYPE, NC_ECHAR, NC_EINVAL, NC_ENOMEM or other errors from the underlying netCDF call.
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_put_vars_bfloat16()

int nc_put_vars_bfloat16 ( int ncid,
int varid,
const size_t * startp,
const size_t * countp,
const ptrdiff_t * stridep,
const nc_bfloat16_t * op )

Write a strided hyperslab of a variable from bfloat16 values.

Parameters
ncidNetCDF file ID.
varidVariable ID.
startpStart index in each dimension.
countpEdge count in each dimension.
stridepStride in each dimension.
opThe bfloat16 values to write.
Returns
NC_NOERR on success; error as in nc_put_vara_bfloat16().
See also
nc_put_vara_bfloat16()
Author
Edward Hartnett, Intelligent Data Design, Inc.

Write a strided hyperslab of a variable from bfloat16 values. See nep.h for the variable types accepted and the conversion rules.

Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nc_put_vars_float16()

int nc_put_vars_float16 ( int ncid,
int varid,
const size_t * startp,
const size_t * countp,
const ptrdiff_t * stridep,
const nc_float16_t * op )

Write a strided hyperslab of a variable from IEEE 754 float16 values.

Parameters
ncidNetCDF file ID.
varidVariable ID.
startpStart index in each dimension.
countpEdge count in each dimension.
stridepStride in each dimension.
opThe float16 values to write.
Returns
NC_NOERR on success; error as in nc_put_vara_float16().
See also
nc_put_vara_float16()
Author
Edward Hartnett, Intelligent Data Design, Inc.

◆ nep_set_log_level()

int nep_set_log_level ( int new_level)

Set the NEP logging level (0=errors, higher=more verbose, -1=off).

Set the NEP logging threshold.

Parameters
new_levelThe new logging level. Use -1 to disable logging, 0 for errors only, and higher numbers for progressively more verbose output.
Returns
NC_NOERR No error.
Author
Edward Hartnett