static NCerror buildattribute3a(NCDAPCOMMON* dapcomm, NCattribute* att, nc_type vartype, int varid) { int i; NCerror ncstat = NC_NOERR; unsigned int nvalues = nclistlength(att->values); NC* drno = dapcomm->controller; /* If the type of the attribute is string, then we need*/ /* to convert to a single character string by concatenation. modified: 10/23/09 to insert newlines. modified: 10/28/09 to interpret escapes */ if(att->etype == NC_STRING || att->etype == NC_URL) { char* newstring; size_t newlen = 0; for(i=0;i<nvalues;i++) { char* s = (char*)nclistget(att->values,i); newlen += (1+strlen(s)); } newstring = (char*)malloc(newlen); MEMCHECK(newstring,NC_ENOMEM); newstring[0] = '\0'; for(i=0;i<nvalues;i++) { char* s = (char*)nclistget(att->values,i); if(i > 0) strcat(newstring,"\n"); strcat(newstring,s); } dapexpandescapes(newstring); if(newstring[0]=='\0') ncstat = nc_put_att_text(drno->substrate,varid,att->name,1,newstring); else ncstat = nc_put_att_text(drno->substrate,varid,att->name,strlen(newstring),newstring); free(newstring); } else { nc_type atype; unsigned int typesize; void* mem; /* It turns out that some servers upgrade the type of _FillValue in order to correctly preserve the original value. However, since the type of the underlying variable is not changes, we get a type mismatch. So, make sure the type of the fillvalue is the same as that of the controlling variable. */ if(varid != NC_GLOBAL && strcmp(att->name,"_FillValue")==0) atype = nctypeconvert(dapcomm,vartype); else atype = nctypeconvert(dapcomm,att->etype); typesize = nctypesizeof(atype); mem = malloc(typesize * nvalues); ncstat = dapcvtattrval3(atype,mem,att->values); ncstat = nc_put_att(drno->substrate,varid,att->name,atype,nvalues,mem); nullfree(mem); } return THROW(ncstat); }
/* Exceptions: anonymous dimensions. */ static NCerror fix1node(NCDAPCOMMON* nccomm, CDFnode* node) { if(node->nctype == NC_Dimension && node->ocname == NULL) return NC_NOERR; ASSERT((node->ocname != NULL)); nullfree(node->ncbasename); node->ncbasename = cdflegalname(node->ocname); if(node->ncbasename == NULL) return NC_ENOMEM; nullfree(node->ncfullname); node->ncfullname = makecdfpathstring(node,nccomm->cdf.separator); if(node->ncfullname == NULL) return NC_ENOMEM; if(node->nctype == NC_Atomic) node->externaltype = nctypeconvert(nccomm,node->etype); return NC_NOERR; }