mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-01-18 15:55:12 +08:00
revise sunroutine equal, add equal2 for matched ityep and xtype APIs, and add nc_err_code_name
This commit is contained in:
parent
ecc851b21c
commit
9cf01256cf
219
nc_test/util.c
219
nc_test/util.c
@ -170,7 +170,43 @@ equal(
|
||||
const double dbl_epsilon = 2.2204460492503131E-16;
|
||||
double epsilon;
|
||||
|
||||
epsilon = xtype == NC_FLOAT || itype == NCT_FLOAT ? flt_epsilon : dbl_epsilon;
|
||||
epsilon = xtype == NC_FLOAT ||
|
||||
itype == NCT_FLOAT ? flt_epsilon : dbl_epsilon;
|
||||
|
||||
if (xtype == NC_CHAR && itype == NCT_TEXT) {
|
||||
/* because in-memory data type char can be signed or unsigned,
|
||||
* type cast the value from external NC_CHAR before the comparison
|
||||
*/
|
||||
char x2 = (char) x;
|
||||
char y2 = (char) y;
|
||||
return ABS(x2-y2) <= epsilon * MAX( ABS(x2), ABS(y2));
|
||||
}
|
||||
|
||||
return ABS(x-y) <= epsilon * MAX( ABS(x), ABS(y));
|
||||
}
|
||||
|
||||
/* this function is for the APIs without itype, i.e. xtype == itype */
|
||||
int
|
||||
equal2(
|
||||
const double x,
|
||||
const double y,
|
||||
nc_type xtype) /* external data type */
|
||||
{
|
||||
const double flt_epsilon = 1.19209290E-07;
|
||||
const double dbl_epsilon = 2.2204460492503131E-16;
|
||||
double epsilon;
|
||||
|
||||
epsilon = xtype == NC_FLOAT ? flt_epsilon : dbl_epsilon;
|
||||
|
||||
if (xtype == NC_CHAR) {
|
||||
/* because in-memory data type char can be signed or unsigned,
|
||||
* type cast the value from external NC_CHAR before the comparison
|
||||
*/
|
||||
char x2 = (char) x;
|
||||
char y2 = (char) y;
|
||||
return ABS(x2-y2) <= epsilon * MAX( ABS(x2), ABS(y2));
|
||||
}
|
||||
|
||||
return ABS(x-y) <= epsilon * MAX( ABS(x), ABS(y));
|
||||
}
|
||||
|
||||
@ -314,14 +350,20 @@ int dbl2nc ( const double d, const nc_type xtype, void *p)
|
||||
*((signed char *) p) = r;
|
||||
break;
|
||||
case NC_CHAR:
|
||||
r = floor(0.5+d);
|
||||
if ( r < text_min || r > text_max ) return 2;
|
||||
#ifndef __CHAR_UNSIGNED__
|
||||
*((char *) p) = r;
|
||||
r = floor(0.5+d);
|
||||
/* d is obtained from hash() which may be set to X_CHAR_MIN (0)
|
||||
* or X_CHAR_MAX (255). When in-memory data type char is signed
|
||||
* (i.e. ranged from -128 to 127), we should still allow a type
|
||||
* cast a unsigned value > 127 to a signed char without
|
||||
* reporting it as a range error.
|
||||
*/
|
||||
if ( r < X_CHAR_MIN || r > X_CHAR_MAX ) return 2;
|
||||
#if defined(__CHAR_UNSIGNED__) && __CHAR_UNSIGNED__ != 0
|
||||
*((signed char*) p) = r;
|
||||
#else
|
||||
*((signed char*) p) = r;
|
||||
*((char *) p) = r;
|
||||
#endif
|
||||
break;
|
||||
break;
|
||||
case NC_SHORT:
|
||||
r = floor(0.5+d);
|
||||
if ( r < short_min || r > short_max ) return 2;
|
||||
@ -801,7 +843,7 @@ put_atts(int ncid)
|
||||
int j; /* index of attribute */
|
||||
int allInRange;
|
||||
double att[MAX_NELS];
|
||||
signed char catt[MAX_NELS];
|
||||
char catt[MAX_NELS];
|
||||
|
||||
for (i = -1; i < numVars; i++) {
|
||||
for (j = 0; j < NATTS(i); j++) {
|
||||
@ -842,7 +884,7 @@ put_vars(int ncid)
|
||||
int i;
|
||||
size_t j;
|
||||
double value[MAX_NELS];
|
||||
signed char text[MAX_NELS];
|
||||
char text[MAX_NELS];
|
||||
int allInRange;
|
||||
|
||||
for (j = 0; j < MAX_RANK; j++)
|
||||
@ -945,7 +987,7 @@ check_vars(int ncid)
|
||||
int err; /* status */
|
||||
int i;
|
||||
size_t j;
|
||||
signed char text;
|
||||
char text;
|
||||
double value;
|
||||
nc_type xtype;
|
||||
int ndims;
|
||||
@ -1035,7 +1077,7 @@ check_atts(int ncid)
|
||||
nc_type xtype;
|
||||
char name[NC_MAX_NAME];
|
||||
size_t length;
|
||||
signed char text[MAX_NELS];
|
||||
char text[MAX_NELS];
|
||||
double value[MAX_NELS];
|
||||
double expect;
|
||||
int nok = 0; /* count of valid comparisons */
|
||||
@ -1170,3 +1212,158 @@ int file_open(const char *filename, int omode, int *ncid)
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
char* nc_err_code_name(int err)
|
||||
{
|
||||
static char unknown_str[32];
|
||||
switch (err) {
|
||||
case (NC_NOERR): return "NC_NOERR";
|
||||
case (NC_EBADID): return "NC_EBADID";
|
||||
case (NC_ENFILE): return "NC_ENFILE";
|
||||
case (NC_EEXIST): return "NC_EEXIST";
|
||||
case (NC_EINVAL): return "NC_EINVAL";
|
||||
case (NC_EPERM): return "NC_EPERM";
|
||||
case (NC_ENOTINDEFINE): return "NC_ENOTINDEFINE";
|
||||
case (NC_EINDEFINE): return "NC_EINDEFINE";
|
||||
case (NC_EINVALCOORDS): return "NC_EINVALCOORDS";
|
||||
case (NC_EMAXDIMS): return "NC_EMAXDIMS";
|
||||
case (NC_ENAMEINUSE): return "NC_ENAMEINUSE";
|
||||
case (NC_ENOTATT): return "NC_ENOTATT";
|
||||
case (NC_EMAXATTS): return "NC_EMAXATTS";
|
||||
case (NC_EBADTYPE): return "NC_EBADTYPE";
|
||||
case (NC_EBADDIM): return "NC_EBADDIM";
|
||||
case (NC_EUNLIMPOS): return "NC_EUNLIMPOS";
|
||||
case (NC_EMAXVARS): return "NC_EMAXVARS";
|
||||
case (NC_ENOTVAR): return "NC_ENOTVAR";
|
||||
case (NC_EGLOBAL): return "NC_EGLOBAL";
|
||||
case (NC_ENOTNC): return "NC_ENOTNC";
|
||||
case (NC_ESTS): return "NC_ESTS";
|
||||
case (NC_EMAXNAME): return "NC_EMAXNAME";
|
||||
case (NC_EUNLIMIT): return "NC_EUNLIMIT";
|
||||
case (NC_ENORECVARS): return "NC_ENORECVARS";
|
||||
case (NC_ECHAR): return "NC_ECHAR";
|
||||
case (NC_EEDGE): return "NC_EEDGE";
|
||||
case (NC_ESTRIDE): return "NC_ESTRIDE";
|
||||
case (NC_EBADNAME): return "NC_EBADNAME";
|
||||
case (NC_ERANGE): return "NC_ERANGE";
|
||||
case (NC_ENOMEM): return "NC_ENOMEM";
|
||||
case (NC_EVARSIZE): return "NC_EVARSIZE";
|
||||
case (NC_EDIMSIZE): return "NC_EDIMSIZE";
|
||||
case (NC_ETRUNC): return "NC_ETRUNC";
|
||||
case (NC_EAXISTYPE): return "NC_EAXISTYPE";
|
||||
case (NC_EDAP): return "NC_EDAP";
|
||||
case (NC_ECURL): return "NC_ECURL";
|
||||
case (NC_EIO): return "NC_EIO";
|
||||
case (NC_ENODATA): return "NC_ENODATA";
|
||||
case (NC_EDAPSVC): return "NC_EDAPSVC";
|
||||
case (NC_EDAS): return "NC_EDAS";
|
||||
case (NC_EDDS): return "NC_EDDS";
|
||||
case (NC_EDATADDS): return "NC_EDATADDS";
|
||||
case (NC_EDAPURL): return "NC_EDAPURL";
|
||||
case (NC_EDAPCONSTRAINT): return "NC_EDAPCONSTRAINT";
|
||||
case (NC_ETRANSLATION): return "NC_ETRANSLATION";
|
||||
case (NC_EACCESS): return "NC_EACCESS";
|
||||
case (NC_EAUTH): return "NC_EAUTH";
|
||||
case (NC_ENOTFOUND): return "NC_ENOTFOUND";
|
||||
case (NC_ECANTREMOVE): return "NC_ECANTREMOVE";
|
||||
case (NC_EHDFERR): return "NC_EHDFERR";
|
||||
case (NC_ECANTREAD): return "NC_ECANTREAD";
|
||||
case (NC_ECANTWRITE): return "NC_ECANTWRITE";
|
||||
case (NC_ECANTCREATE): return "NC_ECANTCREATE";
|
||||
case (NC_EFILEMETA): return "NC_EFILEMETA";
|
||||
case (NC_EDIMMETA): return "NC_EDIMMETA";
|
||||
case (NC_EATTMETA): return "NC_EATTMETA";
|
||||
case (NC_EVARMETA): return "NC_EVARMETA";
|
||||
case (NC_ENOCOMPOUND): return "NC_ENOCOMPOUND";
|
||||
case (NC_EATTEXISTS): return "NC_EATTEXISTS";
|
||||
case (NC_ENOTNC4): return "NC_ENOTNC4";
|
||||
case (NC_ESTRICTNC3): return "NC_ESTRICTNC3";
|
||||
case (NC_ENOTNC3): return "NC_ENOTNC3";
|
||||
case (NC_ENOPAR): return "NC_ENOPAR";
|
||||
case (NC_EPARINIT): return "NC_EPARINIT";
|
||||
case (NC_EBADGRPID): return "NC_EBADGRPID";
|
||||
case (NC_EBADTYPID): return "NC_EBADTYPID";
|
||||
case (NC_ETYPDEFINED): return "NC_ETYPDEFINED";
|
||||
case (NC_EBADFIELD): return "NC_EBADFIELD";
|
||||
case (NC_EBADCLASS): return "NC_EBADCLASS";
|
||||
case (NC_EMAPTYPE): return "NC_EMAPTYPE";
|
||||
case (NC_ELATEFILL): return "NC_ELATEFILL";
|
||||
case (NC_ELATEDEF): return "NC_ELATEDEF";
|
||||
case (NC_EDIMSCALE): return "NC_EDIMSCALE";
|
||||
case (NC_ENOGRP): return "NC_ENOGRP";
|
||||
case (NC_ESTORAGE): return "NC_ESTORAGE";
|
||||
case (NC_EBADCHUNK): return "NC_EBADCHUNK";
|
||||
case (NC_ENOTBUILT): return "NC_ENOTBUILT";
|
||||
case (NC_EDISKLESS): return "NC_EDISKLESS";
|
||||
case (NC_ECANTEXTEND): return "NC_ECANTEXTEND";
|
||||
case (NC_EMPI): return "NC_EMPI";
|
||||
// case (NC_EURL): return "NC_EURL";
|
||||
// case (NC_ECONSTRAINT): return "NC_ECONSTRAINT";
|
||||
#ifdef USE_PNETCDF
|
||||
case (NC_ESMALL): return "NC_ESMALL";
|
||||
case (NC_ENOTINDEP): return "NC_ENOTINDEP";
|
||||
case (NC_EINDEP): return "NC_EINDEP";
|
||||
case (NC_EFILE): return "NC_EFILE";
|
||||
case (NC_EREAD): return "NC_EREAD";
|
||||
case (NC_EWRITE): return "NC_EWRITE";
|
||||
case (NC_EOFILE): return "NC_EOFILE";
|
||||
case (NC_EMULTITYPES): return "NC_EMULTITYPES";
|
||||
case (NC_EIOMISMATCH): return "NC_EIOMISMATCH";
|
||||
case (NC_ENEGATIVECNT): return "NC_ENEGATIVECNT";
|
||||
case (NC_EUNSPTETYPE): return "NC_EUNSPTETYPE";
|
||||
case (NC_EINVAL_REQUEST): return "NC_EINVAL_REQUEST";
|
||||
case (NC_EAINT_TOO_SMALL): return "NC_EAINT_TOO_SMALL";
|
||||
case (NC_ENOTSUPPORT): return "NC_ENOTSUPPORT";
|
||||
case (NC_ENULLBUF): return "NC_ENULLBUF";
|
||||
case (NC_EPREVATTACHBUF): return "NC_EPREVATTACHBUF";
|
||||
case (NC_ENULLABUF): return "NC_ENULLABUF";
|
||||
case (NC_EPENDINGBPUT): return "NC_EPENDINGBPUT";
|
||||
case (NC_EINSUFFBUF): return "NC_EINSUFFBUF";
|
||||
case (NC_ENOENT): return "NC_ENOENT";
|
||||
case (NC_EINTOVERFLOW): return "NC_EINTOVERFLOW";
|
||||
case (NC_ENOTENABLED): return "NC_ENOTENABLED";
|
||||
case (NC_EBAD_FILE): return "NC_EBAD_FILE";
|
||||
case (NC_ENO_SPACE): return "NC_ENO_SPACE";
|
||||
case (NC_EQUOTA): return "NC_EQUOTA";
|
||||
case (NC_ENULLSTART): return "NC_ENULLSTART";
|
||||
case (NC_ENULLCOUNT): return "NC_ENULLCOUNT";
|
||||
case (NC_EINVAL_CMODE): return "NC_EINVAL_CMODE";
|
||||
case (NC_EINVAL_OMODE): return "NC_EINVAL_OMODE";
|
||||
case (NC_ETYPESIZE): return "NC_ETYPESIZE";
|
||||
case (NC_ETYPE_MISMATCH): return "NC_ETYPE_MISMATCH";
|
||||
case (NC_ETYPESIZE_MISMATCH): return "NC_ETYPESIZE_MISMATCH";
|
||||
case (NC_ESTRICTCDF2): return "NC_ESTRICTCDF2";
|
||||
case (NC_ENOTRECVAR): return "NC_ENOTRECVAR";
|
||||
case (NC_ENOTFILL): return "NC_ENOTFILL";
|
||||
case (NC_EMULTIDEFINE): return "NC_EMULTIDEFINE";
|
||||
case (NC_EMULTIDEFINE_OMODE): return "NC_EMULTIDEFINE_OMODE";
|
||||
case (NC_EMULTIDEFINE_CMODE): return "NC_EMULTIDEFINE_CMODE";
|
||||
case (NC_EMULTIDEFINE_DIM_NUM): return "NC_EMULTIDEFINE_DIM_NUM";
|
||||
case (NC_EMULTIDEFINE_DIM_SIZE): return "NC_EMULTIDEFINE_DIM_SIZE";
|
||||
case (NC_EMULTIDEFINE_DIM_NAME): return "NC_EMULTIDEFINE_DIM_NAME";
|
||||
case (NC_EMULTIDEFINE_VAR_NUM): return "NC_EMULTIDEFINE_VAR_NUM";
|
||||
case (NC_EMULTIDEFINE_VAR_NAME): return "NC_EMULTIDEFINE_VAR_NAME";
|
||||
case (NC_EMULTIDEFINE_VAR_NDIMS): return "NC_EMULTIDEFINE_VAR_NDIMS";
|
||||
case (NC_EMULTIDEFINE_VAR_DIMIDS): return "NC_EMULTIDEFINE_VAR_DIMIDS";
|
||||
case (NC_EMULTIDEFINE_VAR_TYPE): return "NC_EMULTIDEFINE_VAR_TYPE";
|
||||
case (NC_EMULTIDEFINE_VAR_LEN): return "NC_EMULTIDEFINE_VAR_LEN";
|
||||
case (NC_EMULTIDEFINE_NUMRECS): return "NC_EMULTIDEFINE_NUMRECS";
|
||||
case (NC_EMULTIDEFINE_VAR_BEGIN): return "NC_EMULTIDEFINE_VAR_BEGIN";
|
||||
case (NC_EMULTIDEFINE_ATTR_NUM): return "NC_EMULTIDEFINE_ATTR_NUM";
|
||||
case (NC_EMULTIDEFINE_ATTR_SIZE): return "NC_EMULTIDEFINE_ATTR_SIZE";
|
||||
case (NC_EMULTIDEFINE_ATTR_NAME): return "NC_EMULTIDEFINE_ATTR_NAME";
|
||||
case (NC_EMULTIDEFINE_ATTR_TYPE): return "NC_EMULTIDEFINE_ATTR_TYPE";
|
||||
case (NC_EMULTIDEFINE_ATTR_LEN): return "NC_EMULTIDEFINE_ATTR_LEN";
|
||||
case (NC_EMULTIDEFINE_ATTR_VAL): return "NC_EMULTIDEFINE_ATTR_VAL";
|
||||
case (NC_EMULTIDEFINE_FNC_ARGS): return "NC_EMULTIDEFINE_FNC_ARGS";
|
||||
case (NC_EMULTIDEFINE_FILL_MODE): return "NC_EMULTIDEFINE_FILL_MODE";
|
||||
case (NC_EMULTIDEFINE_VAR_FILL_MODE): return "NC_EMULTIDEFINE_VAR_FILL_MODE";
|
||||
case (NC_EMULTIDEFINE_VAR_FILL_VALUE): return "NC_EMULTIDEFINE_VAR_FILL_VALUE";
|
||||
#endif
|
||||
default:
|
||||
sprintf(unknown_str,"Unknown code %d",err);
|
||||
}
|
||||
return unknown_str;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user