Skip to content

Commit

Permalink
changed open/create to use ncid as final parameter instead of NC *
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Aug 2, 2019
1 parent b28779c commit 1a11dbf
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/clib/pio_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/clib/pioc_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
34 changes: 21 additions & 13 deletions src/ncint/ncintdispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,18 @@ 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
*/
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;
Expand All @@ -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;
Expand All @@ -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.
Expand All @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/ncint/ncintdispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions tests/cunit/test_darray.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down
2 changes: 1 addition & 1 deletion tests/cunit/test_iosystem2_simple.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1a11dbf

Please sign in to comment.