Skip to content

Commit

Permalink
Use "_FillValue" and avoid using C macro _FillValue or NC_FillValue
Browse files Browse the repository at this point in the history
This is to conform with NetCDF4's header, netcdf.hs, changed in 4.9.3.
See Unidata/netcdf-c#2911
  • Loading branch information
wkliao committed Oct 17, 2024
1 parent c920993 commit 9018c41
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/dispatchers/attr_getput.m4
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ sanity_check_put(PNC *pncp,

#ifdef NO_NC_GLOBAL_FILLVALUE
/* See r3403 and RELEASE_NOTES 1.9.0 */
if (varid == NC_GLOBAL && !strcmp(name, _FillValue))
DEBUG_RETURN_ERROR(NC_EGLOBAL) /* global _FillValue is not allowed */
if (varid == NC_GLOBAL && !strcmp(name, "_FillValue"))
DEBUG_RETURN_ERROR(NC_EGLOBAL) /* global "_FillValue" is not allowed */
#endif

if (strlen(name) > NC_MAX_NAME) /* name length */
Expand Down
2 changes: 1 addition & 1 deletion src/dispatchers/variable.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ ncmpi_def_var_fill(int ncid, /* IN: file ID */
}

if (varid == NC_GLOBAL) {
/* setting global _FillValue through this API is not allowed */
/* setting global attribute _FillValue through this API is not allowed */
DEBUG_ASSIGN_ERROR(err, NC_EGLOBAL)
goto err_check;
}
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/ncmpio/ncmpio_attr.m4
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ ncmpio_put_att(void *ncdp,
/* If this is attribute _FillValue, then let PnetCDF return the
* same error codes as netCDF
*/
if (varid != NC_GLOBAL && !strcmp(name, NC_FillValue)) {
if (varid != NC_GLOBAL && !strcmp(name, "_FillValue")) {
/* Fill value must be of the same data type */
if (xtype != ncp->vars.value[varid]->xtype) {
DEBUG_ASSIGN_ERROR(err, NC_EBADTYPE)
Expand Down
26 changes: 13 additions & 13 deletions src/drivers/ncmpio/ncmpio_fill.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ fill_var_buf(const NC_var *varp,
{
int i, indx;

indx = ncmpio_NC_findattr(&varp->attrs, _FillValue);
indx = ncmpio_NC_findattr(&varp->attrs, "_FillValue");
if (indx >= 0) {
/* User defined fill value */
NC_attr *attrp = varp->attrs.value[indx];
Expand Down Expand Up @@ -280,12 +280,12 @@ fillerup(NC *ncp)
* explicitly filled by calling ncmpi_fill_var_rec() */
continue;

/* check if _FillValue attribute is defined */
indx = ncmpio_NC_findattr(&ncp->vars.value[i]->attrs, _FillValue);
/* check if attribute _FillValue is defined */
indx = ncmpio_NC_findattr(&ncp->vars.value[i]->attrs, "_FillValue");

/* only if filling this variable is requested. Fill mode can be
* enabled by 2 ways: explictly call to ncmpi_def_var_fill() or put
* the attribute named _FillValue */
* the attribute named "_FillValue" */
if (ncp->vars.value[i]->no_fill && indx == -1) continue;

/* collectively fill the entire variable */
Expand All @@ -309,8 +309,8 @@ fill_added(NC *ncp, NC *old_ncp)
/* skip record variables */
continue;

/* check if _FillValue attribute is defined */
indx = ncmpio_NC_findattr(&ncp->vars.value[varid]->attrs, _FillValue);
/* check if attribute _FillValue is defined */
indx = ncmpio_NC_findattr(&ncp->vars.value[varid]->attrs, "_FillValue");

/* only if filling this variable is requested */
if (ncp->vars.value[varid]->no_fill && indx == -1) continue;
Expand Down Expand Up @@ -338,8 +338,8 @@ fill_added_recs(NC *ncp, NC *old_ncp)
/* skip non-record variables */
continue;

/* check if _FillValue attribute is defined */
indx = ncmpio_NC_findattr(&ncp->vars.value[varid]->attrs, _FillValue);
/* check if attribute _FillValue is defined */
indx = ncmpio_NC_findattr(&ncp->vars.value[varid]->attrs, "_FillValue");

/* only if filling this variable is requested */
if (ncp->vars.value[varid]->no_fill && indx == -1) continue;
Expand Down Expand Up @@ -725,8 +725,8 @@ ncmpio_fill_var_rec(void *ncdp,
goto err_check;
}

/* check if _FillValue attribute is defined */
indx = ncmpio_NC_findattr(&varp->attrs, _FillValue);
/* check if attribute _FillValue is defined */
indx = ncmpio_NC_findattr(&varp->attrs, "_FillValue");

/* error if the fill mode of this variable is not on */
if (varp->no_fill && indx == -1) {
Expand Down Expand Up @@ -891,7 +891,7 @@ ncmpio_def_var_fill(void *ncdp,
if (fill_value != NULL && !varp->no_fill) {

/* create/overwrite attribute _FillValue */
err = ncmpio_put_att(ncdp, varid, _FillValue, varp->xtype,
err = ncmpio_put_att(ncdp, varid, "_FillValue", varp->xtype,
1, fill_value, ncmpii_nc2mpitype(varp->xtype));
if (err != NC_NOERR) return err;
}
Expand All @@ -911,9 +911,9 @@ ncmpio_inq_var_fill(NC_var *varp,

assert(varp != NULL); /* NC_GLOBAL varid is illegal in this context */

/* Check if _FillValue is defined for this variable */
/* Check if attribute _FillValue is defined for this variable */
for (i=0; i<ncap->ndefined; i++) {
if (strcmp(ncap->value[i]->name, _FillValue) == 0)
if (strcmp(ncap->value[i]->name, "_FillValue") == 0)
break;
}
if (i == ncap->ndefined) { /* attribute _FillValue is not set */
Expand Down
8 changes: 4 additions & 4 deletions src/utils/ncmpidump/ncmpidump.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,18 +538,18 @@ do_ncdump(const char *path, struct fspec* specp)

var.has_fillval = 1; /* by default, but turn off for bytes */

/* get _FillValue attribute */
ncmpi_status = ncmpi_inq_att(ncid, varid, _FillValue,
/* get attribute _FillValue */
ncmpi_status = ncmpi_inq_att(ncid, varid, "_FillValue",
&att.type, &att.len);
if (ncmpi_status == NC_NOERR &&
att.type == var.type && att.len == 1) {
if (var.type == NC_CHAR) {
char fillc;
NC_CHECK(ncmpi_get_att_text(ncid, varid, _FillValue,
NC_CHECK(ncmpi_get_att_text(ncid, varid, "_FillValue",
&fillc));
var.fillval = fillc;
} else
NC_CHECK(ncmpi_get_att_double(ncid, varid, _FillValue,
NC_CHECK(ncmpi_get_att_double(ncid, varid, "_FillValue",
&var.fillval));
} else {
switch (var.type) {
Expand Down
4 changes: 2 additions & 2 deletions src/utils/ncmpigen/ncmpigen.y
Original file line number Diff line number Diff line change
Expand Up @@ -1221,13 +1221,13 @@ void equalatt(void)
/* shrink space down to what was really needed */
att_space = erealloc(att_space, valnum*nctypesize(valtype));
atts[natts].val = att_space;
if (STREQ(atts[natts].name, _FillValue) &&
if (STREQ(atts[natts].name, "_FillValue") &&
atts[natts].var != NC_GLOBAL) {
nc_putfill(atts[natts].type,atts[natts].val,
&vars[atts[natts].var].fill_value);
if(atts[natts].type != vars[atts[natts].var].type) {
derror("variable %s: %s type mismatch",
vars[atts[natts].var].name, _FillValue);
vars[atts[natts].var].name, "_FillValue");
}
}
natts++;
Expand Down
4 changes: 2 additions & 2 deletions src/utils/ncmpigen/ncmpigentab.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,13 @@ void equalatt(void)
/* shrink space down to what was really needed */
att_space = erealloc(att_space, valnum*nctypesize(valtype));
atts[natts].val = att_space;
if (STREQ(atts[natts].name, _FillValue) &&
if (STREQ(atts[natts].name, "_FillValue") &&
atts[natts].var != NC_GLOBAL) {
nc_putfill(atts[natts].type,atts[natts].val,
&vars[atts[natts].var].fill_value);
if(atts[natts].type != vars[atts[natts].var].type) {
derror("variable %s: %s type mismatch",
vars[atts[natts].var].name, _FillValue);
vars[atts[natts].var].name, "_FillValue");
}
}
natts++;
Expand Down
6 changes: 3 additions & 3 deletions test/nc_test/t_nc.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static const char * const reqattr[] = {
"SCALEMIN",
"SCALEMAX",
"FIELDNAM",
_FillValue
"_FillValue"
};
#define NUM_RATTRS 6

Expand Down Expand Up @@ -359,8 +359,8 @@ int t_nc(char *filename, int cmode)

{
int ifill = -1; double dfill = -9999;
err = ncmpi_put_att_int(id, Long_id, _FillValue, NC_INT, 1, &ifill); ERR
err = ncmpi_put_att_double(id, Double_id, _FillValue, NC_DOUBLE, 1, &dfill); ERR
err = ncmpi_put_att_int(id, Long_id, "_FillValue", NC_INT, 1, &ifill); ERR
err = ncmpi_put_att_double(id, Double_id, "_FillValue", NC_DOUBLE, 1, &dfill); ERR
}

#ifdef REDEF
Expand Down

0 comments on commit 9018c41

Please sign in to comment.