char* dumpcachenode(NCcachenode* node) { char* result = NULL; char tmp[8192]; int i; NCbytes* buf; if(node == NULL) return strdup("cachenode{null}"); buf = ncbytesnew(); snprintf(tmp,sizeof(tmp),"cachenode%s(%lx){size=%lu; constraint=%s; vars=", node->prefetch?"*":"", (unsigned long)node, (unsigned long)node->xdrsize, buildconstraintstring3(node->constraint)); ncbytescat(buf,tmp); if(nclistlength(node->vars)==0) ncbytescat(buf,"null"); else for(i=0;i<nclistlength(node->vars);i++) { CDFnode* var = (CDFnode*)nclistget(node->vars,i); if(i > 0) ncbytescat(buf,","); ncbytescat(buf,makesimplepathstring3(var)); } ncbytescat(buf,"}"); result = ncbytesdup(buf); ncbytesfree(buf); return result; }
NCerror showprojection3(NCDAPCOMMON* dapcomm, CDFnode* var) { int i,rank; NCerror ncstat = NC_NOERR; NCbytes* projection = ncbytesnew(); NClist* path = nclistnew(); NC* drno = dapcomm->controller; /* Collect the set of DDS node name forming the xpath */ collectnodepath3(var,path,WITHOUTDATASET); for(i=0;i<nclistlength(path);i++) { CDFnode* node = (CDFnode*)nclistget(path,i); if(i > 0) ncbytescat(projection,"."); ncbytescat(projection,node->ocname); } /* Now, add the dimension info */ rank = nclistlength(var->array.dimset0); for(i=0;i<rank;i++) { CDFnode* dim = (CDFnode*)nclistget(var->array.dimset0,i); char tmp[32]; ncbytescat(projection,"["); snprintf(tmp,sizeof(tmp),"%lu",(unsigned long)dim->dim.declsize); ncbytescat(projection,tmp); ncbytescat(projection,"]"); } /* Define the attribute */ ncstat = nc_put_att_text(getncid(drno),var->ncid, "_projection", ncbyteslength(projection), ncbytescontents(projection)); return ncstat; }
char* makepathstring(NClist* path, const char* separator, int flags) { int i,len,first; NCbytes* pathname = NULL; char* result; CDFnode* node; len = nclistlength(path); ASSERT(len > 0); /* dataset at least */ if(len == 1) {/* dataset only */ node = (CDFnode*)nclistget(path,0); return nulldup(node->ncbasename); } pathname = ncbytesnew(); for(first=1,i=0;i<len;i++) { CDFnode* node = (CDFnode*)nclistget(path,i); char* name; if(!node->elided || (flags & PATHELIDE)==0) { if(node->nctype != NC_Dataset) { name = node->ncbasename; assert(name != NULL); if(!first) ncbytescat(pathname,separator); ncbytescat(pathname,name); first = 0; } } } result = ncbytesextract(pathname); ncbytesfree(pathname); return result; }
static void dumptreer(CDFnode* root, NCbytes* buf, int indent, int visible) { int i; char* primtype = NULL; if(visible && !root->visible) return; switch (root->nctype) { case NC_Dataset: dumptreer1(root,buf,indent,"Dataset",visible); break; case NC_Sequence: dumptreer1(root,buf,indent,"Sequence",visible); break; case NC_Structure: dumptreer1(root,buf,indent,"Structure",visible); break; case NC_Grid: dumptreer1(root,buf,indent,"Grid",visible); break; case NC_Primitive: switch (root->etype) { case NC_BYTE: primtype = "byte"; break; case NC_CHAR: primtype = "char"; break; case NC_SHORT: primtype = "short"; break; case NC_INT: primtype = "int"; break; case NC_FLOAT: primtype = "float"; break; case NC_DOUBLE: primtype = "double"; break; case NC_UBYTE: primtype = "ubyte"; break; case NC_USHORT: primtype = "ushort"; break; case NC_UINT: primtype = "uint"; break; case NC_INT64: primtype = "int64"; break; case NC_UINT64: primtype = "uint64"; break; case NC_STRING: primtype = "string"; break; default: break; } dumpindent(indent,buf); ncbytescat(buf,primtype); ncbytescat(buf," "); ncbytescat(buf,root->name); break; default: break; } if(nclistlength(root->array.dimensions) > 0) { for(i=0;i<nclistlength(root->array.dimensions);i++) { CDFnode* dim = (CDFnode*)nclistget(root->array.dimensions,i); char tmp[64]; ncbytescat(buf,"["); if(dim->name != NULL) { ncbytescat(buf,dim->name); ncbytescat(buf,"="); } snprintf(tmp,sizeof(tmp),"%lu",(unsigned long)dim->dim.declsize); ncbytescat(buf,tmp); ncbytescat(buf,"]"); } } ncbytescat(buf,";\n"); }
char* dumpselection1(NCselection* sel) { NCbytes* buf = ncbytesnew(); char* sstring; NClist* path = NULL; char* pathstring = NULL; int j; if(sel == NULL) return nulldup(""); path = sel->path; ncbytescat(buf,"&"); if(path == NULL) pathstring = makecdfpathstring3(sel->node,"."); else pathstring = simplepathstring3(path,"."); ncbytescat(buf,pathstring); efree(pathstring); ncbytescat(buf,opstrings[sel->operator]); ncbytescat(buf,"{"); for(j=0;j<nclistlength(sel->values);j++) { NCvalue* value = (NCvalue*)nclistget(sel->values,j); char tmp[64]; if(j > 0) ncbytescat(buf,","); switch (value->kind) { case ST_STR: ncbytescat(buf,value->value.text); break; case ST_INT: snprintf(tmp,sizeof(tmp),"%lld",value->value.intvalue); ncbytescat(buf,tmp); break; case ST_FLOAT: snprintf(tmp,sizeof(tmp),"%g",value->value.floatvalue); ncbytescat(buf,tmp); break; case ST_VAR: path = value->value.var.path; if(path == NULL) pathstring = makecdfpathstring3(value->value.var.node,"."); else pathstring = simplepathstring3(path,"."); ncbytescat(buf,pathstring); efree(pathstring); break; default: PANIC1("unexpected tag: %d",(int)value->kind); } } ncbytescat(buf,"}"); sstring = ncbytesdup(buf); ncbytesfree(buf); return sstring; }
char* dumpselection(NCselection* sel) { NCbytes* buf = ncbytesnew(); NCbytes* segbuf = ncbytesnew(); char* sstring; NClist* segments = NULL; int j; if(sel == NULL) return nulldup(""); segments = sel->lhs->var->segments; ncbytescat(buf,"&"); tostringncsegments(segments,segbuf); ncbytescat(buf,ncbytescontents(segbuf)); ncbytescat(buf,opstrings[sel->operator]); ncbytescat(buf,"{"); for(j=0;j<nclistlength(sel->rhs);j++) { NCvalue* value = (NCvalue*)nclistget(sel->rhs,j); NCconstant* con = value->constant; char tmp[64]; if(j > 0) ncbytescat(buf,","); switch (value->discrim) { case NS_STR: ncbytescat(buf,con->text); break; case NS_CONST: switch (con->discrim) { case NS_INT: snprintf(tmp,sizeof(tmp),"%lld",con->intvalue); ncbytescat(buf,tmp); break; case NS_FLOAT: snprintf(tmp,sizeof(tmp),"%g",con->floatvalue); ncbytescat(buf,tmp); break; default: PANIC1("unexpected discriminator %d",(int)con->discrim); } break; case NS_VAR: segments = value->var->segments; ncbytesclear(segbuf); tostringncsegments(segments,segbuf); ncbytescat(buf,ncbytescontents(segbuf)); break; default: PANIC1("unexpected discriminator %d",(int)value->discrim); } } ncbytescat(buf,"}"); sstring = ncbytesdup(buf); ncbytesfree(buf); ncbytesfree(segbuf); return sstring; }
static void dcedumprawlist(NClist* list, NCbytes* buf) { int i; if(list == NULL || buf == NULL) return; ncbytescat(buf,"("); for(i=0;i<nclistlength(list);i++) { DCEnode* node = (DCEnode*)nclistget(list,i); if(node == NULL) continue; if(i>0) ncbytescat(buf,","); dcedumpraw((DCEnode*)node,buf); } ncbytescat(buf,")"); }
char* dumpsegment(NCsegment* segment) { NCbytes* buf; char* result; if(segment == NULL) return nulldup("(nullsegment)"); buf = ncbytesnew(); ncbytescat(buf,(segment->segment?segment->segment:"(null)")); if(!segment->slicesdefined) ncbytescat(buf,dumpslices(segment->slices,segment->slicerank)); result = ncbytesdup(buf); ncbytesfree(buf); return result; }
char* dumpcache(NCcache* cache) { char* result = NULL; char tmp[8192]; int i; NCbytes* buf; if(cache == NULL) return strdup("cache{null}"); buf = ncbytesnew(); snprintf(tmp,sizeof(tmp),"cache{limit=%lu; size=%lu;\n", (unsigned long)cache->cachelimit, (unsigned long)cache->cachesize); ncbytescat(buf,tmp); if(cache->prefetch) { ncbytescat(buf,"\tprefetch="); ncbytescat(buf,dumpcachenode(cache->prefetch)); ncbytescat(buf,"\n"); } if(nclistlength(cache->nodes) > 0) { for(i=0;i<nclistlength(cache->nodes);i++) { NCcachenode* node = (NCcachenode*)nclistget(cache->nodes,i); ncbytescat(buf,"\t"); ncbytescat(buf,dumpcachenode(node)); ncbytescat(buf,"\n"); } } ncbytescat(buf,"}"); result = ncbytesdup(buf); ncbytesfree(buf); return result; }
static void atomicsToString(D4printer* out, union ATOMICS* value, nc_type type) { char tmp[256]; ncbytesclear(out->tmp); switch (type) { case NC_CHAR: snprintf(tmp,sizeof(tmp),"'%c'",value->i8[0]); break; case NC_BYTE: snprintf(tmp,sizeof(tmp),"%d",value->i8[0]); break; case NC_UBYTE: snprintf(tmp,sizeof(tmp),"%u",value->u8[0]); break; case NC_SHORT: snprintf(tmp,sizeof(tmp),"%d",value->i16[0]); break; case NC_USHORT: snprintf(tmp,sizeof(tmp),"%u",value->u16[0]); break; case NC_INT: snprintf(tmp,sizeof(tmp),"%d",value->i32[0]); break; case NC_UINT: snprintf(tmp,sizeof(tmp),"%u",value->u32[0]); break; case NC_INT64: snprintf(tmp,sizeof(tmp),"%lld",value->i64[0]); break; case NC_UINT64: snprintf(tmp,sizeof(tmp),"%llu",value->u64[0]); break; case NC_FLOAT: snprintf(tmp,sizeof(tmp),"%g",value->f32[0]); break; case NC_DOUBLE: snprintf(tmp,sizeof(tmp),"%g",value->f64[0]); break; case NC_STRING: ncbytescat(out->tmp,"\""); ncbytescat(out->tmp,value->s[0]); ncbytescat(out->tmp,"\""); break; default: abort(); } if(type != NC_STRING) ncbytescat(out->tmp,tmp); ncbytesnull(out->tmp); }
/* Convert an NCprojection instance into a string that can be used with the url */ char* dumpprojections(NClist* projections) { int i; NCbytes* buf = ncbytesnew(); char* pstring; for(i=0;i<nclistlength(projections);i++) { NCprojection* p = (NCprojection*)nclistget(projections,i); if(i > 0) ncbytescat(buf,","); ncbytescat(buf,dumpprojection1(p)); } pstring = ncbytesdup(buf); ncbytesfree(buf); return pstring; }
static void dumpindent(int indent, NCbytes* buf) { static char* indentstr = " "; int i; for(i=0;i<indent;i++) ncbytescat(buf,indentstr); }
static NCerror computeseqcountconstraints3(NCDAPCOMMON* dapcomm, CDFnode* seq, NCbytes* seqcountconstraints) { int i,j; NClist* path = NULL; CDFnode* var = NULL; ASSERT(seq->nctype == NC_Sequence); computeseqcountconstraints3r(dapcomm,seq,&var); ASSERT((var != NULL)); /* Compute var path */ path = nclistnew(); collectnodepath3(var,path,WITHOUTDATASET); /* construct the projection path using minimal index values */ for(i=0;i<nclistlength(path);i++) { CDFnode* node = (CDFnode*)nclistget(path,i); if(i > 0) ncbytescat(seqcountconstraints,"."); ncbytescat(seqcountconstraints,node->ocname); if(node == seq) { /* Use the limit */ if(node->sequencelimit > 0) { char tmp[64]; snprintf(tmp,sizeof(tmp),"[0:%lu]", (unsigned long)(node->sequencelimit - 1)); ncbytescat(seqcountconstraints,tmp); } } else if(nclistlength(node->array.dimset0) > 0) { int ndims = nclistlength(node->array.dimset0); for(j=0;j<ndims;j++) { CDFnode* dim = (CDFnode*)nclistget(node->array.dimset0,j); if(DIMFLAG(dim,CDFDIMSTRING)) { ASSERT((j == (ndims - 1))); break; } ncbytescat(seqcountconstraints,"[0]"); } } } /* Finally, add in any selection from the original URL */ if(dapcomm->oc.url->selection != NULL) ncbytescat(seqcountconstraints,dapcomm->oc.url->selection); nclistfree(path); return NC_NOERR; }
char* dumpprojection1(NCprojection* p) { int i; NCbytes* buf; char* pstring; if(p == NULL) return nulldup(""); buf = ncbytesnew(); for(i=0;i<nclistlength(p->segments);i++) { NCsegment* segment = (NCsegment*)nclistget(p->segments,i); char tmp[1024]; snprintf(tmp,sizeof(tmp),"%s%s/%lu", (i > 0?".":""), (segment->segment?segment->segment:"<unknown>"), (unsigned long)segment->slicerank); ncbytescat(buf,tmp); if(segment->slicesdefined) ncbytescat(buf,dumpslices(segment->slices,segment->slicerank)); else ncbytescat(buf,"[-]"); } if(iswholeprojection(p)) ncbytescat(buf,"*"); ncbytescat(buf,"("); if(p->leaf != NULL) ncbytescat(buf,p->leaf->name); ncbytescat(buf,")"); pstring = ncbytesdup(buf); ncbytesfree(buf); return pstring; }
/** * @internal Build _NCProperties attribute value. * * Convert a NCPROPINFO instance to a single string. * * @param info Properties info. * @param propdatap Pointer that gets properties string. * * @return ::NC_NOERR No error. * @return ::NC_EINVAL failed. * @author Dennis Heimbigner */ int NC4_buildpropinfo(struct NCPROPINFO* info, char** propdatap) { int stat = NC_NOERR; int i; NCbytes* buffer = NULL; char sversion[64]; LOG((3, "%s", __func__)); if(info == NULL || info->version == 0 || propdatap == NULL) {stat = NC_EINVAL; goto done;} *propdatap = NULL; buffer = ncbytesnew(); if(!buffer) {stat = NC_ENOMEM; goto done;} /* start with version */ ncbytescat(buffer,NCPVERSION); ncbytesappend(buffer,'='); snprintf(sversion,sizeof(sversion),"%d",info->version); ncbytescat(buffer,sversion); for(i=0;i<nclistlength(info->properties);i+=2) { char* value, *name; name = nclistget(info->properties,i); if(name == NULL) continue; value = nclistget(info->properties,i+1); ncbytesappend(buffer,NCPROPSSEP2); /* terminate last entry */ escapify(buffer,name); ncbytesappend(buffer,'='); escapify(buffer,value); } /* Force null termination */ ncbytesnull(buffer); *propdatap = ncbytesextract(buffer); done: if(buffer != NULL) ncbytesfree(buffer); return stat; }
char* dumppath(CDFnode* leaf) { NClist* path = nclistnew(); NCbytes* buf = ncbytesnew(); char* result; int i; if(leaf == NULL) return nulldup(""); collectnodepath3(leaf,path,!WITHDATASET); for(i=0;i<nclistlength(path);i++) { CDFnode* node = (CDFnode*)nclistget(path,i); if(i > 0) ncbytescat(buf,"."); ncbytescat(buf,node->name); } result = ncbytesdup(buf); ncbytesfree(buf); nclistfree(path); return result; }
void dcelisttobuffer(NClist* list, NCbytes* buf, char* sep) { int i; if(list == NULL || buf == NULL) return; if(sep == NULL) sep = ","; for(i=0;i<nclistlength(list);i++) { DCEnode* node = (DCEnode*)nclistget(list,i); if(i>0) ncbytescat(buf,sep); dcetobuffer((DCEnode*)node,buf); } }
char* makeocpathstring(OClink conn, OCddsnode node, const char* sep) { int i,len,first; char* result; char* name; OCtype octype; NClist* ocpath = NULL; NCbytes* pathname = NULL; /* If we are asking for the dataset path only, then include it, otherwise elide it */ oc_dds_type(conn,node,&octype); if(octype == OC_Dataset) { oc_dds_name(conn,node,&name); return nulldup(name); } ocpath = nclistnew(); collectocpath(conn,node,ocpath); len = nclistlength(ocpath); assert(len > 0); /* dataset at least */ pathname = ncbytesnew(); for(first=1,i=1;i<len;i++) { /* start at 1 to skip dataset name */ OCddsnode node = (OCddsnode)nclistget(ocpath,i); char* name; oc_dds_type(conn,node,&octype); oc_dds_name(conn,node,&name); if(!first) ncbytescat(pathname,sep); ncbytescat(pathname,name); nullfree(name); first = 0; } result = ncbytesextract(pathname); ncbytesfree(pathname); nclistfree(ocpath); return result; }
static void dumptreer1(CDFnode* root, NCbytes* buf, int indent, char* tag, int visible) { int i; dumpindent(indent,buf); ncbytescat(buf,tag); ncbytescat(buf," {\n"); for(i=0;i<nclistlength(root->subnodes);i++) { CDFnode* node = (CDFnode*)nclistget(root->subnodes,i); if(visible && !root->visible) continue; if(root->nctype == NC_Grid) { if(i==0) { dumpindent(indent+1,buf); ncbytescat(buf,"Array:\n"); } else if(i==1) { dumpindent(indent+1,buf); ncbytescat(buf,"Maps:\n"); } dumptreer(node,buf,indent+2,visible); } else { dumptreer(node,buf,indent+1,visible); } } dumpindent(indent,buf); ncbytescat(buf,"} "); ncbytescat(buf,root->name); }
char* dumpconstraint(NCconstraint* con) { NCbytes* buf = ncbytesnew(); char* result = NULL; if(nclistlength(con->projections)==0 && nclistlength(con->selections)==0) goto done; if(nclistlength(con->projections) > 0) { char* pstring = dumpprojections(con->projections); ncbytescat(buf,pstring); efree(pstring); } if(nclistlength(con->selections) > 0) { char* sstring = dumpselections(con->selections); ncbytescat(buf,sstring); efree(sstring); } done: result = ncbytesdup(buf); ncbytesfree(buf); return result; }
static int readfile(NCD4INFO* state, const NCURI* uri, const char* suffix, NCbytes* packet) { int stat = NC_NOERR; NCbytes* tmp = ncbytesnew(); char* filename = NULL; ncbytescat(tmp,uri->path); if(suffix != NULL) ncbytescat(tmp,suffix); ncbytesnull(tmp); filename = ncbytesextract(tmp); ncbytesfree(tmp); #ifdef HAVE_GETTIMEOFDAY struct timeval time0; struct timeval time1; #endif state->fileproto.filename = filename; /* filename is alloc'd here anyway */ if(FLAGSET(state->controls.flags,NCF_SHOWFETCH)) { char* surl = NULL; #ifdef HAVE_GETTIMEOFDAY gettimeofday(&time0,NULL); #endif surl = ncuribuild((NCURI*)uri,NULL,NULL,NCURIALL); nclog(NCLOGDBG,"fetch uri=%s file=%s",surl,filename); } stat = NC_readfile(filename,packet); if(FLAGSET(state->controls.flags,NCF_SHOWFETCH)) { double secs; #ifdef HAVE_GETTIMEOFDAY gettimeofday(&time1,NULL); secs = deltatime(time0,time1); #endif nclog(NCLOGDBG,"fetch complete: %0.3f",secs); } return THROW(stat); }
char* dumpslices(DCEslice* slice, unsigned int rank) { int i; NCbytes* buf; char* result = NULL; buf = ncbytesnew(); for(i=0;i<rank;i++,slice++) { ncbytescat(buf,dumpslice(slice)); } result = ncbytesdup(buf); ncbytesfree(buf); return result; }
char* dumpsegments(NClist* segments) { int i; NCbytes* buf = ncbytesnew(); char* sstring; if(nclistlength(segments) == 0) return nulldup(""); for(i=0;i<nclistlength(segments);i++) { NCsegment* seg = (NCsegment*)nclistget(segments,i); ncbytescat(buf,dumpsegment(seg)); } sstring = ncbytesdup(buf); ncbytesfree(buf); return sstring; }
/* Provide detailed data on a CDFnode */ char* dumpnode(CDFnode* node) { NCbytes* buf = ncbytesnew(); char* result; int i; char* nctype = NULL; char* primtype = NULL; char tmp[1024]; switch (node->nctype) { case NC_Dataset: nctype = "Dataset"; break; case NC_Sequence: nctype = "Sequence"; break; case NC_Structure: nctype = "Structure"; break; case NC_Grid: nctype = "Grid"; break; case NC_Primitive: switch (node->etype) { case NC_BYTE: primtype = "byte"; break; case NC_CHAR: primtype = "char"; break; case NC_SHORT: primtype = "short"; break; case NC_INT: primtype = "int"; break; case NC_FLOAT: primtype = "float"; break; case NC_DOUBLE: primtype = "double"; break; case NC_UBYTE: primtype = "ubyte"; break; case NC_USHORT: primtype = "ushort"; break; case NC_UINT: primtype = "uint"; break; case NC_INT64: primtype = "int64"; break; case NC_UINT64: primtype = "uint64"; break; case NC_STRING: primtype = "string"; break; default: break; } break; default: break; } snprintf(tmp,sizeof(tmp),"%s %s {\n", (nctype?nctype:primtype),node->name); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"dds=%lx\n",(unsigned long)node->dds); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"container=%s\n", (node->container?node->container->name:"null")); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"root=%s\n", (node->root?node->root->name:"null")); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"ncbasename=%s\n",node->ncbasename); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"ncfullname=%s\n",node->ncfullname); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"|subnodes|=%d\n",nclistlength(node->subnodes)); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"externaltype=%d\n",node->externaltype); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"ncid=%d\n",node->ncid); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"maxstringlength=%ld\n",node->maxstringlength); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"sequencelimit=%ld\n",node->sequencelimit); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"usesequence=%d\n",node->usesequence); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"elided=%d\n",node->elided); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"visible=%d\n",node->visible); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"attachment=%s\n", (node->attachment?node->attachment->name:"null")); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp),"rank=%u\n",nclistlength(node->array.dimensions)); ncbytescat(buf,tmp); for(i=0;i<nclistlength(node->array.dimensions);i++) { CDFnode* dim = (CDFnode*)nclistget(node->array.dimensions,i); snprintf(tmp,sizeof(tmp),"dims[%d]={\n",i); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp)," name=%s\n",dim->name); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp)," dimflags=%u\n", (unsigned int)dim->dim.dimflags); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp)," declsize=%lu\n", (unsigned long)dim->dim.declsize); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp)," declsize0=%lu\n", (unsigned long)dim->dim.declsize0); ncbytescat(buf,tmp); snprintf(tmp,sizeof(tmp)," }\n"); ncbytescat(buf,tmp); } result = ncbytesdup(buf); ncbytesfree(buf); return result; }
/* Compute the set of prefetched data */ NCerror prefetchdata4(NCDRNO* drno) { int i,j; NCerror ncstat = NC_NOERR; NClist* allvars = drno->cdf.varnodes; NCconstraint* constraint = &drno->dap.constraint; NClist* vars = nclistnew(); NCcachenode* cache = NULL; NCconstraint newconstraint; /* If caching is off, and we can do constraints, then don't even do prefetch */ if(!FLAGSET(drno,NCF_CACHE) && !FLAGSET(drno,NCF_UNCONSTRAINABLE)) { drno->cdf.cache.prefetch = NULL; goto done; } for(i=0;i<nclistlength(allvars);i++) { CDFnode* var = (CDFnode*)nclistget(allvars,i); size_t nelems = 1; /* Compute the # of elements in the variable */ for(j=0;j<nclistlength(var->array.dimensions);j++) { CDFnode* dim = (CDFnode*)nclistget(var->array.dimensions,j); nelems *= dim->dim.declsize; } /* If we cannot constrain, then pull in everything */ if(FLAGSET(drno,NCF_UNCONSTRAINABLE) || nelems <= drno->cdf.smallsizelimit) nclistpush(vars,(ncelem)var); } /* If we cannot constrain, then pull in everything */ if(FLAGSET(drno,NCF_UNCONSTRAINABLE)) { newconstraint.projections = NULL; newconstraint.selections= NULL; } else { /* Construct the projections for this set of vars */ /* Construct the projections for this set of vars */ /* Initially, the constraints are same as the merged constraints */ newconstraint.projections = cloneprojections(constraint->projections); restrictprojection3(drno,vars,newconstraint.projections); /* similar for selections */ newconstraint.selections = cloneselections(constraint->selections); } ncstat = buildcachenode3(drno,&newconstraint,vars,&cache,0); if(ncstat) goto done; if(FLAGSET(drno,NCF_SHOWFETCH)) { /* Log the set of prefetch variables */ NCbytes* buf = ncbytesnew(); ncbytescat(buf,"prefetch.vars: "); for(i=0;i<nclistlength(vars);i++) { CDFnode* var = (CDFnode*)nclistget(vars,i); ncbytescat(buf," "); ncbytescat(buf,makesimplepathstring3(var)); } ncbytescat(buf,"\n"); oc_log(OCLOGNOTE,ncbytescontents(buf)); ncbytesfree(buf); } done: if(ncstat) { freenccachenode(drno,cache); } return THROW(ncstat); }
/* Compute the set of prefetched data. Notes: 1. All prefetches are whole variable fetches. 2. If the data set is unconstrainable, we will prefetch the whole thing */ NCerror prefetchdata3(NCDAPCOMMON* nccomm) { int i; NCFLAGS flags; NCerror ncstat = NC_NOERR; NClist* allvars = nccomm->cdf.ddsroot->tree->varnodes; DCEconstraint* urlconstraint = nccomm->oc.dapconstraint; NClist* vars = nclistnew(); NCcachenode* cache = NULL; DCEconstraint* newconstraint = NULL; if(FLAGSET(nccomm->controls,NCF_UNCONSTRAINABLE)) { /* If we cannot constrain and caching is enabled, then pull in everything */ if(FLAGSET(nccomm->controls,NCF_CACHE)) { for(i=0;i<nclistlength(allvars);i++) { nclistpush(vars,nclistget(allvars,i)); } } else { /* do no prefetching */ nccomm->cdf.cache->prefetch = NULL; goto done; } } else { /* pull in those variables previously marked as prefetchable */ for(i=0;i<nclistlength(allvars);i++) { CDFnode* var = (CDFnode*)nclistget(allvars,i); /* Most of the important testing was already done */ if(!var->basenode->prefetchable) continue; /* Do not attempt to prefetch any variables in the nc_open url's projection list */ if(nclistcontains(nccomm->cdf.projectedvars,(void*)var)) continue; /* Should be prefetchable */ nclistpush(vars,(void*)var); if(SHOWFETCH) { nclog(NCLOGDBG,"prefetch: %s",var->ncfullname); } } } /* If there are no vars, then do nothing */ if(nclistlength(vars) == 0) { nccomm->cdf.cache->prefetch = NULL; goto done; } /* Create a single constraint consisting of the projections for the variables; each projection is whole variable. The selections are passed on as is. The exception is if we are prefetching everything. */ newconstraint = (DCEconstraint*)dcecreate(CES_CONSTRAINT); newconstraint->projections = nclistnew(); newconstraint->selections = dceclonelist(urlconstraint->selections); for(i=0;i<nclistlength(vars);i++) { CDFnode* var = (CDFnode*)nclistget(vars,i); DCEprojection* varprojection; /* convert var to a projection */ ncstat = dapvar2projection(var,&varprojection); if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto done;} nclistpush(newconstraint->projections,(void*)varprojection); } if(SHOWFETCH) { char* s = dumpprojections(newconstraint->projections); LOG1(NCLOGNOTE,"prefetch.final: %s",s); nullfree(s); } flags = NCF_PREFETCH; if(nclistlength(allvars) == nclistlength(vars)) flags |= NCF_PREFETCH_ALL; ncstat = buildcachenode34(nccomm,newconstraint,vars,&cache,flags); newconstraint = NULL; /* buildcachenode34 takes control of newconstraint */ if(ncstat) goto done; cache->wholevariable = 1; /* All prefetches are whole variable */ /* Make cache node be the prefetch node */ nccomm->cdf.cache->prefetch = cache; if(SHOWFETCH) { LOG0(NCLOGNOTE,"prefetch.complete"); } if(SHOWFETCH) { char* s = NULL; /* Log the set of prefetch variables */ NCbytes* buf = ncbytesnew(); ncbytescat(buf,"prefetch.vars: "); for(i=0;i<nclistlength(vars);i++) { CDFnode* var = (CDFnode*)nclistget(vars,i); ncbytescat(buf," "); s = makecdfpathstring3(var,"."); ncbytescat(buf,s); nullfree(s); } ncbytescat(buf,"\n"); nclog(NCLOGNOTE,"%s",ncbytescontents(buf)); ncbytesfree(buf); } done: nclistfree(vars); dcefree((DCEnode*)newconstraint); if(ncstat) freenccachenode(nccomm,cache); return THROW(ncstat); }
void dcetobuffer(DCEnode* node, NCbytes* buf) { int i; char tmp[1024]; if(buf == NULL) return; if(node == NULL) {ncbytesappend(buf,'?'); return;} switch (node->sort) { case CES_SLICE: { DCEslice* slice = (DCEslice*)node; size_t last = (slice->first+slice->length)-1; if(last > slice->declsize && slice->declsize > 0) last = slice->declsize - 1; if(slice->count == 1) { snprintf(tmp,sizeof(tmp),"[%lu]", (unsigned long)slice->first); } else if(slice->stride == 1) { snprintf(tmp,sizeof(tmp),"[%lu:%lu]", (unsigned long)slice->first, (unsigned long)last); } else { snprintf(tmp,sizeof(tmp),"[%lu:%lu:%lu]", (unsigned long)slice->first, (unsigned long)slice->stride, (unsigned long)last); } ncbytescat(buf,tmp); } break; case CES_SEGMENT: { DCEsegment* segment = (DCEsegment*)node; int rank = segment->rank; char* name = (segment->name?segment->name:"<unknown>"); ncbytescat(buf,nulldup(name)); if(!dceiswholesegment(segment)) { for(i=0;i<rank;i++) { DCEslice* slice = segment->slices+i; dcetobuffer((DCEnode*)slice,buf); } } } break; case CES_VAR: { DCEvar* var = (DCEvar*)node; dcelisttobuffer(var->segments,buf,"."); } break; case CES_FCN: { DCEfcn* fcn = (DCEfcn*)node; ncbytescat(buf,fcn->name); ncbytescat(buf,"("); dcelisttobuffer(fcn->args,buf,","); ncbytescat(buf,")"); } break; case CES_CONST: { DCEconstant* value = (DCEconstant*)node; switch (value->discrim) { case CES_STR: ncbytescat(buf,value->text); break; case CES_INT: snprintf(tmp,sizeof(tmp),"%lld",value->intvalue); ncbytescat(buf,tmp); break; case CES_FLOAT: snprintf(tmp,sizeof(tmp),"%g",value->floatvalue); ncbytescat(buf,tmp); break; default: assert(0); } } break; case CES_VALUE: { DCEvalue* value = (DCEvalue*)node; switch (value->discrim) { case CES_CONST: dcetobuffer((DCEnode*)value->constant,buf); break; case CES_VAR: dcetobuffer((DCEnode*)value->var,buf); break; case CES_FCN: dcetobuffer((DCEnode*)value->fcn,buf); break; default: assert(0); } } break; case CES_PROJECT: { DCEprojection* target = (DCEprojection*)node; switch (target->discrim) { case CES_VAR: dcetobuffer((DCEnode*)target->var,buf); break; case CES_FCN: dcetobuffer((DCEnode*)target->fcn,buf); break; default: assert(0); } } break; case CES_SELECT: { DCEselection* sel = (DCEselection*)node; dcetobuffer((DCEnode*)sel->lhs,buf); if(sel->operator == CES_NIL) break; ncbytescat(buf,opstrings[(int)sel->operator]); if(nclistlength(sel->rhs) > 1) ncbytescat(buf,"{"); dcelisttobuffer(sel->rhs,buf,","); if(nclistlength(sel->rhs) > 1) ncbytescat(buf,"}"); } break; case CES_CONSTRAINT: { DCEconstraint* con = (DCEconstraint*)node; if(con->projections != NULL && nclistlength(con->projections) > 0) { dcelisttobuffer(con->projections,buf,","); } if(con->selections != NULL && nclistlength(con->selections) > 0) { ncbytescat(buf,"&"); /* because & is really a prefix */ dcelisttobuffer(con->selections,buf,"&"); } } break; case CES_NIL: { ncbytescat(buf,"<nil>"); } break; default: assert(0); } }
static void dcedumpraw(DCEnode* node, NCbytes* buf) { int i; char tmp[1024]; if(buf == NULL) return; if(node == NULL) {ncbytescat(buf,"<null>"); return;} ncbytescat(buf,LBRACE); ncbytescat(buf,(char*)dcesortname(node->sort)); switch (node->sort) { case CES_SLICE: { DCEslice* slice = (DCEslice*)node; snprintf(tmp,sizeof(tmp), " [first=%lu stride=%lu last=%lu len=%lu count=%lu size=%lu]", (unsigned long)slice->first, (unsigned long)slice->stride, (unsigned long)slice->last, (unsigned long)slice->length, (unsigned long)slice->count, (unsigned long)slice->declsize); ncbytescat(buf,tmp); } break; case CES_SEGMENT: { DCEsegment* segment = (DCEsegment*)node; int rank = segment->rank; char* name = (segment->name?segment->name:"<unknown>"); ncbytescat(buf," name="); ncbytescat(buf,name); snprintf(tmp,sizeof(tmp)," rank=%lu",(unsigned long)rank); ncbytescat(buf,tmp); ncbytescat(buf," defined="); ncbytescat(buf,(segment->slicesdefined?"1":"0")); ncbytescat(buf," declized="); ncbytescat(buf,(segment->slicesdeclized?"1":"0")); if(rank > 0) { ncbytescat(buf," slices="); for(i=0;i<rank;i++) { DCEslice* slice = segment->slices+i; dcedumpraw((DCEnode*)slice,buf); } } } break; case CES_VAR: { DCEvar* var = (DCEvar*)node; ncbytescat(buf," segments="); dcedumprawlist(var->segments,buf); } break; case CES_FCN: { DCEfcn* fcn = (DCEfcn*)node; ncbytescat(buf," name="); ncbytescat(buf,fcn->name); ncbytescat(buf,"args="); dcedumprawlist(fcn->args,buf); } break; case CES_CONST: { DCEconstant* value = (DCEconstant*)node; ncbytescat(buf," discrim="); ncbytescat(buf,dcesortname(value->discrim)); ncbytescat(buf," value="); switch (value->discrim) { case CES_STR: ncbytescat(buf,"|"); ncbytescat(buf,value->text); ncbytescat(buf,"|"); break; case CES_INT: snprintf(tmp,sizeof(tmp),"%lld",value->intvalue); ncbytescat(buf,tmp); break; case CES_FLOAT: snprintf(tmp,sizeof(tmp),"%g",value->floatvalue); ncbytescat(buf,tmp); break; default: assert(0); } } break; case CES_VALUE: { DCEvalue* value = (DCEvalue*)node; ncbytescat(buf," discrim="); ncbytescat(buf,dcesortname(value->discrim)); switch (value->discrim) { case CES_CONST: dcedumpraw((DCEnode*)value->constant,buf); break; case CES_VAR: dcedumpraw((DCEnode*)value->var,buf); break; case CES_FCN: dcedumpraw((DCEnode*)value->fcn,buf); break; default: assert(0); } } break; case CES_PROJECT: { DCEprojection* target = (DCEprojection*)node; ncbytescat(buf," discrim="); ncbytescat(buf,dcesortname(target->discrim)); switch (target->discrim) { case CES_VAR: dcedumpraw((DCEnode*)target->var,buf); break; case CES_FCN: dcedumpraw((DCEnode*)target->fcn,buf); break; default: assert(0); } } break; case CES_SELECT: { DCEselection* sel = (DCEselection*)node; ncbytescat(buf," "); dcedumpraw((DCEnode*)sel->lhs,buf); if(sel->operator == CES_NIL) break; ncbytescat(buf,opstrings[(int)sel->operator]); if(nclistlength(sel->rhs) > 1) ncbytescat(buf,"{"); dcedumprawlist(sel->rhs,buf); if(nclistlength(sel->rhs) > 1) ncbytescat(buf,"}"); } break; case CES_CONSTRAINT: { DCEconstraint* con = (DCEconstraint*)node; if(con->projections != NULL && nclistlength(con->projections) > 0) { ncbytescat(buf,"projections="); dcedumprawlist(con->projections,buf); } if(con->selections != NULL && nclistlength(con->selections) > 0) { ncbytescat(buf,"selections="); dcedumprawlist(con->selections,buf); } } break; case CES_NIL: { ncbytescat(buf,"<nil>"); } break; default: assert(0); } ncbytescat(buf,RBRACE); }
char* ncuribuild(NCURI* duri, const char* prefix, const char* suffix, int flags) { char* newuri = NULL; NCbytes* buf = ncbytesnew(); #ifdef NEWESCAPE const int encode = (flags&NCURIENCODE ? 1 : 0); #else const int encode = 0; #endif if(prefix != NULL) ncbytescat(buf,prefix); ncbytescat(buf,duri->protocol); ncbytescat(buf,"://"); /* this will produce file:///... */ if((flags & NCURIPWD) && duri->user != NULL && duri->password != NULL) { /* The user and password must be encoded */ char* encoded = ncuriencodeonly(duri->user,userpwdallow); ncbytescat(buf,encoded); nullfree(encoded); ncbytescat(buf,":"); encoded = ncuriencodeonly(duri->password,userpwdallow); ncbytescat(buf,encoded); nullfree(encoded); ncbytescat(buf,"@"); } if(duri->host != NULL) ncbytescat(buf,duri->host); if(duri->port != NULL) { ncbytescat(buf,":"); ncbytescat(buf,duri->port); } if((flags & NCURIPATH)) { if(duri->path == NULL) ncbytescat(buf,"/"); else if(encode) { char* encoded = ncuriencodeonly(duri->path,pathallow); ncbytescat(buf,encoded); nullfree(encoded); } else ncbytescat(buf,duri->path); } /* The suffix is intended to some kind of path extension (e.g. .dds) so insert here */ if(suffix != NULL) ncbytescat(buf,suffix); if((flags & NCURIQUERY) && duri->querylist != NULL) { char** p; int first = 1; for(p=duri->querylist;*p;p+=2,first=0) { ncbytescat(buf,(first?"?":"&")); ncbytescat(buf,p[0]); if(p[1] != NULL && strlen(p[1]) > 0) { ncbytescat(buf,"="); if(encode) { char* encoded = ncuriencodeonly(p[1],queryallow); ncbytescat(buf,encoded); nullfree(encoded); } else ncbytescat(buf,p[1]); } } } if((flags & NCURIFRAG) && duri->fraglist != NULL) { char** p; int first = 1; for(p=duri->fraglist;*p;p+=2,first=0) { ncbytescat(buf,(first?"#":"&")); ncbytescat(buf,p[0]); if(p[1] != NULL && strlen(p[1]) > 0) { ncbytescat(buf,"="); if(encode) { char* encoded = ncuriencodeonly(p[1],queryallow); ncbytescat(buf,encoded); nullfree(encoded); } else ncbytescat(buf,p[1]); } } } ncbytesnull(buf); newuri = ncbytesextract(buf); ncbytesfree(buf); return newuri; }
static NCerror buildglobalattrs3(NCDAPCOMMON* dapcomm, CDFnode* root) { int i; NCerror ncstat = NC_NOERR; const char* txt; char *nltxt, *p; NCbytes* buf = NULL; NClist* cdfnodes; NC* drno = dapcomm->controller; if(root->attributes != NULL) { for(i=0;i<nclistlength(root->attributes);i++) { NCattribute* att = (NCattribute*)nclistget(root->attributes,i); ncstat = buildattribute3a(dapcomm,att,NC_NAT,NC_GLOBAL); if(ncstat != NC_NOERR) goto done; } } /* Add global attribute identifying the sequence dimensions */ if(paramcheck34(dapcomm,"show","seqdims")) { buf = ncbytesnew(); cdfnodes = dapcomm->cdf.ddsroot->tree->nodes; for(i=0;i<nclistlength(cdfnodes);i++) { CDFnode* dim = (CDFnode*)nclistget(cdfnodes,i); if(dim->nctype != NC_Dimension) continue; if(DIMFLAG(dim,CDFDIMSEQ)) { char* cname = cdflegalname3(dim->ocname); if(ncbyteslength(buf) > 0) ncbytescat(buf,", "); ncbytescat(buf,cname); nullfree(cname); } } if(ncbyteslength(buf) > 0) { ncstat = nc_put_att_text(drno->substrate,NC_GLOBAL,"_sequence_dimensions", ncbyteslength(buf),ncbytescontents(buf)); } } /* Define some additional system global attributes depending on show= clientparams*/ /* Ignore failures*/ if(paramcheck34(dapcomm,"show","translate")) { /* Add a global attribute to show the translation */ ncstat = nc_put_att_text(drno->substrate,NC_GLOBAL,"_translate", strlen("netcdf-3"),"netcdf-3"); } if(paramcheck34(dapcomm,"show","url")) { if(dapcomm->oc.rawurltext != NULL) ncstat = nc_put_att_text(drno->substrate,NC_GLOBAL,"_url", strlen(dapcomm->oc.rawurltext),dapcomm->oc.rawurltext); } if(paramcheck34(dapcomm,"show","dds")) { txt = NULL; if(dapcomm->cdf.ddsroot != NULL) txt = oc_inq_text(dapcomm->oc.conn,dapcomm->cdf.ddsroot->ocnode); if(txt != NULL) { /* replace newlines with spaces*/ nltxt = nulldup(txt); for(p=nltxt;*p;p++) {if(*p == '\n' || *p == '\r' || *p == '\t') {*p = ' ';}}; ncstat = nc_put_att_text(drno->substrate,NC_GLOBAL,"_dds",strlen(nltxt),nltxt); nullfree(nltxt); } } if(paramcheck34(dapcomm,"show","das")) { txt = NULL; if(dapcomm->oc.ocdasroot != OCNULL) txt = oc_inq_text(dapcomm->oc.conn,dapcomm->oc.ocdasroot); if(txt != NULL) { nltxt = nulldup(txt); for(p=nltxt;*p;p++) {if(*p == '\n' || *p == '\r' || *p == '\t') {*p = ' ';}}; ncstat = nc_put_att_text(drno->substrate,NC_GLOBAL,"_das",strlen(nltxt),nltxt); nullfree(nltxt); } } done: ncbytesfree(buf); return THROW(ncstat); }