[GRASS-SVN] r71950 - grass-addons/grass7/raster/r.resamp.tps

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Dec 18 14:18:56 PST 2017


Author: mmetz
Date: 2017-12-18 14:18:56 -0800 (Mon, 18 Dec 2017)
New Revision: 71950

Modified:
   grass-addons/grass7/raster/r.resamp.tps/cache.c
   grass-addons/grass7/raster/r.resamp.tps/cache.h
   grass-addons/grass7/raster/r.resamp.tps/main.c
Log:
r.resamp.tps: generalize cache interface

Modified: grass-addons/grass7/raster/r.resamp.tps/cache.c
===================================================================
--- grass-addons/grass7/raster/r.resamp.tps/cache.c	2017-12-18 08:40:07 UTC (rev 71949)
+++ grass-addons/grass7/raster/r.resamp.tps/cache.c	2017-12-18 22:18:56 UTC (rev 71950)
@@ -1,5 +1,4 @@
 #include <string.h>
-#include <grass/raster.h>
 #include <grass/segment.h>
 #include <grass/glocale.h>
 #include "cache.h"
@@ -29,16 +28,22 @@
     return p;
 }
 
-int cache_create(struct cache *c, int nrows, int ncols, int seg_size,
-                 int use_seg, int nbytes, int nseg)
+int cache_create(struct cache *c, int nrows, int ncols, int srows,
+                 int scols, int nbytes, int nseg)
 {
+    int nseg_total;
+
     c->n = nbytes;
     c->rows = nrows;
     c->cols = ncols;
 
-    if (use_seg) {
-	G_verbose_message("Using segment lib");
-	if (Segment_open(&c->s, G_tempfile(), nrows, ncols, seg_size, seg_size,
+    nseg_total = ((nrows + srows - 1) / srows) * 
+                 ((ncols + scols - 1) / scols);
+
+    if (nseg < nseg_total) {
+	G_verbose_message("Using disk cache");
+
+	if (Segment_open(&c->s, G_tempfile(), nrows, ncols, srows, scols,
 			 nbytes, nseg) != 1)
 	    G_fatal_error("Unable to create temporary file");
 

Modified: grass-addons/grass7/raster/r.resamp.tps/cache.h
===================================================================
--- grass-addons/grass7/raster/r.resamp.tps/cache.h	2017-12-18 08:40:07 UTC (rev 71949)
+++ grass-addons/grass7/raster/r.resamp.tps/cache.h	2017-12-18 22:18:56 UTC (rev 71950)
@@ -10,8 +10,8 @@
     void *(* put)(struct cache *c, void *p, int row, int col);
 };
 
-int cache_create(struct cache *c, int nrows, int ncols, int seg_size,
-                 int use_seg, int nbytes, int nseg);
+int cache_create(struct cache *c, int nrows, int ncols, int srows,
+                 int scols, int nbytes, int nseg);
 int cache_destroy(struct cache *c);
 void *cache_get(struct cache *c, void *p, int row, int col);
 void *cache_put(struct cache *c, void *p, int row, int col);

Modified: grass-addons/grass7/raster/r.resamp.tps/main.c
===================================================================
--- grass-addons/grass7/raster/r.resamp.tps/main.c	2017-12-18 08:40:07 UTC (rev 71949)
+++ grass-addons/grass7/raster/r.resamp.tps/main.c	2017-12-18 22:18:56 UTC (rev 71950)
@@ -268,7 +268,7 @@
     G_message(_("Loading input..."));
 
     insize = (1 + n_vars) * sizeof(DCELL);
-    if (cache_create(&in_seg, nrows, ncols, 64, nsegs < nsegs_total, 
+    if (cache_create(&in_seg, nrows, ncols, 64, 64, 
                      insize, nsegs) != 1) {
 	G_fatal_error("Unable to create input temporary files");
     }
@@ -327,7 +327,7 @@
     nrows = dst.rows;
     ncols = dst.cols;
 
-    if (cache_create(&out_seg, nrows, ncols, 64, nsegs < nsegs_total, 
+    if (cache_create(&out_seg, nrows, ncols, 64, 64, 
                      sizeof(struct tps_out), nsegs) != 1) {
 	G_fatal_error("Unable to create input temporary files");
     }
@@ -337,7 +337,7 @@
 	/* intialize output raster and load corresponding covariables */
 	G_message(_("Loading covariables for output..."));
 	varsize = (n_vars) * sizeof(DCELL);
-	if (cache_create(&var_seg, nrows, ncols, 64, nsegs < nsegs_total, 
+	if (cache_create(&var_seg, nrows, ncols, 64, 64, 
 			 varsize, nsegs) != 1) {
 	    G_fatal_error("Unable to create input temporary files");
 	}



More information about the grass-commit mailing list