[GRASS-SVN] r40738 - grass/trunk/raster/r.flow
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jan 29 15:02:43 EST 2010
Author: glynn
Date: 2010-01-29 15:02:42 -0500 (Fri, 29 Jan 2010)
New Revision: 40738
Modified:
grass/trunk/raster/r.flow/io.c
Log:
Don't compare floating-point values with ==, use a tolerance
Modified: grass/trunk/raster/r.flow/io.c
===================================================================
--- grass/trunk/raster/r.flow/io.c 2010-01-29 19:57:59 UTC (rev 40737)
+++ grass/trunk/raster/r.flow/io.c 2010-01-29 20:02:42 UTC (rev 40738)
@@ -27,6 +27,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <math.h>
#include <grass/raster.h>
#include <grass/glocale.h>
#include "r.flow.h"
@@ -69,6 +70,12 @@
return Rast_open_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;
@@ -78,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++) {
@@ -94,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