Skip to content

Commit

Permalink
Merge pull request ESMCI#1278 from NCAR/ejh_test_4
Browse files Browse the repository at this point in the history
Fixes to PIO for newer netCDF library versions
  • Loading branch information
edhartnett authored Jan 11, 2018
2 parents 4e42e46 + fda1302 commit 7c92c48
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 13 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
27 changes: 25 additions & 2 deletions src/clib/pio_darray_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,10 +805,16 @@ int pio_read_darray_nc(file_desc_t *file, io_desc_t *iodesc, int vid, void *iobu
the mpitype. */
region = iodesc->firstregion;

/* ??? */
/* There are different numbers of dims in the decomposition
* and the file. */
if (fndims > ndims)
{
ndims++;

/* If the user did not call setframe, use a default frame
* of 0. This is required for backward compatibility. */
if (vdesc->record < 0)
vdesc->record = 0;
}

/* For each regions, read the data. */
Expand All @@ -833,7 +839,8 @@ int pio_read_darray_nc(file_desc_t *file, io_desc_t *iodesc, int vid, void *iobu
else
bufptr=(void *)((char *)iobuf + iodesc->mpitype_size * region->loffset);

LOG((2, "%d %d %d", iodesc->llen - region->loffset, iodesc->llen, region->loffset));
LOG((2, "iodesc->llen - region->loffset %d, iodesc->llen %d, region->loffset %d vdesc->record %d",
iodesc->llen - region->loffset, iodesc->llen, region->loffset, vdesc->record));

/* Get the start/count arrays. */
if (vdesc->record >= 0 && fndims > 1)
Expand Down Expand Up @@ -862,6 +869,11 @@ int pio_read_darray_nc(file_desc_t *file, io_desc_t *iodesc, int vid, void *iobu
}
}

#ifdef LOGGING
for (int i = 1; i < ndims; i++)
LOG((3, "start[%d] %d count[%d] %d", i, start[i], i, count[i]));
#endif /* LOGGING */

/* Do the read. */
switch (file->iotype)
{
Expand Down Expand Up @@ -1023,6 +1035,11 @@ int pio_read_darray_nc_serial(file_desc_t *file, io_desc_t *iodesc, int vid,
if ((ierr = PIOc_inq_varndims(file->pio_ncid, vid, &fndims)))
return pio_err(ios, file, ierr, __FILE__, __LINE__);

/* If setframe was not called, use a default value of 0. This is
* required for backward compatibility. */
if (fndims == ndims + 1 && vdesc->record < 0)
vdesc->record = 0;

/* Confirm that we are being called with the correct ndims. */
pioassert((fndims == ndims && vdesc->record < 0) ||
(fndims == ndims + 1 && vdesc->record >= 0),
Expand All @@ -1043,6 +1060,12 @@ int pio_read_darray_nc_serial(file_desc_t *file, io_desc_t *iodesc, int vid,
the mpitype. */
region = iodesc->firstregion;

/* If setframe was not set before this call, assume a value of
* 0. This is required for backward compatibility. */
if (fndims > ndims)
if (vdesc->record < 0)
vdesc->record = 0;

/* Put together start/count arrays for all regions. */
for (int regioncnt = 0; regioncnt < iodesc->maxregions; regioncnt++)
{
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
1 change: 0 additions & 1 deletion src/clib/pioc.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ int PIOc_setframe(int ncid, int varid, int frame)

/* Set the record dimension value for this variable. This will be
* used by the write_darray functions. */
/* file->varlist[varid].record = frame; */
vdesc->record = frame;

return PIO_NOERR;
Expand Down
8 changes: 3 additions & 5 deletions tests/cunit/test_darray_1d.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,9 @@ int test_darray_fill_unlim(int iosysid, int ioid, int pio_type, int num_flavors,
if (!(test_data_in = malloc(type_size * arraylen)))
ERR(PIO_ENOMEM);

/* Set the record number for the unlimited dimension. */
if ((ret = PIOc_setframe(ncid, varid, 0)))
ERR(ret);

/* Read the data. */
/* Read the data. We don't have to set the record number for
* the unlimited dimension. If we don't set it, PIO will
* assume a value of 0. */
if ((ret = PIOc_read_darray(ncid, varid, ioid, arraylen, test_data_in)))
ERR(ret);

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 7c92c48

Please sign in to comment.