예제 #1
0
파일: vario_io.c 프로젝트: BenGraeler/gstat
double sem_cov_ab(VARIOGRAM *v, DPOINT *a, DPOINT *b, int sem)
/*
 * return Cov(a,b) or Sem(a,b),
 * taking care of IS_BLOCK(a) and IS_BLOCK(b):
 */
{
	static DATA *Discr_a = NULL, *Discr_b = NULL;
	static DPOINT *block_p = NULL;
	DPOINT *tmp;

	if (block_p == NULL)
		block_p = get_block_p();
	if (a == b) {
		if (IS_POINT(a))
			return sem_cov_blocks(v, NULL, NULL, sem);
		Discr_a = block_discr(Discr_a, block_p, a);
		return sem_cov_blocks(v, Discr_a, Discr_a, sem);
	}
	/*
	 * if one of them IS_BLOCK, make sure it's a: 
	 * (because block_discr() will otherwise store block
	 * discretisations in both Discr_a and Discr_b)
	 */
	if (IS_POINT(a) && IS_BLOCK(b)) {  
		tmp = a; a = b; b = tmp; /* swap a and b */
	}
	Discr_a = block_discr(Discr_a, block_p, a);
	Discr_b = block_discr(Discr_b, block_p, b);
	return sem_cov_blocks(v, Discr_a, Discr_b, sem);
}
예제 #2
0
파일: data.c 프로젝트: BenGraeler/gstat
void calc_polynomial_point(DATA *d, DPOINT *pt) {
	static DATA *bl = NULL;
	int j, k;

	bl = block_discr(bl, get_block_p(), pt);
	for (j = 0; j < d->n_X; j++) {
		if (d->colX[j] < -1)
			/* do eventual block averaging here: */
			for (k = 0, pt->X[j] = 0.0; k < bl->n_list; k++)
				pt->X[j] += bl->list[k]->u.weight *
						calc_polynomial(bl->list[k], d->colX[j]);
	}
}
예제 #3
0
파일: predict.c 프로젝트: abedzadeh/gstat
static double *get_maskX(DATA **data, DPOINT *p,
		unsigned int row, unsigned int col) {
	static double *d = NULL;
	static int totX = 0, *posMask = NULL;
	int i, j, k, l;
	static DATA *bl = NULL;
	static GRIDMAP **local_masks = NULL;

	if (data == NULL) {
		if (d != NULL) {
			efree(d);
			d = NULL;
			efree(posMask);
			posMask = NULL;
			local_masks = NULL;
			totX = 0;
		}
		return NULL;
	}
	if (d == NULL) { /* first time calling */
		for (i = 0, totX = 0; i < get_n_vars(); i++) 
			totX += data[i]->n_X;
		posMask = (int *) emalloc(totX * sizeof(int));
		d = (double *) emalloc(totX * sizeof(double));
		for (i = 0, k = 0; i < get_n_vars(); i++) {
			for (j = 0; j < data[i]->n_X; j++) {
				if (data[i]->colX[j] > 0)
					posMask[k] = 1;
				if (data[i]->colX[j] == 0)
					posMask[k] = 0;
				if (data[i]->colX[j] < -1)
					posMask[k] = -1;
				k++;
			}
		}
		if (get_mode() == STRATIFY) {
			if (get_n_masks() > 1)
				local_masks = masks + 1; /* skip the first (= strata) map */
		} else
			local_masks = masks;
	}

 	bl = block_discr(bl, get_block_p(), p);
 	/* bl is a single point-list with p if IS_POINT(p) */
	for (i = 0, k = 0; i < get_n_vars(); i++) {
		for (j = 0; j < data[i]->n_X; j++) {
			if (data[i]->colX[j] < -1) {
				/* do eventual block averaging here: */
				for (l = 0, d[k] = 0.0; l < bl->n_list; l++)
					d[k] += bl->list[l]->u.weight *
							calc_polynomial(bl->list[l], data[i]->colX[j]);
			}
			k++;
		}
	}

	for (i = 0, j = 0; i < totX; i++) {
		switch(posMask[i]) {
			case -1:
				/* is done above */
				break;
			case 1:
				if (map_cell_is_mv(local_masks[j], row, col))
					ErrMsg(ER_IMPOSVAL, "missing value in one of the mask maps");
				d[i] = map_get_cell(local_masks[j], row, col);
				j++;
				break;
			case 0:
				d[i] = (double) 1.0;
				break;
			default:
				ErrMsg(ER_IMPOSVAL, "get_maskX()");
				break;
		}
	}
	return d;
}