コード例 #1
0
ファイル: glvars.c プロジェクト: BenGraeler/gstat
void remove_all(void) {

	while (n_vars)
		remove_id(0); /* hard way */
	/* for (i = n_vars-1; i >= 0; i--)
		remove_id(i);
	*/
	/* remove_id(n_vars - 1);  */
	/* the hard way; remove_id(n_vars-1) would be the ``easy'' alternative */
	gls(NULL, 0, GLS_INIT, NULL, NULL); /* cleans up static arrays */
	reset_block_discr(); /* resets block settings */
	max_block_dimension(1); /* reset */
	if (gl_bounds != NULL) {
		efree(gl_bounds);
		gl_bounds = NULL;
	}
	if (valdata != NULL)
		free_data(valdata);
	valdata = NULL;
}
コード例 #2
0
ファイル: predict.c プロジェクト: abedzadeh/gstat
void predict_all(DATA **data) {
	int i = 0, random_path = 0;
	DPOINT *here = NULL, *where = NULL;
	PRED_AT at_what;
	unsigned int row, col;

	n_done = 0;
	val_data = get_dataval();
	if (val_data->id > -1) {
		at_what = AT_POINTS;
		n_pred_locs = val_data->n_list;
		if (val_data->colns)
			strata_min = val_data->minstratum;
	} else if (get_n_masks() > 0) {
		at_what = AT_GRIDMAP;
		here = (DPOINT *) emalloc(sizeof(DPOINT));
		here->u.stratum = -2; /* only NON-MV cells */
		if (max_block_dimension(0) > 0.0)
			SET_BLOCK(here);
		else
			SET_POINT(here);
	} else /* what else ? */
		return;

	if (at_what == AT_GRIDMAP && get_n_outfile() == 0) {
		pr_warning("no output maps defined");
		return;
	}

	init_predictions(at_what);

	if (at_what == AT_GRIDMAP && !data[0]->dummy) { 
		if (data[0]->maxX < masks[0]->x_ul ||
				data[0]->minX > (masks[0]->x_ul + masks[0]->cols * masks[0]->cellsizex) ||
				data[0]->minY > masks[0]->y_ul ||
				data[0]->maxY < (masks[0]->y_ul - masks[0]->rows * masks[0]->cellsizey)) {
			pr_warning("ALL data are outside the map boundaries");
			printlog("data x[%g,%g], y[%g,%g]; map x[%g,%g], y[%g,%g]\n",
				data[0]->minX, data[0]->maxX, data[0]->minY, data[0]->maxY,
				masks[0]->x_ul,
				masks[0]->x_ul + masks[0]->cols * masks[0]->cellsizex,
				masks[0]->y_ul - masks[0]->rows * masks[0]->cellsizey,
				masks[0]->y_ul
				);
		}
		else if (map_xy2rowcol(masks[0], data[0]->minX, data[0]->minY, &row, &col) ||
				map_xy2rowcol(masks[0], data[0]->maxX, data[0]->minY, &row, &col) ||
				map_xy2rowcol(masks[0], data[0]->minX, data[0]->maxY, &row, &col) ||
				map_xy2rowcol(masks[0], data[0]->maxX, data[0]->maxY, &row, &col))
			pr_warning("at least some data are outside the map boundaries");
			/* this is not a sufficient test! */
	}

	if (gl_rp) /* Yes, by default */
		random_path = is_simulation(get_method());
	row = col = 0;
	while ((where = next_location(here, at_what, random_path,
			&row, &col, data)) != NULL) {
		for (i = 0; i < get_n_outfile(); i++)
			set_mv_double(&(est[i])); /* initialize estimates */
		if (where->u.stratum >= 0) {
			if (get_mode() != STRATIFY) {
				for (i = 0; i < get_n_vars(); i++)
					select_at(data[i], where);
			} else if (where->u.stratum < get_n_vars())
				select_at(data[where->u.stratum], where);
			get_est(data, get_method(), where, est);
		}
		/* printf("%g %g\n", est[0], est[1]); */
		write_output(est, at_what, where, row, col);
	}
	exit_predictions(at_what);
	if (here != NULL)
		efree(here);
	print_progress(100, 100);
}
コード例 #3
0
ファイル: glvars.c プロジェクト: BenGraeler/gstat
void check_global_variables(void) {
/*
 * Purpose       : check internal variable consistency, add some parameters 
 * Created by    : Edzer J. Pebesma
 * Date          : april 13, 1992
 * Prerequisites : none
 * Returns       : -
 * Side effects  : none
 * also check Cauchy-Schwartz unequality on cross/variograms.
 */
	int i, j, nposX, n_merge = 0;
	METHOD m;
	VARIOGRAM *v_tmp;

	/* UK: check if n_masks equals total nr of unbiasedness cond. */
	if (gl_nblockdiscr < 2)
		ErrMsg(ER_RANGE, "nblockdiscr must be >= 2");
	if (method == UKR || method == LSLM) {
		nposX = 0;
		for (i = 0; i < get_n_vars(); i++)
			for (j = 0; j < data[i]->n_X; j++) {
				if (data[i]->colX[j] > 0)
					nposX++;
			}
	}
    
	if (method == SPREAD) {
		for (i = 0; i < get_n_vars(); i++)
			if (data[i]->sel_rad == DBL_MAX)
				data[i]->sel_rad *= 0.99; /* force distance calculation */
	}

	if (get_n_beta_set() != 0 && get_n_beta_set() != get_n_vars())
		ErrMsg(ER_SYNTAX, 
			"set sk_mean or beta either for all or for no variables");

	if (!(method == ISI || method == GSI)) {
		if (gl_nsim > 1)
			ErrMsg(ER_IMPOSVAL, "nsim only allowed for simulation");
	}

	if (method == ISI && max_block_dimension(0) > 0.0)
		ErrMsg(ER_IMPOSVAL, "indicator simulation only for points");
	/*
	 * check if both block and area are set
	 */
	if (data_area != NULL && (block.x > 0.0 || block.y > 0.0 || block.z > 0.0))
		ErrMsg(ER_IMPOSVAL, "both block and area set: choose one");
	/*
	 * check for equality of coordinate dimensions:
	 */
	for (i = 1; i < get_n_vars(); i++) {
		if ((data[i]->mode & V_BIT_SET) != (data[0]->mode & V_BIT_SET))  {
			message("data(%s) and data(%s):\n", name_identifier(0), 
				name_identifier(i));
			ErrMsg(ER_IMPOSVAL, "data have different coordinate dimensions");
		}
	}
	if (valdata->id > 0 && data[0]->dummy == 0 &&
			((data[0]->mode | (V_BIT_SET | S_BIT_SET)) !=
			 (valdata->mode | (V_BIT_SET | S_BIT_SET)))) {
		message("data() and data(%s):\n", name_identifier(0));
		ErrMsg(ER_IMPOSVAL, "data have different coordinate dimensions");
		for (i = 0; i < get_n_vars(); i++) {
			if (data[i]->dummy) {
				data[i]->mode = (valdata->mode | V_BIT_SET);
				data[i]->minX = valdata->minX;
				data[i]->minY = valdata->minY;
				data[i]->minZ = valdata->minZ;
				data[i]->maxX = valdata->maxX;
				data[i]->maxY = valdata->maxY;
				data[i]->maxZ = valdata->maxZ;
				set_norm_fns(data[i]);
			}
		}
	}

	for (i = 0; i < get_n_vars(); i++) {
		if (data[i]->fname == NULL && !data[i]->dummy) {
			message("file name for data(%s) not set\n", name_identifier(i));
			ErrMsg(ER_NULL, " ");
		}
		if (data[i]->id < 0) {
			message("data(%s) not set\n", name_identifier(i));
			ErrMsg(ER_NULL, " ");
		}
		if (data[i]->beta && data[i]->beta->size != data[i]->n_X) {
			pr_warning("beta dimension (%d) should equal n_X (%d)", 
				data[i]->beta->size, data[i]->n_X);
			ErrMsg(ER_IMPOSVAL, "sizes of beta and X don't match");
		}
		if (data[i]->sel_rad == DBL_MAX && data[i]->oct_max > 0)
			ErrMsg(ER_IMPOSVAL, 
				"define maximum search radius (rad) for octant search");
		if (data[i]->vdist && data[i]->sel_rad == DBL_MAX)
			ErrMsg(ER_IMPOSVAL, "when using vdist, radius should be set");
		if (! data[i]->dummy && ! (data[i]->mode & V_BIT_SET)) {
			message("no v attribute set for data(%s)\n", 
				name_identifier(data[i]->id));
			ErrMsg(ER_NULL, " ");
		}
		if (method != SEM && method != COV) {
			/* check neighbourhood settings */
			if (data[i]->sel_rad < 0.0 || data[i]->sel_min < 0 || 
				data[i]->sel_max < 0 || (data[i]->sel_min > data[i]->sel_max)) {
				message(
				"invalid neighbourhood selection: radius %g max %d min %d\n", 
				data[i]->sel_rad, data[i]->sel_max, data[i]->sel_min);
				ErrMsg(ER_IMPOSVAL, " ");
			}
		}
		if (data[i]->id > -1 && (method == OKR || method == SKR || 
				is_simulation(method) || method == UKR)) {
			if (vgm[LTI(i,i)] == NULL || vgm[LTI(i,i)]->id < 0) {
				message("variogram(%s) not set\n", name_identifier(i));
				ErrMsg(ER_VARNOTSET, "variogram()");
			}
		}
		n_merge += data[i]->n_merge;
	}
	if (n_merge && get_mode() != MULTIVARIABLE)
		ErrMsg(ER_IMPOSVAL, "merge only works in multivariable mode");
	if (mode == SIMPLE && get_method() != UIF) {  /* check if it's clean: */
		for (i = 0; i < get_n_vars(); i++)
			for (j = 0; j < i; j++)
				if (vgm[LTI(i,j)] != NULL && vgm[LTI(i,j)]->id > 0) {
					message("variogram(%s, %s) %s\n", name_identifier(i),
						name_identifier(j),
					"can only be set for ck, cs, uk, sk, ok, sem or cov");
					ErrMsg(ER_IMPOSVAL, "variogram()");
				}
	} 
	if ((m = get_default_method()) != get_method()) {
		if (m == UKR && (get_method() == OKR || get_method() == SKR))
			ErrMsg(ER_IMPOSVAL,
				"\nremove X=... settings for ordinary or simple kriging");
		if (m == OKR && get_method() == SKR)
			ErrMsg(ER_IMPOSVAL, "method: something's terribly wrong!");
		if (m == OKR && get_method() == UKR) {
			message("I would recommend:\n");
			message("Do not specify uk if ok is all you'll get\n");
		}
	}
	if (mode == MULTIVARIABLE && get_method() != UIF && get_method() != SEM
			&& get_method() != COV && n_variograms_set() > 0)
		check_variography((const VARIOGRAM **) vgm, get_n_vars());
	v_tmp = init_variogram(NULL);
	free_variogram(v_tmp);
}