Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions libdispatch/dfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ int
nc_def_user_format(int mode_flag, NC_Dispatch *dispatch_table, char *magic_number)
{
/* Check inputs. */
if (mode_flag != NC_UDF0 && mode_flag != NC_UDF1)
return NC_EINVAL;
if (!dispatch_table)
return NC_EINVAL;
if (magic_number && strlen(magic_number) > NC_MAX_MAGIC_NUMBER_LEN)
Expand All @@ -135,21 +133,29 @@ nc_def_user_format(int mode_flag, NC_Dispatch *dispatch_table, char *magic_numbe
/* Check the version of the dispatch table provided. */
if (dispatch_table->dispatch_version != NC_DISPATCH_VERSION)
return NC_EINVAL;

/* user defined magic numbers not allowed with netcdf3 modes */
if (magic_number && (fIsSet(mode_flag, NC_64BIT_OFFSET) ||
fIsSet(mode_flag, NC_64BIT_DATA) ||
(fIsSet(mode_flag, NC_CLASSIC_MODEL) &&
!fIsSet(mode_flag, NC_NETCDF4))))
return NC_EINVAL;
/* Retain a pointer to the dispatch_table and a copy of the magic
* number, if one was provided. */
switch(mode_flag)
if (fIsSet(mode_flag,NC_UDF0))
{
case NC_UDF0:
UDF0_dispatch_table = dispatch_table;
if (magic_number)
strncpy(UDF0_magic_number, magic_number, NC_MAX_MAGIC_NUMBER_LEN);
break;
case NC_UDF1:
}
else if(fIsSet(mode_flag, NC_UDF1))
{
UDF1_dispatch_table = dispatch_table;
if (magic_number)
strncpy(UDF1_magic_number, magic_number, NC_MAX_MAGIC_NUMBER_LEN);
break;
}
else
{
return NC_EINVAL;
}

return NC_NOERR;
Expand All @@ -175,23 +181,23 @@ int
nc_inq_user_format(int mode_flag, NC_Dispatch **dispatch_table, char *magic_number)
{
/* Check inputs. */
if (mode_flag != NC_UDF0 && mode_flag != NC_UDF1)
return NC_EINVAL;

switch(mode_flag)
if (fIsSet(mode_flag,NC_UDF0))
{
case NC_UDF0:
if (dispatch_table)
*dispatch_table = UDF0_dispatch_table;
if (magic_number)
strncpy(magic_number, UDF0_magic_number, NC_MAX_MAGIC_NUMBER_LEN);
break;
case NC_UDF1:
}
else if(fIsSet(mode_flag,NC_UDF1))
{
if (dispatch_table)
*dispatch_table = UDF1_dispatch_table;
if (magic_number)
strncpy(magic_number, UDF1_magic_number, NC_MAX_MAGIC_NUMBER_LEN);
break;
}
else
{
return NC_EINVAL;
}

return NC_NOERR;
Expand Down
85 changes: 59 additions & 26 deletions libdispatch/dinfermodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ static struct FORMATMODES {
{"classic",NC_FORMATX_NC3,0}, /* ditto */
{"netcdf-4",NC_FORMATX_NC4,NC_FORMAT_NETCDF4},
{"enhanced",NC_FORMATX_NC4,NC_FORMAT_NETCDF4},
{"udf0",NC_FORMATX_UDF0,NC_FORMAT_NETCDF4},
{"udf1",NC_FORMATX_UDF1,NC_FORMAT_NETCDF4},
{"udf0",NC_FORMATX_UDF0,0},
{"udf1",NC_FORMATX_UDF1,0},
{"nczarr",NC_FORMATX_NCZARR,NC_FORMAT_NETCDF4},
{"zarr",NC_FORMATX_NCZARR,NC_FORMAT_NETCDF4},
{"bytes",NC_FORMATX_NC4,NC_FORMAT_NETCDF4}, /* temporary until 3 vs 4 is determined */
Expand Down Expand Up @@ -182,8 +182,8 @@ static struct Readable {
{NC_FORMATX_PNETCDF,1},
{NC_FORMATX_DAP2,0},
{NC_FORMATX_DAP4,0},
{NC_FORMATX_UDF0,0},
{NC_FORMATX_UDF1,0},
{NC_FORMATX_UDF0,1},
{NC_FORMATX_UDF1,1},
{NC_FORMATX_NCZARR,0}, /* eventually make readable */
{0,0},
};
Expand Down Expand Up @@ -762,13 +762,31 @@ NC_omodeinfer(int useparallel, int cmode, NCmodel* model)
* use some of the other flags, like NC_NETCDF4, so we must first
* check NC_UDF0 and NC_UDF1 before checking for any other
* flag. */
if(fIsSet(cmode,(NC_UDF0|NC_UDF1))) {
model->format = NC_FORMAT_NETCDF4;
if(fIsSet(cmode,NC_UDF0)) {
if(fIsSet(cmode, NC_UDF0) || fIsSet(cmode, NC_UDF1))
{
if(fIsSet(cmode, NC_UDF0))
{
model->impl = NC_FORMATX_UDF0;
} else {
model->impl = NC_FORMATX_UDF1;
}
if(fIsSet(cmode,NC_64BIT_OFFSET))
{
model->format = NC_FORMAT_64BIT_OFFSET;
}
else if(fIsSet(cmode,NC_64BIT_DATA))
{
model->format = NC_FORMAT_64BIT_DATA;
}
else if(fIsSet(cmode,NC_NETCDF4))
{
if(fIsSet(cmode,NC_CLASSIC_MODEL))
model->format = NC_FORMAT_NETCDF4_CLASSIC;
else
model->format = NC_FORMAT_NETCDF4;
}
if(! model->format)
model->format = NC_FORMAT_CLASSIC;
goto done;
}

Expand Down Expand Up @@ -981,8 +999,6 @@ NC_infermodel(const char* path, int* omodep, int iscreate, int useparallel, void
case NC_FORMATX_NC4:
case NC_FORMATX_NC_HDF4:
case NC_FORMATX_DAP4:
case NC_FORMATX_UDF0:
case NC_FORMATX_UDF1:
case NC_FORMATX_NCZARR:
omode |= NC_NETCDF4;
if(model->format == NC_FORMAT_NETCDF4_CLASSIC)
Expand All @@ -1001,6 +1017,17 @@ NC_infermodel(const char* path, int* omodep, int iscreate, int useparallel, void
case NC_FORMATX_DAP2:
omode &= ~(NC_NETCDF4|NC_64BIT_OFFSET|NC_64BIT_DATA|NC_CLASSIC_MODEL);
break;
case NC_FORMATX_UDF0:
case NC_FORMATX_UDF1:
if(model->format == NC_FORMAT_64BIT_OFFSET)
omode |= NC_64BIT_OFFSET;
else if(model->format == NC_FORMAT_64BIT_DATA)
omode |= NC_64BIT_DATA;
else if(model->format == NC_FORMAT_NETCDF4)
omode |= NC_NETCDF4;
else if(model->format == NC_FORMAT_NETCDF4_CLASSIC)
omode |= NC_NETCDF4|NC_CLASSIC_MODEL;
break;
default:
{stat = NC_ENOTNC; goto done;}
}
Expand Down Expand Up @@ -1513,23 +1540,10 @@ static int
NC_interpret_magic_number(char* magic, NCmodel* model)
{
int status = NC_NOERR;
int tmpimpl = 0;
/* Look at the magic number */
#ifdef USE_NETCDF4
if (strlen(UDF0_magic_number) && !strncmp(UDF0_magic_number, magic,
strlen(UDF0_magic_number)))
{
model->impl = NC_FORMATX_UDF0;
model->format = NC_FORMAT_NETCDF4;
goto done;
}
if (strlen(UDF1_magic_number) && !strncmp(UDF1_magic_number, magic,
strlen(UDF1_magic_number)))
{
model->impl = NC_FORMATX_UDF1;
model->format = NC_FORMAT_NETCDF4;
goto done;
}
#endif /* USE_NETCDF4 */
if(model->impl == NC_FORMATX_UDF0 || model->impl == NC_FORMATX_UDF1)
tmpimpl = model->impl;

/* Use the complete magic number string for HDF5 */
if(memcmp(magic,HDF5_SIGNATURE,sizeof(HDF5_SIGNATURE))==0) {
Expand Down Expand Up @@ -1561,10 +1575,29 @@ NC_interpret_magic_number(char* magic, NCmodel* model)
}
}
/* No match */
status = NC_ENOTNC;
if (!tmpimpl)
status = NC_ENOTNC;

goto done;

done:
/* if model->impl was UDF0 or UDF1 on entry, make it so on exit */
if(tmpimpl)
model->impl = tmpimpl;
/* if this is a UDF magic_number update the model->impl */
if (strlen(UDF0_magic_number) && !strncmp(UDF0_magic_number, magic,
strlen(UDF0_magic_number)))
{
model->impl = NC_FORMATX_UDF0;
status = NC_NOERR;
}
if (strlen(UDF1_magic_number) && !strncmp(UDF1_magic_number, magic,
strlen(UDF1_magic_number)))
{
model->impl = NC_FORMATX_UDF1;
status = NC_NOERR;
}

return check(status);
}

Expand Down
7 changes: 6 additions & 1 deletion nc_test4/tst_udf.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ main(int argc, char **argv)
* priority. If NC_NETCDF4 flag were given priority, then
* nc_abort() will not return TEST_VAL_42, but instead will
* return 0. */
if (nc_open(FILE_NAME, mode[i]|NC_NETCDF4, &ncid)) ERR;
if (nc_open(FILE_NAME, mode[i], &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;
Expand Down Expand Up @@ -336,6 +336,7 @@ main(int argc, char **argv)
for (i = 0; i < NUM_UDFS; i++)
{
/* Add our test user defined format. */
mode[i] = mode[i]|NC_NETCDF4;
if (nc_def_user_format(mode[i], &tst_dispatcher, magic_number)) ERR;

/* Check that our user-defined format has been added. */
Expand All @@ -360,13 +361,17 @@ main(int argc, char **argv)
printf("*** testing bad version causes dispatch table to be rejected...");
{
int i;
char magic_number[5] = "1111";

/* Test all available user-defined format slots. */
for (i = 0; i < NUM_UDFS; i++)
{
/* Make sure our bad version format is rejected. */
if (nc_def_user_format(mode[i], &tst_dispatcher_bad_version,
NULL) != NC_EINVAL) ERR;
/* Make sure defining a magic number with netcdf3 is rejected. */
if (nc_def_user_format(NC_CLASSIC_MODEL, &tst_dispatcher,
magic_number) != NC_EINVAL) ERR;
}
}
SUMMARIZE_ERR;
Expand Down