[GRASS-SVN] r30767 - in grass/branches/releasebranch_6_3/raster/r.terraflow: . IOStream/include IOStream/lib/src

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Mar 27 17:06:23 EDT 2008


Author: neteler
Date: 2008-03-27 17:06:23 -0400 (Thu, 27 Mar 2008)
New Revision: 30767

Modified:
   grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/include/ami_stream.h
   grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/include/quicksort.h
   grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/include/rtimer.h
   grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/lib/src/ami_stream.cc
   grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/lib/src/mm_utils.cc
   grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/lib/src/rtimer.cc
   grass/branches/releasebranch_6_3/raster/r.terraflow/common.cc
   grass/branches/releasebranch_6_3/raster/r.terraflow/flow.cc
   grass/branches/releasebranch_6_3/raster/r.terraflow/grass2str.h
   grass/branches/releasebranch_6_3/raster/r.terraflow/main.cc
   grass/branches/releasebranch_6_3/raster/r.terraflow/stats.cc
Log:
MINGW32 fixed backported

Modified: grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/include/ami_stream.h
===================================================================
--- grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/include/ami_stream.h	2008-03-27 17:23:30 UTC (rev 30766)
+++ grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/include/ami_stream.h	2008-03-27 21:06:23 UTC (rev 30767)
@@ -36,6 +36,10 @@
 
 #include "mm.h" // Get the memory manager.
 
+#ifdef __MINGW32__
+#define getpagesize() (4096)
+#endif
+
 #define DEBUG_DELETE if(0)
 
 // The name of the environment variable which keeps the name of the
@@ -421,7 +425,7 @@
   
   // Get rid of the file if not persistent and if not substream.
   if ((per != PERSIST_PERSISTENT) && (substream_level == 0)) {
-    if (unlink(path) == -1) {
+    if (remove(path) == -1) {
       cerr << "AMI_STREAM: failed to unlink " << path << endl;
       perror("cannot unlink ");
       assert(0);

Modified: grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/include/quicksort.h
===================================================================
--- grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/include/quicksort.h	2008-03-27 17:23:30 UTC (rev 30766)
+++ grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/include/quicksort.h	2008-03-27 21:06:23 UTC (rev 30767)
@@ -41,7 +41,11 @@
     
     // Try to get a good partition value and avoid being bitten by already
     // sorted input.
+#ifdef __MINGW32__
+    ptpart = data + (rand() % n);
+#else
     ptpart = data + (random() % n);
+#endif
     tpart = *ptpart;
     *ptpart = data[0];
     data[0] = tpart;

Modified: grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/include/rtimer.h
===================================================================
--- grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/include/rtimer.h	2008-03-27 17:23:30 UTC (rev 30766)
+++ grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/include/rtimer.h	2008-03-27 21:06:23 UTC (rev 30767)
@@ -22,6 +22,38 @@
 
 /* $Id$ */
 
+#ifdef __MINGW32__
+
+#include <time.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+
+typedef struct {
+  time_t tv1, tv2;
+} Rtimer;
+
+#define rt_start(rt)				\
+  if((time(&(rt.tv1)) == ((time_t) -1))) {	\
+	perror("time");				\
+	exit(1);				\
+  }
+
+/* doesn't really stop, just updates endtimes */
+#define rt_stop(rt)								\
+  if((time(&(rt.tv2)) == ((time_t) -1))) {	\
+	perror("time");				\
+	exit(1);				\
+  }
+
+#define rt_u_useconds(rt)	rt_w_useconds(rt)
+
+#define rt_s_useconds(rt)	rt_w_useconds(rt)
+
+#define rt_w_useconds(rt)	(1.0e6 * (rt.tv2 - rt.tv1))
+
+#else /* __MINGW32__ */
+
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <stdio.h>
@@ -48,10 +80,6 @@
         perror("rusage/gettimeofday");			\
         exit(1);								\
   }
-
-/* not required to be called, but makes values print as 0. 
-   obviously a hack */
-#define rt_zero(rt) bzero(&(rt),sizeof(Rtimer));
 	
 
 #define rt_u_useconds(rt)							\
@@ -72,12 +100,16 @@
 	  - ((double)rt.tv1.tv_usec +			\
 		 (double)rt.tv1.tv_sec*1000000))
 
+#endif /* __MINGW32__ */
+
+/* not required to be called, but makes values print as 0. 
+   obviously a hack */
+#define rt_zero(rt) bzero(&(rt),sizeof(Rtimer));
+
 #define rt_seconds(rt) (rt_w_useconds(rt)/1000000)
 
 #define rt_sprint(buf, rt) rt_sprint_safe(buf,rt)
 
 char * rt_sprint_safe(char *buf, Rtimer rt);
 
-
-
 #endif /* RTIMER_H */

Modified: grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/lib/src/ami_stream.cc
===================================================================
--- grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/lib/src/ami_stream.cc	2008-03-27 17:23:30 UTC (rev 30766)
+++ grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/lib/src/ami_stream.cc	2008-03-27 21:06:23 UTC (rev 30767)
@@ -42,7 +42,11 @@
   assert(base_dir);
 
   sprintf(tmp_path, "%s/%s_XXXXXX", base_dir, base);
+#ifdef __MINGW32__
+  fd = mktemp(tmp_path) ? open(tmp_path, O_CREAT|O_EXCL|O_RDWR, 0600) : -1;
+#else
   fd  = mkstemp(tmp_path);
+#endif
 
   if (fd == -1) {
     cerr <<  "ami_single_temp_name: ";

Modified: grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/lib/src/mm_utils.cc
===================================================================
--- grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/lib/src/mm_utils.cc	2008-03-27 17:23:30 UTC (rev 30766)
+++ grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/lib/src/mm_utils.cc	2008-03-27 21:06:23 UTC (rev 30767)
@@ -17,7 +17,6 @@
  *****************************************************************************/
 
 #include <sys/types.h>
-#include <sys/mman.h>
 #include <ctype.h>
 
 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)

Modified: grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/lib/src/rtimer.cc
===================================================================
--- grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/lib/src/rtimer.cc	2008-03-27 17:23:30 UTC (rev 30766)
+++ grass/branches/releasebranch_6_3/raster/r.terraflow/IOStream/lib/src/rtimer.cc	2008-03-27 21:06:23 UTC (rev 30767)
@@ -18,7 +18,6 @@
 
 
 #include <sys/time.h>
-#include <sys/resource.h>
 #include <stdio.h>
 #include <string.h>
 #include <strings.h>

Modified: grass/branches/releasebranch_6_3/raster/r.terraflow/common.cc
===================================================================
--- grass/branches/releasebranch_6_3/raster/r.terraflow/common.cc	2008-03-27 17:23:30 UTC (rev 30766)
+++ grass/branches/releasebranch_6_3/raster/r.terraflow/common.cc	2008-03-27 21:06:23 UTC (rev 30767)
@@ -18,7 +18,9 @@
 
 
 #include <sys/types.h>
+#ifdef USE_LARGEMEM
 #include <sys/mman.h>
+#endif
 #include <ctype.h>
 
 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)

Modified: grass/branches/releasebranch_6_3/raster/r.terraflow/flow.cc
===================================================================
--- grass/branches/releasebranch_6_3/raster/r.terraflow/flow.cc	2008-03-27 17:23:30 UTC (rev 30766)
+++ grass/branches/releasebranch_6_3/raster/r.terraflow/flow.cc	2008-03-27 21:06:23 UTC (rev 30767)
@@ -64,8 +64,12 @@
       perror("time");
       exit(1);
     }
+#ifdef __MINGW32__
+    strcpy(buf, ctime(&t));
+#else
     ctime_r(&t, buf);
     buf[24] = '\0';
+#endif
     stats->timestamp(buf);
     *stats << endl;  
     

Modified: grass/branches/releasebranch_6_3/raster/r.terraflow/grass2str.h
===================================================================
--- grass/branches/releasebranch_6_3/raster/r.terraflow/grass2str.h	2008-03-27 17:23:30 UTC (rev 30766)
+++ grass/branches/releasebranch_6_3/raster/r.terraflow/grass2str.h	2008-03-27 21:06:23 UTC (rev 30767)
@@ -57,12 +57,12 @@
   char *mapset;
   mapset = G_find_cell (cellname, "");
   if (mapset == NULL)
-    G_fatal_error ("cell file [%s] not found", cellname);
+    G_fatal_error (_("Raster map <%s> not found"), cellname);
   
   /* open map */
   int infd;
   if ( (infd = G_open_cell_old (cellname, mapset)) < 0)
-    G_fatal_error ("Cannot open raster map [%s]", cellname);
+    G_fatal_error (_("Unable to open raster map <%s>"), cellname);
   
   /* determine map type (CELL/FCELL/DCELL) */
   RASTER_MAP_TYPE data_type;
@@ -82,7 +82,7 @@
 	
 	/* read input map */
     if (G_get_raster_row (infd, inrast, i, data_type) < 0)
-      G_fatal_error ("Could not read from <%s>, row=%d",cellname,i);
+      G_fatal_error (_("Unable to read raster map <%s>, row %d"),cellname, i);
   
 	for (int j=0; j<ncols; j++) {
 
@@ -109,7 +109,7 @@
 		}
 		break;
 	  default:
-		G_fatal_error("raster type not implemented");		
+		G_fatal_error("Raster type not implemented");		
       }
 	  /* cout << form("(i=%d,j=%d): (%d, %f)\n",i,j,x,d); cout.flush(); */
 	  /* handle null values */
@@ -175,7 +175,7 @@
   /* open output raster map */
   int outfd;
   if ( (outfd = G_open_raster_new (cellname, mtype)) < 0) {
-    G_fatal_error ("Could not open <%s>", cellname);
+    G_fatal_error (_("Unable to create raster map <%s>"), cellname);
   }
   
   /* Allocate output buffer */

Modified: grass/branches/releasebranch_6_3/raster/r.terraflow/main.cc
===================================================================
--- grass/branches/releasebranch_6_3/raster/r.terraflow/main.cc	2008-03-27 17:23:30 UTC (rev 30766)
+++ grass/branches/releasebranch_6_3/raster/r.terraflow/main.cc	2008-03-27 21:06:23 UTC (rev 30767)
@@ -14,6 +14,7 @@
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
+ *  TODO before GRASS 7 released: change param 'STREAM_DIR' -> 'stream_dir'
  *****************************************************************************/
  
 #include <stdio.h>
@@ -224,7 +225,7 @@
   char *mapset;
   mapset = G_find_cell(cellname, "");
   if (mapset == NULL) {
-    G_fatal_error(_("cell file [%s] not found"), cellname);
+    G_fatal_error(_("Raster map <%s> not found"), cellname);
   }
   /* read cell header */
   struct Cell_head cell_hd;
@@ -283,24 +284,24 @@
 
   /* check if filled elevation grid name is  valid */
   if (G_legal_filename (opt->filled_grid) < 0) {
-    G_fatal_error(_("[%s] is an illegal name"), opt->filled_grid);
+    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) {
-    G_fatal_error(_("[%s] is an illegal name"), opt->dir_grid);
+    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 name"), opt->filled_grid);
+    G_fatal_error(_("<%s> is an illegal file name"), opt->filled_grid);
   }
   if (G_legal_filename (opt->flowaccu_grid) < 0) {
-    G_fatal_error(_("[%s] is an illegal name"), opt->flowaccu_grid);
+    G_fatal_error(_("<%s> is an illegal file name"), opt->flowaccu_grid);
   }
   if (G_legal_filename (opt->watershed_grid) < 0) {
-    G_fatal_error(_("[%s] is an illegal name"), opt->watershed_grid);
+    G_fatal_error(_("<%s> is an illegal file name"), opt->watershed_grid);
   }
 #ifdef OUTPU_TCI
   if (G_legal_filename (opt->tci_grid) < 0) {
-  G_fatal_error(_("[%s] is an illegal name"), opt->tci_grid);
+  G_fatal_error(_("<%s> is an illegal file name"), opt->tci_grid);
   }
 #endif
   
@@ -324,8 +325,12 @@
     exit(1);
   }
 
+#ifdef __MINGW32__
+  strcpy(buf, ctime(&t));
+#else
   ctime_r(&t, buf);
   buf[24] = '\0';
+#endif
   stats->timestamp(buf);
   
   *stats << "Command Line: " << endl;
@@ -369,7 +374,7 @@
 
   mapset = G_find_cell(cellname, "");
   if (mapset == NULL) {
-    G_fatal_error (_("cell file [%s] not found"), cellname);
+    G_fatal_error (_("Raster map <%s> not found"), cellname);
   }
   if (G_read_range(cellname, mapset, &r) == -1) {
     G_fatal_error(_("cannot read range"));
@@ -409,7 +414,7 @@
 
   mapset = G_find_cell(cellname, "");
   if (mapset == NULL) {
-    G_fatal_error (_("cell file [%s] not found"), cellname);
+    G_fatal_error (_("Raster map <%s> not found"), cellname);
   }
   if (G_read_range(cellname, mapset, &r) == -1) {
     G_fatal_error(_("cannot read range"));
@@ -519,7 +524,8 @@
  
   /* check STREAM path (the place where intermediate STREAMs are placed) */
   sprintf(buf, "%s=%s",STREAM_TMPDIR, opt->streamdir);
-  putenv(buf);
+  /* 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");

Modified: grass/branches/releasebranch_6_3/raster/r.terraflow/stats.cc
===================================================================
--- grass/branches/releasebranch_6_3/raster/r.terraflow/stats.cc	2008-03-27 17:23:30 UTC (rev 30766)
+++ grass/branches/releasebranch_6_3/raster/r.terraflow/stats.cc	2008-03-27 21:06:23 UTC (rev 30767)
@@ -21,7 +21,9 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/time.h>
+#ifndef __MINGW32__
 #include <sys/resource.h>
+#endif
 #include <stdio.h>
 #include <errno.h>
 
@@ -126,7 +128,9 @@
   //ofstream that takes an fd; wrote another noclobber() function that
   //closes fd and returns the name;
   rt_start(tm);
+#ifndef __MINGW32__
   bss = sbrk(0);
+#endif
   char buf[BUFSIZ];
   *this << freeMem(buf) << endl;
 }
@@ -135,6 +139,9 @@
 
 long 
 statsRecorder::freeMem() {
+#ifdef __MINGW32__
+  return -1;
+#else
   struct rlimit rlim;
   if (getrlimit(RLIMIT_DATA, &rlim) == -1) {
 	perror("getrlimit: ");
@@ -148,6 +155,7 @@
   } 
   long freeMem = rlim.rlim_cur - ((char*)sbrk(0)-(char*)bss);
   return freeMem;
+#endif /* __MINGW32__ */
 }
 
 char *



More information about the grass-commit mailing list