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; }
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; }
static int readfiletofile(NCD4INFO* state, const NCURI* uri, const char* suffix, FILE* stream, d4size_t* sizep) { int stat = NC_NOERR; NCbytes* packet = ncbytesnew(); size_t len; stat = readfile(state, uri,suffix,packet); #ifdef D4DEBUG fprintf(stderr,"readfiletofile: packet.size=%lu\n", (unsigned long)ncbyteslength(packet)); #endif if(stat != NC_NOERR) goto unwind; len = nclistlength(packet); if(stat == NC_NOERR) { size_t written; fseek(stream,0,SEEK_SET); written = fwrite(ncbytescontents(packet),1,len,stream); if(written != len) { #ifdef D4DEBUG fprintf(stderr,"readfiletofile: written!=length: %lu :: %lu\n", (unsigned long)written,(unsigned long)len); #endif stat = NC_EIO; } } if(sizep != NULL) *sizep = len; unwind: ncbytesfree(packet); return THROW(stat); }
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; }
int main(int argc, char** argv) { int i; int ret = NC_NOERR; if(argc == 1) { fprintf(stderr,"usage: nc4printer <file> <file>...\n"); exit(1); } for(i=1;i<argc;i++) { int ncid; char* filename; NCbytes* buf; filename = argv[i]; buf = ncbytesnew(); if((ret = nc_open(filename,NC_NETCDF4,&ncid))) goto fail; ret = NC4print(buf,ncid); ncbytesnull(buf); fprintf(stderr,"========== %s ==========\n",filename); fprintf(stderr,"%s\n",ncbytescontents(buf)); ncbytesfree(buf); } exit(0); fail: fprintf(stderr,"***Fail: (%d) %s\n",ret,nc_strerror(ret)); exit(1); }
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; }
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; }
void dcelexinit(char* input, DCElexstate** lexstatep) { DCElexstate* lexstate = (DCElexstate*)malloc(sizeof(DCElexstate)); /* If lexstatep is NULL, we want to free lexstate and return to avoid a memory leak. */ if(lexstatep) { *lexstatep = lexstate; } else { if(lexstate) free(lexstate); return; } if(lexstate == NULL) return; memset((void*)lexstate,0,sizeof(DCElexstate)); #ifdef URLDECODE lexstate->input = ncuridecode(input); #else lexstate->input = strdup(input); #endif lexstate->next = lexstate->input; lexstate->yytext = ncbytesnew(); lexstate->reclaim = nclistnew(); }
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; }
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* 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* 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* buildprojectionstring(NClist* projections) { char* pstring; NCbytes* buf = ncbytesnew(); dcelisttobuffer(projections,buf,","); pstring = ncbytesdup(buf); ncbytesfree(buf); return pstring; }
char* dumpvisible(CDFnode* root) { NCbytes* buf = ncbytesnew(); char* result; dumptreer(root,buf,0,1); result = ncbytesdup(buf); ncbytesfree(buf); return result; }
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; }
static void ccelexinit(char* input, CCElexstate** lexstatep) { CCElexstate* lexstate = (CCElexstate*)malloc(sizeof(CCElexstate)); if(lexstatep) *lexstatep = lexstate; if(lexstate == NULL) return; memset((void*)lexstate,0,sizeof(CCElexstate)); lexstate->input = strdup(input); lexstate->next = lexstate->input; lexstate->yytext = ncbytesnew(); lexstate->reclaim = nclistnew(); }
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; }
void daplexinit(char* input, DAPlexstate** lexstatep) { DAPlexstate* lexstate; if(lexstatep == NULL) return; /* no point in building it */ lexstate = (DAPlexstate*)malloc(sizeof(DAPlexstate)); *lexstatep = lexstate; if(lexstate == NULL) return; memset((void*)lexstate,0,sizeof(DAPlexstate)); lexstate->input = strdup(input); lexstate->next = lexstate->input; lexstate->yytext = ncbytesnew(); lexstate->reclaim = nclistnew(); dapsetwordchars(lexstate,0); /* Assume DDS */ }
/* 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; }
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; }
void dcelexinit(char* input, DCElexstate** lexstatep) { DCElexstate* lexstate = (DCElexstate*)malloc(sizeof(DCElexstate)); if(lexstatep) *lexstatep = lexstate; if(lexstate == NULL) return; memset((void*)lexstate,0,sizeof(DCElexstate)); #ifdef URLDECODE lexstate->input = ncuridecode(input); #else lexstate->input = strdup(input); #endif lexstate->next = lexstate->input; lexstate->yytext = ncbytesnew(); lexstate->reclaim = nclistnew(); }
/** * @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; }