/* 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; }
NCerror fixgrid(NCDAPCOMMON* nccomm, CDFnode* grid) { unsigned int i,glen; CDFnode* array; glen = nclistlength(grid->subnodes); array = (CDFnode*)nclistget(grid->subnodes,0); if(nccomm->controls.flags & (NCF_NC3)) { /* Rename grid Array: variable, but leave its oc base name alone */ nullfree(array->ncbasename); array->ncbasename = nulldup(grid->ncbasename); if(!array->ncbasename) return NC_ENOMEM; } /* validate and modify the grid structure */ if((glen-1) != nclistlength(array->array.dimset0)) goto invalid; for(i=1; i<glen; i++) { CDFnode* arraydim = (CDFnode*)nclistget(array->array.dimset0,i-1); CDFnode* map = (CDFnode*)nclistget(grid->subnodes,i); CDFnode* mapdim; /* map must have 1 dimension */ if(nclistlength(map->array.dimset0) != 1) goto invalid; /* and the map name must match the ith array dimension */ if(arraydim->ocname != NULL && map->ocname != NULL && strcmp(arraydim->ocname,map->ocname) != 0) goto invalid; /* and the map name must match its dim name (if any) */ mapdim = (CDFnode*)nclistget(map->array.dimset0,0); if(mapdim->ocname != NULL && map->ocname != NULL && strcmp(mapdim->ocname,map->ocname) != 0) goto invalid; /* Add appropriate names for the anonymous dimensions */ /* Do the map name first, so the array dim may inherit */ if(mapdim->ocname == NULL) { nullfree(mapdim->ncbasename); mapdim->ocname = nulldup(map->ocname); if(!mapdim->ocname) return NC_ENOMEM; mapdim->ncbasename = cdflegalname(mapdim->ocname); if(!mapdim->ncbasename) return NC_ENOMEM; } if(arraydim->ocname == NULL) { nullfree(arraydim->ncbasename); arraydim->ocname = nulldup(map->ocname); if(!arraydim->ocname) return NC_ENOMEM; arraydim->ncbasename = cdflegalname(arraydim->ocname); if(!arraydim->ncbasename) return NC_ENOMEM; } if(FLAGSET(nccomm->controls,(NCF_NCDAP|NCF_NC3))) { char tmp[3*NC_MAX_NAME]; /* Add the grid name to the basename of the map */ snprintf(tmp,sizeof(tmp),"%s%s%s",map->container->ncbasename, nccomm->cdf.separator, map->ncbasename); nullfree(map->ncbasename); map->ncbasename = nulldup(tmp); if(!map->ncbasename) return NC_ENOMEM; } } return NC_NOERR; invalid: return NC_EINVAL; /* mal-formed grid */ }