Hi all, 

 First, a general question: with the new trac/osgeo/svn system, what is
the best way to submit patches? I have attached a patch for r.terraflow
below, but if there is a better place to submit, let me know. 

 The main purpose of the patch is to support single flow directions
properly (SFD) in r.terraflow. The previous version has a -s switch for
SFD, but it is not implemented properly. Tools like Hamish's matlab
script for converting terraflow flow direction values to sfd are
incomplete and sometimes result in ambiguous because they are based on
incomplete cases in the terraflow source. With the new patch, sfd should
be supported correctly and the terraflow direction grid should only
output 1 of 9 possible direction values (0,1,2,4,8,16,32,64,128),
instead of the 256 directions it printed before.

 The second purpose of the patch is to eliminate gcc 4.2 warnings of the
form 

warning: deprecated conversion from string constant to ‘char*’

 This required making two new C files to handle the option parsing in
C-style instead of C++. The changes are minor but touched several files.
The actual flow direction fix is rather localized. New files have been
indented according to the SUBMITTING rules

 users using the default Multiple Flow Direction (mfd) options should
see no changes. Users of sfd should notice that it works.

-Andy
Index: types.h
===================================================================
--- types.h	(revision 31860)
+++ types.h	(working copy)
@@ -63,7 +63,6 @@
 /* output parameter types */
 /* ------------------------------------------------------------ */
 typedef float flowaccumulation_type;    
-static const flowaccumulation_type MAX_ACCU = 1e+15;
 typedef float tci_type;       
 
 
Index: nodata.h
===================================================================
--- nodata.h	(revision 31860)
+++ nodata.h	(working copy)
@@ -24,7 +24,6 @@
 
 #include <ami.h>
 #include "types.h"
-#include "option.h"
 
 
 
Index: direction.cc
===================================================================
--- direction.cc	(revision 31860)
+++ direction.cc	(working copy)
@@ -19,9 +19,10 @@
 
 #include "direction.h"
 #include "nodata.h"
+#include "common.h" /*for global opt->d8 flag*/
 
-/***************************************************************/
-/* returns the direction corresponding to the window */
+#define TF_ROOTTWO 1.4142135623
+
 /* directions:
    32 64 128
    16 *   1
@@ -33,6 +34,21 @@
 				dimension_type row, 
 				dimension_type col) {
   
+  /*check global opt flag and call appropriate model*/
+	if(opt->d8){
+    return encodeDirectionSFD(elevwin, nrows, ncols, row, col);
+	}
+  return encodeDirectionMFD(elevwin, nrows, ncols, row, col);
+}
+
+/***************************************************************/
+/* returns the direction corresponding to the window using MFD */
+direction_type 
+encodeDirectionMFD(const genericWindow<elevation_type>& elevwin,
+				const dimension_type nrows, const dimension_type ncols,
+				dimension_type row, 
+				dimension_type col) {
+  
   direction_type dir = DIRECTION_UNDEF;
   
   if(!is_nodata(elevwin.get())) {
@@ -67,7 +83,71 @@
   return dir;
 }
 
+/***************************************************************/
+/* returns the direction corresponding to the window using SFD */
+direction_type 
+encodeDirectionSFD(const genericWindow<elevation_type>& elevwin,
+				const dimension_type nrows, const dimension_type ncols,
+				dimension_type row, 
+				dimension_type col) {
 
+  direction_type dir = DIRECTION_UNDEF;
+	float tdrop, max_drop;
+	int max_indx;
+  
+  if(!is_nodata(elevwin.get())) {
+    dir = 0;
+		max_drop = 0;
+		max_indx = -1;
+		for(int i=0; i<9; i++){
+			if(i%2==1){ /*cardinal direction*/
+				tdrop=elevwin.get()-elevwin.get(i);
+				if(tdrop>max_drop){ max_drop=tdrop; max_indx=i; }
+			}
+			else if(i!=4){ /*diagonal*/
+				tdrop=(elevwin.get()-elevwin.get(i))/TF_ROOTTWO;
+				if(tdrop>max_drop){ max_drop=tdrop; max_indx=i; }
+			}
+		}
+		switch(max_indx){
+			case 0:
+			case 1:
+			case 2:
+				dir=32<<max_indx; break;
+		  case 3:
+				dir=16; break;
+			case 5:
+				dir=1; break;
+			case 6:
+			case 7:
+			case 8:
+				dir=8>>(max_indx-6); break;
+			defualt:
+				dir=0; break;
+		}
+  }
+  
+  /* if no direction, check for boundary */
+  if(dir==0 || dir==DIRECTION_UNDEF) {
+    if(row==0) {
+      dir = 64;
+    }
+    if(row==nrows-1) {
+      dir = 48;
+    }
+    if(col==0) {
+      if(row==0) dir = 32;
+      else if(row==nrows-1) dir = 8;
+      else dir = 16;
+    }
+    if(col==ncols-1) {
+      if(row==0) dir = 128;
+      else if(row==nrows-1) dir = 2;
+      else dir = 1;
+    }
+  }
+  return dir;
+}
 
 direction_type
 findDominant(direction_type dir) {
@@ -143,8 +223,25 @@
 	return 128;
   }
 
-
-  return dir;
+  /* Otherwise, there is no dominant direction.
+	 * SFD must output a single direction 1,2,4,8,16,32,64, or 128
+	 * pick the first matching one, with preference to cardinal direction
+	 */
+	if(dir & 85 ){ 
+		/* at least one cardinal direction (1+4+16+64=E+S+W+N) matches */
+		if(dir & 1){ return 1;}
+		if(dir & 4){ return 4;}
+		if(dir & 16){ return 16;}
+		if(dir & 64){ return 64;}
+	}
+	else{ 
+		/* 2 8 32 128 = SE SW NW NE*/
+		if(dir & 2){ return 2;}
+		if(dir & 8){ return 8;}
+		if(dir & 32){ return 32;}
+		if(dir & 128){ return 128;}
+  }
+  return dir; /* shouldn't get here unless dir <= 0 */
 }
 
 
@@ -152,7 +249,7 @@
 directionSymbol(direction_type dir) {
   char c='?';
   int cnt=0;
-  char *symbols = ">\\v/<\\^/";
+  char symbols[] = ">\\v/<\\^/";
 
   if(dir == 0) return '.';
   
@@ -201,3 +298,4 @@
 } 
 
 
+#undef TF_ROOTTWO
Index: main.cc
===================================================================
--- main.cc	(revision 31860)
+++ main.cc	(working copy)
@@ -35,7 +35,6 @@
 #include <grass/glocale.h>
 }
 
-#include "option.h"
 #include "common.h" /* declares the globals */
 #include "fill.h"
 #include "flow.h"
@@ -43,6 +42,7 @@
 #include "grass2str.h"
 #include "water.h"
 #include "sortutils.h"
+#include "tflowopts.h"
 
 
 /* globals: in common.H
@@ -57,148 +57,7 @@
    and jump directly to computing flow accumulation; the flowstream
    must exist in /var/tmp/flowStream */
 
-
 /* ---------------------------------------------------------------------- */
-void 
-parse_args(int argc, char *argv[]) {
-
-  /* input elevation grid  */
-  struct Option *input_elev;
-  input_elev = G_define_standard_option(G_OPT_R_ELEV);
-
-  /* output filled elevation grid */
-  struct Option *output_elev;
-  output_elev = G_define_standard_option(G_OPT_R_OUTPUT);
-  output_elev->key        = "filled";
-  output_elev->description= _("Output filled (flooded) elevation raster map");
-  
- /* output direction  grid */
-  struct Option *output_dir;
-  output_dir = G_define_standard_option(G_OPT_R_OUTPUT);
-  output_dir->key        = "direction";
-  output_dir->description= _("Output flow direction raster map");
-
-  /* output sinkwatershed  grid */
-  struct Option *output_watershed;
-  output_watershed = G_define_standard_option(G_OPT_R_OUTPUT);
-  output_watershed->key        = "swatershed";
-  output_watershed->description= _("Output sink-watershed raster map");
-
-  /* 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= _("Output flow accumulation raster map");
-
-#ifdef OUTPUT_TCI
-  struct Option *output_tci;
-  output_tci = G_define_standard_option(G_OPT_R_OUTPUT);
-  output_tci->key        = "tci";
-  output_tci->description=
-    _("Output topographic convergence index (tci) raster map");
-#endif
-
-  /* MFD/SFD flag */
-  struct Flag *sfd_flag;
-  sfd_flag = G_define_flag() ;
-  sfd_flag->key        = 's';
-  sfd_flag->description= _("SFD (D8) flow (default is MFD)");
-  /* sfd_flag->answer     = 'n'; */
-
-  /* D8CUT value*/
-  struct Option *d8cut;
-  d8cut = G_define_option();
-  d8cut->key  = "d8cut";
-  d8cut->type = TYPE_DOUBLE;
-  d8cut->required = NO;
-  d8cut->answer = "infinity"; /* default value */
-  d8cut->description =
-    _("If flow accumulation is larger than this value it is routed using "
-      "SFD (D8) direction \n \t\t (meaningfull only  for MFD flow)");
-  
-  /* main memory */
-  struct Option *mem;
-  mem = G_define_option() ;
-  mem->key         = "memory";
-  mem->type        = TYPE_INTEGER;
-  mem->required    = NO;
-  mem->answer      = "300"; /* 300MB default value */
-  mem->description = _("Maximum runtime memory size (in MB)");
-
-  /* temporary STREAM path */
-  struct Option *streamdir;
-  streamdir = G_define_option() ;
-  streamdir->key        = "STREAM_DIR";
-  streamdir->type       = TYPE_STRING;
-  streamdir->required   = NO;
-  streamdir->answer     = "/var/tmp"; 
-  streamdir->description=
-     _("Directory to hold temporary files (they can be large)");
-
-  /* verbose flag */
-  /* please, remove before GRASS 7 released */
-  struct Flag *quiet;
-  quiet = G_define_flag() ;
-  quiet->key         = 'q' ;
-  quiet->description = _("Quiet");
-  /* quiet->answer = 'n'; */
-
- /* stats file */
-  struct Option *stats_opt;
-  stats_opt = G_define_option() ;
-  stats_opt->key        = "stats";
-  stats_opt->type       = TYPE_STRING;
-  stats_opt->required   = NO;
-  stats_opt->description= _("Name of file containing runtime statistics");
-  stats_opt->answer     = "stats.out";
-
-
-  if (G_parser(argc, argv)) {
-    exit (EXIT_FAILURE);
-  }
-  
-  /* ************************* */
-  assert(opt);
-  opt->elev_grid = input_elev->answer;
-  opt->filled_grid = output_elev->answer;
-  opt->dir_grid = output_dir->answer; 
-  opt->watershed_grid = output_watershed->answer;
-  opt->flowaccu_grid = output_accu->answer;
-#ifdef OUTPUT_TCI
-  opt->tci_grid = output_tci->answer;
-#endif
-
-  opt->d8 = sfd_flag->answer;
-  if (strcmp(d8cut->answer, "infinity") == 0) {
-    opt->d8cut = MAX_ACCU;
-  } else {
-    opt->d8cut = atoi(d8cut->answer);
-  }
-
-  opt->mem = atoi(mem->answer);
-  opt->streamdir = streamdir->answer;
-
-  opt->verbose = FALSE;
-/* please, remove before GRASS 7 released */
-  if(quiet->answer) {
-    G_warning(_("The '-q' flag is superseded and will be removed "
-	"in future. Please use '--quiet' instead."));
-    G_putenv("GRASS_VERBOSE","0");
-    opt->verbose = FALSE;
-  }
-  else {
-    if(G_verbose() == G_verbose_max())
-	opt->verbose = TRUE;
-  }
-
-
-  opt->stats = stats_opt->answer;
-
-  /* somebody should delete the options */
-}
-
-
-/* ---------------------------------------------------------------------- */
 /* check compatibility of map header and region header */
 void check_header(char* cellname) {
 
@@ -465,17 +324,9 @@
 */
 
   /* initialize GIS library */
-  G_gisinit(argv[0]);
+  G_gisinit(argv[0]); 
+  init_module(&module);
 
- 
-  module = G_define_module();
-#ifdef ELEV_SHORT
-  module->description = _("Flow computation for massive grids (Integer version).");
-#endif
-#ifdef ELEV_FLOAT
-  module->description = _("Flow computation for massive grids (Float version).");
-#endif
-
   /* get the current region and dimensions */  
   region = (struct Cell_head*)malloc(sizeof(struct Cell_head));
   assert(region);
Index: fill.cc
===================================================================
--- fill.cc	(revision 31860)
+++ fill.cc	(working copy)
@@ -20,8 +20,8 @@
 #include <ctype.h>
 #include <time.h>
 
+#include <string> 
 #include "fill.h"
-#include "option.h"
 #include "common.h"
 #include "water.h"
 #include "sortutils.h"
@@ -138,9 +138,9 @@
 
 
 char *
-verbosedir(char *s) {
+verbosedir(std::string s) {
   static char buf[BUFSIZ];
-  sprintf(buf, "dump/%s", s);
+  sprintf(buf, "dump/%s", s.c_str());
   return buf;
 }
 
Index: common.cc
===================================================================
--- common.cc	(revision 31860)
+++ common.cc	(working copy)
@@ -38,7 +38,6 @@
 /* globals */
 
 statsRecorder *stats = NULL;
-userOptions *opt = NULL;
 struct  Cell_head *region = NULL; 
 dimension_type nrows = 0, ncols = 0;
 
Index: Makefile
===================================================================
--- Makefile	(revision 31860)
+++ Makefile	(working copy)
@@ -4,16 +4,24 @@
 
 include $(MODULE_TOPDIR)/include/Make/Multi.make
 
-SOURCES = main.cc common.cc stats.cc fill.cc types.cc ccforest.cc \
+CPPSOURCES = 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 \
 	flow.cc sweep.cc weightWindow.cc
 
+CSOURCES = tflowopts.c
+
 OBJARCH=OBJ.$(ARCH)
 
-FLOAT_OBJ := $(patsubst %.cc, $(OBJARCH)/FLOAT/%.o, $(SOURCES))
-SHORT_OBJ := $(patsubst %.cc, $(OBJARCH)/SHORT/%.o, $(SOURCES))
+FLOAT_CPPOBJ := $(patsubst %.cc, $(OBJARCH)/FLOAT/%.o, $(CPPSOURCES))
+SHORT_CPPOBJ := $(patsubst %.cc, $(OBJARCH)/SHORT/%.o, $(CPPSOURCES))
 
+FLOAT_COBJ := $(patsubst %.c, $(OBJARCH)/FLOAT/%.o, $(CSOURCES))
+SHORT_COBJ := $(patsubst %.c, $(OBJARCH)/SHORT/%.o, $(CSOURCES))
+
+FLOAT_OBJ = $(FLOAT_CPPOBJ) $(FLOAT_COBJ)
+SHORT_OBJ = $(SHORT_CPPOBJ) $(SHORT_COBJ)
+
 IOSTREAM_LIBNAME = iostream
 IOSTREAM_DIR = IOStream
 IOSTREAM_INC = $(IOSTREAM_DIR)/include
@@ -24,11 +32,19 @@
 		-DUSER=\"$(USER)\" \
 		-DNODATA_FIX -D_FILE_OFFSET_BITS=64
 
-LIBS = $(GISLIB) 
+CFLAGS += -DUSER=\"$(USER)\" 
+
+LIBS = $(GISLIB)
 DEPLIBS = $(DEPGISLIB)
 
 CLEAN_SUBDIRS = $(IOSTREAM_DIR)
 
+$(OBJARCH)/FLOAT/tflowopts.o: tflowopts.c tflowopts.h
+	$(CC) -c $(CFLAGS) $(NLS_CFLAGS) -DELEV_FLOAT $< -o $@
+
+$(OBJARCH)/SHORT/tflowopts.o: tflowopts.c tflowopts.h
+	$(CC) -c $(CFLAGS) $(NLS_CFLAGS) -DELEV_SHORT $< -o $@
+
 #Note: 	if a header file is modified, the .o files do not get rebuilt..
 #		header files should be included as prerequisites, but does not work 
 #		because of GRASS scripts 
Index: grass2str.h
===================================================================
--- grass2str.h	(revision 31860)
+++ grass2str.h	(working copy)
@@ -21,7 +21,6 @@
 #define _gras2str_H
 
 #include <ami.h>
-#include "option.h"
 #include "types.h"
 #include "common.h"
 #include "nodata.h" /* for TERRAFLOW_INTERNAL_NODATA_VALUE */
Index: IOStream/include/mm_utils.h
===================================================================
--- IOStream/include/mm_utils.h	(revision 31860)
+++ IOStream/include/mm_utils.h	(working copy)
@@ -22,12 +22,12 @@
 
 
 #include "mm.h"
+#include <string>
 
-
 void  LOG_avail_memo();
 
 size_t getAvailableMemory();
 
-void  MEMORY_LOG(char* str);
+void  MEMORY_LOG(std::string str);
 
 #endif
Index: IOStream/include/mem_stream.h
===================================================================
--- IOStream/include/mem_stream.h	(revision 31860)
+++ IOStream/include/mem_stream.h	(working copy)
@@ -84,7 +84,7 @@
 template<class T>
 AMI_err MEM_STREAM<T>::name(char **stream_name)  {
 
-  char *path = "dummy";
+  char const* path = "dummy";
 
   *stream_name = new char [strlen(path) + 1];
   strcpy(*stream_name, path);
Index: IOStream/include/ami_stream.h
===================================================================
--- IOStream/include/ami_stream.h	(revision 31860)
+++ IOStream/include/ami_stream.h	(working copy)
@@ -178,7 +178,7 @@
 /**********************************************************************/
 /* creates a random file name, opens the file for reading and writing
    and and returns a file descriptor */
-int ami_single_temp_name(char *base, char* tmp_path);
+int ami_single_temp_name(const std::string& base, char* tmp_path);
 
 
 /**********************************************************************/
Index: IOStream/lib/src/ami_stream.cc
===================================================================
--- IOStream/lib/src/ami_stream.cc	(revision 31860)
+++ IOStream/lib/src/ami_stream.cc	(working copy)
@@ -32,7 +32,7 @@
 /* creates a random file name, opens the file for reading and writing
    and and returns a file descriptor */
 int
-ami_single_temp_name(char *base, char* tmp_path) {
+ami_single_temp_name(const std::string& base, char* tmp_path) {
  
   char *base_dir;
   int fd;
@@ -41,7 +41,7 @@
   base_dir = getenv(STREAM_TMPDIR);
   assert(base_dir);
 
-  sprintf(tmp_path, "%s/%s_XXXXXX", base_dir, base);
+  sprintf(tmp_path, "%s/%s_XXXXXX", base_dir, base.c_str());
 #ifdef __MINGW32__
   fd = mktemp(tmp_path) ? open(tmp_path, O_CREAT|O_EXCL|O_RDWR, 0600) : -1;
 #else
Index: IOStream/lib/src/mm_utils.cc
===================================================================
--- IOStream/lib/src/mm_utils.cc	(revision 31860)
+++ IOStream/lib/src/mm_utils.cc	(working copy)
@@ -46,8 +46,7 @@
   return fmem;
 }
 
-void 
-MEMORY_LOG(char* str) {
-  printf("%s", str);
+void MEMORY_LOG(std::string str) {
+  printf("%s", str.c_str());
   fflush(stdout);
 }
Index: flow.cc
===================================================================
--- flow.cc	(revision 31860)
+++ flow.cc	(working copy)
@@ -21,7 +21,6 @@
 
 #include "flow.h"
 #include "sweep.h"
-#include "option.h"
 #include "common.h"
 #include "sortutils.h"
 #include "streamutils.h"
Index: direction.h
===================================================================
--- direction.h	(revision 31860)
+++ direction.h	(working copy)
@@ -141,6 +141,16 @@
 			       const dimension_type ncols,
 			       dimension_type row, dimension_type col);
 
+direction_type encodeDirectionMFD(const genericWindow<elevation_type>& elevwin,
+			       const dimension_type nrows, 
+			       const dimension_type ncols,
+			       dimension_type row, dimension_type col);
+
+direction_type encodeDirectionSFD(const genericWindow<elevation_type>& elevwin,
+			       const dimension_type nrows, 
+			       const dimension_type ncols,
+			       dimension_type row, dimension_type col);
+
 direction_type findDominant(direction_type dir);
 char directionSymbol(direction_type dir);
 
Index: sweep.cc
===================================================================
--- sweep.cc	(revision 31860)
+++ sweep.cc	(working copy)
@@ -25,7 +25,6 @@
 
 #include <ami.h>
 
-#include "option.h"
 #include "stats.h"
 #include "sweep.h"
 #include "common.h"
Index: sweep.h
===================================================================
--- sweep.h	(revision 31860)
+++ sweep.h	(working copy)
@@ -24,7 +24,6 @@
 
 #include <ami.h>
 
-#include "option.h"
 #include "types.h"
 #include "weightWindow.h"
 
Index: common.h
===================================================================
--- common.h	(revision 31860)
+++ common.h	(working copy)
@@ -27,16 +27,16 @@
 #include <ami.h>
 
 #include "stats.h"
-#include "option.h"
 #include "types.h" /* for dimension_type */
 extern "C" {
 #include <grass/gis.h>
+#include "option.h"
+#include "tflowopts.h"
 }
 
 
 
 extern statsRecorder *stats;     /* stats file */
-extern userOptions *opt;          /* command-line options */
 extern struct  Cell_head *region; /* header of the region */
 extern dimension_type nrows, ncols;
 
/****************************************************************************
 * 
 *  MODULE:	r.terraflow
 *
 *  COPYRIGHT (C) 2007 Laura Toma
 *   
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *****************************************************************************/

#include <stdlib.h>

#include <grass/gis.h>
#include <grass/glocale.h>

#include "tflowopts.h"

userOptions *opt = NULL;

void init_module(struct GModule **module)
{
    *module = G_define_module();
#ifdef ELEV_SHORT
    (*module)->description =
	_("Flow computation for massive grids (Integer version).");
#endif
#ifdef ELEV_FLOAT
    (*module)->description =
	_("Flow computation for massive grids (Float version).");
#endif
}

#define MAX_ACCU 1e+15
void parse_args(int argc, char *argv[])
{

    /* input elevation grid  */
    struct Option *input_elev;

    input_elev = G_define_standard_option(G_OPT_R_ELEV);

    /* output filled elevation grid */
    struct Option *output_elev;

    output_elev = G_define_standard_option(G_OPT_R_OUTPUT);
    output_elev->key = "filled";
    output_elev->description =
	_("Output filled (flooded) elevation raster map");

    /* output direction  grid */
    struct Option *output_dir;

    output_dir = G_define_standard_option(G_OPT_R_OUTPUT);
    output_dir->key = "direction";
    output_dir->description = _("Output flow direction raster map");

    /* output sinkwatershed  grid */
    struct Option *output_watershed;

    output_watershed = G_define_standard_option(G_OPT_R_OUTPUT);
    output_watershed->key = "swatershed";
    output_watershed->description = _("Output sink-watershed raster map");

    /* 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 = _("Output flow accumulation raster map");

#ifdef OUTPUT_TCI
    struct Option *output_tci;

    output_tci = G_define_standard_option(G_OPT_R_OUTPUT);
    output_tci->key = "tci";
    output_tci->description =
	_("Output topographic convergence index (tci) raster map");
#endif

    /* MFD/SFD flag */
    struct Flag *sfd_flag;

    sfd_flag = G_define_flag();
    sfd_flag->key = 's';
    sfd_flag->description = _("SFD (D8) flow (default is MFD)");
    /* sfd_flag->answer     = 'n'; */

    /* D8CUT value */
    struct Option *d8cut;

    d8cut = G_define_option();
    d8cut->key = "d8cut";
    d8cut->type = TYPE_DOUBLE;
    d8cut->required = NO;
    d8cut->answer = "infinity";	/* default value */
    d8cut->description =
	_("If flow accumulation is larger than this value it is routed using "
	  "SFD (D8) direction \n \t\t (meaningfull only  for MFD flow)");

    /* main memory */
    struct Option *mem;

    mem = G_define_option();
    mem->key = "memory";
    mem->type = TYPE_INTEGER;
    mem->required = NO;
    mem->answer = "300";	/* 300MB default value */
    mem->description = _("Maximum runtime memory size (in MB)");

    /* temporary STREAM path */
    struct Option *streamdir;

    streamdir = G_define_option();
    streamdir->key = "STREAM_DIR";
    streamdir->type = TYPE_STRING;
    streamdir->required = NO;
    streamdir->answer = "/var/tmp";
    streamdir->description =
	_("Directory to hold temporary files (they can be large)");

    /* verbose flag */
    /* please, remove before GRASS 7 released */
    struct Flag *quiet;

    quiet = G_define_flag();
    quiet->key = 'q';
    quiet->description = _("Quiet");
    /* quiet->answer = 'n'; */

    /* stats file */
    struct Option *stats_opt;

    stats_opt = G_define_option();
    stats_opt->key = "stats";
    stats_opt->type = TYPE_STRING;
    stats_opt->required = NO;
    stats_opt->description = _("Name of file containing runtime statistics");
    stats_opt->answer = "stats.out";


    if (G_parser(argc, argv)) {
	exit(EXIT_FAILURE);
    }

    /* ************************* */
    opt->elev_grid = input_elev->answer;
    opt->filled_grid = output_elev->answer;
    opt->dir_grid = output_dir->answer;
    opt->watershed_grid = output_watershed->answer;
    opt->flowaccu_grid = output_accu->answer;
#ifdef OUTPUT_TCI
    opt->tci_grid = output_tci->answer;
#endif

    opt->d8 = sfd_flag->answer;
    if (strcmp(d8cut->answer, "infinity") == 0) {
	opt->d8cut = MAX_ACCU;
    }
    else {
	opt->d8cut = atoi(d8cut->answer);
    }

    opt->mem = atoi(mem->answer);
    opt->streamdir = streamdir->answer;

    opt->verbose = FALSE;
    /* please, remove before GRASS 7 released */
    if (quiet->answer) {
	G_warning(_("The '-q' flag is superseded and will be removed "
		    "in future. Please use '--quiet' instead."));
	G_putenv("GRASS_VERBOSE", "0");
	opt->verbose = FALSE;
    }
    else {
	if (G_verbose() == G_verbose_max())
	    opt->verbose = TRUE;
    }


    opt->stats = stats_opt->answer;

    /* somebody should delete the options */
}

#undef MAX_ACCU
/****************************************************************************
 * 
 *  MODULE:	r.terraflow
 *
 *  COPYRIGHT (C) 2007 Laura Toma
 *   
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *****************************************************************************/

#ifndef TFLOWOPTS_H
#define TFLOWOPTS_H

#include <grass/gis.h>
#include "option.h"


extern userOptions *opt;	/* command-line options */

void init_module(struct GModule **module);

void parse_args(int argc, char *argv[]);

#endif /*TFLOWOPTS_H */
_______________________________________________
grass-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-dev

Reply via email to