|
NEP 4.3.0
NetCDF Expansion Pack
|
Build a nxCDF NC_BFLOAT16 copy of the GDAS sample file. More...
#include <netcdf.h>#include <nep.h>#include "nxcdf/nxcdf.h"#include <stdio.h>#include <stdlib.h>#include <string.h>Macros | |
| #define | ERRCODE 2 |
| #define | ERR(e) |
| #define | HISTORY "Data fields converted from gdas_sfc_sample.nc to NC_BFLOAT16 with nc_get_var_bfloat16 (round to nearest, ties to even) by make_bfloat16_sample" |
Functions | |
| static size_t | type_size (nc_type xtype) |
| Return the size in bytes of an atomic NetCDF type. | |
| static int | copy_att (int ncid_in, int varid_in, const char *name, int ncid_out, int varid_out) |
| Copy one attribute between files, keeping type and length. | |
| static int | copy_global_atts (int ncid_in, int ncid_out) |
| Copy the global attributes and add the history attribute. | |
| static int | def_dims (int ncid_in, int ncid_out) |
| Define the output dimensions in fixed order. | |
| static int | def_vars (int ncid_in, int ncid_out) |
| Define all output variables and copy their attributes. | |
| static int | copy_data (int ncid_in, int ncid_out) |
| Copy the data of every variable. | |
| int | main (int argc, char **argv) |
| Main entry point. | |
Build a nxCDF NC_BFLOAT16 copy of the GDAS sample file.
Reads test/data/netCDF-4/gdas_sfc_sample.nc (an ordinary NetCDF-4 file) and writes a nxCDF file in which every NC_FLOAT data variable is stored as NC_BFLOAT16. The conversion is done by nc_get_var_bfloat16() on the source variables, which rounds to nearest, ties to even; fill points (9.99e+20) are converted like any other value. The NC_DOUBLE coordinate variables are copied unchanged. The output is uncompressed and contiguous; run make_bfloat16_sample.sh to apply the shuffle+zstd layout with h5repack.
Differences from the source: time is a fixed dimension of length 1, and the bfloat16 variables carry no _FillValue or missing_value attributes (NC_BFLOAT16 fill values are not supported, issue #377). A history global attribute records the conversion.
Usage:
| #define ERR | ( | e | ) |
| #define ERRCODE 2 |
| #define HISTORY "Data fields converted from gdas_sfc_sample.nc to NC_BFLOAT16 with nc_get_var_bfloat16 (round to nearest, ties to even) by make_bfloat16_sample" |
Value of the history global attribute added to the output.
|
static |
Copy one attribute between files, keeping type and length.
| ncid_in | Input file. |
| varid_in | Variable the attribute is attached to (NC_GLOBAL ok). |
| name | Attribute name. |
| ncid_out | Output file. |
| varid_out | Output variable (NC_GLOBAL ok). |
|
static |
Copy the data of every variable.
NC_DOUBLE variables are copied with nc_get_var_double()/ nc_put_var_double(). NC_BFLOAT16 variables are read from the source NC_FLOAT variable with nc_get_var_bfloat16() into a uint16_t bit buffer (NEP rounds to nearest, ties to even) and written with nc_put_var_bfloat16(). An NC_ERANGE from the get is an error, because the GDAS sample has no out-of-range values.
| ncid_in | Input file. |
| ncid_out | Output file. |
|
static |
Copy the global attributes and add the history attribute.
| ncid_in | Input file. |
| ncid_out | Output file. |
|
static |
Define the output dimensions in fixed order.
Defines grid_xt, grid_yt and a fixed-length time, with the lengths taken from the same-named input dimensions.
| ncid_in | Input file. |
| ncid_out | Output file. |
|
static |
Define all output variables and copy their attributes.
For every input variable, in input order: NC_DOUBLE variables are defined as NC_DOUBLE (the coordinates) and NC_FLOAT variables as NC_BFLOAT16 with no fill value. Any other type is an error. Output dims are mapped by name. Every variable attribute is copied except _FillValue and missing_value.
| ncid_in | Input file. |
| ncid_out | Output file. |
| int main | ( | int | argc, |
| char ** | argv ) |
Main entry point.
| argc | Argument count; must be 3. |
| argv | argv[1] is the input netCDF-4 file, argv[2] the output nxCDF file. |
|
static |
Return the size in bytes of an atomic NetCDF type.
| xtype | The nc_type. |