mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-01-30 16:10:44 +08:00
Merge branch 'master' into vc9
This commit is contained in:
commit
7796ecb196
@ -1,8 +1,3 @@
|
||||
# blocklist
|
||||
branches:
|
||||
except:
|
||||
- /.*[.]dmh/
|
||||
|
||||
sudo: required
|
||||
language: c
|
||||
services:
|
||||
|
@ -1002,7 +1002,6 @@ IF(ENABLE_PARALLEL4 AND ENABLE_NETCDF_4)
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
|
||||
# Options to enable parallel IO, tests.
|
||||
SET(STATUS_PNETCDF "OFF")
|
||||
OPTION(ENABLE_PNETCDF "Build with parallel I/O for classic and 64-bit offset files using parallel-netcdf." OFF)
|
||||
@ -1108,6 +1107,12 @@ IF(ENABLE_PARALLEL_TESTS AND USE_PARALLEL)
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
||||
# Enable special filter test; experimental when using cmake.
|
||||
OPTION(ENABLE_FILTER_TEST "Enable special filter test. Ignored if netCDF4 is not enabled" OFF)
|
||||
IF(USE_NETCDF4)
|
||||
SET(ENABLE_FILTER_TEST OFF CACHE BOOL "")
|
||||
ENDIF()
|
||||
|
||||
# Determine whether or not to generate documentation.
|
||||
OPTION(ENABLE_DOXYGEN "Enable generation of doxygen-based documentation." OFF)
|
||||
IF(ENABLE_DOXYGEN)
|
||||
@ -1248,6 +1253,7 @@ CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H)
|
||||
CHECK_INCLUDE_FILE("sys/wait.h" HAVE_SYS_WAIT_H)
|
||||
CHECK_INCLUDE_FILE("sys/mman.h" HAVE_SYS_MMAN_H)
|
||||
CHECK_INCLUDE_FILE("sys/resource.h" HAVE_SYS_RESOURCE_H)
|
||||
CHECK_INCLUDE_FILE("sys/cdefs.h" HAVE_SYS_CDEFS_H)
|
||||
CHECK_INCLUDE_FILE("fcntl.h" HAVE_FCNTL_H)
|
||||
CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H)
|
||||
CHECK_INCLUDE_FILE("pstdint.h" HAVE_PSTDINT_H)
|
||||
|
6
cf
6
cf
@ -6,9 +6,9 @@ FAST=1
|
||||
|
||||
HDF5=1
|
||||
DAP=1
|
||||
SZIP=1
|
||||
#SZIP=1
|
||||
#HDF4=1
|
||||
PNETCDF=1
|
||||
#PNETCDF=1
|
||||
#PAR4=1
|
||||
|
||||
if test $# != 0 ; then
|
||||
@ -117,7 +117,7 @@ FLAGS="$FLAGS --enable-logging"
|
||||
#FLAGS="$FLAGS --disable-properties-attribute"
|
||||
#FLAGS="$FLAGS --disable-silent-rules"
|
||||
#FLAGS="$FLAGS --with-testservers=remotestserver.localhost:8083"
|
||||
FLAGS="$FLAGS --enable-filter-test"
|
||||
#FLAGS="$FLAGS --enable-filter-test"
|
||||
|
||||
if test "x$PAR4" != x1 ; then
|
||||
FLAGS="$FLAGS --disable-parallel4"
|
||||
|
15
cf.cmake
15
cf.cmake
@ -1,8 +1,17 @@
|
||||
# Visual Studio
|
||||
VS=1
|
||||
|
||||
if test "x$1" = xsetup ; then
|
||||
VSSETUP=1
|
||||
case "$1" in
|
||||
vs|VS) VS=1 ;;
|
||||
linux|nix) unset VS ;;
|
||||
*) echo "Must specify env: vs|linux"; exit 1; ;;
|
||||
esac
|
||||
|
||||
if test "x$VS" = x1 ; then
|
||||
if test "x$2" = xsetup ; then
|
||||
VSSETUP=1
|
||||
else
|
||||
unset VSSETUP
|
||||
fi
|
||||
fi
|
||||
|
||||
#export NCPATHDEBUG=1
|
||||
|
@ -410,6 +410,9 @@ are set when opening a binary file on Windows. */
|
||||
/* Define to 1 if you have the `sysconf' function. */
|
||||
#cmakedefine HAVE_SYSCONF 1
|
||||
|
||||
/* Define to 1 if you have the <sys/cdefs.h> header file. */
|
||||
#cmakedefine HAVE_SYS_CDEFS_H 1
|
||||
|
||||
/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'.
|
||||
*/
|
||||
#cmakedefine HAVE_SYS_DIR_H 1
|
||||
|
@ -795,6 +795,8 @@ AC_FUNC_VPRINTF
|
||||
AC_CHECK_HEADERS([sys/resource.h])
|
||||
#fi
|
||||
|
||||
AC_CHECK_HEADERS([sys/cdefs.h])
|
||||
|
||||
# Check for <stdbool.h> that conforms to C99 requirements
|
||||
AC_HEADER_STDBOOL
|
||||
|
||||
|
@ -58,6 +58,8 @@ EXTRA_DIST = test_parse.sh test_meta.sh test_data.sh \
|
||||
baseline baselineraw baselineremote CMakeLists.txt
|
||||
|
||||
CLEANFILES = *.exe
|
||||
# This should only be left behind if using parallel io
|
||||
CLEANFILES += tmp_*
|
||||
|
||||
# One last thing
|
||||
BUILT_SOURCES = .daprc
|
||||
|
@ -47,6 +47,8 @@ main(int argc, char** argv)
|
||||
if((ret=nc_close(ncid))) goto done;
|
||||
|
||||
done:
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"code=%d %s\n",ret,nc_strerror(ret));
|
||||
#endif
|
||||
return (ret ? 1 : 0);
|
||||
}
|
||||
|
@ -10,6 +10,10 @@
|
||||
#ifndef NCCONFIGURE_H
|
||||
#define NCCONFIGURE_H 1
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
This is included in bottom
|
||||
of config.h. It is where,
|
||||
@ -42,6 +46,14 @@ char *nulldup(const char* s);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
#ifdef _MSC_VER
|
||||
/* Windows strlcat_s is equivalent to strlcat, but different arg order */
|
||||
#define strlcat(d,s,n) strcat_s((d),(n),(s))
|
||||
#else
|
||||
extern size_t strlcat(char* dst, const char* src, size_t dsize);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef nulldup
|
||||
#define nulldup(s) ((s)==NULL?NULL:strdup(s))
|
||||
|
@ -151,368 +151,3 @@ buildattribute(char* name, nc_type ptype,
|
||||
return THROW(ncstat);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
Given a das attribute walk it to see if it
|
||||
has at least 1 actual attribute (no recursion)
|
||||
*/
|
||||
static int
|
||||
hasattribute(OClink conn, OCdasnode dasnode)
|
||||
{
|
||||
int i;
|
||||
OCerror ocstat = OC_NOERR;
|
||||
int tf = 0; /* assume false */
|
||||
OCtype ocsubtype;
|
||||
NClist* subnodes = nclistnew();
|
||||
|
||||
OCCHECK(oc_dds_octype(conn,dasnode,&ocsubtype));
|
||||
if(ocsubtype == OC_Attribute) return 1; /* this is an attribute */
|
||||
ASSERT((ocsubtype == OC_Attributeset));
|
||||
|
||||
OCCHECK(collect_subnodes(conn,dasnode,subnodes));
|
||||
for(i=0;i<nclistlength(subnodes);i++) {
|
||||
OCdasnode subnode = (OCdasnode)nclistget(subnodes,i);
|
||||
OCCHECK(oc_dds_class(conn,subnode,&ocsubtype));
|
||||
if(ocsubtype == OC_Attribute) {tf=1; break;}
|
||||
}
|
||||
done:
|
||||
nclistfree(subnodes);
|
||||
return tf;
|
||||
}
|
||||
|
||||
int
|
||||
dapmerge(NCDAPCOMMON* nccomm, CDFnode* ddsroot, OCddsnode dasroot)
|
||||
{
|
||||
unsigned int i,j;
|
||||
NCerror ncerr = NC_NOERR;
|
||||
OCerror ocstat = OC_NOERR;
|
||||
OClink conn = nccomm->oc.conn;
|
||||
size_t nsubnodes;
|
||||
NClist* dasglobals = nclistnew();
|
||||
NClist* dasnodes = nclistnew();
|
||||
NClist* dodsextra = nclistnew();
|
||||
NClist* varnodes = nclistnew();
|
||||
NClist* alldasnodes = nclistnew();
|
||||
|
||||
if(ddsroot == NULL || dasroot == NULL) return NC_NOERR;
|
||||
|
||||
ocstat = collect_alldasnodes(conn,dasroot,alldasnodes);
|
||||
|
||||
/* 1. collect all the relevant DAS nodes;
|
||||
namely those that contain at least one
|
||||
attribute value.
|
||||
Simultaneously look for potential ambiguities
|
||||
if found; complain but continue: result are indeterminate.
|
||||
also collect globals and DODS_EXTRA separately.
|
||||
*/
|
||||
for(i=0;i<nclistlength(alldasnodes);i++) {
|
||||
OCddsnode das = (OCddsnode)nclistget(alldasnodes,i);
|
||||
OCtype octype;
|
||||
char* ocname = NULL;
|
||||
int isglobal = 0;
|
||||
int hasattributes = 0;
|
||||
|
||||
OCCHECK(oc_dds_class(conn,das,&octype));
|
||||
if(octype == OC_Attribute) continue; /* ignore these for now*/
|
||||
|
||||
OCCHECK(oc_dds_name(conn,das,&ocname));
|
||||
OCCHECK(oc_dds_nsubnodes(conn,das,&nsubnodes));
|
||||
|
||||
isglobal = (ocname == NULL ? 0 : isglobalname(ocname));
|
||||
|
||||
/* catch DODS_EXTRA */
|
||||
if(isglobal && ocname != NULL && strcmp(ocname,"DODS_EXTRA")==0) {
|
||||
nclistpush(dodsextra,(void*)das);
|
||||
nullfree(ocname);
|
||||
continue;
|
||||
}
|
||||
if(ocname == NULL || isglobal) {
|
||||
nclistpush(dasglobals,(void*)das);
|
||||
nullfree(ocname);
|
||||
continue;
|
||||
}
|
||||
hasattributes = hasattribute(conn,das);
|
||||
if(hasattributes) {
|
||||
/* Look for previously collected nodes with same name*/
|
||||
for(j=0;j<nclistlength(dasnodes);j++) {
|
||||
OCddsnode das2 = (OCddsnode)nclistget(dasnodes,j);
|
||||
char* ocname2;
|
||||
OCCHECK(oc_dds_name(conn,das2,&ocname2));
|
||||
if(ocname2 == NULL || ocname == NULL) goto loop;
|
||||
if(strcmp(ocname2,"DODS")==0) goto loop;
|
||||
if(strcmp(ocname,ocname2)==0)
|
||||
nclog(NCLOGWARN,"nc_mergedas: potentially ambiguous DAS name: %s",ocname2);
|
||||
loop:
|
||||
nullfree(ocname2);
|
||||
}
|
||||
nclistpush(dasnodes,(void*)das);
|
||||
}
|
||||
nullfree(ocname);
|
||||
}
|
||||
|
||||
/* 2. collect all the leaf DDS nodes (of type NC_Atomic)*/
|
||||
ocstat = collect_leaves(link,ddsroot,varnodes);
|
||||
|
||||
/* 3. For each das node, locate matching DDS node(s) and attach
|
||||
attributes to the DDS node(s).
|
||||
Match means:
|
||||
1. DAS->fullname :: DDS->fullname
|
||||
2. DAS->name :: DDS->fullname (support DAS names with embedded '.'
|
||||
3. DAS->name :: DDS->name
|
||||
4. special case for DODS. Apply 1-3 on DODS parent.
|
||||
*/
|
||||
for(i=0;i<nclistlength(dasnodes);i++) {
|
||||
OCddsnode das = (OCddsnode)nclistget(dasnodes,i);
|
||||
char* ocfullname = NULL;
|
||||
char* ocbasename = NULL;
|
||||
|
||||
if(das == NULL) continue;
|
||||
OCCHECK(oc_dds_name(conn,das,&ocbasename));
|
||||
if(strcmp(ocbasename,"DODS")==0) {
|
||||
OCddsnode container;
|
||||
OCCHECK(oc_dds_container(conn,das,&container));
|
||||
ASSERT(container != NULL);
|
||||
ocfullname = makeocpathstring(conn,container,".");
|
||||
} else {
|
||||
ocfullname = makeocpathstring(conn,das,".");
|
||||
}
|
||||
for(j=0;j<nclistlength(varnodes);j++) {
|
||||
CDFnode* dds = (CDFnode*)nclistget(varnodes,j);
|
||||
char* ddsfullname = makecdfpathstring(dds,".");
|
||||
if(strcmp(ocfullname,ddsfullname)==0
|
||||
|| strcmp(ocbasename,ddsfullname)==0
|
||||
|| strcmp(ocbasename,dds->ocname)==0) {
|
||||
mergedas1(nccomm,conn,dds,das);
|
||||
/* remove from dasnodes list*/
|
||||
nclistset(dasnodes,i,(void*)NULL);
|
||||
}
|
||||
nullfree(ddsfullname);
|
||||
}
|
||||
nullfree(ocfullname);
|
||||
nullfree(ocbasename);
|
||||
}
|
||||
|
||||
/* 4. Assign globals */
|
||||
for(i=0;i<nclistlength(dasglobals);i++) {
|
||||
OCddsnode das = (OCddsnode)nclistget(dasglobals,i);
|
||||
mergedas1(nccomm,conn,ddsroot,das);
|
||||
}
|
||||
|
||||
/* 5. Assign DOD_EXTRA */
|
||||
for(i=0;i<nclistlength(dodsextra);i++) {
|
||||
OCddsnode das = (OCddsnode)nclistget(dodsextra,i);
|
||||
mergedas1(nccomm,conn,ddsroot,das);
|
||||
}
|
||||
|
||||
done: /* cleanup*/
|
||||
nclistfree(dasglobals);
|
||||
nclistfree(dasnodes);
|
||||
nclistfree(alldasnodes);
|
||||
nclistfree(dodsextra);
|
||||
nclistfree(varnodes);
|
||||
if(ocstat != OC_NOERR)
|
||||
ncerr = ocerrtoncerr(ocstat);
|
||||
return THROW(ncerr);
|
||||
}
|
||||
|
||||
static int
|
||||
mergedas1(NCDAPCOMMON* nccomm, OClink conn, CDFnode* dds, OCddsnode das)
|
||||
{
|
||||
NCerror ncstat = NC_NOERR;
|
||||
OCerror ocstat = OC_NOERR;
|
||||
unsigned int i,j,k;
|
||||
unsigned int nsubnodes;
|
||||
OCobject* subnodes = NULL;
|
||||
OCobject* dodsnodes = NULL;
|
||||
unsigned int ndodsnodes;
|
||||
|
||||
if(dds == NULL || das == OCNULL) return NC_NOERR; /* nothing to do */
|
||||
if(dds->attributes == NULL) dds->attributes = nclistnew();
|
||||
/* assign the simple attributes in the das set to this dds node*/
|
||||
OCCHECK(oc_inq_nsubnodes(conn,das,&nsubnodes));
|
||||
OCCHECK(oc_inq_subnodes(conn,das,&subnodes));
|
||||
for(i=0;i<nsubnodes;i++) {
|
||||
OCobject attnode = subnodes[i];
|
||||
OCtype octype, ocetype;
|
||||
char* ocname = NULL;
|
||||
unsigned int ocnvalues;
|
||||
OCCHECK(oc_inq_name(conn,attnode,&ocname));
|
||||
OCCHECK(oc_inq_class(conn,attnode,&octype));
|
||||
if(octype == OC_Attribute) {
|
||||
NCattribute* att = NULL;
|
||||
NClist* stringvalues;
|
||||
OCCHECK(oc_inq_primtype(conn,attnode,&ocetype));
|
||||
OCCHECK(oc_inq_dasattr_nvalues(conn,attnode,&ocnvalues));
|
||||
stringvalues = nclistnew();
|
||||
for(j=0;j<ocnvalues;j++) {
|
||||
char* stringval;
|
||||
OCCHECK(oc_inq_dasattr(conn,attnode,j,&ocetype,&stringval));
|
||||
nclistpush(stringvalues,(void*)stringval);
|
||||
}
|
||||
ncstat = buildattribute(ocname,
|
||||
octypetonc(ocetype),
|
||||
stringvalues,
|
||||
&att);
|
||||
if(ncstat) goto done;
|
||||
nclistpush(dds->attributes,(void*)att);
|
||||
} else if(octype == OC_Attributeset
|
||||
&& (strcmp(ocname,"DODS")==0
|
||||
|| strcmp(ocname,"DODS_EXTRA")==0)) {
|
||||
/* Turn the DODS special attributes into into
|
||||
special attributes for dds node */
|
||||
OCCHECK(oc_inq_nsubnodes(conn,attnode,&ndodsnodes));
|
||||
OCCHECK(oc_inq_subnodes(conn,attnode,&dodsnodes));
|
||||
for(j=0;j<ndodsnodes;j++) {
|
||||
char* dodsname = NULL;
|
||||
char newname[4096];
|
||||
OCobject attnode = dodsnodes[j];
|
||||
NCattribute* att = NULL;
|
||||
NClist* stringvalues;
|
||||
OCCHECK(oc_inq_class(conn,attnode,&octype));
|
||||
if(octype != OC_Attribute) continue;
|
||||
OCCHECK(oc_inq_primtype(conn,attnode,&ocetype));
|
||||
OCCHECK(oc_inq_dasattr_nvalues(conn,attnode,&ocnvalues));
|
||||
stringvalues = nclistnew();
|
||||
for(k=0;k<ocnvalues;k++) {
|
||||
char* stringval;
|
||||
OCCHECK(oc_inq_dasattr(conn,attnode,k,&ocetype,&stringval));
|
||||
nclistpush(stringvalues,(void*)stringval);
|
||||
}
|
||||
OCCHECK(oc_inq_name(conn,attnode,&dodsname));
|
||||
/* Compute new special name */
|
||||
strcpy(newname,"_DODS_");
|
||||
strcat(newname,dodsname);
|
||||
ncstat = buildattribute(newname,
|
||||
octypetonc(ocetype),
|
||||
stringvalues,
|
||||
&att);
|
||||
if(ncstat) goto done;
|
||||
att->invisible = 1;
|
||||
nclistpush(dds->attributes,(void*)att);
|
||||
|
||||
/* Define extra semantics associated with DODS and DODS_EXTRA attribute */
|
||||
if(strcmp(dodsname,"strlen")==0) {
|
||||
unsigned int maxstrlen = 0;
|
||||
if(nclistlength(stringvalues) > 0) {
|
||||
char* stringval = (char*)nclistget(stringvalues,0);
|
||||
if(0==sscanf(stringval,"%u",&maxstrlen)) maxstrlen = 0;
|
||||
}
|
||||
dds->dodsspecial.maxstrlen = maxstrlen;
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"%s.maxstrlen=%d\n",dds->ocname,(int)dds->dodsspecial.maxstrlen);
|
||||
#endif
|
||||
} else if(strcmp(dodsname,"dimName")==0) {
|
||||
if(nclistlength(stringvalues) > 0) {
|
||||
char* stringval = (char*)nclistget(stringvalues,0);
|
||||
dds->dodsspecial.dimname = nulldup(stringval);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"%s.dimname=%s\n",dds->ocname,dds->dodsspecial.dimname);
|
||||
#endif
|
||||
} else dds->dodsspecial.dimname = NULL;
|
||||
} else if(strcmp(dodsname,"Unlimited_Dimension")==0) {
|
||||
char* stringval = NULL;
|
||||
if(nclistlength(stringvalues) > 0)
|
||||
stringval = (char*)nclistget(stringvalues,0);
|
||||
if(stringval != NULL) {
|
||||
if(nccomm->cdf.recorddimname != NULL) {
|
||||
if(strcmp(stringval,nccomm->cdf.recorddimname) != 0)
|
||||
nclog(NCLOGWARN,"Duplicate DODS_EXTRA:Unlimited_Dimension specifications");
|
||||
} else {
|
||||
nccomm->cdf.recorddimname = nulldup(stringval);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr,"%s.Unlimited_Dimension=%s\n",dds->ocname,nccomm->cdf.recorddimname);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
} /* else ignore */
|
||||
nullfree(dodsname);
|
||||
}
|
||||
nullfree(dodsnodes);
|
||||
}
|
||||
nullfree(ocname);
|
||||
}
|
||||
|
||||
done:
|
||||
nullfree(subnodes);
|
||||
if(ocstat != OC_NOERR) ncstat = ocerrtoncerr(ocstat);
|
||||
return THROW(ncstat);
|
||||
}
|
||||
|
||||
static int
|
||||
isglobalname(char* name)
|
||||
{
|
||||
int len = strlen(name);
|
||||
int glen = strlen("global");
|
||||
char* p;
|
||||
if(len < glen) return 0;
|
||||
p = name + (len - glen);
|
||||
if(strcasecmp(p,"global") != 0)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static OCerror
|
||||
collect_alldasnodes(OClink link, OCddsnode dasnode, NClist* alldasnodes)
|
||||
{
|
||||
size_t nsubnodes,i;
|
||||
OCerror ocstat = OC_NOERR;
|
||||
nclistpush(alldasnodes,(void*)dasnode);
|
||||
ocstat = oc_dds_nsubnodes(link,dasnode,&nsubnodes);
|
||||
if(ocstat != OC_NOERR) goto done;
|
||||
for(i=0;i<nsubnodes;i++) {
|
||||
OCddsnode subnode;
|
||||
ocstat = oc_dds_ithsubnode(link,dasnode,i,&subnode);
|
||||
if(ocstat != OC_NOERR) goto done;
|
||||
ocstat = collect_alldasnodes(link,subnode,alldasnodes);
|
||||
if(ocstat != OC_NOERR) goto done;
|
||||
}
|
||||
|
||||
done:
|
||||
return ocstat;
|
||||
}
|
||||
|
||||
static OCerror
|
||||
collect_leaves(OClink link, OCddsnode ddsnode, NClist* leaves)
|
||||
{
|
||||
size_t nsubnodes,i;
|
||||
OCerror ocstat = OC_NOERR;
|
||||
OCtype octype;
|
||||
ocstat = oc_dds_octype(link,ddsnode,&octype);
|
||||
if(ocstat != OC_NOERR) goto done;
|
||||
if(octype == OC_Atomic) {
|
||||
nclistpush(leaves,(void*)ddsnode);
|
||||
} else {
|
||||
ocstat = oc_dds_nsubnodes(link,ddsnode,&nsubnodes);
|
||||
if(ocstat != OC_NOERR) goto done;
|
||||
for(i=0;i<nsubnodes;i++) {
|
||||
OCddsnode subnode;
|
||||
ocstat = oc_dds_ithsubnode(link,ddsnode,i,&subnode);
|
||||
if(ocstat != OC_NOERR) goto done;
|
||||
ocstat = collect_leaves(link,subnode,leaves);
|
||||
if(ocstat != OC_NOERR) goto done;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
return ocstat;
|
||||
}
|
||||
|
||||
static OCerror
|
||||
collect_subnodes(OClink link, OCddsnode ddsnode, NClist* subnodes)
|
||||
{
|
||||
size_t nsubnodes,i;
|
||||
OCerror ocstat = OC_NOERR;
|
||||
ocstat = oc_dds_nsubnodes(link,ddsnode,&nsubnodes);
|
||||
if(ocstat != OC_NOERR) goto done;
|
||||
for(i=0;i<nsubnodes;i++) {
|
||||
OCddsnode subnode;
|
||||
ocstat = oc_dds_ithsubnode(link,ddsnode,i,&subnode);
|
||||
if(ocstat != OC_NOERR) goto done;
|
||||
nclistpush(subnodes,(void*)subnode);
|
||||
}
|
||||
|
||||
done:
|
||||
return ocstat;
|
||||
}
|
||||
#endif /*0*/
|
||||
|
@ -584,7 +584,7 @@ dumpslice(DCEslice* slice)
|
||||
(unsigned long)slice->stride,
|
||||
(unsigned long)slice->last);
|
||||
}
|
||||
strcat(buf,tmp);
|
||||
strlcat(buf,tmp,sizeof(buf));
|
||||
return strdup(tmp);
|
||||
}
|
||||
|
||||
|
@ -79,14 +79,14 @@ dapodom_print(Dapodometer* odom)
|
||||
char tmp[64];
|
||||
line[0] = '\0';
|
||||
if(odom->rank == 0) {
|
||||
strcat(line,"[]");
|
||||
strlcat(line,"[]",sizeof(line));
|
||||
} else for(i=0;i<odom->rank;i++) {
|
||||
sprintf(tmp,"[%lu/%lu:%lu:%lu]",
|
||||
(size_t)odom->index[i],
|
||||
(size_t)odom->start[i],
|
||||
(size_t)odom->stride[i],
|
||||
(size_t)odom->length[i]);
|
||||
strcat(line,tmp);
|
||||
strlcat(line,tmp,sizeof(line));
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
@ -442,13 +442,13 @@ simplepathstring(NClist* names, char* separator)
|
||||
len += strlen(name);
|
||||
len += strlen(separator);
|
||||
}
|
||||
len++; /* null terminator */
|
||||
result = (char*)malloc(len);
|
||||
len++; /* room for strlcat to null terminate */
|
||||
result = (char*)malloc(len+1);
|
||||
result[0] = '\0';
|
||||
for(i=0;i<nclistlength(names);i++) {
|
||||
char* segment = (char*)nclistget(names,i);
|
||||
if(i > 0) strcat(result,separator);
|
||||
strcat(result,segment);
|
||||
if(i > 0) strlcat(result,separator,len);
|
||||
strlcat(result,segment,len);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -776,10 +776,13 @@ repairname(const char* name, const char* badchars)
|
||||
const char *p;
|
||||
char *q;
|
||||
int c;
|
||||
int nnlen = 0;
|
||||
|
||||
if(name == NULL) return NULL;
|
||||
newname = (char*)malloc(1+(3*strlen(name))); /* max needed */
|
||||
newname[0] = '\0'; /* so we can use strcat */
|
||||
nnlen = (3*strlen(name)); /* max needed */
|
||||
nnlen++; /* room for strlcat to add nul */
|
||||
newname = (char*)malloc(1+nnlen); /* max needed */
|
||||
newname[0] = '\0'; /* so we can use strlcat */
|
||||
for(p=name,q=newname;(c=*p);p++) {
|
||||
if(strchr(badchars,c) != NULL) {
|
||||
int digit;
|
||||
@ -790,11 +793,11 @@ repairname(const char* name, const char* badchars)
|
||||
digit = (c & 0x0f);
|
||||
newchar[2] = hexdigits[digit];
|
||||
newchar[3] = '\0';
|
||||
strcat(newname,newchar);
|
||||
strlcat(newname,newchar,nnlen);
|
||||
q += 3; /*strlen(newchar)*/
|
||||
} else
|
||||
*q++ = c;
|
||||
*q = '\0'; /* so we can always do strcat */
|
||||
*q = '\0'; /* so we can always do strlcat */
|
||||
}
|
||||
*q = '\0'; /* ensure trailing null */
|
||||
return newname;
|
||||
|
@ -316,10 +316,14 @@ NCD2_open(const char* path, int mode,
|
||||
#endif
|
||||
|
||||
#ifdef OCCOMPILEBYDEFAULT
|
||||
{ int rullen = 0;
|
||||
/* set the compile flag by default */
|
||||
dapcomm->oc.rawurltext = (char*)emalloc(strlen(path)+strlen("[compile]")+1);
|
||||
strcpy(dapcomm->oc.rawurltext,"[compile]");
|
||||
strcat(dapcomm->oc.rawurltext, path);
|
||||
rullen = strlen(path)+strlen("[compile]");;
|
||||
rullen++; /* strlcat nul */
|
||||
dapcomm->oc.rawurltext = (char*)emalloc(rullen+1);
|
||||
strncpy(dapcomm->oc.rawurltext,"[compile]",rullen);
|
||||
strlcat(dapcomm->oc.rawurltext, path, rullen);
|
||||
}
|
||||
#else
|
||||
dapcomm->oc.rawurltext = strdup(path);
|
||||
#endif
|
||||
@ -905,15 +909,14 @@ buildattribute(NCDAPCOMMON* dapcomm, NCattribute* att, nc_type vartype, int vari
|
||||
char* s = (char*)nclistget(att->values,i);
|
||||
newlen += (1+strlen(s));
|
||||
}
|
||||
if(newlen > 0)
|
||||
newstring = (char*)malloc(newlen);
|
||||
|
||||
MEMCHECK(newstring,NC_ENOMEM);
|
||||
newlen++; /* for strlcat nul */
|
||||
newstring = (char*)malloc(newlen+1);
|
||||
MEMCHECK(newstring,NC_ENOMEM);
|
||||
newstring[0] = '\0';
|
||||
for(i=0;i<nvalues;i++) {
|
||||
char* s = (char*)nclistget(att->values,i);
|
||||
if(i > 0) strcat(newstring,"\n");
|
||||
strcat(newstring,s);
|
||||
if(i > 0) strlcat(newstring,"\n",newlen);
|
||||
strlcat(newstring,s,newlen);
|
||||
}
|
||||
dapexpandescapes(newstring);
|
||||
if(newstring[0]=='\0')
|
||||
@ -1137,11 +1140,14 @@ fprintf(stderr,"conflict: %s[%lu] %s[%lu]\n",
|
||||
nullfree(dim->ncbasename);
|
||||
if(dim->dim.index1 > 0) {/* need to fix conflicting names (see above) */
|
||||
char sindex[64];
|
||||
size_t baselen;
|
||||
snprintf(sindex,sizeof(sindex),"_%d",dim->dim.index1);
|
||||
dim->ncbasename = (char*)malloc(strlen(sindex)+strlen(legalname)+1);
|
||||
baselen = strlen(sindex)+strlen(legalname);
|
||||
baselen++; /* for strlcat nul */
|
||||
dim->ncbasename = (char*)malloc(baselen+1);
|
||||
if(dim->ncbasename == NULL) {nullfree(legalname); return NC_ENOMEM;}
|
||||
strcpy(dim->ncbasename,legalname);
|
||||
strcat(dim->ncbasename,sindex);
|
||||
strncpy(dim->ncbasename,legalname,baselen);
|
||||
strlcat(dim->ncbasename,sindex,baselen);
|
||||
nullfree(legalname);
|
||||
} else {/* standard case */
|
||||
dim->ncbasename = legalname;
|
||||
@ -1271,9 +1277,9 @@ applyclientparams(NCDAPCOMMON* nccomm)
|
||||
CDFnode* var = (CDFnode*)nclistget(nccomm->cdf.ddsroot->tree->varnodes,i);
|
||||
/* Define the client param stringlength for this variable*/
|
||||
var->maxstringlength = 0; /* => use global dfalt */
|
||||
strcpy(tmpname,"stringlength_");
|
||||
strncpy(tmpname,"stringlength_",sizeof(tmpname));
|
||||
pathstr = makeocpathstring(conn,var->ocnode,".");
|
||||
strncat(tmpname,pathstr,NC_MAX_NAME);
|
||||
strlcat(tmpname,pathstr,sizeof(tmpname));
|
||||
nullfree(pathstr);
|
||||
value = paramlookup(nccomm,tmpname);
|
||||
if(value != NULL && strlen(value) != 0) {
|
||||
@ -1285,13 +1291,13 @@ applyclientparams(NCDAPCOMMON* nccomm)
|
||||
CDFnode* var = (CDFnode*)nclistget(nccomm->cdf.ddsroot->tree->nodes,i);
|
||||
if(var->nctype != NC_Sequence) continue;
|
||||
var->sequencelimit = dfaltseqlim;
|
||||
strcpy(tmpname,"nolimit_");
|
||||
strncpy(tmpname,"nolimit_",sizeof(tmpname));
|
||||
pathstr = makeocpathstring(conn,var->ocnode,".");
|
||||
strncat(tmpname,pathstr,NC_MAX_NAME);
|
||||
strlcat(tmpname,pathstr,sizeof(tmpname));
|
||||
if(paramlookup(nccomm,tmpname) != NULL)
|
||||
var->sequencelimit = 0;
|
||||
strcpy(tmpname,"limit_");
|
||||
strncat(tmpname,pathstr,NC_MAX_NAME);
|
||||
strncpy(tmpname,"limit_",sizeof(tmpname));
|
||||
strlcat(tmpname,pathstr,sizeof(tmpname));
|
||||
value = paramlookup(nccomm,tmpname);
|
||||
if(value != NULL && strlen(value) != 0) {
|
||||
if(sscanf(value,"%d",&len) && len > 0)
|
||||
|
@ -90,8 +90,8 @@ main()
|
||||
exit(1);
|
||||
}
|
||||
printf("Using test server: %s\n",svc);
|
||||
strcpy(URL,svc);
|
||||
strcat(URL,DTSTEST);
|
||||
strncpy(URL,svc,sizeof(URL));
|
||||
strlcat(URL,DTSTEST,sizeof(URL));
|
||||
|
||||
memset((void*)target,0,sizeof(target));
|
||||
|
||||
|
@ -349,10 +349,12 @@ set_curl_properties(NCD4INFO* d4info)
|
||||
int ret = NC_NOERR;
|
||||
|
||||
if(d4info->auth.curlflags.useragent == NULL) {
|
||||
size_t len = strlen(DFALTUSERAGENT) + strlen(VERSION) + 1;
|
||||
char* agent = (char*)malloc(len+1);
|
||||
char* agent;
|
||||
size_t len = strlen(DFALTUSERAGENT) + strlen(VERSION);
|
||||
len++; /*strlcat nul*/
|
||||
agent = (char*)malloc(len+1);
|
||||
strncpy(agent,DFALTUSERAGENT,len);
|
||||
strncat(agent,VERSION,len);
|
||||
strlcat(agent,VERSION,len);
|
||||
d4info->auth.curlflags.useragent = agent;
|
||||
}
|
||||
|
||||
|
@ -76,14 +76,14 @@ d4odom_print(D4odometer* odom)
|
||||
char tmp[64];
|
||||
line[0] = '\0';
|
||||
if(odom->rank == 0) {
|
||||
strcat(line,"[]");
|
||||
strlcat(line,"[]",sizeof(line));
|
||||
} else for(i=0;i<odom->rank;i++) {
|
||||
sprintf(tmp,"[%lu/%lu:%lu:%lu]",
|
||||
(size_t)odom->index[i],
|
||||
(size_t)odom->start[i],
|
||||
(size_t)odom->stride[i],
|
||||
(size_t)odom->length[i]);
|
||||
strcat(line,tmp);
|
||||
strlcat(line,tmp,sizeof(line));
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
@ -525,7 +525,7 @@ parseSequence(NCD4parser* parser, NCD4node* container, ezxml_t xml, NCD4node** n
|
||||
vlentype->basetype = var->basetype;
|
||||
/* Use name <fqnname>_t */
|
||||
strncpy(name,fqnname,sizeof(name));
|
||||
strncat(name,"_t",sizeof(name)-strlen(name));
|
||||
strlcat(name,"_t",sizeof(name));
|
||||
SETNAME(vlentype,name);
|
||||
/* Set the basetype */
|
||||
var->basetype = vlentype;
|
||||
@ -540,7 +540,7 @@ parseSequence(NCD4parser* parser, NCD4node* container, ezxml_t xml, NCD4node** n
|
||||
classify(group,structtype);
|
||||
/* Use name <fqnname>_base */
|
||||
strncpy(name,fqnname,sizeof(name));
|
||||
strncat(name,"_base",sizeof(name)-strlen(name));
|
||||
strlcat(name,"_base",sizeof(name));
|
||||
SETNAME(structtype,name);
|
||||
/* Parse Fields into type */
|
||||
if((ret = parseFields(parser,structtype,xml))) goto done;
|
||||
@ -549,7 +549,7 @@ parseSequence(NCD4parser* parser, NCD4node* container, ezxml_t xml, NCD4node** n
|
||||
classify(group,vlentype);
|
||||
/* Use name <xname>_t */
|
||||
strncpy(name,fqnname,sizeof(name));
|
||||
strncat(name,"_t",sizeof(name)-strlen(name));
|
||||
strlcat(name,"_t",sizeof(name));
|
||||
SETNAME(vlentype,name);
|
||||
vlentype->basetype = structtype;
|
||||
/* Set the basetype */
|
||||
|
@ -113,19 +113,20 @@ NCD4_makeFQN(NCD4node* node)
|
||||
nclistinsert(path,0,g);
|
||||
}
|
||||
estimate = (estimate*2) + 2*nclistlength(path);
|
||||
/* start at 1 to avoid dataset */
|
||||
estimate++; /*strlcat nul*/
|
||||
fqn = (char*)malloc(estimate+1);
|
||||
if(fqn == NULL) goto done;
|
||||
fqn[0] = '\0';
|
||||
/* Create the group-based fqn prefix */
|
||||
/* start at 1 to avoid dataset */
|
||||
for(i=1;i<nclistlength(path);i++) {
|
||||
NCD4node* elem = (NCD4node*)nclistget(path,i);
|
||||
if(elem->sort != NCD4_GROUP) break;
|
||||
/* Add in the group name */
|
||||
escaped = backslashEscape(elem->name);
|
||||
if(escaped == NULL) {free(fqn); fqn = NULL; goto done;}
|
||||
strcat(fqn,"/");
|
||||
strcat(fqn,escaped);
|
||||
strlcat(fqn,"/",estimate);
|
||||
strlcat(fqn,escaped,estimate);
|
||||
free(escaped);
|
||||
}
|
||||
/* Add in the final name part (if not group) */
|
||||
@ -133,8 +134,8 @@ NCD4_makeFQN(NCD4node* node)
|
||||
int last = nclistlength(path)-1;
|
||||
NCD4node* n = (NCD4node*)nclistget(path,last);
|
||||
char* name = NCD4_makeName(n,".");
|
||||
strcat(fqn,"/");
|
||||
strcat(fqn,name);
|
||||
strlcat(fqn,"/",estimate);
|
||||
strlcat(fqn,name,estimate);
|
||||
nullfree(name);
|
||||
}
|
||||
|
||||
@ -161,7 +162,7 @@ NCD4_makeName(NCD4node* elem, const char* sep)
|
||||
nclistinsert(path,0,n);
|
||||
estimate += (1+(2*strlen(n->name)));
|
||||
}
|
||||
|
||||
estimate++; /*strlcat nul*/
|
||||
fqn = (char*)malloc(estimate+1);
|
||||
if(fqn == NULL) goto done;
|
||||
fqn[0] = '\0';
|
||||
@ -171,8 +172,8 @@ NCD4_makeName(NCD4node* elem, const char* sep)
|
||||
char* escaped = backslashEscape(elem->name);
|
||||
if(escaped == NULL) {free(fqn); fqn = NULL; goto done;}
|
||||
if(i > 0)
|
||||
strcat(fqn,sep);
|
||||
strcat(fqn,escaped);
|
||||
strlcat(fqn,sep,estimate);
|
||||
strlcat(fqn,escaped,estimate);
|
||||
free(escaped);
|
||||
}
|
||||
done:
|
||||
|
@ -27,7 +27,7 @@ Research/Unidata. See COPYRIGHT file for more info.
|
||||
/* If Defined, then use only stdio for all magic number io;
|
||||
otherwise use stdio or mpio as required.
|
||||
*/
|
||||
#define USE_STDIO
|
||||
#undef DEBUG
|
||||
|
||||
/**
|
||||
Sort info for open/read/close of
|
||||
@ -48,7 +48,9 @@ struct MagicFile {
|
||||
static int openmagic(struct MagicFile* file);
|
||||
static int readmagic(struct MagicFile* file, long pos, char* magic);
|
||||
static int closemagic(struct MagicFile* file);
|
||||
#ifdef DEBUG
|
||||
static void printmagic(const char* tag, char* magic,struct MagicFile*);
|
||||
#endif
|
||||
|
||||
extern int NC_initialized;
|
||||
extern int NC_finalized;
|
||||
@ -171,11 +173,7 @@ NC_check_file_type(const char *path, int flags, void *parameters,
|
||||
|
||||
int diskless = ((flags & NC_DISKLESS) == NC_DISKLESS);
|
||||
#ifdef USE_PARALLEL
|
||||
#ifdef USE_STDIO
|
||||
int use_parallel = 0;
|
||||
#else
|
||||
int use_parallel = ((flags & NC_MPIIO) == NC_MPIIO);
|
||||
#endif
|
||||
#endif /* USE_PARALLEL */
|
||||
int inmemory = (diskless && ((flags & NC_INMEMORY) == NC_INMEMORY));
|
||||
struct MagicFile file;
|
||||
@ -2062,7 +2060,6 @@ openmagic(struct MagicFile* file)
|
||||
/* Get its length */
|
||||
NC_MEM_INFO* meminfo = (NC_MEM_INFO*)file->parameters;
|
||||
file->filelen = (long long)meminfo->size;
|
||||
fprintf(stderr,"XXX: openmagic: memory=0x%llx size=%ld\n",(long long unsigned int)meminfo->memory,meminfo->size);
|
||||
goto done;
|
||||
}
|
||||
#ifdef USE_PARALLEL
|
||||
@ -2128,13 +2125,13 @@ readmagic(struct MagicFile* file, long pos, char* magic)
|
||||
if(file->inmemory) {
|
||||
char* mempos;
|
||||
NC_MEM_INFO* meminfo = (NC_MEM_INFO*)file->parameters;
|
||||
fprintf(stderr,"XXX: readmagic: memory=0x%llx size=%ld\n",(long long unsigned int)meminfo->memory,meminfo->size);
|
||||
fprintf(stderr,"XXX: readmagic: pos=%ld filelen=%lld\n",pos,file->filelen);
|
||||
if((pos + MAGIC_NUMBER_LEN) > meminfo->size)
|
||||
{status = NC_EDISKLESS; goto done;}
|
||||
mempos = ((char*)meminfo->memory) + pos;
|
||||
memcpy((void*)magic,mempos,MAGIC_NUMBER_LEN);
|
||||
printmagic("XXX: readmagic",magic,file);
|
||||
#ifdef DEBUG
|
||||
printmagic("XXX: readmagic",magic,file);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
#ifdef USE_PARALLEL
|
||||
@ -2191,6 +2188,7 @@ done:
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
static void
|
||||
printmagic(const char* tag, char* magic, struct MagicFile* f)
|
||||
{
|
||||
@ -2211,3 +2209,4 @@ printmagic(const char* tag, char* magic, struct MagicFile* f)
|
||||
fprintf(stderr,"\n");
|
||||
fflush(stderr);
|
||||
}
|
||||
#endif
|
||||
|
@ -5,8 +5,8 @@
|
||||
/* $Id: string.c,v 1.76 2010/05/26 21:43:33 dmh Exp $ */
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
@ -14,7 +14,6 @@
|
||||
#include "rnd.h"
|
||||
#include "ncutf8.h"
|
||||
|
||||
|
||||
/* There are 3 levels of UTF8 checking: 1=> (exact)validating 2=>relaxed
|
||||
and 3=>very relaxed
|
||||
*/
|
||||
@ -302,3 +301,58 @@ strdup(const char* s)
|
||||
#endif
|
||||
|
||||
/**************************************************/
|
||||
/* strlcat */
|
||||
/*
|
||||
* Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
#ifndef _MSC_VER /* We will use strcat_s */
|
||||
/*
|
||||
* Appends src to string dst of size dsize (unlike strncat, dsize is the
|
||||
* full size of dst, not space left). At most dsize-1 characters
|
||||
* will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
|
||||
* Returns strlen(src) + MIN(dsize, strlen(initial dst)).
|
||||
* If retval >= dsize, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcat(char* dst, const char* src, size_t dsize)
|
||||
{
|
||||
const char *odst = dst;
|
||||
const char *osrc = src;
|
||||
size_t n = dsize;
|
||||
size_t dlen;
|
||||
|
||||
/* Find the end of dst and adjust bytes left but don't go past end. */
|
||||
while (n-- != 0 && *dst != '\0')
|
||||
dst++;
|
||||
dlen = dst - odst;
|
||||
n = dsize - dlen;
|
||||
|
||||
if (n-- == 0)
|
||||
return(dlen + strlen(src));
|
||||
while (*src != '\0') {
|
||||
if (n != 0) {
|
||||
*dst++ = *src;
|
||||
n--;
|
||||
}
|
||||
src++;
|
||||
}
|
||||
*dst = '\0';
|
||||
|
||||
return(dlen + (src - osrc)); /* count does not include NUL */
|
||||
}
|
||||
#endif /*!_MSC_VER*/
|
||||
#endif /*!HAVE_STRLCAT*/
|
||||
|
@ -246,7 +246,7 @@ NC_mktmp(const char* base)
|
||||
#endif /* !HAVE_MKSTEMP */
|
||||
if(fd < 0) {
|
||||
nclog(NCLOGERR, "Could not create temp file: %s",tmp);
|
||||
return (NC_EPERM);
|
||||
return NULL;
|
||||
} else
|
||||
close(fd);
|
||||
return strdup(tmp);
|
||||
|
@ -85,6 +85,8 @@ EXTRA_DIST = tst_ncdap3.sh \
|
||||
t_ncf330.c tst_ber.sh
|
||||
|
||||
CLEANFILES = test_varm3 test_cvt3 results/*.dmp results/*.das results/*.dds datadds* t_dap3a test_nstride_cached *.exe
|
||||
# This should only be left behind if using parallel io
|
||||
CLEANFILES += tmp_*
|
||||
|
||||
# This rule are used if someone wants to rebuild t_dap3a.c
|
||||
# Otherwise never invoked, but records how to do it.
|
||||
|
@ -110,7 +110,7 @@ int main()
|
||||
{
|
||||
int ncid, varid;
|
||||
int ncstat = NC_NOERR;
|
||||
char* url;
|
||||
char url[8192];
|
||||
const char* topsrcdir;
|
||||
size_t len;
|
||||
#ifndef USE_NETCDF4
|
||||
@ -123,20 +123,15 @@ int main()
|
||||
|
||||
topsrcdir = gettopsrcdir();
|
||||
|
||||
len = strlen("file://") + strlen(topsrcdir) + strlen("/ncdap_test/testdata3/test.02") + 1;
|
||||
#ifdef DEBUG
|
||||
len += strlen("[log][show=fetch]");
|
||||
#endif
|
||||
url = (char*)malloc(len);
|
||||
url[0] = '\0';
|
||||
|
||||
#ifdef DEBUG
|
||||
strcat(url,"[log][show=fetch]");
|
||||
strlcat(url,"[log][show=fetch]",sizeof(url));
|
||||
#endif
|
||||
|
||||
strcat(url,"file://");
|
||||
strcat(url,topsrcdir);
|
||||
strcat(url,"/ncdap_test/testdata3/test.02");
|
||||
strlcat(url,"file://",sizeof(url));
|
||||
strlcat(url,topsrcdir,sizeof(url));
|
||||
strlcat(url,"/ncdap_test/testdata3/test.02",sizeof(url));
|
||||
|
||||
printf("*** Test: var conversions on URL: %s\n",url);
|
||||
|
||||
|
@ -111,7 +111,7 @@ int main()
|
||||
{
|
||||
int ncid, varid;
|
||||
int ncstat = NC_NOERR;
|
||||
char* url;
|
||||
char url[8102];
|
||||
const char* topsrcdir;
|
||||
size_t len;
|
||||
#ifndef USE_NETCDF4
|
||||
@ -124,20 +124,15 @@ int main()
|
||||
|
||||
topsrcdir = gettopsrcdir();
|
||||
|
||||
len = strlen("file://") + strlen(topsrcdir) + strlen("/ncdap_test/testdata3/test.02") + 1;
|
||||
#ifdef DEBUG
|
||||
len += strlen("[log][show=fetch]");
|
||||
#endif
|
||||
url = (char*)malloc(len);
|
||||
url[0] = '\0';
|
||||
|
||||
#ifdef DEBUG
|
||||
strcat(url,"[log][show=fetch]");
|
||||
strlcat(url,"[log][show=fetch]",sizeof(url));
|
||||
#endif
|
||||
|
||||
strcat(url,"file://");
|
||||
strcat(url,topsrcdir);
|
||||
strcat(url,"/ncdap_test/testdata3/test.02");
|
||||
strlcat(url,"file://",sizeof(url));
|
||||
strlcat(url,topsrcdir,sizeof(url));
|
||||
strlcat(url,"/ncdap_test/testdata3/test.02",sizeof(url));
|
||||
|
||||
printf("*** Test: var conversions on URL: %s\n",url);
|
||||
|
||||
|
@ -27,9 +27,9 @@ main()
|
||||
|
||||
topsrcdir = gettopsrcdir();
|
||||
|
||||
strcpy(url,"file://");
|
||||
strcat(url,topsrcdir);
|
||||
strcat(url,"/ncdap_test/testdata3/test.02");
|
||||
strncpy(url,"file://",sizeof(url));
|
||||
strlcat(url,topsrcdir,sizeof(url));
|
||||
strlcat(url,"/ncdap_test/testdata3/test.02",sizeof(url));
|
||||
|
||||
if ((retval = nc_open(url, 0, &ncid)))
|
||||
ERR(retval);
|
||||
|
@ -1,466 +0,0 @@
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "netcdf.h"
|
||||
#include "t_srcdir.h"
|
||||
|
||||
#undef GENERATE
|
||||
|
||||
#undef DEBUG
|
||||
|
||||
/* Test (some) internal/external type conversions
|
||||
using following DAP dataset (test.02).
|
||||
Dataset {
|
||||
Byte b[DIMSIZE];
|
||||
Int32 i32[DIMSIZE];
|
||||
UInt32 ui32[DIMSIZE];
|
||||
Int16 i16[DIMSIZE];
|
||||
UInt16 ui16[DIMSIZE];
|
||||
Float32 f32[DIMSIZE];
|
||||
Float64 f64[DIMSIZE];
|
||||
String s[DIMSIZE];
|
||||
Url u[DIMSIZE];
|
||||
} OneDimensionalSimpleArrays;
|
||||
*/
|
||||
|
||||
#define NDIMS 1
|
||||
#define DIMSIZE 25
|
||||
#define STRLEN 64
|
||||
|
||||
#ifndef USE_NETCDF4
|
||||
#define NC_UBYTE 7 /* unsigned 1 byte int */
|
||||
#define NC_USHORT 8 /* unsigned 2-byte int */
|
||||
#define NC_UINT 9 /* unsigned 4-byte int */
|
||||
#define NC_INT64 10 /* signed 8-byte int */
|
||||
#define NC_UINT64 11 /* unsigned 8-byte int */
|
||||
#define NC_STRING 12 /* string */
|
||||
#endif
|
||||
|
||||
|
||||
#define CHECK(expr) check(expr,__FILE__,__LINE__);
|
||||
|
||||
#define COMMA (i==0?"":",")
|
||||
|
||||
#define COMPARE(t1,t2,v1,v2) compare(t1,t2,(void*)v1,(void*)v2,#v2,__FILE__,__LINE__)
|
||||
|
||||
static int failure = 0;
|
||||
|
||||
static void compare(nc_type,nc_type,void*,void*,char*,char*,int);
|
||||
|
||||
static void
|
||||
report(const int i, const char* var, const int line)
|
||||
{
|
||||
fprintf(stdout,"%s mismatch: [%d] file: %s line: %d\n",var,i,__FILE__,line);
|
||||
failure = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
check(int ncstat, char* file, int line)
|
||||
{
|
||||
if(ncstat == NC_NOERR) return;
|
||||
fprintf(stderr,"*** FAIL: %d (%s) at %s:%d\n",
|
||||
ncstat,nc_strerror(ncstat),file,line);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* return 1 if |f1-f2| > 0.05 */
|
||||
static int
|
||||
fdiff(double f1, double f2)
|
||||
{
|
||||
double delta = (f1 - f2);
|
||||
if(delta < 0) delta = - delta;
|
||||
if(delta > 0.05) {
|
||||
fprintf(stdout,"fdiff: %1.3f %1.3f delta=%1.3f\n",f1,f2,delta);
|
||||
}
|
||||
return (delta > 0.05?1:0);
|
||||
}
|
||||
|
||||
static char ch_data[DIMSIZE];
|
||||
static signed char int8_data[DIMSIZE];
|
||||
static unsigned char uint8_data[DIMSIZE];
|
||||
static int int8toint32_data[DIMSIZE];
|
||||
static float int82float32_data[DIMSIZE];
|
||||
static short int16_data[DIMSIZE];
|
||||
static int int16toint32_data[DIMSIZE];
|
||||
static float int162float32_data[DIMSIZE];
|
||||
static int int32_data[DIMSIZE];
|
||||
static float int32tofloat32_data[DIMSIZE];
|
||||
static long int32toilong_data[DIMSIZE];
|
||||
static float float32_data[DIMSIZE];
|
||||
static double float64_data[DIMSIZE];
|
||||
#ifndef USE_NETCDF4
|
||||
static char string3_data[DIMSIZE][STRLEN];
|
||||
#endif
|
||||
|
||||
static char ch[DIMSIZE];
|
||||
static signed char int8[DIMSIZE];
|
||||
static unsigned char uint8[DIMSIZE];
|
||||
static short int16[DIMSIZE];
|
||||
static int int32[DIMSIZE];
|
||||
static float float32[DIMSIZE];
|
||||
static double float64[DIMSIZE];
|
||||
static long ilong[DIMSIZE];
|
||||
#ifndef USE_NETCDF4
|
||||
static char string3[DIMSIZE][STRLEN];
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
int ncid, varid;
|
||||
int ncstat = NC_NOERR;
|
||||
char* url;
|
||||
const char* topsrcdir;
|
||||
size_t len;
|
||||
#ifndef USE_NETCDF4
|
||||
int i,j;
|
||||
#endif
|
||||
|
||||
/* location of our target url: use file:// to avoid remote
|
||||
server downtime issues
|
||||
*/
|
||||
|
||||
topsrcdir = gettopsrcdir();
|
||||
|
||||
len = strlen("file://") + strlen(topsrcdir) + strlen("/ncdap_test/testdata3/test.02") + 1;
|
||||
#ifdef DEBUG
|
||||
len += strlen("[log][show=fetch]");
|
||||
#endif
|
||||
url = (char*)malloc(len);
|
||||
url[0] = '\0';
|
||||
|
||||
#ifdef DEBUG
|
||||
strcat(url,"[log][show=fetch]");
|
||||
#endif
|
||||
|
||||
strcat(url,"file://");
|
||||
strcat(url,topsrcdir);
|
||||
strcat(url,"/ncdap_test/testdata3/test.02");
|
||||
|
||||
printf("*** Test: var conversions on URL: %s\n",url);
|
||||
|
||||
/* open file, get varid */
|
||||
CHECK(nc_open(url, NC_NOWRITE, &ncid));
|
||||
|
||||
/* extract the string case for netcdf-3*/
|
||||
#ifndef USE_NETCDF4
|
||||
CHECK(nc_inq_varid(ncid, "s", &varid));
|
||||
CHECK(nc_get_var_text(ncid,varid,(char*)string3));
|
||||
#ifdef GENERATE
|
||||
printf("static %s string3_data[DIMSIZE][STRLEN]={","char");
|
||||
for(i=0;i<DIMSIZE;i++) {
|
||||
int j;
|
||||
/* Do simple escape */
|
||||
for(j=0;j<STRLEN;j++) {
|
||||
if(string3[i][j] > 0
|
||||
&& string3[i][j] != '\n'
|
||||
&& string3[i][j] != '\r'
|
||||
&& string3[i][j] != '\t'
|
||||
&&(string3[i][j] < ' ' || string3[i][j] >= '\177'))
|
||||
string3[i][j] = '?';
|
||||
}
|
||||
printf("%s\"%s\"",COMMA,string3[i]);
|
||||
}
|
||||
printf("};\n");
|
||||
#else
|
||||
fprintf(stdout,"*** testing: %s\n","string3");
|
||||
for(i=0;i<DIMSIZE;i++) {
|
||||
for(j=0;j<STRLEN;j++) {
|
||||
if(string3[i][j] != string3_data[i][j]) {report(i,"string3",__LINE__); break;}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_text(ncid,varid,ch));
|
||||
#ifdef GENERATE
|
||||
printf("static %s ch_data[DIMSIZE]={","char");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s'\\%03hho'",COMMA,ch[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_CHAR,NC_CHAR,ch,ch_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_schar(ncid,varid,int8));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int8_data[DIMSIZE]={","signed char");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hhd",COMMA,int8[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_BYTE,NC_BYTE,int8,int8_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_uchar(ncid,varid,uint8));
|
||||
#ifdef GENERATE
|
||||
printf("static %s uint8_data[DIMSIZE]={","unsigned char");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hhu",COMMA,uint8[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_UBYTE,NC_UBYTE,uint8,uint8_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int8toint32_data[DIMSIZE]={","int");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_BYTE,NC_INT,int32,int8toint32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int82float32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_FLOAT,NC_FLOAT,float32,int82float32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i16", &varid));
|
||||
CHECK(nc_get_var_short(ncid,varid,int16));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int16_data[DIMSIZE]={","short");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hd",COMMA,int16[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_SHORT,NC_SHORT,int16,int16_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i16", &varid));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int16toint32_data[DIMSIZE]={","int");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_SHORT,NC_INT,int32,int16toint32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i16", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int162float32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_SHORT,NC_FLOAT,float32,int162float32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i32", &varid));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int32_data[DIMSIZE]={","int");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_INT,NC_INT,int32,int32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i32", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int32tofloat32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_INT,NC_FLOAT,float32,int32tofloat32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i32", &varid));
|
||||
CHECK(nc_get_var_long(ncid,varid,ilong));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int32toilong_data[DIMSIZE]={","long");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%ld",COMMA,ilong[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_INT,NC_NAT,ilong,int32toilong_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "f32", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
#ifdef GENERATE
|
||||
printf("static %s float32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_FLOAT,NC_FLOAT,float32,float32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "f64", &varid));
|
||||
CHECK(nc_get_var_double(ncid,varid,float64));
|
||||
#ifdef GENERATE
|
||||
printf("static %s float64_data[DIMSIZE]={","double");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float64[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_DOUBLE,NC_DOUBLE,float64,float64_data);
|
||||
#endif
|
||||
|
||||
if(failure) {
|
||||
printf("ncstat=%d %s",ncstat,nc_strerror(ncstat));
|
||||
exit(1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char ch_data[DIMSIZE]={'\000','\001','\002','\003','\004','\005','\006','\007','\010','\011','\012','\013','\014','\015','\016','\017','\020','\021','\022','\023','\024','\025','\026','\027','\030'};
|
||||
static signed char int8_data[DIMSIZE]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24};
|
||||
static unsigned char uint8_data[DIMSIZE]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24};
|
||||
static int int8toint32_data[DIMSIZE]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24};
|
||||
static float int82float32_data[DIMSIZE]={0.000,1.000,2.000,3.000,4.000,5.000,6.000,7.000,8.000,9.000,10.000,11.000,12.000,13.000,14.000,15.000,16.000,17.000,18.000,19.000,20.000,21.000,22.000,23.000,24.000};
|
||||
static short int16_data[DIMSIZE]={0,256,512,768,1024,1280,1536,1792,2048,2304,2560,2816,3072,3328,3584,3840,4096,4352,4608,4864,5120,5376,5632,5888,6144};
|
||||
static int int16toint32_data[DIMSIZE]={0,256,512,768,1024,1280,1536,1792,2048,2304,2560,2816,3072,3328,3584,3840,4096,4352,4608,4864,5120,5376,5632,5888,6144};
|
||||
static float int162float32_data[DIMSIZE]={0.000,256.000,512.000,768.000,1024.000,1280.000,1536.000,1792.000,2048.000,2304.000,2560.000,2816.000,3072.000,3328.000,3584.000,3840.000,4096.000,4352.000,4608.000,4864.000,5120.000,5376.000,5632.000,5888.000,6144.000};
|
||||
static int int32_data[DIMSIZE]={0,2048,4096,6144,8192,10240,12288,14336,16384,18432,20480,22528,24576,26624,28672,30720,32768,34816,36864,38912,40960,43008,45056,47104,49152};
|
||||
static float int32tofloat32_data[DIMSIZE]={0.000,2048.000,4096.000,6144.000,8192.000,10240.000,12288.000,14336.000,16384.000,18432.000,20480.000,22528.000,24576.000,26624.000,28672.000,30720.000,32768.000,34816.000,36864.000,38912.000,40960.000,43008.000,45056.000,47104.000,49152.000};
|
||||
static long int32toilong_data[DIMSIZE]={0,2048,4096,6144,8192,10240,12288,14336,16384,18432,20480,22528,24576,26624,28672,30720,32768,34816,36864,38912,40960,43008,45056,47104,49152};
|
||||
static float float32_data[DIMSIZE]={0.000,0.010,0.020,0.030,0.040,0.050,0.060,0.070,0.080,0.090,0.100,0.110,0.120,0.130,0.140,0.149,0.159,0.169,0.179,0.189,0.199,0.208,0.218,0.228,0.238};
|
||||
static double float64_data[DIMSIZE]={1.000,1.000,1.000,1.000,0.999,0.999,0.998,0.998,0.997,0.996,0.995,0.994,0.993,0.992,0.990,0.989,0.987,0.986,0.984,0.982,0.980,0.978,0.976,0.974,0.971};
|
||||
|
||||
#ifndef USE_NETCDF4
|
||||
static char string3_data[DIMSIZE][STRLEN]={"This is a data test string (pass 0).","This is a data test string (pass 1).","This is a data test string (pass 2).","This is a data test string (pass 3).","This is a data test string (pass 4).","This is a data test string (pass 5).","This is a data test string (pass 6).","This is a data test string (pass 7).","This is a data test string (pass 8).","This is a data test string (pass 9).","This is a data test string (pass 10).","This is a data test string (pass 11).","This is a data test string (pass 12).","This is a data test string (pass 13).","This is a data test string (pass 14).","This is a data test string (pass 15).","This is a data test string (pass 16).","This is a data test string (pass 17).","This is a data test string (pass 18).","This is a data test string (pass 19).","This is a data test string (pass 20).","This is a data test string (pass 21).","This is a data test string (pass 22).","This is a data test string (pass 23).","This is a data test string (pass 24)."};
|
||||
#endif
|
||||
|
||||
static void
|
||||
compare(nc_type t1, nc_type t2, void* v0, void* vdata0, char* tag,
|
||||
char* file, int line)
|
||||
{
|
||||
int i;
|
||||
fprintf(stdout,"*** testing: %s\n",tag); \
|
||||
|
||||
#ifdef DEBUG
|
||||
#define test \
|
||||
printf("v ="); \
|
||||
for(i=0;i<DIMSIZE;i++) {printf(" %llu",(unsigned long long)v[i]);} \
|
||||
printf("\n"); \
|
||||
printf("vdata ="); \
|
||||
for(i=0;i<DIMSIZE;i++) {printf(" %llu",(unsigned long long)vdata[i]);} \
|
||||
printf("\n"); \
|
||||
for(i=0;i<DIMSIZE;i++) {\
|
||||
if(v[i] != vdata[i]) {report(i,tag,line); break;}\
|
||||
}
|
||||
#define ftest \
|
||||
printf("v ="); \
|
||||
for(i=0;i<DIMSIZE;i++) {printf(" %g",v[i]);} \
|
||||
printf("\n"); \
|
||||
printf("vdata ="); \
|
||||
for(i=0;i<DIMSIZE;i++) {printf(" %g",vdata[i]);} \
|
||||
printf("\n"); \
|
||||
for(i=0;i<DIMSIZE;i++) {\
|
||||
if(fdiff((double)v[i],(double)vdata[i])) {report(i,tag,line); break;}\
|
||||
}
|
||||
#else
|
||||
#define test for(i=0;i<DIMSIZE;i++) {\
|
||||
if(v[i] != vdata[i]) {report(i,tag,line); break;}\
|
||||
}
|
||||
#define ftest for(i=0;i<DIMSIZE;i++) {\
|
||||
if(fdiff((double)v[i],(double)vdata[i])) {report(i,tag,line); break;}\
|
||||
}
|
||||
#endif
|
||||
|
||||
#define setup(T) T* v = (T*)v0; T* vdata = (T*)vdata0;
|
||||
|
||||
#define CASE(nc1,nc2) (nc1*256+nc2)
|
||||
switch(CASE(t1,t2)) {
|
||||
|
||||
default: {
|
||||
printf("unexpected compare: %d %d\n",(int)t1,(int)t2);
|
||||
abort();
|
||||
}
|
||||
|
||||
case CASE(NC_CHAR,NC_CHAR): {
|
||||
setup(char);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_BYTE,NC_BYTE): {
|
||||
setup(signed char);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_SHORT,NC_SHORT): {
|
||||
setup(short);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_INT,NC_INT): {
|
||||
setup(int);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_FLOAT,NC_FLOAT): {
|
||||
setup(float);
|
||||
ftest;
|
||||
} break;
|
||||
case CASE(NC_DOUBLE,NC_DOUBLE): {
|
||||
setup(double);
|
||||
ftest;
|
||||
} break;
|
||||
|
||||
|
||||
/* Mixed comparisons */
|
||||
case CASE(NC_BYTE,NC_INT): {
|
||||
setup(int);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_SHORT,NC_INT): {
|
||||
setup(int);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_SHORT,NC_FLOAT): {
|
||||
setup(float);
|
||||
ftest;
|
||||
} break;
|
||||
case CASE(NC_INT,NC_FLOAT): {
|
||||
setup(float);
|
||||
ftest;
|
||||
} break;
|
||||
|
||||
/* This is an get_var_long case */
|
||||
case CASE(NC_INT,NC_NAT): {
|
||||
setup(long);
|
||||
test;
|
||||
} break;
|
||||
|
||||
case CASE(NC_UBYTE,NC_UBYTE): {
|
||||
setup(unsigned char);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_USHORT,NC_USHORT): {
|
||||
setup(unsigned short);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_UINT,NC_UINT): {
|
||||
setup(unsigned int);
|
||||
test;
|
||||
} break;
|
||||
|
||||
/* Mixed cases */
|
||||
case CASE(NC_INT,NC_INT64): {
|
||||
setup(long long);
|
||||
test;
|
||||
} break;
|
||||
|
||||
case CASE(NC_INT,NC_UINT64): {
|
||||
setup(unsigned long long);
|
||||
test;
|
||||
} break;
|
||||
|
||||
case CASE(NC_STRING,NC_STRING):{
|
||||
setup(char*);
|
||||
for(i=0;i<DIMSIZE;i++) {
|
||||
if(strcmp(v[i],vdata[i])!=0) {report(i,tag,line); break;}
|
||||
}
|
||||
} break;
|
||||
|
||||
case CASE(NC_CHAR,NC_STRING):{
|
||||
setup(char*);
|
||||
if(memcmp((void*)v[0],(void*)vdata,DIMSIZE+1)!=0)
|
||||
{report(0,tag,line);}
|
||||
} break;
|
||||
|
||||
} /*switch*/
|
||||
}
|
||||
|
@ -1,937 +0,0 @@
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "netcdf.h"
|
||||
#include "t_srcdir.h"
|
||||
|
||||
#undef GENERATE
|
||||
|
||||
#undef DEBUG
|
||||
|
||||
/* Test (some) internal/external type conversions
|
||||
using following DAP dataset (test.02).
|
||||
Dataset {
|
||||
Byte b[DIMSIZE];
|
||||
Int32 i32[DIMSIZE];
|
||||
UInt32 ui32[DIMSIZE];
|
||||
Int16 i16[DIMSIZE];
|
||||
UInt16 ui16[DIMSIZE];
|
||||
Float32 f32[DIMSIZE];
|
||||
Float64 f64[DIMSIZE];
|
||||
String s[DIMSIZE];
|
||||
Url u[DIMSIZE];
|
||||
} OneDimensionalSimpleArrays;
|
||||
*/
|
||||
|
||||
#define NDIMS 1
|
||||
#define DIMSIZE 25
|
||||
#define STRLEN 64
|
||||
|
||||
#ifndef USE_NETCDF4
|
||||
#define NC_UBYTE 7 /* unsigned 1 byte int */
|
||||
#define NC_USHORT 8 /* unsigned 2-byte int */
|
||||
#define NC_UINT 9 /* unsigned 4-byte int */
|
||||
#define NC_INT64 10 /* signed 8-byte int */
|
||||
#define NC_UINT64 11 /* unsigned 8-byte int */
|
||||
#define NC_STRING 12 /* string */
|
||||
#endif
|
||||
|
||||
|
||||
#define CHECK(expr) check(expr,__FILE__,__LINE__);
|
||||
|
||||
#define COMMA (i==0?"":",")
|
||||
|
||||
#define COMPARE(t1,t2,v1,v2) compare(t1,t2,(void*)v1,(void*)v2,#v2,__FILE__,__LINE__)
|
||||
|
||||
static int failure = 0;
|
||||
|
||||
static void compare(nc_type,nc_type,void*,void*,char*,char*,int);
|
||||
|
||||
static void
|
||||
report(const int i, const char* var, const int line)
|
||||
{
|
||||
fprintf(stdout,"%s mismatch: [%d] file: %s line: %d\n",var,i,__FILE__,line);
|
||||
failure = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
check(int ncstat, char* file, int line)
|
||||
{
|
||||
if(ncstat == NC_NOERR) return;
|
||||
fprintf(stderr,"*** FAIL: %d (%s) at %s:%d\n",
|
||||
ncstat,nc_strerror(ncstat),file,line);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* return 1 if |f1-f2| > 0.05 */
|
||||
static int
|
||||
fdiff(double f1, double f2)
|
||||
{
|
||||
double delta = (f1 - f2);
|
||||
if(delta < 0) delta = - delta;
|
||||
if(delta > 0.05) {
|
||||
fprintf(stdout,"fdiff: %1.3f %1.3f delta=%1.3f\n",f1,f2,delta);
|
||||
}
|
||||
return (delta > 0.05?1:0);
|
||||
}
|
||||
|
||||
static char ch_data[DIMSIZE];
|
||||
static signed char int8_data[DIMSIZE];
|
||||
static unsigned char uint8_data[DIMSIZE];
|
||||
static int int8toint32_data[DIMSIZE];
|
||||
static float int82float32_data[DIMSIZE];
|
||||
static short int16_data[DIMSIZE];
|
||||
static int int16toint32_data[DIMSIZE];
|
||||
static float int162float32_data[DIMSIZE];
|
||||
static int int32_data[DIMSIZE];
|
||||
static float int32tofloat32_data[DIMSIZE];
|
||||
static long int32toilong_data[DIMSIZE];
|
||||
static float float32_data[DIMSIZE];
|
||||
static double float64_data[DIMSIZE];
|
||||
#ifndef USE_NETCDF4
|
||||
static char string3_data[DIMSIZE][STRLEN];
|
||||
#endif
|
||||
|
||||
static char ch[DIMSIZE];
|
||||
static signed char int8[DIMSIZE];
|
||||
static unsigned char uint8[DIMSIZE];
|
||||
static short int16[DIMSIZE];
|
||||
static int int32[DIMSIZE];
|
||||
static float float32[DIMSIZE];
|
||||
static double float64[DIMSIZE];
|
||||
static long ilong[DIMSIZE];
|
||||
#ifndef USE_NETCDF4
|
||||
static char string3[DIMSIZE][STRLEN];
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
int ncid, varid;
|
||||
int ncstat = NC_NOERR;
|
||||
char* url;
|
||||
const char* topsrcdir;
|
||||
size_t len;
|
||||
#ifndef USE_NETCDF4
|
||||
int i,j;
|
||||
#endif
|
||||
|
||||
/* location of our target url: use file:// to avoid remote
|
||||
server downtime issues
|
||||
*/
|
||||
|
||||
/* Assume that TESTS_ENVIRONMENT was set */
|
||||
topsrcdir = gettopsrcdir();
|
||||
|
||||
len = strlen("file://") + strlen(topsrcdir) + strlen("/ncdap_test/testdata3/test.02") + 1;
|
||||
#ifdef DEBUG
|
||||
len += strlen("[log][show=fetch]");
|
||||
#endif
|
||||
url = (char*)malloc(len);
|
||||
url[0] = '\0';
|
||||
|
||||
#ifdef DEBUG
|
||||
strcat(url,"[log][show=fetch]");
|
||||
#endif
|
||||
|
||||
strcat(url,"file://");
|
||||
strcat(url,topsrcdir);
|
||||
strcat(url,"/ncdap_test/testdata3/test.02");
|
||||
|
||||
printf("*** Test: var conversions on URL: %s\n",url);
|
||||
|
||||
/* open file, get varid */
|
||||
CHECK(nc_open(url, NC_NOWRITE, &ncid));
|
||||
|
||||
/* extract the string case for netcdf-3*/
|
||||
#ifndef USE_NETCDF4
|
||||
CHECK(nc_inq_varid(ncid, "s", &varid));
|
||||
CHECK(nc_get_var_text(ncid,varid,(char*)string3));
|
||||
#ifdef GENERATE
|
||||
printf("static %s string3_data[DIMSIZE][STRLEN]={","char");
|
||||
for(i=0;i<DIMSIZE;i++) {
|
||||
int j;
|
||||
/* Do simple escape */
|
||||
for(j=0;j<STRLEN;j++) {
|
||||
if(string3[i][j] > 0
|
||||
&& string3[i][j] != '\n'
|
||||
&& string3[i][j] != '\r'
|
||||
&& string3[i][j] != '\t'
|
||||
&&(string3[i][j] < ' ' || string3[i][j] >= '\177'))
|
||||
string3[i][j] = '?';
|
||||
}
|
||||
printf("%s\"%s\"",COMMA,string3[i]);
|
||||
}
|
||||
printf("};\n");
|
||||
#else
|
||||
fprintf(stdout,"*** testing: %s\n","string3");
|
||||
for(i=0;i<DIMSIZE;i++) {
|
||||
for(j=0;j<STRLEN;j++) {
|
||||
if(string3[i][j] != string3_data[i][j]) {report(i,"string3",__LINE__); break;}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_text(ncid,varid,ch));
|
||||
#ifdef GENERATE
|
||||
printf("static %s ch_data[DIMSIZE]={","char");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s'\\%03hho'",COMMA,ch[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_CHAR,NC_CHAR,ch,ch_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_schar(ncid,varid,int8));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int8_data[DIMSIZE]={","signed char");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hhd",COMMA,int8[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_BYTE,NC_BYTE,int8,int8_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_uchar(ncid,varid,uint8));
|
||||
#ifdef GENERATE
|
||||
printf("static %s uint8_data[DIMSIZE]={","unsigned char");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hhu",COMMA,uint8[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_UBYTE,NC_UBYTE,uint8,uint8_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int8toint32_data[DIMSIZE]={","int");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_BYTE,NC_INT,int32,int8toint32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int82float32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_FLOAT,NC_FLOAT,float32,int82float32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i16", &varid));
|
||||
CHECK(nc_get_var_short(ncid,varid,int16));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int16_data[DIMSIZE]={","short");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hd",COMMA,int16[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_SHORT,NC_SHORT,int16,int16_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i16", &varid));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int16toint32_data[DIMSIZE]={","int");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_SHORT,NC_INT,int32,int16toint32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i16", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int162float32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_SHORT,NC_FLOAT,float32,int162float32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i32", &varid));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int32_data[DIMSIZE]={","int");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_INT,NC_INT,int32,int32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i32", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int32tofloat32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_INT,NC_FLOAT,float32,int32tofloat32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i32", &varid));
|
||||
CHECK(nc_get_var_long(ncid,varid,ilong));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int32toilong_data[DIMSIZE]={","long");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%ld",COMMA,ilong[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_INT,NC_NAT,ilong,int32toilong_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "f32", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32));
|
||||
#ifdef GENERATE
|
||||
printf("static %s float32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_FLOAT,NC_FLOAT,float32,float32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "f64", &varid));
|
||||
CHECK(nc_get_var_double(ncid,varid,float64));
|
||||
#ifdef GENERATE
|
||||
printf("static %s float64_data[DIMSIZE]={","double");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float64[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_DOUBLE,NC_DOUBLE,float64,float64_data);
|
||||
#endif
|
||||
|
||||
if(failure) {
|
||||
printf("ncstat=%d %s",ncstat,nc_strerror(ncstat));
|
||||
exit(1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char ch_data[DIMSIZE]={'\000','\001','\002','\003','\004','\005','\006','\007','\010','\011','\012','\013','\014','\015','\016','\017','\020','\021','\022','\023','\024','\025','\026','\027','\030'};
|
||||
static signed char int8_data[DIMSIZE]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24};
|
||||
static unsigned char uint8_data[DIMSIZE]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24};
|
||||
static int int8toint32_data[DIMSIZE]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24};
|
||||
static float int82float32_data[DIMSIZE]={0.000,1.000,2.000,3.000,4.000,5.000,6.000,7.000,8.000,9.000,10.000,11.000,12.000,13.000,14.000,15.000,16.000,17.000,18.000,19.000,20.000,21.000,22.000,23.000,24.000};
|
||||
static short int16_data[DIMSIZE]={0,256,512,768,1024,1280,1536,1792,2048,2304,2560,2816,3072,3328,3584,3840,4096,4352,4608,4864,5120,5376,5632,5888,6144};
|
||||
static int int16toint32_data[DIMSIZE]={0,256,512,768,1024,1280,1536,1792,2048,2304,2560,2816,3072,3328,3584,3840,4096,4352,4608,4864,5120,5376,5632,5888,6144};
|
||||
static float int162float32_data[DIMSIZE]={0.000,256.000,512.000,768.000,1024.000,1280.000,1536.000,1792.000,2048.000,2304.000,2560.000,2816.000,3072.000,3328.000,3584.000,3840.000,4096.000,4352.000,4608.000,4864.000,5120.000,5376.000,5632.000,5888.000,6144.000};
|
||||
static int int32_data[DIMSIZE]={0,2048,4096,6144,8192,10240,12288,14336,16384,18432,20480,22528,24576,26624,28672,30720,32768,34816,36864,38912,40960,43008,45056,47104,49152};
|
||||
static float int32tofloat32_data[DIMSIZE]={0.000,2048.000,4096.000,6144.000,8192.000,10240.000,12288.000,14336.000,16384.000,18432.000,20480.000,22528.000,24576.000,26624.000,28672.000,30720.000,32768.000,34816.000,36864.000,38912.000,40960.000,43008.000,45056.000,47104.000,49152.000};
|
||||
static long int32toilong_data[DIMSIZE]={0,2048,4096,6144,8192,10240,12288,14336,16384,18432,20480,22528,24576,26624,28672,30720,32768,34816,36864,38912,40960,43008,45056,47104,49152};
|
||||
static float float32_data[DIMSIZE]={0.000,0.010,0.020,0.030,0.040,0.050,0.060,0.070,0.080,0.090,0.100,0.110,0.120,0.130,0.140,0.149,0.159,0.169,0.179,0.189,0.199,0.208,0.218,0.228,0.238};
|
||||
static double float64_data[DIMSIZE]={1.000,1.000,1.000,1.000,0.999,0.999,0.998,0.998,0.997,0.996,0.995,0.994,0.993,0.992,0.990,0.989,0.987,0.986,0.984,0.982,0.980,0.978,0.976,0.974,0.971};
|
||||
|
||||
#ifndef USE_NETCDF4
|
||||
static char string3_data[DIMSIZE][STRLEN]={"This is a data test string (pass 0).","This is a data test string (pass 1).","This is a data test string (pass 2).","This is a data test string (pass 3).","This is a data test string (pass 4).","This is a data test string (pass 5).","This is a data test string (pass 6).","This is a data test string (pass 7).","This is a data test string (pass 8).","This is a data test string (pass 9).","This is a data test string (pass 10).","This is a data test string (pass 11).","This is a data test string (pass 12).","This is a data test string (pass 13).","This is a data test string (pass 14).","This is a data test string (pass 15).","This is a data test string (pass 16).","This is a data test string (pass 17).","This is a data test string (pass 18).","This is a data test string (pass 19).","This is a data test string (pass 20).","This is a data test string (pass 21).","This is a data test string (pass 22).","This is a data test string (pass 23).","This is a data test string (pass 24)."};
|
||||
#endif
|
||||
|
||||
static void
|
||||
compare(nc_type t1, nc_type t2, void* v0, void* vdata0, char* tag,
|
||||
char* file, int line)
|
||||
{
|
||||
int i;
|
||||
fprintf(stdout,"*** testing: %s\n",tag); \
|
||||
|
||||
#ifdef DEBUG
|
||||
#define test \
|
||||
printf("v ="); \
|
||||
for(i=0;i<DIMSIZE;i++) {printf(" %llu",(unsigned long long)v[i]);} \
|
||||
printf("\n"); \
|
||||
printf("vdata ="); \
|
||||
for(i=0;i<DIMSIZE;i++) {printf(" %llu",(unsigned long long)vdata[i]);} \
|
||||
printf("\n"); \
|
||||
for(i=0;i<DIMSIZE;i++) {\
|
||||
if(v[i] != vdata[i]) {report(i,tag,line); break;}\
|
||||
}
|
||||
#define ftest \
|
||||
printf("v ="); \
|
||||
for(i=0;i<DIMSIZE;i++) {printf(" %g",v[i]);} \
|
||||
printf("\n"); \
|
||||
printf("vdata ="); \
|
||||
for(i=0;i<DIMSIZE;i++) {printf(" %g",vdata[i]);} \
|
||||
printf("\n"); \
|
||||
for(i=0;i<DIMSIZE;i++) {\
|
||||
if(fdiff((double)v[i],(double)vdata[i])) {report(i,tag,line); break;}\
|
||||
}
|
||||
#else
|
||||
#define test for(i=0;i<DIMSIZE;i++) {\
|
||||
if(v[i] != vdata[i]) {report(i,tag,line); break;}\
|
||||
}
|
||||
#define ftest for(i=0;i<DIMSIZE;i++) {\
|
||||
if(fdiff((double)v[i],(double)vdata[i])) {report(i,tag,line); break;}\
|
||||
}
|
||||
#endif
|
||||
|
||||
#define setup(T) T* v = (T*)v0; T* vdata = (T*)vdata0;
|
||||
|
||||
#define CASE(nc1,nc2) (nc1*256+nc2)
|
||||
switch(CASE(t1,t2)) {
|
||||
|
||||
default: {
|
||||
printf("unexpected compare: %d %d\n",(int)t1,(int)t2);
|
||||
abort();
|
||||
}
|
||||
|
||||
case CASE(NC_CHAR,NC_CHAR): {
|
||||
setup(char);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_BYTE,NC_BYTE): {
|
||||
setup(signed char);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_SHORT,NC_SHORT): {
|
||||
setup(short);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_INT,NC_INT): {
|
||||
setup(int);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_FLOAT,NC_FLOAT): {
|
||||
setup(float);
|
||||
ftest;
|
||||
} break;
|
||||
case CASE(NC_DOUBLE,NC_DOUBLE): {
|
||||
setup(double);
|
||||
ftest;
|
||||
} break;
|
||||
|
||||
|
||||
/* Mixed comparisons */
|
||||
case CASE(NC_BYTE,NC_INT): {
|
||||
setup(int);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_SHORT,NC_INT): {
|
||||
setup(int);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_SHORT,NC_FLOAT): {
|
||||
setup(float);
|
||||
ftest;
|
||||
} break;
|
||||
case CASE(NC_INT,NC_FLOAT): {
|
||||
setup(float);
|
||||
ftest;
|
||||
} break;
|
||||
|
||||
/* This is an get_var_long case */
|
||||
case CASE(NC_INT,NC_NAT): {
|
||||
setup(long);
|
||||
test;
|
||||
} break;
|
||||
|
||||
case CASE(NC_UBYTE,NC_UBYTE): {
|
||||
setup(unsigned char);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_USHORT,NC_USHORT): {
|
||||
setup(unsigned short);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_UINT,NC_UINT): {
|
||||
setup(unsigned int);
|
||||
test;
|
||||
} break;
|
||||
|
||||
/* Mixed cases */
|
||||
case CASE(NC_INT,NC_INT64): {
|
||||
setup(long long);
|
||||
test;
|
||||
} break;
|
||||
|
||||
case CASE(NC_INT,NC_UINT64): {
|
||||
setup(unsigned long long);
|
||||
test;
|
||||
} break;
|
||||
|
||||
case CASE(NC_STRING,NC_STRING):{
|
||||
setup(char*);
|
||||
for(i=0;i<DIMSIZE;i++) {
|
||||
if(strcmp(v[i],vdata[i])!=0) {report(i,tag,line); break;}
|
||||
}
|
||||
} break;
|
||||
|
||||
case CASE(NC_CHAR,NC_STRING):{
|
||||
setup(char*);
|
||||
if(memcmp((void*)v[0],(void*)vdata,DIMSIZE+1)!=0)
|
||||
{report(0,tag,line);}
|
||||
} break;
|
||||
|
||||
} /*switch*/
|
||||
}
|
||||
|
||||
#include <config.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "netcdf.h"
|
||||
|
||||
|
||||
#undef GENERATE
|
||||
|
||||
#undef DEBUG
|
||||
|
||||
/* Test (some) internal/external type conversions
|
||||
using following DAP dataset (test.02).
|
||||
Dataset {
|
||||
Byte b[DIMSIZE];
|
||||
Int32 i32[DIMSIZE];
|
||||
UInt32 ui32[DIMSIZE];
|
||||
Int16 i16[DIMSIZE];
|
||||
UInt16 ui16[DIMSIZE];
|
||||
Float32 f32[DIMSIZE];
|
||||
Float64 f64[DIMSIZE];
|
||||
String s[DIMSIZE];
|
||||
Url u[DIMSIZE];
|
||||
} OneDimensionalSimpleArrays;
|
||||
*/
|
||||
|
||||
#define NDIMS 1
|
||||
#define DIMSIZE 25
|
||||
#define STRLEN 64
|
||||
|
||||
#ifndef USE_NETCDF4
|
||||
#define NC_UBYTE 7 /* unsigned 1 byte int */
|
||||
#define NC_USHORT 8 /* unsigned 2-byte int */
|
||||
#define NC_UINT 9 /* unsigned 4-byte int */
|
||||
#define NC_INT64 10 /* signed 8-byte int */
|
||||
#define NC_UINT64 11 /* unsigned 8-byte int */
|
||||
#define NC_STRING 12 /* string */
|
||||
#endif
|
||||
|
||||
|
||||
#define CHECK(expr) check(expr,__FILE__,__LINE__);
|
||||
|
||||
#define COMMA (i==0?"":",")
|
||||
|
||||
#define COMPARE(t1,t2,v1,v2) compare(t1,t2,(void*)v1,(void*)v2,#v2,__FILE__,__LINE__)
|
||||
|
||||
static int failure = 0;
|
||||
|
||||
static void compare(nc_type,nc_type,void*,void*,char*,char*,int);
|
||||
|
||||
static void
|
||||
report(const int i, const char* var, const int line)
|
||||
{
|
||||
fprintf(stdout,"%s mismatch: [%d] file: %s line: %d\n",var,i,__FILE__,line);
|
||||
failure = 1;
|
||||
}
|
||||
|
||||
static void
|
||||
check(int ncstat, char* file, int line)
|
||||
{
|
||||
if(ncstat == NC_NOERR) return;
|
||||
fprintf(stderr,"*** FAIL: %d (%s) at %s:%d\n",
|
||||
ncstat,nc_strerror(ncstat),file,line);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* return 1 if |f1-f2| > 0.05 */
|
||||
static int
|
||||
fdiff(double f1, double f2)
|
||||
{
|
||||
double delta = (f1 - f2);
|
||||
if(delta < 0) delta = - delta;
|
||||
if(delta > 0.05) {
|
||||
fprintf(stdout,"fdiff: %1.3f %1.3f delta=%1.3f\n",f1,f2,delta);
|
||||
}
|
||||
return (delta > 0.05?1:0);
|
||||
}
|
||||
|
||||
static char ch_data[DIMSIZE];
|
||||
static signed char int8_data[DIMSIZE];
|
||||
static unsigned char uint8_data[DIMSIZE];
|
||||
static int int8toint32_data[DIMSIZE];
|
||||
static float int82float32_data[DIMSIZE];
|
||||
static short int16_data[DIMSIZE];
|
||||
static int int16toint32_data[DIMSIZE];
|
||||
static float int162float32_data[DIMSIZE];
|
||||
static int int32_data[DIMSIZE];
|
||||
static float int32tofloat32_data[DIMSIZE];
|
||||
static long int32toilong_data[DIMSIZE];
|
||||
static float float32_data[DIMSIZE];
|
||||
static double float64_data[DIMSIZE];
|
||||
#ifndef USE_NETCDF4
|
||||
static char string3_data[DIMSIZE][STRLEN];
|
||||
#endif
|
||||
|
||||
static char ch[DIMSIZE];
|
||||
static signed char int8v[DIMSIZE];
|
||||
static unsigned char uint8v[DIMSIZE];
|
||||
static short int16v[DIMSIZE];
|
||||
static int int32v[DIMSIZE];
|
||||
static float float32v[DIMSIZE];
|
||||
static double float64v[DIMSIZE];
|
||||
static long ilong[DIMSIZE];
|
||||
#ifndef USE_NETCDF4
|
||||
static char string3[DIMSIZE][STRLEN];
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
int ncid, varid;
|
||||
int ncstat = NC_NOERR;
|
||||
char* url;
|
||||
char* topsrcdir;
|
||||
size_t len;
|
||||
#ifndef USE_NETCDF4
|
||||
int i,j;
|
||||
#endif
|
||||
|
||||
/* location of our target url: use file:// to avoid remote
|
||||
server downtime issues
|
||||
*/
|
||||
|
||||
/* Assume that TESTS_ENVIRONMENT was set */
|
||||
topsrcdir = getenv("TOPSRCDIR");
|
||||
if(topsrcdir == NULL) {
|
||||
fprintf(stderr,"*** FAIL: $abs_top_srcdir not defined: location= %s:%d\n",__FILE__,__LINE__);
|
||||
exit(1);
|
||||
}
|
||||
len = strlen("file://") + strlen(topsrcdir) + strlen("/ncdap_test/testdata3/test.02") + 1;
|
||||
#ifdef DEBUG
|
||||
len += strlen("[log][show=fetch]");
|
||||
#endif
|
||||
url = (char*)malloc(len);
|
||||
url[0] = '\0';
|
||||
|
||||
#ifdef DEBUG
|
||||
strcat(url,"[log][show=fetch]");
|
||||
#endif
|
||||
|
||||
strcat(url,"file://");
|
||||
strcat(url,topsrcdir);
|
||||
strcat(url,"/ncdap_test/testdata3/test.02");
|
||||
|
||||
printf("*** Test: var conversions on URL: %s\n",url);
|
||||
|
||||
/* open file, get varid */
|
||||
CHECK(nc_open(url, NC_NOWRITE, &ncid));
|
||||
|
||||
/* extract the string case for netcdf-3*/
|
||||
#ifndef USE_NETCDF4
|
||||
CHECK(nc_inq_varid(ncid, "s", &varid));
|
||||
CHECK(nc_get_var_text(ncid,varid,(char*)string3));
|
||||
#ifdef GENERATE
|
||||
printf("static %s string3_data[DIMSIZE][STRLEN]={","char");
|
||||
for(i=0;i<DIMSIZE;i++) {
|
||||
int j;
|
||||
/* Do simple escape */
|
||||
for(j=0;j<STRLEN;j++) {
|
||||
if(string3[i][j] > 0
|
||||
&& string3[i][j] != '\n'
|
||||
&& string3[i][j] != '\r'
|
||||
&& string3[i][j] != '\t'
|
||||
&&(string3[i][j] < ' ' || string3[i][j] >= '\177'))
|
||||
string3[i][j] = '?';
|
||||
}
|
||||
printf("%s\"%s\"",COMMA,string3[i]);
|
||||
}
|
||||
printf("};\n");
|
||||
#else
|
||||
fprintf(stdout,"*** testing: %s\n","string3");
|
||||
for(i=0;i<DIMSIZE;i++) {
|
||||
for(j=0;j<STRLEN;j++) {
|
||||
if(string3[i][j] != string3_data[i][j]) {report(i,"string3",__LINE__); break;}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_text(ncid,varid,ch));
|
||||
#ifdef GENERATE
|
||||
printf("static %s ch_data[DIMSIZE]={","char");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s'\\%03hho'",COMMA,ch[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_CHAR,NC_CHAR,ch,ch_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_schar(ncid,varid,int8v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int8_data[DIMSIZE]={","signed char");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hhd",COMMA,int8v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_BYTE,NC_BYTE,int8v,int8_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_uchar(ncid,varid,uint8v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s uint8_data[DIMSIZE]={","unsigned char");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hhu",COMMA,uint8v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_UBYTE,NC_UBYTE,uint8v,uint8_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int8toint32_data[DIMSIZE]={","int");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_BYTE,NC_INT,int32v,int8toint32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "b", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int82float32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_FLOAT,NC_FLOAT,float32v,int82float32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i16", &varid));
|
||||
CHECK(nc_get_var_short(ncid,varid,int16v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int16_data[DIMSIZE]={","short");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%hd",COMMA,int16v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_SHORT,NC_SHORT,int16v,int16_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i16", &varid));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int16toint32_data[DIMSIZE]={","int");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_SHORT,NC_INT,int32v,int16toint32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i16", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int162float32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_SHORT,NC_FLOAT,float32v,int162float32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i32", &varid));
|
||||
CHECK(nc_get_var_int(ncid,varid,int32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int32_data[DIMSIZE]={","int");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%d",COMMA,int32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_INT,NC_INT,int32v,int32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i32", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int32tofloat32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_INT,NC_FLOAT,float32v,int32tofloat32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "i32", &varid));
|
||||
CHECK(nc_get_var_long(ncid,varid,ilong));
|
||||
#ifdef GENERATE
|
||||
printf("static %s int32toilong_data[DIMSIZE]={","long");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%ld",COMMA,ilong[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_INT,NC_NAT,ilong,int32toilong_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "f32", &varid));
|
||||
CHECK(nc_get_var_float(ncid,varid,float32v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s float32_data[DIMSIZE]={","float");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float32v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_FLOAT,NC_FLOAT,float32v,float32_data);
|
||||
#endif
|
||||
|
||||
CHECK(nc_inq_varid(ncid, "f64", &varid));
|
||||
CHECK(nc_get_var_double(ncid,varid,float64v));
|
||||
#ifdef GENERATE
|
||||
printf("static %s float64_data[DIMSIZE]={","double");
|
||||
for(i=0;i<DIMSIZE;i++) printf("%s%1.3f",COMMA,float64v[i]);
|
||||
printf("};\n");
|
||||
#else
|
||||
COMPARE(NC_DOUBLE,NC_DOUBLE,float64v,float64_data);
|
||||
#endif
|
||||
|
||||
if(failure) {
|
||||
printf("ncstat=%d %s",ncstat,nc_strerror(ncstat));
|
||||
exit(1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char ch_data[DIMSIZE]={'\000','\001','\002','\003','\004','\005','\006','\007','\010','\011','\012','\013','\014','\015','\016','\017','\020','\021','\022','\023','\024','\025','\026','\027','\030'};
|
||||
static signed char int8_data[DIMSIZE]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24};
|
||||
static unsigned char uint8_data[DIMSIZE]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24};
|
||||
static int int8toint32_data[DIMSIZE]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24};
|
||||
static float int82float32_data[DIMSIZE]={0.000,1.000,2.000,3.000,4.000,5.000,6.000,7.000,8.000,9.000,10.000,11.000,12.000,13.000,14.000,15.000,16.000,17.000,18.000,19.000,20.000,21.000,22.000,23.000,24.000};
|
||||
static short int16_data[DIMSIZE]={0,256,512,768,1024,1280,1536,1792,2048,2304,2560,2816,3072,3328,3584,3840,4096,4352,4608,4864,5120,5376,5632,5888,6144};
|
||||
static int int16toint32_data[DIMSIZE]={0,256,512,768,1024,1280,1536,1792,2048,2304,2560,2816,3072,3328,3584,3840,4096,4352,4608,4864,5120,5376,5632,5888,6144};
|
||||
static float int162float32_data[DIMSIZE]={0.000,256.000,512.000,768.000,1024.000,1280.000,1536.000,1792.000,2048.000,2304.000,2560.000,2816.000,3072.000,3328.000,3584.000,3840.000,4096.000,4352.000,4608.000,4864.000,5120.000,5376.000,5632.000,5888.000,6144.000};
|
||||
static int int32_data[DIMSIZE]={0,2048,4096,6144,8192,10240,12288,14336,16384,18432,20480,22528,24576,26624,28672,30720,32768,34816,36864,38912,40960,43008,45056,47104,49152};
|
||||
static float int32tofloat32_data[DIMSIZE]={0.000,2048.000,4096.000,6144.000,8192.000,10240.000,12288.000,14336.000,16384.000,18432.000,20480.000,22528.000,24576.000,26624.000,28672.000,30720.000,32768.000,34816.000,36864.000,38912.000,40960.000,43008.000,45056.000,47104.000,49152.000};
|
||||
static long int32toilong_data[DIMSIZE]={0,2048,4096,6144,8192,10240,12288,14336,16384,18432,20480,22528,24576,26624,28672,30720,32768,34816,36864,38912,40960,43008,45056,47104,49152};
|
||||
static float float32_data[DIMSIZE]={0.000,0.010,0.020,0.030,0.040,0.050,0.060,0.070,0.080,0.090,0.100,0.110,0.120,0.130,0.140,0.149,0.159,0.169,0.179,0.189,0.199,0.208,0.218,0.228,0.238};
|
||||
static double float64_data[DIMSIZE]={1.000,1.000,1.000,1.000,0.999,0.999,0.998,0.998,0.997,0.996,0.995,0.994,0.993,0.992,0.990,0.989,0.987,0.986,0.984,0.982,0.980,0.978,0.976,0.974,0.971};
|
||||
|
||||
#ifndef USE_NETCDF4
|
||||
static char string3_data[DIMSIZE][STRLEN]={"This is a data test string (pass 0).","This is a data test string (pass 1).","This is a data test string (pass 2).","This is a data test string (pass 3).","This is a data test string (pass 4).","This is a data test string (pass 5).","This is a data test string (pass 6).","This is a data test string (pass 7).","This is a data test string (pass 8).","This is a data test string (pass 9).","This is a data test string (pass 10).","This is a data test string (pass 11).","This is a data test string (pass 12).","This is a data test string (pass 13).","This is a data test string (pass 14).","This is a data test string (pass 15).","This is a data test string (pass 16).","This is a data test string (pass 17).","This is a data test string (pass 18).","This is a data test string (pass 19).","This is a data test string (pass 20).","This is a data test string (pass 21).","This is a data test string (pass 22).","This is a data test string (pass 23).","This is a data test string (pass 24)."};
|
||||
#endif
|
||||
|
||||
static void
|
||||
compare(nc_type t1, nc_type t2, void* v0, void* vdata0, char* tag,
|
||||
char* file, int line)
|
||||
{
|
||||
int i;
|
||||
fprintf(stdout,"*** testing: %s\n",tag); \
|
||||
|
||||
#ifdef DEBUG
|
||||
#define test \
|
||||
printf("v ="); \
|
||||
for(i=0;i<DIMSIZE;i++) {printf(" %llu",(unsigned long long)v[i]);} \
|
||||
printf("\n"); \
|
||||
printf("vdata ="); \
|
||||
for(i=0;i<DIMSIZE;i++) {printf(" %llu",(unsigned long long)vdata[i]);} \
|
||||
printf("\n"); \
|
||||
for(i=0;i<DIMSIZE;i++) {\
|
||||
if(v[i] != vdata[i]) {report(i,tag,line); break;}\
|
||||
}
|
||||
#define ftest \
|
||||
printf("v ="); \
|
||||
for(i=0;i<DIMSIZE;i++) {printf(" %g",v[i]);} \
|
||||
printf("\n"); \
|
||||
printf("vdata ="); \
|
||||
for(i=0;i<DIMSIZE;i++) {printf(" %g",vdata[i]);} \
|
||||
printf("\n"); \
|
||||
for(i=0;i<DIMSIZE;i++) {\
|
||||
if(fdiff((double)v[i],(double)vdata[i])) {report(i,tag,line); break;}\
|
||||
}
|
||||
#else
|
||||
#define test for(i=0;i<DIMSIZE;i++) {\
|
||||
if(v[i] != vdata[i]) {report(i,tag,line); break;}\
|
||||
}
|
||||
#define ftest for(i=0;i<DIMSIZE;i++) {\
|
||||
if(fdiff((double)v[i],(double)vdata[i])) {report(i,tag,line); break;}\
|
||||
}
|
||||
#endif
|
||||
|
||||
#define setup(T) T* v = (T*)v0; T* vdata = (T*)vdata0;
|
||||
|
||||
#define CASE(nc1,nc2) (nc1*256+nc2)
|
||||
switch(CASE(t1,t2)) {
|
||||
|
||||
default: {
|
||||
printf("unexpected compare: %d %d\n",(int)t1,(int)t2);
|
||||
abort();
|
||||
}
|
||||
|
||||
case CASE(NC_CHAR,NC_CHAR): {
|
||||
setup(char);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_BYTE,NC_BYTE): {
|
||||
setup(signed char);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_SHORT,NC_SHORT): {
|
||||
setup(short);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_INT,NC_INT): {
|
||||
setup(int);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_FLOAT,NC_FLOAT): {
|
||||
setup(float);
|
||||
ftest;
|
||||
} break;
|
||||
case CASE(NC_DOUBLE,NC_DOUBLE): {
|
||||
setup(double);
|
||||
ftest;
|
||||
} break;
|
||||
|
||||
|
||||
/* Mixed comparisons */
|
||||
case CASE(NC_BYTE,NC_INT): {
|
||||
setup(int);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_SHORT,NC_INT): {
|
||||
setup(int);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_SHORT,NC_FLOAT): {
|
||||
setup(float);
|
||||
ftest;
|
||||
} break;
|
||||
case CASE(NC_INT,NC_FLOAT): {
|
||||
setup(float);
|
||||
ftest;
|
||||
} break;
|
||||
|
||||
/* This is an get_var_long case */
|
||||
case CASE(NC_INT,NC_NAT): {
|
||||
setup(long);
|
||||
test;
|
||||
} break;
|
||||
|
||||
case CASE(NC_UBYTE,NC_UBYTE): {
|
||||
setup(unsigned char);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_USHORT,NC_USHORT): {
|
||||
setup(unsigned short);
|
||||
test;
|
||||
} break;
|
||||
case CASE(NC_UINT,NC_UINT): {
|
||||
setup(unsigned int);
|
||||
test;
|
||||
} break;
|
||||
|
||||
/* Mixed cases */
|
||||
case CASE(NC_INT,NC_INT64): {
|
||||
setup(long long);
|
||||
test;
|
||||
} break;
|
||||
|
||||
case CASE(NC_INT,NC_UINT64): {
|
||||
setup(unsigned long long);
|
||||
test;
|
||||
} break;
|
||||
|
||||
case CASE(NC_STRING,NC_STRING):{
|
||||
setup(char*);
|
||||
for(i=0;i<DIMSIZE;i++) {
|
||||
if(strcmp(v[i],vdata[i])!=0) {report(i,tag,line); break;}
|
||||
}
|
||||
} break;
|
||||
|
||||
case CASE(NC_CHAR,NC_STRING):{
|
||||
setup(char*);
|
||||
if(memcmp((void*)v[0],(void*)vdata,DIMSIZE+1)!=0)
|
||||
{report(0,tag,line);}
|
||||
} break;
|
||||
|
||||
} /*switch*/
|
||||
}
|
||||
|
@ -1,51 +0,0 @@
|
||||
#include "config.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "netcdf.h"
|
||||
#include "t_srcdir.h"
|
||||
|
||||
#define VAR "i32"
|
||||
|
||||
#define ERRCODE 2
|
||||
#define ERR(e) {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);}
|
||||
|
||||
#undef DEBUG
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
int ncid, varid;
|
||||
int retval;
|
||||
int i32[100];
|
||||
size_t start[1];
|
||||
size_t count[1];
|
||||
int ok = 1;
|
||||
|
||||
const char* topsrcdir;
|
||||
char url[4096];
|
||||
|
||||
topsrcdir = gettopsrcdir();
|
||||
|
||||
strcpy(url,"file://");
|
||||
strcat(url,topsrcdir);
|
||||
strcat(url,"/ncdap_test/testdata3/test.02");
|
||||
|
||||
if ((retval = nc_open(url, 0, &ncid)))
|
||||
ERR(retval);
|
||||
if ((retval = nc_inq_varid(ncid, VAR, &varid)))
|
||||
ERR(retval);
|
||||
|
||||
start[0] = 0;
|
||||
count[0] = 26;
|
||||
if ((retval = nc_get_vara_int(ncid, varid, start, count, i32)))
|
||||
if(retval != NC_EINVALCOORDS) {
|
||||
printf("nc_get_vara_int did not return NC_EINVALCOORDS");
|
||||
ok = 0;
|
||||
}
|
||||
|
||||
nc_close(ncid);
|
||||
|
||||
printf(ok?"*** PASS\n":"*** FAIL\n");
|
||||
return 0;
|
||||
}
|
@ -110,7 +110,7 @@ int main()
|
||||
{
|
||||
int ncid, varid;
|
||||
int ncstat = NC_NOERR;
|
||||
char* url;
|
||||
char url[8192];
|
||||
const char* topsrcdir;
|
||||
size_t len;
|
||||
#ifndef USE_NETCDF4
|
||||
@ -123,20 +123,15 @@ int main()
|
||||
|
||||
topsrcdir = gettopsrcdir();
|
||||
|
||||
len = strlen("file://") + strlen(topsrcdir) + strlen("/ncdap_test/testdata3/test.02") + 1;
|
||||
#ifdef DEBUG
|
||||
len += strlen("[log][show=fetch]");
|
||||
#endif
|
||||
url = (char*)malloc(len);
|
||||
url[0] = '\0';
|
||||
|
||||
#ifdef DEBUG
|
||||
strcat(url,"[log][show=fetch]");
|
||||
strlcat(url,"[log][show=fetch]",sizeof(url));
|
||||
#endif
|
||||
|
||||
strcat(url,"file://");
|
||||
strcat(url,topsrcdir);
|
||||
strcat(url,"/ncdap_test/testdata3/test.02");
|
||||
strlcat(url,"file://",sizeof(url));
|
||||
strlcat(url,topsrcdir,sizeof(url));
|
||||
strlcat(url,"/ncdap_test/testdata3/test.02",sizeof(url));
|
||||
|
||||
printf("*** Test: var conversions on URL: %s\n",url);
|
||||
|
||||
|
@ -101,7 +101,6 @@ main()
|
||||
exit(0);
|
||||
}
|
||||
|
||||
strcpy(url,URL);
|
||||
snprintf(url,sizeof(url),URL,svc);
|
||||
|
||||
for (idim=0; idim<5; idim++) {
|
||||
|
@ -106,9 +106,9 @@ main()
|
||||
fprintf(stderr,"Cannot locate test server\n");
|
||||
exit(0);
|
||||
}
|
||||
strcpy(url,PARAMS);
|
||||
strcat(url,svc);
|
||||
strcat(url,DTSTEST);
|
||||
strncpy(url,PARAMS,sizeof(url));
|
||||
strlcat(url,svc,sizeof(url));
|
||||
strlcat(url,DTSTEST,sizeof(url));
|
||||
|
||||
printf("test_partvar: url=%s\n",url);
|
||||
|
||||
|
@ -95,9 +95,9 @@ main()
|
||||
fprintf(stderr,"Cannot locate test server\n");
|
||||
exit(1);
|
||||
}
|
||||
strcpy(url,PARAMS);
|
||||
strcat(url,svc);
|
||||
strcat(url,DTSTEST);
|
||||
strncpy(url,PARAMS,sizeo(url));
|
||||
strlcat(url,svc,sizeof(url));
|
||||
strlcat(url,DTSTEST,sizeof(url));
|
||||
|
||||
printf("test_partvar: url=%s\n",url);
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include "config.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@ -81,9 +82,9 @@ main()
|
||||
|
||||
topsrcdir = gettopsrcdir();
|
||||
|
||||
strcpy(url,"file://");
|
||||
strcat(url,topsrcdir);
|
||||
strcat(url,"/ncdap_test/testdata3/test.06");
|
||||
strncpy(url,"file://",sizeof(url));
|
||||
strlcat(url,topsrcdir,sizeof(url));
|
||||
strlcat(url,"/ncdap_test/testdata3/test.06",sizeof(url));
|
||||
|
||||
printf("test_vara: url=%s\n",url);
|
||||
|
||||
|
@ -99,8 +99,8 @@ main()
|
||||
fprintf(stderr,"Cannot locate test server\n");
|
||||
exit(0);
|
||||
}
|
||||
strcpy(url,svc);
|
||||
strcat(url,TESTPATH);
|
||||
strncpy(url,svc,sizeof(url));
|
||||
strlcat(url,TESTPATH,sizeof(url));
|
||||
|
||||
printf("*** Test: varm on URL: %s\n",url);
|
||||
|
||||
|
@ -174,10 +174,10 @@ ENDIF()
|
||||
|
||||
# Known failure on MSVC; the number of 0's padding
|
||||
# is different, but the result is actually correct.
|
||||
#IF(NOT MSVC)
|
||||
IF(NOT MSVC)
|
||||
add_sh_test(ncdump tst_netcdf4)
|
||||
build_bin_test_no_prefix(tst_h_rdc0)
|
||||
#ENDIF()
|
||||
ENDIF()
|
||||
|
||||
add_bin_test_no_prefix(tst_unicode)
|
||||
|
||||
|
@ -113,62 +113,6 @@ char float_att_fmt[] = "%#.NNgf";
|
||||
char float_attx_fmt[] = "%#.NNg";
|
||||
char double_att_fmt[] = "%#.NNg";
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
/* $OpenBSD: strlcat.c,v 1.12 2005/03/30 20:13:52 otto Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Appends src to string dst of size siz (unlike strncat, siz is the
|
||||
* full size of dst, not space left). At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
|
||||
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
|
||||
* If retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcat(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
size_t n = siz;
|
||||
size_t dlen;
|
||||
|
||||
/* Find the end of dst and adjust bytes left but don't go past end */
|
||||
while (n-- != 0 && *d != '\0')
|
||||
d++;
|
||||
dlen = d - dst;
|
||||
n = siz - dlen;
|
||||
|
||||
if (n == 0)
|
||||
return(dlen + strlen(s));
|
||||
while (*s != '\0') {
|
||||
if (n != 1) {
|
||||
*d++ = *s;
|
||||
n--;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
*d = '\0';
|
||||
|
||||
return(dlen + (s - src)); /* count does not include NUL */
|
||||
}
|
||||
#endif /* ! HAVE_STRLCAT */
|
||||
|
||||
|
||||
/* magic number stored in a safebuf and checked, hoping it will be
|
||||
* changed if buffer was overwritten inadvertently */
|
||||
#define SAFEBUF_CERT 2147114711
|
||||
|
@ -50,11 +50,6 @@ extern char double_att_fmt[];
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
/* Append src to dst of size siz */
|
||||
extern size_t strlcat(char *dst, const char *src, size_t siz);
|
||||
#endif /* ! HAVE_STRLCAT */
|
||||
|
||||
/* In case different formats specified with -d option, set them here. */
|
||||
extern void set_formats ( int flt_digs, int dbl_digs );
|
||||
|
||||
|
@ -1837,61 +1837,6 @@ grow_aarray(
|
||||
*arpp = (struct atts *) erealloc(*arpp, 2 * nar * sizeof(struct atts));
|
||||
}
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
/* $OpenBSD: strlcat.c,v 1.12 2005/03/30 20:13:52 otto Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Appends src to string dst of size siz (unlike strncat, siz is the
|
||||
* full size of dst, not space left). At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
|
||||
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
|
||||
* If retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcat(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
size_t n = siz;
|
||||
size_t dlen;
|
||||
|
||||
/* Find the end of dst and adjust bytes left but don't go past end */
|
||||
while (n-- != 0 && *d != '\0')
|
||||
d++;
|
||||
dlen = d - dst;
|
||||
n = siz - dlen;
|
||||
|
||||
if (n == 0)
|
||||
return(dlen + strlen(s));
|
||||
while (*s != '\0') {
|
||||
if (n != 1) {
|
||||
*d++ = *s;
|
||||
n--;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
*d = '\0';
|
||||
|
||||
return(dlen + (s - src)); /* count does not include NUL */
|
||||
}
|
||||
#endif /* ! HAVE_STRLCAT */
|
||||
|
||||
|
||||
/*
|
||||
* Replace special chars in name so it can be used in C and Fortran
|
||||
|
@ -80,11 +80,6 @@ extern void nc_fill ( nc_type type, size_t num, void* datp,
|
||||
/* reset symbol table to empty, defined in ncgen.y */
|
||||
extern void clearout(void);
|
||||
|
||||
/* In case we are missing strlcat */
|
||||
#ifndef HAVE_STRLCAT
|
||||
extern size_t strlcat(char *dst, const char *src, size_t siz);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -15,10 +15,6 @@
|
||||
#include "ncgen.h"
|
||||
#include "genlib.h"
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
extern size_t strlcat(char *dst, const char *src, size_t siz);
|
||||
#endif
|
||||
|
||||
extern int netcdf_flag;
|
||||
extern int c_flag;
|
||||
extern int fortran_flag;
|
||||
|
@ -28,8 +28,8 @@ check(OCstate* state, int flag, void* value)
|
||||
} else {
|
||||
char show[65];
|
||||
char* s = (char*)value;
|
||||
strncpy(show,s,64);
|
||||
show[64] = '\0';
|
||||
strncpy(show,s,sizeof(show)-1);
|
||||
show[sizeof(show)-1] = '\0';
|
||||
OCDBG2("%s=%s",name,show);
|
||||
}
|
||||
#endif
|
||||
|
50
oc2/ocdump.c
50
oc2/ocdump.c
@ -232,14 +232,14 @@ ocdumpclause(OCprojectionclause* ref)
|
||||
|
||||
|
||||
static void
|
||||
addfield(char* field, char* line, int align)
|
||||
addfield(char* field, size_t llen, char* line, int align)
|
||||
{
|
||||
int len,rem;
|
||||
strcat(line,"|");
|
||||
strcat(line,field);
|
||||
strlcat(line,"|",llen);
|
||||
strlcat(line,field,llen);
|
||||
len = strlen(field);
|
||||
rem = (align - len);
|
||||
while(rem-- > 0) strcat(line," ");
|
||||
while(rem-- > 0) strlcat(line," ",llen);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -264,27 +264,27 @@ dumpfield(size_t index, char* n8, int isxdr)
|
||||
|
||||
/* offset */
|
||||
sprintf(tmp,"%6zd",index);
|
||||
addfield(tmp,line,5);
|
||||
addfield(tmp,sizeof(line),line,5);
|
||||
|
||||
memcpy(form.cv,n8,4);
|
||||
|
||||
/* straight hex*/
|
||||
sprintf(tmp,"%08x",form.uv);
|
||||
addfield(tmp,line,8);
|
||||
addfield(tmp,sizeof(line),line,8);
|
||||
|
||||
if(isxdr) {swapinline32(&form.uv);}
|
||||
|
||||
/* unsigned integer */
|
||||
sprintf(tmp,"%12u",form.uv);
|
||||
addfield(tmp,line,12);
|
||||
addfield(tmp,sizeof(line),line,12);
|
||||
|
||||
/* signed integer */
|
||||
sprintf(tmp,"%12d",form.sv);
|
||||
addfield(tmp,line,12);
|
||||
addfield(tmp,sizeof(line),line,12);
|
||||
|
||||
/* float */
|
||||
sprintf(tmp,"%#g",form.fv);
|
||||
addfield(tmp,line,12);
|
||||
addfield(tmp,sizeof(line),line,12);
|
||||
|
||||
/* char[4] */
|
||||
{
|
||||
@ -303,13 +303,13 @@ dumpfield(size_t index, char* n8, int isxdr)
|
||||
}
|
||||
}
|
||||
|
||||
addfield(tmp,line,16);
|
||||
addfield(tmp,sizeof(line),line,16);
|
||||
|
||||
/* double */
|
||||
memcpy(dform.cv,n8,(size_t)(2*XDRUNIT));
|
||||
if(isxdr) xxdrntohdouble(dform.cv,&dform.d);
|
||||
sprintf(tmp,"%#g",dform.d);
|
||||
addfield(tmp,line,12);
|
||||
addfield(tmp,sizeof(line),line,12);
|
||||
|
||||
fprintf(stdout,"%s\n",line);
|
||||
}
|
||||
@ -326,14 +326,14 @@ typedmemorydump(char* memory, size_t len, int fromxdr)
|
||||
|
||||
/* build the header*/
|
||||
line[0] = '\0';
|
||||
addfield("offset",line,6);
|
||||
addfield("hex",line,8);
|
||||
addfield("uint",line,12);
|
||||
addfield("int",line,12);
|
||||
addfield("float",line,12);
|
||||
addfield("char[4]",line,16);
|
||||
addfield("double",line,12);
|
||||
strcat(line,"\n");
|
||||
addfield("offset",sizeof(line),line,6);
|
||||
addfield("hex",sizeof(line),line,8);
|
||||
addfield("uint",sizeof(line),line,12);
|
||||
addfield("int",sizeof(line),line,12);
|
||||
addfield("float",sizeof(line),line,12);
|
||||
addfield("char[4]",sizeof(line),line,16);
|
||||
addfield("double",sizeof(line),line,12);
|
||||
strlcat(line,"\n",sizeof(line));
|
||||
fprintf(stdout,"%s",line);
|
||||
|
||||
count = (len / sizeof(int));
|
||||
@ -367,9 +367,9 @@ simplememorydump(char* memory, size_t len, int fromxdr)
|
||||
|
||||
/* build the header*/
|
||||
line[0] = '\0';
|
||||
addfield("offset",line,6);
|
||||
addfield("XDR (hex)",line,9);
|
||||
addfield("!XDR (hex)",line,10);
|
||||
addfield("offset",sizeof(line),line,6);
|
||||
addfield("XDR (hex)",sizeof(line),line,9);
|
||||
addfield("!XDR (hex)",sizeof(line),line,10);
|
||||
fprintf(stdout,"%s\n",line);
|
||||
|
||||
count = (len / sizeof(int));
|
||||
@ -384,11 +384,11 @@ simplememorydump(char* memory, size_t len, int fromxdr)
|
||||
if(!xxdr_network_order) swapinline32(&v);
|
||||
line[0] = '\0';
|
||||
sprintf(tmp,"%6d",i);
|
||||
addfield(tmp,line,6);
|
||||
addfield(tmp,sizeof(line),line,6);
|
||||
sprintf(tmp,"%08x",vx);
|
||||
addfield(tmp,line,9);
|
||||
addfield(tmp,sizeof(line),line,9);
|
||||
sprintf(tmp,"%08x",v);
|
||||
addfield(tmp,line,10);
|
||||
addfield(tmp,sizeof(line),line,10);
|
||||
fprintf(stdout,"%s\n",line);
|
||||
}
|
||||
fflush(stdout);
|
||||
|
12
oc2/ocnode.c
12
oc2/ocnode.c
@ -400,13 +400,13 @@ mergedods1(OCnode* dds, OCnode* dods)
|
||||
*/
|
||||
size_t len = strlen(attnode->name)
|
||||
+ strlen(dods->name)
|
||||
+ strlen(".")
|
||||
+ 1; /*null*/
|
||||
char* newname = (char*)malloc(len);
|
||||
+ strlen(".");
|
||||
len++; /*strlcat nul*/
|
||||
char* newname = (char*)malloc(len+1);
|
||||
if(newname == NULL) return OC_ENOMEM;
|
||||
strcpy(newname,dods->name);
|
||||
strcat(newname,".");
|
||||
strcat(newname,attnode->name);
|
||||
strncpy(newname,dods->name,len);
|
||||
strlcat(newname,".",len);
|
||||
strlcat(newname,attnode->name,len);
|
||||
att = makeattribute(newname,attnode->etype,attnode->att.values);
|
||||
free(newname);
|
||||
nclistpush(dds->attributes,(void*)att);
|
||||
|
Loading…
Reference in New Issue
Block a user