Exemplo n.º 1
0
int main(int argc, char **argv)
{
    srand(time(NULL));
    clock_t beg, end;

    cmd_args args;
    parse_options(argc, argv, &args);
    
    grid *gd = allocate_grid(args.width, args.height);
    
    beg = clock();
    run_percolation(gd, args.prob, args.recursive);
    end = clock();
    
    if (args.img_output)
        create_image(args.filename, gd, args.size, args.color);
    
    printf("Finished in %g sec\n", (double)(end - beg) / CLOCKS_PER_SEC);

    free_grid(gd);
    
    return 0;
}
Exemplo n.º 2
0
/* ---------------------------------------------------------------------- */
void
mexFunction(int nlhs,       mxArray *plhs[],
            int nrhs, const mxArray *prhs[])
/* ---------------------------------------------------------------------- */
{
    double                tolerance;
    char                  errmsg[1023 + 1];
    struct grdecl         grdecl;
    struct processed_grid g;

    if (args_ok(nlhs, nrhs, prhs)) {
        mx_init_grdecl(&grdecl, prhs[0]);
        tolerance = define_tolerance(nrhs, prhs);

        process_grdecl(&grdecl, tolerance, &g);

        plhs[0] = allocate_grid(&g, mexFunctionName());

        if (plhs[0] != NULL) {
            fill_grid(plhs[0], &g);
        } else {
            /* Failed to create grid structure.  Return empty. */
            plhs[0] = mxCreateDoubleMatrix(0, 0, mxREAL);
        }

        free_processed_grid(&g);
    } else {
        sprintf(errmsg,
                "Calling sequence is\n\t"
                "G = %s(grdecl)\t%%or\n\t"
                "G = %s(grdecl, tolerance)\n"
                "The 'grdecl' must be a valid structure with fields\n"
                "\t'cartDims', 'COORD', 'ZCORN'",
                mexFunctionName(), mexFunctionName());
        mexErrMsgTxt(errmsg);
    }
}
Exemplo n.º 3
0
int
main(int argc, char *argv[])
{
    char input[MAX_FILENAME_SIZE];
    int c;
    int iterations = 1;
    int generate = 0;
    struct Grid *grid;
    struct Grid *tmp_grid;

    if (argc < 2) {
        help();
        return 0;
    }

    while ((c = getopt(argc, argv, "?hv:n:i:g")) != -1) {
        switch (c) {
            case 'h':
            case 'v':
                help();
                return 0;
            case 'n':
                iterations = atoi((char *) getopt);
                break;
            case 'i':
                strncpy(input, optarg, MAX_FILENAME_SIZE);
                break;
            case 'g':
                generate = 1;
                break;
            default:
                help();
                return 0;
        }
    } 

    if (argc != optind) {
        help();
        return 0;
    }

    grid = allocate_grid();
    tmp_grid = allocate_grid();
    if (!grid || !tmp_grid) {
        printf("error: out of memory\n");
        return -1;
    }
    if (generate) {
        generate_grid(grid);
    } else {
        read_grid(input, grid); 
    }
    for (c = 0; c < iterations; c++) {
        mean_filter(grid, tmp_grid);
        struct Grid *tmp = grid;
        grid = tmp_grid;
        tmp_grid = tmp;
    }
    write_grid(grid);
    cleanup_grid(grid);
    cleanup_grid(tmp_grid);

    return 0;
}