コード例 #1
0
ファイル: nsearch.c プロジェクト: BenGraeler/gstat
static void init_qtree(DATA *d) {
/*
 * Initialize the root of the search tree:
 * Since this is called from qtree_quick_select(), we know allready
 * quite a lot. This helps choosing sensible values for the 
 * top level bbox origin and size.
 */
 	const GRIDMAP *gt = NULL;
 	DATA *simlocs = NULL;
 	int i, mode;
 	BBOX bbox;

	if (is_simulation(get_method())) {
		/*
		 * sequential simulation: the simulation path (through DATA or GRIDMAP)
		 * will make up for (most of) the search locations:
		 */
		gt = (const GRIDMAP *) NULL;
		simlocs = get_dataval();
		/* in case of simulation one of them will be non-NULL */
	} 

	/* get initial estimate for top level bbox: */
	if (gt != NULL)
		bbox = bbox_from_grid(gt, NULL);
	else if (simlocs != NULL) {
		bbox = bbox_from_data(simlocs);
		if (bbox.size <= 0.0)
			bbox = bbox_from_data(d);
	} else
		bbox = bbox_from_data(d);
	if (bbox.size <= 0.0)
		bbox = bbox_from_data(get_dataval());
	if (bbox.size <= 0.0)
		ErrMsg(ER_IMPOSVAL, "bbox with zero size: remove neighbourhood settings?");
	init_qnode(&(d->qtree_root), d->n_list < gl_split, bbox); /* ML1 */
	
	mode = bbox.mode;

	for (i = 0; i < d->n_list; i++)
		qtree_push_point(d, d->list[i]); /* now they won't be rejected */ /* ML2 */

	if (DEBUG_DUMP) {
		printlog("top level search tree statistics for data(%s):\n",
			name_identifier(d->id));
		printlog("bounding box origin [");
		if (mode & X_BIT_SET)
			printlog("%g", d->qtree_root->bb.x);
		if (mode & Y_BIT_SET)
			printlog(",%g", d->qtree_root->bb.y);
		if (mode & Z_BIT_SET)
			printlog(",%g", d->qtree_root->bb.z);
		printlog("]; dimension %g\n", d->qtree_root->bb.size);
	}
	/* qtree_print(d); */
	return;
}
コード例 #2
0
ファイル: gstat.c プロジェクト: Andlon/cs267FinalProject
int main(int argc, char *argv[]) {
#else
int gstat_main(int argc, char *argv[]) {
#endif

	DATA      **data = NULL, *valdata = NULL;

/*
 * initialise some global variables:
 */
	atexit(close_gstat_log_file);
	init_userio(1);
	init_global_variables();
	argv0 = argv[0];
/*
 * register command line arguments on command_line:
 */
	command_line = store_argv(argc, argv);
	parse_gstatrc();
/*
 * INPUT: command line options;
 */
	parse_options(argc, argv); /* exits on -e options */

/*
 * start with program heading:
 */
	printlog("%s: %s version %s\n", GSTAT_NAME, GSTAT_OS, VERSION);
	printlog("%s\n", GSTAT_CR);
	gstat_start();

/*
 * INPUT: Parse command files: 
 */
	if (optind == argc) { /* there's no command file name left */
		if (get_method() != UIF) { /* -i or -m command line option */
			/* no arguments */
			printlog("Updates, manuals and source code: %s\n", 
				GSTAT_HOME);
			printlog("%s\n", USAGE);
			ErrMsg(ER_NOCMD, "");
		} else {
			start_ui();
			exit(0);
		}
	} else { /* we have a command file to be read */
		for ( ; optind < argc; optind++) {
			command_file_name = argv[optind];
			parse_file(command_file_name);
			if (logfile_name != NULL)
				set_gstat_log_file(efopen(logfile_name, "w"));
/* 
 * get global variables locally: 
 */
			data = 			get_gstat_data();
			valdata = 		get_dataval();
			set_seed(gl_seed);

/* 
 * check variable settings and next
 * INPUT: read data values from file: 
 */
			read_all_data(data, valdata, get_n_vars());
			if (get_method() == NSP) /* Still no answer to this: choose default */
				set_method(get_default_method());
			set_mode();
			check_global_variables();
			setup_meschach_error_handler();
			if (DEBUG_DUMP)
				dump_all();
			if (get_method() != NSP)
				printlog("[%s]\n", method_string(get_method()));
			if (check_only)
				set_method(NSP);

/*
 * start calculations && OUTPUT routines:
 */
			switch (get_method()) {
				case UIF:
					start_ui();
					break;
				case NSP:
					break;
				case COV: 
				case SEM:
					do_variogram(get_n_vars(), get_method());
					break;
        		case POLY:
            		setup_poly_method();
            		/*FALLTHROUGH*/
				default: 
					if (gl_xvalid) /* validation/cross validation */
						cross_valid(data);
					else
						predict_all(data); /* or prediction: */
					break;
			} /* switch get_method() */
			remove_all(); /* free all data etc. */
			init_global_variables(); /* re-init for next round */
		}
	}

	if (DEBUG_DUMP)
		atexit(print_file_record);

	if (get_method() != UIF)
		elapsed();
/* 
 * file closing & data freeing time:
 */
	if (plotfile != NULL)
		efclose(plotfile);

	exit(0);
} /* end of main() */
コード例 #3
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);
}