This commit fixes the logical problem of using the default file formats.

The fix includes the following changes.
1. Checking and using the default file format at file create time is now
   done only when the create mode (argument cmode) does not include any
   format related flags, i.e. NC_64BIT_OFFSET, NC_64BIT_DATA,
   NC_CLASSIC_MODEL, and NC_NETCDF4.
2. Adjustment of cmode based on the default format is now done in
   NC_create() only. The idea is to adjust cmode before entering the
   dispatcher's file create subroutine.
3. Any adjustment of cmode is removed from all I/O dispatchers, i.e.
   NC4_create(), NC3_create(), and NCP_create().
4. Checking for illegal cmode has been done in check_create_mode() called
   in NC_create(). This commit removes the redundant checking from
   NCP_create().
5. Remove PnetCDF tests in nc_test/tst_names.c, so it can focus on testing
   all classic formats and netCDF4 formats.

Two new test programs are added. They can be used to test netCDF with and
without this commit.
1. nc_test/tst_default_format.c
2. nc_test/tst_default_format_pnetcdf.c (use when PnetCDF is enabled).
This commit is contained in:
Wei-keng Liao 2018-07-28 02:49:07 -05:00
parent ac805e3ebd
commit 0ee68a3263
12 changed files with 446 additions and 111 deletions

View File

@ -896,8 +896,8 @@ nc_inq_var_filter(int ncid, int varid, unsigned int* idp, size_t* nparams, unsig
EXTERNL int
nc_set_fill(int ncid, int fillmode, int *old_modep);
/* Set the default nc_create format to NC_FORMAT_CLASSIC,
* NC_FORMAT_64BIT, NC_FORMAT_NETCDF4, etc */
/* Set the default nc_create format to NC_FORMAT_CLASSIC, NC_FORMAT_64BIT,
* NC_FORMAT_CDF5, NC_FORMAT_NETCDF4, or NC_FORMAT_NETCDF4_CLASSIC */
EXTERNL int
nc_set_default_format(int format, int *old_formatp);

View File

@ -29,6 +29,7 @@
#include "ncdispatch.h"
#include "netcdf_mem.h"
#include "ncwinpath.h"
#include "fbits.h"
/* If Defined, then use only stdio for all magic number io;
otherwise use stdio or mpio as required.
@ -2027,7 +2028,6 @@ NC_create(const char *path0, int cmode, size_t initialsz,
/* Need three pieces of information for now */
int model = NC_FORMATX_UNDEFINED; /* one of the NC_FORMATX values */
int isurl = 0; /* dap or cdmremote or neither */
int xcmode = 0; /* for implied cmode flags */
char* path = NULL;
TRACE(nc_create);
@ -2073,66 +2073,49 @@ NC_create(const char *path0, int cmode, size_t initialsz,
}
}
/* Look to the incoming cmode for hints */
if(model == NC_FORMATX_UNDEFINED) {
/* determine the model */
#ifdef USE_NETCDF4
if((cmode & NC_NETCDF4) == NC_NETCDF4)
model = NC_FORMATX_NC4;
else
if (model == NC_FORMATX_UNDEFINED && ((cmode & NC_NETCDF4) == NC_NETCDF4))
model = NC_FORMATX_NC4;
#endif
#ifdef USE_PNETCDF
/* pnetcdf is used for parallel io on CDF-1, CDF-2, and CDF-5 */
if((cmode & NC_MPIIO) == NC_MPIIO)
model = NC_FORMATX_PNETCDF;
else
if (model == NC_FORMATX_UNDEFINED && ((cmode & NC_MPIIO) == NC_MPIIO))
/* pnetcdf is used for parallel io on CDF-1, CDF-2, and CDF-5 */
model = NC_FORMATX_PNETCDF;
#endif
{}
}
if(model == NC_FORMATX_UNDEFINED) {
/* Check default format (not formatx) */
int format = nc_get_default_format();
switch (format) {
/* Check default format (not formatx) */
if (!fIsSet(cmode, NC_64BIT_OFFSET) && !fIsSet(cmode, NC_64BIT_DATA) &&
!fIsSet(cmode, NC_CLASSIC_MODEL) && !fIsSet(cmode, NC_NETCDF4)) {
/* if no file format flag is set in cmode, use default */
int format = nc_get_default_format();
switch (format) {
#ifdef USE_NETCDF4
case NC_FORMAT_NETCDF4:
xcmode |= NC_NETCDF4;
model = NC_FORMATX_NC4;
break;
case NC_FORMAT_NETCDF4_CLASSIC:
xcmode |= NC_CLASSIC_MODEL;
model = NC_FORMATX_NC4;
break;
case NC_FORMAT_NETCDF4:
cmode |= NC_NETCDF4;
if (model == NC_FORMATX_UNDEFINED) model = NC_FORMATX_NC4;
break;
case NC_FORMAT_NETCDF4_CLASSIC:
cmode |= NC_NETCDF4 | NC_CLASSIC_MODEL;
if (model == NC_FORMATX_UNDEFINED) model = NC_FORMATX_NC4;
break;
#endif
#ifdef ENABLE_CDF5
case NC_FORMAT_CDF5:
xcmode |= NC_64BIT_DATA;
model = NC_FORMATX_NC3;
break;
case NC_FORMAT_CDF5:
cmode |= NC_64BIT_DATA;
break;
#endif
case NC_FORMAT_64BIT_OFFSET:
xcmode |= NC_64BIT_OFFSET;
model = NC_FORMATX_NC3;
break;
case NC_FORMAT_CLASSIC:
model = NC_FORMATX_NC3;
break;
default:
model = NC_FORMATX_NC3;
break;
}
}
case NC_FORMAT_64BIT_OFFSET:
cmode |= NC_64BIT_OFFSET;
break;
case NC_FORMAT_CLASSIC: break;
default: break;
}
}
/* Add inferred flags */
cmode |= xcmode;
/* Clean up illegal combinations */
if((cmode & (NC_64BIT_OFFSET|NC_64BIT_DATA)) == (NC_64BIT_OFFSET|NC_64BIT_DATA))
cmode &= ~(NC_64BIT_OFFSET); /*NC_64BIT_DATA=>NC_64BIT_OFFSET*/
if((cmode & NC_MPIIO) && (cmode & NC_MPIPOSIX))
{
nullfree(path);
return NC_EINVAL;
}
/* default model */
if (model == NC_FORMATX_UNDEFINED)
model = NC_FORMATX_NC3;
if (dispatcher == NULL)
{

View File

@ -92,11 +92,11 @@ nc_set_default_format(int format, int *old_formatp)
format != NC_FORMAT_NETCDF4 && format != NC_FORMAT_NETCDF4_CLASSIC &&
format != NC_FORMAT_CDF5)
return NC_EINVAL;
#else
#else
if (format != NC_FORMAT_CLASSIC && format != NC_FORMAT_64BIT_OFFSET &&
format != NC_FORMAT_CDF5)
return NC_EINVAL;
#endif
#endif
default_create_format = format;
return NC_NOERR;
}

View File

@ -307,18 +307,6 @@ NC4_create(const char* path, int cmode, size_t initialsz, int basepe,
}
#endif /* USE_PARALLEL_POSIX */
cmode |= NC_NETCDF4;
/* Apply default create format. */
if (nc_get_default_format() == NC_FORMAT_CDF5)
cmode |= NC_CDF5;
else if (nc_get_default_format() == NC_FORMAT_64BIT_OFFSET)
cmode |= NC_64BIT_OFFSET;
else if (nc_get_default_format() == NC_FORMAT_NETCDF4_CLASSIC)
cmode |= NC_CLASSIC_MODEL;
LOG((2, "cmode after applying default format: 0x%x", cmode));
nc_file->int_ncid = nc_file->ext_ncid;
res = nc4_create_file(path, cmode, initialsz, parameters, nc_file);

View File

@ -1072,12 +1072,6 @@ NC3_create(const char *path, int ioflags,
assert(nc3->flags == 0);
/* Apply default create format. */
if (nc_get_default_format() == NC_FORMAT_64BIT_OFFSET)
ioflags |= NC_64BIT_OFFSET;
else if (nc_get_default_format() == NC_FORMAT_CDF5)
ioflags |= NC_64BIT_DATA;
/* Now we can set min size */
if (fIsSet(ioflags, NC_64BIT_DATA))
nc3->xsz = MIN_NC5_XSZ; /* CDF-5 has minimum 16 extra bytes */

View File

@ -53,25 +53,6 @@ NCP_create(const char *path, int cmode,
if(cmode & ~LEGAL_CREATE_FLAGS)
{res = NC_EINVAL; goto done;}
/* Cannot have both MPIO flags */
if((cmode & (NC_MPIIO|NC_MPIPOSIX)) == (NC_MPIIO|NC_MPIPOSIX))
{res = NC_EINVAL; goto done;}
/* Cannot have both NC_64BIT_OFFSET & NC_64BIT_DATA */
if((cmode & (NC_64BIT_OFFSET|NC_64BIT_DATA)) == (NC_64BIT_OFFSET|NC_64BIT_DATA))
{res = NC_EINVAL; goto done;}
default_format = nc_get_default_format();
/* if (default_format == NC_FORMAT_CLASSIC) then we respect the format set in cmode */
if (default_format == NC_FORMAT_64BIT_OFFSET) {
if (! (cmode & NC_64BIT_OFFSET)) /* check if cmode has NC_64BIT_OFFSET already */
cmode |= NC_64BIT_OFFSET;
}
else if (default_format == NC_FORMAT_CDF5) {
if (! (cmode & NC_64BIT_DATA)) /* check if cmode has NC_64BIT_DATA already */
cmode |= NC_64BIT_DATA;
}
/* No MPI environment initialized */
if (mpidata == NULL)
{res = NC_ENOPAR; goto done;}

View File

@ -30,7 +30,7 @@ TARGET_LINK_LIBRARIES(nc_test
)
# Some extra stand-alone tests
SET(TESTS t_nc tst_small tst_misc tst_norm tst_names tst_nofill tst_nofill2 tst_nofill3 tst_meta tst_inq_type tst_utf8_validate tst_utf8_phrases tst_global_fillval tst_max_var_dims tst_formats tst_def_var_fill tst_err_enddef)
SET(TESTS t_nc tst_small tst_misc tst_norm tst_names tst_nofill tst_nofill2 tst_nofill3 tst_meta tst_inq_type tst_utf8_validate tst_utf8_phrases tst_global_fillval tst_max_var_dims tst_formats tst_def_var_fill tst_err_enddef tst_default_format)
IF(NOT HAVE_BASH)
SET(TESTS ${TESTS} tst_atts3)
@ -42,6 +42,7 @@ IF(USE_PNETCDF)
build_bin_test_no_prefix(tst_addvar)
add_sh_test(nc_test run_pnetcdf_test)
add_bin_test(nc_test tst_formatx_pnetcdf)
add_bin_test(nc_test tst_default_format_pnetcdf)
ENDIF()
IF(LARGE_FILE_TESTS)

View File

@ -19,10 +19,12 @@ TEST_EXTENSIONS = .sh
TESTPROGRAMS = t_nc tst_small nc_test tst_misc tst_norm tst_names \
tst_nofill tst_nofill2 tst_nofill3 tst_atts3 tst_meta tst_inq_type \
tst_utf8_validate tst_utf8_phrases tst_global_fillval \
tst_max_var_dims tst_formats tst_def_var_fill tst_err_enddef
tst_max_var_dims tst_formats tst_def_var_fill tst_err_enddef \
tst_default_format
if USE_PNETCDF
TESTPROGRAMS += tst_parallel2 tst_pnetcdf tst_addvar tst_formatx_pnetcdf
TESTPROGRAMS += tst_parallel2 tst_pnetcdf tst_addvar tst_formatx_pnetcdf \
tst_default_format_pnetcdf
endif
if TEST_PARALLEL4

View File

@ -0,0 +1,220 @@
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <netcdf.h>
#define ERR { \
if (err != NC_NOERR) { \
printf("Error at %s line %d: %s\n", __FILE__, __LINE__, \
nc_strerror(err)); \
nerrs++; \
} \
}
static int default_format;
static int
create_check(char *fname, int cmode, int exp_format)
{
int nerrs=0, err, ncid, format;
char *exp_str;
switch (exp_format) {
case NC_FORMAT_CLASSIC: exp_str="NC_FORMAT_CLASSIC"; break;
case NC_FORMAT_64BIT_OFFSET: exp_str="NC_FORMAT_64BIT_OFFSET"; break;
case NC_FORMAT_64BIT_DATA: exp_str="NC_FORMAT_64BIT_DATA"; break;
case NC_FORMAT_NETCDF4: exp_str="NC_FORMAT_NETCDF4"; break;
case NC_FORMAT_NETCDF4_CLASSIC:
exp_str="NC_FORMAT_NETCDF4_CLASSIC";break;
default: break;
}
/* create a file */
cmode |= NC_CLOBBER;
err = nc_create(fname, cmode, &ncid); ERR
err = nc_close(ncid); ERR
/* open the file and check its format */
err = nc_open(fname, NC_NOWRITE, &ncid); ERR
err = nc_inq_format(ncid, &format); ERR
if (format != exp_format) {
char *f_str, *d_str;
switch (format) {
case NC_FORMAT_CLASSIC: f_str = "NC_FORMAT_CLASSIC";
break;
case NC_FORMAT_64BIT_OFFSET: f_str = "NC_FORMAT_64BIT_OFFSET";
break;
case NC_FORMAT_64BIT_DATA: f_str = "NC_FORMAT_64BIT_DATA";
break;
case NC_FORMAT_NETCDF4: f_str = "NC_FORMAT_NETCDF4";
break;
case NC_FORMAT_NETCDF4_CLASSIC: f_str = "NC_FORMAT_NETCDF4_CLASSIC";
break;
default: break;
}
switch (default_format) {
case NC_FORMAT_CLASSIC: d_str = "NC_FORMAT_CLASSIC";
break;
case NC_FORMAT_64BIT_OFFSET: d_str = "NC_FORMAT_64BIT_OFFSET";
break;
case NC_FORMAT_64BIT_DATA: d_str = "NC_FORMAT_64BIT_DATA";
break;
case NC_FORMAT_NETCDF4: d_str = "NC_FORMAT_NETCDF4";
break;
case NC_FORMAT_NETCDF4_CLASSIC: d_str = "NC_FORMAT_NETCDF4_CLASSIC";
break;
default: break;
}
printf("Error at %s line %d: default is %s and expect %s but got %s\n",
__FILE__, __LINE__, d_str, exp_str, f_str);
nerrs++;
}
err = nc_close(ncid); ERR
return nerrs;
}
int main(int argc, char *argv[])
{
char *fname="tst_default_format.nc";
int err, nerrs=0, ncid, cmode, format;
if (argc == 2) fname = argv[1];
default_format = NC_FORMAT_CLASSIC;
/* check illegal cmode */
cmode = NC_64BIT_OFFSET | NC_64BIT_DATA;
err = nc_create(fname, cmode, &ncid);
if (err != NC_EINVAL) {
printf("Error at %s line %d: expect NC_EINVAL but got %d\n",
__FILE__, __LINE__, err);
nerrs++;
}
/* check illegal cmode */
cmode = NC_NETCDF4 | NC_64BIT_OFFSET;
err = nc_create(fname, cmode, &ncid);
if (err != NC_EINVAL) {
printf("Error at %s line %d: expect NC_EINVAL but got %d\n",
__FILE__, __LINE__, err);
nerrs++;
}
/* check illegal cmode */
cmode = NC_MPIIO | NC_MPIPOSIX;
err = nc_create(fname, cmode, &ncid);
if (err != NC_EINVAL) {
printf("Error at %s line %d: expect NC_EINVAL but got %d\n",
__FILE__, __LINE__, err);
nerrs++;
}
/* check illegal cmode */
cmode = NC_MPIIO | NC_DISKLESS;
err = nc_create(fname, cmode, &ncid);
if (err != NC_EINVAL) {
printf("Error at %s line %d: expect NC_EINVAL but got %d\n",
__FILE__, __LINE__, err);
nerrs++;
}
/* check illegal cmode */
cmode = NC_MPIPOSIX | NC_DISKLESS;
err = nc_create(fname, cmode, &ncid);
if (err != NC_EINVAL) {
printf("Error at %s line %d: expect NC_EINVAL but got %d\n",
__FILE__, __LINE__, err);
nerrs++;
}
/* create a file in CDF1 format */
cmode = 0;
nerrs += create_check(fname, cmode, NC_FORMAT_CLASSIC);
/* create a file in CDF2 format */
cmode = NC_64BIT_OFFSET;
nerrs += create_check(fname, cmode, NC_FORMAT_64BIT_OFFSET);
#ifdef ENABLE_CDF5
/* create a file in CDF5 format */
cmode = NC_64BIT_DATA;
nerrs += create_check(fname, cmode, NC_FORMAT_64BIT_DATA);
#endif
/* set default file format to NC_FORMAT_64BIT_OFFSET ------------------*/
default_format = NC_FORMAT_64BIT_OFFSET;
err = nc_set_default_format(default_format, NULL); ERR
/* create a file in default format */
cmode = 0;
nerrs += create_check(fname, cmode, NC_FORMAT_64BIT_OFFSET);
#ifdef ENABLE_CDF5
/* create a file in CDF5 format (this should ignore default) */
cmode = NC_64BIT_DATA;
nerrs += create_check(fname, cmode, NC_FORMAT_64BIT_DATA);
#endif
#ifdef ENABLE_CDF5
/* set default file format to NC_FORMAT_64BIT_DATA --------------------*/
default_format = NC_FORMAT_64BIT_DATA;
err = nc_set_default_format(default_format, NULL); ERR
/* create a file in default format */
cmode = 0;
nerrs += create_check(fname, cmode, NC_FORMAT_64BIT_DATA);
/* create a file in CDF2 format (this should ignore default) */
cmode = NC_64BIT_OFFSET;
nerrs += create_check(fname, cmode, NC_FORMAT_64BIT_OFFSET);
#endif
#ifdef USE_NETCDF4
/* set default file format to NC_FORMAT_NETCDF4 -----------------------*/
default_format = NC_FORMAT_NETCDF4;
err = nc_set_default_format(default_format, NULL); ERR
/* create a file in default format */
cmode = 0;
nerrs += create_check(fname, cmode, NC_FORMAT_NETCDF4);
/* create a file in CDF2 format (this should ignore default) */
cmode = NC_64BIT_OFFSET;
nerrs += create_check(fname, cmode, NC_FORMAT_64BIT_OFFSET);
/* set default file format to NC_FORMAT_NETCDF4_CLASSIC ---------------*/
default_format = NC_FORMAT_NETCDF4_CLASSIC;
err = nc_set_default_format(default_format, NULL); ERR
/* create a file in default format */
cmode = 0;
nerrs += create_check(fname, cmode, NC_FORMAT_NETCDF4_CLASSIC);
/* create a file in NETCDF4 format (this should ignore default) */
cmode = NC_NETCDF4;
nerrs += create_check(fname, cmode, NC_FORMAT_NETCDF4);
/* create a file in CDF2 format (this should ignore default) */
cmode = NC_64BIT_OFFSET;
nerrs += create_check(fname, cmode, NC_FORMAT_64BIT_OFFSET);
/* set default file format to NC_FORMAT_NETCDF4 -----------------------*/
default_format = NC_FORMAT_NETCDF4;
err = nc_set_default_format(default_format, NULL); ERR
/* create a file in default format */
cmode = 0;
nerrs += create_check(fname, cmode, NC_FORMAT_NETCDF4);
/* create a file in NETCDF4 format (this should ignore default) */
cmode = NC_NETCDF4 | NC_CLASSIC_MODEL;
nerrs += create_check(fname, cmode, NC_FORMAT_NETCDF4_CLASSIC);
/* create a file in CDF2 format (this should ignore default) */
cmode = NC_64BIT_OFFSET;
nerrs += create_check(fname, cmode, NC_FORMAT_64BIT_OFFSET);
#endif
return (nerrs > 0);
}

View File

@ -0,0 +1,174 @@
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <netcdf.h>
#include <netcdf_par.h>
#define ERR { \
if (err != NC_NOERR) { \
printf("Error at %s line %d: %s\n", __FILE__, __LINE__, \
nc_strerror(err)); \
nerrs++; \
} \
}
static int default_format;
static int
create_check_pnetcdf(char *fname, int cmode, int exp_format)
{
int nerrs=0, err, ncid, format;
char *exp_str;
cmode |= NC_MPIIO;
switch (exp_format) {
case NC_FORMAT_CLASSIC: exp_str="NC_FORMAT_CLASSIC"; break;
case NC_FORMAT_64BIT_OFFSET: exp_str="NC_FORMAT_64BIT_OFFSET"; break;
case NC_FORMAT_64BIT_DATA: exp_str="NC_FORMAT_64BIT_DATA"; break;
case NC_FORMAT_NETCDF4: exp_str="NC_FORMAT_NETCDF4"; break;
case NC_FORMAT_NETCDF4_CLASSIC:
exp_str="NC_FORMAT_NETCDF4_CLASSIC";break;
default: break;
}
/* create a file */
cmode |= NC_CLOBBER;
err = nc_create_par(fname, cmode, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid); ERR
err = nc_close(ncid); ERR
/* open the file and check its format */
err = nc_open(fname, NC_NOWRITE, &ncid); ERR
err = nc_inq_format(ncid, &format); ERR
if (format != exp_format) {
char *f_str, *d_str;
switch (format) {
case NC_FORMAT_CLASSIC: f_str = "NC_FORMAT_CLASSIC";
break;
case NC_FORMAT_64BIT_OFFSET: f_str = "NC_FORMAT_64BIT_OFFSET";
break;
case NC_FORMAT_64BIT_DATA: f_str = "NC_FORMAT_64BIT_DATA";
break;
case NC_FORMAT_NETCDF4: f_str = "NC_FORMAT_NETCDF4";
break;
case NC_FORMAT_NETCDF4_CLASSIC: f_str = "NC_FORMAT_NETCDF4_CLASSIC";
break;
default: break;
}
switch (default_format) {
case NC_FORMAT_CLASSIC: d_str = "NC_FORMAT_CLASSIC";
break;
case NC_FORMAT_64BIT_OFFSET: d_str = "NC_FORMAT_64BIT_OFFSET";
break;
case NC_FORMAT_64BIT_DATA: d_str = "NC_FORMAT_64BIT_DATA";
break;
case NC_FORMAT_NETCDF4: d_str = "NC_FORMAT_NETCDF4";
break;
case NC_FORMAT_NETCDF4_CLASSIC: d_str = "NC_FORMAT_NETCDF4_CLASSIC";
break;
default: break;
}
printf("Error at %s line %d: default is %s and expect %s but got %s\n",
__FILE__, __LINE__, d_str, exp_str, f_str);
nerrs++;
}
err = nc_close(ncid); ERR
return nerrs;
}
int main(int argc, char *argv[])
{
char *fname="tst_default_format.nc";
int err, nerrs=0, ncid, cmode, format;
MPI_Init(&argc, &argv);
if (argc == 2) fname = argv[1];
default_format = NC_FORMAT_CLASSIC;
/* check illegal cmode */
cmode = NC_64BIT_OFFSET | NC_64BIT_DATA;
err = nc_create_par(fname, cmode, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid);
if (err != NC_EINVAL) {
printf("Error at %s line %d: expect NC_EINVAL but got %d\n",
__FILE__, __LINE__, err);
nerrs++;
}
/* check illegal cmode */
cmode = NC_NETCDF4 | NC_64BIT_OFFSET;
err = nc_create_par(fname, cmode, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid);
if (err != NC_EINVAL) {
printf("Error at %s line %d: expect NC_EINVAL but got %d\n",
__FILE__, __LINE__, err);
nerrs++;
}
/* check illegal cmode */
cmode = NC_MPIIO | NC_MPIPOSIX;
err = nc_create_par(fname, cmode, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid);
if (err != NC_EINVAL) {
printf("Error at %s line %d: expect NC_EINVAL but got %d\n",
__FILE__, __LINE__, err);
nerrs++;
}
/* check illegal cmode */
cmode = NC_MPIIO | NC_DISKLESS;
err = nc_create_par(fname, cmode, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid);
if (err != NC_EINVAL) {
printf("Error at %s line %d: expect NC_EINVAL but got %d\n",
__FILE__, __LINE__, err);
nerrs++;
}
/* check illegal cmode */
cmode = NC_MPIPOSIX | NC_DISKLESS;
err = nc_create_par(fname, cmode, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid);
if (err != NC_EINVAL) {
printf("Error at %s line %d: expect NC_EINVAL but got %d\n",
__FILE__, __LINE__, err);
nerrs++;
}
/* create a file in CDF1 format */
cmode = 0;
nerrs += create_check_pnetcdf(fname, cmode, NC_FORMAT_CLASSIC);
/* create a file in CDF2 format */
cmode = NC_64BIT_OFFSET;
nerrs += create_check_pnetcdf(fname, cmode, NC_FORMAT_64BIT_OFFSET);
/* create a file in CDF5 format */
cmode = NC_64BIT_DATA;
nerrs += create_check_pnetcdf(fname, cmode, NC_FORMAT_64BIT_DATA);
/* set default file format to NC_FORMAT_64BIT_OFFSET ------------------*/
default_format = NC_FORMAT_64BIT_OFFSET;
err = nc_set_default_format(default_format, NULL); ERR
/* create a file in default format */
cmode = 0;
nerrs += create_check_pnetcdf(fname, cmode, NC_FORMAT_64BIT_OFFSET);
/* create a file in CDF5 format (this should ignore default) */
cmode = NC_64BIT_DATA;
nerrs += create_check_pnetcdf(fname, cmode, NC_FORMAT_64BIT_DATA);
/* set default file format to NC_FORMAT_64BIT_DATA --------------------*/
default_format = NC_FORMAT_64BIT_DATA;
err = nc_set_default_format(default_format, NULL); ERR
/* create a file in default format */
cmode = 0;
nerrs += create_check_pnetcdf(fname, cmode, NC_FORMAT_64BIT_DATA);
/* create a file in CDF2 format (this should ignore default) */
cmode = NC_64BIT_OFFSET;
nerrs += create_check_pnetcdf(fname, cmode, NC_FORMAT_64BIT_OFFSET);
MPI_Finalize();
return (nerrs > 0);
}

View File

@ -241,20 +241,12 @@ main(int argc, char **argv)
"classic", "64-bit offset", "64-bit data", "netCDF-4/HDF5", "netCDF-4 classic model"
};
#ifdef TEST_PNETCDF
MPI_Init(&argc, &argv);
#endif
printf("\n*** testing names with file %s...\n", testfile);
for (j = 0; j < num_formats; j++)
{
printf("*** switching to netCDF %s format...", format_names[j]);
nc_set_default_format(formats[j], NULL);
#ifdef TEST_PNETCDF
if((res = nc_create_par(testfile, NC_CLOBBER|NC_PNETCDF, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid)))
#else
if((res = nc_create(testfile, NC_CLOBBER, &ncid)))
#endif
ERROR
/* Define dimensions, variables, and attributes with various
@ -302,11 +294,7 @@ main(int argc, char **argv)
ERROR
/* Check it out, make sure all objects with good names were defined OK */
#ifdef TEST_PNETCDF
if ((res = nc_open_par(testfile, NC_NOWRITE|NC_PNETCDF, MPI_COMM_WORLD, MPI_INFO_NULL, &ncid)))
#else
if ((res = nc_open(testfile, NC_NOWRITE, &ncid)))
#endif
ERROR
for (i = 0; i < NUM_GOOD; i++) {
size_t attlen;
@ -336,8 +324,5 @@ main(int argc, char **argv)
total_err += nerrs;
FINAL_RESULTS;
#ifdef TEST_PNETCDF
MPI_Finalize();
#endif
return 0;
}

View File

@ -1404,6 +1404,13 @@ char* nc_err_code_name(int err)
int
test_nc_against_pnetcdf(void)
{
int format;
nc_set_default_format(NC_FORMAT_CLASSIC, &format);
nc_set_default_format(format, NULL); /* restore default */
if (format == NC_FORMAT_NETCDF4 || format == NC_FORMAT_NETCDF4_CLASSIC)
return 1; /* skip test for netcdf4 formats */
#ifdef USE_PNETCDF
int ncid; /* netCDF id */
int err; /* status */