[GRASS-SVN] r42456 - grass-addons/raster/r.stream.basins

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jun 3 07:30:57 EDT 2010


Author: mmetz
Date: 2010-06-03 07:30:57 -0400 (Thu, 03 Jun 2010)
New Revision: 42456

Modified:
   grass-addons/raster/r.stream.basins/catchment.c
   grass-addons/raster/r.stream.basins/global.h
   grass-addons/raster/r.stream.basins/io.c
   grass-addons/raster/r.stream.basins/main.c
Log:
format and clean up code

Modified: grass-addons/raster/r.stream.basins/catchment.c
===================================================================
--- grass-addons/raster/r.stream.basins/catchment.c	2010-06-03 11:30:25 UTC (rev 42455)
+++ grass-addons/raster/r.stream.basins/catchment.c	2010-06-03 11:30:57 UTC (rev 42456)
@@ -1,5 +1,7 @@
 #include "global.h"
 
+int tail, head, has_point;
+
 /* 
    Link: a channel between junction
    Ooutlet: is final cell of every segment
@@ -16,11 +18,10 @@
  */
 int find_outlets(void)
 {
-    int d, i, j;		/* d: direction, i: iteration */
+    int d;		/* d: direction */
     int r, c;
     int next_stream = -1, cur_stream;
     int out_max = ncols + nrows;
-
     int nextr[9] = { 0, -1, -1, -1, 0, 1, 1, 1, 0 };
     int nextc[9] = { 0, 1, 0, -1, -1, -1, 0, 1, 1 };
 
@@ -31,17 +32,19 @@
 
     for (r = 0; r < nrows; ++r) {
 	for (c = 0; c < ncols; ++c) {
-	  
-	  if (streams[r][c] > 0) {
-		
-			if (outlets_num > 2*(out_max - 1))
-		G_fatal_error("Stream and direction maps probably do not match");
-		
-			if (outlets_num > (out_max - 1)) 
-		outlets =	(OUTLET *) G_realloc(outlets,
-				out_max * 2 * sizeof(OUTLET));
 
+	    if (streams[r][c] > 0) {
 
+		if (outlets_num > 2 * (out_max - 1))
+		    G_fatal_error
+			("Stream and direction maps probably do not match");
+
+		if (outlets_num > (out_max - 1))
+		    outlets = (OUTLET *) G_realloc(outlets,
+						   out_max * 2 *
+						   sizeof(OUTLET));
+
+
 		d = abs(dirs[r][c]);	/* abs */
 		if (r + nextr[d] < 0 || r + nextr[d] > (nrows - 1) ||
 		    c + nextc[d] < 0 || c + nextc[d] > (ncols - 1)) {
@@ -54,16 +57,16 @@
 		}
 		if (d == 0)
 		    next_stream = -1;
-		
+
 		cur_stream = streams[r][c];
 
 		if (lasts) {
 		    if (cur_stream != next_stream && next_stream < 0) {	/* is outlet! */
-				
-					if (categories) { /* but not in list */
-						if (categories[streams[r][c]]==-1)
-					continue;	
-					}
+
+			if (categories) {	/* but not in list */
+			    if (categories[streams[r][c]] == -1)
+				continue;
+			}
 			outlets[outlets_num].r = r;
 			outlets[outlets_num].c = c;
 			outlets[outlets_num].val =
@@ -73,12 +76,12 @@
 		}
 		else {
 		    if (cur_stream != next_stream) {	/* is outlet or node! */
-					
-					if (categories) { /* but not in list */
-						if (categories[streams[r][c]]==-1)
-					continue;	
-					}
-			
+
+			if (categories) {	/* but not in list */
+			    if (categories[streams[r][c]] == -1)
+				continue;
+			}
+
 			outlets[outlets_num].r = r;
 			outlets[outlets_num].c = c;
 			outlets[outlets_num].val =
@@ -105,18 +108,18 @@
  */
 int reset_catchments(void)
 {
-  int r, c, i;
-  
-    for (r = 0; r < nrows; ++r) {
-	for (c = 0; c < ncols; ++c) {
-	   streams[r][c] = 0;
+    int r, c, i;
+
+    for (r = 0; r < nrows; r++) {
+	for (c = 0; c < ncols; c++) {
+	    streams[r][c] = 0;
 	}
     }
-    
-  if (in_streams) {
-		for (i = 0; i < outlets_num; ++i) 
-	streams[outlets[i].r][outlets[i].c] = outlets[i].val;
-		}
+
+    if (in_streams) {
+	for (i = 0; i < outlets_num; ++i)
+	    streams[outlets[i].r][outlets[i].c] = outlets[i].val;
+    }
     return 0;
 }
 
@@ -126,42 +129,47 @@
  */
 int fill_catchments(OUTLET outlet)
 {
-
     int nextr[9] = { 0, -1, -1, -1, 0, 1, 1, 1, 0 };
     int nextc[9] = { 0, 1, 0, -1, -1, -1, 0, 1, 1 };
-
+    int next_r, next_c;
     int r, c, val, i, j;
     POINT n_cell;
 
     tail = 0;
     head = -1;
+    has_point = 0;
     r = outlet.r;
     c = outlet.c;
     val = outlet.val;
 
+    G_debug(1, "processing outlet at row %d col %d", r, c);
+
     streams[r][c] = val;
 
     while (tail != head) {
-	for (i = 1; i < 9; ++i) {
-	    if (r + nextr[i] < 0 || r + nextr[i] > (nrows - 1) ||
-		c + nextc[i] < 0 || c + nextc[i] > (ncols - 1))
-		continue;	/* border */
-	    j = (i + 4) > 8 ? i - 4 : i + 4;
-	    if (dirs[r + nextr[i]][c + nextc[i]] == j) {	/* countributing cell */
+	for (i = 1; i < 9; i++) {
+	    next_r = r + nextr[i];
+	    next_c = c + nextc[i];
 
-		if (streams[r + nextr[i]][c + nextc[i]] > 0)
-		    continue;	/* other outlet */
+	    if (next_r >= 0 && next_r < nrows && next_c >= 0 && next_c < ncols) {
 
-		streams[r + nextr[i]][c + nextc[i]] = val;
-		n_cell.r = (r + nextr[i]);
-		n_cell.c = (c + nextc[i]);
-		fifo_insert(n_cell);
+		j = (i + 4) > 8 ? i - 4 : i + 4;
+
+		/* countributing cell, not yet assigned to a basin */
+		if (dirs[next_r][next_c] == j && streams[next_r][next_c] == 0) {
+
+		    streams[next_r][next_c] = val;
+		    n_cell.r = next_r;
+		    n_cell.c = next_c;
+		    fifo_insert(n_cell);
+		}
 	    }
 	}			/* end for i... */
 
 	n_cell = fifo_return_del();
 	r = n_cell.r;
 	c = n_cell.c;
+
     }
 
     return 0;
@@ -170,15 +178,26 @@
 /* fifo functions */
 int fifo_insert(POINT point)
 {
+    if (has_point && tail == head + 1)
+	G_fatal_error("fifo queue: circular buffer too small");
+	
     fifo_outlet[tail++] = point;
-    if (tail > fifo_max)
+    has_point = 1;
+    if (tail > fifo_max) {
+	G_debug(1, "tail > fifo_max");
 	tail = 0;
+    }
     return 0;
 }
 
 POINT fifo_return_del(void)
 {
-    if (head > fifo_max)
+    if (head >= fifo_max) {
+	G_debug(1, "head >= fifo_max");
 	head = -1;
-    return fifo_outlet[++head];
+    }
+    if (++head == tail)
+	has_point = 0;
+	
+    return fifo_outlet[head];
 }

Modified: grass-addons/raster/r.stream.basins/global.h
===================================================================
--- grass-addons/raster/r.stream.basins/global.h	2010-06-03 11:30:25 UTC (rev 42455)
+++ grass-addons/raster/r.stream.basins/global.h	2010-06-03 11:30:57 UTC (rev 42456)
@@ -7,7 +7,7 @@
 #include <grass/glocale.h>
 
 
-					/* define */
+/* define */
 
 /*define directions for code simplicity
 
@@ -20,22 +20,22 @@
 
 #define POINT struct points	
 POINT {
-	int r, c;
-	};
+    int r, c;
+};
 	
 #define OUTLET struct outs
 OUTLET { 
-	int r, c;
-	int val;
-	};	
+    int r, c;
+    int val;
+};	
 	
-					/* functions.c */ 
+/* functions.c */ 
 
 /* io.c */
 int open_raster(char *mapname);
 int create_maps(void);
 int max_link(void);
-int write_chatchment(void);
+int write_catchment(void);
 int set_null(void);
 int process_coors (char **answers);
 int process_cats (char **answers);
@@ -65,15 +65,14 @@
 
 GLOBAL int nrows, ncols; 
 
-POINT *fifo_outlet;
-int tail, head;
-int outlets_num;
-int fifo_max;
+GLOBAL POINT *fifo_outlet;
+GLOBAL int outlets_num;
+GLOBAL int fifo_max;
 	
 GLOBAL int out; /* number of strahler and horton outlets: index */
 GLOBAL int *categories;
 
-OUTLET *outlets;
+GLOBAL OUTLET *outlets;
 
 
 GLOBAL struct History history;	/* holds meta-data (title, comments,..) */

Modified: grass-addons/raster/r.stream.basins/io.c
===================================================================
--- grass-addons/raster/r.stream.basins/io.c	2010-06-03 11:30:25 UTC (rev 42455)
+++ grass-addons/raster/r.stream.basins/io.c	2010-06-03 11:30:57 UTC (rev 42456)
@@ -21,8 +21,9 @@
 	G_fatal_error("Unable to read file header of <%s>", mapname);
 
     if (window.ew_res != cellhd.ew_res || window.ns_res != cellhd.ns_res)
-	G_fatal_error("Region resolution and map %s resolution differs. Run g.region rast=%s to set proper resolution",
-		      mapname, mapname);
+	G_fatal_error
+	    ("Region resolution and map %s resolution differs. Run g.region rast=%s to set proper resolution",
+	     mapname, mapname);
 
     return fd;
 }
@@ -31,68 +32,65 @@
 {
     int r, c;
     int in_dir_fd, in_stm_fd;	/* input file descriptors: indir_fd - direction.... etc */
-
     CELL *r_dirs, *r_streams;
 
-		G_message("Reading maps...");
-		
-		
+    G_message("Reading maps...");
 
     in_dir_fd = open_raster(in_dirs);
     r_dirs = (CELL *) G_malloc(sizeof(CELL) * ncols);
     dirs = (CELL **) G_malloc(sizeof(CELL *) * nrows);
 
     r_streams = (CELL *) G_malloc(sizeof(CELL) * ncols);
-		streams = (CELL **) G_malloc(sizeof(CELL *) * nrows);
-    
-			if (in_streams) { 
-    
-    in_stm_fd = open_raster(in_streams);
-		
-			for (r = 0; r < nrows; ++r) {
-		G_percent(r, nrows, 2);
-		streams[r] = (CELL *) G_malloc(sizeof(CELL) * ncols);
+    streams = (CELL **) G_malloc(sizeof(CELL *) * nrows);
 
+    if (in_streams) {
 
-		if (G_get_c_raster_row(in_stm_fd, r_streams, r) < 0) {
-	    G_close_cell(in_stm_fd);
-	    G_fatal_error("Unable to read raster maps at row <%d>", r);
-		}
+	in_stm_fd = open_raster(in_streams);
 
-		for (c = 0; c < ncols; ++c) {
-	    if (G_is_c_null_value(&r_streams[c]))
-		streams[r][c] = 0;
-	    else 
-		streams[r][c] = r_streams[c];
-		}
-			}
-		G_free(r_streams);		
+	for (r = 0; r < nrows; ++r) {
+	    G_percent(r, nrows, 2);
+	    streams[r] = (CELL *) G_malloc(sizeof(CELL) * ncols);
+
+
+	    if (G_get_c_raster_row(in_stm_fd, r_streams, r) < 0) {
 		G_close_cell(in_stm_fd);
-		G_percent(r, nrows, 2);		
-				}	/* end if streams */
+		G_fatal_error("Unable to read raster maps at row <%d>", r);
+	    }
 
+	    for (c = 0; c < ncols; ++c) {
+		if (G_is_c_null_value(&r_streams[c]))
+		    streams[r][c] = 0;
+		else
+		    streams[r][c] = r_streams[c];
+	    }
+	}
+	G_free(r_streams);
+	G_close_cell(in_stm_fd);
+	G_percent(r, nrows, 2);
+    }				/* end if streams */
+
     for (r = 0; r < nrows; ++r) {
-			G_percent(r, nrows, 2);
+	G_percent(r, nrows, 2);
 
-			dirs[r] = (CELL *) G_malloc(sizeof(CELL) * ncols);
-				if (!in_streams)
-			streams[r] =(CELL *) G_malloc(sizeof(CELL) * ncols);
+	dirs[r] = (CELL *) G_malloc(sizeof(CELL) * ncols);
+	if (!in_streams)
+	    streams[r] = (CELL *) G_malloc(sizeof(CELL) * ncols);
 
-			if (G_get_c_raster_row(in_dir_fd, r_dirs, r) < 0) {
-				G_close_cell(in_dir_fd);
-				G_fatal_error("Unable to read raster maps at row <%d>", r);
-			}
+	if (G_get_c_raster_row(in_dir_fd, r_dirs, r) < 0) {
+	    G_close_cell(in_dir_fd);
+	    G_fatal_error("Unable to read raster maps at row <%d>", r);
+	}
 
-			for (c = 0; c < ncols; ++c) {
-				if (G_is_c_null_value(&r_dirs[c]))
-					dirs[r][c] = 0;
-				else 
-			dirs[r][c] = r_dirs[c];
-			}
+	for (c = 0; c < ncols; ++c) {
+	    if (G_is_c_null_value(&r_dirs[c]))
+		dirs[r][c] = 0;
+	    else
+		dirs[r][c] = r_dirs[c];
+	}
     }				/*end for r */
 
     G_free(r_dirs);
-		G_close_cell(in_dir_fd);
+    G_close_cell(in_dir_fd);
     G_percent(r, nrows, 2);
     return 0;
 }				/* end create maps */
@@ -111,7 +109,7 @@
 }				/* end_max_link       */
 
 
-int write_chatchment(void)
+int write_catchment(void)
 {
     int r;
     int fdo = 0;
@@ -121,6 +119,7 @@
 
     for (r = 0; r < nrows; ++r)
 	G_put_c_raster_row(fdo, streams[r]);
+
     G_close_cell(fdo);
     G_short_history(name_catchments, "raster", &history);
     G_write_history(name_catchments, &history);
@@ -136,6 +135,9 @@
 
     for (r = 0; r < nrows; ++r) {
 	for (c = 0; c < ncols; ++c) {
+	    if (streams[r][c] < 0)
+		streams[r][c] = 1;
+
 	    if (streams[r][c] == 0)
 		G_set_c_null_value(&streams[r][c], 1);
 	}
@@ -143,104 +145,111 @@
     return 0;
 }
 
-int process_coors (char **answers) {
-	
-	int n;
-	double X,Y;
-	outlets = G_malloc(sizeof(OUTLET));
-	
-		if(!answers)
+int process_coors(char **answers)
+{
+
+    int n, n_outlets;
+    double X, Y;
+
+    if (!answers)
 	return 0;
-	
-	for (n=0; answers[n] != NULL; n+=2) {
-			if(!G_scan_easting(answers[n], &X , G_projection()))
-    G_fatal_error("Wrong coordinate <%s>",answers[n]);    
-      if(!G_scan_northing(answers[n+1], &Y , G_projection()))
-    G_fatal_error("Wrong coordinate <%s>",answers[n+1]);    
+
+    for (n = 0, n_outlets = 0; answers[n] != NULL; n += 2, n_outlets++);
+
+    outlets = (OUTLET *)G_malloc(n_outlets * sizeof(OUTLET));
+
+    for (n = 0, n_outlets = 0; answers[n] != NULL; n += 2, n_outlets++) {
+	if (!G_scan_easting(answers[n], &X, G_projection()))
+	    G_fatal_error("Wrong coordinate <%s>", answers[n]);
+	if (!answers[n + 1])
+	    G_fatal_error("Missing north coordinate for east %g", X);
+	if (!G_scan_northing(answers[n + 1], &Y, G_projection()))
+	    G_fatal_error("Wrong coordinate <%s>", answers[n + 1]);
+
+	if (X < window.west || X > window.east || Y < window.south ||
+	    Y > window.north)
+	    G_fatal_error("Coordinates outside window");
+
+	outlets[n_outlets].r = (window.north - Y) / window.ns_res;
+	outlets[n_outlets].c = (X - window.west) / window.ew_res;
+	outlets[n_outlets].val = n_outlets + 1;
     }
 
-		if (X < window.west || X > window.east || Y < window.south || Y > window.north) 
-	G_fatal_error("Coordinates outside window");
-	
-	outlets->r = (window.north - Y) / window.ns_res;
-	outlets->c = (X - window.west) / window.ew_res;
-	outlets->val=1;
-	
-	return 1; /* not an success */
+    return n_outlets;
 }
 
-int process_cats (char **answers) {
-		
-	int i;
-	int link_max=max_link();
-	int cat;
+int process_cats(char **answers)
+{
+    int i;
+    int link_max = max_link();
+    int cat;
 
-		if(!answers)
-	return;
-	
-	categories = G_malloc((link_max+1)* sizeof(int));
-	
-	for (i=0;i<(link_max+1);++i)
-		categories[i]=-1;
-	
-	
-	for (i = 0; answers[i] != NULL; ++i) {
-		cat=atoi(answers[i]);
-			if (cat<1 || cat>link_max)
-		G_fatal_error("Stream categories must be > 0 and < maximum stream category");
-		categories[cat]=cat;
-	}
-	
-	return 0; /* success */
+    if (!answers)
+	return 1;
+
+    categories = G_malloc((link_max + 1) * sizeof(int));
+
+    for (i = 0; i < (link_max + 1); ++i)
+	categories[i] = -1;
+
+
+    for (i = 0; answers[i] != NULL; ++i) {
+	cat = atoi(answers[i]);
+	if (cat < 1 || cat > link_max)
+	    G_fatal_error
+		("Stream categories must be > 0 and < maximum stream category");
+	categories[cat] = cat;
+    }
+
+    return 0;			/* success */
 }
 
 
-int process_vector (char *in_point) {
-	char *mapset;
-	struct Map_info Map;
-	struct bound_box box;
-  int num_point=0;
-  int type, i, cat;
-	
-	struct line_pnts* sites;
-  struct line_cats* cats;
-  
-  sites = Vect_new_line_struct();
-  cats = Vect_new_cats_struct();
-  
-	
-	mapset = G_find_vector2(in_point, "");
-		if (mapset == NULL)
+int process_vector(char *in_point)
+{
+    char *mapset;
+    struct Map_info Map;
+    struct bound_box box;
+    int num_point = 0;
+    int type, i, cat;
+    struct line_pnts *sites;
+    struct line_cats *cats;
+
+    sites = Vect_new_line_struct();
+    cats = Vect_new_cats_struct();
+
+    mapset = G_find_vector2(in_point, "");
+    if (mapset == NULL)
 	G_fatal_error(_("Vector map <%s> not found"), in_point);
-	
-	  if (Vect_open_old(&Map, in_point, mapset) < 0)
+
+    if (Vect_open_old(&Map, in_point, mapset) < 0)
 	G_fatal_error("Cannot open vector map <%s>", in_point);
-	
-	Vect_region_box(&window, &box);
-	
-	while (type=Vect_read_next_line(&Map, sites, cats) > -1) {
-			if (type != GV_POINT)
-	  continue;
-			if (Vect_point_in_box(sites->x[0], sites->y[0], sites->z[0], &box))
-		num_point++;
-	}
-	
-	outlets = (OUTLET *)G_malloc(num_point * sizeof(OUTLET));
-	
-	for (i=0;i<num_point;++i) {
-		
-		type = Vect_read_line(&Map, sites, cats,i+1);
-			if (type != GV_POINT)
-	  continue;
-	  
-			if (!Vect_point_in_box(sites->x[0], sites->y[0], sites->z[0], &box))
-		continue;	
-	  
-	  Vect_cat_get(cats, 1, &cat);
-		
-		outlets[i].r=(int)G_northing_to_row(sites->y[0], &window);
-		outlets[i].c=(int)G_easting_to_col(sites->x[0], &window);
-		outlets[i].val=cat;
-	}
-	return num_point;
+
+    Vect_region_box(&window, &box);
+
+    while ((type = Vect_read_next_line(&Map, sites, cats)) > -1) {
+	if (type != GV_POINT)
+	    continue;
+	if (Vect_point_in_box(sites->x[0], sites->y[0], sites->z[0], &box))
+	    num_point++;
+    }
+
+    outlets = (OUTLET *) G_malloc(num_point * sizeof(OUTLET));
+
+    for (i = 0; i < num_point; ++i) {
+
+	type = Vect_read_line(&Map, sites, cats, i + 1);
+	if (type != GV_POINT)
+	    continue;
+
+	if (!Vect_point_in_box(sites->x[0], sites->y[0], sites->z[0], &box))
+	    continue;
+
+	Vect_cat_get(cats, 1, &cat);
+
+	outlets[i].r = (int)G_northing_to_row(sites->y[0], &window);
+	outlets[i].c = (int)G_easting_to_col(sites->x[0], &window);
+	outlets[i].val = cat;
+    }
+    return num_point;
 }

Modified: grass-addons/raster/r.stream.basins/main.c
===================================================================
--- grass-addons/raster/r.stream.basins/main.c	2010-06-03 11:30:25 UTC (rev 42455)
+++ grass-addons/raster/r.stream.basins/main.c	2010-06-03 11:30:57 UTC (rev 42456)
@@ -29,15 +29,11 @@
  */
 int main(int argc, char *argv[])
 {
-
     struct GModule *module;	/* GRASS module for parsing arguments */
-    struct Option *in_dir_opt, *in_coor_opt, *in_stm_opt, *in_stm_cat_opt, * in_point_opt, *out_opt;	/* options */
+    struct Option *in_dir_opt, *in_coor_opt, *in_stm_opt, *in_stm_cat_opt, *in_point_opt, *out_opt;	/* options */
     struct Flag *out_back, *out_cat, *out_last;	/* flags */
+    int b_test = 0;		/* test which option have been choosed: like chmod */
 
-    
-    int b_test=0; /* test which option have been choosed: like chmod */
-    
-
     /* initialize GIS environment */
     G_gisinit(argv[0]);		/* reads grass env, stores program name to G_program_name() */
 
@@ -45,15 +41,15 @@
     module = G_define_module();
     module->keywords = _("stream, order, catchments");
     module->description = _("Calculate basins according user' input");
-	 
+
     in_dir_opt = G_define_option();	/* input directon file */
     in_dir_opt->key = "dir";
     in_dir_opt->type = TYPE_STRING;
     in_dir_opt->required = YES;
     in_dir_opt->gisprompt = "old,cell,raster";
     in_dir_opt->description = "Name of flow direction input map";
-    
-	  in_coor_opt = G_define_option();	/* input coordinates de outlet */
+
+    in_coor_opt = G_define_option();	/* input coordinates de outlet */
     in_coor_opt->key = "coors";
     in_coor_opt->type = TYPE_STRING;
     in_coor_opt->key_desc = "x,y";
@@ -62,14 +58,13 @@
     in_coor_opt->multiple = YES;
     in_coor_opt->description = "Basin's outlet's coordinates: E,N";
 
-
-	  in_stm_opt = G_define_option();	/* input stream mask file - optional */
+    in_stm_opt = G_define_option();	/* input stream mask file - optional */
     in_stm_opt->key = "stream";
     in_stm_opt->type = TYPE_STRING;
     in_stm_opt->required = NO;
     in_stm_opt->gisprompt = "old,cell,raster";
     in_stm_opt->description = "Name of stream mask input map";
-    
+
     in_stm_cat_opt = G_define_option();	/* input stream mask file - optional */
     in_stm_cat_opt->key = "cats";
     in_stm_cat_opt->type = TYPE_STRING;
@@ -95,7 +90,6 @@
     out_opt->gisprompt = "new,cell,raster";
     out_opt->description = "Output basin map";
 
-
     /* Define the different flags */
     out_back = G_define_flag();
     out_back->key = 'z';
@@ -115,19 +109,19 @@
     if (G_parser(argc, argv))	/* parser */
 	exit(EXIT_FAILURE);
 
-		if (!in_coor_opt->answers && !in_stm_opt->answer && !in_point_opt->answer)
-	G_fatal_error("Basin's outlet definition is required");	
+    if (!in_coor_opt->answers && !in_stm_opt->answer && !in_point_opt->answer)
+	G_fatal_error("Basin's outlet definition is required");
 
-		if (in_coor_opt->answers)
+    if (in_coor_opt->answers)
 	b_test += 1;
-		if (in_stm_opt->answer)
+    if (in_stm_opt->answer)
 	b_test += 2;
-		if (in_point_opt->answer)
-	b_test += 4;		
-	
-	if (b_test != 1 && b_test != 2 && b_test != 4)
-	G_fatal_error("Only one outlet definition is allowed");	
+    if (in_point_opt->answer)
+	b_test += 4;
 
+    if (b_test != 1 && b_test != 2 && b_test != 4)
+	G_fatal_error("Only one outlet definition is allowed");
+
     /* stores input options to variables */
     in_dirs = in_dir_opt->answer;
     in_streams = in_stm_opt->answer;
@@ -144,41 +138,41 @@
     nrows = G_window_rows();
     ncols = G_window_cols();
     create_maps();
-    
-  switch (b_test) {
-		case 1:
-			G_message("Calculate basins using coordinates...");
-			process_coors (in_coor_opt->answers);
-			outlets_num=1;
-		break;
-			
-		case 2:
-			G_message("Calculate basins using streams...");
-			categories=NULL;
-			process_cats (in_stm_cat_opt->answers);
-			find_outlets();
-		break;
-			
-		case 4:
-			G_message("Calculate basins using point file...");
-			outlets_num=process_vector(in_point);
-		break;
-		}
-		
-	 { 
+
+    switch (b_test) {
+    case 1:
+	G_message("Calculate basins using coordinates...");
+	outlets_num = process_coors(in_coor_opt->answers);
+	break;
+
+    case 2:
+	G_message("Calculate basins using streams...");
+	categories = NULL;
+	process_cats(in_stm_cat_opt->answers);
+	find_outlets();
+	break;
+
+    case 4:
+	G_message("Calculate basins using point file...");
+	outlets_num = process_vector(in_point);
+	break;
+    }
+
+    {
 	int j;
+
 	reset_catchments();
 	fifo_max = 4 * (nrows + ncols);
 	fifo_outlet = (POINT *) G_malloc((fifo_max + 1) * sizeof(POINT));
-	
+
 	for (j = 0; j < outlets_num; ++j) {
-	  fill_catchments(outlets[j]);
+	    fill_catchments(outlets[j]);
 	}
 	G_free(fifo_outlet);
 	if (!zeros)
 	    set_null();
-	write_chatchment();
-    } 
-	
+	write_catchment();
+    }
+
     exit(EXIT_SUCCESS);
 }



More information about the grass-commit mailing list