[GRASS-SVN] r38005 - in grass/trunk: include lib/gis lib/raster

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jun 21 05:56:48 EDT 2009


Author: martinl
Date: 2009-06-21 05:56:47 -0400 (Sun, 21 Jun 2009)
New Revision: 38005

Added:
   grass/trunk/lib/gis/adj_cellhd.c
   grass/trunk/lib/gis/rd_cellhd.c
   grass/trunk/lib/raster/Makefile
Removed:
   grass/trunk/lib/raster/adj_cellhd.c
   grass/trunk/lib/raster/rd_cellhd.c
Modified:
   grass/trunk/include/Rast.h
   grass/trunk/include/gisdefs.h
   grass/trunk/lib/gis/align_window.c
   grass/trunk/lib/gis/get_window.c
   grass/trunk/lib/gis/set_window.c
   grass/trunk/lib/raster/get_cellhd.c
Log:
adj_cellhd.c, rd_cellhd.c, get_cellhd.c moved back to gislib


Modified: grass/trunk/include/Rast.h
===================================================================
--- grass/trunk/include/Rast.h	2009-06-20 22:49:13 UTC (rev 38004)
+++ grass/trunk/include/Rast.h	2009-06-21 09:56:47 UTC (rev 38005)
@@ -4,10 +4,6 @@
 
 /* --- ANSI prototypes for the lib/raster functions --- */
 
-/* adj_cellhd.c */
-const char *Rast_adjust_Cell_head(struct Cell_head *, int, int);
-const char *Rast_adjust_Cell_head3(struct Cell_head *, int, int, int);
-
 /* alloc_cell.c */
 size_t Rast_raster_size(RASTER_MAP_TYPE);
 CELL *Rast_allocate_cell_buf(void);
@@ -513,10 +509,6 @@
 			     char *);
 int Rast__raster_misc_write_line(const char *, const char *, const char *);
 
-/* rd_cellhd.c */
-char *Rast__read_Cell_head(FILE *, struct Cell_head *, int);
-char *Rast__read_Cell_head_array(char **, struct Cell_head *, int);
-
 /* reclass.c */
 int Rast_is_reclass(const char *, const char *, char *, char *);
 int Rast_is_reclassed_to(const char *, const char *, int *, char ***);

Modified: grass/trunk/include/gisdefs.h
===================================================================
--- grass/trunk/include/gisdefs.h	2009-06-20 22:49:13 UTC (rev 38004)
+++ grass/trunk/include/gisdefs.h	2009-06-21 09:56:47 UTC (rev 38005)
@@ -46,6 +46,10 @@
 
 #include <sys/types.h>
 
+/* adj_cellhd.c */
+const char *G_adjust_Cell_head(struct Cell_head *, int, int);
+const char *G_adjust_Cell_head3(struct Cell_head *, int, int, int);
+
 /* align_window.c */
 const char *G_align_window(struct Cell_head *, const struct Cell_head *);
 
@@ -506,6 +510,10 @@
 double G_transverse_radius_of_curvature(double, double, double);
 double G_radius_of_conformal_tangent_sphere(double, double, double);
 
+/* rd_cellhd.c */
+char *G__read_Cell_head(FILE *, struct Cell_head *, int);
+char *G__read_Cell_head_array(char **, struct Cell_head *, int);
+
 /* remove.c */
 int G_remove(const char *, const char *);
 int G_remove_misc(const char *, const char *, const char *);

Copied: grass/trunk/lib/gis/adj_cellhd.c (from rev 38004, grass/trunk/lib/raster/adj_cellhd.c)
===================================================================
--- grass/trunk/lib/gis/adj_cellhd.c	                        (rev 0)
+++ grass/trunk/lib/gis/adj_cellhd.c	2009-06-21 09:56:47 UTC (rev 38005)
@@ -0,0 +1,356 @@
+/*!
+ * \file gis/adj_cellhd.c
+ *
+ * \brief GIS Library - CELL header adjustment.
+ *
+ * (C) 2001-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.
+ *
+ * \author Original author CERL
+ */
+
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+/*!
+ * \brief Adjust cell header.
+ *
+ * This function fills in missing parts of the input cell header (or
+ * region). It also makes projection-specific adjustments. The
+ * <i>cellhd</i> structure must have its <i>north, south, east,
+ * west</i>, and <i>proj</i> fields set.
+ * 
+ * If <i>row_flag</i> is true, then the north-south resolution is
+ * computed from the number of <i>rows</i> in the <i>cellhd</i>
+ * structure. Otherwise the number of <i>rows</i> is computed from the
+ * north-south resolution in the structure, similarly for
+ * <i>col_flag</i> and the number of columns and the east-west
+ * resolution.
+ *
+ * <b>Note:</b> 3D values are not adjusted.
+ *
+ * \param[in,out] cellhd pointer to Cell_head structure
+ * \param row_flag compute n-s resolution
+ * \param col_flag compute e-w resolution
+
+ * \return NULL on success
+ * \return localized text string on error
+ */
+const char *G_adjust_Cell_head(struct Cell_head *cellhd, int row_flag, int col_flag)
+{
+    if (!row_flag) {
+	if (cellhd->ns_res <= 0)
+	    return (_("Illegal n-s resolution value"));
+    }
+    else {
+	if (cellhd->rows <= 0)
+	    return (_("Illegal row value"));
+    }
+    if (!col_flag) {
+	if (cellhd->ew_res <= 0)
+	    return (_("Illegal e-w resolution value"));
+    }
+    else {
+	if (cellhd->cols <= 0)
+	    return (_("Illegal col value"));
+    }
+
+    /* for lat/lon, check north,south. force east larger than west */
+    if (cellhd->proj == PROJECTION_LL) {
+	double epsilon_ns, epsilon_ew;
+
+	/* TODO: find good thresholds */
+	epsilon_ns = 1. / cellhd->rows * 0.001;
+	epsilon_ew = .000001;	/* epsilon_ew calculation doesn't work due to cellhd->cols update/global wraparound below */
+
+	G_debug(3, "G_adjust_Cell_head: epsilon_ns: %g, epsilon_ew: %g",
+		epsilon_ns, epsilon_ew);
+
+	/* TODO: once working, change below G_warning to G_debug */
+
+	/* fix rounding problems if input map slightly exceeds the world definition -180 90 180 -90 */
+	if (cellhd->north > 90.0) {
+	    if (((cellhd->north - 90.0) < epsilon_ns) &&
+		((cellhd->north - 90.0) > GRASS_EPSILON)) {
+		G_warning(_("Fixing subtle input data rounding error of north boundary (%g>%g)"),
+			  cellhd->north - 90.0, epsilon_ns);
+		cellhd->north = 90.0;
+	    }
+	    else
+		return (_("Illegal latitude for North"));
+	}
+
+	if (cellhd->south < -90.0) {
+	    if (((cellhd->south + 90.0) < epsilon_ns) &&
+		((cellhd->south + 90.0) < GRASS_EPSILON)) {
+		G_warning(_("Fixing subtle input data rounding error of south boundary (%g>%g)"),
+			  cellhd->south + 90.0, epsilon_ns);
+		cellhd->south = -90.0;
+	    }
+	    else
+		return (_("Illegal latitude for South"));
+	}
+
+#if 0
+	/* DISABLED: this breaks global wrap-around */
+
+	G_debug(3,
+		"G_adjust_Cell_head()  cellhd->west: %f, devi: %g, eps: %g",
+		cellhd->west, cellhd->west + 180.0, epsilon_ew);
+
+	if ((cellhd->west < -180.0) && ((cellhd->west + 180.0) < epsilon_ew)
+	    && ((cellhd->west + 180.0) < GRASS_EPSILON)) {
+	    G_warning(_("Fixing subtle input data rounding error of west boundary (%g>%g)"),
+		      cellhd->west + 180.0, epsilon_ew);
+	    cellhd->west = -180.0;
+	}
+
+	G_debug(3,
+		"G_adjust_Cell_head()  cellhd->east: %f, devi: %g, eps: %g",
+		cellhd->east, cellhd->east - 180.0, epsilon_ew);
+
+	if ((cellhd->east > 180.0) && ((cellhd->east - 180.0) > epsilon_ew)
+	    && ((cellhd->east - 180.0) > GRASS_EPSILON)) {
+	    G_warning(_("Fixing subtle input data rounding error of east boundary (%g>%g)"),
+		      cellhd->east - 180.0, epsilon_ew);
+	    cellhd->east = 180.0;
+	}
+#endif
+
+	while (cellhd->east <= cellhd->west)
+	    cellhd->east += 360.0;
+    }
+
+    /* check the edge values */
+    if (cellhd->north <= cellhd->south) {
+	if (cellhd->proj == PROJECTION_LL)
+	    return (_("North must be north of South"));
+	else
+	    return (_("North must be larger than South"));
+    }
+    if (cellhd->east <= cellhd->west)
+	return (_("East must be larger than West"));
+
+    /* compute rows and columns, if not set */
+    if (!row_flag) {
+	cellhd->rows =
+	    (cellhd->north - cellhd->south +
+	     cellhd->ns_res / 2.0) / cellhd->ns_res;
+	if (cellhd->rows == 0)
+	    cellhd->rows = 1;
+    }
+    if (!col_flag) {
+	cellhd->cols =
+	    (cellhd->east - cellhd->west +
+	     cellhd->ew_res / 2.0) / cellhd->ew_res;
+	if (cellhd->cols == 0)
+	    cellhd->cols = 1;
+    }
+
+    if (cellhd->cols < 0 || cellhd->rows < 0) {
+	return (_("Invalid coordinates"));
+    }
+
+
+    /* (re)compute the resolutions */
+    cellhd->ns_res = (cellhd->north - cellhd->south) / cellhd->rows;
+    cellhd->ew_res = (cellhd->east - cellhd->west) / cellhd->cols;
+
+    return NULL;
+}
+
+/*!
+ * \brief Adjust cell header for 3D values.
+ *
+ * This function fills in missing parts of the input cell header (or
+ * region).  It also makes projection-specific adjustments. The
+ * <i>cellhd</i> structure must have its <i>north, south, east,
+ * west</i>, and <i>proj</i> fields set.
+ * 
+ * If <i>row_flag</i> is true, then the north-south resolution is computed 
+ * from the number of <i>rows</i> in the <i>cellhd</i> structure. 
+ * Otherwise the number of <i>rows</i> is computed from the north-south 
+ * resolution in the structure, similarly for <i>col_flag</i> and the 
+ * number of columns and the east-west resolution. 
+ *
+ * If <i>depth_flag</i> is true, top-bottom resolution is calculated 
+ * from depths.
+ * If <i>depth_flag</i> are false, number of depths is calculated from 
+ * top-bottom resolution.
+ *
+ * \param[in,out] cellhd pointer to Cell_head structure
+ * \param row_flag compute n-s resolution
+ * \param col_flag compute e-w resolution
+ * \param depth_flag compute t-b resolution
+ *
+ * \return NULL on success
+ * \return localized text string on error
+ */
+const char *G_adjust_Cell_head3(struct Cell_head *cellhd, int row_flag,
+				int col_flag, int depth_flag)
+{
+    if (!row_flag) {
+	if (cellhd->ns_res <= 0)
+	    return (_("Illegal n-s resolution value"));
+	if (cellhd->ns_res3 <= 0)
+	    return (_("Illegal n-s3 resolution value"));
+    }
+    else {
+	if (cellhd->rows <= 0)
+	    return (_("Illegal row value"));
+	if (cellhd->rows3 <= 0)
+	    return (_("Illegal row3 value"));
+    }
+    if (!col_flag) {
+	if (cellhd->ew_res <= 0)
+	    return (_("Illegal e-w resolution value"));
+	if (cellhd->ew_res3 <= 0)
+	    return (_("Illegal e-w3 resolution value"));
+    }
+    else {
+	if (cellhd->cols <= 0)
+	    return (_("Illegal col value"));
+	if (cellhd->cols3 <= 0)
+	    return (_("Illegal col3 value"));
+    }
+    if (!depth_flag) {
+	if (cellhd->tb_res <= 0)
+	    return (_("Illegal t-b3 resolution value"));
+    }
+    else {
+	if (cellhd->depths <= 0)
+	    return (_("Illegal depths value"));
+    }
+
+    /* for lat/lon, check north,south. force east larger than west */
+    if (cellhd->proj == PROJECTION_LL) {
+	double epsilon_ns, epsilon_ew;
+
+	/* TODO: find good thresholds */
+	epsilon_ns = 1. / cellhd->rows * 0.001;
+	epsilon_ew = .000001;	/* epsilon_ew calculation doesn't work due to cellhd->cols update/global wraparound below */
+
+	G_debug(3, "G_adjust_Cell_head: epsilon_ns: %g, epsilon_ew: %g",
+		epsilon_ns, epsilon_ew);
+
+	/* TODO: once working, change below G_warning to G_debug */
+
+	/* fix rounding problems if input map slightly exceeds the world definition -180 90 180 -90 */
+	if (cellhd->north > 90.0) {
+	    if (((cellhd->north - 90.0) < epsilon_ns) &&
+		((cellhd->north - 90.0) > GRASS_EPSILON)) {
+		G_warning(_("Fixing subtle input data rounding error of north boundary (%g>%g)"),
+			  cellhd->north - 90.0, epsilon_ns);
+		cellhd->north = 90.0;
+	    }
+	    else
+		return (_("Illegal latitude for North"));
+	}
+
+	if (cellhd->south < -90.0) {
+	    if (((cellhd->south + 90.0) < epsilon_ns) &&
+		((cellhd->south + 90.0) < GRASS_EPSILON)) {
+		G_warning(_("Fixing subtle input data rounding error of south boundary (%g>%g)"),
+			  cellhd->south + 90.0, epsilon_ns);
+		cellhd->south = -90.0;
+	    }
+	    else
+		return (_("Illegal latitude for South"));
+	}
+
+#if 0
+	/* DISABLED: this breaks global wrap-around */
+
+	G_debug(3,
+		"G_adjust_Cell_head3() cellhd->west: %f, devi: %g, eps: %g",
+		cellhd->west, cellhd->west + 180.0, epsilon_ew);
+
+	if ((cellhd->west < -180.0) && ((cellhd->west + 180.0) < epsilon_ew)
+	    && ((cellhd->west + 180.0) < GRASS_EPSILON)) {
+	    G_warning(_("Fixing subtle input data rounding error of west boundary (%g>%g)"),
+		      cellhd->west + 180.0, epsilon_ew);
+	    cellhd->west = -180.0;
+	}
+
+	G_debug(3,
+		"G_adjust_Cell_head3() cellhd->east: %f, devi: %g, eps: %g",
+		cellhd->east, cellhd->east - 180.0, epsilon_ew);
+
+	if ((cellhd->east > 180.0) && ((cellhd->east - 180.0) > epsilon_ew)
+	    && ((cellhd->east - 180.0) > GRASS_EPSILON)) {
+	    G_warning(_("Fixing subtle input data rounding error of east boundary (%g>%g)"),
+		      cellhd->east - 180.0, epsilon_ew);
+	    cellhd->east = 180.0;
+	}
+#endif
+
+	while (cellhd->east <= cellhd->west)
+	    cellhd->east += 360.0;
+    }
+
+    /* check the edge values */
+    if (cellhd->north <= cellhd->south) {
+	if (cellhd->proj == PROJECTION_LL)
+	    return (_("North must be north of South"));
+	else
+	    return (_("North must be larger than South"));
+    }
+    if (cellhd->east <= cellhd->west)
+	return (_("East must be larger than West"));
+    if (cellhd->top <= cellhd->bottom)
+	return (_("Top must be larger than Bottom"));
+
+
+    /* compute rows and columns, if not set */
+    if (!row_flag) {
+	cellhd->rows =
+	    (cellhd->north - cellhd->south +
+	     cellhd->ns_res / 2.0) / cellhd->ns_res;
+	if (cellhd->rows == 0)
+	    cellhd->rows = 1;
+
+	cellhd->rows3 =
+	    (cellhd->north - cellhd->south +
+	     cellhd->ns_res3 / 2.0) / cellhd->ns_res3;
+	if (cellhd->rows3 == 0)
+	    cellhd->rows3 = 1;
+    }
+    if (!col_flag) {
+	cellhd->cols =
+	    (cellhd->east - cellhd->west +
+	     cellhd->ew_res / 2.0) / cellhd->ew_res;
+	if (cellhd->cols == 0)
+	    cellhd->cols = 1;
+
+	cellhd->cols3 =
+	    (cellhd->east - cellhd->west +
+	     cellhd->ew_res3 / 2.0) / cellhd->ew_res3;
+	if (cellhd->cols3 == 0)
+	    cellhd->cols3 = 1;
+    }
+
+    if (!depth_flag) {
+	cellhd->depths =
+	    (cellhd->top - cellhd->bottom +
+	     cellhd->tb_res / 2.0) / cellhd->tb_res;
+	if (cellhd->depths == 0)
+	    cellhd->depths = 1;
+
+    }
+
+    if (cellhd->cols < 0 || cellhd->rows < 0 || cellhd->cols3 < 0 ||
+	cellhd->rows3 < 0 || cellhd->depths < 0) {
+	return (_("Invalid coordinates"));
+    }
+
+    /* (re)compute the resolutions */
+    cellhd->ns_res = (cellhd->north - cellhd->south) / cellhd->rows;
+    cellhd->ns_res3 = (cellhd->north - cellhd->south) / cellhd->rows3;
+    cellhd->ew_res = (cellhd->east - cellhd->west) / cellhd->cols;
+    cellhd->ew_res3 = (cellhd->east - cellhd->west) / cellhd->cols3;
+    cellhd->tb_res = (cellhd->top - cellhd->bottom) / cellhd->depths;
+
+    return NULL;
+}

Modified: grass/trunk/lib/gis/align_window.c
===================================================================
--- grass/trunk/lib/gis/align_window.c	2009-06-20 22:49:13 UTC (rev 38004)
+++ grass/trunk/lib/gis/align_window.c	2009-06-21 09:56:47 UTC (rev 38005)
@@ -71,5 +71,5 @@
 		window->east -= window->ew_res;
     }
 
-    return Rast_adjust_Cell_head(window, 0, 0);
+    return G_adjust_Cell_head(window, 0, 0);
 }

Modified: grass/trunk/lib/gis/get_window.c
===================================================================
--- grass/trunk/lib/gis/get_window.c	2009-06-20 22:49:13 UTC (rev 38004)
+++ grass/trunk/lib/gis/get_window.c	2009-06-21 09:56:47 UTC (rev 38005)
@@ -59,7 +59,7 @@
 
     if (regvar) {
 	char **tokens = G_tokenize(regvar, ";");
-	err = Rast__read_Cell_head_array(tokens, &st->dbwindow, 0);
+	err = G__read_Cell_head_array(tokens, &st->dbwindow, 0);
 	G_free_tokens(tokens);
     }
     else {
@@ -128,7 +128,7 @@
     if (!fp)
 	return G_store(_("is not set"));
 
-    err = Rast__read_Cell_head(fp, window, 0);
+    err = G__read_Cell_head(fp, window, 0);
     fclose(fp);
 
     if (err) {

Copied: grass/trunk/lib/gis/rd_cellhd.c (from rev 38004, grass/trunk/lib/raster/rd_cellhd.c)
===================================================================
--- grass/trunk/lib/gis/rd_cellhd.c	                        (rev 0)
+++ grass/trunk/lib/gis/rd_cellhd.c	2009-06-21 09:56:47 UTC (rev 38005)
@@ -0,0 +1,434 @@
+/* read cell header, or window.
+   returns NULL if ok, error message otherwise
+   note:  the error message can be freed using G_free ().
+ */
+#include <string.h>
+
+#include <grass/gis.h>
+#include <grass/Rast.h>
+#include <grass/glocale.h>
+
+#define ERROR(x,line) return error(x,line)
+static int scan_item(const char *, char *, char *);
+static int scan_int(const char *, int *);
+static double scan_double(const char *, double *);
+static char *error(const char *, int);
+
+#define F_PROJ   1
+#define F_ZONE   2
+#define F_NORTH  3
+#define F_SOUTH  4
+#define F_EAST   5
+#define F_WEST   6
+#define F_EWRES  7
+#define F_NSRES  8
+#define F_FORMAT 9
+#define F_COMP   10
+#define F_COLS   11
+#define F_ROWS   12
+
+#define F_EWRES3 13
+#define F_NSRES3 14
+#define F_COLS3  15
+#define F_ROWS3  16
+#define F_TOP    17
+#define F_BOTTOM 18
+#define F_TBRES  19
+#define F_DEPTHS 20
+
+#define SET(x) flags|=(1<<x)
+#define TEST(x) (flags&(1<<x))
+
+char *G__read_Cell_head_array(char **array,
+			      struct Cell_head *cellhd, int is_cellhd);
+
+char *G__read_Cell_head(FILE * fd, struct Cell_head *cellhd, int is_cellhd)
+{
+    int count;
+    char *result, **array;
+    char buf[1024];
+
+    G_debug(2, "G__read_Cell_head");
+
+    /* Count lines */
+    count = 0;
+    fseek(fd, 0L, 0);
+    while (G_getl(buf, sizeof(buf), fd))
+	count++;
+
+    array = (char **)G_calloc(count + 1, sizeof(char **));
+
+    count = 0;
+    fseek(fd, 0L, 0);
+    while (G_getl(buf, sizeof(buf), fd)) {
+	array[count] = G_store(buf);
+	count++;
+    }
+
+    result = G__read_Cell_head_array(array, cellhd, is_cellhd);
+
+    count = 0;
+    while (array[count]) {
+	G_free(array[count]);
+	count++;
+    }
+    G_free(array);
+
+    return result;
+}
+
+/* Read window from NULL terminated array of strings */
+char *G__read_Cell_head_array(char **array,
+			      struct Cell_head *cellhd, int is_cellhd)
+{
+    char *buf;
+    char label[200];
+    char value[200];
+    int i, line;
+    int flags;
+    const char *err;
+
+    G_debug(2, "G__read_Cell_head_array");
+
+    flags = 0;
+
+    /* initialize the cell header */
+    cellhd->format = 0;
+    cellhd->rows = 0;
+    cellhd->rows3 = 0;
+    cellhd->cols = 0;
+    cellhd->cols3 = 0;
+    cellhd->depths = 1;
+    cellhd->proj = -1;
+    cellhd->zone = -1;
+    cellhd->compressed = -1;
+    cellhd->ew_res = 0.0;
+    cellhd->ew_res3 = 1.0;
+    cellhd->ns_res = 0.0;
+    cellhd->ns_res3 = 1.0;
+    cellhd->tb_res = 1.0;
+    cellhd->north = 0.0;
+    cellhd->south = 0.0;
+    cellhd->east = 0.0;
+    cellhd->west = 0.0;
+    cellhd->top = 1.0;
+    cellhd->bottom = 0.0;
+
+    /* determine projection, zone first */
+
+    i = 0;
+    for (line = 1; (buf = array[i++]); line++) {
+	if (TEST(F_PROJ) && TEST(F_ZONE))
+	    break;
+
+	switch (scan_item(buf, label, value)) {
+	case -1:
+	    ERROR(buf, line);
+	case 0:
+	    continue;
+	case 1:
+	    break;
+	}
+	if (strncmp(label, "proj", 4) == 0) {
+	    if (TEST(F_PROJ))
+		ERROR(_("duplicate projection field"), line);
+
+	    if (!scan_int(value, &cellhd->proj))
+		ERROR(buf, line);
+
+	    SET(F_PROJ);
+	    continue;
+	}
+	if (strncmp(label, "zone", 4) == 0) {
+	    if (TEST(F_ZONE))
+		ERROR(_("duplicate zone field"), line);
+
+	    if (!scan_int(value, &cellhd->zone))
+		ERROR(buf, line);
+
+	    SET(F_ZONE);
+	    continue;
+	}
+    }
+    if (!TEST(F_PROJ))
+	ERROR(_("projection field missing"), 0);
+    if (!TEST(F_ZONE))
+	ERROR(_("zone field missing"), 0);
+
+    /* read the other info */
+    i = 0;
+    for (line = 1; (buf = array[i++]); line++) {
+	G_debug(3, "region item: %s", buf);
+	switch (scan_item(buf, label, value)) {
+	case -1:
+	    ERROR(buf, line);
+	case 0:
+	    continue;
+	case 1:
+	    break;
+	}
+
+	if (strncmp(label, "proj", 4) == 0)
+	    continue;
+	if (strncmp(label, "zone", 4) == 0)
+	    continue;
+
+	if (strncmp(label, "nort", 4) == 0) {
+	    if (TEST(F_NORTH))
+		ERROR(_("duplicate north field"), line);
+	    if (!G_scan_northing(value, &cellhd->north, cellhd->proj))
+		ERROR(buf, line);
+	    SET(F_NORTH);
+	    continue;
+	}
+	if (strncmp(label, "sout", 4) == 0) {
+	    if (TEST(F_SOUTH))
+		ERROR(_("duplicate south field"), line);
+	    if (!G_scan_northing(value, &cellhd->south, cellhd->proj))
+		ERROR(buf, line);
+	    SET(F_SOUTH);
+	    continue;
+	}
+	if (strncmp(label, "east", 4) == 0) {
+	    if (TEST(F_EAST))
+		ERROR(_("duplicate east field"), line);
+	    if (!G_scan_easting(value, &cellhd->east, cellhd->proj))
+		ERROR(buf, line);
+	    SET(F_EAST);
+	    continue;
+	}
+	if (strncmp(label, "west", 4) == 0) {
+	    if (TEST(F_WEST))
+		ERROR(_("duplicate west field"), line);
+	    if (!G_scan_easting(value, &cellhd->west, cellhd->proj))
+		ERROR(buf, line);
+	    SET(F_WEST);
+	    continue;
+	}
+	if (strncmp(label, "top", 3) == 0) {
+	    if (TEST(F_TOP))
+		ERROR(_("duplicate top field"), line);
+	    if (!scan_double(value, &cellhd->top))
+		ERROR(buf, line);
+	    SET(F_TOP);
+	    continue;
+	}
+	if (strncmp(label, "bottom", 6) == 0) {
+	    if (TEST(F_BOTTOM))
+		ERROR(_("duplicate bottom field"), line);
+	    if (!scan_double(value, &cellhd->bottom))
+		ERROR(buf, line);
+	    SET(F_BOTTOM);
+	    continue;
+	}
+	if (strncmp(label, "e-w ", 4) == 0 && strlen(label) == 9) {
+	    if (TEST(F_EWRES))
+		ERROR(_("duplicate e-w resolution field"), line);
+	    if (!G_scan_resolution(value, &cellhd->ew_res, cellhd->proj))
+		ERROR(buf, line);
+	    if (cellhd->ew_res <= 0.0)
+		ERROR(buf, line);
+	    SET(F_EWRES);
+	    continue;
+	}
+	if (strncmp(label, "e-w resol3", 10) == 0) {
+	    if (TEST(F_EWRES3))
+		ERROR(_("duplicate 3D e-w resolution field"), line);
+	    if (!G_scan_resolution(value, &cellhd->ew_res3, cellhd->proj))
+		ERROR(buf, line);
+	    if (cellhd->ew_res3 <= 0.0)
+		ERROR(buf, line);
+	    SET(F_EWRES3);
+	    continue;
+	}
+	if (strncmp(label, "n-s ", 4) == 0 && strlen(label) == 9) {
+	    if (TEST(F_NSRES))
+		ERROR(_("duplicate n-s resolution field"), line);
+	    if (!G_scan_resolution(value, &cellhd->ns_res, cellhd->proj))
+		ERROR(buf, line);
+	    if (cellhd->ns_res <= 0.0)
+		ERROR(buf, line);
+	    SET(F_NSRES);
+	    continue;
+	}
+	if (strncmp(label, "n-s resol3", 10) == 0) {
+	    if (TEST(F_NSRES3))
+		ERROR(_("duplicate 3D n-s resolution field"), line);
+	    if (!G_scan_resolution(value, &cellhd->ns_res3, cellhd->proj))
+		ERROR(buf, line);
+	    if (cellhd->ns_res3 <= 0.0)
+		ERROR(buf, line);
+	    SET(F_NSRES3);
+	    continue;
+	}
+	if (strncmp(label, "t-b ", 4) == 0) {
+	    if (TEST(F_TBRES))
+		ERROR(_("duplicate t-b resolution field"), line);
+	    if (!scan_double(value, &cellhd->tb_res))
+		ERROR(buf, line);
+	    if (cellhd->tb_res <= 0.0)
+		ERROR(buf, line);
+	    SET(F_TBRES);
+	    continue;
+	}
+	if (strncmp(label, "rows", 4) == 0 && strlen(label) == 4) {
+	    if (TEST(F_ROWS))
+		ERROR(_("duplicate rows field"), line);
+	    if (!scan_int(value, &cellhd->rows))
+		ERROR(buf, line);
+	    if (cellhd->rows <= 0)
+		ERROR(buf, line);
+	    SET(F_ROWS);
+	    continue;
+	}
+	if (strncmp(label, "rows3", 5) == 0) {
+	    if (TEST(F_ROWS3))
+		ERROR(_("duplicate 3D rows field"), line);
+	    if (!scan_int(value, &cellhd->rows3))
+		ERROR(buf, line);
+	    if (cellhd->rows3 <= 0)
+		ERROR(buf, line);
+	    SET(F_ROWS3);
+	    continue;
+	}
+	if (strncmp(label, "cols", 4) == 0 && strlen(label) == 4) {
+	    if (TEST(F_COLS))
+		ERROR(_("duplicate cols field"), line);
+	    if (!scan_int(value, &cellhd->cols))
+		ERROR(buf, line);
+	    if (cellhd->cols <= 0)
+		ERROR(buf, line);
+	    SET(F_COLS);
+	    continue;
+	}
+	if (strncmp(label, "cols3", 5) == 0) {
+	    if (TEST(F_COLS3))
+		ERROR(_("duplicate 3D cols field"), line);
+	    if (!scan_int(value, &cellhd->cols3))
+		ERROR(buf, line);
+	    if (cellhd->cols3 <= 0)
+		ERROR(buf, line);
+	    SET(F_COLS3);
+	    continue;
+	}
+	if (strncmp(label, "depths", 6) == 0) {
+	    if (TEST(F_DEPTHS))
+		ERROR(_("duplicate depths field"), line);
+	    if (!scan_int(value, &cellhd->depths))
+		ERROR(buf, line);
+	    if (cellhd->depths <= 0)
+		ERROR(buf, line);
+	    SET(F_DEPTHS);
+	    continue;
+	}
+	if (strncmp(label, "form", 4) == 0) {
+	    if (TEST(F_FORMAT))
+		ERROR(_("duplicate format field"), line);
+	    if (!scan_int(value, &cellhd->format))
+		ERROR(buf, line);
+	    SET(F_FORMAT);
+	    continue;
+	}
+	if (strncmp(label, "comp", 4) == 0) {
+	    if (TEST(F_COMP))
+		ERROR(_("duplicate compressed field"), line);
+	    if (!scan_int(value, &cellhd->compressed))
+		ERROR(buf, line);
+	    SET(F_COMP);
+	    continue;
+	}
+	ERROR(buf, line);
+    }
+
+    /* check some of the fields */
+    if (!TEST(F_NORTH))
+	ERROR(_("north field missing"), 0);
+    if (!TEST(F_SOUTH))
+	ERROR(_("south field missing"), 0);
+    if (!TEST(F_WEST))
+	ERROR(_("west field missing"), 0);
+    if (!TEST(F_EAST))
+	ERROR(_("east field missing"), 0);
+    if (!TEST(F_EWRES) && !TEST(F_COLS))
+	ERROR(_("cols field missing"), 0);
+    if (!TEST(F_NSRES) && !TEST(F_ROWS))
+	ERROR(_("rows field missing"), 0);
+    /* This next stmt is commented out to allow wr_cellhd.c to write
+     * headers that will be readable by GRASS 3.1
+     if ((TEST(F_ROWS) && TEST(F_NSRES))
+     ||  (TEST(F_COLS) && TEST(F_EWRES)))
+     ERROR ("row/col and resolution information can not both appear ",0);
+     */
+
+    /* 3D defined? */
+    if (TEST(F_EWRES3) || TEST(F_NSRES3) || TEST(F_COLS3) || TEST(F_ROWS3)) {
+	if (!TEST(F_EWRES3))
+	    ERROR(_("ewres3 field missing"), 0);
+	if (!TEST(F_NSRES3))
+	    ERROR(_("nsres3 field missing"), 0);
+	if (!TEST(F_COLS3))
+	    ERROR(_("cols3 field missing"), 0);
+	if (!TEST(F_ROWS3))
+	    ERROR(_("rows3 field missing"), 0);
+    }
+    else {			/* use 2D */
+	cellhd->ew_res3 = cellhd->ew_res;
+	cellhd->ns_res3 = cellhd->ns_res;
+	cellhd->cols3 = cellhd->cols;
+	cellhd->rows3 = cellhd->rows;
+    }
+
+    /* Adjust and complete the cell header  */
+    if ((err = G_adjust_Cell_head(cellhd, TEST(F_ROWS), TEST(F_COLS))))
+	ERROR(err, 0);
+
+
+    return NULL;
+}
+
+static int scan_item(const char *buf, char *label, char *value)
+{
+    /* skip blank lines */
+    if (sscanf(buf, "%1s", label) != 1)
+	return 0;
+
+    /* skip comment lines */
+    if (*label == '#')
+	return 0;
+
+    /* must be label: value */
+    if (sscanf(buf, "%[^:]:%[^\n]", label, value) != 2)
+	return -1;
+
+    G_strip(label);
+    G_strip(value);
+    return 1;
+}
+
+static int scan_int(const char *buf, int *n)
+{
+    char dummy[3];
+
+    *dummy = 0;
+    return (sscanf(buf, "%d%1s", n, dummy) == 1 && *dummy == 0);
+}
+
+static double scan_double(const char *buf, double *n)
+{
+    char dummy[3];
+
+    *dummy = 0;
+    return (sscanf(buf, "%lf%1s", n, dummy) == 1 && *dummy == 0);
+}
+
+static char *error(const char *msg, int line)
+{
+    char buf[1024];
+
+    if (line)
+	sprintf(buf, _("line %d: <%s>"), line, msg);
+    else
+	sprintf(buf, "<%s>", msg);
+
+    return G_store(buf);
+}

Modified: grass/trunk/lib/gis/set_window.c
===================================================================
--- grass/trunk/lib/gis/set_window.c	2009-06-20 22:49:13 UTC (rev 38004)
+++ grass/trunk/lib/gis/set_window.c	2009-06-21 09:56:47 UTC (rev 38005)
@@ -53,7 +53,7 @@
        window = &twindow;
      */
 
-    if ((err = Rast_adjust_Cell_head(window, 0, 0))) {
+    if ((err = G_adjust_Cell_head(window, 0, 0))) {
 	G_warning("G_set_window(): %s", err);
 	return -1;
     }

Added: grass/trunk/lib/raster/Makefile
===================================================================
--- grass/trunk/lib/raster/Makefile	                        (rev 0)
+++ grass/trunk/lib/raster/Makefile	2009-06-21 09:56:47 UTC (rev 38005)
@@ -0,0 +1,48 @@
+MODULE_TOPDIR = ../..
+
+GDAL_LINK = $(USE_GDAL)
+GDAL_DYNAMIC = 1
+
+LIB_NAME = $(RASTR_LIBNAME)
+EXTRA_LIBS = $(XDRLIB) $(SOCKLIB) $(DATETIMELIB) $(PTHREADLIBPATH) \
+	$(PTHREADLIB) $(INTLLIB) $(MATHLIB) $(GISLIB)
+EXTRA_INC = $(ZLIBINCPATH) $(PTHREADINCPATH)
+
+include $(MODULE_TOPDIR)/include/Make/Vars.make
+include $(MODULE_TOPDIR)/include/Make/Lib.make
+include $(MODULE_TOPDIR)/include/Make/Doxygen.make
+
+#compile if LFS Large File Support present:
+ifneq ($(USE_LARGEFILES),)
+	EXTRA_CFLAGS = -D_FILE_OFFSET_BITS=64
+endif
+
+ifneq ($(GDAL_LINK),)
+EXTRA_CFLAGS += -DGDAL_LINK=1
+EXTRA_INC += $(PROJINC) $(GDALCFLAGS)
+
+ifneq ($(GDAL_DYNAMIC),)
+EXTRA_CFLAGS += -DGDAL_DYNAMIC=1
+ifneq ($(MINGW),)
+EXTRA_LIBS += -lkernel32
+else
+EXTRA_LIBS += $(DLLIB)
+endif
+else
+EXTRA_LIBS += $(GDALLIBS)
+endif
+
+endif
+
+default: lib
+
+DOXNAME = rasterlib
+
+$(OBJDIR)/auto_mask.o: G.h
+$(OBJDIR)/closecell.o: G.h
+$(OBJDIR)/format.o: G.h
+$(OBJDIR)/get_row.o: G.h
+$(OBJDIR)/get_window.o: G.h
+$(OBJDIR)/maskfd.o: G.h
+$(OBJDIR)/opencell.o: G.h
+$(OBJDIR)/put_row.o: G.h


Property changes on: grass/trunk/lib/raster/Makefile
___________________________________________________________________
Name: svn:mime-type
   + text/x-sh
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native

Deleted: grass/trunk/lib/raster/adj_cellhd.c
===================================================================
--- grass/trunk/lib/raster/adj_cellhd.c	2009-06-20 22:49:13 UTC (rev 38004)
+++ grass/trunk/lib/raster/adj_cellhd.c	2009-06-21 09:56:47 UTC (rev 38005)
@@ -1,356 +0,0 @@
-/*!
- * \file gis/adj_cellhd.c
- *
- * \brief GIS Library - CELL header adjustment.
- *
- * (C) 2001-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.
- *
- * \author Original author CERL
- */
-
-#include <grass/gis.h>
-#include <grass/glocale.h>
-
-/*!
- * \brief Adjust cell header.
- *
- * This function fills in missing parts of the input cell header (or
- * region). It also makes projection-specific adjustments. The
- * <i>cellhd</i> structure must have its <i>north, south, east,
- * west</i>, and <i>proj</i> fields set.
- * 
- * If <i>row_flag</i> is true, then the north-south resolution is
- * computed from the number of <i>rows</i> in the <i>cellhd</i>
- * structure. Otherwise the number of <i>rows</i> is computed from the
- * north-south resolution in the structure, similarly for
- * <i>col_flag</i> and the number of columns and the east-west
- * resolution.
- *
- * <b>Note:</b> 3D values are not adjusted.
- *
- * \param[in,out] cellhd pointer to Cell_head structure
- * \param row_flag compute n-s resolution
- * \param col_flag compute e-w resolution
-
- * \return NULL on success
- * \return localized text string on error
- */
-const char *Rast_adjust_Cell_head(struct Cell_head *cellhd, int row_flag, int col_flag)
-{
-    if (!row_flag) {
-	if (cellhd->ns_res <= 0)
-	    return (_("Illegal n-s resolution value"));
-    }
-    else {
-	if (cellhd->rows <= 0)
-	    return (_("Illegal row value"));
-    }
-    if (!col_flag) {
-	if (cellhd->ew_res <= 0)
-	    return (_("Illegal e-w resolution value"));
-    }
-    else {
-	if (cellhd->cols <= 0)
-	    return (_("Illegal col value"));
-    }
-
-    /* for lat/lon, check north,south. force east larger than west */
-    if (cellhd->proj == PROJECTION_LL) {
-	double epsilon_ns, epsilon_ew;
-
-	/* TODO: find good thresholds */
-	epsilon_ns = 1. / cellhd->rows * 0.001;
-	epsilon_ew = .000001;	/* epsilon_ew calculation doesn't work due to cellhd->cols update/global wraparound below */
-
-	G_debug(3, "Rast_adjust_Cell_head: epsilon_ns: %g, epsilon_ew: %g",
-		epsilon_ns, epsilon_ew);
-
-	/* TODO: once working, change below G_warning to G_debug */
-
-	/* fix rounding problems if input map slightly exceeds the world definition -180 90 180 -90 */
-	if (cellhd->north > 90.0) {
-	    if (((cellhd->north - 90.0) < epsilon_ns) &&
-		((cellhd->north - 90.0) > GRASS_EPSILON)) {
-		G_warning(_("Fixing subtle input data rounding error of north boundary (%g>%g)"),
-			  cellhd->north - 90.0, epsilon_ns);
-		cellhd->north = 90.0;
-	    }
-	    else
-		return (_("Illegal latitude for North"));
-	}
-
-	if (cellhd->south < -90.0) {
-	    if (((cellhd->south + 90.0) < epsilon_ns) &&
-		((cellhd->south + 90.0) < GRASS_EPSILON)) {
-		G_warning(_("Fixing subtle input data rounding error of south boundary (%g>%g)"),
-			  cellhd->south + 90.0, epsilon_ns);
-		cellhd->south = -90.0;
-	    }
-	    else
-		return (_("Illegal latitude for South"));
-	}
-
-#if 0
-	/* DISABLED: this breaks global wrap-around */
-
-	G_debug(3,
-		"Rast_adjust_Cell_head()  cellhd->west: %f, devi: %g, eps: %g",
-		cellhd->west, cellhd->west + 180.0, epsilon_ew);
-
-	if ((cellhd->west < -180.0) && ((cellhd->west + 180.0) < epsilon_ew)
-	    && ((cellhd->west + 180.0) < GRASS_EPSILON)) {
-	    G_warning(_("Fixing subtle input data rounding error of west boundary (%g>%g)"),
-		      cellhd->west + 180.0, epsilon_ew);
-	    cellhd->west = -180.0;
-	}
-
-	G_debug(3,
-		"Rast_adjust_Cell_head()  cellhd->east: %f, devi: %g, eps: %g",
-		cellhd->east, cellhd->east - 180.0, epsilon_ew);
-
-	if ((cellhd->east > 180.0) && ((cellhd->east - 180.0) > epsilon_ew)
-	    && ((cellhd->east - 180.0) > GRASS_EPSILON)) {
-	    G_warning(_("Fixing subtle input data rounding error of east boundary (%g>%g)"),
-		      cellhd->east - 180.0, epsilon_ew);
-	    cellhd->east = 180.0;
-	}
-#endif
-
-	while (cellhd->east <= cellhd->west)
-	    cellhd->east += 360.0;
-    }
-
-    /* check the edge values */
-    if (cellhd->north <= cellhd->south) {
-	if (cellhd->proj == PROJECTION_LL)
-	    return (_("North must be north of South"));
-	else
-	    return (_("North must be larger than South"));
-    }
-    if (cellhd->east <= cellhd->west)
-	return (_("East must be larger than West"));
-
-    /* compute rows and columns, if not set */
-    if (!row_flag) {
-	cellhd->rows =
-	    (cellhd->north - cellhd->south +
-	     cellhd->ns_res / 2.0) / cellhd->ns_res;
-	if (cellhd->rows == 0)
-	    cellhd->rows = 1;
-    }
-    if (!col_flag) {
-	cellhd->cols =
-	    (cellhd->east - cellhd->west +
-	     cellhd->ew_res / 2.0) / cellhd->ew_res;
-	if (cellhd->cols == 0)
-	    cellhd->cols = 1;
-    }
-
-    if (cellhd->cols < 0 || cellhd->rows < 0) {
-	return (_("Invalid coordinates"));
-    }
-
-
-    /* (re)compute the resolutions */
-    cellhd->ns_res = (cellhd->north - cellhd->south) / cellhd->rows;
-    cellhd->ew_res = (cellhd->east - cellhd->west) / cellhd->cols;
-
-    return NULL;
-}
-
-/*!
- * \brief Adjust cell header for 3D values.
- *
- * This function fills in missing parts of the input cell header (or
- * region).  It also makes projection-specific adjustments. The
- * <i>cellhd</i> structure must have its <i>north, south, east,
- * west</i>, and <i>proj</i> fields set.
- * 
- * If <i>row_flag</i> is true, then the north-south resolution is computed 
- * from the number of <i>rows</i> in the <i>cellhd</i> structure. 
- * Otherwise the number of <i>rows</i> is computed from the north-south 
- * resolution in the structure, similarly for <i>col_flag</i> and the 
- * number of columns and the east-west resolution. 
- *
- * If <i>depth_flag</i> is true, top-bottom resolution is calculated 
- * from depths.
- * If <i>depth_flag</i> are false, number of depths is calculated from 
- * top-bottom resolution.
- *
- * \param[in,out] cellhd pointer to Cell_head structure
- * \param row_flag compute n-s resolution
- * \param col_flag compute e-w resolution
- * \param depth_flag compute t-b resolution
- *
- * \return NULL on success
- * \return localized text string on error
- */
-const char *Rast_adjust_Cell_head3(struct Cell_head *cellhd, int row_flag,
-				int col_flag, int depth_flag)
-{
-    if (!row_flag) {
-	if (cellhd->ns_res <= 0)
-	    return (_("Illegal n-s resolution value"));
-	if (cellhd->ns_res3 <= 0)
-	    return (_("Illegal n-s3 resolution value"));
-    }
-    else {
-	if (cellhd->rows <= 0)
-	    return (_("Illegal row value"));
-	if (cellhd->rows3 <= 0)
-	    return (_("Illegal row3 value"));
-    }
-    if (!col_flag) {
-	if (cellhd->ew_res <= 0)
-	    return (_("Illegal e-w resolution value"));
-	if (cellhd->ew_res3 <= 0)
-	    return (_("Illegal e-w3 resolution value"));
-    }
-    else {
-	if (cellhd->cols <= 0)
-	    return (_("Illegal col value"));
-	if (cellhd->cols3 <= 0)
-	    return (_("Illegal col3 value"));
-    }
-    if (!depth_flag) {
-	if (cellhd->tb_res <= 0)
-	    return (_("Illegal t-b3 resolution value"));
-    }
-    else {
-	if (cellhd->depths <= 0)
-	    return (_("Illegal depths value"));
-    }
-
-    /* for lat/lon, check north,south. force east larger than west */
-    if (cellhd->proj == PROJECTION_LL) {
-	double epsilon_ns, epsilon_ew;
-
-	/* TODO: find good thresholds */
-	epsilon_ns = 1. / cellhd->rows * 0.001;
-	epsilon_ew = .000001;	/* epsilon_ew calculation doesn't work due to cellhd->cols update/global wraparound below */
-
-	G_debug(3, "Rast_adjust_Cell_head: epsilon_ns: %g, epsilon_ew: %g",
-		epsilon_ns, epsilon_ew);
-
-	/* TODO: once working, change below G_warning to G_debug */
-
-	/* fix rounding problems if input map slightly exceeds the world definition -180 90 180 -90 */
-	if (cellhd->north > 90.0) {
-	    if (((cellhd->north - 90.0) < epsilon_ns) &&
-		((cellhd->north - 90.0) > GRASS_EPSILON)) {
-		G_warning(_("Fixing subtle input data rounding error of north boundary (%g>%g)"),
-			  cellhd->north - 90.0, epsilon_ns);
-		cellhd->north = 90.0;
-	    }
-	    else
-		return (_("Illegal latitude for North"));
-	}
-
-	if (cellhd->south < -90.0) {
-	    if (((cellhd->south + 90.0) < epsilon_ns) &&
-		((cellhd->south + 90.0) < GRASS_EPSILON)) {
-		G_warning(_("Fixing subtle input data rounding error of south boundary (%g>%g)"),
-			  cellhd->south + 90.0, epsilon_ns);
-		cellhd->south = -90.0;
-	    }
-	    else
-		return (_("Illegal latitude for South"));
-	}
-
-#if 0
-	/* DISABLED: this breaks global wrap-around */
-
-	G_debug(3,
-		"Rast_adjust_Cell_head3() cellhd->west: %f, devi: %g, eps: %g",
-		cellhd->west, cellhd->west + 180.0, epsilon_ew);
-
-	if ((cellhd->west < -180.0) && ((cellhd->west + 180.0) < epsilon_ew)
-	    && ((cellhd->west + 180.0) < GRASS_EPSILON)) {
-	    G_warning(_("Fixing subtle input data rounding error of west boundary (%g>%g)"),
-		      cellhd->west + 180.0, epsilon_ew);
-	    cellhd->west = -180.0;
-	}
-
-	G_debug(3,
-		"Rast_adjust_Cell_head3() cellhd->east: %f, devi: %g, eps: %g",
-		cellhd->east, cellhd->east - 180.0, epsilon_ew);
-
-	if ((cellhd->east > 180.0) && ((cellhd->east - 180.0) > epsilon_ew)
-	    && ((cellhd->east - 180.0) > GRASS_EPSILON)) {
-	    G_warning(_("Fixing subtle input data rounding error of east boundary (%g>%g)"),
-		      cellhd->east - 180.0, epsilon_ew);
-	    cellhd->east = 180.0;
-	}
-#endif
-
-	while (cellhd->east <= cellhd->west)
-	    cellhd->east += 360.0;
-    }
-
-    /* check the edge values */
-    if (cellhd->north <= cellhd->south) {
-	if (cellhd->proj == PROJECTION_LL)
-	    return (_("North must be north of South"));
-	else
-	    return (_("North must be larger than South"));
-    }
-    if (cellhd->east <= cellhd->west)
-	return (_("East must be larger than West"));
-    if (cellhd->top <= cellhd->bottom)
-	return (_("Top must be larger than Bottom"));
-
-
-    /* compute rows and columns, if not set */
-    if (!row_flag) {
-	cellhd->rows =
-	    (cellhd->north - cellhd->south +
-	     cellhd->ns_res / 2.0) / cellhd->ns_res;
-	if (cellhd->rows == 0)
-	    cellhd->rows = 1;
-
-	cellhd->rows3 =
-	    (cellhd->north - cellhd->south +
-	     cellhd->ns_res3 / 2.0) / cellhd->ns_res3;
-	if (cellhd->rows3 == 0)
-	    cellhd->rows3 = 1;
-    }
-    if (!col_flag) {
-	cellhd->cols =
-	    (cellhd->east - cellhd->west +
-	     cellhd->ew_res / 2.0) / cellhd->ew_res;
-	if (cellhd->cols == 0)
-	    cellhd->cols = 1;
-
-	cellhd->cols3 =
-	    (cellhd->east - cellhd->west +
-	     cellhd->ew_res3 / 2.0) / cellhd->ew_res3;
-	if (cellhd->cols3 == 0)
-	    cellhd->cols3 = 1;
-    }
-
-    if (!depth_flag) {
-	cellhd->depths =
-	    (cellhd->top - cellhd->bottom +
-	     cellhd->tb_res / 2.0) / cellhd->tb_res;
-	if (cellhd->depths == 0)
-	    cellhd->depths = 1;
-
-    }
-
-    if (cellhd->cols < 0 || cellhd->rows < 0 || cellhd->cols3 < 0 ||
-	cellhd->rows3 < 0 || cellhd->depths < 0) {
-	return (_("Invalid coordinates"));
-    }
-
-    /* (re)compute the resolutions */
-    cellhd->ns_res = (cellhd->north - cellhd->south) / cellhd->rows;
-    cellhd->ns_res3 = (cellhd->north - cellhd->south) / cellhd->rows3;
-    cellhd->ew_res = (cellhd->east - cellhd->west) / cellhd->cols;
-    cellhd->ew_res3 = (cellhd->east - cellhd->west) / cellhd->cols3;
-    cellhd->tb_res = (cellhd->top - cellhd->bottom) / cellhd->depths;
-
-    return NULL;
-}

Modified: grass/trunk/lib/raster/get_cellhd.c
===================================================================
--- grass/trunk/lib/raster/get_cellhd.c	2009-06-20 22:49:13 UTC (rev 38004)
+++ grass/trunk/lib/raster/get_cellhd.c	2009-06-21 09:56:47 UTC (rev 38005)
@@ -90,7 +90,7 @@
 	}
     }
 
-    Rast__read_Cell_head(fd, cellhd, 1);
+    G__read_Cell_head(fd, cellhd, 1);
     fclose(fd);
 
     return 0;

Deleted: grass/trunk/lib/raster/rd_cellhd.c
===================================================================
--- grass/trunk/lib/raster/rd_cellhd.c	2009-06-20 22:49:13 UTC (rev 38004)
+++ grass/trunk/lib/raster/rd_cellhd.c	2009-06-21 09:56:47 UTC (rev 38005)
@@ -1,434 +0,0 @@
-/* read cell header, or window.
-   returns NULL if ok, error message otherwise
-   note:  the error message can be freed using G_free ().
- */
-#include <string.h>
-
-#include <grass/gis.h>
-#include <grass/Rast.h>
-#include <grass/glocale.h>
-
-#define ERROR(x,line) return error(x,line)
-static int scan_item(const char *, char *, char *);
-static int scan_int(const char *, int *);
-static double scan_double(const char *, double *);
-static char *error(const char *, int);
-
-#define F_PROJ   1
-#define F_ZONE   2
-#define F_NORTH  3
-#define F_SOUTH  4
-#define F_EAST   5
-#define F_WEST   6
-#define F_EWRES  7
-#define F_NSRES  8
-#define F_FORMAT 9
-#define F_COMP   10
-#define F_COLS   11
-#define F_ROWS   12
-
-#define F_EWRES3 13
-#define F_NSRES3 14
-#define F_COLS3  15
-#define F_ROWS3  16
-#define F_TOP    17
-#define F_BOTTOM 18
-#define F_TBRES  19
-#define F_DEPTHS 20
-
-#define SET(x) flags|=(1<<x)
-#define TEST(x) (flags&(1<<x))
-
-char *Rast__read_Cell_head_array(char **array,
-			      struct Cell_head *cellhd, int is_cellhd);
-
-char *Rast__read_Cell_head(FILE * fd, struct Cell_head *cellhd, int is_cellhd)
-{
-    int count;
-    char *result, **array;
-    char buf[1024];
-
-    G_debug(2, "Rast__read_Cell_head");
-
-    /* Count lines */
-    count = 0;
-    fseek(fd, 0L, 0);
-    while (G_getl(buf, sizeof(buf), fd))
-	count++;
-
-    array = (char **)G_calloc(count + 1, sizeof(char **));
-
-    count = 0;
-    fseek(fd, 0L, 0);
-    while (G_getl(buf, sizeof(buf), fd)) {
-	array[count] = G_store(buf);
-	count++;
-    }
-
-    result = Rast__read_Cell_head_array(array, cellhd, is_cellhd);
-
-    count = 0;
-    while (array[count]) {
-	G_free(array[count]);
-	count++;
-    }
-    G_free(array);
-
-    return result;
-}
-
-/* Read window from NULL terminated array of strings */
-char *Rast__read_Cell_head_array(char **array,
-			      struct Cell_head *cellhd, int is_cellhd)
-{
-    char *buf;
-    char label[200];
-    char value[200];
-    int i, line;
-    int flags;
-    const char *err;
-
-    G_debug(2, "Rast__read_Cell_head_array");
-
-    flags = 0;
-
-    /* initialize the cell header */
-    cellhd->format = 0;
-    cellhd->rows = 0;
-    cellhd->rows3 = 0;
-    cellhd->cols = 0;
-    cellhd->cols3 = 0;
-    cellhd->depths = 1;
-    cellhd->proj = -1;
-    cellhd->zone = -1;
-    cellhd->compressed = -1;
-    cellhd->ew_res = 0.0;
-    cellhd->ew_res3 = 1.0;
-    cellhd->ns_res = 0.0;
-    cellhd->ns_res3 = 1.0;
-    cellhd->tb_res = 1.0;
-    cellhd->north = 0.0;
-    cellhd->south = 0.0;
-    cellhd->east = 0.0;
-    cellhd->west = 0.0;
-    cellhd->top = 1.0;
-    cellhd->bottom = 0.0;
-
-    /* determine projection, zone first */
-
-    i = 0;
-    for (line = 1; (buf = array[i++]); line++) {
-	if (TEST(F_PROJ) && TEST(F_ZONE))
-	    break;
-
-	switch (scan_item(buf, label, value)) {
-	case -1:
-	    ERROR(buf, line);
-	case 0:
-	    continue;
-	case 1:
-	    break;
-	}
-	if (strncmp(label, "proj", 4) == 0) {
-	    if (TEST(F_PROJ))
-		ERROR(_("duplicate projection field"), line);
-
-	    if (!scan_int(value, &cellhd->proj))
-		ERROR(buf, line);
-
-	    SET(F_PROJ);
-	    continue;
-	}
-	if (strncmp(label, "zone", 4) == 0) {
-	    if (TEST(F_ZONE))
-		ERROR(_("duplicate zone field"), line);
-
-	    if (!scan_int(value, &cellhd->zone))
-		ERROR(buf, line);
-
-	    SET(F_ZONE);
-	    continue;
-	}
-    }
-    if (!TEST(F_PROJ))
-	ERROR(_("projection field missing"), 0);
-    if (!TEST(F_ZONE))
-	ERROR(_("zone field missing"), 0);
-
-    /* read the other info */
-    i = 0;
-    for (line = 1; (buf = array[i++]); line++) {
-	G_debug(3, "region item: %s", buf);
-	switch (scan_item(buf, label, value)) {
-	case -1:
-	    ERROR(buf, line);
-	case 0:
-	    continue;
-	case 1:
-	    break;
-	}
-
-	if (strncmp(label, "proj", 4) == 0)
-	    continue;
-	if (strncmp(label, "zone", 4) == 0)
-	    continue;
-
-	if (strncmp(label, "nort", 4) == 0) {
-	    if (TEST(F_NORTH))
-		ERROR(_("duplicate north field"), line);
-	    if (!G_scan_northing(value, &cellhd->north, cellhd->proj))
-		ERROR(buf, line);
-	    SET(F_NORTH);
-	    continue;
-	}
-	if (strncmp(label, "sout", 4) == 0) {
-	    if (TEST(F_SOUTH))
-		ERROR(_("duplicate south field"), line);
-	    if (!G_scan_northing(value, &cellhd->south, cellhd->proj))
-		ERROR(buf, line);
-	    SET(F_SOUTH);
-	    continue;
-	}
-	if (strncmp(label, "east", 4) == 0) {
-	    if (TEST(F_EAST))
-		ERROR(_("duplicate east field"), line);
-	    if (!G_scan_easting(value, &cellhd->east, cellhd->proj))
-		ERROR(buf, line);
-	    SET(F_EAST);
-	    continue;
-	}
-	if (strncmp(label, "west", 4) == 0) {
-	    if (TEST(F_WEST))
-		ERROR(_("duplicate west field"), line);
-	    if (!G_scan_easting(value, &cellhd->west, cellhd->proj))
-		ERROR(buf, line);
-	    SET(F_WEST);
-	    continue;
-	}
-	if (strncmp(label, "top", 3) == 0) {
-	    if (TEST(F_TOP))
-		ERROR(_("duplicate top field"), line);
-	    if (!scan_double(value, &cellhd->top))
-		ERROR(buf, line);
-	    SET(F_TOP);
-	    continue;
-	}
-	if (strncmp(label, "bottom", 6) == 0) {
-	    if (TEST(F_BOTTOM))
-		ERROR(_("duplicate bottom field"), line);
-	    if (!scan_double(value, &cellhd->bottom))
-		ERROR(buf, line);
-	    SET(F_BOTTOM);
-	    continue;
-	}
-	if (strncmp(label, "e-w ", 4) == 0 && strlen(label) == 9) {
-	    if (TEST(F_EWRES))
-		ERROR(_("duplicate e-w resolution field"), line);
-	    if (!G_scan_resolution(value, &cellhd->ew_res, cellhd->proj))
-		ERROR(buf, line);
-	    if (cellhd->ew_res <= 0.0)
-		ERROR(buf, line);
-	    SET(F_EWRES);
-	    continue;
-	}
-	if (strncmp(label, "e-w resol3", 10) == 0) {
-	    if (TEST(F_EWRES3))
-		ERROR(_("duplicate 3D e-w resolution field"), line);
-	    if (!G_scan_resolution(value, &cellhd->ew_res3, cellhd->proj))
-		ERROR(buf, line);
-	    if (cellhd->ew_res3 <= 0.0)
-		ERROR(buf, line);
-	    SET(F_EWRES3);
-	    continue;
-	}
-	if (strncmp(label, "n-s ", 4) == 0 && strlen(label) == 9) {
-	    if (TEST(F_NSRES))
-		ERROR(_("duplicate n-s resolution field"), line);
-	    if (!G_scan_resolution(value, &cellhd->ns_res, cellhd->proj))
-		ERROR(buf, line);
-	    if (cellhd->ns_res <= 0.0)
-		ERROR(buf, line);
-	    SET(F_NSRES);
-	    continue;
-	}
-	if (strncmp(label, "n-s resol3", 10) == 0) {
-	    if (TEST(F_NSRES3))
-		ERROR(_("duplicate 3D n-s resolution field"), line);
-	    if (!G_scan_resolution(value, &cellhd->ns_res3, cellhd->proj))
-		ERROR(buf, line);
-	    if (cellhd->ns_res3 <= 0.0)
-		ERROR(buf, line);
-	    SET(F_NSRES3);
-	    continue;
-	}
-	if (strncmp(label, "t-b ", 4) == 0) {
-	    if (TEST(F_TBRES))
-		ERROR(_("duplicate t-b resolution field"), line);
-	    if (!scan_double(value, &cellhd->tb_res))
-		ERROR(buf, line);
-	    if (cellhd->tb_res <= 0.0)
-		ERROR(buf, line);
-	    SET(F_TBRES);
-	    continue;
-	}
-	if (strncmp(label, "rows", 4) == 0 && strlen(label) == 4) {
-	    if (TEST(F_ROWS))
-		ERROR(_("duplicate rows field"), line);
-	    if (!scan_int(value, &cellhd->rows))
-		ERROR(buf, line);
-	    if (cellhd->rows <= 0)
-		ERROR(buf, line);
-	    SET(F_ROWS);
-	    continue;
-	}
-	if (strncmp(label, "rows3", 5) == 0) {
-	    if (TEST(F_ROWS3))
-		ERROR(_("duplicate 3D rows field"), line);
-	    if (!scan_int(value, &cellhd->rows3))
-		ERROR(buf, line);
-	    if (cellhd->rows3 <= 0)
-		ERROR(buf, line);
-	    SET(F_ROWS3);
-	    continue;
-	}
-	if (strncmp(label, "cols", 4) == 0 && strlen(label) == 4) {
-	    if (TEST(F_COLS))
-		ERROR(_("duplicate cols field"), line);
-	    if (!scan_int(value, &cellhd->cols))
-		ERROR(buf, line);
-	    if (cellhd->cols <= 0)
-		ERROR(buf, line);
-	    SET(F_COLS);
-	    continue;
-	}
-	if (strncmp(label, "cols3", 5) == 0) {
-	    if (TEST(F_COLS3))
-		ERROR(_("duplicate 3D cols field"), line);
-	    if (!scan_int(value, &cellhd->cols3))
-		ERROR(buf, line);
-	    if (cellhd->cols3 <= 0)
-		ERROR(buf, line);
-	    SET(F_COLS3);
-	    continue;
-	}
-	if (strncmp(label, "depths", 6) == 0) {
-	    if (TEST(F_DEPTHS))
-		ERROR(_("duplicate depths field"), line);
-	    if (!scan_int(value, &cellhd->depths))
-		ERROR(buf, line);
-	    if (cellhd->depths <= 0)
-		ERROR(buf, line);
-	    SET(F_DEPTHS);
-	    continue;
-	}
-	if (strncmp(label, "form", 4) == 0) {
-	    if (TEST(F_FORMAT))
-		ERROR(_("duplicate format field"), line);
-	    if (!scan_int(value, &cellhd->format))
-		ERROR(buf, line);
-	    SET(F_FORMAT);
-	    continue;
-	}
-	if (strncmp(label, "comp", 4) == 0) {
-	    if (TEST(F_COMP))
-		ERROR(_("duplicate compressed field"), line);
-	    if (!scan_int(value, &cellhd->compressed))
-		ERROR(buf, line);
-	    SET(F_COMP);
-	    continue;
-	}
-	ERROR(buf, line);
-    }
-
-    /* check some of the fields */
-    if (!TEST(F_NORTH))
-	ERROR(_("north field missing"), 0);
-    if (!TEST(F_SOUTH))
-	ERROR(_("south field missing"), 0);
-    if (!TEST(F_WEST))
-	ERROR(_("west field missing"), 0);
-    if (!TEST(F_EAST))
-	ERROR(_("east field missing"), 0);
-    if (!TEST(F_EWRES) && !TEST(F_COLS))
-	ERROR(_("cols field missing"), 0);
-    if (!TEST(F_NSRES) && !TEST(F_ROWS))
-	ERROR(_("rows field missing"), 0);
-    /* This next stmt is commented out to allow wr_cellhd.c to write
-     * headers that will be readable by GRASS 3.1
-     if ((TEST(F_ROWS) && TEST(F_NSRES))
-     ||  (TEST(F_COLS) && TEST(F_EWRES)))
-     ERROR ("row/col and resolution information can not both appear ",0);
-     */
-
-    /* 3D defined? */
-    if (TEST(F_EWRES3) || TEST(F_NSRES3) || TEST(F_COLS3) || TEST(F_ROWS3)) {
-	if (!TEST(F_EWRES3))
-	    ERROR(_("ewres3 field missing"), 0);
-	if (!TEST(F_NSRES3))
-	    ERROR(_("nsres3 field missing"), 0);
-	if (!TEST(F_COLS3))
-	    ERROR(_("cols3 field missing"), 0);
-	if (!TEST(F_ROWS3))
-	    ERROR(_("rows3 field missing"), 0);
-    }
-    else {			/* use 2D */
-	cellhd->ew_res3 = cellhd->ew_res;
-	cellhd->ns_res3 = cellhd->ns_res;
-	cellhd->cols3 = cellhd->cols;
-	cellhd->rows3 = cellhd->rows;
-    }
-
-    /* Adjust and complete the cell header  */
-    if ((err = Rast_adjust_Cell_head(cellhd, TEST(F_ROWS), TEST(F_COLS))))
-	ERROR(err, 0);
-
-
-    return NULL;
-}
-
-static int scan_item(const char *buf, char *label, char *value)
-{
-    /* skip blank lines */
-    if (sscanf(buf, "%1s", label) != 1)
-	return 0;
-
-    /* skip comment lines */
-    if (*label == '#')
-	return 0;
-
-    /* must be label: value */
-    if (sscanf(buf, "%[^:]:%[^\n]", label, value) != 2)
-	return -1;
-
-    G_strip(label);
-    G_strip(value);
-    return 1;
-}
-
-static int scan_int(const char *buf, int *n)
-{
-    char dummy[3];
-
-    *dummy = 0;
-    return (sscanf(buf, "%d%1s", n, dummy) == 1 && *dummy == 0);
-}
-
-static double scan_double(const char *buf, double *n)
-{
-    char dummy[3];
-
-    *dummy = 0;
-    return (sscanf(buf, "%lf%1s", n, dummy) == 1 && *dummy == 0);
-}
-
-static char *error(const char *msg, int line)
-{
-    char buf[1024];
-
-    if (line)
-	sprintf(buf, _("line %d: <%s>"), line, msg);
-    else
-	sprintf(buf, "<%s>", msg);
-
-    return G_store(buf);
-}



More information about the grass-commit mailing list