Пример #1
0
static NCerror
repairgrids(NCDAPCOMMON* ncc, NClist* repairlist)
{
    NCerror ncstat = NC_NOERR;
    int i;
    assert(nclistlength(repairlist) % 2 == 0);
    for(i=0;i<nclistlength(repairlist);i+=2) {
	CDFnode* node = (CDFnode*)nclistget(repairlist,i);
	CDFnode* pattern = (CDFnode*)nclistget(repairlist,i+1);
	int index = findin(node->container,node);
	int tindex = findin(pattern->container,pattern);
	ncstat = structwrap(ncc, node,node->container,index,
                             pattern->container,tindex);
#ifdef DEBUG
fprintf(stderr,"repairgrids: %s -> %s\n",
ocfqn(node->ocnode),ocfqn(pattern->ocnode));
#endif

    }
    return ncstat;
}
Пример #2
0
/*
A variable is prefetchable if
1. it is atomic
2. it's size is sufficiently small
3. it is not contained in sequence or a dimensioned structure.
*/
NCerror
markprefetch(NCDAPCOMMON* nccomm)
{
    int i,j;
    NClist* allvars = nccomm->cdf.fullddsroot->tree->varnodes;
    assert(allvars != NULL);
    /* mark those variables of sufficiently small size */
    for(i=0;i<nclistlength(allvars);i++) {
	CDFnode* var = (CDFnode*)nclistget(allvars,i);
	size_t nelems;

	/* If var is not atomic, then it is not prefetchable */
	if(var->nctype != NC_Atomic)
	    continue;

        /* if var is under a sequence, then never prefetch */
        if(dapinsequence(var))
	    continue;

        /* Compute the # of elements in the variable */
        for(nelems=1,j=0;j<nclistlength(var->array.dimsettrans);j++) {
            CDFnode* dim = (CDFnode*)nclistget(var->array.dimsettrans,j);
            nelems *= dim->dim.declsize;
	}
        if(nelems <= nccomm->cdf.smallsizelimit
           && FLAGSET(nccomm->controls,NCF_PREFETCH)) {
          var->prefetchable = 1;
          if(SHOWFETCH)
            {
              extern char* ocfqn(OCddsnode);
              char *tmp = ocfqn(var->ocnode);
              nclog(NCLOGDBG,"prefetchable: %s=%lu",
                    tmp,(unsigned long)nelems);
              free(tmp);
            }
        }
    }
    return NC_NOERR;
}
Пример #3
0
static int
restructr(NCDAPCOMMON* ncc, CDFnode* dxdparent, CDFnode* templateparent, NClist* repairlist)
{
    int index, i, j, match;

#ifdef DEBUG
    fprintf(stderr,"restruct: matched: %s -> %s\n",
            ocfqn(dxdparent->ocnode),ocfqn(templateparent->ocnode));
#endif

    /* walk each node child and locate its match
       in the template's children; recurse on matches,
       non-matches may be nodes needing wrapping.
    */

    for(index=0; index<nclistlength(dxdparent->subnodes); index++) {
        CDFnode* dxdsubnode = (CDFnode*)nclistget(dxdparent->subnodes,index);
        CDFnode* matchnode = NULL;

        /* Look for a matching template node with same ocname */
        for(i=0; i<nclistlength(templateparent->subnodes); i++) {
            CDFnode* templatesubnode = (CDFnode*)nclistget(templateparent->subnodes,i);
            if(strcmp(dxdsubnode->ocname,templatesubnode->ocname) == 0) {
                matchnode = templatesubnode;
                break;
            }
        }
#ifdef DEBUG
        fprintf(stderr,"restruct: candidate: %s -> %s\n",
                ocfqn(dxdsubnode->ocnode),ocfqn(matchnode->ocnode));
#endif
        if(simplenodematch(dxdsubnode,matchnode)) {
            /* this subnode of the node matches the corresponding
                   node of the template, so it is ok =>
                   recurse looking for nested mis-matches
                */
            if(!restructr(ncc,dxdsubnode,matchnode,repairlist))
                return 0;
        } else {
            /* If we do not have a direct match, then we need to look
               at all the grids to see if this node matches a field
               in one of the grids
            */
            for(match=0,i=0; !match && i<nclistlength(templateparent->subnodes); i++) {
                CDFnode* subtemp = (CDFnode*)nclistget(templateparent->subnodes,i);
                if(subtemp->nctype == NC_Grid) {
                    /* look inside */
                    for(j=0; j<nclistlength(templateparent->subnodes); j++) {
                        CDFnode* gridfield = (CDFnode*)nclistget(subtemp->subnodes,j);
                        if(simplenodematch(dxdsubnode,gridfield)) {
                            /* We need to do this repair */
                            nclistpush(repairlist,(void*)dxdsubnode);
                            nclistpush(repairlist,(void*)gridfield);
                            match = 1;
                            break;
                        }
                    }
                }
            }
            if(!match) return 0; /* we failed */
        }
    }
    return 1; /* we matched everything at this level */
}
Пример #4
0
static NCerror
repairgrids(NCDAPCOMMON* ncc, NClist* repairlist)
{
    NCerror ncstat = NC_NOERR;
    int i;
    assert(nclistlength(repairlist) % 2 == 0);
    for(i=0; i<nclistlength(repairlist); i+=2) {
        CDFnode* node = (CDFnode*)nclistget(repairlist,i);
        CDFnode* template = (CDFnode*)nclistget(repairlist,i+1);
        int index = findin(node->container,node);
        int tindex = findin(template->container,template);
        ncstat = structwrap(ncc, node,node->container,index,
                            template->container,tindex);
#ifdef DEBUG
        fprintf(stderr,"repairgrids: %s -> %s\n",
                ocfqn(node->ocnode),ocfqn(template->ocnode));
#endif

    }
    return ncstat;
}

static NCerror
structwrap(NCDAPCOMMON* ncc, CDFnode* node, CDFnode* parent, int parentindex,
           CDFnode* templategrid, int gridindex)
{
    CDFnode* newstruct;

    ASSERT((templategrid->nctype == NC_Grid));
    newstruct = makenewstruct(ncc, node,templategrid);
    if(newstruct == NULL) {