2011-04-18 02:56:10 +08:00
|
|
|
/*********************************************************************
|
|
|
|
* Copyright 1993, UCAR/Unidata
|
|
|
|
* 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
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
#define OCCHECK(exp) if((ocstat = (exp))) {THROWCHK(ocstat); goto done;}
|
2011-04-18 02:56:10 +08:00
|
|
|
|
|
|
|
/* Forward */
|
2012-08-01 04:34:13 +08:00
|
|
|
static NCerror buildattribute(char*,nc_type,size_t,char**,NCattribute**);
|
2011-04-18 02:56:10 +08:00
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
/*
|
|
|
|
Invoke oc_merge_das and then extract special
|
|
|
|
attributes such as "strlen" and "dimname"
|
|
|
|
and stuff from DODS_EXTRA.
|
|
|
|
*/
|
|
|
|
int
|
2014-03-25 04:02:52 +08:00
|
|
|
dapmerge(NCDAPCOMMON* nccomm, CDFnode* ddsroot, OCddsnode dasroot)
|
2012-08-01 04:34:13 +08:00
|
|
|
{
|
|
|
|
int i,j;
|
|
|
|
NCerror ncstat = NC_NOERR;
|
|
|
|
OCerror ocstat = OC_NOERR;
|
|
|
|
NClist* allnodes;
|
|
|
|
OClink conn;
|
2012-08-03 02:43:21 +08:00
|
|
|
char* ocname = NULL;
|
2013-03-15 06:49:21 +08:00
|
|
|
char** values = NULL;
|
2012-08-01 04:34:13 +08:00
|
|
|
conn = nccomm->oc.conn;
|
|
|
|
|
2014-02-06 08:05:33 +08:00
|
|
|
if(ddsroot == NULL || dasroot == NULL)
|
|
|
|
return NC_NOERR;
|
2012-08-01 04:34:13 +08:00
|
|
|
/* Merge the das tree onto the dds tree */
|
2014-02-06 08:05:33 +08:00
|
|
|
ocstat = oc_merge_das(nccomm->oc.conn,dasroot,ddsroot->ocnode);
|
2012-08-01 04:34:13 +08:00
|
|
|
if(ocstat != OC_NOERR) goto done;
|
|
|
|
|
|
|
|
/* Create attributes on CDFnodes */
|
2014-02-06 08:05:33 +08:00
|
|
|
allnodes = ddsroot->tree->nodes;
|
2012-08-01 04:34:13 +08:00
|
|
|
for(i=0;i<nclistlength(allnodes);i++) {
|
|
|
|
CDFnode* node = (CDFnode*)nclistget(allnodes,i);
|
|
|
|
OCddsnode ocnode = node->ocnode;
|
|
|
|
size_t attrcount;
|
|
|
|
OCtype ocetype;
|
|
|
|
|
|
|
|
OCCHECK(oc_dds_attr_count(conn,ocnode,&attrcount));
|
|
|
|
for(j=0;j<attrcount;j++) {
|
|
|
|
size_t nvalues;
|
2013-03-15 06:49:21 +08:00
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
NCattribute* att = NULL;
|
|
|
|
|
2012-11-15 02:24:45 +08:00
|
|
|
if(ocname != NULL) {
|
|
|
|
free(ocname); ocname = NULL;
|
|
|
|
} /* from last loop */
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
OCCHECK(oc_dds_attr(conn,ocnode,j,&ocname,&ocetype,&nvalues,NULL));
|
|
|
|
if(nvalues > 0) {
|
|
|
|
values = (char**)malloc(sizeof(char*)*nvalues);
|
|
|
|
if(values == NULL) {ncstat = NC_ENOMEM; goto done;}
|
|
|
|
OCCHECK(oc_dds_attr(conn,ocnode,j,NULL,NULL,NULL,values));
|
|
|
|
}
|
|
|
|
ncstat = buildattribute(ocname,octypetonc(ocetype),nvalues,values,&att);
|
|
|
|
if(ncstat != NC_NOERR) goto done;
|
|
|
|
if(node->attributes == NULL)
|
|
|
|
node->attributes = nclistnew();
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(node->attributes,(void*)att);
|
2012-08-01 04:34:13 +08:00
|
|
|
if(strncmp(ocname,"DODS",strlen("DODS"))==0) {
|
|
|
|
att->invisible = 1;
|
|
|
|
/* Define extra semantics associated with
|
|
|
|
DODS and DODS_EXTRA attributes */
|
|
|
|
if(strcmp(ocname,"DODS.strlen")==0
|
|
|
|
|| strcmp(ocname,"DODS_EXTRA.strlen")==0) {
|
|
|
|
unsigned int maxstrlen = 0;
|
|
|
|
if(values != NULL) {
|
|
|
|
if(0==sscanf(values[0],"%u",&maxstrlen))
|
|
|
|
maxstrlen = 0;
|
|
|
|
}
|
|
|
|
node->dodsspecial.maxstrlen = maxstrlen;
|
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr,"%s.maxstrlen=%d\n",node->ocname,(int)node->dodsspecial.maxstrlen);
|
|
|
|
#endif
|
|
|
|
} else if(strcmp(ocname,"DODS.dimName")==0
|
|
|
|
|| strcmp(ocname,"DODS_EXTRA.dimName")==0) {
|
|
|
|
if(values != NULL) {
|
|
|
|
node->dodsspecial.dimname = nulldup(values[0]);
|
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr,"%s.dimname=%s\n",node->ocname,node->dodsspecial.dimname);
|
|
|
|
#endif
|
|
|
|
} else node->dodsspecial.dimname = NULL;
|
|
|
|
} else if(strcmp(ocname,"DODS.Unlimited_Dimension")==0
|
|
|
|
|| strcmp(ocname,"DODS_EXTRA.Unlimited_Dimension")==0) {
|
|
|
|
if(values != NULL) {
|
|
|
|
if(nccomm->cdf.recorddimname != NULL)
|
|
|
|
nclog(NCLOGWARN,"Duplicate DODS_EXTRA:Unlimited_Dimension specifications");
|
|
|
|
else
|
|
|
|
nccomm->cdf.recorddimname = nulldup(values[0]);
|
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr,"%s.Unlimited_Dimension=%s\n",node->ocname,nccomm->cdf.recorddimname);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* clean up */
|
|
|
|
if(values) {
|
|
|
|
oc_reclaim_strings(nvalues,values);
|
|
|
|
free(values);
|
2013-03-15 06:49:21 +08:00
|
|
|
values = NULL;
|
2012-08-01 04:34:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
2013-03-15 06:49:21 +08:00
|
|
|
if(values != NULL) free(values);
|
2012-08-03 02:43:21 +08:00
|
|
|
if(ocname != NULL) free(ocname);
|
2012-08-01 04:34:13 +08:00
|
|
|
if(ocstat != OC_NOERR) ncstat = ocerrtoncerr(ocstat);
|
|
|
|
return THROW(ncstat);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build an NCattribute */
|
2011-04-18 02:56:10 +08:00
|
|
|
static NCerror
|
|
|
|
buildattribute(char* name, nc_type ptype,
|
2012-08-01 04:34:13 +08:00
|
|
|
size_t nvalues, char** values, NCattribute** attp)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
2012-08-01 04:34:13 +08:00
|
|
|
int i;
|
2011-04-18 02:56:10 +08:00
|
|
|
NCerror ncstat = NC_NOERR;
|
2013-03-15 06:49:21 +08:00
|
|
|
NCattribute* att = NULL;
|
2011-04-18 02:56:10 +08:00
|
|
|
|
|
|
|
att = (NCattribute*)calloc(1,sizeof(NCattribute));
|
|
|
|
MEMCHECK(att,NC_ENOMEM);
|
|
|
|
att->name = nulldup(name);
|
|
|
|
att->etype = ptype;
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
att->values = nclistnew();
|
|
|
|
for(i=0;i<nvalues;i++)
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(att->values,(void*)nulldup(values[i]));
|
2011-04-18 02:56:10 +08:00
|
|
|
|
|
|
|
if(attp) *attp = att;
|
2013-03-15 06:49:21 +08:00
|
|
|
else
|
|
|
|
free(att);
|
2011-04-18 02:56:10 +08:00
|
|
|
|
|
|
|
return THROW(ncstat);
|
|
|
|
}
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
#if 0
|
2012-01-30 02:56:29 +08:00
|
|
|
/*
|
|
|
|
Given a das attribute walk it to see if it
|
|
|
|
has at least 1 actual attribute (no recursion)
|
|
|
|
*/
|
|
|
|
static int
|
2014-03-25 04:02:52 +08:00
|
|
|
hasattribute(OClink conn, OCdasnode dasnode)
|
2012-01-30 02:56:29 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
OCerror ocstat = OC_NOERR;
|
|
|
|
int tf = 0; /* assume false */
|
|
|
|
OCtype ocsubtype;
|
2012-08-01 04:34:13 +08:00
|
|
|
NClist* subnodes = nclistnew();
|
2012-01-30 02:56:29 +08:00
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
OCCHECK(oc_dds_octype(conn,dasnode,&ocsubtype));
|
2012-01-30 02:56:29 +08:00
|
|
|
if(ocsubtype == OC_Attribute) return 1; /* this is an attribute */
|
|
|
|
ASSERT((ocsubtype == OC_Attributeset));
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
OCCHECK(collect_subnodes(conn,dasnode,subnodes));
|
|
|
|
for(i=0;i<nclistlength(subnodes);i++) {
|
|
|
|
OCdasnode subnode = (OCdasnode)nclistget(subnodes,i);
|
|
|
|
OCCHECK(oc_dds_class(conn,subnode,&ocsubtype));
|
2012-01-30 02:56:29 +08:00
|
|
|
if(ocsubtype == OC_Attribute) {tf=1; break;}
|
|
|
|
}
|
|
|
|
done:
|
2012-08-01 04:34:13 +08:00
|
|
|
nclistfree(subnodes);
|
2012-01-30 02:56:29 +08:00
|
|
|
return tf;
|
|
|
|
}
|
2011-04-18 02:56:10 +08:00
|
|
|
|
|
|
|
int
|
2014-03-25 04:02:52 +08:00
|
|
|
dapmerge(NCDAPCOMMON* nccomm, CDFnode* ddsroot, OCddsnode dasroot)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
|
|
|
unsigned int i,j;
|
|
|
|
NCerror ncerr = NC_NOERR;
|
|
|
|
OCerror ocstat = OC_NOERR;
|
2012-08-01 04:34:13 +08:00
|
|
|
OClink conn = nccomm->oc.conn;
|
|
|
|
size_t nsubnodes;
|
2011-04-18 02:56:10 +08:00
|
|
|
NClist* dasglobals = nclistnew();
|
|
|
|
NClist* dasnodes = nclistnew();
|
2012-01-30 02:56:29 +08:00
|
|
|
NClist* dodsextra = nclistnew();
|
2011-04-18 02:56:10 +08:00
|
|
|
NClist* varnodes = nclistnew();
|
2012-08-01 04:34:13 +08:00
|
|
|
NClist* alldasnodes = nclistnew();
|
2011-04-18 02:56:10 +08:00
|
|
|
|
|
|
|
if(ddsroot == NULL || dasroot == NULL) return NC_NOERR;
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
ocstat = collect_alldasnodes(conn,dasroot,alldasnodes);
|
2011-04-18 02:56:10 +08:00
|
|
|
|
|
|
|
/* 1. collect all the relevant DAS nodes;
|
|
|
|
namely those that contain at least one
|
|
|
|
attribute value.
|
|
|
|
Simultaneously look for potential ambiguities
|
|
|
|
if found; complain but continue: result are indeterminate.
|
2012-01-30 02:56:29 +08:00
|
|
|
also collect globals and DODS_EXTRA separately.
|
|
|
|
*/
|
2012-08-01 04:34:13 +08:00
|
|
|
for(i=0;i<nclistlength(alldasnodes);i++) {
|
|
|
|
OCddsnode das = (OCddsnode)nclistget(alldasnodes,i);
|
2011-04-18 02:56:10 +08:00
|
|
|
OCtype octype;
|
|
|
|
char* ocname = NULL;
|
|
|
|
int isglobal = 0;
|
|
|
|
int hasattributes = 0;
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
OCCHECK(oc_dds_class(conn,das,&octype));
|
2011-04-18 02:56:10 +08:00
|
|
|
if(octype == OC_Attribute) continue; /* ignore these for now*/
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
OCCHECK(oc_dds_name(conn,das,&ocname));
|
|
|
|
OCCHECK(oc_dds_nsubnodes(conn,das,&nsubnodes));
|
2011-04-18 02:56:10 +08:00
|
|
|
|
2014-03-25 04:02:52 +08:00
|
|
|
isglobal = (ocname == NULL ? 0 : isglobalname(ocname));
|
2011-04-18 02:56:10 +08:00
|
|
|
|
2012-01-30 02:56:29 +08:00
|
|
|
/* catch DODS_EXTRA */
|
|
|
|
if(isglobal && ocname != NULL && strcmp(ocname,"DODS_EXTRA")==0) {
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(dodsextra,(void*)das);
|
2011-04-18 02:56:10 +08:00
|
|
|
nullfree(ocname);
|
|
|
|
continue;
|
|
|
|
}
|
2012-01-30 02:56:29 +08:00
|
|
|
if(ocname == NULL || isglobal) {
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(dasglobals,(void*)das);
|
2011-04-18 02:56:10 +08:00
|
|
|
nullfree(ocname);
|
|
|
|
continue;
|
|
|
|
}
|
2014-03-25 04:02:52 +08:00
|
|
|
hasattributes = hasattribute(conn,das);
|
2011-04-18 02:56:10 +08:00
|
|
|
if(hasattributes) {
|
|
|
|
/* Look for previously collected nodes with same name*/
|
|
|
|
for(j=0;j<nclistlength(dasnodes);j++) {
|
2012-08-01 04:34:13 +08:00
|
|
|
OCddsnode das2 = (OCddsnode)nclistget(dasnodes,j);
|
2011-04-18 02:56:10 +08:00
|
|
|
char* ocname2;
|
2012-08-01 04:34:13 +08:00
|
|
|
OCCHECK(oc_dds_name(conn,das2,&ocname2));
|
2011-04-18 02:56:10 +08:00
|
|
|
if(ocname2 == NULL || ocname == NULL) goto loop;
|
|
|
|
if(strcmp(ocname2,"DODS")==0) goto loop;
|
|
|
|
if(strcmp(ocname,ocname2)==0)
|
|
|
|
nclog(NCLOGWARN,"nc_mergedas: potentially ambiguous DAS name: %s",ocname2);
|
|
|
|
loop:
|
|
|
|
nullfree(ocname2);
|
|
|
|
}
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(dasnodes,(void*)das);
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
nullfree(ocname);
|
|
|
|
}
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
/* 2. collect all the leaf DDS nodes (of type NC_Atomic)*/
|
|
|
|
ocstat = collect_leaves(link,ddsroot,varnodes);
|
2011-04-18 02:56:10 +08:00
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
/* 3. For each das node, locate matching DDS node(s) and attach
|
2011-04-18 02:56:10 +08:00
|
|
|
attributes to the DDS node(s).
|
|
|
|
Match means:
|
|
|
|
1. DAS->fullname :: DDS->fullname
|
|
|
|
2. DAS->name :: DDS->fullname (support DAS names with embedded '.'
|
|
|
|
3. DAS->name :: DDS->name
|
2012-01-30 02:56:29 +08:00
|
|
|
4. special case for DODS. Apply 1-3 on DODS parent.
|
2011-04-18 02:56:10 +08:00
|
|
|
*/
|
|
|
|
for(i=0;i<nclistlength(dasnodes);i++) {
|
2012-08-01 04:34:13 +08:00
|
|
|
OCddsnode das = (OCddsnode)nclistget(dasnodes,i);
|
2012-02-04 05:31:50 +08:00
|
|
|
char* ocfullname = NULL;
|
|
|
|
char* ocbasename = NULL;
|
2012-01-30 02:56:29 +08:00
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
if(das == NULL) continue;
|
|
|
|
OCCHECK(oc_dds_name(conn,das,&ocbasename));
|
2012-01-30 02:56:29 +08:00
|
|
|
if(strcmp(ocbasename,"DODS")==0) {
|
2012-08-01 04:34:13 +08:00
|
|
|
OCddsnode container;
|
|
|
|
OCCHECK(oc_dds_container(conn,das,&container));
|
|
|
|
ASSERT(container != NULL);
|
2014-03-25 04:02:52 +08:00
|
|
|
ocfullname = makeocpathstring(conn,container,".");
|
2012-01-30 02:56:29 +08:00
|
|
|
} else {
|
2014-03-25 04:02:52 +08:00
|
|
|
ocfullname = makeocpathstring(conn,das,".");
|
2012-01-30 02:56:29 +08:00
|
|
|
}
|
2011-04-18 02:56:10 +08:00
|
|
|
for(j=0;j<nclistlength(varnodes);j++) {
|
|
|
|
CDFnode* dds = (CDFnode*)nclistget(varnodes,j);
|
2014-03-25 04:02:52 +08:00
|
|
|
char* ddsfullname = makecdfpathstring(dds,".");
|
2011-04-18 02:56:10 +08:00
|
|
|
if(strcmp(ocfullname,ddsfullname)==0
|
|
|
|
|| strcmp(ocbasename,ddsfullname)==0
|
2011-11-14 12:20:19 +08:00
|
|
|
|| strcmp(ocbasename,dds->ocname)==0) {
|
2012-01-30 12:32:12 +08:00
|
|
|
mergedas1(nccomm,conn,dds,das);
|
2011-04-18 02:56:10 +08:00
|
|
|
/* remove from dasnodes list*/
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistset(dasnodes,i,(void*)NULL);
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
nullfree(ddsfullname);
|
|
|
|
}
|
|
|
|
nullfree(ocfullname);
|
|
|
|
nullfree(ocbasename);
|
|
|
|
}
|
|
|
|
|
2012-01-30 02:56:29 +08:00
|
|
|
/* 4. Assign globals */
|
2011-04-18 02:56:10 +08:00
|
|
|
for(i=0;i<nclistlength(dasglobals);i++) {
|
2012-08-01 04:34:13 +08:00
|
|
|
OCddsnode das = (OCddsnode)nclistget(dasglobals,i);
|
2012-01-30 12:32:12 +08:00
|
|
|
mergedas1(nccomm,conn,ddsroot,das);
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
|
2012-01-30 02:56:29 +08:00
|
|
|
/* 5. Assign DOD_EXTRA */
|
|
|
|
for(i=0;i<nclistlength(dodsextra);i++) {
|
2012-08-01 04:34:13 +08:00
|
|
|
OCddsnode das = (OCddsnode)nclistget(dodsextra,i);
|
2012-01-30 12:32:12 +08:00
|
|
|
mergedas1(nccomm,conn,ddsroot,das);
|
2012-01-30 02:56:29 +08:00
|
|
|
}
|
2011-04-18 02:56:10 +08:00
|
|
|
|
|
|
|
done: /* cleanup*/
|
|
|
|
nclistfree(dasglobals);
|
|
|
|
nclistfree(dasnodes);
|
2012-08-01 04:34:13 +08:00
|
|
|
nclistfree(alldasnodes);
|
2011-04-18 02:56:10 +08:00
|
|
|
nclistfree(dodsextra);
|
|
|
|
nclistfree(varnodes);
|
2012-08-01 04:34:13 +08:00
|
|
|
if(ocstat != OC_NOERR)
|
|
|
|
ncerr = ocerrtoncerr(ocstat);
|
2011-04-18 02:56:10 +08:00
|
|
|
return THROW(ncerr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-08-01 04:34:13 +08:00
|
|
|
mergedas1(NCDAPCOMMON* nccomm, OClink conn, CDFnode* dds, OCddsnode das)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
|
|
|
NCerror ncstat = NC_NOERR;
|
|
|
|
OCerror ocstat = OC_NOERR;
|
2012-01-30 02:56:29 +08:00
|
|
|
unsigned int i,j,k;
|
2011-04-18 02:56:10 +08:00
|
|
|
unsigned int nsubnodes;
|
|
|
|
OCobject* subnodes = NULL;
|
|
|
|
OCobject* dodsnodes = NULL;
|
|
|
|
unsigned int ndodsnodes;
|
|
|
|
|
|
|
|
if(dds == NULL || das == OCNULL) return NC_NOERR; /* nothing to do */
|
|
|
|
if(dds->attributes == NULL) dds->attributes = nclistnew();
|
|
|
|
/* assign the simple attributes in the das set to this dds node*/
|
2012-08-01 04:34:13 +08:00
|
|
|
OCCHECK(oc_inq_nsubnodes(conn,das,&nsubnodes));
|
|
|
|
OCCHECK(oc_inq_subnodes(conn,das,&subnodes));
|
2011-04-18 02:56:10 +08:00
|
|
|
for(i=0;i<nsubnodes;i++) {
|
|
|
|
OCobject attnode = subnodes[i];
|
|
|
|
OCtype octype, ocetype;
|
|
|
|
char* ocname = NULL;
|
|
|
|
unsigned int ocnvalues;
|
2012-08-01 04:34:13 +08:00
|
|
|
OCCHECK(oc_inq_name(conn,attnode,&ocname));
|
|
|
|
OCCHECK(oc_inq_class(conn,attnode,&octype));
|
2011-04-18 02:56:10 +08:00
|
|
|
if(octype == OC_Attribute) {
|
|
|
|
NCattribute* att = NULL;
|
|
|
|
NClist* stringvalues;
|
2012-08-01 04:34:13 +08:00
|
|
|
OCCHECK(oc_inq_primtype(conn,attnode,&ocetype));
|
|
|
|
OCCHECK(oc_inq_dasattr_nvalues(conn,attnode,&ocnvalues));
|
2011-04-18 02:56:10 +08:00
|
|
|
stringvalues = nclistnew();
|
|
|
|
for(j=0;j<ocnvalues;j++) {
|
|
|
|
char* stringval;
|
2012-08-01 04:34:13 +08:00
|
|
|
OCCHECK(oc_inq_dasattr(conn,attnode,j,&ocetype,&stringval));
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(stringvalues,(void*)stringval);
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
ncstat = buildattribute(ocname,
|
|
|
|
octypetonc(ocetype),
|
|
|
|
stringvalues,
|
|
|
|
&att);
|
|
|
|
if(ncstat) goto done;
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(dds->attributes,(void*)att);
|
2012-01-30 02:56:29 +08:00
|
|
|
} else if(octype == OC_Attributeset
|
|
|
|
&& (strcmp(ocname,"DODS")==0
|
|
|
|
|| strcmp(ocname,"DODS_EXTRA")==0)) {
|
|
|
|
/* Turn the DODS special attributes into into
|
|
|
|
special attributes for dds node */
|
2012-08-01 04:34:13 +08:00
|
|
|
OCCHECK(oc_inq_nsubnodes(conn,attnode,&ndodsnodes));
|
|
|
|
OCCHECK(oc_inq_subnodes(conn,attnode,&dodsnodes));
|
2011-04-18 02:56:10 +08:00
|
|
|
for(j=0;j<ndodsnodes;j++) {
|
|
|
|
char* dodsname = NULL;
|
2012-01-30 02:56:29 +08:00
|
|
|
char newname[4096];
|
|
|
|
OCobject attnode = dodsnodes[j];
|
|
|
|
NCattribute* att = NULL;
|
|
|
|
NClist* stringvalues;
|
2012-08-01 04:34:13 +08:00
|
|
|
OCCHECK(oc_inq_class(conn,attnode,&octype));
|
2011-04-18 02:56:10 +08:00
|
|
|
if(octype != OC_Attribute) continue;
|
2012-08-01 04:34:13 +08:00
|
|
|
OCCHECK(oc_inq_primtype(conn,attnode,&ocetype));
|
|
|
|
OCCHECK(oc_inq_dasattr_nvalues(conn,attnode,&ocnvalues));
|
2012-01-30 02:56:29 +08:00
|
|
|
stringvalues = nclistnew();
|
|
|
|
for(k=0;k<ocnvalues;k++) {
|
|
|
|
char* stringval;
|
2012-08-01 04:34:13 +08:00
|
|
|
OCCHECK(oc_inq_dasattr(conn,attnode,k,&ocetype,&stringval));
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(stringvalues,(void*)stringval);
|
2012-01-30 02:56:29 +08:00
|
|
|
}
|
2012-08-01 04:34:13 +08:00
|
|
|
OCCHECK(oc_inq_name(conn,attnode,&dodsname));
|
2012-01-30 02:56:29 +08:00
|
|
|
/* Compute new special name */
|
|
|
|
strcpy(newname,"_DODS_");
|
|
|
|
strcat(newname,dodsname);
|
|
|
|
ncstat = buildattribute(newname,
|
|
|
|
octypetonc(ocetype),
|
|
|
|
stringvalues,
|
|
|
|
&att);
|
|
|
|
if(ncstat) goto done;
|
|
|
|
att->invisible = 1;
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(dds->attributes,(void*)att);
|
2012-01-30 02:56:29 +08:00
|
|
|
|
|
|
|
/* Define extra semantics associated with DODS and DODS_EXTRA attribute */
|
2011-04-18 02:56:10 +08:00
|
|
|
if(strcmp(dodsname,"strlen")==0) {
|
|
|
|
unsigned int maxstrlen = 0;
|
2012-01-30 02:56:29 +08:00
|
|
|
if(nclistlength(stringvalues) > 0) {
|
|
|
|
char* stringval = (char*)nclistget(stringvalues,0);
|
2011-04-18 02:56:10 +08:00
|
|
|
if(0==sscanf(stringval,"%u",&maxstrlen)) maxstrlen = 0;
|
|
|
|
}
|
|
|
|
dds->dodsspecial.maxstrlen = maxstrlen;
|
|
|
|
#ifdef DEBUG
|
2011-11-14 12:20:19 +08:00
|
|
|
fprintf(stderr,"%s.maxstrlen=%d\n",dds->ocname,(int)dds->dodsspecial.maxstrlen);
|
2011-04-18 02:56:10 +08:00
|
|
|
#endif
|
|
|
|
} else if(strcmp(dodsname,"dimName")==0) {
|
2012-01-30 02:56:29 +08:00
|
|
|
if(nclistlength(stringvalues) > 0) {
|
|
|
|
char* stringval = (char*)nclistget(stringvalues,0);
|
|
|
|
dds->dodsspecial.dimname = nulldup(stringval);
|
2011-04-18 02:56:10 +08:00
|
|
|
#ifdef DEBUG
|
2011-11-14 12:20:19 +08:00
|
|
|
fprintf(stderr,"%s.dimname=%s\n",dds->ocname,dds->dodsspecial.dimname);
|
2011-04-18 02:56:10 +08:00
|
|
|
#endif
|
|
|
|
} else dds->dodsspecial.dimname = NULL;
|
2012-01-30 02:56:29 +08:00
|
|
|
} else if(strcmp(dodsname,"Unlimited_Dimension")==0) {
|
|
|
|
if(nccomm->cdf.recorddimname != NULL) {
|
|
|
|
nclog(NCLOGWARN,"Duplicate DODS_EXTRA:Unlimited_Dimension specifications");
|
|
|
|
} else if(nclistlength(stringvalues) > 0) {
|
|
|
|
char* stringval = (char*)nclistget(stringvalues,0);
|
|
|
|
nccomm->cdf.recorddimname = nulldup(stringval);
|
|
|
|
#ifdef DEBUG
|
|
|
|
fprintf(stderr,"%s.Unlimited_Dimension=%s\n",dds->ocname,nccomm->cdf.recorddimname);
|
|
|
|
#endif
|
|
|
|
}
|
2011-04-18 02:56:10 +08:00
|
|
|
} /* else ignore */
|
|
|
|
nullfree(dodsname);
|
|
|
|
}
|
|
|
|
nullfree(dodsnodes);
|
2012-01-30 02:56:29 +08:00
|
|
|
}
|
2011-04-18 02:56:10 +08:00
|
|
|
nullfree(ocname);
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
nullfree(subnodes);
|
|
|
|
if(ocstat != OC_NOERR) ncstat = ocerrtoncerr(ocstat);
|
|
|
|
return THROW(ncstat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-03-25 04:02:52 +08:00
|
|
|
isglobalname(char* name)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
|
|
|
int len = strlen(name);
|
|
|
|
int glen = strlen("global");
|
|
|
|
char* p;
|
|
|
|
if(len < glen) return 0;
|
|
|
|
p = name + (len - glen);
|
|
|
|
if(strcasecmp(p,"global") != 0)
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
|
|
|
|
static OCerror
|
|
|
|
collect_alldasnodes(OClink link, OCddsnode dasnode, NClist* alldasnodes)
|
|
|
|
{
|
|
|
|
size_t nsubnodes,i;
|
|
|
|
OCerror ocstat = OC_NOERR;
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(alldasnodes,(void*)dasnode);
|
2012-08-01 04:34:13 +08:00
|
|
|
ocstat = oc_dds_nsubnodes(link,dasnode,&nsubnodes);
|
|
|
|
if(ocstat != OC_NOERR) goto done;
|
|
|
|
for(i=0;i<nsubnodes;i++) {
|
|
|
|
OCddsnode subnode;
|
|
|
|
ocstat = oc_dds_ithsubnode(link,dasnode,i,&subnode);
|
|
|
|
if(ocstat != OC_NOERR) goto done;
|
|
|
|
ocstat = collect_alldasnodes(link,subnode,alldasnodes);
|
|
|
|
if(ocstat != OC_NOERR) goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
return ocstat;
|
|
|
|
}
|
|
|
|
|
|
|
|
static OCerror
|
|
|
|
collect_leaves(OClink link, OCddsnode ddsnode, NClist* leaves)
|
|
|
|
{
|
|
|
|
size_t nsubnodes,i;
|
|
|
|
OCerror ocstat = OC_NOERR;
|
|
|
|
OCtype octype;
|
|
|
|
ocstat = oc_dds_octype(link,ddsnode,&octype);
|
|
|
|
if(ocstat != OC_NOERR) goto done;
|
|
|
|
if(octype == OC_Atomic) {
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(leaves,(void*)ddsnode);
|
2012-08-01 04:34:13 +08:00
|
|
|
} else {
|
|
|
|
ocstat = oc_dds_nsubnodes(link,ddsnode,&nsubnodes);
|
|
|
|
if(ocstat != OC_NOERR) goto done;
|
|
|
|
for(i=0;i<nsubnodes;i++) {
|
|
|
|
OCddsnode subnode;
|
|
|
|
ocstat = oc_dds_ithsubnode(link,ddsnode,i,&subnode);
|
|
|
|
if(ocstat != OC_NOERR) goto done;
|
|
|
|
ocstat = collect_leaves(link,subnode,leaves);
|
|
|
|
if(ocstat != OC_NOERR) goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
return ocstat;
|
|
|
|
}
|
|
|
|
|
|
|
|
static OCerror
|
|
|
|
collect_subnodes(OClink link, OCddsnode ddsnode, NClist* subnodes)
|
|
|
|
{
|
|
|
|
size_t nsubnodes,i;
|
|
|
|
OCerror ocstat = OC_NOERR;
|
|
|
|
ocstat = oc_dds_nsubnodes(link,ddsnode,&nsubnodes);
|
|
|
|
if(ocstat != OC_NOERR) goto done;
|
|
|
|
for(i=0;i<nsubnodes;i++) {
|
|
|
|
OCddsnode subnode;
|
|
|
|
ocstat = oc_dds_ithsubnode(link,ddsnode,i,&subnode);
|
|
|
|
if(ocstat != OC_NOERR) goto done;
|
2012-08-20 05:12:35 +08:00
|
|
|
nclistpush(subnodes,(void*)subnode);
|
2012-08-01 04:34:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
return ocstat;
|
|
|
|
}
|
|
|
|
#endif /*0*/
|