From 32137052055f58f0882e6b63e9997e61711df82a Mon Sep 17 00:00:00 2001 From: Dennis Heimbigner Date: Sat, 11 Mar 2017 16:17:20 -0700 Subject: [PATCH] Re: github issue https://github.com/Unidata/netcdf-c/issues/373 Github issue https://github.com/Unidata/netcdf-c/issues/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 https://github.com/Unidata/netcdf-c/pull/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. --- libdap2/ncd2dispatch.c | 2 ++ oc2/ocnode.c | 48 +++++++++++++++++++++++++----------------- oc2/ocnode.h | 1 + 3 files changed, 32 insertions(+), 19 deletions(-) diff --git a/libdap2/ncd2dispatch.c b/libdap2/ncd2dispatch.c index d60eb674ad..e269345107 100644 --- a/libdap2/ncd2dispatch.c +++ b/libdap2/ncd2dispatch.c @@ -769,6 +769,8 @@ fprintf(stderr,"buildvars.candidate=|%s|\n",var->ncfullname); } } + + definename = getdefinename(var); #ifdef DEBUG1 diff --git a/oc2/ocnode.c b/oc2/ocnode.c index b840f9d39c..86913b5031 100644 --- a/oc2/ocnode.c +++ b/oc2/ocnode.c @@ -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 @@ -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;isubnodes);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); @@ -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;iattributes == 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); @@ -444,9 +454,9 @@ mergeother1(OCnode* root, OCnode* das) } } else stat = OC_EDAS; +done: return OCTHROW(stat); } -#endif static void ocuncorrelate(OCnode* root) diff --git a/oc2/ocnode.h b/oc2/ocnode.h index 12cf0a9405..e7821dfaa3 100644 --- a/oc2/ocnode.h +++ b/oc2/ocnode.h @@ -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*/ + struct OCnode* var; /* containing var else null */ } OCattinfo; /*! Specifies the OCnode. */