2011-04-18 02:56:10 +08:00
|
|
|
/*********************************************************************
|
2018-12-07 05:21:03 +08:00
|
|
|
* Copyright 2018, UCAR/Unidata
|
2011-04-18 02:56:10 +08:00
|
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
|
|
|
*********************************************************************/
|
|
|
|
|
2017-03-09 08:01:10 +08:00
|
|
|
#include "dapincludes.h"
|
2011-04-18 02:56:10 +08:00
|
|
|
#include "daputil.h"
|
|
|
|
#include "dapdump.h"
|
2023-11-27 19:36:03 +08:00
|
|
|
#include <stddef.h>
|
2011-04-18 02:56:10 +08:00
|
|
|
|
2013-02-26 12:31:06 +08:00
|
|
|
#ifdef DAPDEBUG
|
|
|
|
extern char* ocfqn(OCddsnode);
|
|
|
|
#endif
|
|
|
|
|
2011-04-18 02:56:10 +08:00
|
|
|
/* Forward*/
|
2014-03-25 04:02:52 +08:00
|
|
|
static NCerror sequencecheckr(CDFnode* node, NClist* vars, CDFnode* topseq);
|
|
|
|
static NCerror restructr(NCDAPCOMMON*, CDFnode*, CDFnode*, NClist*);
|
2014-01-25 04:26:00 +08:00
|
|
|
static NCerror repairgrids(NCDAPCOMMON*, NClist*);
|
2014-03-25 04:02:52 +08:00
|
|
|
static NCerror structwrap(NCDAPCOMMON*, CDFnode*, CDFnode*, int, CDFnode*, int);
|
2013-02-26 12:31:06 +08:00
|
|
|
static int findin(CDFnode* parent, CDFnode* child);
|
2014-03-25 04:02:52 +08:00
|
|
|
static CDFnode* makenewstruct(NCDAPCOMMON*, CDFnode*, CDFnode*);
|
|
|
|
static NCerror mapnodesr(CDFnode*, CDFnode*, int depth);
|
2011-11-14 12:20:19 +08:00
|
|
|
static NCerror mapfcn(CDFnode* dstnode, CDFnode* srcnode);
|
2014-03-25 04:02:52 +08:00
|
|
|
static NCerror definedimsetplus(NCDAPCOMMON* nccomm, CDFnode* node);
|
|
|
|
static NCerror definedimsetall(NCDAPCOMMON* nccomm, CDFnode* node);
|
|
|
|
static NCerror definetransdimset(NCDAPCOMMON* nccomm, CDFnode* node);
|
|
|
|
static NCerror definedimsettransR(NCDAPCOMMON* nccomm, CDFnode* node);
|
|
|
|
static NCerror definedimsetsR(NCDAPCOMMON* nccomm, CDFnode* node);
|
|
|
|
static NCerror buildcdftreer(NCDAPCOMMON*, OCddsnode, CDFnode*, CDFtree*, CDFnode**);
|
|
|
|
static void free1cdfnode(CDFnode* node);
|
|
|
|
static NCerror fixnodes(NCDAPCOMMON*, NClist* cdfnodes);
|
|
|
|
static void defdimensions(OCddsnode ocnode, CDFnode* cdfnode, NCDAPCOMMON* nccomm, CDFtree* tree);
|
2011-04-18 02:56:10 +08:00
|
|
|
|
|
|
|
/* Accumulate useful node sets */
|
|
|
|
NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
computecdfnodesets(NCDAPCOMMON* nccomm, CDFtree* tree)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
|
|
|
unsigned int i;
|
2013-03-03 12:06:43 +08:00
|
|
|
NClist* varnodes;
|
|
|
|
NClist* allnodes;
|
|
|
|
|
|
|
|
allnodes = tree->nodes;
|
2014-07-30 00:44:50 +08:00
|
|
|
varnodes = nclistnew();
|
2011-04-18 02:56:10 +08:00
|
|
|
|
2013-03-03 12:06:43 +08:00
|
|
|
if(tree->seqnodes == NULL) tree->seqnodes = nclistnew();
|
|
|
|
if(tree->gridnodes == NULL) tree->gridnodes = nclistnew();
|
|
|
|
nclistclear(tree->seqnodes);
|
|
|
|
nclistclear(tree->gridnodes);
|
2011-04-18 02:56:10 +08:00
|
|
|
|
2014-03-25 04:02:52 +08:00
|
|
|
computevarnodes(nccomm,allnodes,varnodes);
|
2013-03-03 12:06:43 +08:00
|
|
|
nclistfree(tree->varnodes);
|
|
|
|
tree->varnodes = varnodes;
|
|
|
|
varnodes = NULL;
|
2011-04-18 02:56:10 +08:00
|
|
|
|
|
|
|
/* Now compute other sets of interest */
|
|
|
|
for(i=0;i<nclistlength(allnodes);i++) {
|
|
|
|
CDFnode* node = (CDFnode*)nclistget(allnodes,i);
|
|
|
|
switch (node->nctype) {
|
|
|
|
case NC_Sequence:
|
2013-03-03 12:06:43 +08:00
|
|
|
nclistpush(tree->seqnodes,(void*)node);
|
2011-04-18 02:56:10 +08:00
|
|
|
break;
|
|
|
|
case NC_Grid:
|
2013-03-03 12:06:43 +08:00
|
|
|
nclistpush(tree->gridnodes,(void*)node);
|
2011-04-18 02:56:10 +08:00
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
computevarnodes(NCDAPCOMMON* nccomm, NClist* allnodes, NClist* varnodes)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
2023-11-27 22:59:48 +08:00
|
|
|
size_t i, len;
|
2011-04-18 02:56:10 +08:00
|
|
|
NClist* allvarnodes = nclistnew();
|
|
|
|
for(i=0;i<nclistlength(allnodes);i++) {
|
|
|
|
CDFnode* node = (CDFnode*)nclistget(allnodes,i);
|
2013-02-05 02:49:48 +08:00
|
|
|
#if 0
|
2012-04-09 06:47:38 +08:00
|
|
|
/* If this node has a bad name, repair it */
|
|
|
|
if(dap_badname(node->ocname)) {
|
|
|
|
char* newname = dap_repairname(node->ocname);
|
|
|
|
nullfree(node->ocname);
|
|
|
|
node->ocname = newname;
|
|
|
|
}
|
2013-02-05 02:49:48 +08:00
|
|
|
#endif
|
2012-08-01 04:34:13 +08:00
|
|
|
if(node->nctype == NC_Atomic)
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(allvarnodes,(void*)node);
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
/* Further process the variable nodes to get the final set */
|
|
|
|
/* Use toplevel vars first */
|
|
|
|
len = nclistlength(allvarnodes);
|
|
|
|
for(i=0;i<len;i++) {
|
|
|
|
CDFnode* node = (CDFnode*)nclistget(allvarnodes,i);
|
|
|
|
if(node == NULL) continue;
|
|
|
|
if(daptoplevel(node)) {
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(varnodes,(void*)node);
|
|
|
|
nclistset(allvarnodes,i,(void*)NULL);
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*... then grid arrays and maps.
|
|
|
|
but exclude the coordinate variables if we are trying to
|
|
|
|
exactly mimic nc-dap
|
|
|
|
*/
|
|
|
|
for(i=0;i<len;i++) {
|
|
|
|
CDFnode* node = (CDFnode*)nclistget(allvarnodes,i);
|
|
|
|
if(node == NULL) continue;
|
|
|
|
if(dapgridarray(node)) {
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(varnodes,(void*)node);
|
|
|
|
nclistset(allvarnodes,i,(void*)NULL);
|
2011-04-18 02:56:10 +08:00
|
|
|
} else if(dapgridmap(node)) {
|
|
|
|
if(!FLAGSET(nccomm->controls,NCF_NCDAP))
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(varnodes,(void*)node);
|
|
|
|
nclistset(allvarnodes,i,(void*)NULL);
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/*... then all others */
|
|
|
|
for(i=0;i<len;i++) {
|
|
|
|
CDFnode* node = (CDFnode*)nclistget(allvarnodes,i);
|
|
|
|
if(node == NULL) continue;
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(varnodes,(void*)node);
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
nclistfree(allvarnodes);
|
2012-02-04 05:31:50 +08:00
|
|
|
#ifdef DEBUG2
|
|
|
|
for(i=0;i<nclistlength(varnodes);i++) {
|
|
|
|
CDFnode* node = (CDFnode*)nclistget(varnodes,i);
|
|
|
|
if(node == NULL) continue;
|
2014-03-25 04:02:52 +08:00
|
|
|
fprintf(stderr,"computevarnodes: var: %s\n",makecdfpathstring(node,"."));
|
2012-02-04 05:31:50 +08:00
|
|
|
}
|
|
|
|
#endif
|
2011-04-18 02:56:10 +08:00
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
2014-03-25 04:02:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
NCerror
|
|
|
|
fixgrid(NCDAPCOMMON* nccomm, CDFnode* grid)
|
|
|
|
{
|
|
|
|
unsigned int i,glen;
|
|
|
|
CDFnode* array;
|
|
|
|
|
|
|
|
glen = nclistlength(grid->subnodes);
|
2014-07-30 00:44:50 +08:00
|
|
|
array = (CDFnode*)nclistget(grid->subnodes,0);
|
2014-03-25 04:02:52 +08:00
|
|
|
if(nccomm->controls.flags & (NCF_NC3)) {
|
|
|
|
/* Rename grid Array: variable, but leave its oc base name alone */
|
|
|
|
nullfree(array->ncbasename);
|
|
|
|
array->ncbasename = nulldup(grid->ncbasename);
|
|
|
|
if(!array->ncbasename) return NC_ENOMEM;
|
|
|
|
}
|
|
|
|
/* validate and modify the grid structure */
|
|
|
|
if((glen-1) != nclistlength(array->array.dimset0)) goto invalid;
|
|
|
|
for(i=1;i<glen;i++) {
|
|
|
|
CDFnode* arraydim = (CDFnode*)nclistget(array->array.dimset0,i-1);
|
|
|
|
CDFnode* map = (CDFnode*)nclistget(grid->subnodes,i);
|
|
|
|
CDFnode* mapdim;
|
|
|
|
/* map must have 1 dimension */
|
|
|
|
if(nclistlength(map->array.dimset0) != 1) goto invalid;
|
|
|
|
/* and the map name must match the ith array dimension */
|
|
|
|
if(arraydim->ocname != NULL && map->ocname != NULL
|
|
|
|
&& strcmp(arraydim->ocname,map->ocname) != 0)
|
|
|
|
goto invalid;
|
|
|
|
/* and the map name must match its dim name (if any) */
|
|
|
|
mapdim = (CDFnode*)nclistget(map->array.dimset0,0);
|
|
|
|
if(mapdim->ocname != NULL && map->ocname != NULL
|
|
|
|
&& strcmp(mapdim->ocname,map->ocname) != 0)
|
|
|
|
goto invalid;
|
|
|
|
/* Add appropriate names for the anonymous dimensions */
|
|
|
|
/* Do the map name first, so the array dim may inherit */
|
|
|
|
if(mapdim->ocname == NULL) {
|
|
|
|
nullfree(mapdim->ncbasename);
|
|
|
|
mapdim->ocname = nulldup(map->ocname);
|
|
|
|
if(!mapdim->ocname) return NC_ENOMEM;
|
|
|
|
mapdim->ncbasename = cdflegalname(mapdim->ocname);
|
|
|
|
if(!mapdim->ncbasename) return NC_ENOMEM;
|
|
|
|
}
|
|
|
|
if(arraydim->ocname == NULL) {
|
|
|
|
nullfree(arraydim->ncbasename);
|
|
|
|
arraydim->ocname = nulldup(map->ocname);
|
|
|
|
if(!arraydim->ocname) return NC_ENOMEM;
|
|
|
|
arraydim->ncbasename = cdflegalname(arraydim->ocname);
|
|
|
|
if(!arraydim->ncbasename) return NC_ENOMEM;
|
|
|
|
}
|
|
|
|
if(FLAGSET(nccomm->controls,(NCF_NCDAP|NCF_NC3))) {
|
|
|
|
char tmp[3*NC_MAX_NAME];
|
|
|
|
/* Add the grid name to the basename of the map */
|
|
|
|
snprintf(tmp,sizeof(tmp),"%s%s%s",map->container->ncbasename,
|
|
|
|
nccomm->cdf.separator,
|
|
|
|
map->ncbasename);
|
|
|
|
nullfree(map->ncbasename);
|
|
|
|
map->ncbasename = nulldup(tmp);
|
|
|
|
if(!map->ncbasename) return NC_ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NC_NOERR;
|
|
|
|
invalid:
|
|
|
|
return NC_EINVAL; /* mal-formed grid */
|
|
|
|
}
|
|
|
|
|
2011-04-18 02:56:10 +08:00
|
|
|
NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
fixgrids(NCDAPCOMMON* nccomm)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
|
|
|
unsigned int i;
|
2013-03-03 12:06:43 +08:00
|
|
|
NClist* gridnodes = nccomm->cdf.ddsroot->tree->gridnodes;
|
2011-04-18 02:56:10 +08:00
|
|
|
|
|
|
|
for(i=0;i<nclistlength(gridnodes);i++) {
|
|
|
|
CDFnode* grid = (CDFnode*)nclistget(gridnodes,i);
|
2014-03-25 04:02:52 +08:00
|
|
|
(void)fixgrid(nccomm,grid);
|
2011-04-18 02:56:10 +08:00
|
|
|
/* Ignore mal-formed grids */
|
|
|
|
}
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Figure out the names for variables.
|
|
|
|
*/
|
|
|
|
NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
computecdfvarnames(NCDAPCOMMON* nccomm, CDFnode* root, NClist* varnodes)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
|
|
|
unsigned int i,j,d;
|
|
|
|
|
|
|
|
/* clear all elided marks; except for dataset and grids */
|
|
|
|
for(i=0;i<nclistlength(root->tree->nodes);i++) {
|
|
|
|
CDFnode* node = (CDFnode*)nclistget(root->tree->nodes,i);
|
|
|
|
node->elided = 0;
|
|
|
|
if(node->nctype == NC_Grid || node->nctype == NC_Dataset)
|
|
|
|
node->elided = 1;
|
|
|
|
}
|
|
|
|
|
2011-11-14 12:20:19 +08:00
|
|
|
/* ensure all variables have an initial full name defined */
|
2011-04-18 02:56:10 +08:00
|
|
|
for(i=0;i<nclistlength(varnodes);i++) {
|
|
|
|
CDFnode* var = (CDFnode*)nclistget(varnodes,i);
|
|
|
|
nullfree(var->ncfullname);
|
2014-03-25 04:02:52 +08:00
|
|
|
var->ncfullname = makecdfpathstring(var,nccomm->cdf.separator);
|
2012-02-04 05:31:50 +08:00
|
|
|
#ifdef DEBUG2
|
|
|
|
fprintf(stderr,"var names: %s %s %s\n",
|
|
|
|
var->ocname,var->ncbasename,var->ncfullname);
|
|
|
|
#endif
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
2011-11-14 12:20:19 +08:00
|
|
|
|
|
|
|
/* unify all variables with same fullname and dimensions
|
|
|
|
basevar fields says: "for duplicate grid variables";
|
|
|
|
when does this happen?
|
|
|
|
*/
|
2011-04-18 02:56:10 +08:00
|
|
|
if(FLAGSET(nccomm->controls,NCF_NC3)) {
|
|
|
|
for(i=0;i<nclistlength(varnodes);i++) {
|
|
|
|
int match;
|
|
|
|
CDFnode* var = (CDFnode*)nclistget(varnodes,i);
|
|
|
|
for(j=0;j<i;j++) {
|
|
|
|
CDFnode* testnode = (CDFnode*)nclistget(varnodes,j);
|
|
|
|
match = 1;
|
|
|
|
if(testnode->array.basevar != NULL)
|
|
|
|
continue; /* already processed */
|
|
|
|
if(strcmp(var->ncfullname,testnode->ncfullname) != 0)
|
|
|
|
match = 0;
|
2011-11-14 12:20:19 +08:00
|
|
|
else if(nclistlength(testnode->array.dimsetall)
|
|
|
|
!= nclistlength(var->array.dimsetall))
|
2011-04-18 02:56:10 +08:00
|
|
|
match = 0;
|
2011-11-14 12:20:19 +08:00
|
|
|
else for(d=0;d<nclistlength(testnode->array.dimsetall);d++) {
|
|
|
|
CDFnode* vdim = (CDFnode*)nclistget(var->array.dimsetall,d);
|
|
|
|
CDFnode* tdim = (CDFnode*)nclistget(testnode->array.dimsetall,d);
|
2011-04-18 02:56:10 +08:00
|
|
|
if(vdim->dim.declsize != tdim->dim.declsize) {
|
|
|
|
match = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(match) {
|
|
|
|
testnode->array.basevar = var;
|
2011-11-14 12:20:19 +08:00
|
|
|
fprintf(stderr,"basevar invoked: %s\n",var->ncfullname);
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-04 05:31:50 +08:00
|
|
|
|
2011-04-18 02:56:10 +08:00
|
|
|
/* Finally, verify unique names */
|
|
|
|
for(i=0;i<nclistlength(varnodes);i++) {
|
|
|
|
CDFnode* var1 = (CDFnode*)nclistget(varnodes,i);
|
|
|
|
if(var1->array.basevar != NULL) continue;
|
|
|
|
for(j=0;j<i;j++) {
|
|
|
|
CDFnode* var2 = (CDFnode*)nclistget(varnodes,j);
|
|
|
|
if(var2->array.basevar != NULL) continue;
|
|
|
|
if(strcmp(var1->ncfullname,var2->ncfullname)==0) {
|
|
|
|
PANIC1("duplicate var names: %s",var1->ncfullname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-14 12:20:19 +08:00
|
|
|
/* locate and connect usable sequences and vars.
|
|
|
|
A sequence is usable iff:
|
|
|
|
1. it has a path from one of its subnodes to a leaf and that
|
|
|
|
path does not contain a sequence.
|
|
|
|
2. No parent container has dimensions.
|
|
|
|
*/
|
|
|
|
|
2011-04-18 02:56:10 +08:00
|
|
|
NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
sequencecheck(NCDAPCOMMON* nccomm)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
2014-03-25 04:02:52 +08:00
|
|
|
(void)sequencecheckr(nccomm->cdf.ddsroot,
|
2014-07-30 00:44:50 +08:00
|
|
|
nccomm->cdf.ddsroot->tree->varnodes,NULL);
|
2011-04-18 02:56:10 +08:00
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
sequencecheckr(CDFnode* node, NClist* vars, CDFnode* topseq)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
NCerror err = NC_NOERR;
|
|
|
|
int ok = 0;
|
2011-11-14 12:20:19 +08:00
|
|
|
if(topseq == NULL && nclistlength(node->array.dimset0) > 0) {
|
|
|
|
err = NC_EINVAL; /* This container has dimensions, so no sequence within it
|
|
|
|
can be usable */
|
2011-04-18 02:56:10 +08:00
|
|
|
} else if(node->nctype == NC_Sequence) {
|
2011-11-14 12:20:19 +08:00
|
|
|
/* Recursively walk the path for each subnode of this sequence node
|
|
|
|
looking for a path without any sequence */
|
2011-04-18 02:56:10 +08:00
|
|
|
for(i=0;i<nclistlength(node->subnodes);i++) {
|
|
|
|
CDFnode* sub = (CDFnode*)nclistget(node->subnodes,i);
|
2014-03-25 04:02:52 +08:00
|
|
|
err = sequencecheckr(sub,vars,node);
|
2011-04-18 02:56:10 +08:00
|
|
|
if(err == NC_NOERR) ok = 1; /* there is at least 1 usable var below */
|
|
|
|
}
|
|
|
|
if(topseq == NULL && ok == 1) {
|
2011-11-14 12:20:19 +08:00
|
|
|
/* this sequence is usable because it has scalar container
|
|
|
|
(by construction) and has a path to a leaf without an intermediate
|
|
|
|
sequence. */
|
2011-04-18 02:56:10 +08:00
|
|
|
err = NC_NOERR;
|
|
|
|
node->usesequence = 1;
|
|
|
|
} else {
|
2011-11-14 12:20:19 +08:00
|
|
|
/* this sequence is unusable because it has no path
|
|
|
|
to a leaf without an intermediate sequence. */
|
2011-04-18 02:56:10 +08:00
|
|
|
node->usesequence = 0;
|
|
|
|
err = NC_EINVAL;
|
|
|
|
}
|
2012-08-20 05:12:35 +08:00
|
|
|
} else if(nclistcontains(vars,(void*)node)) {
|
2011-11-14 12:20:19 +08:00
|
|
|
/* If we reach a leaf, then topseq is usable, so save it */
|
2011-04-18 02:56:10 +08:00
|
|
|
node->array.sequence = topseq;
|
2011-11-14 12:20:19 +08:00
|
|
|
} else { /* Some kind of non-sequence container node with no dimensions */
|
2011-04-18 02:56:10 +08:00
|
|
|
/* recursively compute usability */
|
|
|
|
for(i=0;i<nclistlength(node->subnodes);i++) {
|
|
|
|
CDFnode* sub = (CDFnode*)nclistget(node->subnodes,i);
|
2014-03-25 04:02:52 +08:00
|
|
|
err = sequencecheckr(sub,vars,topseq);
|
2011-04-18 02:56:10 +08:00
|
|
|
if(err == NC_NOERR) ok = 1;
|
|
|
|
}
|
|
|
|
err = (ok?NC_NOERR:NC_EINVAL);
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-02-26 12:31:06 +08:00
|
|
|
Originally, if one did a constraint on a Grid such that only
|
|
|
|
one array or map in the grid was returned, that element was
|
|
|
|
returned as a top level variable. This is incorrect because
|
|
|
|
it loses the Grid scope information.
|
|
|
|
|
|
|
|
Eventually, this behavior was changed so that such partial
|
|
|
|
grids are converted to structures where the structure name
|
|
|
|
is the grid name. This preserves the proper scoping.
|
|
|
|
However, it is still the case that some servers do the old
|
|
|
|
behavior.
|
|
|
|
|
2012-08-16 01:55:25 +08:00
|
|
|
The rules that most old-style servers appear to adhere to are these.
|
|
|
|
1. Asking for just a grid array or a single grid map
|
|
|
|
returns just the array not wrapped in a structure.
|
|
|
|
2. Asking for a subset of the fields (array plus map) of a grid
|
|
|
|
returns those fields wrapped in a structure.
|
|
|
|
3. However, there is an odd situation: asking for a grid array
|
|
|
|
plus any subset of maps that includes the last map in the grid
|
|
|
|
returns a malformed grid. This is clearly a bug.
|
|
|
|
|
|
|
|
For case 1, we insert a structure node so that case 1 is consistent
|
|
|
|
with case 2. Case 3 should cause an error with a malformed grid.
|
|
|
|
|
|
|
|
[Note: for some reason, this code has been difficult to get right;
|
|
|
|
I have rewritten 6 times and it probably is still not right.]
|
2013-02-26 12:31:06 +08:00
|
|
|
[2/25/2013 Sigh! Previous fixes have introducted another bug,
|
|
|
|
so now we fix the fix.]
|
2011-11-14 12:20:19 +08:00
|
|
|
|
|
|
|
Input is
|
|
|
|
(1) the root of the dds that needs to be re-gridded
|
|
|
|
(2) the full datadds tree that defines where the grids are.
|
|
|
|
(3) the projections that were used to produce (1) from (2).
|
2012-08-16 01:55:25 +08:00
|
|
|
|
2011-04-18 02:56:10 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
NCerror
|
2015-01-16 05:19:51 +08:00
|
|
|
restruct(NCDAPCOMMON* ncc, CDFnode* ddsroot, CDFnode* patternroot, NClist* projections)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
|
|
|
NCerror ncstat = NC_NOERR;
|
2013-02-26 12:31:06 +08:00
|
|
|
NClist* repairs = nclistnew();
|
2011-04-18 02:56:10 +08:00
|
|
|
|
2012-08-16 01:55:25 +08:00
|
|
|
/* The current restruct assumes that the ddsroot tree
|
2015-01-16 05:19:51 +08:00
|
|
|
has missing grids compared to the pattern.
|
2011-04-18 02:56:10 +08:00
|
|
|
It is also assumed that order of the nodes
|
2015-01-16 05:19:51 +08:00
|
|
|
in the ddsroot is the same as in the pattern.
|
2011-04-18 02:56:10 +08:00
|
|
|
*/
|
2013-08-14 23:47:11 +08:00
|
|
|
if(ddsroot->tree->restructed) {
|
|
|
|
nclistfree(repairs);
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
2011-04-18 02:56:10 +08:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2012-08-16 01:55:25 +08:00
|
|
|
fprintf(stderr,"restruct: ddsroot=%s\n",dumptree(ddsroot));
|
2015-01-16 05:19:51 +08:00
|
|
|
fprintf(stderr,"restruct: patternroot=%s\n",dumptree(patternroot));
|
2011-04-18 02:56:10 +08:00
|
|
|
#endif
|
|
|
|
|
2013-02-26 12:31:06 +08:00
|
|
|
/* Match roots */
|
2015-01-16 05:19:51 +08:00
|
|
|
if(!simplenodematch(ddsroot,patternroot))
|
2013-02-26 12:31:06 +08:00
|
|
|
ncstat = NC_EDATADDS;
|
2015-01-16 05:19:51 +08:00
|
|
|
else if(!restructr(ncc,ddsroot,patternroot,repairs))
|
2013-02-26 12:31:06 +08:00
|
|
|
ncstat = NC_EDATADDS;
|
|
|
|
else if(nclistlength(repairs) > 0) {
|
|
|
|
/* Do the repairs */
|
2014-01-25 04:26:00 +08:00
|
|
|
ncstat = repairgrids(ncc, repairs);
|
2013-02-26 12:31:06 +08:00
|
|
|
}
|
2013-04-24 05:50:07 +08:00
|
|
|
|
|
|
|
if(repairs)
|
|
|
|
nclistfree(repairs);
|
|
|
|
|
2012-08-16 01:55:25 +08:00
|
|
|
return THROW(ncstat);
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2012-08-16 01:55:25 +08:00
|
|
|
Locate nodes in the tree rooted at node
|
2015-01-16 05:19:51 +08:00
|
|
|
that correspond to a single grid field in the pattern
|
|
|
|
when the pattern is a grid.
|
2012-08-16 01:55:25 +08:00
|
|
|
Wrap that grid field in a synthesized structure.
|
2013-02-26 12:31:06 +08:00
|
|
|
|
|
|
|
The key thing to look for is the case where
|
|
|
|
we have an atomic variable that appear where
|
|
|
|
we expected a grid.
|
|
|
|
|
2011-04-18 02:56:10 +08:00
|
|
|
*/
|
2013-02-26 12:31:06 +08:00
|
|
|
|
|
|
|
static int
|
2015-01-16 05:19:51 +08:00
|
|
|
restructr(NCDAPCOMMON* ncc, CDFnode* dxdparent, CDFnode* patternparent, NClist* repairlist)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
2023-11-27 19:36:03 +08:00
|
|
|
size_t index, i, j, match;
|
2011-04-18 02:56:10 +08:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2012-08-16 01:55:25 +08:00
|
|
|
fprintf(stderr,"restruct: matched: %s -> %s\n",
|
2015-01-16 05:19:51 +08:00
|
|
|
ocfqn(dxdparent->ocnode),ocfqn(patternparent->ocnode));
|
2011-04-18 02:56:10 +08:00
|
|
|
#endif
|
2012-08-16 01:55:25 +08:00
|
|
|
|
|
|
|
/* walk each node child and locate its match
|
2015-01-16 05:19:51 +08:00
|
|
|
in the pattern's children; recurse on matches,
|
2013-02-26 12:31:06 +08:00
|
|
|
non-matches may be nodes needing wrapping.
|
2012-08-16 01:55:25 +08:00
|
|
|
*/
|
|
|
|
|
2014-02-06 08:05:33 +08:00
|
|
|
for(index=0;index<nclistlength(dxdparent->subnodes);index++) {
|
|
|
|
CDFnode* dxdsubnode = (CDFnode*)nclistget(dxdparent->subnodes,index);
|
2013-02-26 12:31:06 +08:00
|
|
|
CDFnode* matchnode = NULL;
|
|
|
|
|
2015-01-16 05:19:51 +08:00
|
|
|
/* Look for a matching pattern node with same ocname */
|
|
|
|
for(i=0;i<nclistlength(patternparent->subnodes);i++) {
|
|
|
|
CDFnode* patternsubnode = (CDFnode*)nclistget(patternparent->subnodes,i);
|
|
|
|
if(strcmp(dxdsubnode->ocname,patternsubnode->ocname) == 0) {
|
|
|
|
matchnode = patternsubnode;
|
2013-02-26 12:31:06 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-03-03 12:06:43 +08:00
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr,"restruct: candidate: %s -> %s\n",
|
2014-02-06 08:05:33 +08:00
|
|
|
ocfqn(dxdsubnode->ocnode),ocfqn(matchnode->ocnode));
|
2013-03-03 12:06:43 +08:00
|
|
|
#endif
|
2014-03-25 04:02:52 +08:00
|
|
|
if(simplenodematch(dxdsubnode,matchnode)) {
|
2013-02-26 12:31:06 +08:00
|
|
|
/* this subnode of the node matches the corresponding
|
2015-01-16 05:19:51 +08:00
|
|
|
node of the pattern, so it is ok =>
|
2013-02-26 12:31:06 +08:00
|
|
|
recurse looking for nested mis-matches
|
|
|
|
*/
|
2014-03-25 04:02:52 +08:00
|
|
|
if(!restructr(ncc,dxdsubnode,matchnode,repairlist))
|
2013-03-03 12:06:43 +08:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
/* If we do not have a direct match, then we need to look
|
|
|
|
at all the grids to see if this node matches a field
|
|
|
|
in one of the grids
|
|
|
|
*/
|
2015-01-16 05:19:51 +08:00
|
|
|
for(match=0,i=0;!match && i<nclistlength(patternparent->subnodes);i++) {
|
|
|
|
CDFnode* subtemp = (CDFnode*)nclistget(patternparent->subnodes,i);
|
2014-02-06 08:05:33 +08:00
|
|
|
if(subtemp->nctype == NC_Grid) {
|
|
|
|
/* look inside */
|
2015-01-16 05:19:51 +08:00
|
|
|
for(j=0;j<nclistlength(patternparent->subnodes);j++) {
|
2013-03-03 12:06:43 +08:00
|
|
|
CDFnode* gridfield = (CDFnode*)nclistget(subtemp->subnodes,j);
|
2014-03-25 04:02:52 +08:00
|
|
|
if(simplenodematch(dxdsubnode,gridfield)) {
|
2013-03-03 12:06:43 +08:00
|
|
|
/* We need to do this repair */
|
2014-02-06 08:05:33 +08:00
|
|
|
nclistpush(repairlist,(void*)dxdsubnode);
|
2013-03-03 12:06:43 +08:00
|
|
|
nclistpush(repairlist,(void*)gridfield);
|
|
|
|
match = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!match) return 0; /* we failed */
|
2013-02-26 12:31:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1; /* we matched everything at this level */
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
|
2015-01-16 05:19:51 +08:00
|
|
|
/* Wrap the node wrt the pattern grid or pattern struct */
|
2012-08-16 01:55:25 +08:00
|
|
|
|
2013-02-26 12:31:06 +08:00
|
|
|
static NCerror
|
2014-01-25 04:26:00 +08:00
|
|
|
repairgrids(NCDAPCOMMON* ncc, NClist* repairlist)
|
2013-02-26 12:31:06 +08:00
|
|
|
{
|
|
|
|
NCerror ncstat = NC_NOERR;
|
2023-11-27 19:36:03 +08:00
|
|
|
size_t i;
|
2013-02-26 12:31:06 +08:00
|
|
|
assert(nclistlength(repairlist) % 2 == 0);
|
|
|
|
for(i=0;i<nclistlength(repairlist);i+=2) {
|
|
|
|
CDFnode* node = (CDFnode*)nclistget(repairlist,i);
|
2015-01-16 05:19:51 +08:00
|
|
|
CDFnode* pattern = (CDFnode*)nclistget(repairlist,i+1);
|
2013-02-26 12:31:06 +08:00
|
|
|
int index = findin(node->container,node);
|
2015-01-16 05:19:51 +08:00
|
|
|
int tindex = findin(pattern->container,pattern);
|
2014-03-25 04:02:52 +08:00
|
|
|
ncstat = structwrap(ncc, node,node->container,index,
|
2015-01-16 05:19:51 +08:00
|
|
|
pattern->container,tindex);
|
2013-03-03 12:06:43 +08:00
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr,"repairgrids: %s -> %s\n",
|
2015-01-16 05:19:51 +08:00
|
|
|
ocfqn(node->ocnode),ocfqn(pattern->ocnode));
|
2013-03-03 12:06:43 +08:00
|
|
|
#endif
|
|
|
|
|
2013-02-26 12:31:06 +08:00
|
|
|
}
|
|
|
|
return ncstat;
|
|
|
|
}
|
|
|
|
|
2011-04-18 02:56:10 +08:00
|
|
|
static NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
structwrap(NCDAPCOMMON* ncc, CDFnode* node, CDFnode* parent, int parentindex,
|
2015-01-16 05:19:51 +08:00
|
|
|
CDFnode* patterngrid, int gridindex)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
2012-08-16 01:55:25 +08:00
|
|
|
CDFnode* newstruct;
|
|
|
|
|
2015-01-16 05:19:51 +08:00
|
|
|
ASSERT((patterngrid->nctype == NC_Grid));
|
|
|
|
newstruct = makenewstruct(ncc, node,patterngrid);
|
2013-02-26 12:31:06 +08:00
|
|
|
if(newstruct == NULL) {return THROW(NC_ENOMEM);}
|
|
|
|
|
2012-08-16 01:55:25 +08:00
|
|
|
/* replace the node with the new structure
|
|
|
|
in the parent's list of children*/
|
2013-02-26 12:31:06 +08:00
|
|
|
nclistset(parent->subnodes,parentindex,(void*)newstruct);
|
|
|
|
|
2012-08-16 01:55:25 +08:00
|
|
|
/* Update the list of all nodes in the tree */
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(node->root->tree->nodes,(void*)newstruct);
|
2013-02-26 12:31:06 +08:00
|
|
|
return NC_NOERR;
|
|
|
|
}
|
2012-08-16 01:55:25 +08:00
|
|
|
|
2013-02-26 12:31:06 +08:00
|
|
|
static int
|
|
|
|
findin(CDFnode* parent, CDFnode* child)
|
|
|
|
{
|
2023-11-27 19:36:03 +08:00
|
|
|
size_t i;
|
2013-02-26 12:31:06 +08:00
|
|
|
NClist* subnodes = parent->subnodes;
|
|
|
|
for(i=0;i<nclistlength(subnodes);i++) {
|
|
|
|
if(nclistget(subnodes,i) == child)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
|
2012-08-16 01:55:25 +08:00
|
|
|
/* Create a structure to surround projected grid array or map;
|
|
|
|
this occurs because some servers (that means you ferret and you thredds!)
|
|
|
|
do not adhere to the DAP2 protocol spec.
|
|
|
|
*/
|
2014-07-30 00:44:50 +08:00
|
|
|
|
2011-04-18 02:56:10 +08:00
|
|
|
static CDFnode*
|
2015-01-16 05:19:51 +08:00
|
|
|
makenewstruct(NCDAPCOMMON* ncc, CDFnode* node, CDFnode* patternnode)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
2015-01-16 05:19:51 +08:00
|
|
|
CDFnode* newstruct = makecdfnode(ncc,patternnode->ocname,OC_Structure,
|
|
|
|
patternnode->ocnode, node->container);
|
2012-08-16 01:55:25 +08:00
|
|
|
if(newstruct == NULL) return NULL;
|
2012-09-21 00:31:31 +08:00
|
|
|
newstruct->nc_virtual = 1;
|
2015-01-16 05:19:51 +08:00
|
|
|
newstruct->ncbasename = nulldup(patternnode->ncbasename);
|
2012-08-16 01:55:25 +08:00
|
|
|
newstruct->subnodes = nclistnew();
|
2015-01-16 05:19:51 +08:00
|
|
|
newstruct->pattern = patternnode;
|
2012-08-16 01:55:25 +08:00
|
|
|
node->container = newstruct;
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(newstruct->subnodes,(void*)node);
|
2012-08-16 01:55:25 +08:00
|
|
|
return newstruct;
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
|
2011-09-16 00:57:16 +08:00
|
|
|
/**
|
|
|
|
Make the constrained dds nodes (root)
|
|
|
|
point to the corresponding unconstrained
|
2011-11-14 12:20:19 +08:00
|
|
|
dds nodes (fullroot).
|
2011-09-16 00:57:16 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
mapnodes(CDFnode* root, CDFnode* fullroot)
|
2011-09-16 00:57:16 +08:00
|
|
|
{
|
|
|
|
NCerror ncstat = NC_NOERR;
|
|
|
|
ASSERT(root != NULL && fullroot != NULL);
|
2014-03-25 04:02:52 +08:00
|
|
|
if(!simplenodematch(root,fullroot))
|
2011-09-16 00:57:16 +08:00
|
|
|
{THROWCHK(ncstat=NC_EINVAL); goto done;}
|
|
|
|
/* clear out old associations*/
|
2014-03-25 04:02:52 +08:00
|
|
|
unmap(root);
|
|
|
|
ncstat = mapnodesr(root,fullroot,0);
|
2011-09-16 00:57:16 +08:00
|
|
|
done:
|
|
|
|
return ncstat;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
mapnodesr(CDFnode* connode, CDFnode* fullnode, int depth)
|
2011-09-16 00:57:16 +08:00
|
|
|
{
|
|
|
|
unsigned int i,j;
|
|
|
|
NCerror ncstat = NC_NOERR;
|
|
|
|
|
2014-03-25 04:02:52 +08:00
|
|
|
ASSERT((simplenodematch(connode,fullnode)));
|
2014-07-30 00:44:50 +08:00
|
|
|
|
2011-09-16 00:57:16 +08:00
|
|
|
#ifdef DEBUG
|
2012-11-22 07:57:42 +08:00
|
|
|
{
|
2014-03-25 04:02:52 +08:00
|
|
|
char* path1 = makecdfpathstring(fullnode,".");
|
|
|
|
char* path2 = makecdfpathstring(connode,".");
|
2012-01-30 02:56:29 +08:00
|
|
|
fprintf(stderr,"mapnode: %s->%s\n",path1,path2);
|
|
|
|
nullfree(path1); nullfree(path2);
|
2012-11-22 07:57:42 +08:00
|
|
|
}
|
2011-09-16 00:57:16 +08:00
|
|
|
#endif
|
|
|
|
|
2011-11-14 12:20:19 +08:00
|
|
|
/* Map node */
|
|
|
|
mapfcn(connode,fullnode);
|
2011-09-16 00:57:16 +08:00
|
|
|
|
2012-11-22 07:57:42 +08:00
|
|
|
#if 0
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i=0;i<nclistlength(fullnode->subnodes);i++) {
|
|
|
|
CDFnode* n = (CDFnode*)nclistget(fullnode->subnodes,i);
|
|
|
|
fprintf(stderr,"fullnode.subnode[%d]: (%d) %s\n",i,n->nctype,n->ocname);
|
|
|
|
}
|
|
|
|
for(i=0;i<nclistlength(connode->subnodes);i++) {
|
|
|
|
CDFnode* n = (CDFnode*)nclistget(connode->subnodes,i);
|
|
|
|
fprintf(stderr,"connode.subnode[%d]: (%d) %s\n",i,n->nctype,n->ocname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-09-16 00:57:16 +08:00
|
|
|
/* Try to match connode subnodes against fullnode subnodes */
|
|
|
|
ASSERT(nclistlength(connode->subnodes) <= nclistlength(fullnode->subnodes));
|
|
|
|
|
|
|
|
for(i=0;i<nclistlength(connode->subnodes);i++) {
|
|
|
|
CDFnode* consubnode = (CDFnode*)nclistget(connode->subnodes,i);
|
|
|
|
/* Search full subnodes for a matching subnode from con */
|
|
|
|
for(j=0;j<nclistlength(fullnode->subnodes);j++) {
|
|
|
|
CDFnode* fullsubnode = (CDFnode*)nclistget(fullnode->subnodes,j);
|
2014-03-25 04:02:52 +08:00
|
|
|
if(simplenodematch(fullsubnode,consubnode)) {
|
|
|
|
ncstat = mapnodesr(consubnode,fullsubnode,depth+1);
|
2011-09-16 00:57:16 +08:00
|
|
|
if(ncstat) goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
return THROW(ncstat);
|
|
|
|
}
|
|
|
|
|
2011-11-14 12:20:19 +08:00
|
|
|
|
|
|
|
/* The specific actions of a map are defined
|
|
|
|
by this function.
|
|
|
|
*/
|
|
|
|
static NCerror
|
|
|
|
mapfcn(CDFnode* dstnode, CDFnode* srcnode)
|
|
|
|
{
|
|
|
|
/* Mark node as having been mapped */
|
|
|
|
dstnode->basenode = srcnode;
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
2011-09-16 00:57:16 +08:00
|
|
|
void
|
2014-03-25 04:02:52 +08:00
|
|
|
unmap(CDFnode* root)
|
2011-09-16 00:57:16 +08:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
CDFtree* tree = root->tree;
|
|
|
|
for(i=0;i<nclistlength(tree->nodes);i++) {
|
|
|
|
CDFnode* node = (CDFnode*)nclistget(tree->nodes,i);
|
|
|
|
node->basenode = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-30 00:44:50 +08:00
|
|
|
/*
|
2012-02-04 05:31:50 +08:00
|
|
|
Move dimension data from basenodes to nodes
|
2011-04-18 02:56:10 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
dimimprint(NCDAPCOMMON* nccomm)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
|
|
|
NCerror ncstat = NC_NOERR;
|
2011-11-14 12:20:19 +08:00
|
|
|
NClist* allnodes;
|
2023-11-27 19:36:03 +08:00
|
|
|
size_t i,j;
|
2011-11-14 12:20:19 +08:00
|
|
|
CDFnode* basenode;
|
2011-04-18 02:56:10 +08:00
|
|
|
|
2011-11-14 12:20:19 +08:00
|
|
|
allnodes = nccomm->cdf.ddsroot->tree->nodes;
|
|
|
|
for(i=0;i<nclistlength(allnodes);i++) {
|
|
|
|
CDFnode* node = (CDFnode*)nclistget(allnodes,i);
|
2023-11-27 19:36:03 +08:00
|
|
|
size_t noderank, baserank;
|
2011-11-14 12:20:19 +08:00
|
|
|
/* Do dimension imprinting */
|
|
|
|
basenode = node->basenode;
|
|
|
|
if(basenode == NULL) continue;
|
|
|
|
noderank = nclistlength(node->array.dimset0);
|
|
|
|
baserank = nclistlength(basenode->array.dimset0);
|
|
|
|
if(noderank == 0) continue;
|
|
|
|
ASSERT(noderank == baserank);
|
|
|
|
#ifdef DEBUG
|
2023-11-27 19:36:03 +08:00
|
|
|
fprintf(stderr,"dimimprint %s/%zu -> %s/%zu\n",
|
2014-03-25 04:02:52 +08:00
|
|
|
makecdfpathstring(basenode,"."),
|
2011-11-14 12:20:19 +08:00
|
|
|
noderank,
|
2014-03-25 04:02:52 +08:00
|
|
|
makecdfpathstring(node,"."),
|
2011-11-14 12:20:19 +08:00
|
|
|
baserank);
|
|
|
|
#endif
|
|
|
|
for(j=0;j<noderank;j++) {
|
|
|
|
CDFnode* dim = (CDFnode*)nclistget(node->array.dimset0,j);
|
|
|
|
CDFnode* basedim = (CDFnode*)nclistget(basenode->array.dimset0,j);
|
2014-07-30 00:44:50 +08:00
|
|
|
dim->dim.declsize0 = basedim->dim.declsize;
|
2011-11-14 12:20:19 +08:00
|
|
|
#ifdef DEBUG
|
2012-02-04 05:31:50 +08:00
|
|
|
fprintf(stderr,"dimimprint: %d: %lu -> %lu\n",i,basedim->dim.declsize,dim->dim.declsize0);
|
2011-11-14 12:20:19 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2011-04-18 02:56:10 +08:00
|
|
|
return ncstat;
|
|
|
|
}
|
|
|
|
|
2011-11-14 12:20:19 +08:00
|
|
|
static CDFnode*
|
|
|
|
clonedim(NCDAPCOMMON* nccomm, CDFnode* dim, CDFnode* var)
|
|
|
|
{
|
|
|
|
CDFnode* clone;
|
2014-03-25 04:02:52 +08:00
|
|
|
clone = makecdfnode(nccomm,dim->ocname,OC_Dimension,
|
2012-08-01 04:34:13 +08:00
|
|
|
NULL,dim->container);
|
2011-11-14 12:20:19 +08:00
|
|
|
/* Record its existence */
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(dim->container->root->tree->nodes,(void*)clone);
|
2011-11-14 12:20:19 +08:00
|
|
|
clone->dim = dim->dim; /* copy most everything */
|
|
|
|
clone->dim.dimflags |= CDFDIMCLONE;
|
|
|
|
clone->dim.array = var;
|
|
|
|
return clone;
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
|
2011-11-14 12:20:19 +08:00
|
|
|
static NClist*
|
2014-03-25 04:02:52 +08:00
|
|
|
clonedimset(NCDAPCOMMON* nccomm, NClist* dimset, CDFnode* var)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
2014-02-06 08:05:33 +08:00
|
|
|
NClist* result = NULL;
|
2023-11-27 19:36:03 +08:00
|
|
|
size_t i;
|
2014-02-20 22:24:55 +08:00
|
|
|
|
|
|
|
for(i=0;i<nclistlength(dimset);i++) {
|
|
|
|
CDFnode *dim = NULL;
|
|
|
|
if(result == NULL)
|
|
|
|
result = nclistnew();
|
|
|
|
|
|
|
|
dim = (CDFnode*)nclistget(dimset,i);
|
|
|
|
nclistpush(result,(void*)clonedim(nccomm,dim,var));
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
2011-11-14 12:20:19 +08:00
|
|
|
return result;
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
|
2014-02-06 08:05:33 +08:00
|
|
|
/* Define the dimsetplus list for a node = dimset0+pseudo dims */
|
2011-11-14 12:20:19 +08:00
|
|
|
static NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
definedimsetplus(NCDAPCOMMON* nccomm/*notused*/, CDFnode* node)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
2011-11-14 12:20:19 +08:00
|
|
|
int ncstat = NC_NOERR;
|
2014-02-06 08:05:33 +08:00
|
|
|
NClist* dimset = NULL;
|
|
|
|
CDFnode* clone = NULL;
|
2011-11-14 12:20:19 +08:00
|
|
|
|
2014-02-06 08:05:33 +08:00
|
|
|
if(node->array.dimset0 != NULL)
|
|
|
|
/* copy the dimset0 into dimset */
|
This PR adds EXPERIMENTAL support for accessing data in the
cloud using a variant of the Zarr protocol and storage
format. This enhancement is generically referred to as "NCZarr".
The data model supported by NCZarr is netcdf-4 minus the user-defined
types and the String type. In this sense it is similar to the CDF-5
data model.
More detailed information about enabling and using NCZarr is
described in the document NUG/nczarr.md and in a
[Unidata Developer's blog entry](https://www.unidata.ucar.edu/blogs/developer/en/entry/overview-of-zarr-support-in).
WARNING: this code has had limited testing, so do use this version
for production work. Also, performance improvements are ongoing.
Note especially the following platform matrix of successful tests:
Platform | Build System | S3 support
------------------------------------
Linux+gcc | Automake | yes
Linux+gcc | CMake | yes
Visual Studio | CMake | no
Additionally, and as a consequence of the addition of NCZarr,
major changes have been made to the Filter API. NOTE: NCZarr
does not yet support filters, but these changes are enablers for
that support in the future. Note that it is possible
(probable?) that there will be some accidental reversions if the
changes here did not correctly mimic the existing filter testing.
In any case, previously filter ids and parameters were of type
unsigned int. In order to support the more general zarr filter
model, this was all converted to char*. The old HDF5-specific,
unsigned int operations are still supported but they are
wrappers around the new, char* based nc_filterx_XXX functions.
This entailed at least the following changes:
1. Added the files libdispatch/dfilterx.c and include/ncfilter.h
2. Some filterx utilities have been moved to libdispatch/daux.c
3. A new entry, "filter_actions" was added to the NCDispatch table
and the version bumped.
4. An overly complex set of structs was created to support funnelling
all of the filterx operations thru a single dispatch
"filter_actions" entry.
5. Move common code to from libhdf5 to libsrc4 so that it is accessible
to nczarr.
Changes directly related to Zarr:
1. Modified CMakeList.txt and configure.ac to support both C and C++
-- this is in support of S3 support via the awd-sdk libraries.
2. Define a size64_t type to support nczarr.
3. More reworking of libdispatch/dinfermodel.c to
support zarr and to regularize the structure of the fragments
section of a URL.
Changes not directly related to Zarr:
1. Make client-side filter registration be conditional, with default off.
2. Hack include/nc4internal.h to make some flags added by Ed be unique:
e.g. NC_CREAT, NC_INDEF, etc.
3. cleanup include/nchttp.h and libdispatch/dhttp.c.
4. Misc. changes to support compiling under Visual Studio including:
* Better testing under windows for dirent.h and opendir and closedir.
5. Misc. changes to the oc2 code to support various libcurl CURLOPT flags
and to centralize error reporting.
6. By default, suppress the vlen tests that have unfixed memory leaks; add option to enable them.
7. Make part of the nc_test/test_byterange.sh test be contingent on remotetest.unidata.ucar.edu being accessible.
Changes Left TO-DO:
1. fix provenance code, it is too HDF5 specific.
2020-06-29 08:02:47 +08:00
|
|
|
dimset = nclistclone(node->array.dimset0, 0);
|
2011-11-14 12:20:19 +08:00
|
|
|
/* Insert the sequence or string dims */
|
|
|
|
if(node->array.stringdim != NULL) {
|
2014-02-06 08:05:33 +08:00
|
|
|
if(dimset == NULL) dimset = nclistnew();
|
2011-11-14 12:20:19 +08:00
|
|
|
clone = node->array.stringdim;
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(dimset,(void*)clone);
|
2011-11-14 12:20:19 +08:00
|
|
|
}
|
|
|
|
if(node->array.seqdim != NULL) {
|
2014-02-06 08:05:33 +08:00
|
|
|
if(dimset == NULL) dimset = nclistnew();
|
2011-11-14 12:20:19 +08:00
|
|
|
clone = node->array.seqdim;
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(dimset,(void*)clone);
|
2011-11-14 12:20:19 +08:00
|
|
|
}
|
|
|
|
node->array.dimsetplus = dimset;
|
|
|
|
return ncstat;
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
|
2014-02-06 08:05:33 +08:00
|
|
|
/* Define the dimsetall list for a node = */
|
2011-11-14 12:20:19 +08:00
|
|
|
static NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
definedimsetall(NCDAPCOMMON* nccomm/*notused*/, CDFnode* node)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
2023-11-27 19:36:03 +08:00
|
|
|
size_t i;
|
2011-11-14 12:20:19 +08:00
|
|
|
int ncstat = NC_NOERR;
|
2014-02-06 08:05:33 +08:00
|
|
|
NClist* dimsetall = NULL;
|
2011-11-14 12:20:19 +08:00
|
|
|
|
|
|
|
if(node->container != NULL) {
|
|
|
|
/* We need to clone the parent dimensions because we will be assigning
|
|
|
|
indices vis-a-vis this variable */
|
2014-03-25 04:02:52 +08:00
|
|
|
dimsetall = clonedimset(nccomm,node->container->array.dimsetall,node);
|
2014-02-06 08:05:33 +08:00
|
|
|
}
|
|
|
|
/* append dimsetplus; */
|
2011-11-14 12:20:19 +08:00
|
|
|
for(i=0;i<nclistlength(node->array.dimsetplus);i++) {
|
2014-02-12 06:49:34 +08:00
|
|
|
CDFnode* clone = NULL;
|
2014-02-06 08:05:33 +08:00
|
|
|
if(dimsetall == NULL) dimsetall = nclistnew();
|
2014-02-12 06:49:34 +08:00
|
|
|
clone = (CDFnode*)nclistget(node->array.dimsetplus,i);
|
|
|
|
nclistpush(dimsetall,(void*)clone);
|
2011-11-14 12:20:19 +08:00
|
|
|
}
|
|
|
|
node->array.dimsetall = dimsetall;
|
|
|
|
#ifdef DEBUG1
|
2013-02-26 12:31:06 +08:00
|
|
|
fprintf(stderr,"dimsetall: |%s|=%d\n",node->ocname,(int)nclistlength(dimsetall));
|
2011-11-14 12:20:19 +08:00
|
|
|
#endif
|
|
|
|
return ncstat;
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
|
2014-02-06 08:05:33 +08:00
|
|
|
/* Define the dimsettrans list for a single node */
|
2013-03-03 12:06:43 +08:00
|
|
|
static NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
definetransdimset(NCDAPCOMMON* nccomm/*notused*/, CDFnode* node)
|
2013-03-03 12:06:43 +08:00
|
|
|
{
|
2023-11-27 19:36:03 +08:00
|
|
|
size_t i;
|
2013-03-03 12:06:43 +08:00
|
|
|
int ncstat = NC_NOERR;
|
2014-02-06 08:05:33 +08:00
|
|
|
NClist* dimsettrans = NULL;
|
2013-03-03 12:06:43 +08:00
|
|
|
|
|
|
|
#ifdef DEBUG1
|
2014-02-06 08:05:33 +08:00
|
|
|
fprintf(stderr,"dimsettrans3: node=%s/%d\n",node->ocname,nclistlength(node->array.dimset0));
|
2013-03-03 12:06:43 +08:00
|
|
|
#endif
|
2014-02-06 08:05:33 +08:00
|
|
|
if(node->container != NULL) {
|
2013-03-03 12:06:43 +08:00
|
|
|
/* We need to clone the parent dimensions because we will be assigning
|
|
|
|
indices vis-a-vis this variable */
|
2014-03-25 04:02:52 +08:00
|
|
|
dimsettrans = clonedimset(nccomm,node->container->array.dimsettrans,node);
|
2014-02-06 08:05:33 +08:00
|
|
|
}
|
|
|
|
/* concat parent dimset0 and dimset;*/
|
2018-05-19 10:28:51 +08:00
|
|
|
if(dimsettrans == NULL)
|
|
|
|
dimsettrans = nclistnew();
|
2013-03-03 12:06:43 +08:00
|
|
|
for(i=0;i<nclistlength(node->array.dimset0);i++) {
|
2018-05-19 10:28:51 +08:00
|
|
|
CDFnode* clone = NULL;
|
|
|
|
clone = (CDFnode*)nclistget(node->array.dimset0,i);
|
2013-03-03 12:06:43 +08:00
|
|
|
nclistpush(dimsettrans,(void*)clone);
|
|
|
|
}
|
|
|
|
node->array.dimsettrans = dimsettrans;
|
2018-05-19 10:28:51 +08:00
|
|
|
dimsettrans = NULL;
|
2013-03-03 12:06:43 +08:00
|
|
|
#ifdef DEBUG1
|
|
|
|
fprintf(stderr,"dimsettrans: |%s|=%d\n",node->ocname,(int)nclistlength(dimsettrans));
|
|
|
|
#endif
|
|
|
|
return ncstat;
|
|
|
|
}
|
|
|
|
|
2014-02-06 08:05:33 +08:00
|
|
|
/*
|
|
|
|
Recursively define the transitive closure of dimensions
|
|
|
|
(dimsettrans) based on the original dimension set (dimset0):
|
2011-11-14 12:20:19 +08:00
|
|
|
*/
|
2014-02-06 08:05:33 +08:00
|
|
|
|
2011-04-18 02:56:10 +08:00
|
|
|
NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
definedimsettrans(NCDAPCOMMON* nccomm, CDFtree* tree)
|
2014-02-06 08:05:33 +08:00
|
|
|
{
|
|
|
|
/* recursively walk the tree */
|
2014-03-25 04:02:52 +08:00
|
|
|
definedimsettransR(nccomm, tree->root);
|
2014-02-06 08:05:33 +08:00
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Recursive helper for definedimsettrans3
|
|
|
|
*/
|
|
|
|
static NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
definedimsettransR(NCDAPCOMMON* nccomm, CDFnode* node)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
2023-11-27 19:36:03 +08:00
|
|
|
size_t i;
|
2011-11-14 12:20:19 +08:00
|
|
|
int ncstat = NC_NOERR;
|
|
|
|
|
2014-03-25 04:02:52 +08:00
|
|
|
definetransdimset(nccomm,node);
|
2014-02-06 08:05:33 +08:00
|
|
|
/* recurse */
|
|
|
|
for(i=0;i<nclistlength(node->subnodes);i++) {
|
|
|
|
CDFnode* subnode = (CDFnode*)nclistget(node->subnodes,i);
|
|
|
|
if(subnode->nctype == NC_Dimension) continue; /*ignore*/
|
|
|
|
ASSERT((subnode->array.dimsettrans == NULL));
|
|
|
|
ASSERT((subnode->array.dimsetplus == NULL));
|
|
|
|
ASSERT((subnode->array.dimsetall == NULL));
|
2014-03-25 04:02:52 +08:00
|
|
|
ncstat = definedimsettransR(nccomm,subnode);
|
2014-02-06 08:05:33 +08:00
|
|
|
if(ncstat != NC_NOERR)
|
|
|
|
break;
|
2011-11-14 12:20:19 +08:00
|
|
|
}
|
2014-02-06 08:05:33 +08:00
|
|
|
return ncstat;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Recursively define two dimension sets for each structural node
|
|
|
|
based on the original dimension set (dimset0):
|
|
|
|
1. dimsetplus = dimset0+pseudo-dimensions (string,sequence).
|
|
|
|
2. dimsetall = parent-dimsetall + dimsetplus
|
|
|
|
*/
|
|
|
|
|
|
|
|
NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
definedimsets(NCDAPCOMMON* nccomm, CDFtree* tree)
|
2014-02-06 08:05:33 +08:00
|
|
|
{
|
|
|
|
/* recursively walk the tree */
|
2014-03-25 04:02:52 +08:00
|
|
|
definedimsetsR(nccomm, tree->root);
|
2011-04-18 02:56:10 +08:00
|
|
|
return NC_NOERR;
|
|
|
|
}
|
2011-11-14 12:20:19 +08:00
|
|
|
|
2014-02-06 08:05:33 +08:00
|
|
|
/*
|
|
|
|
Recursive helper
|
|
|
|
*/
|
|
|
|
static NCerror
|
2014-03-25 04:02:52 +08:00
|
|
|
definedimsetsR(NCDAPCOMMON* nccomm, CDFnode* node)
|
2014-02-06 08:05:33 +08:00
|
|
|
{
|
2023-11-27 19:36:03 +08:00
|
|
|
size_t i;
|
2014-02-06 08:05:33 +08:00
|
|
|
int ncstat = NC_NOERR;
|
|
|
|
|
2014-03-25 04:02:52 +08:00
|
|
|
definedimsetplus(nccomm,node);
|
|
|
|
definedimsetall(nccomm,node);
|
2014-02-06 08:05:33 +08:00
|
|
|
/* recurse */
|
|
|
|
for(i=0;i<nclistlength(node->subnodes);i++) {
|
|
|
|
CDFnode* subnode = (CDFnode*)nclistget(node->subnodes,i);
|
|
|
|
if(subnode->nctype == NC_Dimension) continue; /*ignore*/
|
|
|
|
ASSERT((subnode->array.dimsettrans == NULL));
|
|
|
|
ASSERT((subnode->array.dimsetplus == NULL));
|
|
|
|
ASSERT((subnode->array.dimsetall == NULL));
|
2014-03-25 04:02:52 +08:00
|
|
|
ncstat = definedimsetsR(nccomm,subnode);
|
2014-02-06 08:05:33 +08:00
|
|
|
if(ncstat != NC_NOERR)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ncstat;
|
|
|
|
}
|
|
|
|
|
2014-03-25 04:02:52 +08:00
|
|
|
CDFnode*
|
|
|
|
makecdfnode(NCDAPCOMMON* nccomm, char* ocname, OCtype octype,
|
|
|
|
/*optional*/ OCddsnode ocnode, CDFnode* container)
|
|
|
|
{
|
|
|
|
CDFnode* node;
|
|
|
|
assert(nccomm != NULL);
|
|
|
|
node = (CDFnode*)calloc(1,sizeof(CDFnode));
|
|
|
|
if(node == NULL) return (CDFnode*)NULL;
|
|
|
|
|
|
|
|
node->ocname = NULL;
|
|
|
|
if(ocname) {
|
|
|
|
size_t len = strlen(ocname);
|
|
|
|
if(len >= NC_MAX_NAME) len = NC_MAX_NAME-1;
|
|
|
|
node->ocname = (char*)malloc(len+1);
|
|
|
|
if(node->ocname == NULL) { nullfree(node); return NULL;}
|
|
|
|
memcpy(node->ocname,ocname,len);
|
|
|
|
node->ocname[len] = '\0';
|
|
|
|
}
|
|
|
|
node->nctype = octypetonc(octype);
|
|
|
|
node->ocnode = ocnode;
|
|
|
|
node->subnodes = nclistnew();
|
|
|
|
node->container = container;
|
|
|
|
if(ocnode != NULL) {
|
|
|
|
oc_dds_atomictype(nccomm->oc.conn,ocnode,&octype);
|
|
|
|
node->etype = octypetonc(octype);
|
|
|
|
}
|
|
|
|
if(container != NULL)
|
|
|
|
node->root = container->root;
|
|
|
|
else if(node->nctype == NC_Dataset)
|
|
|
|
node->root = node;
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given an OCnode tree, mimic it as a CDFnode tree;
|
|
|
|
Add DAS attributes if DAS is available. Accumulate set
|
|
|
|
of all nodes in preorder.
|
|
|
|
*/
|
|
|
|
NCerror
|
|
|
|
buildcdftree(NCDAPCOMMON* nccomm, OCddsnode ocroot, OCdxd occlass, CDFnode** cdfrootp)
|
|
|
|
{
|
|
|
|
CDFnode* root = NULL;
|
|
|
|
CDFtree* tree = (CDFtree*)calloc(1,sizeof(CDFtree));
|
|
|
|
NCerror err = NC_NOERR;
|
2014-07-30 00:44:50 +08:00
|
|
|
if(!tree)
|
|
|
|
return OC_ENOMEM;
|
|
|
|
|
2014-03-25 04:02:52 +08:00
|
|
|
tree->ocroot = ocroot;
|
|
|
|
tree->nodes = nclistnew();
|
|
|
|
tree->occlass = occlass;
|
|
|
|
tree->owner = nccomm;
|
|
|
|
|
|
|
|
err = buildcdftreer(nccomm,ocroot,NULL,tree,&root);
|
|
|
|
if(!err) {
|
|
|
|
if(occlass != OCDAS)
|
|
|
|
fixnodes(nccomm,tree->nodes);
|
|
|
|
if(cdfrootp) *cdfrootp = root;
|
|
|
|
}
|
|
|
|
return err;
|
2014-07-30 00:44:50 +08:00
|
|
|
}
|
2014-03-25 04:02:52 +08:00
|
|
|
|
|
|
|
static NCerror
|
|
|
|
buildcdftreer(NCDAPCOMMON* nccomm, OCddsnode ocnode, CDFnode* container,
|
|
|
|
CDFtree* tree, CDFnode** cdfnodep)
|
|
|
|
{
|
|
|
|
size_t i,ocrank,ocnsubnodes;
|
|
|
|
OCtype octype;
|
|
|
|
OCtype ocatomtype;
|
|
|
|
char* ocname = NULL;
|
|
|
|
NCerror ncerr = NC_NOERR;
|
2014-03-29 07:11:26 +08:00
|
|
|
CDFnode* cdfnode = NULL;
|
2014-03-25 04:02:52 +08:00
|
|
|
|
|
|
|
oc_dds_class(nccomm->oc.conn,ocnode,&octype);
|
|
|
|
if(octype == OC_Atomic)
|
|
|
|
oc_dds_atomictype(nccomm->oc.conn,ocnode,&ocatomtype);
|
|
|
|
else
|
|
|
|
ocatomtype = OC_NAT;
|
|
|
|
oc_dds_name(nccomm->oc.conn,ocnode,&ocname);
|
|
|
|
oc_dds_rank(nccomm->oc.conn,ocnode,&ocrank);
|
|
|
|
oc_dds_nsubnodes(nccomm->oc.conn,ocnode,&ocnsubnodes);
|
|
|
|
|
|
|
|
#ifdef DEBUG1
|
|
|
|
if(ocatomtype == OC_NAT)
|
|
|
|
fprintf(stderr,"buildcdftree: connect: %s %s\n",oc_typetostring(octype),ocname);
|
|
|
|
else
|
|
|
|
fprintf(stderr,"buildcdftree: connect: %s %s\n",oc_typetostring(ocatomtype),ocname);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (octype) {
|
|
|
|
case OC_Dataset:
|
|
|
|
cdfnode = makecdfnode(nccomm,ocname,octype,ocnode,container);
|
|
|
|
nclistpush(tree->nodes,(void*)cdfnode);
|
|
|
|
tree->root = cdfnode;
|
|
|
|
cdfnode->tree = tree;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OC_Grid:
|
|
|
|
case OC_Structure:
|
|
|
|
case OC_Sequence:
|
|
|
|
cdfnode = makecdfnode(nccomm,ocname,octype,ocnode,container);
|
|
|
|
nclistpush(tree->nodes,(void*)cdfnode);
|
|
|
|
#if 0
|
|
|
|
if(tree->root == NULL) {
|
|
|
|
tree->root = cdfnode;
|
|
|
|
cdfnode->tree = tree;
|
2014-07-30 00:44:50 +08:00
|
|
|
}
|
2014-03-25 04:02:52 +08:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OC_Atomic:
|
|
|
|
cdfnode = makecdfnode(nccomm,ocname,octype,ocnode,container);
|
|
|
|
nclistpush(tree->nodes,(void*)cdfnode);
|
|
|
|
#if 0
|
|
|
|
if(tree->root == NULL) {
|
|
|
|
tree->root = cdfnode;
|
|
|
|
cdfnode->tree = tree;
|
2014-07-30 00:44:50 +08:00
|
|
|
}
|
2014-03-25 04:02:52 +08:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case OC_Dimension:
|
2019-09-18 10:27:43 +08:00
|
|
|
default: PANIC1("buildcdftree: unexpected OC node type: %d",(int)octype);
|
2014-03-25 04:02:52 +08:00
|
|
|
|
2014-03-29 07:11:26 +08:00
|
|
|
}
|
2014-07-30 00:44:50 +08:00
|
|
|
/* Avoid a rare but perhaps possible null-dereference
|
2014-03-29 07:11:26 +08:00
|
|
|
of cdfnode. Not sure what error to throw, so using
|
|
|
|
NC_EDAP: generic DAP error. */
|
|
|
|
if(!cdfnode) {
|
|
|
|
return NC_EDAP;
|
|
|
|
}
|
|
|
|
|
2014-03-25 04:02:52 +08:00
|
|
|
#if 0
|
|
|
|
/* cross link */
|
|
|
|
assert(tree->root != NULL);
|
|
|
|
cdfnode->root = tree->root;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(ocrank > 0) defdimensions(ocnode,cdfnode,nccomm,tree);
|
|
|
|
for(i=0;i<ocnsubnodes;i++) {
|
|
|
|
OCddsnode ocsubnode;
|
|
|
|
CDFnode* subnode;
|
|
|
|
oc_dds_ithfield(nccomm->oc.conn,ocnode,i,&ocsubnode);
|
|
|
|
ncerr = buildcdftreer(nccomm,ocsubnode,cdfnode,tree,&subnode);
|
2014-08-01 05:34:52 +08:00
|
|
|
if(ncerr) {
|
|
|
|
if(ocname) free(ocname);
|
|
|
|
return ncerr;
|
|
|
|
}
|
2014-03-25 04:02:52 +08:00
|
|
|
nclistpush(cdfnode->subnodes,(void*)subnode);
|
|
|
|
}
|
|
|
|
nullfree(ocname);
|
|
|
|
if(cdfnodep) *cdfnodep = cdfnode;
|
|
|
|
return ncerr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
freecdfroot(CDFnode* root)
|
|
|
|
{
|
2023-11-27 19:36:03 +08:00
|
|
|
size_t i;
|
2014-03-25 04:02:52 +08:00
|
|
|
CDFtree* tree;
|
|
|
|
NCDAPCOMMON* nccomm;
|
|
|
|
if(root == NULL) return;
|
|
|
|
tree = root->tree;
|
|
|
|
ASSERT((tree != NULL));
|
|
|
|
/* Explicitly FREE the ocroot */
|
|
|
|
nccomm = tree->owner;
|
|
|
|
oc_root_free(nccomm->oc.conn,tree->ocroot);
|
|
|
|
tree->ocroot = NULL;
|
|
|
|
for(i=0;i<nclistlength(tree->nodes);i++) {
|
|
|
|
CDFnode* node = (CDFnode*)nclistget(tree->nodes,i);
|
|
|
|
free1cdfnode(node);
|
|
|
|
}
|
|
|
|
nclistfree(tree->nodes);
|
|
|
|
nclistfree(tree->varnodes);
|
|
|
|
nclistfree(tree->seqnodes);
|
|
|
|
nclistfree(tree->gridnodes);
|
|
|
|
nullfree(tree);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free up a single node, but not any
|
|
|
|
nodes it points to.
|
2014-07-30 00:44:50 +08:00
|
|
|
*/
|
2014-03-25 04:02:52 +08:00
|
|
|
static void
|
|
|
|
free1cdfnode(CDFnode* node)
|
|
|
|
{
|
|
|
|
unsigned int j,k;
|
|
|
|
if(node == NULL) return;
|
|
|
|
nullfree(node->ocname);
|
|
|
|
nullfree(node->ncbasename);
|
|
|
|
nullfree(node->ncfullname);
|
2021-05-30 11:30:33 +08:00
|
|
|
nullfree(node->dodsspecial.dimname);
|
2014-03-25 04:02:52 +08:00
|
|
|
if(node->attributes != NULL) {
|
|
|
|
for(j=0;j<nclistlength(node->attributes);j++) {
|
|
|
|
NCattribute* att = (NCattribute*)nclistget(node->attributes,j);
|
|
|
|
nullfree(att->name);
|
|
|
|
for(k=0;k<nclistlength(att->values);k++)
|
|
|
|
nullfree((char*)nclistget(att->values,k));
|
|
|
|
nclistfree(att->values);
|
|
|
|
nullfree(att);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nclistfree(node->subnodes);
|
|
|
|
nclistfree(node->attributes);
|
|
|
|
nclistfree(node->array.dimsetplus);
|
|
|
|
nclistfree(node->array.dimsetall);
|
|
|
|
nclistfree(node->array.dimset0);
|
2018-05-19 10:28:51 +08:00
|
|
|
nclistfree(node->array.dimsettrans);
|
2014-03-25 04:02:52 +08:00
|
|
|
|
|
|
|
/* Clean up the ncdap4 fields also */
|
|
|
|
nullfree(node->typename);
|
|
|
|
nullfree(node->vlenname);
|
|
|
|
nullfree(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Return true if node and node1 appear to refer to the same thing;
|
|
|
|
takes grid->structure changes into account.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
nodematch(CDFnode* node1, CDFnode* node2)
|
|
|
|
{
|
|
|
|
return simplenodematch(node1,node2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Try to figure out if two nodes
|
|
|
|
are the "related" =>
|
|
|
|
same name && same nc_type and same arity
|
|
|
|
but: Allow Grid == Structure
|
|
|
|
*/
|
|
|
|
|
|
|
|
int
|
|
|
|
simplenodematch(CDFnode* node1, CDFnode* node2)
|
|
|
|
{
|
|
|
|
/* Test all the obvious stuff */
|
|
|
|
if(node1 == NULL || node2 == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Add hack to address the screwed up Columbia server
|
|
|
|
which returns different Dataset {...} names
|
|
|
|
depending on the constraint.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(FLAGSET(node1->root->tree->owner->controls,NCF_COLUMBIA)
|
|
|
|
&& node1->nctype == NC_Dataset) return 1;
|
|
|
|
|
|
|
|
if(strcmp(node1->ocname,node2->ocname)!=0) /* same names */
|
|
|
|
return 0;
|
|
|
|
if(nclistlength(node1->array.dimset0)
|
|
|
|
!= nclistlength(node2->array.dimset0)) /* same arity */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if(node1->nctype != node2->nctype) {
|
|
|
|
/* test for struct-grid match */
|
|
|
|
int structgrid = ((node1->nctype == NC_Grid && node2->nctype == NC_Structure)
|
|
|
|
|| (node1->nctype == NC_Structure && node2->nctype == NC_Grid) ? 1 : 0);
|
|
|
|
if(!structgrid)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(node1->nctype == NC_Atomic && node1->etype != node2->etype)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ensure every node has an initial base name defined and fullname */
|
|
|
|
/* Exceptions: anonymous dimensions. */
|
|
|
|
static NCerror
|
|
|
|
fix1node(NCDAPCOMMON* nccomm, CDFnode* node)
|
|
|
|
{
|
|
|
|
if(node->nctype == NC_Dimension && node->ocname == NULL) return NC_NOERR;
|
|
|
|
ASSERT((node->ocname != NULL));
|
|
|
|
nullfree(node->ncbasename);
|
|
|
|
node->ncbasename = cdflegalname(node->ocname);
|
|
|
|
if(node->ncbasename == NULL) return NC_ENOMEM;
|
|
|
|
nullfree(node->ncfullname);
|
|
|
|
node->ncfullname = makecdfpathstring(node,nccomm->cdf.separator);
|
|
|
|
if(node->ncfullname == NULL) return NC_ENOMEM;
|
|
|
|
if(node->nctype == NC_Atomic)
|
|
|
|
node->externaltype = nctypeconvert(nccomm,node->etype);
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NCerror
|
|
|
|
fixnodes(NCDAPCOMMON* nccomm, NClist* cdfnodes)
|
|
|
|
{
|
2023-11-27 19:36:03 +08:00
|
|
|
size_t i;
|
2014-03-25 04:02:52 +08:00
|
|
|
for(i=0;i<nclistlength(cdfnodes);i++) {
|
|
|
|
CDFnode* node = (CDFnode*)nclistget(cdfnodes,i);
|
|
|
|
NCerror err = fix1node(nccomm,node);
|
|
|
|
if(err) return err;
|
|
|
|
}
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
defdimensions(OCddsnode ocnode, CDFnode* cdfnode, NCDAPCOMMON* nccomm, CDFtree* tree)
|
|
|
|
{
|
|
|
|
size_t i,ocrank;
|
2014-07-30 00:44:50 +08:00
|
|
|
|
2014-03-25 04:02:52 +08:00
|
|
|
oc_dds_rank(nccomm->oc.conn,ocnode,&ocrank);
|
|
|
|
assert(ocrank > 0);
|
|
|
|
for(i=0;i<ocrank;i++) {
|
|
|
|
CDFnode* cdfdim;
|
|
|
|
OCddsnode ocdim;
|
|
|
|
char* ocname;
|
|
|
|
size_t declsize;
|
2014-07-30 00:44:50 +08:00
|
|
|
|
2014-03-25 04:02:52 +08:00
|
|
|
oc_dds_ithdimension(nccomm->oc.conn,ocnode,i,&ocdim);
|
|
|
|
oc_dimension_properties(nccomm->oc.conn,ocdim,&declsize,&ocname);
|
|
|
|
|
|
|
|
cdfdim = makecdfnode(nccomm,ocname,OC_Dimension,
|
|
|
|
ocdim,cdfnode->container);
|
|
|
|
nullfree(ocname);
|
|
|
|
nclistpush(tree->nodes,(void*)cdfdim);
|
|
|
|
/* Initially, constrained and unconstrained are same */
|
|
|
|
cdfdim->dim.declsize = declsize;
|
|
|
|
cdfdim->dim.array = cdfnode;
|
2014-07-30 00:44:50 +08:00
|
|
|
if(cdfnode->array.dimset0 == NULL)
|
2014-03-25 04:02:52 +08:00
|
|
|
cdfnode->array.dimset0 = nclistnew();
|
|
|
|
nclistpush(cdfnode->array.dimset0,(void*)cdfdim);
|
2014-07-30 00:44:50 +08:00
|
|
|
}
|
2014-03-25 04:02:52 +08:00
|
|
|
}
|