To solve NC_ELATEFILL error for NetCDF-4 files, mark all variables written at enddef.

This commit is contained in:
Wei-keng Liao 2017-03-24 20:55:00 -05:00
parent d0d1a69826
commit 73ccb364a9
3 changed files with 16 additions and 4 deletions

View File

@ -47,7 +47,7 @@ EXTRA_DIST = attr.m4 ncx.m4 putget.m4 $(man_MANS) CMakeLists.txt XGetopt.c
# This tells make how to turn .m4 files into .c files.
.m4.c:
m4 $(AM_M4FLAGS) $(M4FLAGS) -s $< >${srcdir}/$@
m4 $(AM_M4FLAGS) $(M4FLAGS) -s $< > $@
# The C API man page.
man_MANS = netcdf.3

View File

@ -2984,6 +2984,8 @@ static int NC4_enddef(int ncid)
{
NC *nc;
NC_HDF5_FILE_INFO_T* nc4_info;
NC_GRP_INFO_T *grp;
int i;
LOG((1, "%s: ncid 0x%x", __func__, ncid));
@ -2991,6 +2993,14 @@ static int NC4_enddef(int ncid)
return NC_EBADID;
assert(nc4_info);
/* Find info for this file and group */
if (!(grp = nc4_rec_find_grp(nc4_info->root_grp, (ncid & GRP_ID_MASK))))
return NC_EBADGRPID;
/* when exiting define mode, mark all variable written */
for (i=0; i<grp->vars.nelems; i++)
grp->vars.value[i]->written_to = NC_TRUE;
return nc4_enddef_netcdf4_file(nc4_info);
}

View File

@ -61,13 +61,17 @@ main(int argc, char **argv)
printf("**** testing simple fill value attribute creation...");
{
int status;
/* Create a netcdf-4 file with one scalar var. Add fill
* value. */
if (nc_create(FILE_NAME, cmode, &ncid)) ERR;
if (nc_def_var(ncid, VAR_NAME, NC_BYTE, 0, NULL, &varid)) ERR;
if (nc_put_att_schar(ncid, varid, _FillValue, NC_BYTE, 1, &fill_value)) ERR;
if (nc_enddef(ncid)) ERR;
if (nc_redef(ncid)) ERR;
if (nc_put_att_schar(ncid, varid, _FillValue, NC_BYTE, 1, &fill_value)) ERR;
status = nc_put_att_schar(ncid, varid, _FillValue, NC_BYTE, 1, &fill_value);
if (status != NC_ELATEFILL)
printf("Error at line %d: expecting NC_ELATEFILL but got %s\n",__LINE__,nc_strerror(status));
if (nc_close(ncid)) ERR;
/* Open the file and check. */
@ -94,8 +98,6 @@ main(int argc, char **argv)
if (nc_create(FILE_NAME, cmode, &ncid)) ERR;
if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR;
if (nc_def_var(ncid, VAR_NAME, NC_BYTE, NUM_DIMS, dimids, &varid)) ERR;
if (nc_enddef(ncid)) ERR;
if (nc_redef(ncid)) ERR;
if (nc_put_att_schar(ncid, varid, _FillValue, NC_BYTE, 1, &fill_value)) ERR;
if (nc_enddef(ncid)) ERR;