Skip to content

Commit

Permalink
Merge pull request ESMCI#1299 from NCAR/ejh_back_5
Browse files Browse the repository at this point in the history
Fix fillvalue in write_darray()
  • Loading branch information
edhartnett authored May 10, 2018
2 parents 85e008b + cb2cffd commit a018098
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 19 deletions.
6 changes: 3 additions & 3 deletions examples/c/darray_no_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,9 @@ int main(int argc, char* argv[])
if ((ret = PIOc_set_log_level(LOG_LEVEL)))
return ret;

/* Change error handling so we can test inval parameters. */
if ((ret = PIOc_set_iosystem_error_handling(PIO_DEFAULT, PIO_RETURN_ERROR, NULL)))
return ret;
/* /\* Change error handling so we can test inval parameters. *\/ */
/* if ((ret = PIOc_set_iosystem_error_handling(PIO_DEFAULT, PIO_RETURN_ERROR, NULL))) */
/* return ret; */

/* Initialize the PIO IO system. This specifies how many and
* which processors are involved in I/O. */
Expand Down
1 change: 0 additions & 1 deletion examples/c/examplePio.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,6 @@ int main(int argc, char* argv[])

#ifdef TIMING
/* Initialize the GPTL timing library. */
int ret;
if ((ret = GPTLinitialize ()))
return ret;
#endif
Expand Down
12 changes: 9 additions & 3 deletions src/clib/pio_darray.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,17 @@ pio_inq_var_fill_expected(int ncid, int varid, int pio_type, PIO_Offset type_siz
ncid, varid, pio_type, type_size));

/* Is there a _FillValue attribute? */
ret = PIOc_get_att(ncid, varid, "_FillValue", fillvalue);
ret = PIOc_inq_att_eh(ncid, varid, "_FillValue", 0, NULL, NULL);

LOG((3, "pio_inq_var_fill_expected ret %d", ret));

/* If no _FillValue at was found we still have work to do. */
if (ret)
/* If there is a fill value, get it. */
if (!ret)
{
if ((ret = PIOc_get_att(ncid, varid, "_FillValue", fillvalue)))
return ret;
}
else /* If no _FillValue at was found we still have work to do. */
{
/* Did we get some other error? */
if (ret != PIO_ENOTATT)
Expand Down
55 changes: 43 additions & 12 deletions src/clib/pio_nc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1085,14 +1085,17 @@ int PIOc_inq_varid(int ncid, const char *name, int *varidp)
*
* @param ncid the ncid of the open file, obtained from
* PIOc_openfile() or PIOc_createfile().
* @param varid the variable ID.
* @param varid the variable ID or NC_GLOBAL.
* @param name name of the attribute.
* @param eh non-zero to handle errors in the function. This will
* cause program to halt if PIO error handler is set to INTERNAL.
* @param xtypep a pointer that will get the type of the attribute.
* @param lenp a pointer that will get the number of values
* @return PIO_NOERR for success, error code otherwise.
* @author Jim Edwards, Ed Hartnett
*/
int PIOc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep,
PIO_Offset *lenp)
int PIOc_inq_att_eh(int ncid, int varid, const char *name, int eh,
nc_type *xtypep, PIO_Offset *lenp)
{
int msg = PIO_MSG_INQ_ATT;
iosystem_desc_t *ios;
Expand Down Expand Up @@ -1160,18 +1163,46 @@ int PIOc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep,
/* Broadcast and check the return code. */
if ((mpierr = MPI_Bcast(&ierr, 1, MPI_INT, ios->ioroot, ios->my_comm)))
return check_mpi(file, mpierr, __FILE__, __LINE__);
if (ierr)
if (eh && ierr)
return check_netcdf(file, ierr, __FILE__, __LINE__);

/* Broadcast results. */
if (xtypep)
if ((mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm)))
check_mpi(file, mpierr, __FILE__, __LINE__);
if (lenp)
if ((mpierr = MPI_Bcast(lenp, 1, MPI_OFFSET, ios->ioroot, ios->my_comm)))
check_mpi(file, mpierr, __FILE__, __LINE__);
/* Broadcast results if call succeeded. */
if (!ierr)
{
if (xtypep)
if ((mpierr = MPI_Bcast(xtypep, 1, MPI_INT, ios->ioroot, ios->my_comm)))
check_mpi(file, mpierr, __FILE__, __LINE__);
if (lenp)
if ((mpierr = MPI_Bcast(lenp, 1, MPI_OFFSET, ios->ioroot, ios->my_comm)))
check_mpi(file, mpierr, __FILE__, __LINE__);
}

return PIO_NOERR;
return ierr;
}

/**
* @ingroup PIO_inq_att
* The PIO-C interface for the NetCDF function nc_inq_att.
*
* This routine is called collectively by all tasks in the communicator
* ios.union_comm. For more information on the underlying NetCDF commmand
* please read about this function in the NetCDF documentation at:
* http://www.unidata.ucar.edu/software/netcdf/docs/group__attributes.html
*
* @param ncid the ncid of the open file, obtained from
* PIOc_openfile() or PIOc_createfile().
* @param varid the variable ID.
* @param varid the variable ID or NC_GLOBAL.
* @param name name of the attribute.
* @param xtypep a pointer that will get the type of the attribute.
* @param lenp a pointer that will get the number of values
* @return PIO_NOERR for success, error code otherwise.
* @author Jim Edwards, Ed Hartnett
*/
int PIOc_inq_att(int ncid, int varid, const char *name, nc_type *xtypep,
PIO_Offset *lenp)
{
return PIOc_inq_att_eh(ncid, varid, name, 1, xtypep, lenp);
}

/**
Expand Down

0 comments on commit a018098

Please sign in to comment.