diff --git a/src/clib/pio_darray.c b/src/clib/pio_darray.c index 4f205cede7a..16926ad4851 100644 --- a/src/clib/pio_darray.c +++ b/src/clib/pio_darray.c @@ -529,8 +529,10 @@ int PIOc_write_darray(int ncid, int varid, int ioid, PIO_Offset arraylen, void * if ((ierr = find_var_fillvalue(file, varid, vdesc))) return pio_err(ios, file, PIO_EBADID, __FILE__, __LINE__); - /* Check that if the user passed a fill value, it is correct. */ - if (fillvalue) + /* Check that if the user passed a fill value, it is correct. If + * use_fill is false, then find_var_fillvalue will not end up + * getting a fill value. */ + if (fillvalue && vdesc->use_fill) if (memcmp(fillvalue, vdesc->fillvalue, vdesc->pio_type_size)) return pio_err(ios, file, PIO_EINVAL, __FILE__, __LINE__); diff --git a/src/clib/pio_msg.c b/src/clib/pio_msg.c index 90514c5fbf3..ec8003a8a47 100644 --- a/src/clib/pio_msg.c +++ b/src/clib/pio_msg.c @@ -1121,7 +1121,7 @@ int inq_var_fill_handler(iosystem_desc_t *ios) char fill_mode_present, fill_value_present; PIO_Offset type_size; int fill_mode, *fill_modep = NULL; - PIO_Offset *fill_value, *fill_valuep = NULL; + void *fill_value, *fill_valuep = NULL; int mpierr; assert(ios); @@ -1154,12 +1154,21 @@ int inq_var_fill_handler(iosystem_desc_t *ios) fill_valuep = fill_value; /* Call the inq function to get the values. */ + LOG((3, "inq_var_fill_handlder about to call inq_var_fill")); PIOc_inq_var_fill(ncid, varid, fill_modep, fill_valuep); + if (fill_modep) + LOG((3, "after inq_var_fill fill_modep %d", *fill_modep)); /* Free fill value storage if we allocated some. */ if (fill_value_present) + { + LOG((3, "about to free fill_value")); free(fill_value); + LOG((3, "freed fill_value")); + } + if (fill_modep) + LOG((3, "done with inq_var_fill_handler", *fill_modep)); return PIO_NOERR; } diff --git a/src/clib/pio_nc.c b/src/clib/pio_nc.c index a258dc1abb4..52895b21bd9 100644 --- a/src/clib/pio_nc.c +++ b/src/clib/pio_nc.c @@ -2208,8 +2208,8 @@ int PIOc_def_var_fill(int ncid, int varid, int fill_mode, const void *fill_value return check_netcdf(file, ierr, __FILE__, __LINE__); if ((ierr = PIOc_inq_type(ncid, xtype, NULL, &type_size))) return check_netcdf(file, ierr, __FILE__, __LINE__); + LOG((2, "PIOc_def_var_fill type_size = %d", type_size)); } - LOG((2, "PIOc_def_var_fill type_size = %d", type_size)); /* If async is in use, and this is not an IO task, bcast the parameters. */ if (ios->async) @@ -2264,7 +2264,11 @@ int PIOc_def_var_fill(int ncid, int varid, int fill_mode, const void *fill_value { LOG((2, "defining fill value attribute for netCDF classic file")); if (file->do_io) - ierr = nc_put_att(file->fh, varid, _FillValue, xtype, 1, fill_valuep); + { + ierr = nc_set_fill(file->fh, NC_FILL, NULL); + if (!ierr) + ierr = nc_put_att(file->fh, varid, _FillValue, xtype, 1, fill_valuep); + } } else { diff --git a/tests/cunit/test_darray_2sync.c b/tests/cunit/test_darray_2sync.c index a5e27ccc4ab..e0a81c84be6 100644 --- a/tests/cunit/test_darray_2sync.c +++ b/tests/cunit/test_darray_2sync.c @@ -189,6 +189,10 @@ int darray_fill_test(int iosysid, int my_rank, int num_iotypes, int *iotype, if ((ret = PIOc_def_var(ncid, VAR_NAME, test_type[t], NDIM1, &dimid, &varid))) ERR(ret); + /* Turn on fill mode for this var. */ + if ((ret = PIOc_def_var_fill(ncid, varid, 0, default_fillvalue))) + ERR(ret); + /* End define mode. */ if ((ret = PIOc_enddef(ncid))) ERR(ret);