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() */
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); }