[GRASS-SVN] r69860 - grass-addons/grass7/raster/r.hants

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Nov 21 12:37:37 PST 2016


Author: mmetz
Date: 2016-11-21 12:37:36 -0800 (Mon, 21 Nov 2016)
New Revision: 69860

Modified:
   grass-addons/grass7/raster/r.hants/main.c
Log:
r.hants: add flag to avoid extrapolation

Modified: grass-addons/grass7/raster/r.hants/main.c
===================================================================
--- grass-addons/grass7/raster/r.hants/main.c	2016-11-21 15:51:28 UTC (rev 69859)
+++ grass-addons/grass7/raster/r.hants/main.c	2016-11-21 20:37:36 UTC (rev 69860)
@@ -134,7 +134,7 @@
     } parm;
     struct
     {
-	struct Flag *lo, *hi, *lazy;
+	struct Flag *lo, *hi, *lazy, *int_only;
     } flag;
     int i, j, k;
     int num_inputs;
@@ -152,6 +152,7 @@
     int bl;
     double **mat, **mat_t, **A, *Av, *Azero, *za, *zr, maxerrlo, maxerrhi;
     int asize;
+    int first, last, interp_only;
     int dod, nf, nr, nout, noutmax;
     int rejlo, rejhi, *useval;
     int do_amp, do_phase;
@@ -250,6 +251,10 @@
     flag.lazy->key = 'z';
     flag.lazy->description = _("Don't keep files open");
 
+    flag.int_only = G_define_flag();
+    flag.int_only->key = 'i';
+    flag.int_only->description = _("Do not extrapolate, only interpolate");
+
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -302,6 +307,8 @@
     if ((rejlo || rejhi) && !parm.fet->answer)
 	G_fatal_error(_("Fit error tolerance is required when outliers should be rejected"));
 
+    interp_only = flag.int_only->answer;
+
     /* process the input maps from the file */
     if (parm.file->answer) {
 	FILE *in;
@@ -537,6 +544,8 @@
 	for (col = 0; col < ncols; col++) {
 	    int null = 0, non_null = 0;
 
+	    first = last = -1;
+
 	    for (i = 0; i < num_inputs; i++) {
 		DCELL v = inputs[i].buf[col];
 
@@ -551,12 +560,21 @@
 		else {
 		    non_null++;
 		    useval[i] = 1;
+
+		    if (first == -1)
+			first = i;
+		    last = i;
 		}
 
 		values[i] = v;
 	    }
 	    nout = null;
 
+	    if (!interp_only) {
+		first = 0;
+		last = num_inputs - 1;
+	    }
+
 	    /* HANTS */
 	    if (nout <= noutmax) {
 		int n = 0, done = 0;
@@ -645,9 +663,17 @@
 			done = 1;
 		}
 
-		for (i = 0; i < num_outputs; i++) {
+		i = 0;
+		while (i < first) {
 		    struct output *out = &outputs[i];
 
+		    Rast_set_d_null_value(&out->buf[col], 1);
+		    i++;
+		}
+
+		for (i = first; i <= last; i++) {
+		    struct output *out = &outputs[i];
+
 		    out->buf[col] = rc[i];
 		    if (rc[i] < lo)
 			out->buf[col] = lo;
@@ -655,6 +681,14 @@
 			out->buf[col] = hi;
 		}
 
+		i = last + 1;
+		while (i < num_outputs) {
+		    struct output *out = &outputs[i];
+
+		    Rast_set_d_null_value(&out->buf[col], 1);
+		    i++;
+		}
+
 		if (do_amp || do_phase) {
 		    /* amplitude and phase */
 		    /* skip constant */



More information about the grass-commit mailing list