示例#1
0
int main(int argc, char* argv[])
{
    char* fname = NULL;
    int ij = 0;
    int compact = 0;
    NODETYPE nt = NT_DD;
    gridnodes* gn = NULL;
    poly* pl = NULL;

    parse_commandline(argc, argv, &fname, &compact, &ij, &nt);

    if (nt == NT_DD) {
        /*
         * read DD grid nodes 
         */
        gridnodes* gndd = gridnodes_read(fname, NT_DD);

        gridnodes_validate(gndd);
        /*
         * get corner grid nodes from DD grid nodes 
         */
        gn = gridnodes_transform(gndd, NT_COR);
        gridnodes_destroy(gndd);
    } else {
        gn = gridnodes_read(fname, NT_COR);
        gridnodes_validate(gn);
    }

    /*
     * build boundary polygon 
     */
    if (!ij)
        pl = poly_formbound(gridnodes_getnce1(gn), gridnodes_getnce2(gn), gridnodes_getx(gn), gridnodes_gety(gn));
    else
        pl = poly_formboundij(gridnodes_getnce1(gn), gridnodes_getnce2(gn), gridnodes_getx(gn));

    if (compact)
        poly_compact(pl, 1.0e-10);

    poly_write(pl, stdout);

    poly_destroy(pl);
    gridnodes_destroy(gn);

    return 0;
}
示例#2
0
/* Builds a grid map structure to facilitate conversion from coordinate
 * to index space.
 *
 * @param gx array of X coordinates (of size (nce1+1)*(nce2+1))
 * @param gy array of Y coordinates (of size (nce1+1)*(nce2+1))
 * @param nce1 number of cells in e1 direction
 * @param nce2 number of cells in e2 direction
 * @return a map tree to be use by xy2ij
 */
gridmap* gridmap_build(int nce1, int nce2, double** gx, double** gy)
{
    gridmap* gm = malloc(sizeof(gridmap));
    poly* bound;
    subgrid* trunk;

    gm->nce1 = nce1;
    gm->nce2 = nce2;
    gm->gx = gx;
    gm->gy = gy;
    gm->sign = 0;

    bound = poly_formbound(nce1, nce2, gx, gy);
    trunk = subgrid_create(gm, bound, 0, nce1, 0, nce2);

    gm->bound = bound;
    gm->trunk = trunk;
    gm->nleaves = 1;

    gridmap_subdivide(gm, trunk);       /* recursive */

    return gm;
}