Skip to content

Commit

Permalink
Re: github issue #373
Browse files Browse the repository at this point in the history
Github issue #152
requested that "orphaned" DAS attributes be included in the netcdf
metadata as global variables. The term orphaned here meant that
they were not connected to any variable in the DDS.
This was done in pull request #164

However, some servers (e.g. Thredds) include attributes for variables not
specified in a constraint expression, but which exist in the full DDS.
So I was adding these to the set of global attributes, but in retrospect
this should not have been done: they should have been elided.

Solution: modify oc2 code to be more distriminatory about
which orphaned attributes to include.
  • Loading branch information
DennisHeimbigner committed Mar 11, 2017
1 parent 1aab755 commit 3213705
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
2 changes: 2 additions & 0 deletions libdap2/ncd2dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,8 @@ fprintf(stderr,"buildvars.candidate=|%s|\n",var->ncfullname);
}
}



definename = getdefinename(var);

#ifdef DEBUG1
Expand Down
48 changes: 29 additions & 19 deletions oc2/ocnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,14 @@
#include "occompile.h"
#include "ocdebug.h"

/* If enabled, then DAS attributes that cannot
be connected to any variable will be shown as
global attributes. No obvious reason to enable
except possibly for debugging purposes.
*/
#undef SHOWORPHAN

static const unsigned int MAX_UINT = 0xffffffff;

static OCerror mergedas1(OCnode* dds, OCnode* das);
static OCerror mergedods1(OCnode* dds, OCnode* das);
static char* pathtostring(OClist* path, char* separator);
static void computefullname(OCnode* node);
#ifdef SHOWORPHAN
static OCerror mergeother1(OCnode* root, OCnode* das);
#endif
static OCerror mergeother(OCnode* ddsroot, OClist* dasnodes);

/* Process ocnodes to fix various semantic issues*/
void
Expand Down Expand Up @@ -344,15 +336,13 @@ ocddsdasmerge(OCstate* state, OCnode* dasroot, OCnode* ddsroot)
mergedods1(ddsroot,das);
}

#ifdef SHOWORPHAN
/* 6. Assign other orphan attributes, which means
construct their full name and assign as a global attribute. */
for(i=0;i<oclistlength(dasnodes);i++) {
OCnode* das = (OCnode*)oclistget(dasnodes,i);
if(das == NULL) continue;
mergeother1(ddsroot, das);
}
#endif
construct their full name and assign as a global attribute.
This is complicated because some servers (e.g. thredds) returns
attributes for variables that were not referenced in the DDS.
These we continue to suppress.
*/
mergeother(ddsroot,dasnodes);

done:
/* cleanup*/
Expand All @@ -374,6 +364,11 @@ mergedas1(OCnode* dds, OCnode* das)
for(i=0;i<oclistlength(das->subnodes);i++) {
OCnode* attnode = (OCnode*)oclistget(das->subnodes,i);
if(attnode->octype == OC_Attribute) {
if(dds->octype == OC_Atomic
|| dds->octype == OC_Sequence
|| dds->octype == OC_Structure
|| dds->octype == OC_Grid)
attnode->att.var = dds;
OCattribute* att = makeattribute(attnode->name,
attnode->etype,
attnode->att.values);
Expand Down Expand Up @@ -418,7 +413,19 @@ mergedods1(OCnode* dds, OCnode* dods)
return OCTHROW(stat);
}

#ifdef SHOWORPHAN
static OCerror
mergeother(OCnode* ddsroot, OClist* dasnodes)
{
OCerror stat = OC_NOERR;
int i;
for(i=0;i<oclistlength(dasnodes);i++) {
OCnode* das = (OCnode*)oclistget(dasnodes,i);
if(das == NULL) continue;
if((stat = mergeother1(ddsroot, das))) break;
}
return stat;
}

static OCerror
mergeother1(OCnode* root, OCnode* das)
{
Expand All @@ -428,6 +435,9 @@ mergeother1(OCnode* root, OCnode* das)
OCASSERT(root != NULL);
if(root->attributes == NULL) root->attributes = oclistnew();

/* Only include if this is not connected to a variable */
if(das->att.var != NULL) goto done;

if(das->octype == OC_Attribute) {
/* compute the full name of this attribute */
computefullname(das);
Expand All @@ -444,9 +454,9 @@ mergeother1(OCnode* root, OCnode* das)
}
} else
stat = OC_EDAS;
done:
return OCTHROW(stat);
}
#endif

static void
ocuncorrelate(OCnode* root)
Expand Down
1 change: 1 addition & 0 deletions oc2/ocnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ typedef struct OCattinfo {
int isglobal; /* is this supposed to be a global attribute set?*/
int isdods; /* is this a global DODS_XXX attribute set */
OClist* values; /* oclist<char*>*/
struct OCnode* var; /* containing var else null */
} OCattinfo;

/*! Specifies the OCnode. */
Expand Down

0 comments on commit 3213705

Please sign in to comment.