[GRASS-SVN] r70516 - in grass/trunk: include/iostream raster/r.terraflow

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Feb 9 06:35:23 PST 2017


Author: martinl
Date: 2017-02-09 06:35:23 -0800 (Thu, 09 Feb 2017)
New Revision: 70516

Modified:
   grass/trunk/include/iostream/empq_adaptive.h
   grass/trunk/raster/r.terraflow/Makefile
   grass/trunk/raster/r.terraflow/common.h
   grass/trunk/raster/r.terraflow/filldepr.cpp
   grass/trunk/raster/r.terraflow/flow.cpp
   grass/trunk/raster/r.terraflow/grass2str.h
   grass/trunk/raster/r.terraflow/main.cpp
   grass/trunk/raster/r.terraflow/main.h
   grass/trunk/raster/r.terraflow/plateau.cpp
   grass/trunk/raster/r.terraflow/stats.cpp
   grass/trunk/raster/r.terraflow/sweep.cpp
Log:
r.terraflow requires all output options to be given (see #3280)
            be also LESS verbose


Modified: grass/trunk/include/iostream/empq_adaptive.h
===================================================================
--- grass/trunk/include/iostream/empq_adaptive.h	2017-02-09 14:19:09 UTC (rev 70515)
+++ grass/trunk/include/iostream/empq_adaptive.h	2017-02-09 14:35:23 UTC (rev 70516)
@@ -44,10 +44,9 @@
 #include "empq_impl.h"
 
 
+#define EMPQAD_DEBUG if(G_verbose() > G_verbose_std())
 
-#define EMPQAD_DEBUG if(1)
 
-
 enum regim_type {
   INMEM = 0,
   EXTMEM,

Modified: grass/trunk/raster/r.terraflow/Makefile
===================================================================
--- grass/trunk/raster/r.terraflow/Makefile	2017-02-09 14:19:09 UTC (rev 70515)
+++ grass/trunk/raster/r.terraflow/Makefile	2017-02-09 14:35:23 UTC (rev 70516)
@@ -2,8 +2,8 @@
 
 PGM = r.terraflow
 
-LIBES = $(RASTERLIB) $(GISLIB) $(IOSTREAMLIB) $(MATHLIB)
-DEPENDENCIES = $(RASTERDEP) $(GISDEP) $(IOSTREAMDEP)
+LIBES = $(GISLIB) $(RASTERLIB) $(IOSTREAMLIB) $(MATHLIB)
+DEPENDENCIES = $(GISDEP) $(RASTERDEP) $(IOSTREAMDEP)
 
 include $(MODULE_TOPDIR)/include/Make/Module.make
 

Modified: grass/trunk/raster/r.terraflow/common.h
===================================================================
--- grass/trunk/raster/r.terraflow/common.h	2017-02-09 14:19:09 UTC (rev 70515)
+++ grass/trunk/raster/r.terraflow/common.h	2017-02-09 14:35:23 UTC (rev 70516)
@@ -30,6 +30,7 @@
 #include "types.h" /* for dimension_type */
 extern "C" {
 #include <grass/gis.h>
+#include <grass/glocale.h>
 }
 
 

Modified: grass/trunk/raster/r.terraflow/filldepr.cpp
===================================================================
--- grass/trunk/raster/r.terraflow/filldepr.cpp	2017-02-09 14:19:09 UTC (rev 70515)
+++ grass/trunk/raster/r.terraflow/filldepr.cpp	2017-02-09 14:35:23 UTC (rev 70516)
@@ -18,12 +18,10 @@
 
 #include <assert.h>
 
-#include <grass/iostream/ami.h>
 #include "filldepr.h"
 #include "unionFind.h"
 #include "common.h"
 
-
 #define FLOOD_DEBUG if(0)
 
 /************************************************************/
@@ -58,8 +56,9 @@
   }
   
   /* find available memory */
-   size_t mem_avail = getAvailableMemory();
-  MM_manager.print();
+  size_t mem_avail = getAvailableMemory();
+  if (opt->verbose)
+    MM_manager.print();
   
   /* find how much memory filling depression uses */
   size_t mem_usage = inmemory_fill_depression_mmusage(maxWatersheds);
@@ -77,9 +76,7 @@
 elevation_type* 
 ext_fill_depression(AMI_STREAM<boundaryType> *boundaryStr,
 			 cclabel_type maxWatersheds) {
- 
-  fprintf(stderr, "fill_depressions: does not fit in memory\n");
-  G_fatal_error("not implemented yet");
+  G_fatal_error(_("Fill_depressions do not fit in memory. Not implemented yet"));
 }
 
 
@@ -186,8 +183,8 @@
   for (cclabel_type i=1; i< maxWatersheds; i++) {
     /* assert(done[unionf.findSet(i)]); sometimes this fails! */
     if (!done[unionf.findSet(i)]) {
-      fprintf(stderr, "warning: watershed %d (R=%d) not done\n", 
-	     i, unionf.findSet(i));
+      G_warning(_("Watershed %d (R=%d) not done"), 
+                i, unionf.findSet(i));
     }
   }
 #endif

Modified: grass/trunk/raster/r.terraflow/flow.cpp
===================================================================
--- grass/trunk/raster/r.terraflow/flow.cpp	2017-02-09 14:19:09 UTC (rev 70515)
+++ grass/trunk/raster/r.terraflow/flow.cpp	2017-02-09 14:35:23 UTC (rev 70516)
@@ -218,20 +218,17 @@
 				nodataType::ELEVATION_NODATA, sweepstr);
   delete fillStream;
 
-  if (opt->verbose) {
-    fprintf(stderr,  "sweep stream size: %.2fMB",
-			(double)sweepstr->stream_len()*sizeof(sweepItem)/(1<<20));
-    fprintf(stderr,  " (%d items, item size=%d B\n ", 
-			(int)sweepstr->stream_len(), sizeof(sweepItem));;
-  }
+  G_debug(1, "sweep stream size: %.2fMB",
+          (double)sweepstr->stream_len()*sizeof(sweepItem)/(1<<20));
+  G_debug(1, " (%d items, item size=%d B\n ", 
+          (int)sweepstr->stream_len(), sizeof(sweepItem));;
+
   if (stats)
     stats->recordLength("sweep stream", sweepstr);
   
   /* sort sweep stream by (increasing) priority */
-  if (opt->verbose) {
-    fprintf(stderr, "sorting sweep stream (%.2fMB) in priority order\n", 
-	    (double)sweepstr->stream_len()*sizeof(sweepItem)/(1<<20));
-  }
+  G_debug(1, "Sorting sweep stream (%.2fMB) in priority order", 
+          (double)sweepstr->stream_len()*sizeof(sweepItem)/(1<<20));
   if (stats)
     stats->comment("sorting sweep stream");
   sort(&sweepstr, PrioCmpSweepItem());

Modified: grass/trunk/raster/r.terraflow/grass2str.h
===================================================================
--- grass/trunk/raster/r.terraflow/grass2str.h	2017-02-09 14:19:09 UTC (rev 70515)
+++ grass/trunk/raster/r.terraflow/grass2str.h	2017-02-09 14:35:23 UTC (rev 70516)
@@ -55,19 +55,13 @@
     G_verbose_message(_("Reading data from <%s> to stream <%s>"), cellname, foo);
   }
 
-  const char *mapset;
-  mapset = G_find_raster (cellname, "");
-  if (mapset == NULL)
-    G_fatal_error(_("Raster map <%s> not found"), cellname);
-  
   /* open map */
   int infd;
-  if ( (infd = Rast_open_old (cellname, mapset)) < 0)
-    G_fatal_error(_("Unable to open raster map <%s>"), cellname);
+  infd = Rast_open_old (cellname, "");
   
   /* determine map type (CELL/FCELL/DCELL) */
   RASTER_MAP_TYPE data_type;
-  data_type = Rast_map_type(cellname, mapset);
+  data_type = Rast_map_type(cellname, "");
   
   /* Allocate input buffer */
   void *inrast;
@@ -79,6 +73,7 @@
   T x;
   int isnull = 0;
 
+  G_important_message(_("Reading input data..."));
   for (int i = 0; i< nrows; i++) {
 
 	/* read input map */
@@ -130,11 +125,10 @@
 	  
 	} /* for j */
 
-	if (opt->verbose) G_percent(i, nrows, 2);
+	G_percent(i, nrows, 2);
   }/* for i */
 
-  if (opt->verbose)
-	G_percent(1, 1, 2); /* finish it */
+  G_percent(1, 1, 1); /* finish it */
 
   /* delete buffers */
   G_free(inrast);
@@ -173,13 +167,11 @@
     str->name(&foo); 
     if (stats)
       *stats << "Writing stream <" << foo << "> to raster map <" << cellname << ">.\n";
-    G_verbose_message(_("Writing stream <%s> to raster map <%s>"), foo, cellname);
   }
 
   /* open output raster map */
   int outfd;
-  if ( (outfd = Rast_open_new (cellname, mtype)) < 0)
-	G_fatal_error (_("Unable to create raster map <%s>"), cellname);
+  outfd = Rast_open_new (cellname, mtype);
 
   /* Allocate output buffer */
   unsigned char *outrast;
@@ -187,39 +179,40 @@
   assert(outrast);
  
   T* elt;
+  G_important_message(_("Writing to raster map <%s>..."), cellname);
   for (int i=0; i< nrows; i++) {
-	for (int j=0; j< ncols; j++) {
-	  
+      for (int j=0; j< ncols; j++) {
+          
 	  /* READ VALUE */
 	  ae = str->read_item(&elt);
 	  if (ae != AMI_ERROR_NO_ERROR) {
-		str->sprint();
-		G_fatal_error(_("stream2cell: Reading stream failed at (%d,%d)"),
-				i, j);
+              str->sprint();
+              G_fatal_error(_("stream2cell: Reading stream failed at (%d,%d)"),
+                            i, j);
 	  }
-
+          
 	  /* WRITE VALUE */
-    if(usefcell){
-      if (is_nodata(*elt)) {
-        Rast_set_f_null_value( &( ((FCELL *) outrast)[j]), 1);
-      } else { 
-        ((FCELL *) outrast)[j] = (FCELL)(*elt);
-      }
-    }else{
-      if (is_nodata(*elt)) {
-        Rast_set_c_null_value( &( ((CELL *) outrast)[j]), 1);
-      } else { 
-        ((CELL *) outrast)[j] = (CELL)(*elt);
-      }
-    }
-
-  } /* for j*/
-  Rast_put_row (outfd, outrast, mtype);
-
-  G_percent(i, nrows, 2);
+          if(usefcell){
+              if (is_nodata(*elt)) {
+                  Rast_set_f_null_value( &( ((FCELL *) outrast)[j]), 1);
+              } else { 
+                  ((FCELL *) outrast)[j] = (FCELL)(*elt);
+              }
+          }else{
+              if (is_nodata(*elt)) {
+                  Rast_set_c_null_value( &( ((CELL *) outrast)[j]), 1);
+              } else { 
+                  ((CELL *) outrast)[j] = (CELL)(*elt);
+              }
+          }
+          
+      } /* for j*/
+      Rast_put_row (outfd, outrast, mtype);
+      
+      G_percent(i, nrows, 2);
   }/* for i */
   G_percent(1, 1, 2); /* finish it */
-
+  
   G_free(outrast);
   Rast_close (outfd);
 
@@ -257,15 +250,12 @@
     char * foo;
     str->name(&foo); 
     if (stats)
-      *stats << "Writing stream <" << foo << "> to raster map <" << cellname << ">." << endl;
-    G_verbose_message(_("Writing stream <%s> to raster map <%s>"), foo, cellname);
+        *stats << "Writing stream <" << foo << "> to raster map <" << cellname << ">." << endl;
   }
   
   /* open output raster map */
   int outfd;
-  if ( (outfd = Rast_open_new (cellname, CELL_TYPE)) < 0) {
-    G_fatal_error(_("Could not open <%s>"), cellname);
-  }
+  outfd = Rast_open_new (cellname, CELL_TYPE);
   
   /* Allocate output buffer */
   unsigned char *outrast;
@@ -275,6 +265,8 @@
   T* elt;
   ae = str->read_item(&elt);
   assert(ae == AMI_ERROR_NO_ERROR || ae == AMI_ERROR_END_OF_STREAM);
+
+  G_important_message(_("Writing to raster map <%s>..."), cellname);
   for (int i=0; i< nrows; i++) {
     for (int j=0; j< ncols; j++) {
       
@@ -298,7 +290,7 @@
 
     G_percent(i, nrows, 2);
   }/* for i */
-  G_percent(1, 1, 2); /* finish it */
+  G_percent(1, 1, 1); /* finish it */
 
   G_free(outrast);
   Rast_close (outfd);
@@ -333,14 +325,11 @@
     str->name(&foo); 
     if (stats)
       *stats << "Writing stream <" << foo << "> to raster map <" << cellname << ">." << endl;
-    G_verbose_message(_("Writing stream <%s> to raster map <%s>"), foo, cellname);
   }
   
   /* open output raster map */
   int outfd;
-  if ( (outfd = Rast_open_new (cellname, FCELL_TYPE)) < 0) {
-    G_fatal_error(_("Could not open <%s>"), cellname);
-  }
+  outfd = Rast_open_new(cellname, FCELL_TYPE);
   
   /* Allocate output buffer */
   unsigned char *outrast;
@@ -350,6 +339,7 @@
   T* elt;
   ae = str->read_item(&elt);
   assert(ae == AMI_ERROR_NO_ERROR || ae == AMI_ERROR_END_OF_STREAM);
+  G_important_message(_("Writing to raster map <%s>..."), cellname);
   for (int i=0; i< nrows; i++) {
     for (int j=0; j< ncols; j++) {
       
@@ -373,7 +363,7 @@
 
     G_percent(i, nrows, 2);
   }/* for i */
-  G_percent(1, 1, 2); /* finish it */
+  G_percent(1, 1, 1); /* finish it */
 
   G_free(outrast);
   Rast_close (outfd);
@@ -422,11 +412,10 @@
   {
     char * foo;
     str->name(&foo); 
-    if (stats)
+    if (stats) {
       *stats << "Writing stream <" << foo << "> to raster maps <"
-	   << cellname1 << "> and <" << cellname2 << ">." << endl;
-    G_verbose_message(_("Writing stream <%s> to raster maps <%s> and <%s>"), 
-		foo, cellname1, cellname2);
+             << cellname1 << "> and <" << cellname2 << ">." << endl;
+    }
   }
 
   /* open  raster maps */
@@ -435,9 +424,7 @@
     G_fatal_error(_("Could not open <%s>"), cellname1);
   }
   int fd2;
-  if ( (fd2 = Rast_open_new (cellname2, FCELL_TYPE)) < 0) {
-    G_fatal_error(_("Could not open <%s>"), cellname2);
-  }
+  fd2 = Rast_open_new (cellname2, FCELL_TYPE);
   
 
   /* Allocate output buffers */
@@ -451,6 +438,9 @@
   T* elt;
   ae = str->read_item(&elt);
   assert(ae == AMI_ERROR_NO_ERROR || ae == AMI_ERROR_END_OF_STREAM);
+  G_important_message(_("Writing to raster maps <%s,%s>..."), 
+                          cellname1, cellname2);
+
   for (int i=0; i< nrows; i++) {
     for (int j=0; j< ncols; j++) {
       
@@ -461,11 +451,11 @@
 	} else { 
 	  rast1[j] = fmt1(*elt);
 	};
-	if (is_nodata( fmt2(*elt))) {
-	  Rast_set_f_null_value(&(rast2[j]), 1);
-	} else { 
-	  rast2[j] = fmt2(*elt);
-	}
+        if (is_nodata( fmt2(*elt))) {
+            Rast_set_f_null_value(&(rast2[j]), 1);
+        } else { 
+            rast2[j] = fmt2(*elt);
+        }
 	/* read next value */
 	ae = str->read_item(&elt);
 	assert(ae == AMI_ERROR_NO_ERROR || ae == AMI_ERROR_END_OF_STREAM);
@@ -474,7 +464,7 @@
       } else { 
 	/* WRITE NODATA */
 	Rast_set_f_null_value(&(rast1[j]), 1);
-	Rast_set_f_null_value(&(rast2[j]), 1);
+        Rast_set_f_null_value(&(rast2[j]), 1);
       }
 
     } /* for j*/
@@ -485,13 +475,12 @@
     G_percent(i, nrows, 2);
 
   }/* for i */
-  G_percent(1, 1, 2); /* finish it */
+  G_percent(1, 1, 1); /* finish it */
 
   G_free(rast1);
   Rast_close (fd1);
   G_free(rast2);
   Rast_close (fd2);
-
   
   rt_stop(rt);
   if (stats)

Modified: grass/trunk/raster/r.terraflow/main.cpp
===================================================================
--- grass/trunk/raster/r.terraflow/main.cpp	2017-02-09 14:19:09 UTC (rev 70515)
+++ grass/trunk/raster/r.terraflow/main.cpp	2017-02-09 14:35:23 UTC (rev 70516)
@@ -71,31 +71,41 @@
   output_elev = G_define_standard_option(G_OPT_R_OUTPUT);
   output_elev->key        = "filled";
   output_elev->description= _("Name for output filled (flooded) elevation raster map");
+  output_elev->required = NO;
+  output_elev->guisection = _("Outputs");
   
  /* output direction  grid */
   struct Option *output_dir;
   output_dir = G_define_standard_option(G_OPT_R_OUTPUT);
   output_dir->key        = "direction";
   output_dir->description= _("Name for output flow direction raster map");
-
+  output_dir->required = NO;
+  output_dir->guisection = _("Outputs");
+    
   /* output sinkwatershed  grid */
   struct Option *output_watershed;
   output_watershed = G_define_standard_option(G_OPT_R_OUTPUT);
   output_watershed->key        = "swatershed";
   output_watershed->description= _("Name for output sink-watershed raster map");
-
+  output_watershed->required = NO;
+  output_watershed->guisection = _("Outputs");
+   
   /* output flow accumulation grid */
   struct Option *output_accu;
   output_accu = G_define_standard_option(G_OPT_R_OUTPUT);
   output_accu->key        = "accumulation";
   output_accu->description= _("Name for output flow accumulation raster map");
-
+  output_accu->required = NO;
+  output_accu->guisection = _("Outputs");
+   
 #ifdef OUTPUT_TCI
   struct Option *output_tci;
   output_tci = G_define_standard_option(G_OPT_R_OUTPUT);
   output_tci->key        = "tci";
   output_tci->description=
     _("Name for output topographic convergence index (tci) raster map");
+  output_tci->required = NO;
+  output_tci->guisection = _("Outputs");
 #endif
 
   /* MFD/SFD flag */
@@ -144,8 +154,11 @@
   stats_opt->type       = TYPE_STRING;
   stats_opt->required   = NO;
   stats_opt->description= _("Name of file containing runtime statistics");
-
-
+  stats_opt->guisection = _("Outputs");
+  
+  G_option_requires(input_elev, output_elev, output_dir, output_watershed,
+                    output_accu, output_tci, NULL);
+  
   if (G_parser(argc, argv)) {
     exit (EXIT_FAILURE);
   }
@@ -179,10 +192,10 @@
   else
     opt->streamdir = streamdir->answer;
 
+  opt->stats = stats_opt->answer;
+
   opt->verbose = G_verbose() == G_verbose_max();
 
-  opt->stats = stats_opt->answer;
-
   /* somebody should delete the options */
 }
 
@@ -203,42 +216,39 @@
   /* check compatibility with module region */
   if (!((region->ew_res == cell_hd.ew_res)
 		&& (region->ns_res == cell_hd.ns_res))) {
-    G_fatal_error(_("cell file %s resolution differs from current region"),
-				  cellname);
+    G_fatal_error(_("Raster map <%s> resolution differs from current region"),
+                  cellname);
   } else {
-    if (opt->verbose) { 
-      G_message(_("cell %s header compatible with region header"),
-	      cellname);
-      fflush(stderr);
-    }
+      G_verbose_message(_("Header of raster map <%s> compatible with region header"),
+                        cellname);
   }
 
 
   /* check type of input elevation raster and check if precision is lost */
     RASTER_MAP_TYPE data_type;
-	data_type = Rast_map_type(opt->elev_grid, mapset);
+    data_type = Rast_map_type(opt->elev_grid, mapset);
 #ifdef ELEV_SHORT
 	G_verbose_message(_("Elevation stored as SHORT (%dB)"),
 		sizeof(elevation_type));
 	if (data_type == FCELL_TYPE) {
-	  G_warning(_("raster %s is of type FCELL_TYPE "
-			"--precision may be lost."), opt->elev_grid); 
+	  G_warning(_("Raster map <%s> is of type FCELL_TYPE "
+                      "-- precision may be lost"), opt->elev_grid); 
 	}
 	if (data_type == DCELL_TYPE) {
-	  G_warning(_("raster %s is of type DCELL_TYPE "
-			"--precision may be lost."),  opt->elev_grid);
+	  G_warning(_("Raster map <%s> is of type DCELL_TYPE "
+                      "-- precision may be lost"),  opt->elev_grid);
 	}
 #endif 
 #ifdef ELEV_FLOAT
 	G_verbose_message( _("Elevation stored as FLOAT (%dB)"), 
 			sizeof(elevation_type));
 	if (data_type == CELL_TYPE) {
-	  G_warning(_("raster %s is of type CELL_TYPE "
-		"--you should use r.terraflow.short"), opt->elev_grid); 
+	  G_warning(_("Raster map <%s> is of type CELL_TYPE "
+                      "-- you should use r.terraflow.short"), opt->elev_grid); 
 	}
 	if (data_type == DCELL_TYPE) {
-	  G_warning(_("raster %s is of type DCELL_TYPE "
-		"--precision may be lost."),  opt->elev_grid);
+	  G_warning(_("Raster map <%s> is of type DCELL_TYPE "
+                      "-- precision may be lost"),  opt->elev_grid);
 	}
 #endif
 	
@@ -251,24 +261,21 @@
 void check_args() {
 
   /* check if filled elevation grid name is  valid */
-  if (G_legal_filename (opt->filled_grid) < 0) {
+  if (opt->filled_grid && G_legal_filename (opt->filled_grid) < 0) {
     G_fatal_error(_("<%s> is an illegal file name"), opt->filled_grid);
   }
   /* check if output grid names are valid */
-  if (G_legal_filename (opt->dir_grid) < 0) {
+  if (opt->dir_grid && G_legal_filename (opt->dir_grid) < 0) {
     G_fatal_error(_("<%s> is an illegal file name"), opt->dir_grid);
   }
-  if (G_legal_filename (opt->filled_grid) < 0) {
-    G_fatal_error(_("<%s> is an illegal file name"), opt->filled_grid);
-  }
-  if (G_legal_filename (opt->flowaccu_grid) < 0) {
+  if (opt->flowaccu_grid && G_legal_filename (opt->flowaccu_grid) < 0) {
     G_fatal_error(_("<%s> is an illegal file name"), opt->flowaccu_grid);
   }
-  if (G_legal_filename (opt->watershed_grid) < 0) {
+  if (opt->watershed_grid && G_legal_filename (opt->watershed_grid) < 0) {
     G_fatal_error(_("<%s> is an illegal file name"), opt->watershed_grid);
   }
-#ifdef OUTPU_TCI
-  if (G_legal_filename (opt->tci_grid) < 0) {
+#ifdef OUTPUT_TCI
+  if (opt->tci_grid && G_legal_filename (opt->tci_grid) < 0) {
   G_fatal_error(_("<%s> is an illegal file name"), opt->tci_grid);
   }
 #endif
@@ -308,12 +315,17 @@
   *stats << endl;
   
   *stats << "input elevation grid: " << opt->elev_grid << "\n";
-  *stats << "output (flooded) elevations grid: " << opt->filled_grid << "\n";
-  *stats << "output directions grid: " << opt->dir_grid << "\n";
-  *stats << "output sinkwatershed grid: " << opt->watershed_grid << "\n";
-  *stats << "output accumulation grid: " << opt->flowaccu_grid << "\n";
+  if (opt->filled_grid)
+      *stats << "output (flooded) elevations grid: " << opt->filled_grid << "\n";
+  if (opt->dir_grid)
+      *stats << "output directions grid: " << opt->dir_grid << "\n";
+  if (opt->watershed_grid)
+      *stats << "output sinkwatershed grid: " << opt->watershed_grid << "\n";
+  if (opt->flowaccu_grid)
+      *stats << "output accumulation grid: " << opt->flowaccu_grid << "\n";
 #ifdef OUTPUT_TCI
-  *stats <<  "output tci grid: " << opt->tci_grid << "\n";
+  if (opt->tci_grid)
+      *stats <<  "output tci grid: " << opt->tci_grid << "\n";
 #endif
   if (opt->d8) {
     stats ->comment("SFD (D8) flow direction");
@@ -347,7 +359,7 @@
   if (Rast_read_range(cellname, mapset, &r) == -1) {
     G_fatal_error(_("cannot read range"));
   }
-  /*fprintf(stderr, "%s range is: min=%d, max=%d\n", cellname, r.min, r.max);*/
+  /*G_debug(1, "%s range is: min=%d, max=%d\n", cellname, r.min, r.max);*/
   int v[6];
   v[0] = r.min;
   v[1] = 5;
@@ -406,32 +418,31 @@
   long long maxneed = (fillmaxsize > flowmaxsize) ? fillmaxsize: flowmaxsize;
   maxneed =  2*maxneed; /* need 2*N to sort */
 
-  G_message( "total elements=%ld, nodata elements=%ld",
-		(long)nrows * ncols, nodata_count);
-  G_message( "largest temporary files: ");
-  G_message( "\t\t FILL: %s [%ld elements, %dB each]",
-		  formatNumber(buf, fillmaxsize),
-		  (long)nrows * ncols, sizeof(waterWindowType));
-  G_message( "\t\t FLOW: %s [%ld elements, %dB each]",
-		  formatNumber(buf, flowmaxsize),
-		  (long)nrows * ncols - nodata_count, sizeof(sweepItem));
-  G_message( "Will need at least %s space available in %s",
-		  formatNumber(buf, maxneed),  	  /* need 2*N to sort */
-		  getenv(STREAM_TMPDIR));
+  G_debug(1, "total elements=%ld, nodata elements=%ld",
+          (long)nrows * ncols, nodata_count);
+  G_debug(1, "largest temporary files: ");
+  G_debug(1, "\t\t FILL: %s [%ld elements, %dB each]",
+          formatNumber(buf, fillmaxsize),
+          (long)nrows * ncols, sizeof(waterWindowType));
+  G_debug(1, "\t\t FLOW: %s [%ld elements, %dB each]",
+          formatNumber(buf, flowmaxsize),
+          (long)nrows * ncols - nodata_count, sizeof(sweepItem));
+  G_debug(1, "Will need at least %s space available in %s",
+          formatNumber(buf, maxneed),  	  /* need 2*N to sort */
+          getenv(STREAM_TMPDIR));
 
 #ifdef HAVE_STATVFS_H
-  fprintf(stderr, "Checking current space in %s: ", getenv(STREAM_TMPDIR));
+  G_debug(1, "Checking current space in %s: ", getenv(STREAM_TMPDIR));
   struct statvfs statbuf;
   statvfs(getenv(STREAM_TMPDIR), &statbuf);
 
   float avail = statbuf.f_bsize*statbuf.f_bavail;
-  fprintf(stderr, "available %ld blocks x %ldB = %.0fB",
-		  (long)statbuf.f_bavail, statbuf.f_bsize, avail);
+  G_debug(1, "available %ld blocks x %ldB = %.0fB",
+          (long)statbuf.f_bavail, statbuf.f_bsize, avail);
   if (avail > maxneed) {
-	fprintf(stderr, ". OK.\n");
+      G_debug(1, ". OK.");
   } else {
-	fprintf(stderr, ". Not enough space available.\n");
-	exit(EXIT_FAILURE);
+      G_fatal_error("Not enough space available");
   }
 #endif
 }
@@ -495,12 +506,13 @@
   /* don't pass an automatic variable; putenv() isn't guaranteed to make a copy */
   putenv(G_store(buf));
   if (getenv(STREAM_TMPDIR) == NULL) {
-    fprintf(stderr, "%s:", STREAM_TMPDIR);
-    G_fatal_error("not set");
+      G_fatal_error(_("%s not set"), STREAM_TMPDIR);
   } else {
-    fprintf(stderr, "STREAM temporary files in %s  ",
-	    getenv(STREAM_TMPDIR)); 
-	fprintf(stderr, "(THESE INTERMEDIATE STREAMS WILL NOT BE DELETED IN CASE OF ABNORMAL TERMINATION OF THE PROGRAM. TO SAVE SPACE PLEASE DELETE THESE FILES MANUALLY!)\n");
+      G_verbose_message(_("STREAM temporary files in <%s>. "
+                          "THESE INTERMEDIATE STREAMS WILL NOT BE DELETED "
+                          "IN CASE OF ABNORMAL TERMINATION OF THE PROGRAM. "
+                          "TO SAVE SPACE PLEASE DELETE THESE FILES MANUALLY!"),
+                        getenv(STREAM_TMPDIR));
   }
   
   if (opt->stats) {
@@ -521,11 +533,12 @@
   size_t mm_size = (size_t) opt->mem << 20; /* opt->mem is in MB */
   MM_manager.set_memory_limit(mm_size);
   if (opt->verbose) {
-	MM_manager.warn_memory_limit();
+      MM_manager.warn_memory_limit();
   } else {
-	MM_manager.ignore_memory_limit();
+      MM_manager.ignore_memory_limit();
   }
-  MM_manager.print_limit_mode();
+  if (opt->verbose)
+      MM_manager.print_limit_mode();
 
 
   /* initialize nodata */
@@ -558,18 +571,23 @@
   delete elstr;
 
   /* write streams to GRASS raster maps */
-  stream2_CELL(dirstr, nrows, ncols, opt->dir_grid);
+  if (opt->dir_grid)
+      stream2_CELL(dirstr, nrows, ncols, opt->dir_grid);
   delete dirstr;
+  if (opt->filled_grid) {
 #ifdef ELEV_SHORT
-  stream2_CELL(filledstr, nrows, ncols, opt->filled_grid);
+      stream2_CELL(filledstr, nrows, ncols, opt->filled_grid);
 #else
-  stream2_CELL(filledstr, nrows, ncols, opt->filled_grid,true);
+      stream2_CELL(filledstr, nrows, ncols, opt->filled_grid,true);
 #endif
+  }
   delete filledstr; 
 
-  stream2_CELL(labeledWater, nrows, ncols, labelElevTypePrintLabel(), 
-			   opt->watershed_grid);
-  setSinkWatershedColorTable(opt->watershed_grid);
+  if (opt->watershed_grid) {
+      stream2_CELL(labeledWater, nrows, ncols, labelElevTypePrintLabel(), 
+                   opt->watershed_grid);
+      setSinkWatershedColorTable(opt->watershed_grid);
+  }
   delete labeledWater;
   
 #else 
@@ -578,8 +596,8 @@
 
   sprintf(path, "%s/flowStream", streamdir->answer);
   flowStream = new AMI_STREAM<waterWindowBaseType>(path);
-  fprintf(stderr, "flowStream opened: len=%d\n", flowStream->stream_len());
-  fprintf(stderr, "jumping to flow accumulation computation\n");
+  G_verbose_message(_("flowStream opened: len=%d\n", flowStream->stream_len());
+  G_verbose_message(_("jumping to flow accumulation computation\n");
 #endif
   
   /* -------------------------------------------------- */
@@ -591,14 +609,22 @@
 
   /* write output stream to GRASS raster maps */
 #ifdef OUTPUT_TCI
-  stream2_FCELL(outstr, nrows, ncols, printAccumulation(), printTci(),
-		opt->flowaccu_grid, opt->tci_grid);
-#else 
-  stream2_FCELL(outstr, nrows, ncols, printAccumulation(), opt->flowaccu_grid);
+  if (opt->flowaccu_grid && opt->tci_grid)
+      stream2_FCELL(outstr, nrows, ncols, printAccumulation(), printTci(),
+                    opt->flowaccu_grid, opt->tci_grid);
+  else if (opt->tci_grid)
+      stream2_FCELL(outstr, nrows, ncols, printTci(),
+                    opt->tci_grid);
+  else if (opt->flowaccu_grid)
+      stream2_FCELL(outstr, nrows, ncols, printAccumulation(),
+                    opt->flowaccu_grid);
+#else
+  if (opt->flowaccu_grid)
+      stream2_FCELL(outstr, nrows, ncols, printAccumulation(),
+                    opt->flowaccu_grid);
 #endif
-
-  setFlowAccuColorTable(opt->flowaccu_grid);
-
+  if (opt->flowaccu_grid)
+      setFlowAccuColorTable(opt->flowaccu_grid);
   delete outstr;
   
   rt_stop(rtTotal);

Modified: grass/trunk/raster/r.terraflow/main.h
===================================================================
--- grass/trunk/raster/r.terraflow/main.h	2017-02-09 14:19:09 UTC (rev 70515)
+++ grass/trunk/raster/r.terraflow/main.h	2017-02-09 14:35:23 UTC (rev 70516)
@@ -26,7 +26,7 @@
   char* stats;         /* stats file */
   int   d8;            /* 1 if d8 flow model, 0 otherwise */ 
   int   mem;           /* main memory, in MB */
-  int verbose;         /* 1 if verbose, 0 otherwise */ 
+  int verbose;         /* 1 if verbose, 0 otherwise */
 } user_options;
 
 

Modified: grass/trunk/raster/r.terraflow/plateau.cpp
===================================================================
--- grass/trunk/raster/r.terraflow/plateau.cpp	2017-02-09 14:19:09 UTC (rev 70515)
+++ grass/trunk/raster/r.terraflow/plateau.cpp	2017-02-09 14:35:23 UTC (rev 70516)
@@ -296,9 +296,9 @@
   dirQueue = new queue<direction_type>();
   platQueue = new queue<plateauType>();
   /* scan3(elstr, hdr, hdr.get_nodata(), *this);  */
-  if (opt->verbose) STRACE("starting memscan");
+  //  if (opt->verbose) STRACE("starting memscan");
   memoryScan(elstr, nrows, ncols, nodata_value, *this); 
-  if (opt->verbose) STRACE("memscan done");
+  //if (opt->verbose) STRACE("memscan done");
   delete dirQueue;
   delete platQueue;
 }

Modified: grass/trunk/raster/r.terraflow/stats.cpp
===================================================================
--- grass/trunk/raster/r.terraflow/stats.cpp	2017-02-09 14:19:09 UTC (rev 70515)
+++ grass/trunk/raster/r.terraflow/stats.cpp	2017-02-09 14:35:23 UTC (rev 70516)
@@ -85,11 +85,10 @@
 	exit(1);
       } else { /* file exists */
 	char buf[BUFSIZ];
-	fprintf(stderr, "file %s exists - renaming.\n", fname);
+	G_debug(1, "file %s exists - renaming.\n", fname);
 	sprintf(buf, "%s.old", fname);
 	if(rename(fname, buf) != 0) {
-	  perror(fname);
-	  exit(1);
+	  G_fatal_error(fname);
 	}
       }
     }
@@ -107,11 +106,10 @@
       exit(1);
     } else { /* file exists */
       char buf[BUFSIZ];
-      fprintf(stderr, "file %s exists - renaming.\n", fname);
+      G_debug(1, "file %s exists - renaming.\n", fname);
       sprintf(buf, "%s.old", fname);
       if(rename(fname, buf) != 0) {
-	perror(fname);
-	exit(1);
+	G_fatal_error(fname);
       }
       close(fd);
     }

Modified: grass/trunk/raster/r.terraflow/sweep.cpp
===================================================================
--- grass/trunk/raster/r.terraflow/sweep.cpp	2017-02-09 14:19:09 UTC (rev 70515)
+++ grass/trunk/raster/r.terraflow/sweep.cpp	2017-02-09 14:35:23 UTC (rev 70516)
@@ -34,13 +34,6 @@
 #include "sortutils.h"
 
 
-/* 
-   #define CHECKPARAM        //output the parameters during sweeping 
-   #define CHECK_WEIGHTS     //output weights as computed
-   #define SWEEP_PRINT_PQSIZE      //output priority queue size during sweeping
-   #define CHECK_MEMORY  //enables printing available memory in between steps
-*/
-
 /* frequency; used to print progress dots */
 static const int DOT_CYCLE = 50;
 static const int PQSIZE_CYCLE = 100;
@@ -119,7 +112,7 @@
     /* assert(correct_tci > 0); //is this true? */
     /* there is no need for this warning. tci can be negative if the flow is small. */
     /* if (correct_tci < 0) {
-       fprintf(stderr, "warning: tci negative, [flow=%f,dx=%f,dy=%f,cont=%f]\n",
+       G_warning(tci negative, [flow=%f,dx=%f,dy=%f,cont=%f]\n",
        flow.get(), weight.dx(), weight.dy(), weight.totalContour());
        }
     */
@@ -162,32 +155,6 @@
   return flowpq;
 }
   
-
-#define INIT_PRINT_PROGRESS()						\
-  long out_frequency, pqsize_frequency;					\
-  out_frequency = nrows*ncols / DOT_CYCLE;		\
-  pqsize_frequency = nrows*ncols / PQSIZE_CYCLE;	\
-  assert(out_frequency);						\
-  assert(pqsize_frequency);
-
-#define PRINT_PROGRESS(k) 			\
-  if ((k) % out_frequency == 0) {		\
-    fprintf(stderr,"."); 				\
-    fflush(stderr);				\
-  };
-
-#ifdef SWEEP_PRINT_PQSIZE
-#define PRINT_PQSIZE(k,flowpq)			\
-  if ((k) % pqsize_frequency == 0) {		\
-    fprintf(stderr," %ld ", (long)(flowpq)->size());	\
-    fflush(stderr);				\
-  }
-#else
-#define PRINT_PQSIZE(k,flowpq)
-#endif
-
-
-
 /***************************************************************/
 /* Read the points in order from the sweep stream and process them.
    If trustdir = 1 then trust and use the directions contained in the
@@ -207,15 +174,13 @@
   Rtimer rt;
   AMI_STREAM<sweepOutput>* outstr;
 
-  /* INIT_PRINT_PROGRESS(); */
-
   rt_start(rt);
 
   assert(sweepstr);
 
   if (stats)
     *stats << "sweeping\n";
-  fprintf(stderr,  "sweeping: ");
+  G_debug(1, "sweeping: ");
   /* create and initialize flow data structure */
   FLOW_DATASTR *flowpq;
   flowpq = initializePQ();
@@ -234,6 +199,7 @@
   /* scan the sweep stream  */
   ae = sweepstr->seek(0);
   assert(ae == AMI_ERROR_NO_ERROR);
+  G_important_message(_("Sweeping..."));
   for (long k = 0; k < nitems; k++) {
     
     /* cout << k << endl; cout.flush(); */
@@ -305,13 +271,10 @@
     ae = outstr->write_item(output);
     assert(ae == AMI_ERROR_NO_ERROR);
     
-    /* PRINT_PROGRESS(k); */
-    /* PRINT_PQSIZE(k, flowpq); */
-    
     G_percent(k, nitems, 2);
   } /* for k  */
   
-  G_percent(1, 1, 2); /* finish it */
+  G_percent(1, 1, 1); /* finish it */
 
   if (stats)
     *stats << "sweeping done\n";



More information about the grass-commit mailing list