netcdf-c
netcdf-c copied to clipboard
Improve error message when trying to do nc_def_var_deflate() on vlen type variable
Using netcdf 4.9.0 the following snippet of code produces an error message that is hard to understand:
#include <netcdf.h>
#include <stdio.h>
#define BAIL(e) \
do { \
printf("Bailing out in file %s, line %d, error:%s.\n", __FILE__, \
__LINE__, nc_strerror(e)); \
return e; \
} while (0)
#define CHECK(f) \
if ((res = f)) BAIL(res);
int main() {
int res = 0;
int nc_id = 0;
CHECK(nc_create("test.nc", NC_NETCDF4, &nc_id));
int dim_id = 0;
CHECK(nc_def_dim(nc_id, "number_tm_packets", 100, &dim_id));
int grp_id = 0;
CHECK(nc_def_grp(nc_id, "data", &grp_id));
int vlen_id = 0;
CHECK(nc_def_vlen(nc_id, "row_of_bytes", NC_BYTE, &vlen_id));
int dims[] = {dim_id};
int var_id = 0;
CHECK(nc_def_var(grp_id, "number_tm_packets", vlen_id, 1, dims, &var_id));
CHECK(nc_def_var_deflate(grp_id, var_id, 1, 1, 2));
}
The error message is:
error:NetCDF: Filter error: bad id or parameters or duplicate filter.
Could this error message be improved to say something like:
error:NetCDF: Filter error: unsupported operation deflate on vlen type variable
?
See https://github.com/Unidata/netcdf4-python/issues/1175
error:NetCDF: Filter error: unsupported operation deflate on vlen type variable
No, because thata error message is the generic one for NC_EFILTER, which is used in several places to signal a number of different errors. We could however ensure that a log message is generated to give more detailed info. This requires figuring out where in the code, the error is signalled.
I think that def_var_deflate() should check for legal types and return a NC_EINVAL.
Actually the check is currently made for nc_def_var_filter, but apparently nc_def_var_deflate bypasses that code.