diff --git a/src/clib/pio_internal.h b/src/clib/pio_internal.h index 25e67e89594..0379929e6be 100644 --- a/src/clib/pio_internal.h +++ b/src/clib/pio_internal.h @@ -186,7 +186,7 @@ extern "C" { int get_var_desc(int varid, var_desc_t **varlist, var_desc_t **var_desc); int delete_var_desc(int varid, var_desc_t **varlist); - /* Create a file (internal function). */ + /* Create a file. */ int PIOc_createfile_int(int iosysid, int *ncidp, int *iotype, const char *filename, int mode, int use_ext_ncid); diff --git a/src/clib/pioc_support.c b/src/clib/pioc_support.c index 21f2c83db13..040e1659f12 100644 --- a/src/clib/pioc_support.c +++ b/src/clib/pioc_support.c @@ -1930,7 +1930,8 @@ PIOc_writemap_from_f90(const char *file, int ndims, const int *gdims, * @param iosysid A defined pio system ID, obtained from * PIOc_Init_Intracomm() or PIOc_InitAsync(). * @param ncidp A pointer that gets the ncid of the newly created - * file. + * file. For NetCDF integration, this contains the ncid assigned by + * the netCDF layer, which is used instead of a PIO-generated ncid. * @param iotype A pointer to a pio output format. Must be one of * PIO_IOTYPE_PNETCDF, PIO_IOTYPE_NETCDF, PIO_IOTYPE_NETCDF4C, or * PIO_IOTYPE_NETCDF4P. diff --git a/src/ncint/ncintdispatch.c b/src/ncint/ncintdispatch.c index bdbcd52fdc4..cf0c3e5116d 100644 --- a/src/ncint/ncintdispatch.c +++ b/src/ncint/ncintdispatch.c @@ -162,7 +162,8 @@ PIO_NCINT_finalize(void) * @param parameters pointer to struct holding extra data (e.g. for * parallel I/O) layer. Ignored if NULL. * @param dispatch Pointer to the dispatch table for this file. - * @param nc_file Pointer to an already-existing instance of NC. + * @param ncid The ncid assigned to this file by netCDF (aka + * ext_ncid). * * @return ::NC_NOERR No error, or error code. * @author Ed Hartnett @@ -170,8 +171,9 @@ PIO_NCINT_finalize(void) int PIO_NCINT_create(const char *path, int cmode, size_t initialsz, int basepe, size_t *chunksizehintp, void *parameters, - const NC_Dispatch *dispatch, NC *nc_file) + const NC_Dispatch *dispatch, int ncid) { + NC *nc; int iotype; iosystem_desc_t *ios; /* Pointer to io system information. */ int ret; @@ -189,14 +191,17 @@ PIO_NCINT_create(const char *path, int cmode, size_t initialsz, int basepe, if ((ret = find_iotype_from_omode(cmode, &iotype))) return pio_err(ios, NULL, ret, __FILE__, __LINE__); + /* Find NC pointer for this file. */ + if ((ret = NC_check_id(ncid, &nc))) + return ret; + /* Add necessary structs to hold netcdf-4 file data. */ - if ((ret = nc4_nc4f_list_add(nc_file, path, cmode))) + if ((ret = nc4_nc4f_list_add(nc, path, cmode))) return ret; - /* Open the file with PIO. Tell openfile_retry to accept the - * externally assigned ncid. */ - if ((ret = PIOc_createfile_int(diosysid, &nc_file->ext_ncid, &iotype, - path, cmode, 1))) + /* Create the file with PIO. The final parameter tests + * createfile_int to accept the externally assigned ncid. */ + if ((ret = PIOc_createfile_int(diosysid, &ncid, &iotype, path, cmode, 1))) return ret; return PIO_NOERR; @@ -212,8 +217,7 @@ PIO_NCINT_create(const char *path, int cmode, size_t initialsz, int basepe, * @param parameters pointer to struct holding extra data (e.g. for * parallel I/O) layer. Ignored if NULL. Ignored by this function. * @param dispatch Pointer to the dispatch table for this file. - * @param nc_file Pointer to an instance of NC. The ncid has already - * been assigned, and is in nc_file->ext_ncid. + * @param ncid * * @return ::NC_NOERR No error. * @return ::NC_EINVAL Invalid input. @@ -223,8 +227,9 @@ PIO_NCINT_create(const char *path, int cmode, size_t initialsz, int basepe, */ int PIO_NCINT_open(const char *path, int mode, int basepe, size_t *chunksizehintp, - void *parameters, const NC_Dispatch *dispatch, NC *nc_file) + void *parameters, const NC_Dispatch *dispatch, int ncid) { + NC *nc; int iotype; iosystem_desc_t *ios; /* Pointer to io system information. */ int ret; @@ -242,14 +247,17 @@ PIO_NCINT_open(const char *path, int mode, int basepe, size_t *chunksizehintp, if ((ret = find_iotype_from_omode(mode, &iotype))) return pio_err(ios, NULL, ret, __FILE__, __LINE__); + /* Find NC pointer for this file. */ + if ((ret = NC_check_id(ncid, &nc))) + return ret; + /* Add necessary structs to hold netcdf-4 file data. */ - if ((ret = nc4_nc4f_list_add(nc_file, path, mode))) + if ((ret = nc4_nc4f_list_add(nc, path, mode))) return ret; /* Open the file with PIO. Tell openfile_retry to accept the * externally assigned ncid. */ - if ((ret = PIOc_openfile_retry(diosysid, &nc_file->ext_ncid, &iotype, - path, mode, 0, 1))) + if ((ret = PIOc_openfile_retry(diosysid, &ncid, &iotype, path, mode, 0, 1))) return ret; return NC_NOERR; diff --git a/src/ncint/ncintdispatch.h b/src/ncint/ncintdispatch.h index fad328c54e4..8afec9f8a9e 100644 --- a/src/ncint/ncintdispatch.h +++ b/src/ncint/ncintdispatch.h @@ -22,12 +22,12 @@ extern "C" { extern int PIO_NCINT_open(const char *path, int mode, int basepe, size_t *chunksizehintp, - void *parameters, const NC_Dispatch *, NC *); + void *parameters, const NC_Dispatch *, int); extern int PIO_NCINT_create(const char* path, int cmode, size_t initialsz, int basepe, size_t *chunksizehintp, void *parameters, - const NC_Dispatch *dispatch, NC *nc_file); + const NC_Dispatch *dispatch, int); extern int PIO_NCINT_def_var(int ncid, const char *name, nc_type xtype, int ndims, diff --git a/tests/cunit/test_darray.c b/tests/cunit/test_darray.c index 3c5317ff73b..5b8f32eda85 100644 --- a/tests/cunit/test_darray.c +++ b/tests/cunit/test_darray.c @@ -106,7 +106,8 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank /* Use PIO to create the example file in each of the four * available ways. */ - for (int fmt = 0; fmt < num_flavors; fmt++) + /* for (int fmt = 0; fmt < num_flavors; fmt++) */ + for (int fmt = 3; fmt < 4; fmt++) { /* Add a couple of extra tests for the @@ -384,7 +385,7 @@ int main(int argc, char **argv) /* Initialize test. */ if ((ret = pio_test_init2(argc, argv, &my_rank, &ntasks, MIN_NTASKS, - MIN_NTASKS, -1, &test_comm))) + MIN_NTASKS, 3, &test_comm))) ERR(ERR_INIT); if ((ret = PIOc_set_iosystem_error_handling(PIO_DEFAULT, PIO_RETURN_ERROR, NULL))) diff --git a/tests/cunit/test_iosystem2_simple.c b/tests/cunit/test_iosystem2_simple.c index 863d94faf6e..aaf2ddf4d44 100644 --- a/tests/cunit/test_iosystem2_simple.c +++ b/tests/cunit/test_iosystem2_simple.c @@ -45,7 +45,7 @@ int main(int argc, char **argv) /* Initialize test. */ if ((ret = pio_test_init2(argc, argv, &my_rank, &ntasks, TARGET_NTASKS, TARGET_NTASKS, - -1, &test_comm))) + 3, &test_comm))) ERR(ERR_INIT); /* Test code runs on TARGET_NTASKS tasks. The left over tasks do