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

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jun 22 02:35:25 EDT 2009


Author: glynn
Date: 2009-06-22 02:35:20 -0400 (Mon, 22 Jun 2009)
New Revision: 38019

Added:
   grass/trunk/lib/gis/G.h
   grass/trunk/lib/raster/R.h
   grass/trunk/lib/raster/window_map.c
Removed:
   grass/trunk/lib/raster/G.h
Modified:
   grass/trunk/include/Make/Grass.make
   grass/trunk/include/Make/Platform.make.in
   grass/trunk/include/gisdefs.h
   grass/trunk/include/raster.h
   grass/trunk/lib/gis/Makefile
   grass/trunk/lib/gis/debug.c
   grass/trunk/lib/gis/get_window.c
   grass/trunk/lib/gis/gisinit.c
   grass/trunk/lib/gis/set_window.c
   grass/trunk/lib/gis/window_map.c
   grass/trunk/lib/raster/Makefile
   grass/trunk/lib/raster/auto_mask.c
   grass/trunk/lib/raster/closecell.c
   grass/trunk/lib/raster/color_read.c
   grass/trunk/lib/raster/format.c
   grass/trunk/lib/raster/gdal.c
   grass/trunk/lib/raster/get_row.c
   grass/trunk/lib/raster/get_row_colr.c
   grass/trunk/lib/raster/init.c
   grass/trunk/lib/raster/maskfd.c
   grass/trunk/lib/raster/opencell.c
   grass/trunk/lib/raster/put_row.c
   grass/trunk/lib/raster/range.c
   grass/trunk/lib/raster/set_window.c
Log:
Split G__ between lib/gis and lib/raster
Move relevant parts of window_map.c to lib/raster
Remove zlib references from XDRLIB
Remove XDRLIB, SOCKLIB references from GISLIB


Modified: grass/trunk/include/Make/Grass.make
===================================================================
--- grass/trunk/include/Make/Grass.make	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/include/Make/Grass.make	2009-06-22 06:35:20 UTC (rev 38019)
@@ -219,7 +219,7 @@
 CAIRODRIVERLIB= -l$(CAIRODRIVER_LIBNAME) $(DRIVERLIB) $(GISLIB)
 HTMLDRIVERLIB = -l$(HTMLDRIVER_LIBNAME) $(DRIVERLIB) $(GISLIB)
 G3DLIB        = -l$(G3D_LIBNAME) $(GISLIB) 
-GISLIB        = -l$(GIS_LIBNAME) $(DATETIMELIB) $(XDRLIB) $(SOCKLIB) $(INTLLIB) 
+GISLIB        = -l$(GIS_LIBNAME) $(DATETIMELIB) $(INTLLIB) $(ZLIBLIB)
 GMATHLIB      = -l$(GMATH_LIBNAME) $(GISLIB) 
 GPDELIB       = -l$(GPDE_LIBNAME) $(GISLIB) $(G3DLIB)
 GPROJLIB      = -l$(GPROJ_LIBNAME) $(GISLIB) $(PROJLIB) $(GDALLIBS) 
@@ -232,7 +232,7 @@
 LINKMLIB      = -l$(LINKM_LIBNAME)
 LOCKLIB       = -l$(LOCK_LIBNAME)
 MANAGELIB     = -l$(MANAGE_LIBNAME)
-RASTERLIB     = -l$(RASTER_LIBNAME) $(GISLIB)
+RASTERLIB     = -l$(RASTER_LIBNAME) $(GISLIB) $(XDRLIB) $(SOCKLIB)
 ROWIOLIB      = -l$(ROWIO_LIBNAME)
 SEGMENTLIB    = -l$(SEGMENT_LIBNAME) $(GISLIB) 
 STATSLIB      = -l$(STATS_LIBNAME) $(GISLIB) 

Modified: grass/trunk/include/Make/Platform.make.in
===================================================================
--- grass/trunk/include/Make/Platform.make.in	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/include/Make/Platform.make.in	2009-06-22 06:35:20 UTC (rev 38019)
@@ -91,13 +91,13 @@
 USE_X11             = @USE_X11@
 
 MATHLIB             = @MATHLIB@ 
-XDRLIB              = @XDRLIB@ @ZLIBINCPATH@ @ZLIBLIBPATH@ @ZLIB@
+XDRLIB              = @XDRLIB@
 ICONVLIB            = @ICONVLIB@
 INTLLIB             = @INTLLIB@
 SOCKLIB             = @SOCKLIB@
 
 #ZLIB:
-ZLIB                = @ZLIBINCPATH@ @ZLIBLIBPATH@ @ZLIB@
+ZLIB                = @ZLIB@
 ZLIBINCPATH         = @ZLIBINCPATH@
 ZLIBLIBPATH         = @ZLIBLIBPATH@
 

Modified: grass/trunk/include/gisdefs.h
===================================================================
--- grass/trunk/include/gisdefs.h	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/include/gisdefs.h	2009-06-22 06:35:20 UTC (rev 38019)
@@ -647,7 +647,6 @@
 int G_scan_resolution(const char *, double *, int);
 
 /* window_map.c */
-void G__create_window_mapping(int);
 double G_northing_to_row(double, const struct Cell_head *);
 double G_adjust_east_longitude(double, double);
 double G_adjust_easting(double, const struct Cell_head *);
@@ -657,7 +656,6 @@
 int G_window_rows(void);
 int G_window_cols(void);
 void G__init_window(void);
-int G_row_repeat_nomask(int, int);
 
 /* worker.c */
 void G_begin_execute(void (*func)(void *), void *, void **, int);

Modified: grass/trunk/include/raster.h
===================================================================
--- grass/trunk/include/raster.h	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/include/raster.h	2009-06-22 06:35:20 UTC (rev 38019)
@@ -530,6 +530,11 @@
 /* set_window.c */
 int Rast_set_window(struct Cell_head *);
 
+/* window_map.c */
+void Rast__init_window(void);
+void Rast__create_window_mapping(int);
+int Rast_row_repeat_nomask(int, int);
+
 /* zero_cell.c */
 void Rast_zero_cell_buf(CELL *);
 void Rast_zero_raster_buf(void *, RASTER_MAP_TYPE);

Copied: grass/trunk/lib/gis/G.h (from rev 38014, grass/trunk/lib/raster/G.h)
===================================================================
--- grass/trunk/lib/gis/G.h	                        (rev 0)
+++ grass/trunk/lib/gis/G.h	2009-06-22 06:35:20 UTC (rev 38019)
@@ -0,0 +1,10 @@
+#include <grass/config.h>
+#include <grass/gis.h>
+
+struct G__			/*  Structure of library globals */
+{
+    struct Cell_head window;	/* Contains the current window          */
+    int window_set;		/* Flag: window set?                    */
+};
+
+extern struct G__ G__;		/* allocated in gisinit */

Modified: grass/trunk/lib/gis/Makefile
===================================================================
--- grass/trunk/lib/gis/Makefile	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/gis/Makefile	2009-06-22 06:35:20 UTC (rev 38019)
@@ -2,8 +2,8 @@
 
 LIB_NAME = $(GIS_LIBNAME)
 
-EXTRA_LIBS = $(XDRLIB) $(SOCKLIB) $(DATETIMELIB) $(PTHREADLIBPATH) $(PTHREADLIB) \
-	$(INTLLIB) $(MATHLIB)
+EXTRA_LIBS = $(DATETIMELIB) $(PTHREADLIBPATH) $(PTHREADLIB) \
+	$(INTLLIB) $(MATHLIB) $(ZLIBLIBPATH) $(ZLIB)
 EXTRA_INC = $(ZLIBINCPATH) $(PTHREADINCPATH)
 
 DATASRC = ellipse.table datum.table datumtransform.table FIPS.code state27 state83 projections
@@ -49,12 +49,10 @@
 
 $(OBJDIR)/area_ellipse.o: pi.h
 $(OBJDIR)/area_sphere.o: pi.h
-$(OBJDIR)/debug.o: ../raster/G.h
 $(OBJDIR)/geodesic.o: pi.h
 $(OBJDIR)/geodist.o: pi.h
-$(OBJDIR)/get_window.o: ../raster/G.h
-$(OBJDIR)/gisinit.o: ../raster/G.h
+$(OBJDIR)/get_window.o: G.h
+$(OBJDIR)/gisinit.o: G.h
 $(OBJDIR)/radii.o: pi.h
 $(OBJDIR)/rhumbline.o: pi.h
-$(OBJDIR)/set_window.o: ../raster/G.h
-$(OBJDIR)/window_map.o: ../raster/G.h
+$(OBJDIR)/set_window.o: G.h

Modified: grass/trunk/lib/gis/debug.c
===================================================================
--- grass/trunk/lib/gis/debug.c	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/gis/debug.c	2009-06-22 06:35:20 UTC (rev 38019)
@@ -21,8 +21,6 @@
 #include <grass/gis.h>
 #include <grass/glocale.h>
 
-#include "../raster/G.h"
-
 static int initialized;
 static int grass_debug_level;
 
@@ -102,58 +100,3 @@
     return 1;
 }
 
-
-/**
- * \brief Dumps status of various GIS parameters.
- * 
- * Dumps status of various GIS parameters of a particular
- * file descriptor, <b>fd</b>.
- *
- * \param[in] fd file
- * \return always returns 0
-*/
-
-int G_dump(int fd)
-{
-    const struct fileinfo *fcb = &G__.fileinfo[fd];
-
-    G_message("G_dump: memory allocated to G__");
-    G_message("type for writing floating maps = %d", G__.fp_type);
-    G_message("current window = %p", &G__.window);
-    G_message("Flag: window set? %d", G__.window_set);
-    G_message("File descriptor for automatic mask %d", G__.mask_fd);
-    G_message("Flag denoting automatic masking %d", G__.auto_mask);
-    G_message("Histogram request %d", G__.want_histogram);
-
-    G_message("G_dump: file #%d", fd);
-    G_message("open mode = %d", fcb->open_mode);
-    G_message("Cell header %p", &fcb->cellhd);
-    G_message("Table reclass %p", &fcb->reclass);
-    G_message("Cell stats %p", &fcb->statf);
-    G_message("Range structure %p", &fcb->range);
-    G_message("float Range structure %p", &fcb->fp_range);
-    G_message("want histogram?  %d", fcb->want_histogram);
-    G_message("Automatic reclass flag %d", fcb->reclass_flag);
-    G_message("File row addresses %p", fcb->row_ptr);
-    G_message("Data to window col mapping %p", fcb->col_map);
-    G_message("Data to window row constants %f,%f", fcb->C1, fcb->C2);
-    G_message("Current data row in memory %d", fcb->cur_row);
-    G_message("Current null row in memory %d", fcb->null_cur_row);
-    G_message("nbytes per cell for current row %d", fcb->cur_nbytes);
-    G_message("Decompressed data buffer %s", fcb->data);
-    G_message("bytes per cell %d", fcb->nbytes);
-    G_message("type: int, float or double map %d", fcb->map_type);
-    G_message("Temporary name for NEW files %s", fcb->temp_name);
-    G_message("Temporary name for NEW NULL files %s", fcb->null_temp_name);
-    G_message("for existing raster maps %d", fcb->null_file_exists);
-    G_message("Name of open file %s", fcb->name);
-    G_message("Mapset of open file %s", fcb->mapset);
-    G_message("io error warning given %d", fcb->io_error);
-    G_message("xdr stream for reading fp %p", &fcb->xdrstream);
-    G_message("NULL_ROWS array[%d] = %p", NULL_ROWS_INMEM, fcb->NULL_ROWS);
-    G_message("Minimum row null number in memory %d", fcb->min_null_row);
-    G_message("Quant ptr = %p", &fcb->quant);
-    G_message("G_dump: end");
-
-    return 0;
-}

Modified: grass/trunk/lib/gis/get_window.c
===================================================================
--- grass/trunk/lib/gis/get_window.c	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/gis/get_window.c	2009-06-22 06:35:20 UTC (rev 38019)
@@ -16,7 +16,7 @@
 #include <grass/gis.h>
 #include <grass/glocale.h>
 
-#include "../raster/G.h"
+#include "G.h"
 
 static struct state {
     int initialized;

Modified: grass/trunk/lib/gis/gisinit.c
===================================================================
--- grass/trunk/lib/gis/gisinit.c	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/gis/gisinit.c	2009-06-22 06:35:20 UTC (rev 38019)
@@ -24,7 +24,7 @@
 #include <grass/gis.h>
 #include <grass/glocale.h>
 
-#include "../raster/G.h"
+#include "G.h"
 
 struct G__ G__;
 
@@ -115,18 +115,6 @@
     /* 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;
 
     setlocale(LC_NUMERIC, "C");

Modified: grass/trunk/lib/gis/set_window.c
===================================================================
--- grass/trunk/lib/gis/set_window.c	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/gis/set_window.c	2009-06-22 06:35:20 UTC (rev 38019)
@@ -14,7 +14,7 @@
 #include <grass/gis.h>
 #include <grass/glocale.h>
 
-#include "../raster/G.h"
+#include "G.h"
 
 /*!
  * \brief Get the current working window (region)

Modified: grass/trunk/lib/gis/window_map.c
===================================================================
--- grass/trunk/lib/gis/window_map.c	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/gis/window_map.c	2009-06-22 06:35:20 UTC (rev 38019)
@@ -14,101 +14,11 @@
 #include <stdlib.h>
 #include <grass/gis.h>
 
-#include "../raster/G.h"
+#include "G.h"
 
 
-#define alloc_index(n) (COLUMN_MAPPING *) G_malloc((n)*sizeof(COLUMN_MAPPING))
 
-
 /*!
- * \brief Create window mapping.
- *
- * Creates mapping from cell header into window. The boundaries and 
- * resolution of the two spaces do not have to be the same or aligned in 
- * any way.
- *
- * \param fd file descriptor
- */
-void G__create_window_mapping(int fd)
-{
-    struct fileinfo *fcb = &G__.fileinfo[fd];
-    COLUMN_MAPPING *col;
-    int i;
-    int x;
-    double C1, C2;
-    double west;
-
-    G__init_window();
-
-    if (fcb->open_mode >= 0 && fcb->open_mode != OPEN_OLD)	/* open for write? */
-	return;
-    if (fcb->open_mode == OPEN_OLD)	/* already open ? */
-	G_free(fcb->col_map);
-
-    col = fcb->col_map = alloc_index(G__.window.cols);
-
-    /*
-     * for each column in the window, go to center of the cell,
-     * compute nearest column in the data file
-     * if column is not in data file, set column to 0
-     *
-     * for lat/lon move window so that west is bigger than
-     * cellhd west.
-     */
-    west = G__.window.west;
-    if (G__.window.proj == PROJECTION_LL) {
-	while (west > fcb->cellhd.west + 360.0)
-	    west -= 360.0;
-	while (west < fcb->cellhd.west)
-	    west += 360.0;
-    }
-
-    C1 = G__.window.ew_res / fcb->cellhd.ew_res;
-    C2 = (west - fcb->cellhd.west +
-	  G__.window.ew_res / 2.0) / fcb->cellhd.ew_res;
-    for (i = 0; i < G__.window.cols; i++) {
-	x = C2;
-	if (C2 < x)		/* adjust for rounding of negatives */
-	    x--;
-	if (x < 0 || x >= fcb->cellhd.cols)	/* not in data file */
-	    x = -1;
-	*col++ = x + 1;
-	C2 += C1;
-    }
-
-    /* do wrap around for lat/lon */
-    if (G__.window.proj == PROJECTION_LL) {
-	col = fcb->col_map;
-	C2 = (west - 360.0 - fcb->cellhd.west +
-	      G__.window.ew_res / 2.0) / fcb->cellhd.ew_res;
-	for (i = 0; i < G__.window.cols; i++) {
-	    x = C2;
-	    if (C2 < x)		/* adjust for rounding of negatives */
-		x--;
-	    if (x < 0 || x >= fcb->cellhd.cols)	/* not in data file */
-		x = -1;
-	    if (*col == 0)	/* only change those not already set */
-		*col = x + 1;
-	    col++;
-	    C2 += C1;
-	}
-    }
-
-    G_debug(3, "create window mapping (%d columns)", G__.window.cols);
-/*  for (i = 0; i < G__.window.cols; i++)
-	fprintf(stderr, "%s%ld", i % 15 ? " " : "\n", (long)fcb->col_map[i]);
-    fprintf(stderr, "\n");
-*/
-
-    /* compute C1,C2 for row window mapping */
-    fcb->C1 = G__.window.ns_res / fcb->cellhd.ns_res;
-    fcb->C2 =
-	(fcb->cellhd.north - G__.window.north +
-	 G__.window.ns_res / 2.0) / fcb->cellhd.ns_res;
-}
-
-
-/*!
  * \brief Northing to row.
  *
  * Converts a <i>north</i>ing relative to a <i>window</i> to a row.
@@ -319,47 +229,3 @@
     G_initialize_done(&G__.window_set);
 }
 
-/*!
- * \brief Loops rows until mismatch?.
- *
- * This routine works fine if the mask is not set. It may give
- * incorrect results with a mask, since the mask row may have a
- * different repeat value. The issue can be fixed by doing it for the
- * mask as well and using the smaller value.
- *
- * \param fd file descriptor
- * \param row starting row
- *
- * \return number of rows completed
- */
-int G_row_repeat_nomask(int fd, int row)
-{
-    struct fileinfo *fcb = &G__.fileinfo[fd];
-    double f;
-    int r1, r2;
-    int count;
-
-    count = 1;
-
-    /* r1 is the row in the raster map itself.
-     * r2 is the next row(s) in the raster map
-     * see get_row.c for details on this calculation
-     */
-    f = row * fcb->C1 + fcb->C2;
-    r1 = f;
-    if (f < r1)
-	r1--;
-
-    while (++row < G__.window.rows) {
-	f = row * fcb->C1 + fcb->C2;
-	r2 = f;
-	if (f < r2)
-	    r2--;
-	if (r1 != r2)
-	    break;
-
-	count++;
-    }
-
-    return count;
-}

Deleted: grass/trunk/lib/raster/G.h
===================================================================
--- grass/trunk/lib/raster/G.h	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/raster/G.h	2009-06-22 06:35:20 UTC (rev 38019)
@@ -1,94 +0,0 @@
-#include <grass/config.h>
-#include <grass/gis.h>
-#include <rpc/types.h>
-#include <rpc/xdr.h>
-#ifdef HAVE_GDAL
-#include <gdal.h>
-#endif
-
-#define XDR_FLOAT_NBYTES 4
-#define XDR_DOUBLE_NBYTES 8
-#define NULL_ROWS_INMEM 8
-
-/* if short is 16 bits, then
- *       short will allow 32767 cols
- *       unsigned short will allow 65536 cols
- * use int if you need more columns (but this will take more memory).
- *
- */
-typedef int COLUMN_MAPPING;
-
-struct GDAL_link
-{
-    char *filename;
-    int band_num;
-    DCELL null_val;
-    int hflip;
-    int vflip;
-#ifdef HAVE_GDAL
-    GDALDatasetH data;
-    GDALRasterBandH band;
-    GDALDataType type;
-#endif
-};
-
-#ifdef HAVE_GDAL
-extern CPLErr G_gdal_raster_IO(
-    GDALRasterBandH, GDALRWFlag,
-    int, int, int, int,
-    void *, int, int, GDALDataType,
-    int, int);
-#endif
-
-struct fileinfo			/* Information for opened cell files */
-{
-    int open_mode;		/* see defines below            */
-    struct Cell_head cellhd;	/* Cell header                  */
-    struct Reclass reclass;	/* Table reclass                */
-    struct Cell_stats statf;	/* Cell stats                   */
-    struct Range range;		/* Range structure              */
-    struct FPRange fp_range;	/* float Range structure        */
-    int want_histogram;
-    int reclass_flag;		/* Automatic reclass flag       */
-    off_t *row_ptr;		/* File row addresses           */
-    COLUMN_MAPPING *col_map;	/* Data to window col mapping   */
-    double C1, C2;		/* Data to window row constants */
-    int cur_row;		/* Current data row in memory   */
-    int null_cur_row;		/* Current null row in memory   */
-    int cur_nbytes;		/* nbytes per cell for current row */
-    unsigned char *data;	/* Decompressed data buffer     */
-    int nbytes;			/* bytes per cell               */
-    RASTER_MAP_TYPE map_type;	/* type: int, float or double map */
-    char *temp_name;		/* Temporary name for NEW files */
-    char *null_temp_name;	/* Temporary name for NEW NULL files */
-    int null_file_exists;	/* for existing raster maps     */
-    char *name;			/* Name of open file            */
-    char *mapset;		/* Mapset of open file          */
-    int io_error;		/* io error warning given       */
-    XDR xdrstream;		/* xdr stream for reading fp    */
-    unsigned char *NULL_ROWS[NULL_ROWS_INMEM];
-    int min_null_row;		/* Minimum row null row number in memory */
-    struct Quant quant;
-    struct GDAL_link *gdal;
-};
-
-struct G__			/*  Structure of library globals */
-{
-    RASTER_MAP_TYPE fp_type;	/* type for writing floating maps */
-    struct Cell_head window;	/* Contains the current window          */
-    int window_set;		/* Flag: window set?                    */
-    int mask_fd;		/* File descriptor for automatic mask   */
-    int auto_mask;		/* Flag denoting automatic masking      */
-    int want_histogram;
-    int nbytes;
-    int compression_type;
-
-    int fileinfo_count;
-    struct fileinfo *fileinfo;
-};
-
-extern struct G__ G__;		/* allocated in gisinit */
-
-#define OPEN_OLD              1
-#define OPEN_NEW_COMPRESSED   2
-#define OPEN_NEW_UNCOMPRESSED 3

Modified: grass/trunk/lib/raster/Makefile
===================================================================
--- grass/trunk/lib/raster/Makefile	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/raster/Makefile	2009-06-22 06:35:20 UTC (rev 38019)
@@ -4,9 +4,8 @@
 GDAL_DYNAMIC = 1
 
 LIB_NAME = $(RASTER_LIBNAME)
-EXTRA_LIBS = $(XDRLIB) $(SOCKLIB) $(DATETIMELIB) $(PTHREADLIBPATH) \
-	$(PTHREADLIB) $(INTLLIB) $(MATHLIB) $(GISLIB)
-EXTRA_INC = $(ZLIBINCPATH) $(PTHREADINCPATH)
+EXTRA_LIBS = $(GISLIB) $(XDRLIB) $(SOCKLIB) $(MATHLIB)
+EXTRA_INC = 
 
 include $(MODULE_TOPDIR)/include/Make/Vars.make
 include $(MODULE_TOPDIR)/include/Make/Lib.make
@@ -38,11 +37,12 @@
 
 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
+$(OBJDIR)/auto_mask.o: R.h
+$(OBJDIR)/closecell.o: R.h
+$(OBJDIR)/format.o: R.h
+$(OBJDIR)/get_row.o: R.h
+$(OBJDIR)/get_window.o: R.h
+$(OBJDIR)/maskfd.o: R.h
+$(OBJDIR)/opencell.o: R.h
+$(OBJDIR)/put_row.o: R.h
+$(OBJDIR)/window_map.o: R.h

Copied: grass/trunk/lib/raster/R.h (from rev 38014, grass/trunk/lib/raster/G.h)
===================================================================
--- grass/trunk/lib/raster/R.h	                        (rev 0)
+++ grass/trunk/lib/raster/R.h	2009-06-22 06:35:20 UTC (rev 38019)
@@ -0,0 +1,94 @@
+#include <grass/config.h>
+#include <grass/gis.h>
+#include <rpc/types.h>
+#include <rpc/xdr.h>
+#ifdef HAVE_GDAL
+#include <gdal.h>
+#endif
+
+#define XDR_FLOAT_NBYTES 4
+#define XDR_DOUBLE_NBYTES 8
+#define NULL_ROWS_INMEM 8
+
+/* if short is 16 bits, then
+ *       short will allow 32767 cols
+ *       unsigned short will allow 65536 cols
+ * use int if you need more columns (but this will take more memory).
+ *
+ */
+typedef int COLUMN_MAPPING;
+
+struct GDAL_link
+{
+    char *filename;
+    int band_num;
+    DCELL null_val;
+    int hflip;
+    int vflip;
+#ifdef HAVE_GDAL
+    GDALDatasetH data;
+    GDALRasterBandH band;
+    GDALDataType type;
+#endif
+};
+
+#ifdef HAVE_GDAL
+extern CPLErr Rast_gdal_raster_IO(
+    GDALRasterBandH, GDALRWFlag,
+    int, int, int, int,
+    void *, int, int, GDALDataType,
+    int, int);
+#endif
+
+struct fileinfo			/* Information for opened cell files */
+{
+    int open_mode;		/* see defines below            */
+    struct Cell_head cellhd;	/* Cell header                  */
+    struct Reclass reclass;	/* Table reclass                */
+    struct Cell_stats statf;	/* Cell stats                   */
+    struct Range range;		/* Range structure              */
+    struct FPRange fp_range;	/* float Range structure        */
+    int want_histogram;
+    int reclass_flag;		/* Automatic reclass flag       */
+    off_t *row_ptr;		/* File row addresses           */
+    COLUMN_MAPPING *col_map;	/* Data to window col mapping   */
+    double C1, C2;		/* Data to window row constants */
+    int cur_row;		/* Current data row in memory   */
+    int null_cur_row;		/* Current null row in memory   */
+    int cur_nbytes;		/* nbytes per cell for current row */
+    unsigned char *data;	/* Decompressed data buffer     */
+    int nbytes;			/* bytes per cell               */
+    RASTER_MAP_TYPE map_type;	/* type: int, float or double map */
+    char *temp_name;		/* Temporary name for NEW files */
+    char *null_temp_name;	/* Temporary name for NEW NULL files */
+    int null_file_exists;	/* for existing raster maps     */
+    char *name;			/* Name of open file            */
+    char *mapset;		/* Mapset of open file          */
+    int io_error;		/* io error warning given       */
+    XDR xdrstream;		/* xdr stream for reading fp    */
+    unsigned char *NULL_ROWS[NULL_ROWS_INMEM];
+    int min_null_row;		/* Minimum row null row number in memory */
+    struct Quant quant;
+    struct GDAL_link *gdal;
+};
+
+struct R__			/*  Structure of library globals */
+{
+    RASTER_MAP_TYPE fp_type;	/* type for writing floating maps */
+    struct Cell_head window;	/* Contains the current window          */
+    int window_set;		/* Flag: window set?                    */
+    int mask_fd;		/* File descriptor for automatic mask   */
+    int auto_mask;		/* Flag denoting automatic masking      */
+    int want_histogram;
+    int nbytes;
+    int compression_type;
+
+    int fileinfo_count;
+    struct fileinfo *fileinfo;
+};
+
+extern struct R__ R__;		/* allocated in init */
+
+#define OPEN_OLD              1
+#define OPEN_NEW_COMPRESSED   2
+#define OPEN_NEW_UNCOMPRESSED 3

Modified: grass/trunk/lib/raster/auto_mask.c
===================================================================
--- grass/trunk/lib/raster/auto_mask.c	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/raster/auto_mask.c	2009-06-22 06:35:20 UTC (rev 38019)
@@ -20,7 +20,7 @@
 #include <grass/raster.h>
 #include <grass/glocale.h>
 
-#include "G.h"
+#include "R.h"
 
 
 /**
@@ -39,38 +39,38 @@
     struct Cell_head cellhd;
 
     /* if mask is switched off (-2) return -2
-       if G__.auto_mask is not set (-1) or set (>=0) recheck the MASK */
+       if R__.auto_mask is not set (-1) or set (>=0) recheck the MASK */
 
-    if (G__.auto_mask < -1)
-	return G__.auto_mask;
+    if (R__.auto_mask < -1)
+	return R__.auto_mask;
 
-    /* if(G__.mask_fd > 0) G_free (G__.mask_buf); */
+    /* if(R__.mask_fd > 0) G_free (R__.mask_buf); */
 
     /* look for the existence of the MASK file */
-    G__.auto_mask = (G_find_cell("MASK", G_mapset()) != 0);
+    R__.auto_mask = (G_find_cell("MASK", G_mapset()) != 0);
 
-    if (G__.auto_mask <= 0)
+    if (R__.auto_mask <= 0)
 	return 0;
 
     /* check MASK projection/zone against current region */
     if (Rast_get_cellhd("MASK", G_mapset(), &cellhd) >= 0) {
 	if (cellhd.zone != G_zone() || cellhd.proj != G_projection()) {
-	    G__.auto_mask = 0;
+	    R__.auto_mask = 0;
 	    return 0;
 	}
     }
 
-    Rast_unopen_cell(G__.mask_fd);
-    G__.mask_fd = Rast__open_cell_old("MASK", G_mapset());
-    if (G__.mask_fd < 0) {
-	G__.auto_mask = 0;
+    Rast_unopen_cell(R__.mask_fd);
+    R__.mask_fd = Rast__open_cell_old("MASK", G_mapset());
+    if (R__.mask_fd < 0) {
+	R__.auto_mask = 0;
 	G_warning(_("Unable to open automatic MASK file"));
 	return 0;
     }
 
-    /*    G__.mask_buf = Rast_allocate_cell_buf(); */
+    /*    R__.mask_buf = Rast_allocate_cell_buf(); */
 
-    G__.auto_mask = 1;
+    R__.auto_mask = 1;
 
     return 1;
 }
@@ -84,12 +84,12 @@
 
 void Rast_suppress_masking(void)
 {
-    if (G__.auto_mask > 0) {
-	Rast_close_cell(G__.mask_fd);
-	/* G_free (G__.mask_buf); */
-	G__.mask_fd = -1;
+    if (R__.auto_mask > 0) {
+	Rast_close_cell(R__.mask_fd);
+	/* G_free (R__.mask_buf); */
+	R__.mask_fd = -1;
     }
-    G__.auto_mask = -2;
+    R__.auto_mask = -2;
 }
 
 
@@ -101,8 +101,8 @@
 
 void Rast_unsuppress_masking(void)
 {
-    if (G__.auto_mask < -1) {
-	G__.mask_fd = -1;
+    if (R__.auto_mask < -1) {
+	R__.mask_fd = -1;
 	Rast__check_for_auto_masking();
     }
 }

Modified: grass/trunk/lib/raster/closecell.c
===================================================================
--- grass/trunk/lib/raster/closecell.c	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/raster/closecell.c	2009-06-22 06:35:20 UTC (rev 38019)
@@ -27,7 +27,7 @@
 #include <grass/raster.h>
 #include <grass/glocale.h>
 
-#include "G.h"
+#include "R.h"
 
 #define FORMAT_FILE "f_format"
 #define QUANT_FILE  "f_quant"
@@ -69,9 +69,9 @@
  */
 int Rast_close_cell(int fd)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
 
-    if (fd < 0 || fd >= G__.fileinfo_count || fcb->open_mode <= 0)
+    if (fd < 0 || fd >= R__.fileinfo_count || fcb->open_mode <= 0)
 	return -1;
     if (fcb->open_mode == OPEN_OLD)
 	return close_old(fd);
@@ -102,9 +102,9 @@
  */
 int Rast_unopen_cell(int fd)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
 
-    if (fd < 0 || fd >= G__.fileinfo_count || fcb->open_mode <= 0)
+    if (fd < 0 || fd >= R__.fileinfo_count || fcb->open_mode <= 0)
 	return -1;
     if (fcb->open_mode == OPEN_OLD)
 	return close_old(fd);
@@ -114,13 +114,13 @@
 
 static int close_old(int fd)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     int i;
 
-    /* if G__.auto_mask was only allocated for reading map rows to create
-       non-existant null rows, and not for actuall mask, free G__.mask_row 
-       if(G__.auto_mask <=0)
-       G_free (G__.mask_buf);
+    /* if R__.auto_mask was only allocated for reading map rows to create
+       non-existant null rows, and not for actuall mask, free R__.mask_row 
+       if(R__.auto_mask <=0)
+       G_free (R__.mask_buf);
        This is obsolete since now the mask_bus is always allocated
      */
 
@@ -151,7 +151,7 @@
 
 static void write_support_files(int fd)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     struct Categories cats;
     struct History hist;
     CELL cell_min, cell_max;
@@ -229,7 +229,7 @@
 
 static int close_new_gdal(int fd, int ok)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     char path[GPATH_MAX];
     int stat = 1;
 
@@ -312,7 +312,7 @@
 
 static int close_new(int fd, int ok)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     int stat;
     char path[GPATH_MAX];
     int row, i;
@@ -475,7 +475,7 @@
 /* returns 0 on success, 1 on failure */
 static int write_fp_format(int fd)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     struct Key_Value *format_kv;
     char path[GPATH_MAX];
     int stat;

Modified: grass/trunk/lib/raster/color_read.c
===================================================================
--- grass/trunk/lib/raster/color_read.c	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/raster/color_read.c	2009-06-22 06:35:20 UTC (rev 38019)
@@ -298,7 +298,7 @@
 		Rast_add_color_rule((CELL) cat1, r1, g1, b1,
 				 (CELL) cat2, r2, g2, b2, colors);
 	}
-	G_debug(3, "adding rule %d=%.2lf %d %d %d  %d=%.2lf %d %d %d",
+	G_debug(3, "adding rule %ld=%.2lf %d %d %d  %ld=%.2lf %d %d %d",
 		cat1, val1,  r1, g1, b1, cat2, val2, r2, g2, b2);
     }
     return 1;

Modified: grass/trunk/lib/raster/format.c
===================================================================
--- grass/trunk/lib/raster/format.c	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/raster/format.c	2009-06-22 06:35:20 UTC (rev 38019)
@@ -6,7 +6,7 @@
 #include <grass/raster.h>
 #include <grass/glocale.h>
 
-#include "G.h"
+#include "R.h"
 
 /*!
 
@@ -62,7 +62,7 @@
 
 int Rast__check_format(int fd)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     unsigned char compress[4];
 
     /*
@@ -93,7 +93,7 @@
 
 int Rast__read_row_ptrs(int fd)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     int nrows = fcb->cellhd.rows;
     unsigned char nbytes;
     unsigned char *buf, *b;
@@ -158,7 +158,7 @@
 
 int Rast__write_row_ptrs(int fd)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     int nrows = fcb->cellhd.rows;
     int nbytes = sizeof(off_t);
     unsigned char *buf, *b;

Modified: grass/trunk/lib/raster/gdal.c
===================================================================
--- grass/trunk/lib/raster/gdal.c	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/raster/gdal.c	2009-06-22 06:35:20 UTC (rev 38019)
@@ -8,7 +8,7 @@
 #include <grass/raster.h>
 #include <grass/glocale.h>
 
-#include "G.h"
+#include "R.h"
 
 #ifndef HAVE_GDAL
 #undef GDAL_LINK
@@ -368,7 +368,7 @@
 
     switch (map_type) {
     case CELL_TYPE:
-	switch (G__.nbytes) {
+	switch (R__.nbytes) {
 	case 1:
 	    gdal->type = GDT_Byte;
 	    gdal->null_val = (DCELL) 0xFF;
@@ -404,7 +404,7 @@
     /* Does driver support GDALCreate ? */
     if ((*pGDALGetMetadataItem)(driver, GDAL_DCAP_CREATE, NULL))
     {
-	gdal->data = (*pGDALCreate)(driver, gdal->filename, G__.window.cols, G__.window.rows,
+	gdal->data = (*pGDALCreate)(driver, gdal->filename, R__.window.cols, R__.window.rows,
 				1, gdal->type, st->opts.options);
 	if (!gdal->data)
 	    G_fatal_error(_("Unable to create <%s> dataset using <%s> driver"),
@@ -423,7 +423,7 @@
 	if (!mem_driver)
 	    G_fatal_error(_("Unable to get in-memory raster driver"));
 
-	gdal->data = (*pGDALCreate)(mem_driver, "", G__.window.cols, G__.window.rows,
+	gdal->data = (*pGDALCreate)(mem_driver, "", R__.window.cols, R__.window.rows,
 				    1, gdal->type, st->opts.options);
 	if (!gdal->data)
 	    G_fatal_error(_("Unable to create <%s> dataset using memory driver"),
@@ -438,12 +438,12 @@
     (*pGDALSetRasterNoDataValue)(gdal->band, gdal->null_val);
 
     /* Set Geo Transform  */
-    transform[0] = G__.window.west;
-    transform[1] = G__.window.ew_res;
+    transform[0] = R__.window.west;
+    transform[1] = R__.window.ew_res;
     transform[2] = 0.0;
-    transform[3] = G__.window.north;
+    transform[3] = R__.window.north;
     transform[4] = 0.0;
-    transform[5] = -G__.window.ns_res;
+    transform[5] = -R__.window.ns_res;
 
     if ((*pGDALSetGeoTransform)(gdal->data, transform) >= CE_Failure)
 	G_warning(_("Unable to set geo transform"));
@@ -519,7 +519,7 @@
 }
 
 #ifdef GDAL_LINK
-CPLErr G_gdal_raster_IO(
+CPLErr Rast_gdal_raster_IO(
     GDALRasterBandH band, GDALRWFlag rw_flag,
     int x_off, int y_off, int x_size, int y_size,
     void *buffer, int buf_x_size, int buf_y_size, GDALDataType buf_type,

Modified: grass/trunk/lib/raster/get_row.c
===================================================================
--- grass/trunk/lib/raster/get_row.c	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/raster/get_row.c	2009-06-22 06:35:20 UTC (rev 38019)
@@ -22,7 +22,7 @@
 #include <grass/raster.h>
 #include <grass/glocale.h>
 
-#include "G.h"
+#include "R.h"
 
 #define NULL_FILE   "null"
 
@@ -30,12 +30,12 @@
 
 static int compute_window_row(int fd, int row, int *cellRow)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     double f;
     int r;
 
     /* check for row in window */
-    if (row < 0 || row >= G__.window.rows) {
+    if (row < 0 || row >= R__.window.rows) {
 	G_warning(_("Reading raster map <%s@%s> request for row %d is outside region"),
 		  fcb->name, fcb->mapset, row);
 
@@ -58,14 +58,14 @@
 
 static void do_reclass_int(int fd, void *cell, int null_is_zero)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     CELL *c = cell;
     CELL *reclass_table = fcb->reclass.table;
     CELL min = fcb->reclass.min;
     CELL max = fcb->reclass.max;
     int i;
 
-    for (i = 0; i < G__.window.cols; i++) {
+    for (i = 0; i < R__.window.cols; i++) {
 	if (Rast_is_c_null_value(&c[i])) {
 	    if (null_is_zero)
 		c[i] = 0;
@@ -90,7 +90,7 @@
 static int read_data_fp_compressed(int fd, int row, unsigned char *data_buf,
 				   int *nbytes)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     off_t t1 = fcb->row_ptr[row];
     off_t t2 = fcb->row_ptr[row + 1];
     size_t readamount = t2 - t1;
@@ -129,7 +129,7 @@
 static int read_data_compressed(int fd, int row, unsigned char *data_buf,
 				int *nbytes)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     off_t t1 = fcb->row_ptr[row];
     off_t t2 = fcb->row_ptr[row + 1];
     ssize_t readamount = t2 - t1;
@@ -173,7 +173,7 @@
 static int read_data_uncompressed(int fd, int row, unsigned char *data_buf,
 				  int *nbytes)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     ssize_t bufsize = fcb->cellhd.cols * fcb->nbytes;
 
     *nbytes = fcb->nbytes;
@@ -190,7 +190,7 @@
 #ifdef HAVE_GDAL
 static int read_data_gdal(int fd, int row, unsigned char *data_buf, int *nbytes)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     unsigned char *buf;
     CPLErr err;
 
@@ -203,7 +203,7 @@
 	? G__alloca(fcb->cellhd.cols * fcb->cur_nbytes)
 	: data_buf;
 
-    err = G_gdal_raster_IO(
+    err = Rast_gdal_raster_IO(
 	fcb->gdal->band, GF_Read, 0, row, fcb->cellhd.cols, 1, buf,
 	fcb->cellhd.cols, 1, fcb->gdal->type, 0, 0);
 
@@ -223,7 +223,7 @@
 
 static int read_data(int fd, int row, unsigned char *data_buf, int *nbytes)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
 
 #ifdef HAVE_GDAL
     if (fcb->gdal)
@@ -291,7 +291,7 @@
 			      const COLUMN_MAPPING * cmap, int nbytes,
 			      void *cell, int n)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     FCELL *c = cell;
     COLUMN_MAPPING cmapold = 0;
     XDR *xdrs = &fcb->xdrstream;
@@ -330,7 +330,7 @@
 			       const COLUMN_MAPPING * cmap, int nbytes,
 			       void *cell, int n)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     DCELL *c = cell;
     COLUMN_MAPPING cmapold = 0;
     XDR *xdrs = &fcb->xdrstream;
@@ -370,7 +370,7 @@
 			    const COLUMN_MAPPING *cmap, int nbytes,
 			    CELL *cell, int n)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     const unsigned char *d;
     COLUMN_MAPPING cmapold = 0;
     int i;
@@ -470,29 +470,29 @@
     static void (*gdal_values_type[3]) () = {
     gdal_values_int, gdal_values_float, gdal_values_double};
 #endif
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
 
 #ifdef HAVE_GDAL
     if (fcb->gdal)
     (gdal_values_type[fcb->map_type]) (fd, fcb->data, fcb->col_map,
 				       fcb->cur_nbytes, cell,
-				       G__.window.cols);
+				       R__.window.cols);
     else
 #endif
     (cell_values_type[fcb->map_type]) (fd, fcb->data, fcb->col_map,
 				       fcb->cur_nbytes, cell,
-				       G__.window.cols);
+				       R__.window.cols);
 }
 
 static void transfer_to_cell_fi(int fd, void *cell)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
-    FCELL *work_buf = G__alloca(G__.window.cols * sizeof(FCELL));
+    struct fileinfo *fcb = &R__.fileinfo[fd];
+    FCELL *work_buf = G__alloca(R__.window.cols * sizeof(FCELL));
     int i;
 
     transfer_to_cell_XX(fd, work_buf);
 
-    for (i = 0; i < G__.window.cols; i++)
+    for (i = 0; i < R__.window.cols; i++)
 	((CELL *) cell)[i] = (fcb->col_map[i] == 0)
 	    ? 0
 	    : Rast_quant_get_cell_value(&fcb->quant, work_buf[i]);
@@ -502,13 +502,13 @@
 
 static void transfer_to_cell_di(int fd, void *cell)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
-    DCELL *work_buf = G__alloca(G__.window.cols * sizeof(DCELL));
+    struct fileinfo *fcb = &R__.fileinfo[fd];
+    DCELL *work_buf = G__alloca(R__.window.cols * sizeof(DCELL));
     int i;
 
     transfer_to_cell_XX(fd, work_buf);
 
-    for (i = 0; i < G__.window.cols; i++)
+    for (i = 0; i < R__.window.cols; i++)
 	((CELL *) cell)[i] = (fcb->col_map[i] == 0)
 	    ? 0
 	    : Rast_quant_get_cell_value(&fcb->quant, work_buf[i]);
@@ -518,12 +518,12 @@
 
 static void transfer_to_cell_if(int fd, void *cell)
 {
-    CELL *work_buf = G__alloca(G__.window.cols * sizeof(CELL));
+    CELL *work_buf = G__alloca(R__.window.cols * sizeof(CELL));
     int i;
 
     transfer_to_cell_XX(fd, work_buf);
 
-    for (i = 0; i < G__.window.cols; i++)
+    for (i = 0; i < R__.window.cols; i++)
 	((FCELL *) cell)[i] = work_buf[i];
 
     G__freea(work_buf);
@@ -531,12 +531,12 @@
 
 static void transfer_to_cell_df(int fd, void *cell)
 {
-    DCELL *work_buf = G__alloca(G__.window.cols * sizeof(DCELL));
+    DCELL *work_buf = G__alloca(R__.window.cols * sizeof(DCELL));
     int i;
 
     transfer_to_cell_XX(fd, work_buf);
 
-    for (i = 0; i < G__.window.cols; i++)
+    for (i = 0; i < R__.window.cols; i++)
 	((FCELL *) cell)[i] = work_buf[i];
 
     G__freea(work_buf);
@@ -544,12 +544,12 @@
 
 static void transfer_to_cell_id(int fd, void *cell)
 {
-    CELL *work_buf = G__alloca(G__.window.cols * sizeof(CELL));
+    CELL *work_buf = G__alloca(R__.window.cols * sizeof(CELL));
     int i;
 
     transfer_to_cell_XX(fd, work_buf);
 
-    for (i = 0; i < G__.window.cols; i++)
+    for (i = 0; i < R__.window.cols; i++)
 	((DCELL *) cell)[i] = work_buf[i];
 
     G__freea(work_buf);
@@ -557,12 +557,12 @@
 
 static void transfer_to_cell_fd(int fd, void *cell)
 {
-    FCELL *work_buf = G__alloca(G__.window.cols * sizeof(FCELL));
+    FCELL *work_buf = G__alloca(R__.window.cols * sizeof(FCELL));
     int i;
 
     transfer_to_cell_XX(fd, work_buf);
 
-    for (i = 0; i < G__.window.cols; i++)
+    for (i = 0; i < R__.window.cols; i++)
 	((DCELL *) cell)[i] = work_buf[i];
 
     G__freea(work_buf);
@@ -580,7 +580,7 @@
 	{transfer_to_cell_fi, transfer_to_cell_XX, transfer_to_cell_fd},
 	{transfer_to_cell_di, transfer_to_cell_df, transfer_to_cell_XX}
     };
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     int r;
     int rowStatus;
 
@@ -638,7 +638,7 @@
 static int get_map_row(int fd, void *rast, int row, RASTER_MAP_TYPE data_type,
 		       int null_is_zero, int with_mask)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     int size = Rast_raster_size(data_type);
     CELL *temp_buf = NULL;
     void *buf;
@@ -647,7 +647,7 @@
     int i;
 
     if (fcb->reclass_flag && data_type != CELL_TYPE) {
-	temp_buf = G__alloca(G__.window.cols * sizeof(CELL));
+	temp_buf = G__alloca(R__.window.cols * sizeof(CELL));
 	buf = temp_buf;
 	type = CELL_TYPE;
     }
@@ -674,7 +674,7 @@
     if (data_type == CELL_TYPE)
 	return 1;
 
-    for (i = 0; i < G__.window.cols; i++) {
+    for (i = 0; i < R__.window.cols; i++) {
 	Rast_set_raster_value_c(rast, temp_buf[i], data_type);
 	rast = Rast_incr_void_ptr(rast, size);
     }
@@ -937,7 +937,7 @@
 
 static int open_null_read(int fd)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     const char *name, *mapset, *dummy;
     int null_fd;
 
@@ -1003,10 +1003,10 @@
 
 static void get_null_value_row_nomask(int fd, char *flags, int row)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     int i, j, null_fd;
 
-    if (row > G__.window.rows || row < 0) {
+    if (row > R__.window.rows || row < 0) {
 	G_warning(_("Reading raster map <%s@%s> request for row %d is outside region"),
 		  fcb->name, fcb->mapset, row);
     }
@@ -1027,8 +1027,8 @@
 	null_fd = open_null_read(fd);
 
 	for (i = 0; i < NULL_ROWS_INMEM; i++) {
-	    /* G__.window.rows doesn't have to be a multiple of NULL_ROWS_INMEM */
-	    if (i + fcb->min_null_row >= G__.window.rows)
+	    /* R__.window.rows doesn't have to be a multiple of NULL_ROWS_INMEM */
+	    if (i + fcb->min_null_row >= R__.window.rows)
 		break;
 
 	    if (read_null_bits(null_fd, null_work_buf,
@@ -1036,11 +1036,11 @@
 			       fd) < 0) {
 		if (fcb->map_type == CELL_TYPE) {
 		    /* If can't read null row, assume  that all map 0's are nulls */
-		    CELL *mask_buf = G__alloca(G__.window.cols * sizeof(CELL));
+		    CELL *mask_buf = G__alloca(R__.window.cols * sizeof(CELL));
 
 		    get_map_row_nomask(fd, mask_buf, i + fcb->min_null_row,
 				       CELL_TYPE);
-		    for (j = 0; j < G__.window.cols; j++)
+		    for (j = 0; j < R__.window.cols; j++)
 			flags[j] = (mask_buf[j] == 0);
 
 		    G__freea(mask_buf);
@@ -1048,15 +1048,15 @@
 		else {		/* fp map */
 
 		    /* if can't read null row, assume  that all data is valid */
-		    G_zero(flags, sizeof(char) * G__.window.cols);
+		    G_zero(flags, sizeof(char) * R__.window.cols);
 		    /* the flags row is ready now */
 		}
 	    }			/*if no null file */
 	    else {
 		/* copy null row to flags row translated by window column mapping */
-		/* the fcb->NULL_ROWS[row-fcb->min_null_row] has G__.window.cols bits, */
+		/* the fcb->NULL_ROWS[row-fcb->min_null_row] has R__.window.cols bits, */
 		/* the null_work_buf has size fcb->cellhd.cols */
-		for (j = 0; j < G__.window.cols; j++) {
+		for (j = 0; j < R__.window.cols; j++) {
 		    if (!fcb->col_map[j])
 			flags[j] = 1;
 		    else
@@ -1070,13 +1070,13 @@
 	    /*bf-We should take of the size - or we get 
 	       zeros running on their own after flags convertions -A.Sh. */
 	    fcb->NULL_ROWS[i] = G_realloc(fcb->NULL_ROWS[i],
-					  Rast__null_bitstream_size(G__.window.
+					  Rast__null_bitstream_size(R__.window.
 								 cols) + 1);
 	    if (fcb->NULL_ROWS[i] == NULL)
 		G_fatal_error("get_null_value_row_nomask: %s",
 			      _("Unable to realloc buffer"));
 
-	    Rast__convert_01_flags(flags, fcb->NULL_ROWS[i], G__.window.cols);
+	    Rast__convert_01_flags(flags, fcb->NULL_ROWS[i], R__.window.cols);
 
 	}			/* for loop */
 
@@ -1087,9 +1087,9 @@
     }				/* row is not in memory */
 
     /* copy null file data translated by column mapping to user null row */
-    /* the user requested flags row is of size G__.window.cols */
+    /* the user requested flags row is of size R__.window.cols */
     Rast__convert_flags_01(flags, fcb->NULL_ROWS[row - fcb->min_null_row],
-			G__.window.cols);
+			R__.window.cols);
 }
 
 /*--------------------------------------------------------------------------*/
@@ -1098,17 +1098,17 @@
 
 static void get_null_value_row_gdal(int fd, char *flags, int row)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     DCELL *tmp_buf = Rast_allocate_d_raster_buf();
     int i;
 
     if (get_map_row_nomask(fd, tmp_buf, row, DCELL_TYPE) <= 0) {
-	memset(flags, 1, G__.window.cols);
+	memset(flags, 1, R__.window.cols);
 	G_free(tmp_buf);
 	return;
     }
 
-    for (i = 0; i < G__.window.cols; i++)
+    for (i = 0; i < R__.window.cols; i++)
 	/* note: using == won't work if the null value is NaN */
 	flags[i] = memcmp(&tmp_buf[i], &fcb->gdal->null_val, sizeof(DCELL)) == 0;
 
@@ -1123,21 +1123,21 @@
 
 static void embed_mask(char *flags, int row)
 {
-    CELL *mask_buf = G__alloca(G__.window.cols * sizeof(CELL));
+    CELL *mask_buf = G__alloca(R__.window.cols * sizeof(CELL));
     int i;
 
-    if (G__.auto_mask <= 0)
+    if (R__.auto_mask <= 0)
 	return;
 
-    if (get_map_row_nomask(G__.mask_fd, mask_buf, row, CELL_TYPE) < 0) {
+    if (get_map_row_nomask(R__.mask_fd, mask_buf, row, CELL_TYPE) < 0) {
 	G__freea(mask_buf);
 	return;
     }
 
-    if (G__.fileinfo[G__.mask_fd].reclass_flag)
-	do_reclass_int(G__.mask_fd, mask_buf, 1);
+    if (R__.fileinfo[R__.mask_fd].reclass_flag)
+	do_reclass_int(R__.mask_fd, mask_buf, 1);
 
-    for (i = 0; i < G__.window.cols; i++)
+    for (i = 0; i < R__.window.cols; i++)
 	if (mask_buf[i] == 0)
 	    flags[i] = 1;
 
@@ -1147,7 +1147,7 @@
 static void get_null_value_row(int fd, char *flags, int row, int with_mask)
 {
 #ifdef HAVE_GDAL
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     if (fcb->gdal)
 	get_null_value_row_gdal(fd, flags, row);
     else
@@ -1161,21 +1161,21 @@
 static int embed_nulls(int fd, void *buf, int row, RASTER_MAP_TYPE map_type,
 		       int null_is_zero, int with_mask)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     char *null_buf;
     int i;
 
     /* this is because without null file the nulls can be only due to 0's
        in data row or mask */
     if (null_is_zero && !fcb->null_file_exists
-	&& (G__.auto_mask <= 0 || !with_mask))
+	&& (R__.auto_mask <= 0 || !with_mask))
 	return 1;
 
-    null_buf = G__alloca(G__.window.cols);
+    null_buf = G__alloca(R__.window.cols);
 
     get_null_value_row(fd, null_buf, row, with_mask);
 
-    for (i = 0; i < G__.window.cols; i++) {
+    for (i = 0; i < R__.window.cols; i++) {
 	/* also check for nulls which might be already embedded by quant
 	   rules in case of fp map. */
 	if (null_buf[i] || Rast_is_null_value(buf, map_type)) {

Modified: grass/trunk/lib/raster/get_row_colr.c
===================================================================
--- grass/trunk/lib/raster/get_row_colr.c	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/raster/get_row_colr.c	2009-06-22 06:35:20 UTC (rev 38019)
@@ -15,7 +15,7 @@
 #include <grass/gis.h>
 #include <grass/raster.h>
 
-#include "G.h"
+#include "R.h"
 
 /*!
  * \brief Reads a row of raster data and converts it to RGB.

Modified: grass/trunk/lib/raster/init.c
===================================================================
--- grass/trunk/lib/raster/init.c	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/raster/init.c	2009-06-22 06:35:20 UTC (rev 38019)
@@ -24,9 +24,9 @@
 #include <grass/raster.h>
 #include <grass/glocale.h>
 
-#include "../raster/G.h"
+#include "R.h"
 
-struct G__ G__;
+struct R__ R__;
 
 static int initialized = 0; /** Is set when engine is initialized */
 static int init(void);
@@ -67,20 +67,17 @@
 
 static int init(void)
 {
-    /* Mark window as not set */
-    G__.window_set = 0;
-
     /* no histograms */
-    G__.want_histogram = 0;
+    R__.want_histogram = 0;
 
     /* set the write type for floating maps */
-    G__.fp_type = getenv("GRASS_FP_DOUBLE") ? DCELL_TYPE : FCELL_TYPE;
+    R__.fp_type = getenv("GRASS_FP_DOUBLE") ? DCELL_TYPE : FCELL_TYPE;
 
     /* Set masking flag unknown */
-    G__.auto_mask = -1;
+    R__.auto_mask = -1;
 
-    G__.nbytes = sizeof(CELL);
-    G__.compression_type = getenv("GRASS_INT_ZLIB") ? 2 : 1;
+    R__.nbytes = sizeof(CELL);
+    R__.compression_type = getenv("GRASS_INT_ZLIB") ? 2 : 1;
 
     initialized = 1;
 

Modified: grass/trunk/lib/raster/maskfd.c
===================================================================
--- grass/trunk/lib/raster/maskfd.c	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/raster/maskfd.c	2009-06-22 06:35:20 UTC (rev 38019)
@@ -14,7 +14,7 @@
 #include <grass/gis.h>
 #include <grass/raster.h>
 
-#include "G.h"
+#include "R.h"
 
 /*!
  * \brief Test for MASK.
@@ -27,5 +27,5 @@
 {
     Rast__check_for_auto_masking();
 
-    return G__.auto_mask > 0 ? G__.mask_fd : -1;
+    return R__.auto_mask > 0 ? R__.mask_fd : -1;
 }

Modified: grass/trunk/lib/raster/opencell.c
===================================================================
--- grass/trunk/lib/raster/opencell.c	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/raster/opencell.c	2009-06-22 06:35:20 UTC (rev 38019)
@@ -25,33 +25,33 @@
 #include <grass/raster.h>
 #include <grass/glocale.h>
 
-#include "G.h"
+#include "R.h"
 #define FORMAT_FILE "f_format"
 
 static struct fileinfo *new_fileinfo(int fd)
 {
-    int oldsize = G__.fileinfo_count;
+    int oldsize = R__.fileinfo_count;
     int newsize = oldsize;
     int i;
 
     if (fd < oldsize)
-	return &G__.fileinfo[fd];
+	return &R__.fileinfo[fd];
 
     newsize *= 2;
     if (newsize <= fd)
 	newsize = fd + 20;
 
-    G__.fileinfo = G_realloc(G__.fileinfo, newsize * sizeof(struct fileinfo));
+    R__.fileinfo = G_realloc(R__.fileinfo, newsize * sizeof(struct fileinfo));
 
     /* Mark all cell files as closed */
     for (i = oldsize; i < newsize; i++) {
-	memset(&G__.fileinfo[i], 0, sizeof(struct fileinfo));
-	G__.fileinfo[i].open_mode = -1;
+	memset(&R__.fileinfo[i], 0, sizeof(struct fileinfo));
+	R__.fileinfo[i].open_mode = -1;
     }
 
-    G__.fileinfo_count = newsize;
+    R__.fileinfo_count = newsize;
 
-    return &G__.fileinfo[fd];
+    return &R__.fileinfo[fd];
 }
 
 
@@ -117,8 +117,8 @@
     /* turn on auto masking, if not already on */
     Rast__check_for_auto_masking();
     /*
-       if(G__.auto_mask <= 0)
-       G__.mask_buf = Rast_allocate_cell_buf();
+       if(R__.auto_mask <= 0)
+       R__.mask_buf = Rast_allocate_cell_buf();
        now we don't ever free it!, so no need to allocate it  (Olga)
      */
     /* mask_buf is used for reading MASK file when mask is set and
@@ -169,7 +169,7 @@
     struct GDAL_link *gdal;
 
     /* make sure window is set    */
-    G__init_window();
+    Rast__init_window();
 
     G__unqualified_name(name, mapset, xname, xmapset);
     name = xname;
@@ -222,16 +222,16 @@
 	}
     }
 
-    if (cellhd.proj != G__.window.proj) {
+    if (cellhd.proj != R__.window.proj) {
 	G_warning(_("Raster map <%s@%s> is in different projection than current region. "
 		    "Found raster map <%s@%s>, should be <%s>."),
 		  name, mapset, name, G__projection_name(cellhd.proj),
-		  G__projection_name(G__.window.proj));
+		  G__projection_name(R__.window.proj));
 	return -1;
     }
-    if (cellhd.zone != G__.window.zone) {
+    if (cellhd.zone != R__.window.zone) {
 	G_warning(_("Raster map <%s@%s> is in different zone (%d) than current region (%d)"),
-		  name, mapset, cellhd.zone, G__.window.zone);
+		  name, mapset, cellhd.zone, R__.window.zone);
 	return -1;
     }
 
@@ -287,7 +287,7 @@
 
     /* allocate null bitstream buffers for reading null rows */
     for (i = 0; i < NULL_ROWS_INMEM; i++)
-	fcb->NULL_ROWS[i] = Rast__allocate_null_bits(G__.window.cols);
+	fcb->NULL_ROWS[i] = Rast__allocate_null_bits(R__.window.cols);
     /* initialize : no NULL rows in memory */
     fcb->min_null_row = (-1) * NULL_ROWS_INMEM;
 
@@ -316,7 +316,7 @@
 	}
 
     /* create the mapping from cell file to window */
-    G__create_window_mapping(fd);
+    Rast__create_window_mapping(fd);
 
     /*
      * allocate the data buffer
@@ -407,7 +407,7 @@
 */
 void Rast_want_histogram(int flag)
 {
-    G__.want_histogram = flag;
+    R__.want_histogram = flag;
 }
 
 /*!
@@ -425,11 +425,11 @@
 void Rast_set_cell_format(int n)
 /* sets the format for integer raster map */
 {
-    G__.nbytes = n + 1;
-    if (G__.nbytes <= 0)
-	G__.nbytes = 1;
-    if (G__.nbytes > sizeof(CELL))
-	G__.nbytes = sizeof(CELL);
+    R__.nbytes = n + 1;
+    if (R__.nbytes <= 0)
+	R__.nbytes = 1;
+    if (R__.nbytes > sizeof(CELL))
+	R__.nbytes = sizeof(CELL);
 }
 
 /*!
@@ -469,7 +469,7 @@
 */
 int Rast_open_fp_cell_new(const char *name)
 {
-    return G__open_raster_new(name, OPEN_NEW_COMPRESSED, G__.fp_type);
+    return G__open_raster_new(name, OPEN_NEW_COMPRESSED, R__.fp_type);
 }
 
 /*!
@@ -484,7 +484,7 @@
 */
 int Rast_open_fp_cell_new_uncompressed(const char *name)
 {
-    return G__open_raster_new(name, OPEN_NEW_UNCOMPRESSED, G__.fp_type);
+    return G__open_raster_new(name, OPEN_NEW_UNCOMPRESSED, R__.fp_type);
 }
 
 #ifdef HAVE_GDAL
@@ -509,12 +509,12 @@
     if (!fcb->gdal)
 	return -1;
 
-    fcb->cellhd = G__.window;
+    fcb->cellhd = R__.window;
     fcb->cellhd.compressed = 0;
     fcb->nbytes = Rast_raster_size(fcb->map_type);
-    /* for writing fcb->data is allocated to be G__.window.cols * 
+    /* for writing fcb->data is allocated to be R__.window.cols * 
        sizeof(CELL or DCELL or FCELL)  */
-    fcb->data = G_calloc(G__.window.cols, fcb->nbytes);
+    fcb->data = G_calloc(R__.window.cols, fcb->nbytes);
 
     fcb->name = map;
     fcb->mapset = mapset;
@@ -534,7 +534,7 @@
     /* init cell stats */
     /* now works only for int maps */
     if (fcb->map_type == CELL_TYPE)
-	if ((fcb->want_histogram = G__.want_histogram))
+	if ((fcb->want_histogram = R__.want_histogram))
 	    Rast_init_cell_stats(&fcb->statf);
 
     /* init range and if map is double/float init d/f_range */
@@ -566,7 +566,7 @@
     switch (map_type) {
     case CELL_TYPE:
 	cell_dir = "cell";
-	nbytes = G__.nbytes;
+	nbytes = R__.nbytes;
 	break;
     case FCELL_TYPE:
 	nbytes = XDR_FLOAT_NBYTES;
@@ -594,7 +594,7 @@
     }
 
     /* make sure window is set */
-    G__init_window();
+    Rast__init_window();
 
 #ifdef HAVE_GDAL
     if (G_find_file2("", "GDAL", G_mapset()))
@@ -624,9 +624,9 @@
     fcb->open_mode = -1;
     fcb->gdal = NULL;
 
-    /* for writing fcb->data is allocated to be G__.window.cols * 
+    /* for writing fcb->data is allocated to be R__.window.cols * 
        sizeof(CELL or DCELL or FCELL)  */
-    fcb->data = (unsigned char *)G_calloc(G__.window.cols,
+    fcb->data = (unsigned char *)G_calloc(R__.window.cols,
 					  Rast_raster_size(fcb->map_type));
 
     /*
@@ -635,13 +635,13 @@
      * for compressed writing
      *   allocate space to hold the row address array
      */
-    G_copy((char *)&fcb->cellhd, (char *)&G__.window, sizeof(fcb->cellhd));
+    G_copy((char *)&fcb->cellhd, (char *)&R__.window, sizeof(fcb->cellhd));
 
     if (open_mode == OPEN_NEW_COMPRESSED && fcb->map_type == CELL_TYPE) {
 	fcb->row_ptr = G_calloc(fcb->cellhd.rows + 1, sizeof(off_t));
 	G_zero(fcb->row_ptr, (fcb->cellhd.rows + 1) * sizeof(off_t));
 	Rast__write_row_ptrs(fd);
-	fcb->cellhd.compressed = G__.compression_type;
+	fcb->cellhd.compressed = R__.compression_type;
 
 	fcb->nbytes = 1;	/* to the minimum */
     }
@@ -651,7 +651,7 @@
 	    fcb->row_ptr = G_calloc(fcb->cellhd.rows + 1, sizeof(off_t));
 	    G_zero(fcb->row_ptr, (fcb->cellhd.rows + 1) * sizeof(off_t));
 	    Rast__write_row_ptrs(fd);
-	    fcb->cellhd.compressed = G__.compression_type;
+	    fcb->cellhd.compressed = R__.compression_type;
 	}
 	else
 	    fcb->cellhd.compressed = 0;
@@ -696,7 +696,7 @@
     /* init cell stats */
     /* now works only for int maps */
     if (fcb->map_type == CELL_TYPE)
-	if ((fcb->want_histogram = G__.want_histogram))
+	if ((fcb->want_histogram = R__.want_histogram))
 	    Rast_init_cell_stats(&fcb->statf);
 
     /* init range and if map is double/float init d/f_range */
@@ -731,7 +731,7 @@
     switch (map_type) {
     case FCELL_TYPE:
     case DCELL_TYPE:
-	G__.fp_type = map_type;
+	R__.fp_type = map_type;
 	return 1;
     default:
 	G_warning(_("Rast_set_fp_type(): can only be called with FCELL_TYPE or DCELL_TYPE"));
@@ -822,7 +822,7 @@
  */
 RASTER_MAP_TYPE Rast_get_raster_map_type(int fd)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
 
     return fcb->map_type;
 }
@@ -945,7 +945,7 @@
 */
 int Rast_set_quant_rules(int fd, struct Quant *q)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     CELL cell;
     DCELL dcell;
     struct Quant_table *p;

Modified: grass/trunk/lib/raster/put_row.c
===================================================================
--- grass/trunk/lib/raster/put_row.c	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/raster/put_row.c	2009-06-22 06:35:20 UTC (rev 38019)
@@ -84,7 +84,7 @@
 #include <grass/raster.h>
 #include <grass/glocale.h>
 
-#include "G.h"
+#include "R.h"
 
 static int put_raster_data(int, char *, const void *, int, int, int,
 			   RASTER_MAP_TYPE);
@@ -110,7 +110,7 @@
 
 static int put_null_value_row(int fd, const char *buf)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
 
     if (fcb->gdal)
 	G_fatal_error(_("GDAL output doesn't support writing null rows separately"));
@@ -129,7 +129,7 @@
 
 int Rast_put_map_row(int fd, const CELL * buf)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
 
     if (fcb->map_type != CELL_TYPE) {
 	G_fatal_error(_("Rast_put_map_row: %s is not integer! Use G_put_[f/d]_raster_row()!"),
@@ -164,7 +164,7 @@
 
 static int check_open(const char *me, int fd)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
 
     switch (fcb->open_mode) {
     case OPEN_OLD:
@@ -185,7 +185,7 @@
 
 static void write_error(int fd, int row)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
 
     if (fcb->io_error)
 	return;
@@ -199,7 +199,7 @@
 
 static int write_data(int fd, int row, unsigned char *buf, int n)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     ssize_t nwrite = fcb->nbytes * n;
 
     if (write(fd, buf, nwrite) != nwrite) {
@@ -212,7 +212,7 @@
 
 static int write_data_compressed(int fd, int row, unsigned char *buf, int n)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     int nwrite = fcb->nbytes * n;
 
     if (G_zlib_write(fd, buf, nwrite) < 0) {
@@ -227,7 +227,7 @@
 
 static void set_file_pointer(int fd, int row)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
 
     fcb->row_ptr[row] = lseek(fd, 0L, SEEK_CUR);
 }
@@ -295,7 +295,7 @@
 static int put_fp_data(int fd, char *null_buf, const void *rast,
 		       int row, int n, RASTER_MAP_TYPE data_type)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     int compressed = (fcb->open_mode == OPEN_NEW_COMPRESSED);
     XDR *xdrs = &fcb->xdrstream;
     char *work_buf;
@@ -306,7 +306,7 @@
     if (n <= 0)
 	return 0;
 
-    work_buf = G__alloca(G__.window.cols * fcb->nbytes + 1);
+    work_buf = G__alloca(R__.window.cols * fcb->nbytes + 1);
 
     if (compressed)
 	set_file_pointer(fd, row);
@@ -479,7 +479,7 @@
 static int put_data(int fd, char *null_buf, const CELL *cell,
 		    int row, int n, int zeros_r_nulls)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     int compressed = fcb->cellhd.compressed;
     int len = compressed ? sizeof(CELL) : fcb->nbytes;
     unsigned char *work_buf, *wk;
@@ -491,7 +491,7 @@
     if (n <= 0)
 	return 0;
 
-    work_buf = G__alloca(G__.window.cols * sizeof(CELL) + 1);
+    work_buf = G__alloca(R__.window.cols * sizeof(CELL) + 1);
     wk = work_buf;
 
     if (compressed)
@@ -570,7 +570,7 @@
 			 int zeros_r_nulls, RASTER_MAP_TYPE map_type)
 {
 #ifdef HAVE_GDAL
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     int size = Rast_raster_size(map_type);
     DCELL null_val = fcb->gdal->null_val;
     const void *src;
@@ -605,8 +605,8 @@
 	dst = Rast_incr_void_ptr(dst, size);
     }
 
-    err = G_gdal_raster_IO(fcb->gdal->band, GF_Write, 0, row, n, 1, work_buf,
-			   n, 1, datatype, 0, 0);
+    err = Rast_gdal_raster_IO(fcb->gdal->band, GF_Write, 0, row, n, 1, work_buf,
+			      n, 1, datatype, 0, 0);
 
     G__freea(work_buf);
 
@@ -626,7 +626,7 @@
 			   int row, int n,
 			   int zeros_r_nulls, RASTER_MAP_TYPE map_type)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
 
     if (fcb->gdal)
 	return put_data_gdal(fd, rast, row, n, zeros_r_nulls, map_type);
@@ -644,7 +644,7 @@
 
 static int put_null_data(int fd, const char *flags, int row)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     int null_fd, i;
 
     if (fcb->min_null_row + NULL_ROWS_INMEM <= row) {
@@ -686,7 +686,7 @@
 
 int Rast__open_null_write(int fd)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     int null_fd;
 
     if (access(fcb->null_temp_name, 0) != 0) {
@@ -732,7 +732,7 @@
 
 static int convert_and_write_if(int fd, const CELL * buf)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     FCELL *p = (FCELL *) fcb->data;
     int i;
 
@@ -747,7 +747,7 @@
 
 static int convert_and_write_df(int fd, const DCELL * buf)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     FCELL *p = (FCELL *) fcb->data;
     int i;
 
@@ -762,7 +762,7 @@
 
 static int convert_and_write_id(int fd, const CELL * buf)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     DCELL *p = (DCELL *) fcb->data;
     int i;
 
@@ -777,7 +777,7 @@
 
 static int convert_and_write_fd(int fd, const FCELL * buf)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     DCELL *p = (DCELL *) fcb->data;
     int i;
 
@@ -792,7 +792,7 @@
 
 static int convert_and_write_fi(int fd, const FCELL * buf)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     CELL *p = (CELL *) fcb->data;
     int i;
 
@@ -807,7 +807,7 @@
 
 static int convert_and_write_di(int fd, const DCELL * buf)
 {
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     CELL *p = (CELL *) fcb->data;
     int i;
 
@@ -830,7 +830,7 @@
 	{convert_and_write_fi, NULL, convert_and_write_fd},
 	{convert_and_write_di, convert_and_write_df, NULL}
     };
-    struct fileinfo *fcb = &G__.fileinfo[fd];
+    struct fileinfo *fcb = &R__.fileinfo[fd];
     char *null_buf;
     int stat;
 

Modified: grass/trunk/lib/raster/range.c
===================================================================
--- grass/trunk/lib/raster/range.c	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/raster/range.c	2009-06-22 06:35:20 UTC (rev 38019)
@@ -18,7 +18,7 @@
 #include <grass/raster.h>
 #include <grass/glocale.h>
 
-#include "G.h"
+#include "R.h"
 
 #define DEFAULT_CELL_MIN 1
 #define DEFAULT_CELL_MAX 255

Modified: grass/trunk/lib/raster/set_window.c
===================================================================
--- grass/trunk/lib/raster/set_window.c	2009-06-22 06:02:37 UTC (rev 38018)
+++ grass/trunk/lib/raster/set_window.c	2009-06-22 06:35:20 UTC (rev 38019)
@@ -15,7 +15,7 @@
 #include <grass/raster.h>
 #include <grass/glocale.h>
 
-#include "G.h"
+#include "R.h"
 
 /*!
  * \brief Establishes 'window' as the current working window.
@@ -47,9 +47,9 @@
     /* 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];
+    maskfd = R__.auto_mask > 0 ? R__.mask_fd : -1;
+    for (i = 0; i < R__.fileinfo_count; i++) {
+	struct fileinfo *fcb = &R__.fileinfo[i];
 	if (fcb->open_mode == OPEN_OLD) {
 	    if (fcb->cellhd.zone == window->zone &&
 		fcb->cellhd.proj == window->proj)
@@ -63,25 +63,25 @@
     }
 
     /* close the mask */
-    if (G__.auto_mask > 0) {
+    if (R__.auto_mask > 0) {
 	Rast_close_cell(maskfd);
-	/* G_free (G__.mask_buf); */
-	G__.mask_fd = -1;
-	G__.auto_mask = -1;	/* turn off masking */
+	/* G_free (R__.mask_buf); */
+	R__.mask_fd = -1;
+	R__.auto_mask = -1;	/* turn off masking */
     }
 
     /* copy the window to the current window */
-    G_copy((char *)&G__.window, (char *)window, sizeof(*window));
+    G_copy((char *)&R__.window, (char *)window, sizeof(*window));
 
-    G__.window_set = 1;
+    R__.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];
+    for (i = 0; i < R__.fileinfo_count; i++) {
+	struct fileinfo *fcb = &R__.fileinfo[i];
 
 	if (fcb->open_mode != OPEN_OLD &&
 	    fcb->open_mode != OPEN_NEW_UNCOMPRESSED &&
@@ -89,14 +89,14 @@
 	    continue;
 
 	if (fcb->open_mode == OPEN_OLD)
-	    G__create_window_mapping(i);
+	    Rast__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,
+	    fcb->data = (unsigned char *) G_calloc (R__.window.cols,
 						    Rast_raster_size(fcb->map_type));
 	}
 
@@ -104,7 +104,7 @@
 	for (j=0;j< NULL_ROWS_INMEM; j++)
 	{
 	    G_free (fcb->NULL_ROWS[j]);
-	    fcb->NULL_ROWS[j] = (G__.window.cols);
+	    fcb->NULL_ROWS[j] = (R__.window.cols);
 	}
 
 

Copied: grass/trunk/lib/raster/window_map.c (from rev 38014, grass/trunk/lib/gis/window_map.c)
===================================================================
--- grass/trunk/lib/raster/window_map.c	                        (rev 0)
+++ grass/trunk/lib/raster/window_map.c	2009-06-22 06:35:20 UTC (rev 38019)
@@ -0,0 +1,171 @@
+/*!
+ * \file window_map.c
+ *
+ * \brief GIS Library - Window mapping functions.
+ *
+ * (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 <stdlib.h>
+#include <grass/gis.h>
+#include <grass/raster.h>
+
+#include "R.h"
+
+
+#define alloc_index(n) (COLUMN_MAPPING *) G_malloc((n)*sizeof(COLUMN_MAPPING))
+
+
+/*!
+ * \brief Create window mapping.
+ *
+ * Creates mapping from cell header into window. The boundaries and 
+ * resolution of the two spaces do not have to be the same or aligned in 
+ * any way.
+ *
+ * \param fd file descriptor
+ */
+void Rast__create_window_mapping(int fd)
+{
+    struct fileinfo *fcb = &R__.fileinfo[fd];
+    COLUMN_MAPPING *col;
+    int i;
+    int x;
+    double C1, C2;
+    double west;
+
+    Rast__init_window();
+
+    if (fcb->open_mode >= 0 && fcb->open_mode != OPEN_OLD)	/* open for write? */
+	return;
+    if (fcb->open_mode == OPEN_OLD)	/* already open ? */
+	G_free(fcb->col_map);
+
+    col = fcb->col_map = alloc_index(R__.window.cols);
+
+    /*
+     * for each column in the window, go to center of the cell,
+     * compute nearest column in the data file
+     * if column is not in data file, set column to 0
+     *
+     * for lat/lon move window so that west is bigger than
+     * cellhd west.
+     */
+    west = R__.window.west;
+    if (R__.window.proj == PROJECTION_LL) {
+	while (west > fcb->cellhd.west + 360.0)
+	    west -= 360.0;
+	while (west < fcb->cellhd.west)
+	    west += 360.0;
+    }
+
+    C1 = R__.window.ew_res / fcb->cellhd.ew_res;
+    C2 = (west - fcb->cellhd.west +
+	  R__.window.ew_res / 2.0) / fcb->cellhd.ew_res;
+    for (i = 0; i < R__.window.cols; i++) {
+	x = C2;
+	if (C2 < x)		/* adjust for rounding of negatives */
+	    x--;
+	if (x < 0 || x >= fcb->cellhd.cols)	/* not in data file */
+	    x = -1;
+	*col++ = x + 1;
+	C2 += C1;
+    }
+
+    /* do wrap around for lat/lon */
+    if (R__.window.proj == PROJECTION_LL) {
+	col = fcb->col_map;
+	C2 = (west - 360.0 - fcb->cellhd.west +
+	      R__.window.ew_res / 2.0) / fcb->cellhd.ew_res;
+	for (i = 0; i < R__.window.cols; i++) {
+	    x = C2;
+	    if (C2 < x)		/* adjust for rounding of negatives */
+		x--;
+	    if (x < 0 || x >= fcb->cellhd.cols)	/* not in data file */
+		x = -1;
+	    if (*col == 0)	/* only change those not already set */
+		*col = x + 1;
+	    col++;
+	    C2 += C1;
+	}
+    }
+
+    G_debug(3, "create window mapping (%d columns)", R__.window.cols);
+/*  for (i = 0; i < R__.window.cols; i++)
+	fprintf(stderr, "%s%ld", i % 15 ? " " : "\n", (long)fcb->col_map[i]);
+    fprintf(stderr, "\n");
+*/
+
+    /* compute C1,C2 for row window mapping */
+    fcb->C1 = R__.window.ns_res / fcb->cellhd.ns_res;
+    fcb->C2 =
+	(fcb->cellhd.north - R__.window.north +
+	 R__.window.ns_res / 2.0) / fcb->cellhd.ns_res;
+}
+
+
+/*!
+ * \brief Initialize window.
+ *
+ */
+void Rast__init_window(void)
+{
+    if (G_is_initialized(&R__.window_set))
+	return;
+
+    G__init_window();
+
+    G_get_window(&R__.window);
+
+    G_initialize_done(&R__.window_set);
+}
+
+/*!
+ * \brief Loops rows until mismatch?.
+ *
+ * This routine works fine if the mask is not set. It may give
+ * incorrect results with a mask, since the mask row may have a
+ * different repeat value. The issue can be fixed by doing it for the
+ * mask as well and using the smaller value.
+ *
+ * \param fd file descriptor
+ * \param row starting row
+ *
+ * \return number of rows completed
+ */
+int Rast_row_repeat_nomask(int fd, int row)
+{
+    struct fileinfo *fcb = &R__.fileinfo[fd];
+    double f;
+    int r1, r2;
+    int count;
+
+    count = 1;
+
+    /* r1 is the row in the raster map itself.
+     * r2 is the next row(s) in the raster map
+     * see get_row.c for details on this calculation
+     */
+    f = row * fcb->C1 + fcb->C2;
+    r1 = f;
+    if (f < r1)
+	r1--;
+
+    while (++row < R__.window.rows) {
+	f = row * fcb->C1 + fcb->C2;
+	r2 = f;
+	if (f < r2)
+	    r2--;
+	if (r1 != r2)
+	    break;
+
+	count++;
+    }
+
+    return count;
+}



More information about the grass-commit mailing list