Skip to content

Commit

Permalink
adding create to netcdf integration layer
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Jul 5, 2019
1 parent 20bd34f commit 2570fb4
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 20 deletions.
31 changes: 14 additions & 17 deletions src/clib/pio_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/clib/pio_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
37 changes: 36 additions & 1 deletion src/clib/pioc_support.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @file
* Support functions for the PIO library.
*/
#include <config.h>
#include "config.h"
#if PIO_ENABLE_LOGGING
#include <stdarg.h>
#include <unistd.h>
Expand Down Expand Up @@ -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
Expand Down
39 changes: 37 additions & 2 deletions src/ncint/ncintdispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 2570fb4

Please sign in to comment.