char* dcetostring(DCEnode* node) { char* s; NCbytes* buf = ncbytesnew(); dcetobuffer(node,buf); s = ncbytesextract(buf); ncbytesfree(buf); return s; }
char* dcelisttostring(NClist* list, char* sep) { char* s; NCbytes* buf = ncbytesnew(); dcelisttobuffer(list,buf,sep); s = ncbytesextract(buf); ncbytesfree(buf); return s; }
char* buildselectionstring(NClist* selections) { NCbytes* buf = ncbytesnew(); char* sstring; dcelisttobuffer(selections,buf,","); sstring = ncbytesdup(buf); ncbytesfree(buf); return sstring; }
char* buildconstraintstring(DCEconstraint* constraints) { NCbytes* buf = ncbytesnew(); char* result = NULL; dcetobuffer((DCEnode*)constraints,buf); result = ncbytesdup(buf); ncbytesfree(buf); return result; }
char* dumpvisible(CDFnode* root) { NCbytes* buf = ncbytesnew(); char* result; dumptreer(root,buf,0,1); result = ncbytesdup(buf); ncbytesfree(buf); return result; }
char* dcerawlisttostring(NClist* list) { char* s; NCbytes* buf = ncbytesnew(); dcedumprawlist(list,buf); s = ncbytesextract(buf); ncbytesfree(buf); return s; }
/* Mostly for debugging */ char* dcerawtostring(void* node) { char* s; NCbytes* buf = ncbytesnew(); dcedumpraw((DCEnode*)node,buf); s = ncbytesextract(buf); ncbytesfree(buf); return s; }
char* buildprojectionstring3(NClist* projections) { char* pstring; NCbytes* buf = ncbytesnew(); dcelisttobuffer(projections,buf,","); pstring = ncbytesdup(buf); ncbytesfree(buf); return pstring; }
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; }
int NCD4_print(NCD4meta* metadata, NCbytes* output) { int ret = NC_NOERR; D4printer out; if(metadata == NULL || output == NULL) return THROW(NC_EINVAL); out.out = output; out.tmp = ncbytesnew(); out.metadata = metadata; ret = printNode(&out,metadata->root,0); ncbytesfree(out.tmp); return THROW(ret); }
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* 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; }
/* 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; }
void dcelexcleanup(DCElexstate** lexstatep) { DCElexstate* lexstate = *lexstatep; if(lexstate == NULL) return; if(lexstate->input != NULL) free(lexstate->input); if(lexstate->reclaim != NULL) { while(nclistlength(lexstate->reclaim) > 0) { char* word = (char*)nclistpop(lexstate->reclaim); if(word) free(word); } nclistfree(lexstate->reclaim); } ncbytesfree(lexstate->yytext); free(lexstate); *lexstatep = NULL; }
/** * @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; }
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; }
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); }
/* 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); }
/* 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; }
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); }
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; }
/* 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); }
static NCerror getseqdimsize(NCDAPCOMMON* dapcomm, CDFnode* seq, size_t* sizep) { NCerror ncstat = NC_NOERR; OCerror ocstat = OC_NOERR; OClink conn = dapcomm->oc.conn; OCdatanode rootcontent = NULL; OCddsnode ocroot; CDFnode* dxdroot; CDFnode* xseq; NCbytes* seqcountconstraints = ncbytesnew(); size_t seqsize; /* Read the minimal amount of data in order to get the count */ /* If the url is unconstrainable, then get the whole thing */ computeseqcountconstraints3(dapcomm,seq,seqcountconstraints); #ifdef DEBUG fprintf(stderr,"seqcountconstraints: %s\n",ncbytescontents(seqcountconstraints)); #endif /* Fetch the minimal data */ if(FLAGSET(dapcomm->controls,NCF_UNCONSTRAINABLE)) ocstat = dap_fetch(dapcomm,conn,NULL,OCDATADDS,&ocroot); else ocstat = dap_fetch(dapcomm,conn,ncbytescontents(seqcountconstraints),OCDATADDS,&ocroot); if(ocstat) goto fail; ncstat = buildcdftree34(dapcomm,ocroot,OCDATA,&dxdroot); if(ncstat) goto fail; /* attach DATADDS to DDS */ ncstat = attach34(dxdroot,seq); if(ncstat) goto fail; /* WARNING: we are now switching to datadds tree */ xseq = seq->attachment; ncstat = countsequence(dapcomm,xseq,&seqsize); if(ncstat) goto fail; #ifdef DEBUG fprintf(stderr,"sequencesize: %s = %lu\n",seq->ocname,(unsigned long)seqsize); #endif /* throw away the fetch'd trees */ unattach34(dapcomm->cdf.ddsroot); freecdfroot34(dxdroot); if(ncstat != NC_NOERR) { /* Cannot get DATADDDS*/ char* code; char* msg; long httperr; oc_svcerrordata(dapcomm->oc.conn,&code,&msg,&httperr); if(code != NULL) { nclog(NCLOGERR,"oc_fetch_datadds failed: %s %s %l", code,msg,httperr); } ocstat = OC_NOERR; } if(sizep) *sizep = seqsize; fail: ncbytesfree(seqcountconstraints); oc_data_free(conn,rootcontent); if(ocstat) ncstat = ocerrtoncerr(ocstat); return ncstat; }
/* Compute the set of prefetched data; note that even if caching is off, we will still prefetch the small variables. */ NCerror prefetchdata3(NCDAPCOMMON* nccomm) { int i,j; NCerror ncstat = NC_NOERR; NClist* allvars = nccomm->cdf.varnodes; NCconstraint* constraint = nccomm->oc.dapconstraint; NClist* vars = nclistnew(); NCcachenode* cache = NULL; NCconstraint* newconstraint = NULL; /* Check if we can do constraints */ if(FLAGSET(nccomm->controls,NCF_UNCONSTRAINABLE)) { /*cannot constrain*/ /* If we cannot constrain, then pull in everything */ for(i=0;i<nclistlength(allvars);i++) { nclistpush(vars,nclistget(allvars,i)); } } else { /* can do constraints */ /* pull in those variables of sufficiently small size */ for(i=0;i<nclistlength(allvars);i++) { CDFnode* var = (CDFnode*)nclistget(allvars,i); size_t nelems = 1; /* If var is a sequence or under a sequence, then never prefetch */ if(var->nctype == NC_Sequence || dapinsequence(var)) continue; /* 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(nelems <= nccomm->cdf.smallsizelimit) nclistpush(vars,(ncelem)var); } } /* If there are no vars, then do nothing */ if(nclistlength(vars) == 0) { nccomm->cdf.cache->prefetch = NULL; goto done; } newconstraint = createncconstraint(); /* Construct the projections for this set of vars */ /* Initially, the constraints are same as the merged constraints */ newconstraint->projections = clonencprojections(constraint->projections); restrictprojection34(vars,newconstraint->projections); /* similar for selections */ newconstraint->selections = clonencselections(constraint->selections); ncstat = buildcachenode34(nccomm,newconstraint,vars,&cache,1); if(ncstat) goto done; cache->wholevariable = 1; /* All prefetches are whole variable */ if(FLAGSET(nccomm->controls,NCF_SHOWFETCH)) { oc_log(OCLOGNOTE,"prefetch."); } #ifdef DEBUG /* 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,"%s",ncbytescontents(buf)); ncbytesfree(buf); #endif /* Make cache node be the prefetch node */ nccomm->cdf.cache->prefetch = cache; done: nclistfree(vars); freencconstraint(newconstraint); if(ncstat) freenccachenode(nccomm,cache); return THROW(ncstat); }
/* Compute the set of prefetched data. Notes: 1. Even if caching is off, we will still prefetch the small variables. 2. All prefetches are whole variable fetches. 3. If the data set is unconstrainable, we will prefetch the whole thing */ NCerror prefetchdata3(NCDAPCOMMON* nccomm) { int i,j; NCerror ncstat = NC_NOERR; NClist* allvars = nccomm->cdf.varnodes; DCEconstraint* urlconstraint = nccomm->oc.dapconstraint; NClist* vars = nclistnew(); NCcachenode* cache = NULL; DCEconstraint* newconstraint = NULL; int isnc4 = FLAGSET(nccomm->controls,NCF_NC4); 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 { /* can do constraints */ /* pull in those variables of sufficiently small size */ for(i=0;i<nclistlength(allvars);i++) { CDFnode* var = (CDFnode*)nclistget(allvars,i); size_t nelems = 1; if(!isnc4) { /* If netcdf 3 and var is a sequence or under a sequence, then never prefetch */ if(var->nctype == NC_Sequence || dapinsequence(var)) continue; } /* Compute the # of elements in the variable */ for(j=0;j<nclistlength(var->array.dimset0);j++) { CDFnode* dim = (CDFnode*)nclistget(var->array.dimset0,j); nelems *= dim->dim.declsize; } if(SHOWFETCH) { nclog(NCLOGDBG,"prefetch: %s=%lu",var->ncfullname,(unsigned long)nelems); } if(nelems <= nccomm->cdf.smallsizelimit) { nclistpush(vars,(ncelem)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. */ 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,(ncelem)varprojection); } if(SHOWFETCH) { char* s = dumpprojections(newconstraint->projections); LOG1(NCLOGNOTE,"prefetch.final: %s",s); nullfree(s); } ncstat = buildcachenode34(nccomm,newconstraint,vars,&cache,!isnc4); 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); }