From 6d2fda3cf8c0e2eba66d96c804eb0a48bb8f6747 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 9 May 2018 09:24:48 -0600 Subject: [PATCH 1/4] changing fill value handling in write_darray --- src/clib/pio_darray.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/clib/pio_darray.c b/src/clib/pio_darray.c index 7ff5a9ca33d..329bd4b5d18 100644 --- a/src/clib/pio_darray.c +++ b/src/clib/pio_darray.c @@ -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(ncid, varid, "_FillValue", 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) From e9854d6c1c762d4caa72f55aeb74d2b1bbb53577 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 9 May 2018 09:35:10 -0600 Subject: [PATCH 2/4] fixed problem with _FillValue --- examples/c/darray_no_async.c | 6 ++--- src/clib/pio_darray.c | 2 +- src/clib/pio_nc.c | 48 +++++++++++++++++++++++++++--------- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/examples/c/darray_no_async.c b/examples/c/darray_no_async.c index 7bdb134fafa..126adcd5ba0 100644 --- a/examples/c/darray_no_async.c +++ b/examples/c/darray_no_async.c @@ -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. */ diff --git a/src/clib/pio_darray.c b/src/clib/pio_darray.c index 329bd4b5d18..116f0103770 100644 --- a/src/clib/pio_darray.c +++ b/src/clib/pio_darray.c @@ -411,7 +411,7 @@ 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_inq_att(ncid, varid, "_FillValue", NULL, NULL); + ret = PIOc_inq_att_eh(ncid, varid, "_FillValue", 0, NULL, NULL); LOG((3, "pio_inq_var_fill_expected ret %d", ret)); diff --git a/src/clib/pio_nc.c b/src/clib/pio_nc.c index f15da7856b4..147ee872b2f 100644 --- a/src/clib/pio_nc.c +++ b/src/clib/pio_nc.c @@ -1091,8 +1091,8 @@ int PIOc_inq_varid(int ncid, const char *name, int *varidp) * @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; @@ -1160,18 +1160,44 @@ 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 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); } /** From 8402f426ae369b2d93764efcc6f43756d5ac2a15 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 9 May 2018 09:37:36 -0600 Subject: [PATCH 3/4] added documentation --- src/clib/pio_nc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/clib/pio_nc.c b/src/clib/pio_nc.c index 147ee872b2f..17ca0bf3d8a 100644 --- a/src/clib/pio_nc.c +++ b/src/clib/pio_nc.c @@ -1085,7 +1085,10 @@ 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. @@ -1189,6 +1192,8 @@ int PIOc_inq_att_eh(int ncid, int varid, const char *name, int eh, * @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. From cb2cffd01ee421f95ab5824102e88a8fd650ba89 Mon Sep 17 00:00:00 2001 From: Ed Hartnett Date: Wed, 9 May 2018 09:45:12 -0600 Subject: [PATCH 4/4] removed redeclaration of ret --- examples/c/examplePio.c | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/c/examplePio.c b/examples/c/examplePio.c index a21fa27a0b7..61234f47c22 100644 --- a/examples/c/examplePio.c +++ b/examples/c/examplePio.c @@ -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