[GRASS5] Update: 5.0.3-cvs -> 5.3.0-cvs

Hamish hamish_nospam at yahoo.com
Sat Sep 13 03:58:20 EDT 2003


> The latest r.terraflow code I received yesterday via Helena. 
> However, I hesitate to just copy over in CVS. Is there anyone
> interested to try it first and then upload into CVS?
> For the moment, the new src code is here:
> 
>  http://mpa.itc.it/markus/tmp/r.terraflow.1.5.tar.gz


I don't know enough about r.terraflow, C++, or the build system to be
useful here, but here is the diff for those who do.

-------------- next part --------------
Common subdirectories: r.terraflow/CVS and r.terraflow.1.5/CVS
diff -u r.terraflow/Gmakefile r.terraflow.1.5/Gmakefile
--- r.terraflow/Gmakefile	Sat Mar  1 17:45:52 2003
+++ r.terraflow.1.5/Gmakefile	Tue Apr  8 12:15:35 2003
@@ -1,3 +1,6 @@
+
+CC = g++
+
 SOURCES = main.cc common.cc stats.cc fill.cc types.cc ccforest.cc \
 	nodata.cc plateau.cc direction.cc water.cc  \
 	filldepr.cc grid.cc genericWindow.cc \
@@ -21,10 +24,10 @@
 #		header files should be included as prerequisites, but does not work 
 #		because of GRASS scripts 
 $(OBJARCH)/FLOAT/%.o:%.cc
-	$(CXX) -c $(CXXFLAGS) -DELEV_FLOAT $< -o $@
+	$(CC) -c $(CFLAGS) -DELEV_FLOAT $< -o $@
 
 $(OBJARCH)/SHORT/%.o:%.cc
-	$(CXX) $(CXXFLAGS)  -DELEV_SHORT -c $< -o $@
+	$(CC) $(CFLAGS)  -DELEV_SHORT -c $< -o $@
 
 
 
@@ -39,31 +42,31 @@
   -Wcomment  -Wno-sign-compare
 
 
-CXXFLAGS += -I$(IOSTREAM_INC) \
+CFLAGS += -Wall  -I$(IOSTREAM_INC) -Wno-deprecated\
 		-DUSER=\"$(USER)\" \
 		-DNODATA_FIX -D_FILE_OFFSET_BITS=64
 
-LDFLAGS += -L$(IOSTREAM_LIBDIR)
+LDFLAGS += -L$(IOSTREAM_LIBDIR) -O3
 
 LIBS = $(GISLIB) 
 DEPLIBS = $(DEPGISLIB)
 
 
 
-all: dofirst $(BIN_CMD)/r.terraflow $(BIN_CMD)/r.terraflow.short
+all: force $(BIN_CMD)/r.terraflow $(BIN_CMD)/r.terraflow.short
 
-dofirst:
+force:
 	-mkdir $(OBJARCH)/FLOAT ; true
 	-mkdir $(OBJARCH)/SHORT ; true
 
 $(BIN_CMD)/r.terraflow: $(FLOAT_OBJ) $(GISLIB)  $(DEPLIBS)
 	(cd IOStream/lib ; make)
-	$(CXX) -DELEV_FLOAT $(LDFLAGS) -o $@ $(FLOAT_OBJ) $(LIBS) $(MATHLIB) \
+	$(CC) -DELEV_FLOAT $(LDFLAGS) -o $@ $(FLOAT_OBJ) $(LIBS) $(MATHLIB) \
 	$(XDRLIB) $(IOSTREAM_LIB)
 
 $(BIN_CMD)/r.terraflow.short: $(SHORT_OBJ) $(GISLIB)  $(DEPLIBS)
 	(cd IOStream/lib ; make)
-	$(CXX) -DELEV_SHORT $(LDFLAGS) -o $@ $(SHORT_OBJ) $(LIBS) $(MATHLIB) \
+	$(CC) -DELEV_SHORT $(LDFLAGS) -o $@ $(SHORT_OBJ) $(LIBS) $(MATHLIB) \
 	$(XDRLIB) $(IOSTREAM_LIB)
 
 
Common subdirectories: r.terraflow/IOStream and r.terraflow.1.5/IOStream
diff -u r.terraflow/direction.h r.terraflow.1.5/direction.h
--- r.terraflow/direction.h	Tue Jan 21 05:45:34 2003
+++ r.terraflow.1.5/direction.h	Sun Apr  6 11:57:31 2003
@@ -135,14 +135,17 @@
 			elevation_type elev_neighb) {
     
     if (skipit && get(di,dj) == true) {
-      cout << "WARNING ";
-      cout << form(" at (%d,%d, h=%d, dir=%d) ", i, j, elev_crt, dir);
-      cout << form("direction points to non-valid neighbor (%d,%d,h=%d)\n",
-		   i + di, j + dj, elev_crt - elev_neighb);
+      cout << "WARNING:  at (" 
+	   << i << "," << j << " , h=" << elev_crt << ", dir=" << dir << ")"
+	   << "direction points to non-valid neighbor ("
+	   <<  i + di << ","
+	   <<  j + dj << ", h="
+	   << elev_crt - elev_neighb
+	   << ")\n";
       set(di,dj, false); /* correct it */
     }
     if (!skipit && elev_crt > elev_neighb &&  !is_nodata(elev_neighb)
-		&& get(di,dj) == 0) {
+	&& get(di,dj) == 0) {
       set(di,dj, true); /* correct it */
     }
   }
diff -u r.terraflow/fill.cc r.terraflow.1.5/fill.cc
--- r.terraflow/fill.cc	Tue Jan 21 05:45:34 2003
+++ r.terraflow.1.5/fill.cc	Wed Apr  9 03:52:33 2003
@@ -362,7 +362,7 @@
   waterstr = new AMI_STREAM<waterType>();
   long dc = assignDirections(statstr, platstr, waterstr);
   if(dc) {
-    *stats << form("WARNING: %ld depressions (islands) detected\n", dc);
+    *stats << "WARNING: " << dc << " depressions (islands) detected\n";
   }
   delete platstr;
   delete statstr;
diff -u r.terraflow/filldepr.cc r.terraflow.1.5/filldepr.cc
--- r.terraflow/filldepr.cc	Tue Jan 21 05:45:34 2003
+++ r.terraflow.1.5/filldepr.cc	Wed Apr  9 05:24:34 2003
@@ -137,12 +137,12 @@
     watersheds except for the outside watershed; the outside watershed
     is not in the unionfind structure; */
   unionFind<cclabel_type> unionf;
-  FLOOD_DEBUG cout << form("nb watersheds %d, bstream length %d\n",
-			   maxWatersheds, boundaryStr->stream_len());
+  FLOOD_DEBUG printf("nb watersheds %d, bstream length %ld\n",
+    (int)maxWatersheds, (long)boundaryStr->stream_len());
   
   for (cclabel_type i=1; i< maxWatersheds; i++) {
-    FLOOD_DEBUG cout << form("makeset %d\n",i); cout.flush();
-     unionf.makeSet(i);
+    FLOOD_DEBUG printf("makeset %d\n",i); 
+    unionf.makeSet(i);
   }
 
   /*__________________________________________________________*/
@@ -163,14 +163,13 @@
     v = nextedge->getLabel2();
     h = nextedge->getElevation();
     FLOOD_DEBUG {
-      cout << form("\nreading edge ((%d,%d),h=%d)\n",u,v,h); 
-      cout.flush();
+      printf("\nreading edge ((%d,%d),h=%d)\n",(int)u,(int)v,(int)h); 
     }
 
     /*find representatives;  LABEL_BOUNDARY means the outside watershed*/
     (u==LABEL_BOUNDARY)? ur = LABEL_BOUNDARY: ur = unionf.findSet(u);
     (v==LABEL_BOUNDARY)? vr = LABEL_BOUNDARY: vr = unionf.findSet(v);
-    FLOOD_DEBUG cout <<form("%d is %d, %d is %d\n", u, ur, v, vr);
+    FLOOD_DEBUG printf("%d is %d, %d is %d\n", u, ur, v, vr);
 
     /*watersheds are done; just ignore it*/
     if ((ur == vr) || (done[ur] && done[vr])) {
@@ -184,14 +183,14 @@
     case of boundary watersheds; */
     if (done[ur] || done[vr]) {
       if (done[ur]) {
-	FLOOD_DEBUG cout << form("%d is done, %d raised to %d and done\n", 
-				 ur, vr, h);
+	FLOOD_DEBUG printf("%d is done, %d raised to %d and done\n", 
+			   (int)ur, (int)vr, (int)h);
 	done[vr] = 1;
 	raise[vr] = h;
       } else {
 	assert(done[vr]);
-	FLOOD_DEBUG cout << form("%d is done, %d raised to %d and done\n", 
-				 vr, ur, h);
+	FLOOD_DEBUG printf("%d is done, %d raised to %d and done\n", 
+			   vr, ur, h);
 	done[ur] = 1;
 	raise[ur] = h;
       }
@@ -200,7 +199,7 @@
     
     /* if none of the  watersheds is done: union and raise them */
     assert(!done[ur] && !done[vr] && ur>0 && vr>0);
-    FLOOD_DEBUG cout << form("union %d and %d,  raised to %d\n", ur, vr, h);
+    FLOOD_DEBUG printf("union %d and %d,  raised to %d\n", ur, vr, h);
     raise[ur] = raise[vr] = h;
     unionf.makeUnion(ur,vr);
   }
@@ -209,8 +208,8 @@
   for (cclabel_type i=1; i< maxWatersheds; i++) {
     /* assert(done[unionf.findSet(i)]); sometimes this fails! */
     if (!done[unionf.findSet(i)]) {
-      cerr << form("warning: watershed %d (R=%d) not done\n", 
-		   i, unionf.findSet(i));
+      fprintf(stderr, "warning: watershed %d (R=%d) not done\n", 
+	     i, unionf.findSet(i));
     }
   }
 #endif
diff -u r.terraflow/flow.cc r.terraflow.1.5/flow.cc
--- r.terraflow/flow.cc	Tue Jan 21 05:45:34 2003
+++ r.terraflow.1.5/flow.cc	Wed Apr  9 05:25:52 2003
@@ -93,7 +93,7 @@
     
     size_t mm_size = (opt->mem  << 20); /* (in bytes) */
     formatNumber(buf, mm_size);
-    *stats << form("memory size: %s bytes\n", buf);
+    *stats << "memory size: " << buf << " bytes\n";
   }
 
   /* create sweepstream using info from  fillStream  */
diff -u r.terraflow/grass2str.h r.terraflow.1.5/grass2str.h
--- r.terraflow/grass2str.h	Tue Jan 21 05:45:34 2003
+++ r.terraflow.1.5/grass2str.h	Sun Apr  6 12:14:21 2003
@@ -187,7 +187,7 @@
   {
     char * foo;
     str->name(&foo); 
-    *stats << form("writing stream %s to cell file  %s\n", foo, cellname);
+    *stats << "writing stream " << foo << " to cell file  " << cellname <<"\n";
     fprintf(stderr, "writing stream %s to cell file %s: ", foo, cellname);
   }
 
diff -u r.terraflow/grid.cc r.terraflow.1.5/grid.cc
--- r.terraflow/grid.cc	Tue Jan 21 05:45:34 2003
+++ r.terraflow.1.5/grid.cc	Wed Apr  9 05:25:15 2003
@@ -120,11 +120,11 @@
 grid::print() {
   cout << "    ";
   for(int i=0; i<width; i++) {
-    cout << form("%2d", (jMin + i%10));
+    printf("%2d", (jMin + i%10));
   }
   cout << endl;
   for(int j=0; j<height; j++) {
-    cout << form("%3d ", j + iMin);
+    printf("%3d ", j + iMin);
     for(int i=0; i<width; i++) {
       if(data[i+width*j].valid) {
 	cout << " " << directionSymbol(data[i+width*j].dir);
Common subdirectories: r.terraflow/html and r.terraflow.1.5/html
diff -u r.terraflow/main.cc r.terraflow.1.5/main.cc
--- r.terraflow/main.cc	Tue Jan 21 05:45:34 2003
+++ r.terraflow.1.5/main.cc	Wed Apr  9 06:38:41 2003
@@ -337,13 +337,13 @@
   }
   *stats << endl;
   
-  *stats << form("input elevation grid: %s\n", opt->elev_grid);
-  *stats << form("output (flooded) elevations grid: %s\n", opt->filled_grid);
-  *stats << form("output directions grid: %s\n", opt->dir_grid);
-  *stats << form("output sinkwatershed grid: %s\n", opt->watershed_grid);
-  *stats << form("output accumulation grid: %s\n", opt->flowaccu_grid);
+  *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";
 #ifdef OUTPUT_TCI
-  *stats <<  form("output tci grid: %s\n", opt->tci_grid);
+  *stats <<  "output tci grid: " << opt->tci_grid << "\n";
 #endif
   if (opt->d8) {
     stats ->comment("SFD (D8) flow direction");
@@ -450,7 +450,7 @@
   Rtimer rtTotal;    
   char buf[BUFSIZ];
 
-  fprintf(stderr, "r.terraflow version 1.4, January 2003\n");
+  fprintf(stderr, "r.terraflow version 1.5, April 2003\n");
   fflush(stderr);
 
   /* initialize GIS library */
@@ -507,8 +507,9 @@
   {
     char buf[BUFSIZ];
     long grid_size = nrows * ncols;
-    *stats << form("region size = %s elts (%d rows x %d cols)\n", 
-		   formatNumber(buf, grid_size), nrows, ncols);
+    *stats << "region size = " <<  formatNumber(buf, grid_size) << " elts "
+	   << "(" << nrows << " rows x " << ncols << " cols)\n";
+
     stats->flush();
   }
 
diff -u r.terraflow/stats.cc r.terraflow.1.5/stats.cc
--- r.terraflow/stats.cc	Tue Jan 21 05:45:34 2003
+++ r.terraflow.1.5/stats.cc	Wed Apr  9 03:51:53 2003
@@ -99,29 +99,55 @@
   int fd=-1;
   
   while(fd<0) {
-	fd = open(fname, O_WRONLY|O_CREAT|O_EXCL, 0644);
-	if(fd < 0) {
-	  if(errno != EEXIST) {
-		perror(fname);
-		exit(1);
-	  } else { /* file exists */
-		char buf[BUFSIZ];
-		fprintf(stderr, "file %s exists - renaming.\n", fname);
-		sprintf(buf, "%s.old", fname);
-		if(rename(fname, buf) != 0) {
-		  perror(fname);
-		  exit(1);
-		}
-	  }
+    fd = open(fname, O_WRONLY|O_CREAT|O_EXCL, 0644);
+    if(fd < 0) {
+      if(errno != EEXIST) {
+	perror(fname);
+	exit(1);
+      } else { /* file exists */
+	char buf[BUFSIZ];
+	fprintf(stderr, "file %s exists - renaming.\n", fname);
+	sprintf(buf, "%s.old", fname);
+	if(rename(fname, buf) != 0) {
+	  perror(fname);
+	  exit(1);
 	}
+      }
+    }
   }
   return fd;
 }
 
+char* 
+noclobberFileName(char *fname) {
+  int fd;
+  fd = open(fname, O_WRONLY|O_CREAT|O_EXCL, 0644);
+  if(fd < 0) {
+    if(errno != EEXIST) {
+      perror(fname);
+      exit(1);
+    } else { /* file exists */
+      char buf[BUFSIZ];
+      fprintf(stderr, "file %s exists - renaming.\n", fname);
+      sprintf(buf, "%s.old", fname);
+      if(rename(fname, buf) != 0) {
+	perror(fname);
+	exit(1);
+      }
+      close(fd);
+    }
+  }
+  return fname;
+}
+
+
 
 /* ********************************************************************** */
 
-statsRecorder::statsRecorder(char *fname) : ofstream(noclobberFile(fname)) {
+statsRecorder::statsRecorder(char *fname) : ofstream(noclobberFileName(fname)){
+  //note: in the new version of gcc there is not constructor for
+  //ofstream that takes an fd; wrote another noclobber() function that
+  //closes fd and returns the name;
   rt_start(tm);
   bss = sbrk(0);
   char buf[BUFSIZ];
@@ -173,7 +199,7 @@
 
 
 void 
-statsRecorder::comment(const char *s, const int verbose=1) {
+statsRecorder::comment(const char *s, const int verbose) {
   *this << timestamp() << s << endl;
   if (verbose) {
     cout << s << endl;
diff -u r.terraflow/sweep.cc r.terraflow.1.5/sweep.cc
--- r.terraflow/sweep.cc	Tue Jan 21 05:45:34 2003
+++ r.terraflow.1.5/sweep.cc	Wed Apr  9 05:30:28 2003
@@ -156,14 +156,17 @@
 
 FLOW_DATASTR* 
 initializePQ() {
-  
+   
   stats->comment("sweep:initialize flow data structure", opt->verbose);
   
   FLOW_DATASTR *flowpq;
 #ifdef IM_PQUEUE
   stats->comment("FLOW_DATASTRUCTURE: in-memory pqueue");
   flowpq = new FLOW_DATASTR(PQ_SIZE);
-  *stats << form("initialized to %.2fMB\n", (float)PQ_SIZE / (1<<20));
+  char buf[1024]; 
+  sprintf(buf, "initialized to %.2fMB\n", (float)PQ_SIZE / (1<<20));
+  *stats << buf; 
+
 #endif
 #ifdef EM_PQUEUE
   stats->comment("FLOW_DATASTRUCTURE: ext-memory pqueue");
@@ -253,7 +256,7 @@
     /* read next sweepItem = (prio, elevwin, topoRankwin, dir) */
     ae = sweepstr->read_item(&crtpoint);
     if (ae != AMI_ERROR_NO_ERROR) {
-      cerr << form("sweep: k=%ld: cannot read next item..\n", k);
+      fprintf(stderr, "sweep: k=%ld: cannot read next item..\n", k);
       exit(1);
     }
     /* cout << "k=" << k << " prio =" << crtpoint->getPriority() << "\n"; */
@@ -309,7 +312,7 @@
     printf("%7ld: (%5d, %5d, %5d) flow: %7.3f, weights:[",
 	   k, crtpoint->getElev(), crtpoint->getI(),crtpoint->getJ(), 
 	   flow.get());
-    for (int l=0;l<9;l++) cout << form("%2.1f ",weight.get(l));
+    for (int l=0;l<9;l++) printf("%2.1f ",weight.get(l));
     cout <<"] ";
     cout << output << "\n";
 #endif        
@@ -326,7 +329,9 @@
   
   fprintf(stderr, "\n");
   *stats << "sweeping done\n";
-  *stats << form("pqsize = %ld \n", (long)flowpq->size());
+  char buf[1024];
+  sprintf(buf, "pqsize = %ld \n", (long)flowpq->size());
+  *stats << buf;
   
   assert(outstr->stream_len() == nitems);
   delete flowpq; 
@@ -389,8 +394,8 @@
 	  /* assert(prio >= prio_crt); */
 #if (defined WARNING_FLAG)
 	  if (prio < prio_crt) {
-	    cout << form("\n(row=%d,col=%d,ele=%d): ",
-			 i_crt, j_crt, elev_crt);
+	    printf("\n(row=%d,col=%d,ele=%d): ",
+		   i_crt, j_crt, elev_crt);
 	    cout << "attempt to push flow uphill\n";
 	  }
 #endif
diff -u r.terraflow/sweep.h r.terraflow.1.5/sweep.h
--- r.terraflow/sweep.h	Tue Jan 21 05:45:34 2003
+++ r.terraflow.1.5/sweep.h	Sun Apr  6 12:08:57 2003
@@ -78,9 +78,11 @@
   
   friend ostream& operator << (ostream& s, const sweepOutput &x) {
     return s << "[("  << x.i << ',' << x.j << "):"  
-  	     << form(" accu=%7.3f", x.accu)
+      //<< form(" accu=%7.3f", x.accu)
+	     << " accu=" << x.accu
 #ifdef OUTPUT_TCI
-	     << form(", tci=%3.1f", x.tci)
+      //<< form(", tci=%3.1f", x.tci)
+	     << ", tci=" << x.tci
 #endif
 	     << "]";
   }
diff -u r.terraflow/water.cc r.terraflow.1.5/water.cc
--- r.terraflow/water.cc	Tue Jan 21 05:45:34 2003
+++ r.terraflow.1.5/water.cc	Wed Apr  9 04:51:32 2003
@@ -579,10 +579,11 @@
 
 ostream&
 operator<<(ostream& s, const compressedWaterWindowBaseType &p) {
-  return s << form("[compressedWaterWindowBaseType %d,%d %c e=%d d=%u]",
-		   p.i, p.j, 
-		   directionSymbol(p.getDirection()),
-		   p.getElevation(), p.getDepth());
+  return s << "[compressedWaterWindowBaseType " 
+	   << p.i << "," << p.j 
+	   << " " << directionSymbol(p.getDirection())
+	   << " e=" << p.getElevation() 
+	   << " d =" << p.getDepth() << "]";
 }
 
 /* ********************************************************************** */
@@ -601,10 +602,12 @@
 
 ostream&
 operator<<(ostream& s, const compressedWaterWindowType &p) {
-  return s << form("[compressedWaterWindowType %d,%d %c e=%d d=%u l=%ld]",
-				   p.i, p.j, 
-				   directionSymbol(p.getDirection()),
-				   p.getElevation(), p.getDepth(), p.label);
+  return s << "[compressedWaterWindowType " 
+	   << p.i << "," <<  p.j 
+	   << "  " << directionSymbol(p.getDirection())
+	   << " e=" << p.getElevation()
+	   << " d=" << p.getDepth() 
+	   << " l=" << p.label;
 }
 
 
diff -u r.terraflow/water.h r.terraflow.1.5/water.h
--- r.terraflow/water.h	Tue Jan 21 05:45:34 2003
+++ r.terraflow.1.5/water.h	Sun Apr  6 11:58:48 2003
@@ -60,13 +60,13 @@
 /* ---------------------------------------------------------------------- */
 
 class labelElevType : public ijBaseType {
-  friend labelElevTypePrintLabel;
-protected:
+  friend class labelElevTypePrintLabel;
+ protected:
   elevation_type el;
   cclabel_type label;
-public:
+ public:
   labelElevType() : label(LABEL_UNDEF) {};
-
+  
   labelElevType(dimension_type gi,
 		dimension_type gj,
 		elevation_type gel,
@@ -117,9 +117,9 @@
 class ijCmpBoundaryType;
 
 class boundaryType : public labelElevType {
-  friend waterCmpBoundaryType;
-  friend elevCmpBoundaryType;
-  friend boundaryCmpBoundaryType;
+  friend class waterCmpBoundaryType;
+  friend class elevCmpBoundaryType;
+  friend class boundaryCmpBoundaryType;
 protected:
   cclabel_type label2;
 public:


More information about the grass-dev mailing list