conflict resolution

This commit is contained in:
dmh 2014-08-17 12:52:53 -06:00
commit 46063247cb
10 changed files with 210 additions and 169 deletions

View File

@ -1,5 +1,5 @@
## This is a CMake file, part of Unidata's netCDF package.
# Copyright 2012-2013, see the COPYRIGHT file for more information.
# Copyright 2012-2014, see the COPYRIGHT file for more information.
##################################
# Set Project Properties
@ -49,8 +49,6 @@ ENDIF()
# Determine if DOXYGEN and DOT are available. These will be used
# when building the documentation.
FIND_PROGRAM(NC_DOT NAMES dot)
# For CMAKE_INSTALL_LIBDIR
INCLUDE(GNUInstallDirs)
@ -937,6 +935,7 @@ IF(ENABLE_DOXYGEN)
SET(NC_ENABLE_DOXYGEN_PDF_OUTPUT "NO" CACHE STRING "")
ENDIF()
FIND_PROGRAM(NC_DOT NAMES dot)
# Specify whether or not 'dot' was found on the system path.
IF(NC_DOT)
SET(HAVE_DOT YES CACHE STRING "")

View File

@ -104,7 +104,7 @@ prefetchdata(NCDAPCOMMON* nccomm)
if(FLAGSET(nccomm->controls,NCF_UNCONSTRAINABLE)) {
/* If we cannot constrain and caching is enabled,
then pull in everything */
if(FLAGSET(nccomm->controls,NCF_CACHE)) {
if(FLAGSET(nccomm->controls,NCF_CACHE)) {
for(i=0;i<nclistlength(allvars);i++) {
nclistpush(vars,nclistget(allvars,i));
}
@ -199,7 +199,7 @@ ncbytesfree(buf);
done:
nclistfree(vars);
dcefree((DCEnode*)newconstraint);
dcefree((DCEnode*)newconstraint);
if(ncstat && cache != NULL) freenccachenode(nccomm,cache);
return THROW(ncstat);
}
@ -221,7 +221,7 @@ buildcachenode(NCDAPCOMMON* nccomm,
int isprefetch = 0;
if((flags & NCF_PREFETCH) != 0)
isprefetch = 1;
isprefetch = 1;
#ifndef GRADS_PREFETCH
if((flags & NCF_PREFETCH_ALL) == 0)
@ -370,7 +370,7 @@ iscacheableprojection(DCEprojection* proj)
cacheable = 1; /* assume so */
for(i=0;i<nclistlength(proj->var->segments);i++) {
DCEsegment* segment = (DCEsegment*)nclistget(proj->var->segments,i);
if(!iswholesegment(segment)) {cacheable = 0; break;}
if(!iswholesegment(segment)) {cacheable = 0; break;}
}
return cacheable;
}
@ -419,16 +419,18 @@ markprefetch(NCDAPCOMMON* nccomm)
CDFnode* dim = (CDFnode*)nclistget(var->array.dimsettrans,j);
nelems *= dim->dim.declsize;
}
if(nelems <= nccomm->cdf.smallsizelimit
&& FLAGSET(nccomm->controls,NCF_PREFETCH)) {
var->prefetchable = 1;
if(SHOWFETCH)
{
extern char* ocfqn(OCddsnode);
nclog(NCLOGDBG,"prefetchable: %s=%lu",
ocfqn(var->ocnode),(unsigned long)nelems);
}
}
if(nelems <= nccomm->cdf.smallsizelimit
&& FLAGSET(nccomm->controls,NCF_PREFETCH)) {
var->prefetchable = 1;
if(SHOWFETCH)
{
extern char* ocfqn(OCddsnode);
char *tmp = ocfqn(var->ocnode);
nclog(NCLOGDBG,"prefetchable: %s=%lu",
tmp,(unsigned long)nelems);
free(tmp);
}
}
}
return NC_NOERR;
}

View File

@ -203,7 +203,7 @@ array_indices(DCEparsestate* state, Object list0, Object indexno)
if(start < 0) {
dceerror(state,"Illegal array index");
start = 1;
}
}
slice = (DCEslice*)dcecreate(CES_SLICE);
slice->first = start;
slice->stride = 1;
@ -221,13 +221,13 @@ indexer(DCEparsestate* state, Object name, Object indices)
NClist* list = (NClist*)indices;
DCEsegment* seg = (DCEsegment*)dcecreate(CES_SEGMENT);
seg->name = strdup((char*)name);
for(i=0;i<nclistlength(list);i++) {
for(i=0;i<nclistlength(list);i++) {
DCEslice* slice = (DCEslice*)nclistget(list,i);
seg->slices[i] = *slice;
free(slice);
}
nclistfree(indices);
return seg;
return seg;
}
Object
@ -271,7 +271,7 @@ Object
var(DCEparsestate* state, Object indexpath)
{
DCEvar* v = (DCEvar*)dcecreate(CES_VAR);
v->segments = (NClist*)indexpath;
v->segments = (NClist*)indexpath;
return v;
}
@ -334,18 +334,18 @@ dce_parse_cleanup(DCEparsestate* state)
static DCEparsestate*
ce_parse_init(char* input, DCEconstraint* constraint)
{
DCEparsestate* state = NULL;
if(input==NULL) {
dceerror(state,"ce_parse_init: no input buffer");
} else {
state = (DCEparsestate*)calloc(1,sizeof(DCEparsestate));
if(state==NULL) return (DCEparsestate*)NULL;
state->errorbuf[0] = '\0';
state->errorcode = 0;
dcelexinit(input,&state->lexstate);
DCEparsestate* state = (DCEparsestate*)calloc(1,sizeof(DCEparsestate));;
if(state==NULL) return (DCEparsestate*)NULL;
if(input==NULL) {
dceerror(state,"ce_parse_init: no input buffer");
} else {
state->errorbuf[0] = '\0';
state->errorcode = 0;
dcelexinit(input,&state->lexstate);
state->constraint = constraint;
}
return state;
}
return state;
}
#ifdef PARSEDEBUG

View File

@ -19,7 +19,7 @@ static DCEnode* save = NULL;
struct NCMEMORY {
void* memory;
char* next; /* where to store the next chunk of data*/
};
};
/* Forward:*/
static NCerror moveto(NCDAPCOMMON*, Getvara*, CDFnode* dataroot, void* memory);
@ -125,7 +125,7 @@ nc3d_getvarx(int ncid, int varid,
ncstat = NC_check_id(ncid, (NC**)&drno);
if(ncstat != NC_NOERR) goto fail;
dapcomm = (NCDAPCOMMON*)drno->dispatchdata;
ncstat = NC_check_id(drno->substrate, (NC**)&substrate);
if(ncstat != NC_NOERR) goto fail;
@ -152,7 +152,7 @@ nc3d_getvarx(int ncid, int varid,
if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto fail;}
}
}
/* Get the dimension info */
ncdimsall = cdfvar->array.dimsetall;
ncrank = nclistlength(ncdimsall);
@ -194,24 +194,24 @@ fprintf(stderr,"\n");
//if(startp[i] < 0 || countp[i] < 0 || stridep[i] < 1) {
if(stridep[i] < 1) {
ncstat = NC_EINVALCOORDS;
goto fail;
goto fail;
}
if(startp[i] >= dim->dim.declsize
|| startp[i]+(stridep[i]*(countp[i]-1)) >= dim->dim.declsize) {
ncstat = NC_EINVALCOORDS;
goto fail;
goto fail;
}
}
}
#ifdef DEBUG
{
NClist* dims = cdfvar->array.dimsetall;
fprintf(stderr,"getvarx: %s",cdfvar->ncfullname);
if(nclistlength(dims) > 0) {int i;
for(i=0;i<nclistlength(dims);i++)
for(i=0;i<nclistlength(dims);i++)
fprintf(stderr,"(%lu:%lu:%lu)",(unsigned long)startp[i],(unsigned long)countp[i],(unsigned long)stridep[i]);
fprintf(stderr," -> ");
for(i=0;i<nclistlength(dims);i++)
for(i=0;i<nclistlength(dims);i++)
if(stridep[i]==1)
fprintf(stderr,"[%lu:%lu]",(unsigned long)startp[i],(unsigned long)((startp[i]+countp[i])-1));
else {
@ -288,7 +288,7 @@ fprintf(stderr,"var is in cache\n");
else
state = FETCHPART;
}
ASSERT(state != 0);
ASSERT(state != 0);
switch (state) {
@ -306,7 +306,7 @@ fprintf(stderr,"getvarx: FETCHWHOLE: fetchconstraint: %s\n",dumpconstraint(fetch
#endif
ncstat = buildcachenode(dapcomm,fetchconstraint,vars,&cachenode,0);
fetchconstraint = NULL; /*buildcachenode34 takes control of fetchconstraint.*/
if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto fail;}
if(ncstat != NC_NOERR) {THROWCHK(ncstat); nullfree(varainfo); goto fail;}
} break;
case CACHED: {
@ -325,7 +325,7 @@ fprintf(stderr,"getvarx: FETCHWHOLE: fetchconstraint: %s\n",dumpconstraint(fetch
dcemakewholeprojection(fetchprojection);
#ifdef DEBUG
fprintf(stderr,"getvarx: FETCHVAR: fetchprojection: |%s|\n",dumpprojection(fetchprojection));
fprintf(stderr,"getvarx: FETCHVAR: fetchprojection: |%s|\n",dumpprojection(fetchprojection));
#endif
/* Build the complete constraint to use in the fetch */
@ -334,15 +334,15 @@ fprintf(stderr,"getvarx: FETCHVAR: fetchprojection: |%s|\n",dumpprojection(fetch
fetchconstraint->selections = dceclonelist(dapcomm->oc.dapconstraint->selections);
/* and the created fetch projection */
fetchconstraint->projections = nclistnew();
nclistpush(fetchconstraint->projections,(void*)fetchprojection);
nclistpush(fetchconstraint->projections,(void*)fetchprojection);
#ifdef DEBUG
fprintf(stderr,"getvarx: FETCHVAR: fetchconstraint: %s\n",dumpconstraint(fetchconstraint));
#endif
/* buildcachenode3 will create a new cachenode and
will also fetch the corresponding datadds.
*/
ncstat = buildcachenode(dapcomm,fetchconstraint,vars,&cachenode,0);
fetchconstraint = NULL; /*buildcachenode34 takes control of fetchconstraint.*/
ncstat = buildcachenode(dapcomm,fetchconstraint,vars,&cachenode,0);
fetchconstraint = NULL; /*buildcachenode34 takes control of fetchconstraint.*/
if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto fail;}
} break;
@ -356,12 +356,12 @@ fprintf(stderr,"getvarx: FETCHVAR: fetchconstraint: %s\n",dumpconstraint(fetchco
if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto fail;}
/* Shift the varaprojection for simple walk */
dcefree((DCEnode*)walkprojection) ; /* reclaim any existing walkprojection */
dcefree((DCEnode*)walkprojection) ; /* reclaim any existing walkprojection */
walkprojection = (DCEprojection*)dceclone((DCEnode*)varaprojection);
dapshiftprojection(walkprojection);
#ifdef DEBUG
fprintf(stderr,"getvarx: FETCHPART: fetchprojection: |%s|\n",dumpprojection(fetchprojection));
fprintf(stderr,"getvarx: FETCHPART: fetchprojection: |%s|\n",dumpprojection(fetchprojection));
#endif
/* Build the complete constraint to use in the fetch */
@ -370,9 +370,9 @@ fprintf(stderr,"getvarx: FETCHPART: fetchprojection: |%s|\n",dumpprojection(fetc
fetchconstraint->selections = dceclonelist(dapcomm->oc.dapconstraint->selections);
/* and the created fetch projection */
fetchconstraint->projections = nclistnew();
nclistpush(fetchconstraint->projections,(void*)fetchprojection);
nclistpush(fetchconstraint->projections,(void*)fetchprojection);
#ifdef DEBUG
fprintf(stderr,"getvarx: FETCHPART: fetchconstraint: %s\n",dumpconstraint(fetchconstraint));
fprintf(stderr,"getvarx: FETCHPART: fetchconstraint: %s\n",dumpconstraint(fetchconstraint));
#endif
/* buildcachenode3 will create a new cachenode and
will also fetch the corresponding datadds.
@ -395,7 +395,7 @@ fprintf(stderr,"cache.datadds=%s\n",dumptree(cachenode->datadds));
/* attach DATADDS to (constrained) DDS */
unattach(dapcomm->cdf.ddsroot);
ncstat = attachsubset(cachenode->datadds,dapcomm->cdf.ddsroot);
if(ncstat) goto fail;
if(ncstat) goto fail;
/* Fix up varainfo to use the cache */
varainfo->cache = cachenode;
@ -406,7 +406,7 @@ fprintf(stderr,"cache.datadds=%s\n",dumptree(cachenode->datadds));
/* Get the var correlate from the datadds */
target = varainfo->target;
xtarget = target->attachment;
if(xtarget == NULL)
if(xtarget == NULL)
{THROWCHK(ncstat=NC_ENODATA); goto fail;}
/* Switch to datadds tree space*/
@ -421,6 +421,7 @@ fail:
if(fetchconstraint != null) dcefree((DCEnode*)fetchconstraint);
if(varainfo != null) freegetvara(varainfo);
if(ocstat != OC_NOERR) ncstat = ocerrtoncerr(ocstat);
//if(varainfo) freegetvara(varainfo);
return THROW(ncstat);
}
@ -567,7 +568,7 @@ fprintf(stderr," segment=%s hasstringdim=%d\n",
for the case when the user set a limit and that limit
is not actually reached in this request.
*/
/* By construction, this sequence represents the first
/* By construction, this sequence represents the first
(and only) dimension of this segment */
odom = dapodom_fromsegment(segment,0,1);
while(dapodom_more(odom)) {
@ -598,7 +599,7 @@ fprintf(stderr," segment=%s hasstringdim=%d\n",
if(hasstringdim)
ncstat = extractstring(nccomm, xgetvar, xnode, segment, dimindex, conn, currentcontent, memory);
else
else
ncstat = extract(nccomm, xgetvar, xnode, segment, dimindex, conn, currentcontent, memory);
break;
@ -633,11 +634,25 @@ movetofield(NCDAPCOMMON* nccomm,
OCdatanode fieldcontent = NULL;
CDFnode* xnext;
int newdepth;
int ffield;
/* currentcontent points to the grid/dataset/structure/record instance */
xnext = (CDFnode*)nclistget(path,depth+1);
ASSERT((xnext != NULL));
fieldindex = findfield(xnode,xnext);
/* If findfield is less than 0,
and passes through this stanza,
an undefined value will be passed to
oc_data_ithfield. See coverity
issue 712596. */
ffield = findfield(xnode, xnext);
if(ffield < 0) {
ncstat = NC_EBADFIELD;
goto done;
} else {
fieldindex = findfield(xnode,xnext);
}
/* If the next node is a nc_virtual node, then
we need to effectively
ignore it and use the appropriate subnode.
@ -675,7 +690,7 @@ done:
the odometer will be walking the whole subslice
This will allow us to optimize.
*/
static int
static int
wholeslicepoint(Dapodometer* odom)
{
unsigned int i;
@ -688,7 +703,7 @@ wholeslicepoint(Dapodometer* odom)
}
if(point == -1)
point = 0; /* wholevariable */
else if(point == (odom->rank - 1))
else if(point == (odom->rank - 1))
point = -1; /* no whole point */
else
point += 1; /* intermediate point */
@ -753,7 +768,7 @@ extract(
size_t externtypesize;
size_t interntypesize;
int requireconversion;
char value[16];
char value[16];
ASSERT((segment != NULL));
@ -883,7 +898,7 @@ slicestring(OClink conn, char* stringmem, DCEslice* slice, struct NCMEMORY* memo
/* libnc-dap chooses to convert string escapes to the corresponding
character; so we do likewise.
*/
dapexpandescapes(stringmem);
dapexpandescapes(stringmem);
stringlen = strlen(stringmem);
#ifdef DEBUG2
@ -935,7 +950,7 @@ extractstring(
ASSERT(xnode->etype == NC_STRING || xnode->etype == NC_URL);
/* Compute rank minus string dimension */
/* Compute rank minus string dimension */
rank0 = nclistlength(xnode->array.dimset0);
/* keep whole extracted strings stored in an NClist */
@ -945,7 +960,7 @@ extractstring(
char* value = NULL;
ocstat = oc_data_readscalar(conn,currentcontent,sizeof(value),&value);
if(ocstat != OC_NOERR) goto done;
nclistpush(strings,(void*)value);
nclistpush(strings,(void*)value);
} else {
/* Use the odometer to walk to the appropriate fields*/
odom = dapodom_fromsegment(segment,0,rank0);
@ -954,7 +969,7 @@ extractstring(
ocstat = oc_data_readn(conn,currentcontent,odom->index,1,sizeof(value),&value);
if(ocstat != OC_NOERR)
goto done;
nclistpush(strings,(void*)value);
nclistpush(strings,(void*)value);
dapodom_next(odom);
}
dapodom_free(odom);
@ -1043,7 +1058,7 @@ fprintf(stderr,"attachdim: %s->%s\n",xdim->ocname,tdim->ocname);
return NC_NOERR;
}
/*
/*
Match a DATADDS node to a DDS node.
It is assumed that both trees have been re-struct'ed if necessary.
*/
@ -1062,7 +1077,7 @@ attachr(CDFnode* xnode, NClist* templatepath, int depth)
lastnode = (depth == (plen-1));
templatepathnode = (CDFnode*)nclistget(templatepath,depth);
ASSERT((simplenodematch(xnode,templatepathnode)));
setattach(xnode,templatepathnode);
setattach(xnode,templatepathnode);
#ifdef DEBUG2
fprintf(stderr,"attachnode: %s->%s\n",xnode->ocname,templatepathnode->ocname);
#endif
@ -1152,10 +1167,10 @@ done:
}
/*
/*
Match nodes in template tree to nodes in target tree;
template tree is typically a structural superset of target tree.
WARNING: Dimensions are not attached
WARNING: Dimensions are not attached
*/
static NCerror
@ -1246,7 +1261,7 @@ nc3d_getvarmx(int ncid, int varid,
NULL,NULL,NULL,
data,dsttype0));
}
dsttype = (dsttype0);
/* Default to using the inquiry type for this var*/
@ -1337,7 +1352,7 @@ fprintf(stderr,"new: %lu -> %lu %f\n",
*(float*)localpos);
*/
dapodom_next(odom);
}
}
#else
odom = dapodom_new(ncrank,start,edges,stride,NULL);
while(dapodom_more(odom)) {
@ -1361,11 +1376,10 @@ fprintf(stderr,"old: %lu -> %lu %f\n",
*(float*)externalmem);
*/
dapodom_next(odom);
}
}
#endif
done:
return ncstat;
}
#endif /*EXTERN_UNUSED*/

View File

@ -17,7 +17,7 @@ static void genbin_definevardata(Symbol* vsym);
static int genbin_write(Generator*,Symbol*,Bytebuffer*,int,size_t*,size_t*);
static int genbin_writevar(Generator*,Symbol*,Bytebuffer*,int,size_t*,size_t*);
static int genbin_writeattr(Generator*,Symbol*,Bytebuffer*,int,size_t*,size_t*);
static void freeDatalist(Datalist **dlist);
#ifdef USE_NETCDF4
static void genbin_deftype(Symbol* tsym);
static void genbin_definespecialattributes(Symbol* var);
@ -57,7 +57,7 @@ gen_netcdf(const char *filename)
stat = nc_create(filename, cmode_modifier, &ncid);
check_err(stat,__LINE__,__FILE__);
/* ncid created above is also root group*/
rootgroup->ncid = ncid;
@ -136,10 +136,10 @@ gen_netcdf(const char *filename)
if(ngatts > 0) {
for(iatt = 0; iatt < ngatts; iatt++) {
Symbol* gasym = (Symbol*)listget(gattdefs,iatt);
genbin_defineattr(gasym);
genbin_defineattr(gasym);
}
}
/* define per-variable attributes */
if(natts > 0) {
for(iatt = 0; iatt < natts; iatt++) {
@ -187,7 +187,7 @@ genbin_defineglobalspecials(void)
/* Watch out, this is a global Attribute */
format = kind_string(/*Main.*/format_flag);
stat = nc_put_att_text(rootgroup->ncid,NC_GLOBAL,"_Format",strlen(format),format);
check_err(stat,__LINE__,__FILE__);
check_err(stat,__LINE__,__FILE__);
}
#endif /*0*/
@ -206,7 +206,7 @@ genbin_definespecialattributes(Symbol* var)
:NC_CHUNKED),
chunks);
check_err(stat,__LINE__,__FILE__);
}
}
if(special->flags & _FLETCHER32_FLAG) {
stat = nc_def_var_fletcher32(var->container->ncid,
var->ncid,
@ -221,7 +221,7 @@ genbin_definespecialattributes(Symbol* var)
(special->_DeflateLevel >= 0?special->_DeflateLevel
:0));
check_err(stat,__LINE__,__FILE__);
}
}
if(special->flags & _ENDIAN_FLAG) {
stat = nc_def_var_endian(var->container->ncid,
var->ncid,
@ -229,14 +229,14 @@ genbin_definespecialattributes(Symbol* var)
NC_ENDIAN_LITTLE
:NC_ENDIAN_BIG));
check_err(stat,__LINE__,__FILE__);
}
}
if(special->flags & _NOFILL_FLAG) {
stat = nc_def_var_fill(var->container->ncid,
var->ncid,
(special->_Fill?NC_FILL:NC_NOFILL),
NULL);
check_err(stat,__LINE__,__FILE__);
}
}
}
#endif /*USE_NETCDF4*/
@ -266,9 +266,9 @@ genbin_deftype(Symbol* tsym)
tsym->typ.size,
tsym->name,
&tsym->ncid);
check_err(stat,__LINE__,__FILE__);
check_err(stat,__LINE__,__FILE__);
break;
case NC_ENUM:
case NC_ENUM:
{
Bytebuffer* datum;
Datalist* ecdl;
@ -276,7 +276,7 @@ genbin_deftype(Symbol* tsym)
tsym->typ.basetype->typ.typecode,
tsym->name,
&tsym->ncid);
check_err(stat,__LINE__,__FILE__);
check_err(stat,__LINE__,__FILE__);
datum = bbNew();
ecdl = builddatalist(1);
dlextend(ecdl); /* make room for one constant*/
@ -291,29 +291,29 @@ genbin_deftype(Symbol* tsym)
tsym->ncid,
econst->name,
bbContents(datum));
check_err(stat,__LINE__,__FILE__);
check_err(stat,__LINE__,__FILE__);
}
bbFree(datum);
}
dlfree(&ecdl);
}
break;
case NC_VLEN:
stat = nc_def_vlen(tsym->container->ncid,
tsym->name,
tsym->typ.basetype->ncid,
&tsym->ncid);
check_err(stat,__LINE__,__FILE__);
check_err(stat,__LINE__,__FILE__);
break;
case NC_COMPOUND:
stat = nc_def_compound(tsym->container->ncid,
tsym->typ.size,
tsym->typ.size,
tsym->name,
&tsym->ncid);
check_err(stat,__LINE__,__FILE__);
&tsym->ncid);
check_err(stat,__LINE__,__FILE__);
for(i=0;i<listlength(tsym->subnodes);i++) {
Symbol* efield = (Symbol*)listget(tsym->subnodes,i);
ASSERT(efield->subclass == NC_FIELD);
if(efield->typ.dimset.ndims == 0){
if(efield->typ.dimset.ndims == 0){
stat = nc_insert_compound(
tsym->container->ncid,
tsym->ncid,
@ -337,7 +337,7 @@ genbin_deftype(Symbol* tsym)
efield->typ.dimset.ndims,
dimsizes);
}
check_err(stat,__LINE__,__FILE__);
check_err(stat,__LINE__,__FILE__);
}
break;
default: panic("definectype: unexpected type subclass");
@ -391,7 +391,7 @@ genbin_writevar(Generator* generator, Symbol* vsym, Bytebuffer* memory,
int stat = NC_NOERR;
char* data = bbContents(memory);
#ifdef USE_NOFILL
size_t count[NC_MAX_VAR_DIMS];
size_t count[NC_MAX_VAR_DIMS];
{ int i; for(i=0;i<rank;i++) count[i] = indices[i] - start[i];}
#endif
@ -409,7 +409,7 @@ genbin_writevar(Generator* generator, Symbol* vsym, Bytebuffer* memory,
fflush(stderr);
}
#endif
if(rank == 0) {
size_t count[1] = {1};
stat = nc_put_var1(vsym->container->ncid, vsym->ncid, count, data);
@ -444,7 +444,7 @@ genbin_writeattr(Generator* generator, Symbol* asym, Bytebuffer* databuf,
case NC_BYTE: {
signed char* data = (signed char*)bbContents(databuf);
stat = nc_put_att_schar(grpid,varid,asym->name,typid,len,data);
check_err(stat,__LINE__,__FILE__);
check_err(stat,__LINE__,__FILE__);
} break;
case NC_CHAR: {
char* data = (char*)bbContents(databuf);
@ -452,27 +452,27 @@ genbin_writeattr(Generator* generator, Symbol* asym, Bytebuffer* databuf,
/* Revise length if slen == 0 */
if(slen == 0) {bbAppend(databuf,'\0'); slen++;}
stat = nc_put_att_text(grpid,varid,asym->name,slen,data);
check_err(stat,__LINE__,__FILE__);
check_err(stat,__LINE__,__FILE__);
} break;
case NC_SHORT: {
short* data = (short*)bbContents(databuf);
stat = nc_put_att_short(grpid,varid,asym->name,typid,len,data);
check_err(stat,__LINE__,__FILE__);
check_err(stat,__LINE__,__FILE__);
} break;
case NC_INT: {
int* data = (int*)bbContents(databuf);
stat = nc_put_att_int(grpid,varid,asym->name,typid,len,data);
check_err(stat,__LINE__,__FILE__);
check_err(stat,__LINE__,__FILE__);
} break;
case NC_FLOAT: {
float* data = (float*)bbContents(databuf);
stat = nc_put_att_float(grpid,varid,asym->name,typid,len,data);
check_err(stat,__LINE__,__FILE__);
check_err(stat,__LINE__,__FILE__);
} break;
case NC_DOUBLE: {
double* data = (double*)bbContents(databuf);
stat = nc_put_att_double(grpid,varid,asym->name,typid,len,data);
check_err(stat,__LINE__,__FILE__);
check_err(stat,__LINE__,__FILE__);
} break;
#ifdef USE_NETCDF4
case NC_STRING: {
@ -485,29 +485,29 @@ genbin_writeattr(Generator* generator, Symbol* asym, Bytebuffer* databuf,
case NC_UBYTE: {
unsigned char* data = (unsigned char*)bbContents(databuf);
stat = nc_put_att_uchar(grpid,varid,asym->name,typid,len,data);
check_err(stat,__LINE__,__FILE__);
check_err(stat,__LINE__,__FILE__);
} break;
case NC_USHORT: {
unsigned short* data = (unsigned short*)bbContents(databuf);
stat = nc_put_att_ushort(grpid,varid,asym->name,typid,len,data);
check_err(stat,__LINE__,__FILE__);
check_err(stat,__LINE__,__FILE__);
} break;
case NC_UINT: {
unsigned int* data = (unsigned int*)bbContents(databuf);
stat = nc_put_att_uint(grpid,varid,asym->name,typid,len,data);
check_err(stat,__LINE__,__FILE__);
check_err(stat,__LINE__,__FILE__);
} break;
case NC_INT64: {
long long* data = (long long*)bbContents(databuf);
stat = nc_put_att_longlong(grpid,varid,asym->name,typid,len,data);
check_err(stat,__LINE__,__FILE__);
check_err(stat,__LINE__,__FILE__);
} break;
case NC_UINT64: {
unsigned long long* data = (unsigned long long*)bbContents(databuf);
stat = nc_put_att_ulonglong(grpid,varid,asym->name,typid,len,data);
check_err(stat,__LINE__,__FILE__);
check_err(stat,__LINE__,__FILE__);
} break;
#endif
#endif
default: PANIC1("genbin_defineattr: unexpected basetype: %d",basetype->typ.typecode);
}
} else { /* use the generic put_attribute for user defined types*/

View File

@ -85,7 +85,8 @@ generate_vardata(Symbol* vsym, Generator* generator, Writer writer, Bytebuffer*
if(vsym->data == NULL) return;
/* give the buffer a running start to be large enough*/
bbSetalloc(code, nciterbuffersize);
if(!bbSetalloc(code, nciterbuffersize))
return;
if(rank == 0) {/*scalar case*/
NCConstant* c0 = datalistith(vsym->data,0);
@ -95,7 +96,7 @@ generate_vardata(Symbol* vsym, Generator* generator, Writer writer, Bytebuffer*
generate_array(vsym,code,filler,generator,writer);
}
}
static void
generate_array(Symbol* vsym,
Bytebuffer* code,
@ -153,7 +154,7 @@ generate_array(Symbol* vsym,
Constant* con = datalistith(vsym->data,i);
#else
NCConstant* con = datalistith(vsym->data,i+offset);
#endif
#endif
generator->list(generator,LISTDATA,uid,i,code);
#ifdef USE_NOFILL
if(nofill_flag && con == NULL)
@ -221,7 +222,7 @@ generate_arrayr(Symbol* vsym,
ASSERT(dimindex >= 0 && dimindex < rank);
#ifdef CHARBUG
ASSERT(typecode != NC_CHAR);
ASSERT(typecode != NC_CHAR);
#else /*!CHARBUG*/
if(dimindex == lastunlimited && typecode == NC_CHAR) {
Bytebuffer* charbuf = bbNew();
@ -237,7 +238,7 @@ generate_arrayr(Symbol* vsym,
(similar to case 2 above)
*/
slabodom = newsubodometer(odom,dimset,dimindex,rank);
/* compute the starting offset in our datalist
/* compute the starting offset in our datalist
(Assumes that slabodom->index[i] == slabodom->start[i])
*/
generator->listbegin(generator,LISTDATA,list->length,code,&uid);
@ -267,7 +268,7 @@ generate_arrayr(Symbol* vsym,
&& (dimset->dimsyms[nextunlimited]->dim.isunlimited)));
/* build a sub odometer */
slabodom = newsubodometer(odom,dimset,dimindex,nextunlimited);
/* compute the starting offset in our datalist
/* compute the starting offset in our datalist
(Assumes that slabodom->index[i] == slabodom->start[i])
*/
for(i=0;odometermore(slabodom);i++) {
@ -281,7 +282,7 @@ generate_arrayr(Symbol* vsym,
if(filler == NULL)
filler = getfiller(vsym);
generate_arrayr(vsym,code,filler,odom,nextunlimited,NULL,generator);
} else if(!islistconst(con))
semwarn(constline(con),"Expected {...} representing unlimited list");
else {
@ -361,7 +362,7 @@ generate_basetype(Symbol* tsym, NCConstant* con, Bytebuffer* codebuf, Datalist*
}
data = con->value.compoundv;
/* generate the nc_vlen_t instance*/
vlenbuf = bbNew();
vlenbuf = bbNew();
if(tsym->typ.basetype->typ.typecode == NC_CHAR) {
gen_charvlen(data,vlenbuf);
generator->vlenstring(generator,vlenbuf,&uid,&count);
@ -382,7 +383,7 @@ generate_basetype(Symbol* tsym, NCConstant* con, Bytebuffer* codebuf, Datalist*
case NC_FIELD:
if(tsym->typ.dimset.ndims > 0) {
/* Verify that we have a sublist (or fill situation) */
if(con != NULL && !isfillconst(con) && !islistconst(con))
if(con != NULL && !isfillconst(con) && !islistconst(con))
semerror(constline(con),"Dimensioned fields must be enclose in {...}");
generate_fieldarray(tsym->typ.basetype,con,&tsym->typ.dimset,codebuf,filler,generator);
} else {
@ -413,7 +414,7 @@ generate_fieldarray(Symbol* basetype, NCConstant* con, Dimset* dimset,
if(chartype) {
/* Collect the char field in a separate buffer */
Bytebuffer* charbuf = bbNew();
gen_chararray(dimset,data,charbuf,filler);
gen_chararray(dimset,data,charbuf,filler);
generator->charconstant(generator,codebuf,charbuf);
bbFree(charbuf);
} else {
@ -441,7 +442,7 @@ normalizeopaquelength(NCConstant* prim, unsigned long nbytes)
{
int nnibs = 2*nbytes;
ASSERT(prim->nctype==NC_OPAQUE);
if(prim->value.opaquev.len == nnibs) {
if(prim->value.opaquev.len == nnibs) {
/* do nothing*/
} else if(prim->value.opaquev.len > nnibs) { /* truncate*/
prim->value.opaquev.stringv[nnibs] = '\0';
@ -530,13 +531,13 @@ generate_primdata(Symbol* basetype, NCConstant* prim, Bytebuffer* codebuf,
if(basetype->subclass != NC_ENUM) {
semerror(constline(prim),"Conversion to enum not supported (yet)");
} break;
case NC_OPAQUE:
case NC_OPAQUE:
normalizeopaquelength(&target,basetype->typ.size);
break;
default:
break;
}
generator->constant(generator,&target,codebuf);
return;
}

View File

@ -62,6 +62,7 @@ verror(fmt,va_alist) const char* fmt; va_dcl
strcpy(newfmt,"netCDF classic: not supported: ");
strncat(newfmt,fmt,2000);
vderror(newfmt,argv);
va_end(argv);
}
#ifndef NO_STDARG
@ -103,7 +104,7 @@ markcdf4(const char* msg)
markcdf4_msg = (char*)msg;
}
char*
char*
getmarkcdf4(void)
{
return markcdf4_msg;

View File

@ -84,7 +84,7 @@ tztrim(
)
{
char *cp, *ep;
cp = ss;
if (*cp == '-')
cp++;
@ -138,7 +138,7 @@ freeSymbol(Symbol* sym)
case NG_FIELD:
case NG_OPAQUE:
default: break;
}
}
efree(sym->name);
efree(sym);
#endif
@ -169,15 +169,15 @@ nctypename(nc_type nctype)
return nctypenamesextend[(nctype - NC_GRP)];
if(nctype == NC_FILLVALUE) return "NC_FILL";
if(nctype == NC_NIL) return "NC_NIL";
s = poolalloc(128);
s = poolalloc(128);
sprintf(s,"NC_<%d>",nctype);
return s;
}
/* These are the augmented NC_ values (0 based from NC_GRP)*/
char* ncclassnames[9] = {
"NC_GRP", "NC_DIM", "NC_VAR", "NC_ATT",
"NC_TYP", "NC_ECONST", "NC_FIELD", "NC_ARRAY",
char* ncclassnames[9] = {
"NC_GRP", "NC_DIM", "NC_VAR", "NC_ATT",
"NC_TYP", "NC_ECONST", "NC_FIELD", "NC_ARRAY",
"NC_PRIM"
};
@ -190,7 +190,7 @@ ncclassname(nc_class ncc)
if(ncc == NC_FILLVALUE) return "NC_FILL";
if(ncc >= NC_GRP && ncc <= NC_PRIM)
return ncclassnames[ncc - NC_GRP];
s = poolalloc(128);
s = poolalloc(128);
sprintf(s,"NC_<%d>",ncc);
return s;
}
@ -331,7 +331,7 @@ prefixtostring(List* prefix, char* separator)
strcat(result,separator);
strcat(result,sym->name); /* append "/<prefix[i]>"*/
}
}
}
return result;
}
#endif
@ -340,7 +340,7 @@ prefixtostring(List* prefix, char* separator)
char*
fullname(Symbol* sym)
{
#ifdef USE_NETCDF4
#ifdef USE_NETCDF4
char* s1;
char* result;
char* prefix;
@ -357,7 +357,7 @@ int
prefixeq(List* x1, List* x2)
{
Symbol** l1;
Symbol** l2;
Symbol** l2;
int len,i;
if((len=listlength(x1)) != listlength(x2)) return 0;
l1=(Symbol**)listcontents(x1);
@ -377,7 +377,7 @@ prefixdup(List* prefix)
dupseq = listnew();
listsetalloc(dupseq,listlength(prefix));
for(i=0;i<listlength(prefix);i++) listpush(dupseq,listget(prefix,i));
return dupseq;
return dupseq;
}
/*
@ -445,14 +445,14 @@ makebytestring(char* s, size_t* lenp)
int i;
ASSERT((slen%2) == 0);
ASSERT(blen > 0);
ASSERT(blen > 0);
bytes = (unsigned char*)emalloc(blen);
b = bytes;
for(i=0;i<slen;i+=2) {
unsigned int digit1 = chartohex(*s++);
unsigned int digit2 = chartohex(*s++);
unsigned int byte = (digit1 << 4) | digit2;
*b++ = byte;
*b++ = byte;
}
if(lenp) *lenp = blen;
return bytes;
@ -525,7 +525,30 @@ builddatasublist(Datalist* dl)
d.value.compoundv = dl;
d.filled = 0;
return d;
}
/*! Function to free an allocated datalist.
This function is used to free an individual datalist
object. It is possible, hypothetically, that a
datalist will appear in the middle of a set of datalists,
in which case we'll need to determine that and shuffle around
'next' pointers. For the time being, this assumes that
we are freeing a datalist which was allocated locally
and must be discarded.
Using this function instead of an inline 'free' just in
case we ever want to extend it, we won't have to go back
and re-write a bunch of stuff. I hope.
@param dlist Pointer to datalist object being freed.
*/
void dlfree(Datalist **dlist) {
if(*dlist) free(*dlist);
dlist = NULL;
}
static void
@ -534,7 +557,7 @@ constantFree(NCConstant* con)
switch(con->nctype) {
case NC_COMPOUND:
/* do nothing; ReclaimDatalists below will take care of the datalist */
break;
break;
case NC_STRING:
if(con->value.stringv.len > 0 && con->value.stringv.stringv != NULL)
efree(con->value.stringv.stringv);
@ -560,7 +583,7 @@ reclaimDatalists(void)
for(i=0,con=list->data;i<list->length;i++,con++)
constantFree(con);
list->data = NULL;
}
}
}
/* Step 2: free up the datalist itself*/
for(list=alldatalists;list != NULL;) {
@ -600,7 +623,7 @@ crossproduct(Dimset* dimset, int start, int stop)
for(i=start;i<stop;i++) {
totalsize = totalsize * dimset->dimsyms[i]->dim.declsize;
}
return totalsize;
return totalsize;
}
/* Do the "complement" of crossproduct;
@ -618,7 +641,7 @@ prefixarraylength(Dimset* dimset, int last)
#ifdef USE_NETCDF4
extern int H5Eprint1(FILE * stream);
#endif
#endif
void
check_err(const int stat, const int line, const char* file) {
@ -627,7 +650,7 @@ check_err(const int stat, const int line, const char* file) {
fprintf(stderr, "\t(%s:%d)\n", file,line);
#ifdef USE_NETCDF4
H5Eprint1(stderr);
#endif
#endif
fflush(stderr);
exit(1);
}
@ -669,4 +692,3 @@ kind_string(int kind)
}
return NULL;
}

View File

@ -53,6 +53,7 @@ extern unsigned char* makebytestring(char* s, size_t* lenp);
extern int getpadding(int offset, int alignment);
extern Datalist* builddatalist(int initialize);
extern void dlfree(Datalist **dlist);
extern void dlappend(Datalist*, NCConstant*);
extern NCConstant builddatasublist(Datalist* dl);
extern void dlextend(Datalist* dl);

View File

@ -71,10 +71,10 @@ int filelike; /* 1=>this protocol has no host, user+pwd, or port */
};
/* Allowable character sets for encode */
static char* fileallow =
static char* fileallow =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$&'()*+,-./:;=?@_~";
static char* queryallow =
static char* queryallow =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$&'()*+,-./:;=?@_~";
/* Forward */
@ -112,7 +112,7 @@ ocuriparse(const char* uri0, OCURI** durip)
duri = (OCURI*)calloc(1,sizeof(OCURI));
if(duri == NULL)
{THROW(2); goto fail;}
/* save original uri */
duri->uri = nulldup(uri0);
@ -126,7 +126,7 @@ ocuriparse(const char* uri0, OCURI** durip)
first char is guaranteed to be '\0' */
duri->strings = uri;
uri++;
uri++;
/* dup the incoming url */
strcpy(uri,uri0);
@ -139,7 +139,7 @@ ocuriparse(const char* uri0, OCURI** durip)
for(p=uri;*p;p++) {
if(*p == '\\' || *p < ' ')
oclshift1(p); /* compress out */
}
}
p = uri;
@ -166,7 +166,7 @@ ocuriparse(const char* uri0, OCURI** durip)
}
/* Tag the protocol */
protocol = p;
protocol = p;
p = strchr(p,':');
if(!p)
{THROW(5); goto fail;}
@ -179,7 +179,7 @@ ocuriparse(const char* uri0, OCURI** durip)
for(i=0;i<nprotos;i++) {
if(strcmp(protocol,legalprotocols[i].name)==0) {
proto = &legalprotocols[i];
break;
break;
}
}
if(proto == NULL)
@ -212,7 +212,7 @@ ocuriparse(const char* uri0, OCURI** durip)
file = p+1; /* +1 becauseof the shift */
}
}
/* If you shift in the code below, you must reset file beginning */
if(host != NULL) {/* Parse the host section */
@ -263,7 +263,7 @@ ocuriparse(const char* uri0, OCURI** durip)
p = oclocate(p,"?#");
if(p != NULL) { /* we have constraint and/or suffixparams */
char* fileend = p; /* save the end of the file section */
char* constraintend = NULL;
char* constraintend = NULL;
if(*p == '?')
constraint = p+1;
else
@ -399,8 +399,8 @@ ocurisetconstraints(OCURI* duri,const char* constraints)
if(duri->constraint != NULL) free(duri->constraint);
if(duri->projection != NULL) free(duri->projection);
if(duri->selection != NULL) free(duri->selection);
duri->constraint = NULL;
duri->projection = NULL;
duri->constraint = NULL;
duri->projection = NULL;
duri->selection = NULL;
if(constraints == NULL || strlen(constraints)==0) return;
@ -473,7 +473,7 @@ ocuribuild(OCURI* duri, const char* prefix, const char* suffix, int flags)
if(duri->port != NULL) {
len += (NILLEN(":")+NILLEN(duri->port));
}
tmpfile = duri->file;
if(encode)
tmpfile = ocuriencode(tmpfile,fileallow);
@ -497,7 +497,7 @@ ocuribuild(OCURI* duri, const char* prefix, const char* suffix, int flags)
char** p;
if(duri->paramlist == NULL)
if(!ocuridecodeparams(duri))
return NULL;
return NULL;
for(paramslen=0,nparams=0,p=duri->paramlist;*p;p++) {
nparams++;
paramslen += NILLEN(*p);
@ -512,7 +512,7 @@ ocuribuild(OCURI* duri, const char* prefix, const char* suffix, int flags)
}
len += 1; /* null terminator */
newuri = (char*)malloc(len);
if(newuri == NULL) return NULL;
@ -527,11 +527,11 @@ ocuribuild(OCURI* duri, const char* prefix, const char* suffix, int flags)
if(withuserpwd) {
strcat(newuri,duri->user);
strcat(newuri,":");
strcat(newuri,duri->password);
strcat(newuri,duri->password);
strcat(newuri,"@");
}
if(duri->host != NULL) { /* may be null if using file: protocol */
strcat(newuri,duri->host);
strcat(newuri,duri->host);
}
if(duri->port != NULL) {
strcat(newuri,":");
@ -594,10 +594,10 @@ suceeded, 0 otherwise; */
int
ocuridecodeparams(OCURI* ocuri)
{
char* cp;
char* cp = NULL;
int i,c;
int nparams;
char* params;
char* params = NULL;
char** plist;
if(ocuri == NULL) return 0;
@ -615,21 +615,23 @@ ocuridecodeparams(OCURI* ocuri)
/* plist is an env style list */
plist = (char**)calloc(1,sizeof(char*)*(2*nparams+1)); /* +1 for null termination */
if(plist == NULL)
return 0;
if(plist == NULL) {
free(params);
return 0;
}
/* Break up each param into a (name,value) pair*/
/* and insert into the param list */
/* parameters of the form name name= are converted to name=""*/
for(cp=params,i=0;i<nparams;i++) {
char* next = cp+strlen(cp)+1; /* save ptr to next pair*/
char* vp;
/*break up the ith param*/
vp = strchr(cp,'=');
if(vp != NULL) {*vp = EOFCHAR; vp++;} else {vp = "";}
plist[2*i] = nulldup(cp);
plist[2*i+1] = nulldup(vp);
cp = next;
char* next = cp+strlen(cp)+1; /* save ptr to next pair*/
char* vp;
/*break up the ith param*/
vp = strchr(cp,'=');
if(vp != NULL) {*vp = EOFCHAR; vp++;} else {vp = "";}
plist[2*i] = nulldup(cp);
plist[2*i+1] = nulldup(vp);
cp = next;
}
plist[2*nparams] = NULL;
free(params);
@ -817,7 +819,7 @@ ocuridecodeonly(char* s, char* only)
char* outptr;
char* inptr;
unsigned int c;
if (s == NULL) return NULL;
if(only == NULL) only = "";
@ -847,4 +849,3 @@ ocuridecodeonly(char* s, char* only)
*outptr = EOFCHAR;
return decoded;
}