[GRASS-SVN] r71993 - in grass/trunk: raster scripts scripts/r.drain

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 28 13:33:22 PST 2017


Author: mmetz
Date: 2017-12-28 13:33:22 -0800 (Thu, 28 Dec 2017)
New Revision: 71993

Added:
   grass/trunk/scripts/r.drain/
Removed:
   grass/trunk/scripts/r.drain/filldir.c
   grass/trunk/scripts/r.drain/local.h
   grass/trunk/scripts/r.drain/main.c
   grass/trunk/scripts/r.drain/resolve.c
   grass/trunk/scripts/r.drain/tinf.c
   grass/trunk/scripts/r.drain/tinf.h
Modified:
   grass/trunk/raster/Makefile
   grass/trunk/scripts/Makefile
   grass/trunk/scripts/r.drain/Makefile
Log:
r.drain: convert to script calling r.path + r.fill.dir if no directions are provided

Modified: grass/trunk/raster/Makefile
===================================================================
--- grass/trunk/raster/Makefile	2017-12-28 21:27:36 UTC (rev 71992)
+++ grass/trunk/raster/Makefile	2017-12-28 21:33:22 UTC (rev 71993)
@@ -18,7 +18,6 @@
 	r.cross \
 	r.describe \
 	r.distance \
-	r.drain \
 	r.external \
 	r.external.out \
 	r.fill.dir \

Modified: grass/trunk/scripts/Makefile
===================================================================
--- grass/trunk/scripts/Makefile	2017-12-28 21:27:36 UTC (rev 71992)
+++ grass/trunk/scripts/Makefile	2017-12-28 21:33:22 UTC (rev 71993)
@@ -33,9 +33,10 @@
 	r.blend \
 	r.buffer.lowmem \
 	r.colors.stddev \
+	r.drain \
 	r.fillnulls \
 	r.grow \
-    r.import \
+	r.import \
 	r.in.aster \
 	r.in.srtm \
 	r.in.wms \

Modified: grass/trunk/scripts/r.drain/Makefile
===================================================================
--- grass/trunk/raster/r.drain/Makefile	2017-12-20 22:06:06 UTC (rev 71962)
+++ grass/trunk/scripts/r.drain/Makefile	2017-12-28 21:33:22 UTC (rev 71993)
@@ -2,11 +2,6 @@
 
 PGM = r.drain
 
-LIBES = $(VECTORLIB) $(RASTERLIB) $(GISLIB)
-DEPENDENCIES = $(VECTORDEP) $(RASTERDEP) $(GISDEP)
-EXTRA_INC = $(VECT_INC)
-EXTRA_CFLAGS = $(VECT_CFLAGS)
+include $(MODULE_TOPDIR)/include/Make/Script.make
 
-include $(MODULE_TOPDIR)/include/Make/Module.make
-
-default: cmd
+default: script
\ No newline at end of file

Deleted: grass/trunk/scripts/r.drain/filldir.c
===================================================================
--- grass/trunk/raster/r.drain/filldir.c	2017-12-20 22:06:06 UTC (rev 71962)
+++ grass/trunk/scripts/r.drain/filldir.c	2017-12-28 21:33:22 UTC (rev 71993)
@@ -1,129 +0,0 @@
-#include <grass/config.h>
-#include <sys/types.h>
-#include <stdlib.h>
-#include <math.h>
-#include <limits.h>
-#include <float.h>
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "tinf.h"
-#include "local.h"
-
-/* get the slope between two cells and return a slope direction */
-void check(CELL newdir, CELL * dir, void *center, void *edge, double cnst,
-	   double *oldslope)
-{
-    double newslope;
-
-    /* never discharge to a null boundary */
-    if (is_null(edge))
-	return;
-
-    newslope = slope(center, edge, cnst);
-    if (newslope == *oldslope) {
-	*dir += newdir;
-    }
-    else if (newslope > *oldslope) {
-	*oldslope = newslope;
-	*dir = newdir;
-    }
-
-    return;
-
-}
-
-/* determine the flow direction at each cell on one row */
-void build_one_row(int i, int nl, int ns, struct band3 *bnd, CELL * dir,
-		   struct metrics m)
-{
-    int j, inc;
-    off_t offset;
-    CELL sdir;
-    double slope;
-    char *center;
-    char *edge;
-
-    inc = bpe();
-
-    for (j = 0; j < ns; j += 1) {
-	offset = j * bpe();
-	center = bnd->b[1] + offset;
-	if (is_null(center)) {
-	    Rast_set_c_null_value(dir + j, 1);
-	    continue;
-	}
-
-	sdir = 0;
-	/* slope=HUGE; */
-	slope = HUGE_VAL;
-	if (i == 0) {
-	    sdir = 128;
-	}
-	else if (i == nl - 1) {
-	    sdir = 8;
-	}
-	else if (j == 0) {
-	    sdir = 32;
-	}
-	else if (j == ns - 1) {
-	    sdir = 2;
-	}
-	else {
-	    /* slope=-HUGE; */
-	    slope = -HUGE_VAL;
-
-	    /* check one row back */
-	    edge = bnd->b[0] + offset;
-	    check(64, &sdir, center, edge - inc, m.diag_res, &slope);
-	    check(128, &sdir, center, edge, m.ns_res, &slope);
-	    check(1, &sdir, center, edge + inc, m.diag_res, &slope);
-
-	    /* check this row */
-	    check(32, &sdir, center, center - inc, m.ew_res, &slope);
-	    check(2, &sdir, center, center + inc, m.ew_res, &slope);
-
-	    /* check one row forward */
-	    edge = bnd->b[2] + offset;
-	    check(16, &sdir, center, edge - inc, m.diag_res, &slope);
-	    check(8, &sdir, center, edge, m.ns_res, &slope);
-	    check(4, &sdir, center, edge + inc, m.diag_res, &slope);
-	}
-
-	if (slope == 0.)
-	    sdir = -sdir;
-	else if (slope < 0.)
-	    sdir = -256;
-	dir[j] = sdir;
-    }
-    return;
-}
-
-void filldir(int fe, int fd, int nl, struct band3 *bnd, struct metrics *m)
-{
-    int i, bufsz;  /* use off_t bufsz for large files ? MM */
-    CELL *dir;
-
-    /* determine the flow direction in each cell.  On outer rows and columns
-     * the flow direction is always directly out of the map */
-
-    dir = G_calloc(bnd->ns, sizeof(CELL));
-    bufsz = bnd->ns * sizeof(CELL);
-
-    lseek(fe, 0, SEEK_SET);
-    lseek(fd, 0, SEEK_SET);
-    advance_band3(fe, bnd);
-    for (i = 0; i < nl; i++) {
-        G_percent(i, nl, 5);
-	advance_band3(fe, bnd);
-	build_one_row(i, nl, bnd->ns, bnd, dir, m[i]);
-	write(fd, dir, bufsz);
-    }
-    G_percent(1, 1, 1);
-    advance_band3(fe, bnd);
-    build_one_row(nl - 1, nl, bnd->ns, bnd, dir, m[nl - 1]);
-    write(fd, dir, bufsz);
-
-    G_free(dir);
-
-    return;
-}

Deleted: grass/trunk/scripts/r.drain/local.h
===================================================================
--- grass/trunk/raster/r.drain/local.h	2017-12-20 22:06:06 UTC (rev 71962)
+++ grass/trunk/scripts/r.drain/local.h	2017-12-28 21:33:22 UTC (rev 71993)
@@ -1,10 +0,0 @@
-struct metrics
-{
-    double ew_res, ns_res, diag_res;
-};
-
-void filldir(int, int, int, struct band3 *, struct metrics *);
-void resolve(int, int, struct band3 *);
-int dopolys(int, int, int, int);
-void wtrshed(int, int, int, int, int);
-void ppupdate(int, int, int, int, struct band3 *, struct band3 *);

Deleted: grass/trunk/scripts/r.drain/main.c
===================================================================
--- grass/trunk/raster/r.drain/main.c	2017-12-20 22:06:06 UTC (rev 71962)
+++ grass/trunk/scripts/r.drain/main.c	2017-12-28 21:33:22 UTC (rev 71993)
@@ -1,791 +0,0 @@
-/****************************************************************************
- *
- * MODULE:       r.drain
- *               
- * AUTHOR(S):    Kewan Q. Khawaja <kewan techlogix.com>
- *               Update to FP (2000): Pierre de Mouveaux <pmx at audiovu.com> <pmx at free.fr>
- *               bugfix in FCELL, DCELL: Markus Neteler 12/2000
- *               Rewritten by Roger Miller 7/2001 based on subroutines from
- *               r.fill.dir and on the original r.drain.
- *               24 July 2004: WebValley 2004, error checking and vector points added by
- *               Matteo Franchi          Liceo Leonardo Da Vinci Trento
- *               Roberto Flor            ITC-irst
- *               New code added by Colin Nielsen <colin.nielsen at gmail dot com> *
- *               to use movement direction surface from r.walk and r.cost, and to 
- *               output vector paths 2/2009
- *               
- * PURPOSE:      This is the main program for tracing out the path that a
- *               drop of water would take if released at a certain location
- *               on an input elevation map.  
- * COPYRIGHT:    (C) 2000,2009 by the GRASS Development Team
- *
- *               This program is free software under the GNU General Public
- *               License (>=v2). Read the file COPYING that comes with GRASS
- *               for details.
- *
- *****************************************************************************/
-
-#include <grass/config.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
-#include <float.h>
-
-/* for using the "open" statement */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-/* for using the close statement */
-#include <unistd.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include <grass/glocale.h>
-#include <grass/vector.h>
-
-#define DEBUG
-#include "tinf.h"
-#include "local.h"
-
-/* should probably be updated to a pointer array & malloc/realloc as needed */
-#define POINTS_INCREMENT 1024
-
-/* define a data structure to hold the point data */
-struct point
-{
-    int row;
-    int col;
-    struct point *next;
-    double value;
-};
-
-int main(int argc, char **argv)
-{
-
-    int fe, fd, dir_fd;
-    int i, have_points = 0;
-    int new_id;
-    int nrows, ncols;
-    int *points_row = NULL, *points_col = NULL, npoints;
-    int increment_count;
-    int cell_open(), cell_open_new();
-    int map_id, dir_id;
-    char map_name[GNAME_MAX], new_map_name[GNAME_MAX], dir_name[GNAME_MAX];
-    char *tempfile1, *tempfile2, *tempfile3;
-    struct History history;
-
-    struct Cell_head window;
-    struct Option *opt1, *opt2, *coordopt, *vpointopt, *opt3, *opt4;
-    struct Flag *flag1, *flag2, *flag3, *flag4;
-    struct GModule *module;
-    int in_type;
-    void *in_buf;
-    void *dir_buf;
-    CELL *out_buf;
-    struct band3 bnd, bndC;
-    struct metrics *m = NULL;
-
-    struct point *list;
-    struct point *thispoint;
-    int ival, start_row, start_col, mode;
-    off_t bsz;
-    int costmode = 0;
-    double east, north, val;
-    struct point *drain(int, struct point *, int, int);
-    struct point *drain_cost(int, struct point *, int, int);
-    int bsort(int, struct point *);
-
-    struct line_pnts *Points;
-    struct line_cats *Cats;
-    struct Map_info vout;
-    int cat;
-    double x, y;
-
-    G_gisinit(argv[0]);
-
-    module = G_define_module();
-    G_add_keyword(_("raster"));
-    G_add_keyword(_("hydrology"));
-    G_add_keyword(_("cost surface"));
-    module->description =
-	_("Traces a flow through an elevation model or cost surface on a raster map.");
-
-    opt1 = G_define_standard_option(G_OPT_R_INPUT);
-    opt1->description = _("Name of input elevation or cost surface raster map");
-    
-    opt3 = G_define_standard_option(G_OPT_R_INPUT);
-    opt3->key = "direction";
-    opt3->label =
-	_("Name of input movement direction map associated with the cost surface");
-    opt3->description =
-	_("Direction in degrees CCW from east");
-    opt3->required = NO;
-    opt3->guisection = _("Cost surface");
-
-    opt2 = G_define_standard_option(G_OPT_R_OUTPUT);
-    
-    opt4 = G_define_standard_option(G_OPT_V_OUTPUT);
-    opt4->key = "drain";
-    opt4->required = NO;
-    opt4->label =
-        _("Name for output drain vector map");
-    opt4->description = _("Recommended for cost surface made using knight's move");
-    
-    coordopt = G_define_standard_option(G_OPT_M_COORDS);
-    coordopt->key = "start_coordinates";
-    coordopt->description = _("Coordinates of starting point(s) (E,N)");
-    coordopt->guisection = _("Start");
-
-    vpointopt = G_define_standard_option(G_OPT_V_INPUTS);
-    vpointopt->key = "start_points";
-    vpointopt->required = NO;
-    vpointopt->label = _("Name of starting vector points map(s)");
-    vpointopt->description = NULL;
-    vpointopt->guisection = _("Start");
-
-    flag1 = G_define_flag();
-    flag1->key = 'c';
-    flag1->description = _("Copy input cell values on output");
-    flag1->guisection = _("Path settings");
-
-    flag2 = G_define_flag();
-    flag2->key = 'a';
-    flag2->description = _("Accumulate input values along the path");
-    flag2->guisection = _("Path settings");
-
-    flag3 = G_define_flag();
-    flag3->key = 'n';
-    flag3->description = _("Count cell numbers along the path");
-    flag3->guisection = _("Path settings");
-
-    flag4 = G_define_flag();
-    flag4->key = 'd';
-    flag4->description =
-	_("The input raster map is a cost surface (direction surface must also be specified)");
-    flag4->guisection = _("Cost surface");
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-
-    strcpy(map_name, opt1->answer);
-    strcpy(new_map_name, opt2->answer);
-
-    if (flag4->answer) {
-	costmode = 1;
-	G_verbose_message(_("Directional drain selected... checking for direction raster map"));
-    }
-    else {
-	G_verbose_message(_("Surface/Hydrology drain selected"));
-    }
-
-    if (costmode == 1) {
-	if (!opt3->answer) {
-	    G_fatal_error(_("Direction raster map <%s> not specified, if direction flag is on, "
-                            "a direction raster must be given"), opt3->key);
-	}
-	strcpy(dir_name, opt3->answer);
-    }
-    if (costmode == 0) {
-	if (opt3->answer) {
-	    G_fatal_error(_("Direction raster map <%s> should not be specified for Surface/Hydrology drains"),
-			  opt3->answer);
-	}
-    }
-
-    if (opt4->answer) {
-	if (0 > Vect_open_new(&vout, opt4->answer, 0)) {
-            G_fatal_error(_("Unable to create vector map <%s>"),
-			  opt4->answer);
-	}
-	Vect_hist_command(&vout);
-    }
-    /*      allocate cell buf for the map layer */
-    in_type = Rast_map_type(map_name, "");
-
-    /* set the pointers for multi-typed functions */
-    set_func_pointers(in_type);
-
-    if ((flag1->answer + flag2->answer + flag3->answer) > 1)
-	G_fatal_error(_("Specify just one of the -c, -a and -n flags"));
-
-    mode = 0;
-    if (flag1->answer)
-	mode = 1;
-    if (flag2->answer)
-	mode = 2;
-    if (flag3->answer)
-	mode = 3;
-
-    /* get the window information  */
-    G_get_window(&window);
-    nrows = Rast_window_rows();
-    ncols = Rast_window_cols();
-
-    /* calculate true cell resolution */
-    m = (struct metrics *)G_malloc(nrows * sizeof(struct metrics));    
-    points_row = (int*)G_calloc(POINTS_INCREMENT, sizeof(int));
-    points_col = (int*)G_calloc(POINTS_INCREMENT, sizeof(int));
-    
-    increment_count = 1;
-    npoints = 0;
-    if (coordopt->answer) {
-	for (i = 0; coordopt->answers[i] != NULL; i += 2) {
-	    G_scan_easting(coordopt->answers[i], &east, G_projection());
-	    G_scan_northing(coordopt->answers[i + 1], &north, G_projection());
-	    start_col = (int)Rast_easting_to_col(east, &window);
-	    start_row = (int)Rast_northing_to_row(north, &window);
-
-	    if (start_row < 0 || start_row > nrows ||
-		start_col < 0 || start_col > ncols) {
-		G_warning(_("Starting point %d is outside the current region"),
-			  i + 1);
-		continue;
-	    }
-	    points_row[npoints] = start_row;
-	    points_col[npoints] = start_col;
-	    npoints++;
-	    if (npoints == POINTS_INCREMENT * increment_count)
-	    {
-		increment_count++;
-		points_row = (int*)G_realloc(points_row, POINTS_INCREMENT * increment_count * sizeof(int));
-		points_col = (int*)G_realloc(points_col, POINTS_INCREMENT * increment_count * sizeof(int));
-	    }
-	    have_points = 1;
-	}
-    }
-    if (vpointopt->answers) {
-	for (i = 0; vpointopt->answers[i] != NULL; i++) {
-	    struct Map_info In;
-	    struct bound_box box;
-	    int type;
-
-	    Points = Vect_new_line_struct();
-	    Cats = Vect_new_cats_struct();
-
-	    Vect_set_open_level(1); /* topology not required */
-
-	    if (1 > Vect_open_old(&In, vpointopt->answers[i], ""))
-		G_fatal_error(_("Unable to open vector map <%s>"), vpointopt->answers[i]);
-
-	    G_message(_("Reading vector map <%s> with start points..."),
-                      Vect_get_full_name(&In));
-            
-	    Vect_rewind(&In);
-
-	    Vect_region_box(&window, &box);
-
-	    while (1) {
-		/* register line */
-		type = Vect_read_next_line(&In, Points, Cats);
-
-		/* Note: check for dead lines is not needed, because they are skipped by V1_read_next_line_nat() */
-		if (type == -1) {
-		    G_warning(_("Unable to read vector map"));
-		    continue;
-		}
-		else if (type == -2) {
-		    break;
-		}
-		if (!Vect_point_in_box(Points->x[0], Points->y[0], 0, &box))
-		    continue;
-
-		start_col = (int)Rast_easting_to_col(Points->x[0], &window);
-		start_row = (int)Rast_northing_to_row(Points->y[0], &window);
-
-		/* effectively just a duplicate check to G_site_in_region() ??? */
-		if (start_row < 0 || start_row > nrows || start_col < 0 ||
-		    start_col > ncols)
-		    continue;
-
-		points_row[npoints] = start_row;
-		points_col[npoints] = start_col;
-		npoints++;
-		if (npoints == POINTS_INCREMENT * increment_count)
-		{
-		    increment_count++;
-		    points_row = (int*)G_realloc(points_row, POINTS_INCREMENT * increment_count * sizeof(int));
-		    points_col = (int*)G_realloc(points_col, POINTS_INCREMENT * increment_count * sizeof(int));
-		}
-		have_points = 1;
-	    }
-	    Vect_close(&In);
-
-	    /* only catches maps out of range until something is found, not after */
-	    if (!have_points) {
-		G_warning(_("Starting vector map <%s> contains no points in the current region"),
-			  vpointopt->answers[i]);
-	    }
-	    Vect_destroy_line_struct(Points);
-	    Vect_destroy_cats_struct(Cats);
-	}
-    }
-    if (have_points == 0)
-	G_fatal_error(_("No start/stop point(s) specified"));
-
-    /* determine the drainage paths */
-
-    /* allocate storage for the first point */
-    thispoint = (struct point *)G_malloc(sizeof(struct point));
-    list = thispoint;
-    thispoint->next = NULL;
-
-    G_begin_distance_calculations();
-    {
-	double e1, n1, e2, n2;
-
-	e1 = window.east;
-	n1 = window.north;
-	e2 = e1 + window.ew_res;
-	n2 = n1 - window.ns_res;
-	for (i = 0; i < nrows; i++) {
-	    m[i].ew_res = G_distance(e1, n1, e2, n1);
-	    m[i].ns_res = G_distance(e1, n1, e1, n2);
-	    m[i].diag_res = G_distance(e1, n1, e2, n2);
-	    e2 = e1 + window.ew_res;
-	    n2 = n1 - window.ns_res;
-	}
-    }
-
-    /* buffers for internal use */
-    bndC.ns = ncols;
-    bndC.sz = sizeof(CELL) * ncols;
-    bndC.b[0] = G_calloc(ncols, sizeof(CELL));
-    bndC.b[1] = G_calloc(ncols, sizeof(CELL));
-    bndC.b[2] = G_calloc(ncols, sizeof(CELL));
-
-    /* buffers for external use */
-    bnd.ns = ncols;
-    bnd.sz = ncols * bpe();
-    bnd.b[0] = G_calloc(ncols, bpe());
-    bnd.b[1] = G_calloc(ncols, bpe());
-    bnd.b[2] = G_calloc(ncols, bpe());
-
-    /* an input buffer */
-    in_buf = get_buf();
-
-    /* open the original map and get its file id  */
-    map_id = Rast_open_old(map_name, "");
-
-    /* get some temp files */
-    tempfile1 = G_tempfile();
-    tempfile2 = G_tempfile();
-
-    fe = open(tempfile1, O_RDWR | O_CREAT, 0666);
-    fd = open(tempfile2, O_RDWR | O_CREAT, 0666);
-
-    /* transfer the input map to a temp file */
-    for (i = 0; i < nrows; i++) {
-	get_row(map_id, in_buf, i);
-	write(fe, in_buf, bnd.sz);
-    }
-    Rast_close(map_id);
-
-    if (costmode == 1) {
-	dir_buf = Rast_allocate_d_buf();
-	dir_id = Rast_open_old(dir_name, "");
-	tempfile3 = G_tempfile();
-	dir_fd = open(tempfile3, O_RDWR | O_CREAT, 0666);
-
-	for (i = 0; i < nrows; i++) {
-	    Rast_get_d_row(dir_id, dir_buf, i);
-	    write(dir_fd, dir_buf, ncols * sizeof(DCELL));
-	}
-	Rast_close(dir_id);
-    }
-
-    /* only necessary for non-dir drain */
-    if (costmode == 0) {
-	G_message(_("Calculating flow directions..."));
-
-	/* fill one-cell pits and take a first stab at flow directions */
-	filldir(fe, fd, nrows, &bnd, m);
-
-	/* determine flow directions for more ambiguous cases */
-	resolve(fd, nrows, &bndC);
-    }
-
-    /* free the buffers already used */
-    G_free(bndC.b[0]);
-    G_free(bndC.b[1]);
-    G_free(bndC.b[2]);
-
-    G_free(bnd.b[0]);
-    G_free(bnd.b[1]);
-    G_free(bnd.b[2]);
-
-    /* determine the drainage paths */
-
-    /* repeat for each starting point */
-    for (i = 0; i < npoints; i++) {
-	/* use the flow directions to determine the drainage path
-	 * results are compiled as a linked list of points in downstream order */
-	thispoint->row = points_row[i];
-	thispoint->col = points_col[i];
-	thispoint->next = NULL;
-	/* drain algorithm selection (dir or non-dir) */
-	if (costmode == 0) {
-	    thispoint = drain(fd, thispoint, nrows, ncols);
-	}
-	if (costmode == 1) {
-	    thispoint = drain_cost(dir_fd, thispoint, nrows, ncols);
-	}
-    }
-
-    /* do the output */
-
-    if (mode == 0 || mode == 3) {
-
-	/* Output will be a cell map */
-	/* open a new file and allocate an output buffer */
-	new_id = Rast_open_c_new(new_map_name);
-	out_buf = Rast_allocate_c_buf();
-
-	/* mark each cell */
-	thispoint = list;
-	while (thispoint->next != NULL) {
-	    thispoint->value = 1;
-	    thispoint = thispoint->next;
-	}
-
-	if (mode == 3) {
-	    /* number each cell downstream */
-	    thispoint = list;
-	    ival = 0;
-	    while (thispoint->next != NULL) {
-		if (thispoint->row == INT_MAX) {
-		    ival = 0;
-		    thispoint = thispoint->next;
-		    continue;
-		}
-		thispoint->value += ival;
-		ival = thispoint->value;
-		thispoint = thispoint->next;
-	    }
-	}
-
-	/* build the output map */
-	G_message(_("Writing output raster map..."));
-	for (i = 0; i < nrows; i++) {
-	    G_percent(i, nrows, 2);
-	    Rast_set_c_null_value(out_buf, ncols);
-	    thispoint = list;
-	    while (thispoint->next != NULL) {
-		if (thispoint->row == i)
-		    out_buf[thispoint->col] = (int)thispoint->value;
-		thispoint = thispoint->next;
-	    }
-	    Rast_put_c_row(new_id, out_buf);
-	}
-	G_percent(1, 1, 1);
-    }
-    else {			/* mode = 1 or 2 */
-	/* Output will be of the same type as input */
-	/* open a new file and allocate an output buffer */
-	new_id = Rast_open_new(new_map_name, in_type);
-	out_buf = get_buf();
-	bsz = ncols * bpe();
-
-	/* loop through each point in the list and store the map values */
-	thispoint = list;
-	while (thispoint->next != NULL) {
-	    if (thispoint->row == INT_MAX) {
-		thispoint = thispoint->next;
-		continue;
-	    }
-	    lseek(fe, (off_t) thispoint->row * bsz, SEEK_SET);
-	    read(fe, in_buf, bsz);
-	    memcpy(&thispoint->value, (char *)in_buf + bpe() * thispoint->col,
-		   bpe());
-	    thispoint = thispoint->next;
-	}
-
-	if (mode == 2) {
-	    /* accumulate the input map values downstream */
-	    thispoint = list;
-	    val = 0.;
-	    while (thispoint->next != NULL) {
-		if (thispoint->row == INT_MAX) {
-		    val = 0.;
-		    thispoint = thispoint->next;
-		    continue;
-		}
-		sum(&thispoint->value, &val);
-		memcpy(&val, &thispoint->value, bpe());
-		thispoint = thispoint->next;
-	    }
-	}
-
-	/* build the output map */
-	G_message(_("Writing raster map <%s>..."),
-		  new_map_name);
-	for (i = 0; i < nrows; i++) {
-	    G_percent(i, nrows, 2);
-	    set_null_value(out_buf, ncols);
-	    thispoint = list;
-	    while (thispoint->next != NULL) {
-		if (thispoint->row == i)
-		    memcpy((char *)out_buf + bpe() * thispoint->col,
-			   &(thispoint->value), bpe());
-		thispoint = thispoint->next;
-	    }
-	    put_row(new_id, out_buf);
-	}
-	G_percent(1, 1, 1);
-    }
-
-    /* Output a vector path */
-    if (opt4->answer) {
-	Points = Vect_new_line_struct();
-	Cats = Vect_new_cats_struct();
-	/* Need to modify for multiple paths */
-	thispoint = list;
-	i = 1;
-	while (thispoint->next != NULL) {
-	    if (thispoint->row == INT_MAX) {
-		thispoint = thispoint->next;
-		Vect_cat_set(Cats, 1, i);
-		Vect_write_line(&vout, GV_LINE, Points, Cats);
-		Vect_reset_line(Points);
-		Vect_reset_cats(Cats);
-		i++;
-		continue;
-	    }
-	    if (Vect_cat_get(Cats, 1, &cat) == 0) {
-		Vect_cat_set(Cats, 1, i);
-	    }
-	    /* Need to convert row and col to coordinates 
-	     *      y = cell_head.north - ((double) p->row + 0.5) * cell_head.ns_res;
-	     *  x = cell_head.west + ((double) p->col + 0.5) * cell_head.ew_res;
-	     */
-
-	    x = window.west + ((double)thispoint->col + 0.5) * window.ew_res;
-	    y = window.north - ((double)thispoint->row + 0.5) * window.ns_res;
-	    Vect_append_point(Points, x, y, 0.0);
-	    thispoint = thispoint->next;
-	}			/* End while */
-	Vect_build(&vout);
-	Vect_close(&vout);
-    }
-
-    /* close files and free buffers */
-    Rast_close(new_id);
-
-    Rast_put_cell_title(new_map_name, "Surface flow trace");
-
-    Rast_short_history(new_map_name, "raster", &history);
-    Rast_command_history(&history);
-    Rast_write_history(new_map_name, &history);
-
-    close(fe);
-    close(fd);
-
-    unlink(tempfile1);
-    unlink(tempfile2);
-    G_free(in_buf);
-    G_free(out_buf);
-    if(points_row)
-	G_free(points_row);
-    if(points_col)
-	G_free(points_col);
-
-    if (costmode == 1) {
-	close(dir_fd);
-	unlink(tempfile3);
-	G_free(dir_buf);
-    }
-    
-    exit(EXIT_SUCCESS);
-}
-
-struct point *drain(int fd, struct point *list, int nrow, int ncol)
-{
-    int go = 1, next_row, next_col;
-    CELL direction;
-    CELL *dir;
-
-    dir = Rast_allocate_c_buf();
-    next_row = list->row;
-    next_col = list->col;
-
-    /* begin loop */
-    while (go) {
-
-	/* find flow direction at this point */
-	lseek(fd, (off_t) list->row * ncol * sizeof(CELL), SEEK_SET);
-	read(fd, dir, ncol * sizeof(CELL));
-	direction = *(dir + list->col);
-	go = 0;
-
-	/* identify next downstream cell */
-	if (direction > 0 && direction < 256) {
-
-	    if (direction == 1 || direction == 2 || direction == 4)
-		next_col += 1;
-	    else if (direction == 16 || direction == 32 || direction == 64)
-		next_col -= 1;
-
-	    if (direction == 64 || direction == 128 || direction == 1)
-		next_row -= 1;
-	    else if (direction == 4 || direction == 8 || direction == 16)
-		next_row += 1;
-
-	    if (next_col >= 0 && next_col < ncol
-		&& next_row >= 0 && next_row < nrow) {
-		/* allocate and fill the next point structure */
-		list->next = (struct point *)G_malloc(sizeof(struct point));
-		list = list->next;
-		list->row = next_row;
-		list->col = next_col;
-		go = 1;
-	    }
-	}
-    }				/* end while */
-
-    /* allocate and fill the end-of-path flag */
-    list->next = (struct point *)G_malloc(sizeof(struct point));
-    list = list->next;
-    list->row = INT_MAX;
-
-    /* return a pointer to an empty structure */
-    list->next = (struct point *)G_malloc(sizeof(struct point));
-    list = list->next;
-    list->next = NULL;
-
-    G_free(dir);
-
-    return list;
-}
-
-struct point *drain_cost(int dir_fd, struct point *list, int nrow, int ncol)
-{
-    /*
-     * The idea is that each cell of the direction surface has a value representing
-     * the direction towards the next cell in the path. The direction is read from 
-     * the input raster, and a simple case/switch is used to determine which cell to
-     * read next. This is repeated via a while loop until a null direction is found.
-     */
-
-    int neighbour, next_row, next_col, go = 1;
-    DCELL direction;
-    DCELL *dir_buf;
-
-    dir_buf = Rast_allocate_d_buf();
-
-    next_row = list->row;
-    next_col = list->col;
-
-    while (go) {
-	go = 0;
-	/* Directional algorithm
-	 * 1) read cell direction               
-	 * 2) shift to cell in that direction           
-	 */
-	/* find the direction recorded at row,col */
-	lseek(dir_fd, (off_t) list->row * ncol * sizeof(DCELL), SEEK_SET);
-	read(dir_fd, dir_buf, ncol * sizeof(DCELL));
-	direction = *(dir_buf + list->col);
-	neighbour = direction * 10;
-	if (G_verbose() > 2)
-	    G_message(_("direction read: %lf, neighbour found: %i"),
-		      direction, neighbour);
-	switch (neighbour) {
-	case 225: /* ENE */
-	    next_row = list->row - 1;
-	    next_col = list->col + 2;
-	    break;
-	case 450: /* NE */
-	    next_row = list->row - 1;
-	    next_col = list->col + 1;
-	    break;
-	case 675: /* NNE */
-	    next_row = list->row - 2;
-	    next_col = list->col + 1;
-	    break;
-	case 900: /* N */
-	    next_row = list->row - 1;
-	    next_col = list->col;
-	    break;
-	case 1125: /* NNW */
-	    next_row = list->row - 2;
-	    next_col = list->col - 1;
-	    break;
-	case 1350: /* NW */
-	    next_col = list->col - 1;
-	    next_row = list->row - 1;
-	    break;
-	case 1575: /* WNW */
-	    next_col = list->col - 2;
-	    next_row = list->row - 1;
-	    break;
-	case 1800: /* W*/
-	    next_row = list->row;
-	    next_col = list->col - 1;
-	    break;
-	case 2025: /* WSW */
-	    next_row = list->row + 1;
-	    next_col = list->col - 2;
-	    break;
-	case 2250: /* SW */
-	    next_row = list->row + 1;
-	    next_col = list->col - 1;
-	    break;
-	case 2475: /* SSW */
-	    next_row = list->row + 2;
-	    next_col = list->col - 1;
-	    break;
-	case 2700: /* S */
-	    next_row = list->row + 1;
-	    next_col = list->col;
-	    break;
-	case 2925: /* SSE */
-	    next_row = list->row + 2;
-	    next_col = list->col + 1;
-	    break;
-	case 3150: /* SE */
-	    next_row = list->row + 1;
-	    next_col = list->col + 1;
-	    break;
-	case 3375: /* ESE */
-	    next_row = list->row + 1;
-	    next_col = list->col + 2;
-	    break;
-	case 3600: /* E */
-	    next_row = list->row;
-	    next_col = list->col + 1;
-	    break;
-	    /* default:
-	       break;
-	       Should probably add something here for the possibility of a non-direction map
-	       G_fatal_error(_("Invalid direction given (possibly not a direction map)")); */
-	}			/* end switch/case */
-
-	if (next_col >= 0 && next_col < ncol && next_row >= 0 &&
-	    next_row < nrow) {
-	    list->next = (struct point *)G_malloc(sizeof(struct point));
-	    list = list->next;
-	    list->row = next_row;
-	    list->col = next_col;
-	    next_row = -1;
-	    next_col = -1;
-	    go = 1;
-	}
-
-    }				/* end while */
-
-    /* allocate and fill the end-of-path flag */
-    list->next = (struct point *)G_malloc(sizeof(struct point));
-    list = list->next;
-    list->row = INT_MAX;
-
-    /* return a pointer to an empty structure */
-    list->next = (struct point *)G_malloc(sizeof(struct point));
-    list = list->next;
-    list->next = NULL;
-
-    G_free(dir_buf);
-
-    return list;
-}

Deleted: grass/trunk/scripts/r.drain/resolve.c
===================================================================
--- grass/trunk/raster/r.drain/resolve.c	2017-12-20 22:06:06 UTC (rev 71962)
+++ grass/trunk/scripts/r.drain/resolve.c	2017-12-28 21:33:22 UTC (rev 71993)
@@ -1,209 +0,0 @@
-#include <grass/config.h>
-#include <stdlib.h>
-#include <string.h>
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "tinf.h"
-
-CELL select_dir(CELL i)
-{
-    CELL dir[256] = { 0, 1, 2, 2, 4, 1, 2, 2, 8, 1,
-	8, 2, 8, 4, 4, 2, 16, 16, 16, 2, 16, 4, 4,
-	2, 8, 8, 8, 8, 8, 8, 8, 4, 32, 1, 2, 2,
-	4, 4, 2, 2, 32, 8, 8, 2, 8, 8, 4, 4, 32,
-	32, 32, 32, 16, 32, 4, 2, 16, 16, 16, 16, 8, 16,
-	8, 8, 64, 64, 64, 1, 64, 1, 2, 2, 64, 64, 8,
-	2, 8, 8, 4, 2, 16, 64, 64, 2, 16, 64, 2, 2,
-	16, 8, 8, 8, 8, 8, 8, 4, 32, 64, 32, 1, 32,
-	32, 32, 2, 32, 32, 32, 2, 32, 8, 4, 4, 32, 32,
-	32, 32, 32, 32, 32, 32, 32, 32, 16, 16, 16, 16, 8,
-	8, 128, 128, 128, 1, 4, 1, 2, 2, 128, 128, 2, 1,
-	8, 4, 4, 2, 16, 128, 2, 1, 4, 128, 2, 1, 8,
-	128, 8, 1, 8, 8, 4, 2, 32, 128, 1, 1, 128, 128,
-	2, 1, 32, 128, 32, 1, 8, 128, 4, 2, 32, 32, 32,
-	1, 32, 128, 32, 1, 16, 16, 16, 1, 16, 16, 8, 4,
-	128, 128, 128, 128, 128, 128, 2, 1, 128, 128, 128, 1, 128,
-	128, 4, 2, 64, 128, 128, 1, 128, 128, 128, 1, 8, 128,
-	8, 1, 8, 8, 8, 2, 64, 128, 64, 128, 64, 128, 64,
-	128, 32, 64, 64, 128, 64, 64, 64, 1, 32, 64, 64, 128,
-	64, 64, 64, 128, 32, 32, 32, 64, 32, 32, 16, 128
-    };
-
-    return dir[i];
-}
-
-void flink(int i, int j, int nl, int ns, CELL * p1, CELL * p2, CELL * p3,
-	   int *active, int *goagain)
-{
-    CELL bitmask[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
-    CELL outflow, cwork, c[8];
-    int k;
-
-    cwork = p2[j];
-    if (Rast_is_c_null_value(p2 + j) || cwork >= 0 || cwork == -256)
-	return;
-    cwork = -cwork;
-
-    for (k = 7; k >= 0; k--) {
-	c[k] = 0;
-	if (cwork >= bitmask[k]) {
-	    c[k] = 1;
-	    cwork -= bitmask[k];
-	}
-    }
-
-    outflow = 0;
-
-    /* There's no need to resolve directions at cells adjacent to null cells,
-     * as those directions will be resolved before we get here */
-    /* look one row back */
-    cwork = p1[j - 1];
-    if (cwork > 0 && cwork != 4 && c[6])
-	outflow += 64;
-    cwork = p1[j];
-    if (cwork > 0 && cwork != 8 && c[7])
-	outflow += 128;
-    cwork = p1[j + 1];
-    if (cwork > 0 && cwork != 16 && c[0])
-	outflow += 1;
-
-    /* look at this row */
-    cwork = p2[j - 1];
-    if (cwork > 0 && cwork != 2 && c[5])
-	outflow += 32;
-    cwork = p2[j + 1];
-    if (cwork > 0 && cwork != 32 && c[1])
-	outflow += 2;
-
-    /* look one row forward */
-    cwork = p3[j - 1];
-    if (cwork > 0 && cwork != 1 && c[4])
-	outflow += 16;
-    cwork = p3[j];
-    if (cwork > 0 && cwork != 128 && c[3])
-	outflow += 8;
-    cwork = p3[j + 1];
-    if (cwork > 0 && cwork != 64 && c[2])
-	outflow += 4;
-
-    if (outflow == 0) {
-	*active = 1;
-    }
-    else {
-	*goagain = 1;
-	p2[j] = select_dir(outflow);
-    }
-    return;
-}
-
-void resolve(int fd, int nl, struct band3 *bnd)
-{
-    CELL cvalue;
-    int *active;
-    int offset, isz, i, j, pass, activity, goagain, done;
-
-    active = (int *)G_calloc(nl, sizeof(int));
-
-    isz = sizeof(CELL);
-
-    /* select a direction when there are multiple non-flat links */
-    lseek(fd, bnd->sz, SEEK_SET);
-    for (i = 1; i < nl - 1; i += 1) {
-	read(fd, bnd->b[0], bnd->sz);
-	for (j = 1; j < bnd->ns - 1; j += 1) {
-	    offset = j * isz;
-	    if (Rast_is_c_null_value((void *)(bnd->b[0] + offset)))
-		continue;
-	    memcpy(&cvalue, bnd->b[0] + offset, isz);
-	    if (cvalue > 0)
-		cvalue = select_dir(cvalue);
-	    memcpy(bnd->b[0] + offset, &cvalue, isz);
-	}
-	lseek(fd, -bnd->sz, SEEK_CUR);
-	write(fd, bnd->b[0], bnd->sz);
-    }
-
-    pass = 0;
-    for (i = 1; i < nl - 1; i += 1)
-	active[i] = 1;
-
-    /* select a direction when there are multiple flat links */
-    do {
-	done = 1;
-	pass += 1;
-
-	activity = 0;
-
-	lseek(fd, 0, SEEK_SET);
-	advance_band3(fd, bnd);
-	advance_band3(fd, bnd);
-	for (i = 1; i < nl - 1; i++) {
-	    lseek(fd, (off_t) (i + 1) * bnd->sz, SEEK_SET);
-	    advance_band3(fd, bnd);
-
-	    if (!active[i])
-		continue;
-
-	    done = 0;
-	    active[i] = 0;
-	    do {
-		goagain = 0;
-		for (j = 1; j < bnd->ns - 1; j += 1) {
-		    flink(i, j, nl, bnd->ns,
-			  (void *)bnd->b[0], (void *)bnd->b[1],
-			  (void *)bnd->b[2], &active[i], &goagain);
-		    if (goagain)
-			activity = 1;
-		}
-	    } while (goagain);
-
-	    lseek(fd, (off_t) i * bnd->sz, SEEK_SET);
-	    write(fd, bnd->b[1], bnd->sz);
-
-	}
-
-	if (!activity) {
-	    done = 1;
-	    continue;
-	}
-
-	activity = 0;
-
-	lseek(fd, (off_t) (nl - 1) * bnd->sz, SEEK_SET);
-	retreat_band3(fd, bnd);
-	retreat_band3(fd, bnd);
-	for (i = nl - 2; i >= 1; i -= 1) {
-	    lseek(fd, (off_t) (i - 1) * bnd->sz, SEEK_SET);
-	    retreat_band3(fd, bnd);
-
-	    if (!active[i])
-		continue;
-
-	    done = 0;
-	    active[i] = 0;
-	    do {
-		goagain = 0;
-		for (j = 1; j < bnd->ns - 1; j++) {
-		    flink(i, j, nl, bnd->ns,
-			  (void *)bnd->b[0], (void *)bnd->b[1],
-			  (void *)bnd->b[2], &active[i], &goagain);
-		    if (goagain)
-			activity = 1;
-		}
-	    } while (goagain);
-
-	    lseek(fd, (off_t) i * bnd->sz, SEEK_SET);
-	    write(fd, bnd->b[1], bnd->sz);
-	}
-
-	if (!activity) {
-	    done = 1;
-	}
-
-    } while (!done);
-
-    G_free(active);
-
-    return;
-
-}

Deleted: grass/trunk/scripts/r.drain/tinf.c
===================================================================
--- grass/trunk/raster/r.drain/tinf.c	2017-12-20 22:06:06 UTC (rev 71962)
+++ grass/trunk/scripts/r.drain/tinf.c	2017-12-28 21:33:22 UTC (rev 71993)
@@ -1,409 +0,0 @@
-#include <grass/config.h>
-/* #include <limits.h> */
-#include <float.h>
-#include <math.h>
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "tinf.h"
-
-int (*is_null) (void *);
-void (*set_null_value) (void *, int);
-int (*bpe) ();
-void *(*get_max) (void *, void *);
-void *(*get_min) (void *, void *);
-void (*get_row) (int, void *, int);
-void *(*get_buf) ();
-void (*put_row) (int, void *);
-double (*slope) (void *, void *, double);
-void (*set_min) (void *);
-void (*set_max) (void *);
-void (*diff) (void *, void *);
-void (*sum) (void *, void *);
-void (*quot) (void *, void *);
-void (*prod) (void *, void *);
-
-/* To add a new multitype function, use the function below to initialize
- * the function pointer to each of the three typed functions.  The function
- * pointers and the function prototypes are defined in a header file.   
- * The actual functions follow. */
-
-void set_func_pointers(int in_type)
-{
-    switch (in_type) {
-    case CELL_TYPE:
-	is_null = is_null_c;
-	bpe = bpe_c;
-	get_max = get_max_c;
-	get_min = get_min_c;
-	get_row = get_row_c;
-	get_buf = get_buf_c;
-	put_row = put_row_c;
-	slope = slope_c;
-	set_min = set_min_c;
-	set_max = set_max_c;
-	diff = diff_c;
-	sum = sum_c;
-	quot = quot_c;
-	prod = prod_c;
-	set_null_value = set_null_value_c;
-
-	break;
-
-    case FCELL_TYPE:
-	is_null = is_null_f;
-	bpe = bpe_f;
-	get_max = get_max_f;
-	get_min = get_min_f;
-	get_row = get_row_f;
-	get_buf = get_buf_f;
-	put_row = put_row_f;
-	slope = slope_f;
-	set_min = set_min_f;
-	set_max = set_max_f;
-	diff = diff_f;
-	sum = sum_f;
-	quot = quot_f;
-	prod = prod_f;
-	set_null_value = set_null_value_f;
-
-	break;
-
-    case DCELL_TYPE:
-	is_null = is_null_d;
-	bpe = bpe_d;
-	get_max = get_max_d;
-	get_min = get_min_d;
-	get_row = get_row_d;
-	get_buf = get_buf_d;
-	put_row = put_row_d;
-	slope = slope_d;
-	set_min = set_min_d;
-	set_max = set_max_d;
-	diff = diff_d;
-	sum = sum_d;
-	quot = quot_d;
-	prod = prod_d;
-	set_null_value = set_null_value_d;
-
-    }
-
-    return;
-
-}
-
-/* check for null values */
-int is_null_c(void *value)
-{
-    return Rast_is_c_null_value((CELL *) value);
-}
-int is_null_f(void *value)
-{
-    return Rast_is_f_null_value((FCELL *) value);
-}
-int is_null_d(void *value)
-{
-    return Rast_is_d_null_value((DCELL *) value);
-}
-
-/* set null values in buffer */
-void set_null_value_c(void *value, int num)
-{
-    Rast_set_c_null_value((CELL *) value, num);
-}
-void set_null_value_f(void *value, int num)
-{
-    Rast_set_f_null_value((FCELL *) value, num);
-}
-void set_null_value_d(void *value, int num)
-{
-    Rast_set_d_null_value((DCELL *) value, num);
-}
-
-/* return the size of the current type */
-int bpe_c()
-{
-    return sizeof(CELL);
-}
-
-int bpe_f()
-{
-    return sizeof(FCELL);
-}
-
-int bpe_d()
-{
-    return sizeof(DCELL);
-}
-
-/* return the pointer that points to the smaller of two value */
-void *get_min_c(void *v1, void *v2)
-{
-    void *rc;
-
-    rc = v2;
-    if (*(CELL *) v1 < *(CELL *) v2)
-	rc = v1;
-    return rc;
-}
-
-void *get_min_f(void *v1, void *v2)
-{
-    void *rc;
-
-    rc = v2;
-    if (*(FCELL *) v1 < *(FCELL *) v2)
-	rc = v1;
-    return rc;
-}
-
-void *get_min_d(void *v1, void *v2)
-{
-    void *rc;
-
-    rc = v2;
-    if (*(DCELL *) v1 < *(DCELL *) v2)
-	rc = v1;
-    return rc;
-}
-
-/* return the pointer that points to the larger value */
-void *get_max_c(void *v1, void *v2)
-{
-    void *rc;
-
-    rc = v2;
-    if (*(CELL *) v1 > *(CELL *) v2)
-	rc = v1;
-    return rc;
-}
-
-void *get_max_f(void *v1, void *v2)
-{
-    void *rc;
-
-    rc = v2;
-    if (*(FCELL *) v1 > *(FCELL *) v2)
-	rc = v1;
-    return rc;
-}
-
-void *get_max_d(void *v1, void *v2)
-{
-    void *rc;
-
-    rc = v2;
-    if (*(DCELL *) v1 > *(DCELL *) v2)
-	rc = v1;
-    return rc;
-}
-
-/* Read one line from a raster map */
-void get_row_c(int fd, void *row, int n)
-{
-    Rast_get_c_row(fd, (CELL *) row, n);
-}
-
-void get_row_f(int fd, void *row, int n)
-{
-    Rast_get_f_row(fd, (FCELL *) row, n);
-}
-
-void get_row_d(int fd, void *row, int n)
-{
-    Rast_get_d_row(fd, (DCELL *) row, n);
-}
-
-/* Write one row to a raster map */
-void put_row_c(int fd, void *row)
-{
-    Rast_put_c_row(fd, (CELL *) row);
-}
-
-void put_row_f(int fd, void *row)
-{
-    Rast_put_f_row(fd, (FCELL *) row);
-}
-
-void put_row_d(int fd, void *row)
-{
-    Rast_put_d_row(fd, (DCELL *) row);
-}
-
-/* Allocate memory for one line of data */
-void *get_buf_c(void)
-{
-    return (void *)Rast_allocate_c_buf();
-}
-
-void *get_buf_f(void)
-{
-    return (void *)Rast_allocate_f_buf();
-}
-
-void *get_buf_d(void)
-{
-    return (void *)Rast_allocate_d_buf();
-}
-
-/* initialize memory to a minimum value */
-void set_min_c(void *v)
-{
-    *(CELL *) v = INT_MIN;
-}
-void set_min_f(void *v)
-{
-    *(FCELL *) v = FLT_MIN;
-}
-void set_min_d(void *v)
-{
-    *(DCELL *) v = DBL_MIN;
-}
-
-/* initialize memory to a maximum value */
-void set_max_c(void *v)
-{
-    *(CELL *) v = INT_MAX;
-}
-void set_max_f(void *v)
-{
-    *(FCELL *) v = FLT_MAX;
-}
-void set_max_d(void *v)
-{
-    *(DCELL *) v = DBL_MAX;
-}
-
-/* get the difference between two values, returned in the first pointer */
-void diff_c(void *v1, void *v2)
-{
-    *(CELL *) v1 -= *(CELL *) v2;
-}
-void diff_f(void *v1, void *v2)
-{
-    *(FCELL *) v1 -= *(FCELL *) v2;
-}
-void diff_d(void *v1, void *v2)
-{
-    *(DCELL *) v1 -= *(DCELL *) v2;
-}
-
-/* get the sum of two values, returned in the first pointer */
-void sum_c(void *v1, void *v2)
-{
-    *(CELL *) v1 += *(CELL *) v2;
-}
-void sum_f(void *v1, void *v2)
-{
-    *(FCELL *) v1 += *(FCELL *) v2;
-}
-void sum_d(void *v1, void *v2)
-{
-    *(DCELL *) v1 += *(DCELL *) v2;
-}
-
-/* get the quotient of two values, returned in the first pointer */
-void quot_c(void *v1, void *v2)
-{
-    *(CELL *) v1 /= *(CELL *) v2;
-}
-void quot_f(void *v1, void *v2)
-{
-    *(FCELL *) v1 /= *(FCELL *) v2;
-}
-void quot_d(void *v1, void *v2)
-{
-    *(DCELL *) v1 /= *(DCELL *) v2;
-}
-
-/* get the product of two values, returned in the first pointer */
-void prod_c(void *v1, void *v2)
-{
-    *(CELL *) v1 *= *(CELL *) v2;
-}
-void prod_f(void *v1, void *v2)
-{
-    *(FCELL *) v1 *= *(FCELL *) v2;
-}
-void prod_d(void *v1, void *v2)
-{
-    *(DCELL *) v1 *= *(DCELL *) v2;
-}
-
-/* probably not a function of general interest */
-/* calculate the slope between two cells, returned as a double  */
-double slope_c(void *line1, void *line2, double cnst)
-{
-    double rc;
-    CELL *pedge;
-
-    rc = -HUGE_VAL;
-    pedge = (CELL *) line2;
-    if (!Rast_is_c_null_value(pedge)) {
-	rc = (*(CELL *) line1 - *pedge) / cnst;
-    }
-    return rc;
-}
-
-double slope_f(void *line1, void *line2, double cnst)
-{
-    double rc;
-    FCELL *pedge;
-
-    rc = -HUGE_VAL;
-    pedge = (FCELL *) line2;
-    if (!Rast_is_f_null_value(pedge)) {
-	rc = (*(FCELL *) line1 - *pedge) / cnst;
-    }
-    return rc;
-}
-
-double slope_d(void *line1, void *line2, double cnst)
-{
-    double rc;
-    DCELL *pedge;
-
-    rc = -HUGE_VAL;
-    pedge = (DCELL *) line2;
-    if (!Rast_is_d_null_value(pedge)) {
-	rc = (*(DCELL *) line1 - *pedge) / cnst;
-    }
-    return rc;
-}
-
-/* read a line and update a three-line buffer */
-/* moving forward through a file */
-int advance_band3(int fh, struct band3 *bnd)
-{
-    int rc;
-    void *hold;
-
-    hold = bnd->b[0];
-    bnd->b[0] = bnd->b[1];
-    bnd->b[1] = bnd->b[2];
-    bnd->b[2] = hold;
-    if (fh == 0)
-	rc = 0;
-    else
-	rc = read(fh, bnd->b[2], bnd->sz);
-    return rc;
-}
-
-/* read a line and update a three-line buffer */
-/* moving backward through a file */
-int retreat_band3(int fh, struct band3 *bnd)
-{
-    int rc;
-    void *hold;
-
-    hold = bnd->b[2];
-    bnd->b[2] = bnd->b[1];
-    bnd->b[1] = bnd->b[0];
-    bnd->b[0] = hold;
-    if (fh == 0)
-	rc = 0;
-    else {
-	rc = read(fh, bnd->b[0], bnd->sz);
-	lseek(fh, (off_t) - 2 * bnd->sz, SEEK_CUR);
-    }
-    return rc;
-}

Deleted: grass/trunk/scripts/r.drain/tinf.h
===================================================================
--- grass/trunk/raster/r.drain/tinf.h	2017-12-20 22:06:06 UTC (rev 71962)
+++ grass/trunk/scripts/r.drain/tinf.h	2017-12-28 21:33:22 UTC (rev 71993)
@@ -1,102 +0,0 @@
-#include <limits.h>
-#include <math.h>
-#include <unistd.h>
-#include <sys/types.h>
-/* #include <values.h> */
-
-/* to add a new multiple-type function first add three prototypes
- * (one for each type).  The functions themselves must be defined
- * elsewhere */
-
-void set_func_pointers(int);
-
-int is_null_c(void *);
-int is_null_f(void *);
-int is_null_d(void *);
-
-void set_null_value_c(void *, int);
-void set_null_value_f(void *, int);
-void set_null_value_d(void *, int);
-
-int bpe_c();
-int bpe_f();
-int bpe_d();
-
-void *get_min_c(void *, void *);
-void *get_min_f(void *, void *);
-void *get_min_d(void *, void *);
-
-void *get_max_c(void *, void *);
-void *get_max_f(void *, void *);
-void *get_max_d(void *, void *);
-
-void get_row_c(int, void *, int);
-void get_row_f(int, void *, int);
-void get_row_d(int, void *, int);
-
-void put_row_c(int, void *);
-void put_row_f(int, void *);
-void put_row_d(int, void *);
-
-void *get_buf_c(void);
-void *get_buf_f(void);
-void *get_buf_d(void);
-
-void set_min_c(void *);
-void set_min_f(void *);
-void set_min_d(void *);
-
-void set_max_c(void *);
-void set_max_f(void *);
-void set_max_d(void *);
-
-void diff_c(void *, void *);
-void diff_f(void *, void *);
-void diff_d(void *, void *);
-
-void sum_c(void *, void *);
-void sum_f(void *, void *);
-void sum_d(void *, void *);
-
-void quot_c(void *, void *);
-void quot_f(void *, void *);
-void quot_d(void *, void *);
-
-void prod_c(void *, void *);
-void prod_f(void *, void *);
-void prod_d(void *, void *);
-
-/* to add a new multitype function, add a pointer for the function and
- * its argument list to the list below */
-
-extern int (*is_null) (void *);
-extern void (*set_null_value) (void *, int);
-extern int (*bpe) ();
-extern void *(*get_max) (void *, void *);
-extern void *(*get_min) (void *, void *);
-extern void (*get_row) (int, void *, int);
-extern void *(*get_buf) ();
-extern void (*put_row) (int, void *);
-extern double (*slope) (void *, void *, double);
-extern void (*set_min) (void *);
-extern void (*set_max) (void *);
-extern void (*diff) (void *, void *);
-extern void (*sum) (void *, void *);
-extern void (*quot) (void *, void *);
-extern void (*prod) (void *, void *);
-
-/* probably not something of general interest */
-
-double slope_c(void *, void *, double);
-double slope_f(void *, void *, double);
-double slope_d(void *, void *, double);
-
-struct band3
-{
-    int ns;			/* samples per line */
-    off_t sz;			/* bytes per line */
-    char *b[3];			/* pointers to start of each line */
-};
-
-int advance_band3(int, struct band3 *);
-int retreat_band3(int, struct band3 *);



More information about the grass-commit mailing list