Exemplo n.º 1
0
Arquivo: grid.c Projeto: sakov/enkf-c
void grid_getdims(grid* g, int* ni, int* nj, int* nk)
{
    if (ni != NULL) {
        if (g->htype == GRIDHTYPE_LATLON) {
            gnxy_simple* nodes = (gnxy_simple*) g->gridnodes_xy;

            *ni = nodes->nx;
            *nj = nodes->ny;
#if !defined(NO_GRIDUTILS)
        } else if (g->htype == GRIDHTYPE_CURVILINEAR) {
            gnxy_curv* nodes = (gnxy_curv*) g->gridnodes_xy;

            *ni = gridnodes_getnx(nodes->gn);
            *nj = gridnodes_getny(nodes->gn);
#endif
        } else
            enkf_quit("programming error");
    }
    if (nk != NULL) {
        if (g->vtype == GRIDVTYPE_Z || g->vtype == GRIDVTYPE_SIGMA)
            *nk = ((gnz_simple *) g->gridnodes_z)->nz;
        else
            enkf_quit("not implemented");
    }
}
Exemplo n.º 2
0
Arquivo: grid.c Projeto: sakov/enkf-c
static void z2fk(void* p, double fi, double fj, double z, double* fk)
{
    grid* g = (grid*) p;
    gnz_simple* nodes = g->gridnodes_z;

    /*
     * for sigma coordinates convert `z' to sigma
     */
    if (g->vtype == GRIDVTYPE_SIGMA) {
        int ni = 0, nj = 0;
        double depth;

        if (g->htype == GRIDHTYPE_LATLON) {
            gnxy_simple* nodes = (gnxy_simple*) g->gridnodes_xy;

            ni = nodes->nx;
            nj = nodes->ny;
#if !defined(NO_GRIDUTILS)
        } else if (g->htype == GRIDHTYPE_CURVILINEAR) {
            gnxy_curv* nodes = (gnxy_curv*) g->gridnodes_xy;

            ni = gridnodes_getnx(nodes->gn);
            nj = gridnodes_getny(nodes->gn);
#endif
        } else
            enkf_quit("programming error");

        depth = (double) interpolate2d(fi, fj, ni, nj, g->depth, g->numlevels, grid_isperiodic_x(g));
        z /= depth;
    }

    *fk = z2fk_basic(nodes->nz, nodes->zt, nodes->zc, z);
}
Exemplo n.º 3
0
static void gridnodes_tweaknpolar(gridnodes* gn)
{
    int nx = gridnodes_getnx(gn);
    int ny = gridnodes_getny(gn);
    double** gx = gridnodes_getx(gn);
    double** gy = gridnodes_gety(gn);
    int i, j;

    for (i = 0; i < nx; ++i)
        for (j = 1; j < ny; ++j)
            if (fabs(gx[j][i] - gx[j - 1][i]) > 180.0)
                gx[j][i] += 360.0;

    for (j = 0; j < ny; ++j)
        for (i = 1; i < nx; ++i)
            if (fabs(gx[j][i] - gx[j][i - 1]) > 180.0) {
                gx[j][i - 1] = NaN;
                gy[j][i - 1] = NaN;
            }

    for (j = 0; j < ny; ++j)
        for (i = 1; i < nx; ++i)
            if (fabs(gy[j][i] - gy[j][i - 1]) > 90.0) {
                gx[j][i - 1] = NaN;
                gy[j][i - 1] = NaN;
            }
}
Exemplo n.º 4
0
void grid_getdims(grid* g, int* ni, int* nj, int* nk)
{
    if (ni != NULL) {
        if (g->htype == GRIDHTYPE_LATLON_REGULAR || g->htype == GRIDHTYPE_LATLON_IRREGULAR) {
            gnxy_simple* nodes = (gnxy_simple*) g->gridnodes_xy;

            *ni = nodes->nx;
            *nj = nodes->ny;
#if !defined(NO_GRIDUTILS)
        } else if (g->htype == GRIDHTYPE_CURVILINEAR) {
            gnxy_curv* nodes = (gnxy_curv*) g->gridnodes_xy;

            *ni = gridnodes_getnx(nodes->gn);
            *nj = gridnodes_getny(nodes->gn);
#endif
        } else
            enkf_quit("programming error");
    }
    if (nk != NULL)
        *nk = g->gridnodes_z->nz;
}
Exemplo n.º 5
0
int main(int argc, char* argv[])
{
    char* fname1 = NULL;
    char* fname2 = NULL;
    gridnodes* grid1 = NULL;
    gridnodes* grid2 = NULL;
    gridnodes* grid3 = NULL;
    NODETYPE type = NT_NONE;
    int i0 = INT_MAX;
    int j0 = INT_MAX;
    int nx1 = 0;
    int ny1 = 0;
    int nx2 = 0;
    int ny2 = 0;
    int nx3 = 0;
    int ny3 = 0;
    double** gx1 = NULL;
    double** gy1 = NULL;
    double** gx2 = NULL;
    double** gy2 = NULL;
    double** gx3 = NULL;
    double** gy3 = NULL;
    int i1start, i2start, j1start, j2start;
    int i1, i2, j1, j2, i3, j3;

    parse_commandline(argc, argv, &fname1, &fname2, &i0, &j0, &type);
    grid1 = gridnodes_read(fname1, NT_NONE);
    grid2 = gridnodes_read(fname2, NT_NONE);

    nx1 = gridnodes_getnx(grid1);
    ny1 = gridnodes_getny(grid1);
    nx2 = gridnodes_getnx(grid2);
    ny2 = gridnodes_getny(grid2);

    gx1 = gridnodes_getx(grid1);
    gy1 = gridnodes_gety(grid1);
    gx2 = gridnodes_getx(grid2);
    gy2 = gridnodes_gety(grid2);

    nx3 = (i0 + nx2 > nx1) ? i0 + nx2 : nx1;
    ny3 = (j0 + ny2 > ny1) ? j0 + ny2 : ny1;
    grid3 = gridnodes_create(nx3, ny3, type);
    gx3 = gridnodes_getx(grid3);
    gy3 = gridnodes_gety(grid3);

    if (i0 < 0) {
        i1start = i0;
        i2start = 0;
    } else {
        i1start = 0;
        i2start = -i0;
    }
    if (j0 < 0) {
        j1start = j0;
        j2start = 0;
    } else {
        j1start = 0;
        j2start = -j0;
    }
    if (!merge) {
        for (j3 = 0, j1 = j1start, j2 = j2start; j3 < ny3; ++j3, ++j1, ++j2) {
            for (i3 = 0, i1 = i1start, i2 = i2start; i3 < nx3; ++i3, ++i1, ++i2) {
                int ok2 = (j2 >= 0 && j2 < ny2 && i2 >= 0 && i2 <= nx2);

                if (ok2) {
                    gx3[j3][i3] = gx2[j2][i2];
                    gy3[j3][i3] = gy2[j2][i2];
                } else {
                    int ok1 = (j1 >= 0 && j1 < ny1 && i1 >= 0 && i1 <= nx1);

                    if (ok1) {
                        gx3[j3][i3] = gx1[j1][i1];
                        gy3[j3][i3] = gy1[j1][i1];
                    } else {
                        gx3[j3][i3] = NaN;
                        gy3[j3][i3] = NaN;
                    }
                }
            }
        }
    } else {
        for (j3 = 0, j1 = j1start, j2 = j2start; j3 < ny3; ++j3, ++j1, ++j2) {
            for (i3 = 0, i1 = i1start, i2 = i2start; i3 < nx3; ++i3, ++i1, ++i2) {
                int ok2 = (j2 >= 0 && j2 < ny2 && i2 >= 0 && i2 <= nx2);
                int ok1 = (j1 >= 0 && j1 < ny1 && i1 >= 0 && i1 <= nx1);

                if (!ok2 && !ok1) {
                    gx3[j3][i3] = NaN;
                    gy3[j3][i3] = NaN;
                } else if (ok2 && !ok1) {
                    gx3[j3][i3] = gx2[j2][i2];
                    gy3[j3][i3] = gy2[j2][i2];
                } else if (!ok2 && ok1) {
                    gx3[j3][i3] = gx1[j1][i1];
                    gy3[j3][i3] = gy1[j1][i1];
                } else {
                    if (!isnan(gx2[j2][i2])) {
                        gx3[j3][i3] = gx2[j2][i2];
                        gy3[j3][i3] = gy2[j2][i2];
                    } else {
                        gx3[j3][i3] = gx1[j1][i1];
                        gy3[j3][i3] = gy1[j1][i1];
                    }
                }
            }
        }
    }

    gridnodes_validate(grid3);
    gridnodes_write(grid3, "stdout", CT_XY);

    gridnodes_destroy(grid1);
    gridnodes_destroy(grid2);
    gridnodes_destroy(grid3);

    return 0;
}