[GRASS-SVN] r40751 - grass/branches/develbranch_6/raster/r.flow
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jan 31 10:22:20 EST 2010
Author: neteler
Date: 2010-01-31 10:22:19 -0500 (Sun, 31 Jan 2010)
New Revision: 40751
Modified:
grass/branches/develbranch_6/raster/r.flow/io.c
Log:
glynn: Don't compare floating-point values with ==, use a tolerance (backport from trunk, r40738)
Modified: grass/branches/develbranch_6/raster/r.flow/io.c
===================================================================
--- grass/branches/develbranch_6/raster/r.flow/io.c 2010-01-31 10:52:28 UTC (rev 40750)
+++ grass/branches/develbranch_6/raster/r.flow/io.c 2010-01-31 15:22:19 UTC (rev 40751)
@@ -27,6 +27,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <math.h>
+#include <grass/raster.h>
#include <grass/glocale.h>
#include "r.flow.h"
#include "mem.h"
@@ -68,6 +70,12 @@
return G_open_cell_old(fname, mapset);
}
+static int compare_regions(const struct Cell_head *a, const struct Cell_head *b)
+{
+ return (fabs(a->ew_res - b->ew_res) < 1e-6 * b->ew_res &&
+ fabs(a->ns_res - b->ns_res) < 1e-6 * b->ns_res);
+}
+
void read_input_files(void)
{
DCELL *barc;
@@ -77,8 +85,7 @@
G_message(_("Reading input files: elevation"));
fd = open_existing_cell_file(parm.elevin, &hd);
- if (!((region.ew_res == hd.ew_res)
- && (region.ns_res == hd.ns_res)))
+ if (!compare_regions(®ion, &hd))
G_fatal_error(_("Elevation file's resolution differs from current region resolution"));
for (row = 0; row < region.rows; row++) {
@@ -93,8 +100,7 @@
if (parm.aspin) {
G_message(_("Reading input files: aspect"));
fd = open_existing_cell_file(parm.aspin, &hd);
- if (!((region.ew_res == hd.ew_res)
- && (region.ns_res == hd.ns_res)))
+ if (!compare_regions(®ion, &hd))
G_fatal_error(_("Resolution of aspect file differs from "
"current region resolution"));
More information about the grass-commit
mailing list