Example #1
0
File: vario.c Project: cran/gstat
VARIOGRAM *init_variogram(VARIOGRAM *v) {
/*
 * initializes one variogram structure
 * if v is NULL, memory is allocated for the structure
 */
	int i;

	if (v == NULL)
		v = (VARIOGRAM *) emalloc(sizeof(VARIOGRAM));

	v->id = v->id1 = v->id2 = -1;
	v->n_models = 0;
	v->is_valid_covariance = 1;
	v->isotropic = 1;
	v->n_fit = 0;
	v->fit_is_singular = 0;
	v->max_range = (double) DBL_MIN;
	v->sum_sills = 0.0;
	v->measurement_error = 0.0;
	v->max_val = 0.0;
	v->min_val = 0.0;
	vgm_init_block_values(v);
	v->part = (VGM_MODEL *) emalloc(INIT_N_VGMM * sizeof(VGM_MODEL));
	v->table = NULL;
	for (i = 0; i < INIT_N_VGMM; i++)
		init_variogram_part(&(v->part[i]));
	v->max_n_models = INIT_N_VGMM;
	v->SSErr = 0.0;
	v->ev = init_ev();

	return v;
}
Example #2
0
int ossfim(int argc, char *argv[]) {
	int c, n = 25, dx = 9, dy = 9, i, j, plot_vgm = 0;
	double b = 1, B = 10, s = 1, S = 10, blocksize, samplespacing, est[2],
		**table;
	DATA **d = NULL;
	DPOINT *block = NULL, where;
	char *vgm_str = "1Exp(10)", *map_name = NULL;
	VARIOGRAM *vgm;

	while ((c = getopt(argc, argv, "n:m:B:b:S:s:V:v:x:y:")) != EOF) {
		switch (c) {
			case 'n':
				if (read_int(optarg, &n) || n <= 0)
					ErrMsg(ER_ARGOPT, "n");
				break;
			case 'b':
				if (read_double(optarg, &b) || b < 0)
					ErrMsg(ER_ARGOPT, "b");
				break;
			case 'B':
				if (read_double(optarg, &B) || B <= 0)
					ErrMsg(ER_ARGOPT, "B");
				break;
			case 's':
				if (read_double(optarg, &s) || s <= 0)
					ErrMsg(ER_ARGOPT, "s");
				break;
			case 'S':
				if (read_double(optarg, &S) || S <= 0)
					ErrMsg(ER_ARGOPT, "S");
				break;
			case 'x':
				if (read_int(optarg, &dx) || dx <= 0)
					ErrMsg(ER_ARGOPT, "x");
				break;
			case 'y':
				if (read_int(optarg, &dy) || dy <= 0)
					ErrMsg(ER_ARGOPT, "y");
				break;
			case 'v':
				vgm_str = optarg;
				break;
			case 'V':
				plot_vgm = 1;
				vgm_str = optarg;
				break;
			case 'm':
				map_name = optarg;
				break;
			default:
				ErrClo(optopt);
				break;
		}
	}

	which_identifier("dummy grid");
	d = get_gstat_data();
	init_one_data(d[0]);
	d[0]->id = 0;
	d[0]->n_list = d[0]->n_max = 0;
	d[0]->mode = X_BIT_SET | Y_BIT_SET | V_BIT_SET;
	set_norm_fns(d[0]);
	vgm = get_vgm(0);
	if (read_variogram(vgm, vgm_str))
		ErrMsg(ER_SYNTAX, vgm_str);
	vgm->ev->evt = SEMIVARIOGRAM;
	vgm->id1 = vgm->id2 = d[0]->id;
	block = get_block_p();
	block->z = 0.0;
	block->x = block->y = -1.0;
	est[0] = 0.0;
	est[1] = -1.0;
	where.x = where.y = where.z = 0.0;
	where.X = (double *) emalloc(sizeof(double));
	where.X[0] = 1.0;

	if (plot_vgm)
		return fprint_gnuplot_variogram(stdout, vgm, "", GIF, 0);

	table = (double **) emalloc((dy + 1) * sizeof(double *));
	for (i = 0; i <= dy; i++)
		table[i] = (double *) emalloc((dx + 1) * sizeof(double));

	/* do it: */
	for (i = 0; i <= dx; i++) { /* sample spacing loop */
		samplespacing = s + (i / (1.0 * dx)) * (S - s);
		generate_grid(d[0], samplespacing, n);
		select_at(d[0], &where);
		for (j = 0; j <= dy; j++) { /* block sizes loop */
			reset_block_discr();
			vgm_init_block_values(vgm);
			blocksize = b + (j / (1.0 * dy)) * (B - b);
			block->x = block->y = blocksize;
			if (blocksize == 0.0)
				SET_POINT(&where);
			else
				SET_BLOCK(&where);
			gls(d, 1, GLS_BLUP, &where, est);
			if (map_name)
				table[i][j] = sqrt(est[1]);
			else
				printlog("%g %g %g\n", samplespacing, blocksize, sqrt(est[1]));
		}
	}
	if (map_name)
		ossfim2map(table, map_name, s, S, b, B, dx, dy);
	return 0;
}