Skip to content

Commit

Permalink
fixed fill value problems in PIO
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Jan 9, 2018
1 parent 4e42e46 commit cc6a5fd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/clib/pio_darray.c
Original file line number Diff line number Diff line change
Expand Up @@ -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__);

Expand Down
11 changes: 10 additions & 1 deletion src/clib/pio_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
8 changes: 6 additions & 2 deletions src/clib/pio_nc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
{
Expand Down
4 changes: 4 additions & 0 deletions tests/cunit/test_darray_2sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit cc6a5fd

Please sign in to comment.