diff --git a/src/clib/pio_file.c b/src/clib/pio_file.c index 85cdfa69075..15defd6f5f8 100644 --- a/src/clib/pio_file.c +++ b/src/clib/pio_file.c @@ -187,27 +187,24 @@ PIOc_createfile(int iosysid, int *ncidp, int *iotype, const char *filename, * @author Ed Hartnett */ int -PIOc_create(int iosysid, const char *filename, int cmode, int *ncidp) +PIOc_create(int iosysid, const char *path, int cmode, int *ncidp) { int iotype; /* The PIO IO type. */ + iosystem_desc_t *ios; /* Pointer to io system information. */ + int ret; - /* Figure out the iotype. */ - if (cmode & NC_NETCDF4) - { - if (cmode & NC_MPIIO || cmode & NC_MPIPOSIX) - iotype = PIO_IOTYPE_NETCDF4P; - else - iotype = PIO_IOTYPE_NETCDF4C; - } - else - { - if (cmode & NC_PNETCDF || cmode & NC_MPIIO) - iotype = PIO_IOTYPE_PNETCDF; - else - iotype = PIO_IOTYPE_NETCDF; - } + PLOG((1, "PIOc_create iosysid = %d path = %s cmode = %x", iosysid, path, + cmode)); + + /* 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_cmode(cmode, &iotype))) + return pio_err(ios, NULL, ret, __FILE__, __LINE__); - return PIOc_createfile_int(iosysid, ncidp, &iotype, filename, cmode); + return PIOc_createfile_int(iosysid, ncidp, &iotype, path, cmode); } /** diff --git a/src/clib/pio_internal.h b/src/clib/pio_internal.h index f24f60512a0..87140f50660 100644 --- a/src/clib/pio_internal.h +++ b/src/clib/pio_internal.h @@ -197,6 +197,9 @@ extern "C" { /* Give the mode flag from an open, determine the IOTYPE. */ int find_iotype_from_omode(int mode, int *iotype); + /* Give the mode flag from an nc_create call, determine the IOTYPE. */ + int find_iotype_from_cmode(int cmode, 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 4736ac5165e..e3e809dbc97 100644 --- a/src/clib/pioc_support.c +++ b/src/clib/pioc_support.c @@ -1,7 +1,7 @@ /** @file * Support functions for the PIO library. */ -#include +#include "config.h" #if PIO_ENABLE_LOGGING #include #include @@ -2398,6 +2398,41 @@ find_iotype_from_omode(int mode, int *iotype) return PIO_NOERR; } + +/** + * Find the appropriate IOTYPE from mode flags to nc_create(). + * + * @param mode the mode flag from nc_create(). + * @param iotype pointer that gets the IOTYPE. + * + * @return 0 on success, error code otherwise. + * @author Ed Hartnett + */ +int +find_iotype_from_cmode(int cmode, int *iotype) +{ + /* Check inputs. */ + pioassert(iotype, "pointer to iotype must be provided", __FILE__, __LINE__); + + /* Figure out the iotype. */ + if (cmode & NC_NETCDF4) + { + if (cmode & NC_MPIIO || cmode & NC_MPIPOSIX) + *iotype = PIO_IOTYPE_NETCDF4P; + else + *iotype = PIO_IOTYPE_NETCDF4C; + } + else + { + if (cmode & NC_PNETCDF || cmode & 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 diff --git a/src/ncint/ncintdispatch.c b/src/ncint/ncintdispatch.c index 7518fb2f1a0..6e1f45e5a33 100644 --- a/src/ncint/ncintdispatch.c +++ b/src/ncint/ncintdispatch.c @@ -20,9 +20,9 @@ int diosysid; * functions that make up the NCINT dispatch interface. */ NC_Dispatch NCINT_dispatcher = { - NC_FORMATX_NC_HDF4, + NC_FORMATX_NC_UDF0, - NC_RO_create, + NC_NCINT_create, NC_NCINT_open, NC_RO_redef, @@ -170,6 +170,41 @@ NC_NCINT_open(const char *path, int mode, int basepe, size_t *chunksizehintp, return NC_NOERR; } +int +NC_NCINT_create(const char* path, int cmode, size_t initialsz, 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; + + LOG((1, "NC_NCINT_create 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. */ + cmode = cmode & ~NC_UDF0; + + /* 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. Tell openfile_retry to accept the + * externally assigned ncid. */ + if ((ret = PIOc_createfile_int(diosysid, &nc_file->ext_ncid, iotype, + path, cmode))) + return ret; + + return PIO_NOERR; +} + int NC_NCINT_abort(int ncid) {