Example #1
0
void write_points(const char *fname, DATA *d, DPOINT *where, double *est,
	int n_outfl) {

	static FILE *f = NULL;
#ifdef HAVE_LIBGIS
	static Site *site = NULL;
	static int dim = 2;
	int i;
#endif 

	if (! grass()) {
		if (where == NULL) {
			if (fname != NULL) {
				f = efopen(fname, "w");
				write_ascii_header(f, d, n_outfl);
			} else
				efclose(f);
		} else {
			if (f == NULL)
				ErrMsg(ER_NULL, "write_points(): f");
			output_line(f, d, where, est, n_outfl);
		}
	} else {
#ifdef HAVE_LIBGIS
		if (where == NULL) {
			if (fname != NULL) { /* initialize: */
				DUMP("opening grass sites list\n");
				if (d->mode & Z_BIT_SET)
					dim++;
				if ((f = G_sites_open_new((char *) fname)) == NULL)
					G_fatal_error("%s: cannot open sites file %f for writing\n",
						G_program_name());
				site = G_site_new_struct(CELL_TYPE, dim, 0, n_outfl);
			} else { /* close: */
				DUMP("closing grass sites list\n");
				fclose(f);
				dim = 2;
				G_site_free_struct(site);
				site = NULL;
			}
		} else {
			assert(site != NULL);
			assert(d != NULL);
			/* fill site: */
			site->east = where->x;
			site->north = where->y;
			if (d->mode & Z_BIT_SET)
				site->dim[0] = where->z;
			if (d->mode & S_BIT_SET)
				site->ccat = where->u.stratum + strata_min;
			else
				site->ccat = GET_INDEX(where) + 1;
			for (i = 0; i < n_outfl; i++) {
				if (is_mv_double(&(est[i]))) {
					site->dbl_att[i] = -9999.0;
					if (DEBUG_DUMP)
						printlog(" [%d]:mv ", i);
				} else {
					site->dbl_att[i] = est[i];
					if (DEBUG_DUMP)
						printlog(" value[%d]: %g ", i, site->dbl_att[i]);
				}
			}
			if (DEBUG_DUMP)
				printlog("\n");
			G_site_put(f, site);
		}
#else 
		ErrMsg(ER_IMPOSVAL, "gstat/grass error: libgis() not linked");
#endif 
	}
}
Example #2
0
struct Map_info *G_fopen_sites_new(const char *name)
{
    return G_sites_open_new(name);
}