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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jun 21 06:39:22 EDT 2009


Author: martinl
Date: 2009-06-21 06:39:22 -0400 (Sun, 21 Jun 2009)
New Revision: 38006

Added:
   grass/trunk/lib/raster/init.c
   grass/trunk/lib/raster/set_window.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/gisinit.c
   grass/trunk/lib/gis/rd_cellhd.c
   grass/trunk/lib/gis/set_window.c
   grass/trunk/lib/raster/
Log:
remove rasterlib dependency from libgis (todo: clean-up G__ & libraries initialization)


Modified: grass/trunk/include/Rast.h
===================================================================
--- grass/trunk/include/Rast.h	2009-06-21 09:56:47 UTC (rev 38005)
+++ grass/trunk/include/Rast.h	2009-06-21 10:39:22 UTC (rev 38006)
@@ -522,6 +522,10 @@
 DCELL Rast_get_raster_sample_cubic(int, const struct Cell_head *, struct Categories *, double, double, int);
 DCELL Rast_get_raster_sample(int, const struct Cell_head *, struct Categories *, double, double, int, INTERP_TYPE);
 
+/* set_window.c */
+void Rast_get_set_window(struct Cell_head *);
+int Rast_set_window(struct Cell_head *);
+
 /* zero_cell.c */
 void Rast_zero_cell_buf(CELL *);
 void Rast_zero_raster_buf(void *, RASTER_MAP_TYPE);

Modified: grass/trunk/include/gisdefs.h
===================================================================
--- grass/trunk/include/gisdefs.h	2009-06-21 09:56:47 UTC (rev 38005)
+++ grass/trunk/include/gisdefs.h	2009-06-21 10:39:22 UTC (rev 38006)
@@ -536,7 +536,6 @@
 
 /* set_window.c */
 void G_get_set_window(struct Cell_head *);
-int G_set_window(struct Cell_head *);
 
 /* short_way.c */
 void G_shortest_way(double *, double *);

Modified: grass/trunk/lib/gis/align_window.c
===================================================================
--- grass/trunk/lib/gis/align_window.c	2009-06-21 09:56:47 UTC (rev 38005)
+++ grass/trunk/lib/gis/align_window.c	2009-06-21 10:39:22 UTC (rev 38006)
@@ -13,8 +13,8 @@
 
 #include <stdio.h>
 #include <math.h>
+
 #include <grass/gis.h>
-#include <grass/Rast.h>
 
 /*!
  * \brief Align two regions.

Modified: grass/trunk/lib/gis/get_window.c
===================================================================
--- grass/trunk/lib/gis/get_window.c	2009-06-21 09:56:47 UTC (rev 38005)
+++ grass/trunk/lib/gis/get_window.c	2009-06-21 10:39:22 UTC (rev 38006)
@@ -14,7 +14,6 @@
 #include <stdlib.h>
 
 #include <grass/gis.h>
-#include <grass/Rast.h>
 #include <grass/glocale.h>
 
 #include "../raster/G.h"

Modified: grass/trunk/lib/gis/gisinit.c
===================================================================
--- grass/trunk/lib/gis/gisinit.c	2009-06-21 09:56:47 UTC (rev 38005)
+++ grass/trunk/lib/gis/gisinit.c	2009-06-21 10:39:22 UTC (rev 38006)
@@ -22,7 +22,6 @@
 #include <locale.h>
 
 #include <grass/gis.h>
-#include <grass/Rast.h>
 #include <grass/glocale.h>
 
 #include "../raster/G.h"
@@ -141,12 +140,10 @@
     G_init_env();
     G_init_logging();
     G__init_window();
-    Rast__check_for_auto_masking();
     G_init_locale();
     G_init_debug();
     G_verbose();
     G_init_tempfile();
-    Rast_init_gdal();
     G_get_list_of_mapsets();
     G__home();
     G__machine_name();
@@ -154,4 +151,3 @@
     G_read_datum_table();
     G_read_ellipsoid_table(0);
 }
-

Modified: grass/trunk/lib/gis/rd_cellhd.c
===================================================================
--- grass/trunk/lib/gis/rd_cellhd.c	2009-06-21 09:56:47 UTC (rev 38005)
+++ grass/trunk/lib/gis/rd_cellhd.c	2009-06-21 10:39:22 UTC (rev 38006)
@@ -5,7 +5,6 @@
 #include <string.h>
 
 #include <grass/gis.h>
-#include <grass/Rast.h>
 #include <grass/glocale.h>
 
 #define ERROR(x,line) return error(x,line)

Modified: grass/trunk/lib/gis/set_window.c
===================================================================
--- grass/trunk/lib/gis/set_window.c	2009-06-21 09:56:47 UTC (rev 38005)
+++ grass/trunk/lib/gis/set_window.c	2009-06-21 10:39:22 UTC (rev 38006)
@@ -12,8 +12,8 @@
  */
 
 #include <grass/gis.h>
-#include <grass/Rast.h>
 #include <grass/glocale.h>
+
 #include "../raster/G.h"
 
 /*!
@@ -29,115 +29,3 @@
     G__init_window();
     G_copy(window, &G__.window, sizeof(*window));
 }
-
-
-/*!
- * \brief Establishes 'window' as the current working window.
- * 
- * Any opened cell files has its file-to-window mapping reworked.
- *
- * \param window window to become operative window
- * 
- * \return -1 on error
- * \return  1 on success
- */
-int G_set_window(struct Cell_head *window)
-{
-    int i;
-    int maskfd;
-    const char *err;
-
-    /* adjust window, check for valid window */
-    /* adjust the real one, not a copy
-       G_copy (&twindow, window, sizeof(struct Cell_head));
-       window = &twindow;
-     */
-
-    if ((err = G_adjust_Cell_head(window, 0, 0))) {
-	G_warning("G_set_window(): %s", err);
-	return -1;
-    }
-
-    /* except for MASK, cell files open for read must have same projection
-     * and zone as new window
-     */
-    maskfd = G__.auto_mask > 0 ? G__.mask_fd : -1;
-    for (i = 0; i < G__.fileinfo_count; i++) {
-	struct fileinfo *fcb = &G__.fileinfo[i];
-	if (fcb->open_mode == OPEN_OLD) {
-	    if (fcb->cellhd.zone == window->zone &&
-		fcb->cellhd.proj == window->proj)
-		continue;
-	    if (i != maskfd) {
-		G_warning(_("G_set_window(): projection/zone differs from that of "
-			    "currently open raster maps"));
-		return -1;
-	    }
-	}
-    }
-
-    /* close the mask */
-    if (G__.auto_mask > 0) {
-	Rast_close_cell(maskfd);
-	/* G_free (G__.mask_buf); */
-	G__.mask_fd = -1;
-	G__.auto_mask = -1;	/* turn off masking */
-    }
-
-    /* copy the window to the current window */
-    G_copy((char *)&G__.window, (char *)window, sizeof(*window));
-
-    G__.window_set = 1;
-
-    /* now for each possible open cell file, recreate the window mapping */
-    /*
-     * also the memory for reading and writing must be reallocated for all opened
-     * cell files
-     */
-    for (i = 0; i < G__.fileinfo_count; i++) {
-	struct fileinfo *fcb = &G__.fileinfo[i];
-
-	if (fcb->open_mode != OPEN_OLD &&
-	    fcb->open_mode != OPEN_NEW_UNCOMPRESSED &&
-	    fcb->open_mode != OPEN_NEW_COMPRESSED)
-	    continue;
-
-	if (fcb->open_mode == OPEN_OLD)
-	    G__create_window_mapping(i);
-	/* code commented 10/1999 due to problems */
-#if 0
-	else
-	{
-	    /* opened for writing */
-	    G_free (fcb->data);
-	    fcb->data = (unsigned char *) G_calloc (G__.window.cols,
-						    Rast_raster_size(fcb->map_type));
-	}
-
-	/* allocate null bitstream buffers for reading/writing null rows */
-	for (j=0;j< NULL_ROWS_INMEM; j++)
-	{
-	    G_free (fcb->NULL_ROWS[j]);
-	    fcb->NULL_ROWS[j] = (G__.window.cols);
-	}
-
-
-	/* initialize : no NULL rows in memory */
-	fcb->min_null_row = (-1) * NULL_ROWS_INMEM;
-	if(fcb->null_cur_row > 0)
-	{
-	  G_warning(_("Calling G_set_window() in the middle of writing map %s"), 
-		    fcb->name);
-	    fcb->null_cur_row = 0;
-	}
-#endif
-    }
-
-    /* turn masking (back) on if necessary */
-    Rast__check_for_auto_masking();
-
-    /* we want the number of bytes per cell to be maximum
-       so that there is enough memory for reading and writing rows */
-
-    return 1;
-}


Property changes on: grass/trunk/lib/raster
___________________________________________________________________
Name: svn:ignore
   + OBJ.*


Added: grass/trunk/lib/raster/init.c
===================================================================
--- grass/trunk/lib/raster/init.c	                        (rev 0)
+++ grass/trunk/lib/raster/init.c	2009-06-21 10:39:22 UTC (rev 38006)
@@ -0,0 +1,94 @@
+/**
+ * \file gisinit.c
+ * 
+ * \brief GIS Library - Handles program initialization.
+ *
+ * (C) 2001-2008 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 GRASS GIS Development Team
+ *
+ * \date 2000-2008
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <locale.h>
+
+#include <grass/gis.h>
+#include <grass/Rast.h>
+#include <grass/glocale.h>
+
+#include "../raster/G.h"
+
+struct G__ G__;
+
+static int initialized = 0; /** Is set when engine is initialized */
+static int init(void);
+
+/**
+ * \brief Initialize GRASS GIS engine.
+ *
+ * Initializes GIS engine and ensures a valid mapset is available.
+ *
+ * \param[in] pgm Program (module) name
+ * \return always returns 0 on success
+ * \return exit() is called on error
+ */
+
+void Rast__gisinit()
+{
+    if (initialized)
+	return;
+
+    init();
+}
+
+
+/**
+ * \brief Checks to see if GIS engine is initialized.
+ *
+ * \return
+ */
+
+void Rast__check_gisinit(void)
+{
+    if (initialized)
+	return;
+
+    G_fatal_error(_("Raster library not initialized. Programmer forgot to call Rast_init()."));
+}
+
+
+static int init(void)
+{
+    /* Mark window as not set */
+    G__.window_set = 0;
+
+    /* no histograms */
+    G__.want_histogram = 0;
+
+    /* set the write type for floating maps */
+    G__.fp_type = getenv("GRASS_FP_DOUBLE") ? DCELL_TYPE : FCELL_TYPE;
+
+    /* Set masking flag unknown */
+    G__.auto_mask = -1;
+
+    G__.nbytes = sizeof(CELL);
+    G__.compression_type = getenv("GRASS_INT_ZLIB") ? 2 : 1;
+
+    initialized = 1;
+
+    return 0;
+}
+
+void Rast_init_all(void)
+{
+    Rast__check_for_auto_masking();
+    Rast_init_gdal();
+}

Copied: grass/trunk/lib/raster/set_window.c (from rev 38005, grass/trunk/lib/gis/set_window.c)
===================================================================
--- grass/trunk/lib/raster/set_window.c	                        (rev 0)
+++ grass/trunk/lib/raster/set_window.c	2009-06-21 10:39:22 UTC (rev 38006)
@@ -0,0 +1,144 @@
+/*!
+ * \file gis/set_window.c
+ *
+ * \brief GIS Library - Set window (map region)
+ *
+ * (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/Rast.h>
+#include <grass/glocale.h>
+
+#include "G.h"
+
+/*!
+ * \brief Get the current working window (region)
+ *
+ * The current working window values are returned in the structure
+ * <i>window</i>.
+ *
+ * \param[in,out] window window structure to be set
+ */
+void Rast_get_set_window(struct Cell_head *window)
+{
+    G__init_window();
+    G_copy(window, &G__.window, sizeof(*window));
+}
+
+
+/*!
+ * \brief Establishes 'window' as the current working window.
+ * 
+ * Any opened cell files has its file-to-window mapping reworked.
+ *
+ * \param window window to become operative window
+ * 
+ * \return -1 on error
+ * \return  1 on success
+ */
+int Rast_set_window(struct Cell_head *window)
+{
+    int i;
+    int maskfd;
+    const char *err;
+
+    /* adjust window, check for valid window */
+    /* adjust the real one, not a copy
+       G_copy (&twindow, window, sizeof(struct Cell_head));
+       window = &twindow;
+     */
+
+    if ((err = G_adjust_Cell_head(window, 0, 0))) {
+	G_warning("G_set_window(): %s", err);
+	return -1;
+    }
+
+    /* except for MASK, cell files open for read must have same projection
+     * and zone as new window
+     */
+    maskfd = G__.auto_mask > 0 ? G__.mask_fd : -1;
+    for (i = 0; i < G__.fileinfo_count; i++) {
+	struct fileinfo *fcb = &G__.fileinfo[i];
+	if (fcb->open_mode == OPEN_OLD) {
+	    if (fcb->cellhd.zone == window->zone &&
+		fcb->cellhd.proj == window->proj)
+		continue;
+	    if (i != maskfd) {
+		G_warning(_("G_set_window(): projection/zone differs from that of "
+			    "currently open raster maps"));
+		return -1;
+	    }
+	}
+    }
+
+    /* close the mask */
+    if (G__.auto_mask > 0) {
+	Rast_close_cell(maskfd);
+	/* G_free (G__.mask_buf); */
+	G__.mask_fd = -1;
+	G__.auto_mask = -1;	/* turn off masking */
+    }
+
+    /* copy the window to the current window */
+    G_copy((char *)&G__.window, (char *)window, sizeof(*window));
+
+    G__.window_set = 1;
+
+    /* now for each possible open cell file, recreate the window mapping */
+    /*
+     * also the memory for reading and writing must be reallocated for all opened
+     * cell files
+     */
+    for (i = 0; i < G__.fileinfo_count; i++) {
+	struct fileinfo *fcb = &G__.fileinfo[i];
+
+	if (fcb->open_mode != OPEN_OLD &&
+	    fcb->open_mode != OPEN_NEW_UNCOMPRESSED &&
+	    fcb->open_mode != OPEN_NEW_COMPRESSED)
+	    continue;
+
+	if (fcb->open_mode == OPEN_OLD)
+	    G__create_window_mapping(i);
+	/* code commented 10/1999 due to problems */
+#if 0
+	else
+	{
+	    /* opened for writing */
+	    G_free (fcb->data);
+	    fcb->data = (unsigned char *) G_calloc (G__.window.cols,
+						    Rast_raster_size(fcb->map_type));
+	}
+
+	/* allocate null bitstream buffers for reading/writing null rows */
+	for (j=0;j< NULL_ROWS_INMEM; j++)
+	{
+	    G_free (fcb->NULL_ROWS[j]);
+	    fcb->NULL_ROWS[j] = (G__.window.cols);
+	}
+
+
+	/* initialize : no NULL rows in memory */
+	fcb->min_null_row = (-1) * NULL_ROWS_INMEM;
+	if(fcb->null_cur_row > 0)
+	{
+	  G_warning(_("Calling G_set_window() in the middle of writing map %s"), 
+		    fcb->name);
+	    fcb->null_cur_row = 0;
+	}
+#endif
+    }
+
+    /* turn masking (back) on if necessary */
+    Rast__check_for_auto_masking();
+
+    /* we want the number of bytes per cell to be maximum
+       so that there is enough memory for reading and writing rows */
+
+    return 1;
+}



More information about the grass-commit mailing list