Skip to content

Commit

Permalink
got create working with netcdf integration layer
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Jul 5, 2019
1 parent ff53bf5 commit 92dd174
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/clib/pio_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ PIOc_createfile(int iosysid, int *ncidp, int *iotype, const char *filename,
iosysid, *iotype, filename, mode));

/* Create the file. */
if ((ret = PIOc_createfile_int(iosysid, ncidp, iotype, filename, mode)))
if ((ret = PIOc_createfile_int(iosysid, ncidp, iotype, filename, mode, 0)))
return pio_err(ios, NULL, ret, __FILE__, __LINE__);

/* Run this on all tasks if async is not in use, but only on
Expand Down Expand Up @@ -204,7 +204,7 @@ PIOc_create(int iosysid, const char *path, int cmode, int *ncidp)
if ((ret = find_iotype_from_cmode(cmode, &iotype)))
return pio_err(ios, NULL, ret, __FILE__, __LINE__);

return PIOc_createfile_int(iosysid, ncidp, &iotype, path, cmode);
return PIOc_createfile_int(iosysid, ncidp, &iotype, path, cmode, 0);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/clib/pio_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ extern "C" {
int delete_var_desc(int varid, var_desc_t **varlist);

/* Create a file (internal function). */
int PIOc_createfile_int(int iosysid, int *ncidp, int *iotype, const char *filename, int mode);
int PIOc_createfile_int(int iosysid, int *ncidp, int *iotype, const char *filename,
int mode, int use_ext_ncid);

/* Open a file with optional retry as netCDF-classic if first
* iotype does not work. */
Expand Down
31 changes: 25 additions & 6 deletions src/clib/pioc_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -1935,13 +1935,16 @@ PIOc_writemap_from_f90(const char *file, int ndims, const int *gdims,
* PIO_IOTYPE_NETCDF4P.
* @param filename The filename to create.
* @param mode The netcdf mode for the create operation.
* @paran use_ext_ncid non-zero to use an externally assigned ncid
* (used in the netcdf integration layer).
*
* @returns 0 for success, error code otherwise.
* @ingroup PIO_createfile_c
* @author Ed Hartnett
*/
int
PIOc_createfile_int(int iosysid, int *ncidp, int *iotype, const char *filename,
int mode)
int mode, int use_ext_ncid)
{
iosystem_desc_t *ios; /* Pointer to io system information. */
file_desc_t *file; /* Pointer to file information. */
Expand Down Expand Up @@ -2082,12 +2085,28 @@ PIOc_createfile_int(int iosysid, int *ncidp, int *iotype, const char *filename,
PLOG((3, "createfile bcast pio_next_ncid %d", pio_next_ncid));
}

/* Assign the PIO ncid. */
file->pio_ncid = pio_next_ncid++;
PLOG((2, "file->fh = %d file->pio_ncid = %d", file->fh, file->pio_ncid));
/* With the netCDF integration layer, the ncid is assigned for PIO
* by the netCDF dispatch layer code. So it is passed in. In
* normal PIO operation, the ncid is generated here. */
if (use_ext_ncid)
{
/* 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;
}
else
{
/* Assign the PIO ncid. */
file->pio_ncid = pio_next_ncid++;
PLOG((2, "file->fh = %d file->pio_ncid = %d", file->fh, file->pio_ncid));

/* Return the ncid to the caller. */
*ncidp = file->pio_ncid;
/* Return the ncid to the caller. */
*ncidp = file->pio_ncid;
}

/* Add the struct with this files info to the global list of
* open files. */
Expand Down
2 changes: 1 addition & 1 deletion src/ncint/ncintdispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ NC_NCINT_create(const char* path, int cmode, size_t initialsz, int basepe,
/* 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)))
path, cmode, 1)))
return ret;

return PIO_NOERR;
Expand Down
10 changes: 5 additions & 5 deletions tests/ncint/tst_pio_udf.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@ main(int argc, char **argv)
NC_Dispatch *disp_in;

/* Create an empty file to play with. */
if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR;
if (nc_close(ncid)) ERR;
/* if (nc_create(FILE_NAME, NC_CLOBBER, &ncid)) ERR; */
/* if (nc_close(ncid)) ERR; */

PIOc_set_log_level(3);
/* Initialize the intracomm. */
if (nc_init_intracomm(MPI_COMM_WORLD, 1, 1, 0, 0, &iosysid)) ERR;

/* Add our user defined format. */
if (nc_def_user_format(NC_UDF0, &NCINT_dispatcher, NULL)) ERR;

/* Create an empty file to play with. */
/* if (nc_create(FILE_NAME, NC_UDF0, &ncid)) ERR; */
/* if (nc_close(ncid)) ERR; */
if (nc_create(FILE_NAME, NC_UDF0, &ncid)) ERR;
if (nc_close(ncid)) ERR;

/* Check that our user-defined format has been added. */
if (nc_inq_user_format(NC_UDF0, &disp_in, NULL)) ERR;
if (disp_in != &NCINT_dispatcher) ERR;
PIOc_set_log_level(3);

/* Open file with our defined functions. */
if (nc_open(FILE_NAME, NC_UDF0, &ncid)) ERR;
Expand Down

0 comments on commit 92dd174

Please sign in to comment.