Skip to content

Commit

Permalink
is it working?
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Jul 5, 2019
1 parent a3f925b commit 886fee6
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 42 deletions.
51 changes: 27 additions & 24 deletions src/clib/pio_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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. */
Expand All @@ -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. */
Expand Down Expand Up @@ -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. */

Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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. */
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 @@ -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);

Expand Down
44 changes: 44 additions & 0 deletions src/clib/pioc_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
36 changes: 26 additions & 10 deletions src/ncint/ncintdispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
#include "config.h"
#include <stdlib.h>
#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. */
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 2 additions & 8 deletions tests/ncint/tst_pio_udf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 886fee6

Please sign in to comment.