2011-04-18 02:56:10 +08:00
|
|
|
/*********************************************************************
|
2018-12-07 05:21:03 +08:00
|
|
|
* Copyright 2018, UCAR/Unidata
|
2011-04-18 02:56:10 +08:00
|
|
|
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
|
|
|
|
*********************************************************************/
|
2013-07-28 04:54:50 +08:00
|
|
|
|
2011-04-18 02:56:10 +08:00
|
|
|
#include "config.h"
|
2019-11-05 05:11:55 +08:00
|
|
|
#include "netcdf.h"
|
2023-11-27 19:36:03 +08:00
|
|
|
#include <stddef.h>
|
2011-04-18 02:56:10 +08:00
|
|
|
#ifdef USE_PARALLEL
|
|
|
|
#include "netcdf_par.h"
|
|
|
|
#endif
|
2017-03-09 08:01:10 +08:00
|
|
|
#include "dapincludes.h"
|
2011-04-18 02:56:10 +08:00
|
|
|
#include "dapdump.h"
|
2011-11-14 12:20:19 +08:00
|
|
|
#include "dceconstraints.h"
|
2011-04-18 02:56:10 +08:00
|
|
|
|
|
|
|
#define CHECK(n) if((n) != NC_NOERR) {return (n);} else {}
|
|
|
|
|
2019-03-31 04:06:20 +08:00
|
|
|
static char* indentstr = " "; /* Used by dumpindent */
|
|
|
|
|
2011-11-14 12:20:19 +08:00
|
|
|
static void dumptreer(CDFnode* root, NCbytes* buf, int indent, int visible);
|
|
|
|
|
2011-04-18 02:56:10 +08:00
|
|
|
int
|
|
|
|
dumpmetadata(int ncid, NChdr** hdrp)
|
|
|
|
{
|
|
|
|
int stat,i,j,k;
|
|
|
|
NChdr* hdr = (NChdr*)calloc(1,sizeof(NChdr));
|
|
|
|
MEMCHECK(hdr,NC_ENOMEM);
|
|
|
|
hdr->ncid = ncid;
|
|
|
|
hdr->content = ncbytesnew();
|
|
|
|
if(hdrp) *hdrp = hdr;
|
|
|
|
|
|
|
|
stat = nc_inq(hdr->ncid,
|
|
|
|
&hdr->ndims,
|
|
|
|
&hdr->nvars,
|
|
|
|
&hdr->ngatts,
|
|
|
|
&hdr->unlimid);
|
|
|
|
CHECK(stat);
|
2019-03-31 04:06:20 +08:00
|
|
|
#ifdef DEBUG2
|
2011-04-18 02:56:10 +08:00
|
|
|
fprintf(stdout,"ncid=%d ngatts=%d ndims=%d nvars=%d unlimid=%d\n",
|
|
|
|
hdr->ncid,hdr->ngatts,hdr->ndims,hdr->nvars,hdr->unlimid);
|
2019-03-31 04:06:20 +08:00
|
|
|
#endif
|
2023-11-25 02:20:52 +08:00
|
|
|
hdr->gatts = (NCattribute*)calloc(1, (size_t)hdr->ngatts*sizeof(NCattribute));
|
2011-04-18 02:56:10 +08:00
|
|
|
MEMCHECK(hdr->gatts,NC_ENOMEM);
|
|
|
|
if(hdr->ngatts > 0)
|
|
|
|
fprintf(stdout,"global attributes:\n");
|
|
|
|
for(i=0;i<hdr->ngatts;i++) {
|
|
|
|
NCattribute* att = &hdr->gatts[i];
|
|
|
|
char attname[NC_MAX_NAME];
|
|
|
|
nc_type nctype;
|
|
|
|
size_t typesize;
|
|
|
|
size_t nvalues;
|
|
|
|
|
|
|
|
stat = nc_inq_attname(hdr->ncid,NC_GLOBAL,i,attname);
|
|
|
|
CHECK(stat);
|
|
|
|
att->name = nulldup(attname);
|
|
|
|
stat = nc_inq_att(hdr->ncid,NC_GLOBAL,att->name,&nctype,&nvalues);
|
|
|
|
CHECK(stat);
|
|
|
|
att->etype = nctypetodap(nctype);
|
|
|
|
typesize = nctypesizeof(att->etype);
|
|
|
|
fprintf(stdout,"\t[%d]: name=%s type=%s values(%lu)=",
|
|
|
|
i,att->name,nctypetostring(octypetonc(att->etype)),
|
|
|
|
(unsigned long)nvalues);
|
|
|
|
if(nctype == NC_CHAR) {
|
|
|
|
size_t len = typesize*nvalues;
|
|
|
|
char* values = (char*)malloc(len+1);/* for null terminate*/
|
|
|
|
MEMCHECK(values,NC_ENOMEM);
|
|
|
|
stat = nc_get_att(hdr->ncid,NC_GLOBAL,att->name,values);
|
|
|
|
CHECK(stat);
|
|
|
|
values[len] = '\0';
|
|
|
|
fprintf(stdout," '%s'",values);
|
|
|
|
} else {
|
|
|
|
size_t len = typesize*nvalues;
|
|
|
|
char* values = (char*)malloc(len);
|
|
|
|
MEMCHECK(values,NC_ENOMEM);
|
|
|
|
stat = nc_get_att(hdr->ncid,NC_GLOBAL,att->name,values);
|
|
|
|
CHECK(stat);
|
|
|
|
for(k=0;k<nvalues;k++) {
|
|
|
|
fprintf(stdout," ");
|
|
|
|
dumpdata1(octypetonc(att->etype),k,values);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fprintf(stdout,"\n");
|
|
|
|
}
|
|
|
|
|
2023-11-25 02:20:52 +08:00
|
|
|
hdr->dims = (Dim*)malloc((size_t)hdr->ndims*sizeof(Dim));
|
2011-04-18 02:56:10 +08:00
|
|
|
MEMCHECK(hdr->dims,NC_ENOMEM);
|
|
|
|
for(i=0;i<hdr->ndims;i++) {
|
|
|
|
hdr->dims[i].dimid = i;
|
|
|
|
stat = nc_inq_dim(hdr->ncid,
|
|
|
|
hdr->dims[i].dimid,
|
|
|
|
hdr->dims[i].name,
|
|
|
|
&hdr->dims[i].size);
|
|
|
|
CHECK(stat);
|
|
|
|
fprintf(stdout,"dim[%d]: name=%s size=%lu\n",
|
|
|
|
i,hdr->dims[i].name,(unsigned long)hdr->dims[i].size);
|
2019-11-05 05:11:55 +08:00
|
|
|
}
|
2023-11-25 02:20:52 +08:00
|
|
|
hdr->vars = (Var*)malloc((size_t)hdr->nvars*sizeof(Var));
|
2011-04-18 02:56:10 +08:00
|
|
|
MEMCHECK(hdr->vars,NC_ENOMEM);
|
|
|
|
for(i=0;i<hdr->nvars;i++) {
|
|
|
|
Var* var = &hdr->vars[i];
|
|
|
|
nc_type nctype;
|
|
|
|
var->varid = i;
|
|
|
|
stat = nc_inq_var(hdr->ncid,
|
|
|
|
var->varid,
|
|
|
|
var->name,
|
|
|
|
&nctype,
|
|
|
|
&var->ndims,
|
|
|
|
var->dimids,
|
|
|
|
&var->natts);
|
|
|
|
CHECK(stat);
|
|
|
|
var->nctype = (nctype);
|
|
|
|
fprintf(stdout,"var[%d]: name=%s type=%s |dims|=%d",
|
|
|
|
i,
|
|
|
|
var->name,
|
|
|
|
nctypetostring(var->nctype),
|
|
|
|
var->ndims);
|
|
|
|
fprintf(stdout," dims={");
|
|
|
|
for(j=0;j<var->ndims;j++) {
|
|
|
|
fprintf(stdout," %d",var->dimids[j]);
|
|
|
|
}
|
|
|
|
fprintf(stdout,"}\n");
|
2023-11-25 02:20:52 +08:00
|
|
|
var->atts = (NCattribute*)malloc((size_t)var->natts*sizeof(NCattribute));
|
2011-04-18 02:56:10 +08:00
|
|
|
MEMCHECK(var->atts,NC_ENOMEM);
|
|
|
|
for(j=0;j<var->natts;j++) {
|
|
|
|
NCattribute* att = &var->atts[j];
|
|
|
|
char attname[NC_MAX_NAME];
|
|
|
|
size_t typesize;
|
|
|
|
char* values;
|
|
|
|
nc_type nctype;
|
|
|
|
size_t nvalues;
|
|
|
|
stat = nc_inq_attname(hdr->ncid,var->varid,j,attname);
|
|
|
|
CHECK(stat);
|
|
|
|
att->name = nulldup(attname);
|
|
|
|
stat = nc_inq_att(hdr->ncid,var->varid,att->name,&nctype,&nvalues);
|
|
|
|
CHECK(stat);
|
|
|
|
att->etype = nctypetodap(nctype);
|
|
|
|
typesize = nctypesizeof(att->etype);
|
|
|
|
values = (char*)malloc(typesize*nvalues);
|
|
|
|
MEMCHECK(values,NC_ENOMEM);
|
|
|
|
stat = nc_get_att(hdr->ncid,var->varid,att->name,values);
|
|
|
|
CHECK(stat);
|
|
|
|
fprintf(stdout,"\tattr[%d]: name=%s type=%s values(%lu)=",
|
|
|
|
j,att->name,nctypetostring(octypetonc(att->etype)),(unsigned long)nvalues);
|
|
|
|
for(k=0;k<nvalues;k++) {
|
|
|
|
fprintf(stdout," ");
|
|
|
|
dumpdata1(octypetonc(att->etype),k,values);
|
|
|
|
}
|
|
|
|
fprintf(stdout,"\n");
|
|
|
|
}
|
2019-11-05 05:11:55 +08:00
|
|
|
}
|
2011-04-18 02:56:10 +08:00
|
|
|
fflush(stdout);
|
|
|
|
return NC_NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dumpdata1(nc_type nctype, size_t index, char* data)
|
|
|
|
{
|
|
|
|
switch (nctype) {
|
|
|
|
case NC_CHAR:
|
|
|
|
fprintf(stdout,"'%c' %hhd",data[index],data[index]);
|
|
|
|
break;
|
|
|
|
case NC_BYTE:
|
2018-04-18 04:03:52 +08:00
|
|
|
fprintf(stdout,"%hhdB",((signed char*)data)[index]);
|
2011-04-18 02:56:10 +08:00
|
|
|
break;
|
|
|
|
case NC_UBYTE:
|
2018-04-18 04:03:52 +08:00
|
|
|
fprintf(stdout,"%hhuB",((unsigned char*)data)[index]);
|
2011-04-18 02:56:10 +08:00
|
|
|
break;
|
|
|
|
case NC_SHORT:
|
|
|
|
fprintf(stdout,"%hdS",((short*)data)[index]);
|
|
|
|
break;
|
|
|
|
case NC_USHORT:
|
|
|
|
fprintf(stdout,"%hdUS",((unsigned short*)data)[index]);
|
|
|
|
break;
|
|
|
|
case NC_INT:
|
|
|
|
fprintf(stdout,"%d",((int*)data)[index]);
|
|
|
|
break;
|
|
|
|
case NC_UINT:
|
|
|
|
fprintf(stdout,"%uU",((unsigned int*)data)[index]);
|
|
|
|
break;
|
|
|
|
case NC_FLOAT:
|
|
|
|
fprintf(stdout,"%#gF",((float*)data)[index]);
|
|
|
|
break;
|
|
|
|
case NC_DOUBLE:
|
|
|
|
fprintf(stdout,"%#gD",((double*)data)[index]);
|
|
|
|
break;
|
|
|
|
case NC_STRING:
|
|
|
|
fprintf(stdout,"\"%s\"",((char**)data)[index]);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stdout,"Unknown type: %i",nctype);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Following should be kept consistent with
|
|
|
|
the makeXXXstring3 routines in constraints3.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Convert an NCprojection instance into a string
|
|
|
|
that can be used with the url
|
|
|
|
*/
|
|
|
|
char*
|
|
|
|
dumpprojections(NClist* projections)
|
|
|
|
{
|
2011-11-14 12:20:19 +08:00
|
|
|
char* tmp;
|
|
|
|
tmp = dcelisttostring(projections,",");
|
|
|
|
return tmp;
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
dumpprojection(DCEprojection* proj)
|
|
|
|
{
|
2011-11-14 12:20:19 +08:00
|
|
|
char* tmp;
|
|
|
|
tmp = dcetostring((DCEnode*)proj);
|
|
|
|
return tmp;
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
dumpselections(NClist* selections)
|
|
|
|
{
|
|
|
|
return dcelisttostring(selections,"&");
|
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
dumpselection(DCEselection* sel)
|
|
|
|
{
|
|
|
|
return dcetostring((DCEnode*)sel);
|
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
dumpconstraint(DCEconstraint* con)
|
|
|
|
{
|
2011-11-14 12:20:19 +08:00
|
|
|
char* tmp;
|
|
|
|
tmp = dcetostring((DCEnode*)con);
|
|
|
|
return tmp;
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
dumpsegments(NClist* segments)
|
|
|
|
{
|
|
|
|
return dcelisttostring(segments,".");
|
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
dumppath(CDFnode* leaf)
|
|
|
|
{
|
|
|
|
NClist* path = nclistnew();
|
|
|
|
NCbytes* buf = ncbytesnew();
|
|
|
|
char* result;
|
2023-11-27 19:36:03 +08:00
|
|
|
size_t i;
|
2011-04-18 02:56:10 +08:00
|
|
|
|
|
|
|
if(leaf == NULL) return nulldup("");
|
2014-03-25 04:02:52 +08:00
|
|
|
collectnodepath(leaf,path,!WITHDATASET);
|
2011-04-18 02:56:10 +08:00
|
|
|
for(i=0;i<nclistlength(path);i++) {
|
|
|
|
CDFnode* node = (CDFnode*)nclistget(path,i);
|
|
|
|
if(i > 0) ncbytescat(buf,".");
|
2011-11-14 12:20:19 +08:00
|
|
|
ncbytescat(buf,node->ncbasename);
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
result = ncbytesdup(buf);
|
|
|
|
ncbytesfree(buf);
|
|
|
|
nclistfree(path);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dumpindent(int indent, NCbytes* buf)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for(i=0;i<indent;i++) ncbytescat(buf,indentstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dumptreer1(CDFnode* root, NCbytes* buf, int indent, char* tag, int visible)
|
|
|
|
{
|
2023-11-27 19:36:03 +08:00
|
|
|
size_t i;
|
2011-04-18 02:56:10 +08:00
|
|
|
dumpindent(indent,buf);
|
|
|
|
ncbytescat(buf,tag);
|
|
|
|
ncbytescat(buf," {\n");
|
|
|
|
for(i=0;i<nclistlength(root->subnodes);i++) {
|
|
|
|
CDFnode* node = (CDFnode*)nclistget(root->subnodes,i);
|
2013-03-03 12:06:43 +08:00
|
|
|
if(visible && root->invisible) continue;
|
2011-04-18 02:56:10 +08:00
|
|
|
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,"} ");
|
2013-02-26 12:31:06 +08:00
|
|
|
ncbytescat(buf,(root->ncbasename?root->ncbasename:"<?>"));
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dumptreer(CDFnode* root, NCbytes* buf, int indent, int visible)
|
|
|
|
{
|
2023-11-27 19:36:03 +08:00
|
|
|
size_t i;
|
2011-04-18 02:56:10 +08:00
|
|
|
char* primtype = NULL;
|
2011-11-14 12:20:19 +08:00
|
|
|
NClist* dimset = NULL;
|
|
|
|
|
2013-03-03 12:06:43 +08:00
|
|
|
if(visible && root->invisible) return;
|
2011-04-18 02:56:10 +08:00
|
|
|
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;
|
2012-08-01 04:34:13 +08:00
|
|
|
case NC_Atomic:
|
2011-04-18 02:56:10 +08:00
|
|
|
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," ");
|
2013-02-26 12:31:06 +08:00
|
|
|
ncbytescat(buf,(root->ncbasename?root->ncbasename:"<?>"));
|
2011-04-18 02:56:10 +08:00
|
|
|
break;
|
2019-11-05 05:11:55 +08:00
|
|
|
default: break;
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
|
2011-11-14 12:20:19 +08:00
|
|
|
if(nclistlength(root->array.dimsetplus) > 0) dimset = root->array.dimsetplus;
|
|
|
|
else if(nclistlength(root->array.dimset0) > 0) dimset = root->array.dimset0;
|
|
|
|
if(dimset != NULL) {
|
|
|
|
for(i=0;i<nclistlength(dimset);i++) {
|
|
|
|
CDFnode* dim = (CDFnode*)nclistget(dimset,i);
|
2011-04-18 02:56:10 +08:00
|
|
|
char tmp[64];
|
|
|
|
ncbytescat(buf,"[");
|
2011-11-14 12:20:19 +08:00
|
|
|
if(dim->ncbasename != NULL) {
|
|
|
|
ncbytescat(buf,dim->ncbasename);
|
2011-04-18 02:56:10 +08:00
|
|
|
ncbytescat(buf,"=");
|
|
|
|
}
|
|
|
|
snprintf(tmp,sizeof(tmp),"%lu",(unsigned long)dim->dim.declsize);
|
|
|
|
ncbytescat(buf,tmp);
|
|
|
|
ncbytescat(buf,"]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ncbytescat(buf,";\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
dumptree(CDFnode* root)
|
|
|
|
{
|
|
|
|
NCbytes* buf = ncbytesnew();
|
|
|
|
char* result;
|
|
|
|
dumptreer(root,buf,0,0);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Provide detailed data on a CDFnode */
|
|
|
|
char*
|
|
|
|
dumpnode(CDFnode* node)
|
|
|
|
{
|
|
|
|
NCbytes* buf = ncbytesnew();
|
|
|
|
char* result;
|
2023-11-27 19:36:03 +08:00
|
|
|
size_t i;
|
2011-04-18 02:56:10 +08:00
|
|
|
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;
|
2012-08-01 04:34:13 +08:00
|
|
|
case NC_Atomic:
|
2011-04-18 02:56:10 +08:00
|
|
|
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;
|
2019-11-05 05:11:55 +08:00
|
|
|
default: break;
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
snprintf(tmp,sizeof(tmp),"%s %s {\n",
|
2011-11-14 12:20:19 +08:00
|
|
|
(nctype?nctype:primtype),node->ocname);
|
2011-04-18 02:56:10 +08:00
|
|
|
ncbytescat(buf,tmp);
|
2021-12-24 13:18:56 +08:00
|
|
|
snprintf(tmp,sizeof(tmp),"ocnode=%p\n",node->ocnode);
|
2011-04-18 02:56:10 +08:00
|
|
|
ncbytescat(buf,tmp);
|
|
|
|
snprintf(tmp,sizeof(tmp),"container=%s\n",
|
2011-11-14 12:20:19 +08:00
|
|
|
(node->container?node->container->ocname:"null"));
|
2011-04-18 02:56:10 +08:00
|
|
|
ncbytescat(buf,tmp);
|
|
|
|
snprintf(tmp,sizeof(tmp),"root=%s\n",
|
2011-11-14 12:20:19 +08:00
|
|
|
(node->root?node->root->ocname:"null"));
|
2011-04-18 02:56:10 +08:00
|
|
|
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);
|
2018-02-09 10:53:40 +08:00
|
|
|
snprintf(tmp,sizeof(tmp),"|subnodes|=%u\n",(unsigned)nclistlength(node->subnodes));
|
2011-04-18 02:56:10 +08:00
|
|
|
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);
|
2013-03-03 12:06:43 +08:00
|
|
|
snprintf(tmp,sizeof(tmp),"invisible=%d\n",node->invisible);
|
2011-04-18 02:56:10 +08:00
|
|
|
ncbytescat(buf,tmp);
|
|
|
|
snprintf(tmp,sizeof(tmp),"attachment=%s\n",
|
2011-11-14 12:20:19 +08:00
|
|
|
(node->attachment?node->attachment->ocname:"null"));
|
2011-04-18 02:56:10 +08:00
|
|
|
ncbytescat(buf,tmp);
|
2018-02-09 10:53:40 +08:00
|
|
|
snprintf(tmp,sizeof(tmp),"rank=%u\n",(unsigned)nclistlength(node->array.dimset0));
|
2011-04-18 02:56:10 +08:00
|
|
|
ncbytescat(buf,tmp);
|
2011-11-14 12:20:19 +08:00
|
|
|
for(i=0;i<nclistlength(node->array.dimset0);i++) {
|
|
|
|
CDFnode* dim = (CDFnode*)nclistget(node->array.dimset0,i);
|
2023-11-27 19:36:03 +08:00
|
|
|
snprintf(tmp,sizeof(tmp),"dims[%zu]={\n",i);
|
2011-04-18 02:56:10 +08:00
|
|
|
ncbytescat(buf,tmp);
|
2011-11-14 12:20:19 +08:00
|
|
|
snprintf(tmp,sizeof(tmp)," ocname=%s\n",dim->ocname);
|
|
|
|
ncbytescat(buf,tmp);
|
|
|
|
snprintf(tmp,sizeof(tmp)," ncbasename=%s\n",dim->ncbasename);
|
2011-04-18 02:56:10 +08:00
|
|
|
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)," }\n");
|
|
|
|
ncbytescat(buf,tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
result = ncbytesdup(buf);
|
|
|
|
ncbytesfree(buf);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
2018-11-16 01:00:38 +08:00
|
|
|
dumpalign(NCD2alignment* ncalign)
|
2011-04-18 02:56:10 +08:00
|
|
|
{
|
|
|
|
char* result;
|
|
|
|
char tmp[1024];
|
|
|
|
if(ncalign == NULL)
|
2018-11-16 01:00:38 +08:00
|
|
|
result = nulldup("NCD2alignment{size=-- alignment=-- offset=--}");
|
2011-04-18 02:56:10 +08:00
|
|
|
else {
|
2018-11-16 01:00:38 +08:00
|
|
|
snprintf(tmp,sizeof(tmp),"NCD2alignment{size=%lu alignment=%lu offset=%lu}",
|
2011-04-18 02:56:10 +08:00
|
|
|
ncalign->size,ncalign->alignment,ncalign->offset);
|
|
|
|
result = nulldup(tmp);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
dumpcachenode(NCcachenode* node)
|
|
|
|
{
|
|
|
|
char* result = NULL;
|
|
|
|
char tmp[8192];
|
2023-11-27 19:36:03 +08:00
|
|
|
size_t i;
|
2011-04-18 02:56:10 +08:00
|
|
|
NCbytes* buf;
|
|
|
|
|
|
|
|
if(node == NULL) return strdup("cachenode{null}");
|
|
|
|
buf = ncbytesnew();
|
2014-12-25 01:22:47 +08:00
|
|
|
result = dcebuildconstraintstring(node->constraint);
|
2021-12-24 13:18:56 +08:00
|
|
|
snprintf(tmp,sizeof(tmp),"cachenode%s(%p){size=%lu; constraint=%s; vars=",
|
2013-07-28 04:20:13 +08:00
|
|
|
node->isprefetch?"*":"",
|
2021-12-24 13:18:56 +08:00
|
|
|
node,
|
2011-04-18 02:56:10 +08:00
|
|
|
(unsigned long)node->xdrsize,
|
2011-11-14 12:20:19 +08:00
|
|
|
result);
|
2011-04-18 02:56:10 +08:00
|
|
|
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,",");
|
2014-03-25 04:02:52 +08:00
|
|
|
ncbytescat(buf,makecdfpathstring(var,"."));
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
ncbytescat(buf,"}");
|
|
|
|
result = ncbytesdup(buf);
|
|
|
|
ncbytesfree(buf);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
dumpcache(NCcache* cache)
|
|
|
|
{
|
|
|
|
char* result = NULL;
|
|
|
|
char tmp[8192];
|
2023-11-27 19:36:03 +08:00
|
|
|
size_t i;
|
2011-04-18 02:56:10 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This should be consistent with makeslicestring3 in constraints3.c */
|
|
|
|
char*
|
|
|
|
dumpslice(DCEslice* slice)
|
|
|
|
{
|
2013-04-20 03:55:43 +08:00
|
|
|
char buf[8192];
|
|
|
|
char tmp[8192];
|
|
|
|
buf[0] = '\0';
|
|
|
|
if(slice->last > slice->declsize && slice->declsize > 0)
|
|
|
|
slice->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)slice->last);
|
|
|
|
} else {
|
|
|
|
snprintf(tmp,sizeof(tmp),"[%lu:%lu:%lu]",
|
|
|
|
(unsigned long)slice->first,
|
|
|
|
(unsigned long)slice->stride,
|
|
|
|
(unsigned long)slice->last);
|
|
|
|
}
|
2017-11-24 01:55:24 +08:00
|
|
|
strlcat(buf,tmp,sizeof(buf));
|
2013-04-20 03:55:43 +08:00
|
|
|
return strdup(tmp);
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
dumpslices(DCEslice* slice, unsigned int rank)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
NCbytes* buf;
|
|
|
|
char* result = NULL;
|
|
|
|
|
|
|
|
buf = ncbytesnew();
|
|
|
|
for(i=0;i<rank;i++,slice++) {
|
2014-04-08 04:01:40 +08:00
|
|
|
char* sslice = dumpslice(slice);
|
2014-04-08 03:00:47 +08:00
|
|
|
if(sslice != NULL) {
|
|
|
|
ncbytescat(buf,sslice);
|
|
|
|
free(sslice);
|
|
|
|
}
|
2011-04-18 02:56:10 +08:00
|
|
|
}
|
|
|
|
result = ncbytesdup(buf);
|
|
|
|
ncbytesfree(buf);
|
|
|
|
return result;
|
|
|
|
}
|
2011-11-14 12:20:19 +08:00
|
|
|
|
2012-08-01 04:34:13 +08:00
|
|
|
void
|
|
|
|
dumpraw(void* o)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"%s\n",dcerawtostring(o));
|
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dumplistraw(NClist* l)
|
|
|
|
{
|
|
|
|
fprintf(stderr,"%s\n",dcerawlisttostring(l));
|
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For debugging */
|
|
|
|
void
|
|
|
|
dumpstringlist(NClist* l)
|
|
|
|
{
|
2023-11-27 19:36:03 +08:00
|
|
|
size_t i;
|
2012-08-01 04:34:13 +08:00
|
|
|
for(i=0;i<nclistlength(l);i++) {
|
|
|
|
const char* s = (const char*)nclistget(l,i);
|
2023-11-27 19:36:03 +08:00
|
|
|
fprintf(stderr,"[%zu]: |%s|\n",i,s);
|
2012-08-01 04:34:13 +08:00
|
|
|
}
|
|
|
|
fflush(stderr);
|
|
|
|
}
|