mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-02-17 16:50:18 +08:00
initialization of user-defined formats
This commit is contained in:
parent
0f0cd5085a
commit
2e831e9bbe
@ -158,8 +158,8 @@ Use this in mode flags for both nc_create() and nc_open(). */
|
||||
|
||||
#define NC_PNETCDF (NC_MPIIO) /**< Use parallel-netcdf library; alias for NC_MPIIO. */
|
||||
|
||||
#define NC_UF0 0x0080 /**< User-defined format. */
|
||||
#define NC_UF1 0x0002 /**< User-defined format. */
|
||||
#define NC_UDF0 0x0080 /**< User-defined format. */
|
||||
#define NC_UDF1 0x0002 /**< User-defined format. */
|
||||
|
||||
/** Format specifier for nc_set_default_format() and returned
|
||||
* by nc_inq_format. This returns the format as provided by
|
||||
@ -210,8 +210,8 @@ Use this in mode flags for both nc_create() and nc_open(). */
|
||||
#define NC_FORMATX_PNETCDF (4)
|
||||
#define NC_FORMATX_DAP2 (5)
|
||||
#define NC_FORMATX_DAP4 (6)
|
||||
#define NC_FORMATX_UF0 (8)
|
||||
#define NC_FORMATX_UF1 (9)
|
||||
#define NC_FORMATX_UDF0 (8)
|
||||
#define NC_FORMATX_UDF1 (9)
|
||||
#define NC_FORMATX_UNDEFINED (0)
|
||||
|
||||
/* To avoid breaking compatibility (such as in the python library),
|
||||
|
@ -66,11 +66,10 @@ static char HDF5_SIGNATURE[MAGIC_NUMBER_LEN] = "\211HDF\r\n\032\n";
|
||||
|
||||
#ifdef USE_NETCDF4
|
||||
/* User-defined formats. */
|
||||
NC_Dispatch* UF0_dispatch_table = NULL;
|
||||
NC_Dispatch* UF1_dispatch_table = NULL;
|
||||
NC_Dispatch *UDF0_dispatch_table = NULL;
|
||||
NC_Dispatch *UDF1_dispatch_table = NULL;
|
||||
#endif /* USE_NETCDF4 */
|
||||
|
||||
|
||||
/** \defgroup datasets NetCDF File and Data I/O
|
||||
|
||||
NetCDF opens datasets as files or remote access URLs.
|
||||
@ -111,7 +110,7 @@ of the interfaces for these operations.
|
||||
/**
|
||||
* Add handling of user-defined format.
|
||||
*
|
||||
* @param mode_flag NC_UF0 or NC_UF1
|
||||
* @param mode_flag NC_UDF0 or NC_UDF1
|
||||
* @param dispatch_table Pointer to dispatch table to use for this user format.
|
||||
* @param magic_number Magic number used to identify file. Ignored if
|
||||
* NULL.
|
||||
@ -125,7 +124,7 @@ int
|
||||
nc_def_user_format(int mode_flag, NC_Dispatch *dispatch_table, char *magic_number)
|
||||
{
|
||||
/* Check inputs. */
|
||||
if (mode_flag != NC_UF0 && mode_flag != NC_UF1)
|
||||
if (mode_flag != NC_UDF0 && mode_flag != NC_UDF1)
|
||||
return NC_EINVAL;
|
||||
if (!dispatch_table)
|
||||
return NC_EINVAL;
|
||||
@ -133,11 +132,11 @@ nc_def_user_format(int mode_flag, NC_Dispatch *dispatch_table, char *magic_numbe
|
||||
/* Retain a pointer to the dispatch_table. */
|
||||
switch(mode_flag)
|
||||
{
|
||||
case NC_UF0:
|
||||
UF0_dispatch_table = dispatch_table;
|
||||
case NC_UDF0:
|
||||
UDF0_dispatch_table = dispatch_table;
|
||||
break;
|
||||
case NC_UF1:
|
||||
UF1_dispatch_table = dispatch_table;
|
||||
case NC_UDF1:
|
||||
UDF1_dispatch_table = dispatch_table;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -2202,21 +2201,21 @@ NC_open(const char *path0, int cmode, int basepe, size_t *chunksizehintp,
|
||||
|
||||
#ifdef USE_NETCDF4
|
||||
/* Check for use of user-defined format 0. */
|
||||
if (cmode & NC_UF0)
|
||||
if (cmode & NC_UDF0)
|
||||
{
|
||||
if (!UF0_dispatch_table)
|
||||
if (!UDF0_dispatch_table)
|
||||
return NC_EINVAL;
|
||||
model = NC_FORMATX_UF0;
|
||||
dispatcher = UF0_dispatch_table;
|
||||
model = NC_FORMATX_UDF0;
|
||||
dispatcher = UDF0_dispatch_table;
|
||||
}
|
||||
|
||||
/* Check for use of user-defined format 1. */
|
||||
if (cmode & NC_UF1)
|
||||
if (cmode & NC_UDF1)
|
||||
{
|
||||
if (!UF1_dispatch_table)
|
||||
if (!UDF1_dispatch_table)
|
||||
return NC_EINVAL;
|
||||
model = NC_FORMATX_UF1;
|
||||
dispatcher = UF1_dispatch_table;
|
||||
model = NC_FORMATX_UDF1;
|
||||
dispatcher = UDF1_dispatch_table;
|
||||
}
|
||||
#endif /* USE_NETCDF4 */
|
||||
|
||||
|
@ -9,6 +9,12 @@
|
||||
#include "nc4dispatch.h"
|
||||
#include "nc.h"
|
||||
|
||||
#ifdef USE_NETCDF4
|
||||
/* User-defined formats. */
|
||||
extern NC_Dispatch *UDF0_dispatch_table;
|
||||
extern NC_Dispatch *UDF1_dispatch_table;
|
||||
#endif /* USE_NETCDF4 */
|
||||
|
||||
static NC_Dispatch NC4_dispatcher = {
|
||||
|
||||
NC_FORMATX_NC4,
|
||||
@ -105,7 +111,8 @@ NC4_get_var_chunk_cache,
|
||||
NC_Dispatch* NC4_dispatch_table = NULL; /* moved here from ddispatch.c */
|
||||
|
||||
/**
|
||||
* @internal Initialize netCDF-4.
|
||||
* @internal Initialize netCDF-4. If user-defined format(s) have been
|
||||
* specified in configure, load their dispatch table(s).
|
||||
*
|
||||
* @return ::NC_NOERR No error.
|
||||
* @author Dennis Heimbigner
|
||||
@ -113,16 +120,33 @@ NC_Dispatch* NC4_dispatch_table = NULL; /* moved here from ddispatch.c */
|
||||
int
|
||||
NC4_initialize(void)
|
||||
{
|
||||
NC4_dispatch_table = &NC4_dispatcher;
|
||||
int ret = NC_NOERR;
|
||||
|
||||
NC4_dispatch_table = &NC4_dispatcher;
|
||||
|
||||
#ifdef USE_UDF0
|
||||
/* If user-defined format 0 was specified during configure, set up
|
||||
* it's dispatch table. */
|
||||
if ((ret = nc_def_user_format(NC_UDF0, &UDF0_DISPATCH, NULL)))
|
||||
return ret;
|
||||
#endif /* USE_UDF0 */
|
||||
|
||||
#ifdef USE_UDF1
|
||||
/* If user-defined format 0 was specified during configure, set up
|
||||
* it's dispatch table. */
|
||||
if ((ret = nc_def_user_format(NC_UDF1F, &UDF1_DISPATCH, NULL)))
|
||||
return ret;
|
||||
#endif /* USE_UDF0 */
|
||||
|
||||
#ifdef LOGGING
|
||||
if(getenv(NCLOGLEVELENV) != NULL) {
|
||||
char* slevel = getenv(NCLOGLEVELENV);
|
||||
long level = atol(slevel);
|
||||
if(level >= 0)
|
||||
nc_set_log_level((int)level);
|
||||
}
|
||||
if(getenv(NCLOGLEVELENV) != NULL) {
|
||||
char* slevel = getenv(NCLOGLEVELENV);
|
||||
long level = atol(slevel);
|
||||
if(level >= 0)
|
||||
nc_set_log_level((int)level);
|
||||
}
|
||||
#endif
|
||||
return NC_NOERR;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,7 +66,7 @@ tst_get_vara(int ncid, int varid, const size_t *start, const size_t *count,
|
||||
* functions that make up the HDF4 dispatch interface. */
|
||||
static NC_Dispatch tst_dispatcher = {
|
||||
|
||||
NC_FORMATX_UF0,
|
||||
NC_FORMATX_UDF0,
|
||||
|
||||
NC_RO_create,
|
||||
tst_open,
|
||||
@ -166,14 +166,14 @@ main(int argc, char **argv)
|
||||
if (nc_close(ncid)) ERR;
|
||||
|
||||
/* Add our test user defined format. */
|
||||
if (nc_def_user_format(NC_UF0, &tst_dispatcher, NULL)) ERR;
|
||||
if (nc_def_user_format(NC_UDF0, &tst_dispatcher, NULL)) ERR;
|
||||
|
||||
/* Open file with our defined functions. */
|
||||
if (nc_open(FILE_NAME, NC_UF0, &ncid)) ERR;
|
||||
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_UF0, &ncid)) ERR;
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user