diff --git a/src/clib/pio_file.c b/src/clib/pio_file.c index 67e35b18330..795d2f0466c 100644 --- a/src/clib/pio_file.c +++ b/src/clib/pio_file.c @@ -51,7 +51,8 @@ extern int event_num[2][NUM_EVENTS]; * @ingroup PIO_open_file_c * @author Jim Edwards, Ed Hartnett */ -int PIOc_openfile(int iosysid, int *ncidp, int *iotype, const char *filename, +int +PIOc_openfile(int iosysid, int *ncidp, int *iotype, const char *filename, int mode) { LOG((1, "PIOc_openfile iosysid %d *iotype %d filename %s mode %d", iosysid, @@ -78,7 +79,8 @@ int PIOc_openfile(int iosysid, int *ncidp, int *iotype, const char *filename, * @ingroup PIO_open_file_c * @author Ed Hartnett */ -int PIOc_openfile2(int iosysid, int *ncidp, int *iotype, const char *filename, +int +PIOc_openfile2(int iosysid, int *ncidp, int *iotype, const char *filename, int mode) { LOG((1, "PIOc_openfile2 iosysid %d *iotype %d filename %s mode %d", iosysid, @@ -99,27 +101,23 @@ int PIOc_openfile2(int iosysid, int *ncidp, int *iotype, const char *filename, * @ingroup PIO_open_file_c * @author Ed Hartnett */ -int PIOc_open(int iosysid, const char *path, int mode, int *ncidp) +int +PIOc_open(int iosysid, const char *path, int mode, int *ncidp) { int iotype; + iosystem_desc_t *ios; /* Pointer to io system information. */ + int ret; - LOG((1, "PIOc_open iosysid = %d path = %s mode = %x", iosysid, path, mode)); + LOG((1, "PIOc_open iosysid = %d path = %s mode = %x", iosysid, path, + mode)); - /* Figure out the iotype. */ - if (mode & NC_NETCDF4) - { - if (mode & NC_MPIIO || mode & NC_MPIPOSIX) - iotype = PIO_IOTYPE_NETCDF4P; - else - iotype = PIO_IOTYPE_NETCDF4C; - } - else - { - if (mode & NC_PNETCDF || mode & NC_MPIIO) - iotype = PIO_IOTYPE_PNETCDF; - else - iotype = PIO_IOTYPE_NETCDF; - } + /* Get the IO system info from the id. */ + if (!(ios = pio_get_iosystem_from_id(iosysid))) + return pio_err(NULL, NULL, PIO_EBADID, __FILE__, __LINE__); + + /* Find the IOTYPE from the mode flag. */ + if ((ret = find_iotype_from_omode(mode, &iotype))) + return pio_err(ios, NULL, ret, __FILE__, __LINE__); /* Open the file. If the open fails, do not retry as serial * netCDF. Just return the error code. */ @@ -144,7 +142,8 @@ int PIOc_open(int iosysid, const char *path, int mode, int *ncidp) * @ingroup PIO_create_file_c * @author Jim Edwards, Ed Hartnett */ -int PIOc_createfile(int iosysid, int *ncidp, int *iotype, const char *filename, +int +PIOc_createfile(int iosysid, int *ncidp, int *iotype, const char *filename, int mode) { iosystem_desc_t *ios; /* Pointer to io system information. */ @@ -188,7 +187,8 @@ int PIOc_createfile(int iosysid, int *ncidp, int *iotype, const char *filename, * @ingroup PIO_create_file_c * @author Ed Hartnett */ -int PIOc_create(int iosysid, const char *filename, int cmode, int *ncidp) +int +PIOc_create(int iosysid, const char *filename, int cmode, int *ncidp) { int iotype; /* The PIO IO type. */ @@ -219,7 +219,8 @@ int PIOc_create(int iosysid, const char *filename, int cmode, int *ncidp) * @ingroup PIO_close_file_c * @author Jim Edwards, Ed Hartnett */ -int PIOc_closefile(int ncid) +int +PIOc_closefile(int ncid) { iosystem_desc_t *ios; /* Pointer to io system information. */ file_desc_t *file; /* Pointer to file information. */ @@ -318,7 +319,8 @@ int PIOc_closefile(int ncid) * @returns PIO_NOERR for success, error code otherwise. * @author Jim Edwards, Ed Hartnett */ -int PIOc_deletefile(int iosysid, const char *filename) +int +PIOc_deletefile(int iosysid, const char *filename) { iosystem_desc_t *ios; /* Pointer to io system information. */ int ierr = PIO_NOERR; /* Return code from function calls. */ @@ -395,7 +397,8 @@ int PIOc_deletefile(int iosysid, const char *filename) * @ingroup PIO_sync_file_c * @author Jim Edwards, Ed Hartnett */ -int PIOc_sync(int ncid) +int +PIOc_sync(int ncid) { iosystem_desc_t *ios; /* Pointer to io system information. */ file_desc_t *file; /* Pointer to file information. */ diff --git a/src/clib/pio_internal.h b/src/clib/pio_internal.h index e2a0f432126..adc89f7159c 100644 --- a/src/clib/pio_internal.h +++ b/src/clib/pio_internal.h @@ -194,6 +194,9 @@ extern "C" { int PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename, int mode, int retry, int use_ext_ncid); + /* Give the mode flag from an open, determine the IOTYPE. */ + int find_iotype_from_omode(int mode, int *iotype); + /* Given PIO type, find MPI type and type size. */ int find_mpi_type(int pio_type, MPI_Datatype *mpi_type, int *type_size); diff --git a/src/clib/pioc_support.c b/src/clib/pioc_support.c index 94790185690..f24129ebbe1 100644 --- a/src/clib/pioc_support.c +++ b/src/clib/pioc_support.c @@ -2364,6 +2364,40 @@ inq_file_metadata(file_desc_t *file, int ncid, int iotype, int *nvars, int **rec return PIO_NOERR; } +/** + * Find the appropriate IOTYPE from mode flags to nc_open(). + * + * @param mode the mode flag from nc_open(). + * @param iotype pointer that gets the IOTYPE. + * + * @return 0 on success, error code otherwise. + * @author Ed Hartnett + */ +int +find_iotype_from_omode(int mode, int *iotype) +{ + /* Check inputs. */ + pioassert(iotype, "pointer to iotype must be provided", __FILE__, __LINE__); + + /* Figure out the iotype. */ + if (mode & NC_NETCDF4) + { + if (mode & NC_MPIIO || mode & NC_MPIPOSIX) + *iotype = PIO_IOTYPE_NETCDF4P; + else + *iotype = PIO_IOTYPE_NETCDF4C; + } + else + { + if (mode & NC_PNETCDF || mode & NC_MPIIO) + *iotype = PIO_IOTYPE_PNETCDF; + else + *iotype = PIO_IOTYPE_NETCDF; + } + + return PIO_NOERR; +} + /** * Open an existing file using PIO library. This is an internal * function. Depending on the value of the retry parameter, a failed @@ -2648,6 +2682,16 @@ PIOc_openfile_retry(int iosysid, int *ncidp, int *iotype, const char *filename, /* Return the PIO ncid to the user. */ *ncidp = file->pio_ncid; } + else + { + /* Use the ncid passed in from the netCDF dispatch code. */ + file->pio_ncid = *ncidp; + + /* To prevent PIO from reusing the same ncid, if someone + * starting mingling netcdf integration PIO and regular PIO + * code. */ + pio_next_ncid = file->pio_ncid + 1; + } /* Add this file to the list of currently open files. */ pio_add_to_file_list(file); diff --git a/src/ncint/ncintdispatch.c b/src/ncint/ncintdispatch.c index 9150e9f8c45..317fdef9fe1 100644 --- a/src/ncint/ncintdispatch.c +++ b/src/ncint/ncintdispatch.c @@ -8,7 +8,13 @@ #include "config.h" #include #include "ncintdispatch.h" +#include "nc4dispatch.h" +#include "nc4internal.h" #include "pio.h" +#include "pio_internal.h" + +/** Default iosysid. */ +int diosysid; /* This is the dispatch object that holds pointers to all the * functions that make up the NCINT dispatch interface. */ @@ -129,27 +135,37 @@ NC_NCINT_finalize(void) return NC_NOERR; } -/** Default iosysid. */ -int diosysid; - #define TEST_VAL_42 42 int NC_NCINT_open(const char *path, int mode, int basepe, size_t *chunksizehintp, void *parameters, const NC_Dispatch *dispatch, NC *nc_file) { + int iotype; + iosystem_desc_t *ios; /* Pointer to io system information. */ int ret; - nc_file->int_ncid = nc_file->ext_ncid; + + LOG((1, "NC_NCINT_open path = %s mode = %x", path, mode)); + + /* Get the IO system info from the id. */ + if (!(ios = pio_get_iosystem_from_id(diosysid))) + return pio_err(NULL, NULL, PIO_EBADID, __FILE__, __LINE__); /* Turn of NC_UDF0 in the mode flag. */ mode = mode & ~NC_UDF0; - /* /\* Add necessary structs to hold netcdf-4 file data. *\/ */ - /* if ((retval = nc4_nc4f_list_add(nc_file, path, mode))) */ - /* return retval; */ + /* Find the IOTYPE from the mode flag. */ + if ((ret = find_iotype_from_omode(mode, &iotype))) + return pio_err(ios, NULL, ret, __FILE__, __LINE__); + + /* Add necessary structs to hold netcdf-4 file data. */ + if ((ret = nc4_nc4f_list_add(nc_file, path, mode))) + return ret; - /* /\* Open the file with PIO. *\/ */ - /* if ((ret = PIOc_open(diosysid, path, mode, &nc_file->ext_ncid))) */ - /* 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))) + return ret; return NC_NOERR; } diff --git a/tests/ncint/tst_pio_udf.c b/tests/ncint/tst_pio_udf.c index 0d2d80cc8f8..caa43b8c384 100644 --- a/tests/ncint/tst_pio_udf.c +++ b/tests/ncint/tst_pio_udf.c @@ -51,14 +51,8 @@ main(int argc, char **argv) PIOc_set_log_level(3); /* Open file with our defined functions. */ - /* if (nc_open(FILE_NAME, NC_UDF0, &ncid)) ERR; */ - /* if (nc_close(ncid)) ERR; */ - - /* /\* Open file again and abort, which is the same as closing it. *\/ */ - /* if (nc_open(FILE_NAME, NC_UDF0, &ncid)) ERR; */ - /* if (nc_inq_format(ncid, NULL) != TEST_VAL_42) ERR; */ - /* if (nc_inq_format_extended(ncid, NULL, NULL) != TEST_VAL_42) ERR; */ - /* if (nc_abort(ncid) != TEST_VAL_42) ERR; */ + if (nc_open(FILE_NAME, NC_UDF0, &ncid)) ERR; + if (nc_close(ncid)) ERR; /* Close the iosystem. */ if (nc_free_iosystem(iosysid)) ERR;