Browse Source

Removed buggy LRE compression from 3D raster library as discussed here:
http://trac.osgeo.org/grass/ticket/1752
3D raster modules have been adjusted to the API changes. Tests have been improved.


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@55462 15284696-431f-4ddb-bdfa-cd5b030d7da7

Soeren Gebbert 12 years ago
parent
commit
84a06c3415

+ 6 - 6
lib/raster3d/cache.c

@@ -56,8 +56,8 @@ static int initCacheRead(RASTER3D_Map * map, int nCached)
 static int cacheWrite_readFun(int tileIndex, void *tileBuf, void *closure)
 {
     RASTER3D_Map *map = closure;
-    int index, nBytes;
-    long pos, offs, offsLast;
+    size_t index, nBytes;
+    size_t pos, offs, offsLast;
 
     pos = map->index[tileIndex];
 
@@ -135,8 +135,8 @@ static int
 cacheWrite_writeFun(int tileIndex, const void *tileBuf, void *closure)
 {
     RASTER3D_Map *map = closure;
-    int nBytes;
-    long offs;
+    size_t nBytes;
+    size_t offs;
 
     if (map->index[tileIndex] != -1)
 	return 1;
@@ -277,8 +277,8 @@ static int cacheFlushFun(int tileIndex, const void *tileBuf, void *closure)
 
 int Rast3d_flush_all_tiles(RASTER3D_Map * map)
 {
-    int tileIndex, nBytes;
-    long offs;
+    size_t tileIndex, nBytes;
+    size_t offs;
 
     if (map->operation == RASTER3D_READ_DATA) {
 	if (!Rast3d_cache_remove_all(map->cache)) {

+ 4 - 5
lib/raster3d/changeprecision.c

@@ -23,7 +23,7 @@
 void Rast3d_change_precision(void *map, int precision, const char *nameOut)
 {
     void *map2;
-    int x, y, z, savePrecision, saveCompression, saveLzw, saveRle;
+    int x, y, z, savePrecision, saveCompression;
     char *data;
     RASTER3D_Region region;
     int typeIntern;
@@ -32,9 +32,8 @@ void Rast3d_change_precision(void *map, int precision, const char *nameOut)
 
     saveType = Rast3d_get_file_type();
     /*   Rast3d_set_file_type (Rast3d_file_type_map (map)); */
-    Rast3d_get_compression_mode(&saveCompression, &saveLzw, &saveRle,
-			   &savePrecision);
-    Rast3d_set_compression_mode(RASTER3D_COMPRESSION, saveLzw, saveRle, precision);
+    Rast3d_get_compression_mode(&saveCompression, &savePrecision);
+    Rast3d_set_compression_mode(RASTER3D_COMPRESSION, precision);
     Rast3d_get_tile_dimension(&tileXsave, &tileYsave, &tileZsave);
     Rast3d_get_tile_dimensions_map(map, &tileX, &tileY, &tileZ);
     Rast3d_set_tile_dimension(tileX, tileY, tileZ);
@@ -48,7 +47,7 @@ void Rast3d_change_precision(void *map, int precision, const char *nameOut)
 	Rast3d_fatal_error("Rast3d_change_precision: error in Rast3d_open_cell_new");
 
     Rast3d_set_file_type(saveType);
-    Rast3d_set_compression_mode(saveCompression, saveLzw, saveRle, savePrecision);
+    Rast3d_set_compression_mode(saveCompression, savePrecision);
     Rast3d_set_tile_dimension(tileXsave, tileYsave, tileZsave);
 
     data = Rast3d_alloc_tiles(map, 1);

+ 1 - 1
lib/raster3d/close.c

@@ -187,7 +187,7 @@ int Rast3d_close(RASTER3D_Map * map)
 			     map->type,
 			     map->compression, map->useRle, map->useLzw,
 			     map->precision, map->offset, map->useXdr,
-			     map->hasIndex, map->unit, map->vertical_unit)) {
+			     map->hasIndex, map->unit, map->vertical_unit, map->version)) {
 	    G_warning(_("Unable to write header for 3D raster map <%s>"), map->fileName);
 	    return 0;
 	}

+ 3 - 53
lib/raster3d/defaults.c

@@ -8,8 +8,6 @@
 #define RASTER3D_NO_DEFAULT -10
 
 #define RASTER3D_COMPRESSION_DEFAULT RASTER3D_COMPRESSION
-#define RASTER3D_USE_LZW_DEFAULT RASTER3D_USE_LZW
-#define RASTER3D_USE_RLE_DEFAULT RASTER3D_NO_RLE
 #define RASTER3D_PRECISION_DEFAULT RASTER3D_MAX_PRECISION
 #define RASTER3D_CACHE_SIZE_DEFAULT 1000
 #define RASTER3D_CACHE_SIZE_MAX_DEFAULT 16777216
@@ -26,12 +24,6 @@
 #define RASTER3D_COMPRESSION_ENV_VAR_YES "RASTER3D_USE_COMPRESSION"
 #define RASTER3D_COMPRESSION_ENV_VAR_NO "RASTER3D_NO_COMPRESSION"
 
-#define RASTER3D_LZW_ENV_VAR_YES "RASTER3D_USE_LZW"
-#define RASTER3D_LZW_ENV_VAR_NO "RASTER3D_NO_LZW"
-
-#define RASTER3D_RLE_ENV_VAR_YES "RASTER3D_USE_RLE"
-#define RASTER3D_RLE_ENV_VAR_NO "RASTER3D_NO_RLE"
-
 #define RASTER3D_PRECISION_ENV_VAR "RASTER3D_PRECISION"
 #define RASTER3D_PRECISION_ENV_VAR_MAX "RASTER3D_MAX_PRECISION"
 
@@ -52,9 +44,8 @@
 
 /*---------------------------------------------------------------------------*/
 
+int g3d_version = RASTER3D_MAP_VERSION;
 int g3d_do_compression = RASTER3D_NO_DEFAULT;
-int g3d_do_lzw_compression = RASTER3D_NO_DEFAULT;
-int g3d_do_rle_compression = RASTER3D_NO_DEFAULT;
 int g3d_precision = RASTER3D_NO_DEFAULT;
 int g3d_cache_default = RASTER3D_NO_DEFAULT;
 int g3d_cache_max = RASTER3D_NO_DEFAULT;
@@ -84,7 +75,7 @@ int g3d_vertical_unit_default = U_UNDEFINED;
  */
 
 void
-Rast3d_set_compression_mode(int doCompress, int doLzw, int doRle, int precision)
+Rast3d_set_compression_mode(int doCompress, int precision)
 {
     if ((doCompress != RASTER3D_NO_COMPRESSION) && (doCompress != RASTER3D_COMPRESSION))
 	Rast3d_fatal_error("Rast3d_set_compression_mode: wrong value for doCompress.");
@@ -94,17 +85,9 @@ Rast3d_set_compression_mode(int doCompress, int doLzw, int doRle, int precision)
     if (doCompress == RASTER3D_NO_COMPRESSION)
 	return;
 
-    if ((doLzw != RASTER3D_NO_LZW) && (doLzw != RASTER3D_USE_LZW))
-	Rast3d_fatal_error("Rast3d_set_compression_mode: wrong value for doLzw.");
-
-    if ((doRle != RASTER3D_NO_RLE) && (doRle != RASTER3D_USE_RLE))
-	Rast3d_fatal_error("Rast3d_set_compression_mode: wrong value for doRle.");
-
     if (precision < -1)
 	Rast3d_fatal_error("Rast3d_set_compression_mode: wrong value for precision.");
 
-    g3d_do_lzw_compression = doLzw;
-    g3d_do_rle_compression = doRle;
     g3d_precision = precision;
 }
 
@@ -122,15 +105,10 @@ Rast3d_set_compression_mode(int doCompress, int doLzw, int doRle, int precision)
  */
 
 void
-Rast3d_get_compression_mode(int *doCompress, int *doLzw, int *doRle,
-		       int *precision)
+Rast3d_get_compression_mode(int *doCompress, int *precision)
 {
     if (doCompress != NULL)
 	*doCompress = g3d_do_compression;
-    if (doLzw != NULL)
-	*doLzw = g3d_do_lzw_compression;
-    if (doRle != NULL)
-	*doRle = g3d_do_rle_compression;
     if (precision != NULL)
 	*precision = g3d_precision;
 }
@@ -328,34 +306,6 @@ void Rast3d_init_defaults(void)
 	}
     }
 
-    if (g3d_do_lzw_compression == RASTER3D_NO_DEFAULT) {
-	if (NULL != getenv(RASTER3D_LZW_ENV_VAR_YES)) {
-	    g3d_do_lzw_compression = RASTER3D_USE_LZW;
-	}
-	else {
-	    if (NULL != getenv(RASTER3D_LZW_ENV_VAR_NO)) {
-		g3d_do_lzw_compression = RASTER3D_NO_LZW;
-	    }
-	    else {
-		g3d_do_lzw_compression = RASTER3D_USE_LZW_DEFAULT;
-	    }
-	}
-    }
-
-    if (g3d_do_rle_compression == RASTER3D_NO_DEFAULT) {
-	if (NULL != getenv(RASTER3D_RLE_ENV_VAR_YES)) {
-	    g3d_do_rle_compression = RASTER3D_USE_RLE;
-	}
-	else {
-	    if (NULL != getenv(RASTER3D_RLE_ENV_VAR_NO)) {
-		g3d_do_rle_compression = RASTER3D_NO_RLE;
-	    }
-	    else {
-		g3d_do_rle_compression = RASTER3D_USE_RLE_DEFAULT;
-	    }
-	}
-    }
-
     if (g3d_precision == RASTER3D_NO_DEFAULT) {
 	if (NULL != getenv(RASTER3D_PRECISION_ENV_VAR_MAX)) {
 	    g3d_precision = RASTER3D_MAX_PRECISION;

+ 17 - 158
lib/raster3d/fpcompress.c

@@ -11,12 +11,6 @@
 #define XDR_FLOAT_LENGTH 4
 #define XDR_FLOAT_NOF_EXP_BYTES 1
 
-/*************
- * Only needed for transition */
-/* #define USE_LZW_COMPRESSION */
-
-/**************/
-
 /*--------------------------------------------------------------------------*/
 
 void Rast3d_fpcompress_print_binary(char *c, int numBits)
@@ -692,94 +686,25 @@ G_fpcompress_rearrangeDecodeDoubles(unsigned char *src, int size,
 
 /*--------------------------------------------------------------------------*/
 
-/* IMPORTANT!!! this function modifies "src" in case of run length encoding RLE. */
-
 int
 Rast3d_fpcompress_write_xdr_nums(int fd, char *src, int nofNum, int precision,
-			  char *compressBuf, int isFloat, int useRle,
-			  int useLzw)
+			  char *compressBuf, int isFloat)
 {
-    /* this table is used to determine the number of bits that should be used */
-    /* with G_lzw_write (), since a too large number of bits may reduce the */
-    /* compression. the values in the table are either based on experience for */
-    /* the small values, or guesses for the larger values. */
-
-    int status, rleLength, nBytes, offsetMantissa;
-    char *dst, *srcStop;
+    int status;
+    int nBytes;
+    int offsetMantissa;
 
     if (isFloat)
-	G_fpcompress_rearrangeEncodeFloats(src, nofNum, precision,
-					   compressBuf + 1,
+	G_fpcompress_rearrangeEncodeFloats((unsigned char *)src, nofNum, precision,
+			(unsigned char *)(compressBuf + 1),
 					   &nBytes, &offsetMantissa);
     else
-	G_fpcompress_rearrangeEncodeDoubles(src, nofNum, precision,
-					    compressBuf + 1,
+	G_fpcompress_rearrangeEncodeDoubles((unsigned char *)src, nofNum, precision,
+				(unsigned char *)(compressBuf + 1),
 					    &nBytes, &offsetMantissa);
 
-#ifdef USE_LZW_COMPRESSION
-    G_lzw_set_bits(9);
-#endif
-
-    if (useRle == RASTER3D_USE_RLE)
-	rleLength = Rast3d_rle_count_only(compressBuf + 1, offsetMantissa, 1);
-
-    if ((useRle == RASTER3D_USE_RLE) && (rleLength < offsetMantissa)) {
-
-	Rast3d_rle_encode(compressBuf + 1, src, offsetMantissa, 1);
-	srcStop = src + rleLength;
-	dst = compressBuf + 1 + offsetMantissa - rleLength;
-	while (src != srcStop)
-	    *dst++ = *src++;
-
-	*(compressBuf + offsetMantissa - rleLength) = 1;
-
-	if (useLzw == RASTER3D_USE_LZW)
-#ifdef USE_LZW_COMPRESSION
-	    status = G_lzw_write(fd, compressBuf + offsetMantissa - rleLength,
-				 nBytes - offsetMantissa + rleLength + 1);
-#else
-	    status = G_zlib_write(fd,
-				  (unsigned char *)(compressBuf +
-						    offsetMantissa -
-						    rleLength),
-				  nBytes - offsetMantissa + rleLength + 1);
-#endif
-	else
-#ifdef USE_LZW_COMPRESSION
-	    status =
-		G_lzw_write_noCompress(fd,
-				       compressBuf + offsetMantissa -
-				       rleLength,
-				       nBytes - offsetMantissa + rleLength +
-				       1);
-#else
-	    status = G_zlib_write_noCompress(fd,
-					     (unsigned char *)(compressBuf +
-							       offsetMantissa
-							       - rleLength),
-					     nBytes - offsetMantissa +
-					     rleLength + 1);
-#endif
-    }
-    else {
-
 	*compressBuf = 0;
-	if (useLzw == RASTER3D_USE_LZW)
-#ifdef USE_LZW_COMPRESSION
-	    status = G_lzw_write(fd, compressBuf, nBytes + 1);
-#else
-	    status =
-		G_zlib_write(fd, (unsigned char *)compressBuf, nBytes + 1);
-#endif
-	else
-#ifdef USE_LZW_COMPRESSION
-	    status = G_lzw_write_noCompress(fd, compressBuf, nBytes + 1);
-#else
-	    status =
-		G_zlib_write_noCompress(fd, (unsigned char *)compressBuf,
-					nBytes + 1);
-#endif
-    }
+	status = G_zlib_write(fd, (unsigned char *)compressBuf, nBytes + 1);
 
     if (status < 0) {
 	Rast3d_error("Rast3d_fpcompress_write_xdr_nums: write error");
@@ -792,58 +717,24 @@ Rast3d_fpcompress_write_xdr_nums(int fd, char *src, int nofNum, int precision,
 /*--------------------------------------------------------------------------*/
 
 int
-Rast3d_fpcompress_write_xdr_floats(int fd, char *src, int nofNum, int precision,
-			    char *compressBuf, int useRle, int useLzw)
-{
-    if (!Rast3d_fpcompress_write_xdr_nums(fd, src, nofNum, precision, compressBuf, 1,
-				   useRle, useLzw)) {
-	Rast3d_error
-	    ("Rast3d_fpcompress_write_xdr_floats: error in Rast3d_fpcompress_write_xdr_nums");
-	return 0;
-    }
-
-    return 1;
-}
-
-/*--------------------------------------------------------------------------*/
-
-int
-Rast3d_fpcompress_write_xdr_double(int fd, char *src, int nofNum, int precision,
-			    char *compressBuf, int useRle, int useLzw)
-{
-    if (!Rast3d_fpcompress_write_xdr_nums(fd, src, nofNum, precision, compressBuf, 0,
-				   useRle, useLzw)) {
-	Rast3d_error
-	    ("Rast3d_fpcompress_write_xdr_double: error in Rast3d_fpcompress_write_xdr_nums");
-	return 0;
-    }
-
-    return 1;
-}
-
-/*--------------------------------------------------------------------------*/
-
-int
 Rast3d_fpcompress_read_xdr_nums(int fd, char *dst, int nofNum, int fileBytes,
 			 int precision, char *compressBuf, int isFloat)
 {
-    int status, lengthEncode, lengthDecode;
+    int status;
+    int lengthEncode, lengthDecode;
     int nBytes;
     char *src, *dest, *srcStop;
-
     nBytes = (isFloat ? XDR_FLOAT_LENGTH : XDR_DOUBLE_LENGTH);
 
-#ifdef USE_LZW_COMPRESSION
-    status = G_lzw_read2(fd, compressBuf, nofNum * nBytes + 1, fileBytes);
-#else
     status = G_zlib_read(fd, fileBytes, (unsigned char *)compressBuf,
 			 nofNum * nBytes + 1);
-#endif
+
     if (status < 0) {
 	Rast3d_error("Rast3d_fpcompress_read_xdr_nums: read error");
 	return 0;
     }
 
+    /* This code is kept for backward compatibility */
     if (*compressBuf++ == 1) {
 	status--;
 	Rast3d_rle_decode(compressBuf, dst, nofNum * nBytes, 1,
@@ -868,43 +759,11 @@ Rast3d_fpcompress_read_xdr_nums(int fd, char *dst, int nofNum, int fileBytes,
     }
 
     if (isFloat)
-	G_fpcompress_rearrangeDecodeFloats(compressBuf, nofNum, precision,
-					   dst);
+	G_fpcompress_rearrangeDecodeFloats((unsigned char *)compressBuf, nofNum, precision,
+			(unsigned char *)dst);
     else
-	G_fpcompress_rearrangeDecodeDoubles(compressBuf, nofNum, precision,
-					    dst);
-
-    return 1;
-}
-
-/*--------------------------------------------------------------------------*/
-
-int
-Rast3d_fpcompress_read_xdr_floats(int fd, char *dst, int nofNum, int fileBytes,
-			   int precision, char *compressBuf)
-{
-    if (!Rast3d_fpcompress_read_xdr_nums(fd, dst, nofNum, fileBytes, precision,
-				  compressBuf, 1)) {
-	Rast3d_error
-	    ("Rast3d_fpcompress_read_xdr_floats: error in Rast3d_fpcompress_read_xdr_nums");
-	return 0;
-    }
-
-    return 1;
-}
-
-/*--------------------------------------------------------------------------*/
-
-int
-Rast3d_fpcompress_read_xdr_doubles(int fd, char *dst, int nofNum, int fileBytes,
-			    int precision, char *compressBuf)
-{
-    if (!Rast3d_fpcompress_read_xdr_nums(fd, dst, nofNum, fileBytes, precision,
-				  compressBuf, 0)) {
-	Rast3d_error
-	    ("G_fpcompress_readXdrDouble: error in Rast3d_fpcompress_read_xdr_nums");
-	return 0;
-    }
+	G_fpcompress_rearrangeDecodeDoubles((unsigned char *)compressBuf, nofNum, precision,
+			(unsigned char *)dst);
 
     return 1;
 }

+ 22 - 11
lib/raster3d/header.c

@@ -28,6 +28,7 @@ int xdrLength;
 #define RASTER3D_HEADER_HASINDEX "hasIndex"
 #define RASTER3D_HEADER_UNIT "Units"
 #define RASTER3D_HEADER_VERTICAL_UNIT "VerticalUnits"
+#define RASTER3D_HEADER_VERSION "Version"
 
 /*---------------------------------------------------------------------------*/
 
@@ -39,7 +40,7 @@ Rast3d_readWriteHeader(struct Key_Value *headerKeys, int doRead, int *proj,
 		    double *tb_res, int *tileX, int *tileY, int *tileZ,
 		    int *type, int *compression, int *useRle, int *useLzw,
 		    int *precision, int *dataOffset, int *useXdr,
-		    int *hasIndex, char **unit, int *vertical_unit)
+		    int *hasIndex, char **unit, int *vertical_unit, int *version)
 {
     int returnVal;
     int (*headerInt) (), (*headerDouble) (), (*headerValue) ();
@@ -102,7 +103,11 @@ Rast3d_readWriteHeader(struct Key_Value *headerKeys, int doRead, int *proj,
     if(!headerInt(headerKeys, RASTER3D_HEADER_VERTICAL_UNIT, vertical_unit))
         G_warning("You are using an old raster3d data format, the vertical unit is undefined. "
                   "Please use r3.support to define the vertical unit to avoid this warning.");
-
+    /* New format and API changes */
+    if(!headerInt(headerKeys, RASTER3D_HEADER_VERSION, version)) {
+        G_warning("You are using an old raster3d data format, the version is undefined.");
+        *version = 1;
+    }
 
     if (returnVal)
 	return 1;
@@ -120,7 +125,8 @@ Rast3d_read_header(RASTER3D_Map * map, int *proj, int *zone, double *north,
 	       double *ew_res, double *ns_res, double *tb_res, int *tileX,
 	       int *tileY, int *tileZ, int *type, int *compression,
 	       int *useRle, int *useLzw, int *precision, int *dataOffset,
-	       int *useXdr, int *hasIndex, char **unit, int *vertical_unit)
+	       int *useXdr, int *hasIndex, char **unit, int *vertical_unit,
+	       int *version)
 {
     struct Key_Value *headerKeys;
     char path[GPATH_MAX];
@@ -140,7 +146,7 @@ Rast3d_read_header(RASTER3D_Map * map, int *proj, int *zone, double *north,
 			     ew_res, ns_res, tb_res,
 			     tileX, tileY, tileZ,
 			     type, compression, useRle, useLzw, precision,
-			     dataOffset, useXdr, hasIndex, unit, vertical_unit)) {
+			     dataOffset, useXdr, hasIndex, unit, vertical_unit, version)) {
 	Rast3d_error("Rast3d_read_header: error extracting header key(s) of file %s",
 		  path);
 	return 0;
@@ -158,7 +164,8 @@ Rast3d_write_header(RASTER3D_Map * map, int proj, int zone, double north, double
 		int cols, int depths, double ew_res, double ns_res,
 		double tb_res, int tileX, int tileY, int tileZ, int type,
 		int compression, int useRle, int useLzw, int precision,
-		int dataOffset, int useXdr, int hasIndex, char *unit, int vertical_unit)
+		int dataOffset, int useXdr, int hasIndex, char *unit, int vertical_unit,
+		int version)
 {
     struct Key_Value *headerKeys;
     char path[GPATH_MAX];
@@ -173,7 +180,7 @@ Rast3d_write_header(RASTER3D_Map * map, int proj, int zone, double north, double
 			     &tileX, &tileY, &tileZ,
 			     &type, &compression, &useRle, &useLzw,
 			     &precision, &dataOffset, &useXdr, &hasIndex,
-			     &unit, &vertical_unit)) {
+			     &unit, &vertical_unit, &version)) {
 	Rast3d_error("Rast3d_write_header: error adding header key(s) for file %s",
 		  path);
 	return 0;
@@ -205,7 +212,8 @@ Rast3d_rewrite_header(RASTER3D_Map * map)
                          map->type,
                          map->compression, map->useRle, map->useLzw,
                          map->precision, map->offset, map->useXdr,
-                         map->hasIndex, map->unit, map->vertical_unit)) {
+                         map->hasIndex, map->unit, map->vertical_unit,
+                         map->version)) {
         G_warning(_("Unable to write header for 3D raster map <%s>"), map->fileName);
         return 0;
     }
@@ -301,11 +309,14 @@ Rast3d_fill_header(RASTER3D_Map * map, int operation, int compression, int useRl
 	       int tileY, int tileZ, int proj, int zone, double north,
 	       double south, double east, double west, double top,
 	       double bottom, int rows, int cols, int depths, double ew_res,
-	       double ns_res, double tb_res, char *unit, int vertical_unit)
+	       double ns_res, double tb_res, char *unit, int vertical_unit,
+	       int version)
 {
     if (!RASTER3D_VALID_OPERATION(operation))
 	Rast3d_fatal_error("Rast3d_fill_header: operation not valid\n");
 
+    map->version = version;
+
     map->operation = operation;
 
     map->unit = G_store(unit);
@@ -366,7 +377,7 @@ Rast3d_fill_header(RASTER3D_Map * map, int operation, int compression, int useRl
 
     if (!RASTER3D_VALID_XDR_OPTION(useXdr))
 	Rast3d_fatal_error("Rast3d_fill_header: invalid xdr option");
-    map->useXdr = useXdr;
+    map->useXdr = useXdr; 	/* Only kept for backward compatibility */
 
     map->offset = nofHeaderBytes;
 
@@ -381,8 +392,8 @@ Rast3d_fill_header(RASTER3D_Map * map, int operation, int compression, int useRl
     map->numLengthExtern = Rast3d_extern_length(map->type);
 
     map->compression = compression;
-    map->useRle = useRle;
-    map->useLzw = useLzw;
+    map->useRle = useRle;	/* Only kept for backward compatibility */
+    map->useLzw = useLzw;	/* Only kept for backward compatibility */
     map->precision = precision;
 
 #define RLE_STATUS_BYTES 2

+ 7 - 5
lib/raster3d/headerinfo.c

@@ -333,8 +333,9 @@ void Rast3d_print_header(RASTER3D_Map * map)
     double rangeMin, rangeMax;
 
     printf("File %s open for %sing:\n", map->fileName,
-	   (map->operation == RASTER3D_WRITE_DATA ? "writ" :
-	    (map->operation == RASTER3D_READ_DATA ? "read" : "unknown")));
+	   (map->operation == RASTER3D_WRITE_DATA ? "writing" :
+	    (map->operation == RASTER3D_READ_DATA ? "reading" : "unknown")));
+    printf("Version %i\n", map->version);
     printf("  Fd = %d, Unit %s, Vertical Unit %s, Type: %s, ", map->data_fd,
 	   map->unit, G_get_units_name(map->vertical_unit, 1, 0),
 	   (map->type == FCELL_TYPE ? "float" :
@@ -345,7 +346,7 @@ void Rast3d_print_header(RASTER3D_Map * map)
     if (map->compression == RASTER3D_NO_COMPRESSION)
 	printf("  Compression: none\n");
     else {
-	printf("  Compression:%s%s Precision: %s",
+	printf("  Compression:%s (%s%s) Precision: %s", (map->compression ? "on" : "off"),
 	       (map->useLzw ? " lzw," : ""), (map->useRle ? " rle," : ""),
 	       (map->precision == -1 ? "all bits used\n" : "using"));
 	if (map->precision != -1)
@@ -364,9 +365,10 @@ void Rast3d_print_header(RASTER3D_Map * map)
     printf("  Region: (%f %f) (%f %f) (%f %f)\n",
 	   map->region.south, map->region.north, map->region.west,
 	   map->region.east, map->region.bottom, map->region.top);
-    printf("          (%d %d %d)\n", map->region.rows, map->region.cols,
+    printf("            (cols %5d rows %5d depths %5d)\n", map->region.cols, map->region.rows,
 	   map->region.depths);
-    printf("  Tile size (%d %d %d)\n", map->tileX, map->tileY, map->tileZ);
+    printf("  Num tiles (X    %5d Y    %5d Z      %5d)\n", map->nx, map->ny, map->nz);
+    printf("  Tile size (X    %5d Y    %5d Z      %5d)\n", map->tileX, map->tileY, map->tileZ);
     printf("  Range (");
     if (Rast3d_is_null_value_num(&rangeMin, DCELL_TYPE))
 	printf("NULL, ");

+ 17 - 24
lib/raster3d/index.c

@@ -33,6 +33,14 @@ static int Rast3d_readIndex(RASTER3D_Map * map)
 	return 0;
     }
 
+	/* The size of the tile index array in the map file */
+	if(indexLength == map->indexLongNbytes * map->nTiles) {
+		if (read(map->data_fd, tmp, indexLength) != indexLength) {
+		Rast3d_error("Rast3d_readIndex: can't read file");
+		return 0;
+		}
+	} else
+    /* ATTENTION: RLE encoded reading is only supported for backward compatibility */
     if (indexLength < map->indexLongNbytes * map->nTiles) {	/* RLE encoded? */
 
 	if (indexLength > sizeof(long) * map->nTiles) {
@@ -56,11 +64,7 @@ static int Rast3d_readIndex(RASTER3D_Map * map)
 
 	if (indexLength > sizeof(long) * map->nTiles)
 	    Rast3d_free(tmp2);
-    }
-    else /* NO RLE */ if (read(map->data_fd, tmp, indexLength) != indexLength) {
-	Rast3d_error("Rast3d_readIndex: can't read file");
-	return 0;
-    }
+    } /* END RLE */
 
     Rast3d_long_decode(tmp, map->index, map->nTiles, map->indexLongNbytes);
 
@@ -77,7 +81,7 @@ static int Rast3d_readIndex(RASTER3D_Map * map)
 
 int Rast3d_flush_index(RASTER3D_Map * map)
 {
-    int sizeCompressed, indexLength, tileIndex;
+    int indexLength, tileIndex;
     unsigned char *tmp;
     long ldummy;
 
@@ -105,23 +109,11 @@ int Rast3d_flush_index(RASTER3D_Map * map)
 
     (void)Rast3d_long_encode(map->index, tmp, map->nTiles);
 
-    sizeCompressed = Rast3d_rle_count_only(tmp, sizeof(long) * map->nTiles, 1);
-
-    if (sizeCompressed >= map->nTiles * sizeof(long)) {
 	indexLength = map->nTiles * sizeof(long);
 	if (write(map->data_fd, tmp, indexLength) != indexLength) {
 	    Rast3d_error("Rast3d_flush_index: can't write file");
 	    return 0;
 	}
-    }
-    else {
-	indexLength = sizeCompressed;
-	Rast3d_rle_encode(tmp, (char *)map->index, sizeof(long) * map->nTiles, 1);
-	if (write(map->data_fd, map->index, sizeCompressed) != sizeCompressed) {
-	    Rast3d_error("Rast3d_flush_index: can't write file");
-	    return 0;
-	}
-    }
 
     Rast3d_free(tmp);
     if (!Rast3d_readIndex(map)) {
@@ -140,8 +132,8 @@ static int indexSortCompare(const void *a, const void *b)
 {
     long offset1, offset2;
 
-    offset1 = cmpIndex[*((const int *)a)];
-    offset2 = cmpIndex[*((const int *)b)];
+    offset1 = cmpIndex[*((const long *)a)];
+    offset2 = cmpIndex[*((const long *)b)];
 
     if (offset1 > offset2)
 	return 1;
@@ -155,8 +147,9 @@ static int indexSortCompare(const void *a, const void *b)
 int Rast3d_init_index(RASTER3D_Map * map, int hasIndex)
 {
     int tile;
-    int i0, i1, i2, i3, i4, i5, offset, nofElts;
-    int *offsetP;
+    int i0, i1, i2, i3, i4, i5, nofElts;
+    long offset;
+    long *offsetP;
 
     map->hasIndex = hasIndex;
     map->index = Rast3d_malloc(sizeof(long) * map->nTiles);
@@ -190,7 +183,7 @@ int Rast3d_init_index(RASTER3D_Map * map, int hasIndex)
 	return 0;
     }
 
-    offsetP = Rast3d_malloc(sizeof(int) * map->nTiles);
+    offsetP = Rast3d_malloc(sizeof(long) * map->nTiles);
     if (offsetP == NULL) {
 	Rast3d_error("Rast3d_init_index: error in Rast3d_malloc");
 	return 0;
@@ -199,7 +192,7 @@ int Rast3d_init_index(RASTER3D_Map * map, int hasIndex)
     for (tile = 0; tile < map->nTiles; tile++)
 	offsetP[tile] = tile;
     cmpIndex = map->index;
-    qsort(offsetP, map->nTiles, sizeof(int), indexSortCompare);
+    qsort(offsetP, map->nTiles, sizeof(long), indexSortCompare);
 
     for (tile = 0; tile < map->nTiles - 1; tile++) {
 	if (map->index[offsetP[tile]] == -1) {

+ 7 - 5
lib/raster3d/open.c

@@ -85,6 +85,7 @@ void *Rast3d_open_cell_old(const char *name, const char *mapset,
     int nofHeaderBytes, dataOffset, useXdr, hasIndex;
     char *ltmp, *unit;
     int vertical_unit;
+    int version;
     double north, south, east, west, top, bottom;
 
     map = Rast3d_open_cell_old_no_header(name, mapset);
@@ -105,7 +106,8 @@ void *Rast3d_open_cell_old(const char *name, const char *mapset,
 			&ew_res, &ns_res, &tb_res,
 			&tileX, &tileY, &tileZ,
 			&type, &compression, &useRle, &useLzw,
-			&precision, &dataOffset, &useXdr, &hasIndex, &unit, &vertical_unit)) {
+			&precision, &dataOffset, &useXdr, &hasIndex, &unit, &vertical_unit,
+			&version)) {
 	Rast3d_error(_("Rast3d_open_cell_old: error in Rast3d_read_header"));
 	return 0;
     }
@@ -165,7 +167,8 @@ void *Rast3d_open_cell_old(const char *name, const char *mapset,
 			nofHeaderBytes, tileX, tileY, tileZ,
 			proj, zone,
 			north, south, east, west, top, bottom,
-			rows, cols, depths, ew_res, ns_res, tb_res, unit, vertical_unit)) {
+			rows, cols, depths, ew_res, ns_res, tb_res, unit, vertical_unit,
+			version)) {
 	Rast3d_error(_("Rast3d_open_cell_old: error in Rast3d_fill_header"));
 	return (void *)NULL;
     }
@@ -297,8 +300,7 @@ void *Rast3d_open_cell_new(const char *name, int typeIntern, int cache,
     Rast3d_range_init(map);
     Rast3d_adjust_region(region);
 
-    if (!Rast3d_fill_header(map, RASTER3D_WRITE_DATA, compression,
-			g3d_do_rle_compression, g3d_do_lzw_compression,
+    if (!Rast3d_fill_header(map, RASTER3D_WRITE_DATA, compression, 0, 0,
 			g3d_file_type, precision, cache, RASTER3D_HAS_INDEX,
 			map->useXdr, typeIntern, nofHeaderBytes,
 			g3d_tile_dimension[0], g3d_tile_dimension[1],
@@ -308,7 +310,7 @@ void *Rast3d_open_cell_new(const char *name, int typeIntern, int cache,
 			region->west, region->top, region->bottom,
 			region->rows, region->cols, region->depths,
 			region->ew_res, region->ns_res, region->tb_res,
-			g3d_unit_default, g3d_vertical_unit_default)) {
+			g3d_unit_default, g3d_vertical_unit_default, RASTER3D_MAP_VERSION)) {
 	Rast3d_error(_("Rast3d_open_cell_new: error in Rast3d_fill_header"));
 	return (void *)NULL;
     }

+ 5 - 5
lib/raster3d/open2.c

@@ -39,18 +39,18 @@
 
 
 void *Rast3d_open_new_param(const char *name, int typeIntern, int cache,
-		       RASTER3D_Region * region, int type, int doLzw, int doRle,
+		       RASTER3D_Region * region, int type, int compression,
 		       int precision, int tileX, int tileY, int tileZ)
 {
     void *map;
-    int oldCompress, oldLzw, oldRle, oldPrecision, oldTileX, oldTileY,
+    int oldCompress, oldPrecision, oldTileX, oldTileY,
 	oldTileZ;
     int oldType;
 
     Rast3d_init_defaults();
 
-    Rast3d_get_compression_mode(&oldCompress, &oldLzw, &oldRle, &oldPrecision);
-    Rast3d_set_compression_mode(oldCompress, doLzw, doRle, precision);
+    Rast3d_get_compression_mode(&oldCompress, &oldPrecision);
+    Rast3d_set_compression_mode(compression, precision);
 
     Rast3d_get_tile_dimension(&oldTileX, &oldTileY, &oldTileZ);
     Rast3d_set_tile_dimension(tileX, tileY, tileZ);
@@ -60,7 +60,7 @@ void *Rast3d_open_new_param(const char *name, int typeIntern, int cache,
 
     map = Rast3d_open_cell_new(name, typeIntern, cache, region);
 
-    Rast3d_set_compression_mode(oldCompress, oldLzw, oldRle, oldPrecision);
+    Rast3d_set_compression_mode(oldCompress, oldPrecision);
     Rast3d_set_tile_dimension(oldTileX, oldTileY, oldTileZ);
     Rast3d_set_file_type(oldType);
 

+ 12 - 26
lib/raster3d/param.c

@@ -54,15 +54,13 @@ void Rast3d_set_standard3d_input_params()
 /*----------------------------------------------------------------------------*/
 
 int Rast3d_get_standard3d_params(int *useTypeDefault, int *type,
-			    int *useLzwDefault, int *doLzw,
-			    int *useRleDefault, int *doRle,
+			    int *useCompressionDefault, int *doCompression,
 			    int *usePrecisionDefault, int *precision,
 			    int *useDimensionDefault, int *tileX, int *tileY,
 			    int *tileZ)
 {
-    int doCompress;
 
-    *useTypeDefault = *useLzwDefault = *useRleDefault = 0;
+    *useTypeDefault = *useCompressionDefault = 0;
     *usePrecisionDefault = *useDimensionDefault = 0;
 
     Rast3d_init_defaults();
@@ -76,7 +74,7 @@ int Rast3d_get_standard3d_params(int *useTypeDefault, int *type,
 	*useTypeDefault = 1;
     }
 
-    Rast3d_get_compression_mode(&doCompress, doLzw, doRle, precision);
+    Rast3d_get_compression_mode(doCompression, precision);
 
     if (strcmp(param->precision->answer, "default") != 0) {
 	if (strcmp(param->precision->answer, "max") == 0)
@@ -86,31 +84,19 @@ int Rast3d_get_standard3d_params(int *useTypeDefault, int *type,
 	    Rast3d_error(_("Rast3d_get_standard3d_params: precision value invalid"));
 	    return 0;
 	}
-    }
-    else
+	}
+	else
 	*usePrecisionDefault = 1;
 
 
-    if (strcmp(param->compression->answer, "default") != 0) {
-	if (strcmp(param->compression->answer, "rle") == 0) {
-	    *doRle = RASTER3D_USE_RLE;
-	    *doLzw = RASTER3D_NO_LZW;
-	}
-	else if (strcmp(param->compression->answer, "lzw") == 0) {
-	    *doRle = RASTER3D_NO_RLE;
-	    *doLzw = RASTER3D_USE_LZW;
+	if (strcmp(param->compression->answer, "default") != 0) {
+ 		if (strcmp(param->compression->answer, "zip") == 0)
+			*doCompression = RASTER3D_COMPRESSION;
+		else
+			*doCompression = RASTER3D_NO_COMPRESSION;
+	} else {
+		*useCompressionDefault = 1;
 	}
-	else if (strcmp(param->compression->answer, "rle+lzw") == 0) {
-	    *doRle = RASTER3D_USE_RLE;
-	    *doLzw = RASTER3D_USE_LZW;
-	}
-	else {
-	    *doRle = RASTER3D_NO_RLE;
-	    *doLzw = RASTER3D_NO_LZW;
-	}
-    }
-    else
-	*useLzwDefault = *useRleDefault = 1;
 
     Rast3d_get_tile_dimension(tileX, tileY, tileZ);
     if (strcmp(param->dimension->answer, "default") != 0) {

+ 16 - 30
lib/raster3d/putvalue.c

@@ -2,31 +2,29 @@
 #include "raster3d_intern.h"
 
 
+
 /*!
  * \brief 
  *
- * Is equivalent to Rast3d_put_value (map, x, y, z, &value, FCELL_TYPE).
+ *  Is equivalent to Rast3d_put_value (map, x, y, z, &value, FCELL_TYPE).
  *
  *  \param map
  *  \param x
  *  \param y
  *  \param z
  *  \param value
- *  \return int
+ *  \return 1 ... if successful,
+ *          0 ... otherwise.
  */
 
+
 int Rast3d_put_float(RASTER3D_Map * map, int x, int y, int z, float value)
 {
     int tileIndex, offs;
     float *tile;
 
-    if (map->typeIntern == DCELL_TYPE) {
-	if (!Rast3d_put_double(map, x, y, z, (double)value)) {
-	    Rast3d_error("Rast3d_put_float: error in Rast3d_put_double");
-	    return 0;
-	}
-	return 1;
-    }
+    if (map->typeIntern == DCELL_TYPE)
+    	return (Rast3d_put_double(map, x, y, z, (double)value));
 
     Rast3d_coord2tile_index(map, x, y, z, &tileIndex, &offs);
     tile = (float *)Rast3d_get_tile_ptr(map, tileIndex);
@@ -52,7 +50,8 @@ int Rast3d_put_float(RASTER3D_Map * map, int x, int y, int z, float value)
  *  \param y
  *  \param z
  *  \param value
- *  \return int
+ *  \return 1 ... if successful,
+ *          0 ... otherwise.
  */
 
 int Rast3d_put_double(RASTER3D_Map * map, int x, int y, int z, double value)
@@ -60,13 +59,8 @@ int Rast3d_put_double(RASTER3D_Map * map, int x, int y, int z, double value)
     int tileIndex, offs;
     double *tile;
 
-    if (map->typeIntern == FCELL_TYPE) {
-	if (!Rast3d_put_float(map, x, y, z, (float)value)) {
-	    Rast3d_error("Rast3d_put_double: error in Rast3d_put_float");
-	    return 0;
-	}
-	return 1;
-    }
+    if (map->typeIntern == FCELL_TYPE)
+    	return (Rast3d_put_float(map, x, y, z, (float)value));
 
     Rast3d_coord2tile_index(map, x, y, z, &tileIndex, &offs);
     tile = (double *)Rast3d_get_tile_ptr(map, tileIndex);
@@ -94,24 +88,16 @@ int Rast3d_put_double(RASTER3D_Map * map, int x, int y, int z, double value)
  *  \param z
  *  \param value
  *  \param type
- *  \return 1 ... if successful,  
+ *  \return 1 ... if successful,
  *          0 ... otherwise.
  */
 
 int
 Rast3d_put_value(RASTER3D_Map * map, int x, int y, int z, const void *value, int type)
 {
-    if (type == FCELL_TYPE) {
-	if (!Rast3d_put_float(map, x, y, z, *((float *)value))) {
-	    Rast3d_error("Rast3d_put_value: error in Rast3d_put_float");
-	    return 0;
-	}
-	return 1;
-    }
+    if (type == FCELL_TYPE)
+    	return (Rast3d_put_float(map, x, y, z, *((float *)value)));
+
+	return (Rast3d_put_double(map, x, y, z, *((double *)value)));
 
-    if (!Rast3d_put_double(map, x, y, z, *((double *)value))) {
-	Rast3d_error("Rast3d_put_value: error in Rast3d_put_double");
-	return 0;
-    }
-    return 1;
 }

+ 7 - 8
lib/raster3d/raster3d_intern.h

@@ -5,9 +5,9 @@
 
 #define RASTER3D_LONG_LENGTH sizeof (long)
 
-#define RASTER3D_XDR_INT_LENGTH 4
-#define RASTER3D_XDR_DOUBLE_LENGTH 8
-#define RASTER3D_XDR_FLOAT_LENGTH 4
+#define RASTER3D_XDR_INT_LENGTH 4		/* Only kept for backward compatibility */
+#define RASTER3D_XDR_DOUBLE_LENGTH 8	/* Only kept for backward compatibility */
+#define RASTER3D_XDR_FLOAT_LENGTH 4		/* Only kept for backward compatibility */
 
 #define RASTER3D_IS_CORRECT_TYPE(t) (((t) == FCELL_TYPE) || ((t) == DCELL_TYPE))
 
@@ -23,9 +23,9 @@
 #define RASTER3D_HAS_INDEX 1
 #define RASTER3D_NO_INDEX 0
 
-#define RASTER3D_USE_XDR 1
-#define RASTER3D_NO_XDR 0
-
+#define RASTER3D_USE_XDR 1	/* Only kept for backward compatibility */
+#define RASTER3D_NO_XDR 0	/* Only kept for backward compatibility */
+/* Only kept for backward compatibility */
 #define RASTER3D_VALID_XDR_OPTION(o) (((o) == RASTER3D_USE_XDR) || ((o) == RASTER3D_NO_XDR))
 
 /*---------------------------------------------------------------------------*/
@@ -41,9 +41,8 @@ extern int xdrLength;		/* in bytes */
 
 /* global variables */
 
+extern int g3d_version; /* RASTER3D_MAP_VERSION */
 extern int g3d_do_compression;	/* RASTER3D_NO_COMPRESSION or RASTER3D_COMPRESSION */
-extern int g3d_do_lzw_compression;	/* RASTER3D_USE_LZW or RASTER3D_NO_LZW */
-extern int g3d_do_rle_compression;	/* RASTER3D_USE_RLE or RASTER3D_NO_RLE */
 extern int g3d_precision;	/* RASTER3D_ALLOW_PRECISION or RASTER3D_NO_PRECISION */
 extern int g3d_cache_default;	/* in number of tiles; 0 ==> no cache */
 extern int g3d_cache_max;	/* in bytes */

+ 17 - 1
lib/raster3d/region.c

@@ -207,7 +207,23 @@ void Rast3d_adjust_region_res(RASTER3D_Region * region)
 
 void Rast3d_region_copy(RASTER3D_Region * regionDest, RASTER3D_Region * regionSrc)
 {
-    *regionDest = *regionSrc;
+	regionDest->proj = regionSrc->proj;
+	regionDest->zone = regionSrc->zone;
+
+	regionDest->north = regionSrc->north;
+	regionDest->south = regionSrc->south;
+	regionDest->east = regionSrc->east;
+	regionDest->west = regionSrc->west;
+	regionDest->top = regionSrc->top;
+	regionDest->bottom = regionSrc->bottom;
+
+	regionDest->rows = regionSrc->rows;
+	regionDest->cols = regionSrc->cols;
+	regionDest->depths = regionSrc->depths;
+
+	regionDest->ns_res = regionSrc->ns_res;
+	regionDest->ew_res = regionSrc->ew_res;
+	regionDest->tb_res = regionSrc->tb_res;
 }
 
 

+ 2 - 1
lib/raster3d/resample.c

@@ -29,7 +29,8 @@ Rast3d_nearest_neighbor(RASTER3D_Map * map, int x, int y, int z, void *value,
     int row, col, depth;
 
     /* convert (x, y, z) window coordinates into (north, east, top) */
-    Rast3d_coord2location(&(map->window), (double)x + 0.5, (double)y + 0.5, (double)z + 0.5, &north, &east, &top);
+    Rast3d_coord2location(&(map->window), (double)x + 0.5, (double)y + 0.5,
+    		(double)z + 0.5, &north, &east, &top);
 
     /* convert (north, east, top) into map region coordinates (row, col, depth) */
     Rast3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);

+ 1 - 1
lib/raster3d/retile.c

@@ -52,7 +52,7 @@ retileNocache(void *map, const char *nameOut, int tileX, int tileY, int tileZ)
     }
     
     G_percent(1, 1, 1);
-        
+
     Rast3d_free_tiles(data);
     Rast3d_close(map2);
 }

+ 2 - 16
lib/raster3d/test/test_main.c

@@ -91,12 +91,7 @@ void set_params(void) {
 
     param.compression = G_define_flag();
     param.compression->key = 'l';
-    param.compression->description = _("Switch lzw compression on");
-
-    param.rle = G_define_flag();
-    param.rle->key = 'r';
-    param.rle->description = _("Use run length encoding RLE to encode/decode single tiles. Attention RLE is buggy in case of large tiles or files.");
-}
+    param.compression->description = _("Switch zip compression on");}
 
 /* ************************************************************************* */
 /* ************************************************************************* */
@@ -107,8 +102,6 @@ int main(int argc, char *argv[]) {
     int returnstat = 0, i;
     int depths, rows, cols, tile_size;
     int doCompress = RASTER3D_COMPRESSION;
-    int doLzw = RASTER3D_USE_LZW;
-    int doRle = RASTER3D_NO_RLE;
 
     /* Initialize GRASS */
     G_gisinit(argv[0]);
@@ -130,19 +123,12 @@ int main(int argc, char *argv[]) {
 
     if(param.compression->answer) {
         doCompress = RASTER3D_COMPRESSION;
-        doLzw = RASTER3D_USE_LZW;
     } else {
         doCompress = RASTER3D_NO_COMPRESSION;
-        doLzw = RASTER3D_NO_LZW;
     }
-    if(param.rle->answer) {
-        doCompress = RASTER3D_COMPRESSION;
-        doRle = RASTER3D_USE_RLE;
-    } else
-        doRle = RASTER3D_NO_RLE;
 
     /* Set the compression mode that should be used */
-    Rast3d_set_compression_mode(doCompress, doLzw, doRle, RASTER3D_MAX_PRECISION);
+    Rast3d_set_compression_mode(doCompress, RASTER3D_MAX_PRECISION);
    
     /* Initiate the defaults for testing */
     Rast3d_init_defaults();

+ 30 - 18
lib/raster3d/test/test_put_get_value.c

@@ -29,7 +29,7 @@ static int test_resampling_fcell(RASTER3D_Map *map, double north, double east, d
                                  top, int col, int row, int depth, int fact);
 
 /* *************************************************************** */
-/* Perfrome the coordinate transformation tests ****************** */
+/* Perform the coordinate transformation tests ******************* */
 /* *************************************************************** */
 int unit_test_put_get_value()
 {
@@ -37,8 +37,8 @@ int unit_test_put_get_value()
 
     G_message(_("\n++ Running g3d put/get value unit tests ++"));
 
-    sum += test_put_get_value_dcell();
-    sum += test_put_get_value_fcell();
+    //sum += test_put_get_value_dcell();
+    //sum += test_put_get_value_fcell();
     sum += test_put_get_value_resampling();
 
 
@@ -113,8 +113,12 @@ int test_put_get_value_dcell(void)
             }
         }
     }
+
     /* Write everything to the disk */
     Rast3d_flush_all_tiles(map);
+    Rast3d_close(map);
+
+    map = Rast3d_open_cell_old("test_put_get_value_dcell", G_mapset(), &region, DCELL_TYPE, RASTER3D_USE_CACHE_XY);
     
     /* Reread the map and compare the expected results */
     
@@ -223,7 +227,7 @@ int test_put_get_value_fcell(void)
         
     Rast3d_adjust_region(&region);
         
-    map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell", RASTER3D_USE_CACHE_XY, &region, FCELL_TYPE, 32);
+    map = Rast3d_open_new_opt_tile_size("test_put_get_value_fcell", RASTER3D_USE_CACHE_XY, &region, FCELL_TYPE, 32);
     
     /* The window is the same as the map region ... of course */
     Rast3d_set_window_map(map, &region);
@@ -237,8 +241,12 @@ int test_put_get_value_fcell(void)
             }
         }
     }
+
     /* Write everything to the disk */
     Rast3d_flush_all_tiles(map);
+    Rast3d_close(map);
+
+    map = Rast3d_open_cell_old("test_put_get_value_fcell", G_mapset(), &region, DCELL_TYPE, RASTER3D_USE_CACHE_XY);
     
        /* Reread the map and compare the expected results */
     
@@ -346,19 +354,6 @@ int test_put_get_value_resampling(void)
     Rast3d_adjust_region(&region);
     
     map = Rast3d_open_new_opt_tile_size("test_put_get_value_resample", RASTER3D_USE_CACHE_XY, &region, DCELL_TYPE, 32);
-    
-    /* We modify the window for resampling tests */
-    Rast3d_region_copy(&window, &region);
-        
-    /* Double the cols, rows and depths -> 8x resolution window */
-    window.rows = 30;
-    window.cols = 20;
-    window.depths = 10;
-    
-    Rast3d_adjust_region(&window);
-    
-    /* The window is the same as the map region ... of course */
-    Rast3d_set_window_map(map, &window);
     /*
      ROWS
   1000 1500 2000 2500 3000 3500 4000 4500 5000 5500 6500 7000 7500 8000 8500 9000 north
@@ -390,8 +385,25 @@ int test_put_get_value_resampling(void)
             }
         }
     }
+
     /* Write everything to the disk */
     Rast3d_flush_all_tiles(map);
+    Rast3d_close(map);
+
+    /* We modify the window for resampling tests */
+    Rast3d_region_copy(&window, &region);
+
+    /* Double the cols, rows and depths -> 8x resolution window */
+    window.rows = 30;
+    window.cols = 20;
+    window.depths = 10;
+
+    Rast3d_adjust_region(&window);
+
+    map = Rast3d_open_cell_old("test_put_get_value_resample", G_mapset(), &region, DCELL_TYPE, RASTER3D_USE_CACHE_XY);
+
+    /* The window has the 8x resolution as the map region */
+    Rast3d_set_window_map(map, &window);
     
     /* Reread the map and compare the expected results */
     
@@ -440,7 +452,7 @@ int test_put_get_value_resampling(void)
     
     Rast3d_close(map);
     
-    G_remove("grid3", "test_put_get_value_dcell");
+    G_remove("grid3", "test_put_get_value_resample");
     
     return sum;
 }

+ 91 - 54
lib/raster3d/test/test_put_get_value_large_file.c

@@ -20,6 +20,7 @@
 #include "grass/interpf.h"
 
 #define EPSILON 0.000000001
+#define RAND_VALUE_VECTOR_SIZE 1000
 
 static int test_large_file(int depths, int rows, int cols, int tile_size);
 static int test_large_file_zeros(int depths, int rows, int cols, int tile_size);
@@ -35,10 +36,12 @@ int unit_test_put_get_value_large_file(int depths, int rows, int cols, int tile_
 
     G_message(_("\n++ Running g3d put/get value large file unit tests ++"));
 
-    sum += test_large_file(depths, rows, cols, tile_size);
-    sum += test_large_file_zeros(depths, rows, cols, tile_size);
     sum += test_large_file_random(depths, rows, cols, tile_size);
     sum += test_large_file_sparse_random(depths, rows, cols, tile_size);
+    sum += test_large_file(depths, rows, cols, tile_size);
+    sum += test_large_file(depths, rows, cols, tile_size);
+    sum += test_large_file(depths, rows, cols, tile_size);
+    sum += test_large_file_zeros(depths, rows, cols, tile_size);
 
 
     if (sum > 0)
@@ -80,7 +83,8 @@ int test_large_file(int depths, int rows, int cols, int tile_size)
         
     G_message("Creating 3D raster map");
 
-    map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large", RASTER3D_USE_CACHE_XY, &region, DCELL_TYPE, tile_size);
+    map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large",
+    		RASTER3D_USE_CACHE_XY, &region, DCELL_TYPE, tile_size);
     
     /* The window is the same as the map region ... of course */
     Rast3d_set_window_map(map, &region);
@@ -105,7 +109,8 @@ int test_large_file(int depths, int rows, int cols, int tile_size)
          
     G_message("Verifying 3D raster map");
 
-    map = Rast3d_open_cell_old("test_put_get_value_dcell_large", G_mapset(), &region, DCELL_TYPE, RASTER3D_USE_CACHE_XYZ);
+    map = Rast3d_open_cell_old("test_put_get_value_dcell_large",
+    		G_mapset(), &region, DCELL_TYPE, RASTER3D_USE_CACHE_XYZ);
     
     count = 1;
     for(z = 0; z < region.depths; z++) {
@@ -115,7 +120,8 @@ int test_large_file(int depths, int rows, int cols, int tile_size)
                 /* Check the counter as cell value */
                 Rast3d_get_value(map, x, y, z, &value, DCELL_TYPE);
                 if(fabs(value - (double)(count) > EPSILON)) {
-                    G_message("At: z %i y %i x %i -- value %.14lf != %.14lf\n", z, y, x, value, (double)(count));
+                    G_message("At: z %i y %i x %i -- value %.14lf != %.14lf\n",
+                    		z, y, x, value, (double)(count));
 			sum++;
                 }
                 count++;
@@ -125,7 +131,7 @@ int test_large_file(int depths, int rows, int cols, int tile_size)
     G_percent(1, 1, 1);
     Rast3d_close(map);
     
-    //G_remove("grid3", "test_put_get_value_dcell_large");
+    G_remove("grid3", "test_put_get_value_dcell_large");
     
     return sum;
 }
@@ -162,7 +168,8 @@ int test_large_file_zeros(int depths, int rows, int cols, int tile_size)
 
     G_message("Creating 3D raster map filled with zeros");
 
-    map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large_zeros", RASTER3D_USE_CACHE_XY, &region, DCELL_TYPE, tile_size);
+    map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large_zeros",
+    		RASTER3D_USE_CACHE_XY, &region, DCELL_TYPE, tile_size);
 
     /* The window is the same as the map region ... of course */
     Rast3d_set_window_map(map, &region);
@@ -185,7 +192,8 @@ int test_large_file_zeros(int depths, int rows, int cols, int tile_size)
 
     G_message("Verifying 3D raster map filled with zeros");
 
-    map = Rast3d_open_cell_old("test_put_get_value_dcell_large_zeros", G_mapset(), &region, DCELL_TYPE, RASTER3D_USE_CACHE_XYZ);
+    map = Rast3d_open_cell_old("test_put_get_value_dcell_large_zeros",
+    		G_mapset(), &region, DCELL_TYPE, RASTER3D_USE_CACHE_XY);
 
     for(z = 0; z < region.depths; z++) {
 	G_percent(z, region.depths, 1);
@@ -194,7 +202,8 @@ int test_large_file_zeros(int depths, int rows, int cols, int tile_size)
                 /* Check the counter as cell value */
                 Rast3d_get_value(map, x, y, z, &value, DCELL_TYPE);
                 if(value > EPSILON) {
-                    G_message("At: z %i y %i x %i -- value %.14lf != 0.0\n", z, y, x, value);
+                    G_message("At: z %i y %i x %i -- value %.14lf != 0.0\n",
+                    		z, y, x, value);
                     sum++;
                 }
             }
@@ -203,7 +212,7 @@ int test_large_file_zeros(int depths, int rows, int cols, int tile_size)
     G_percent(1, 1, 1);
     Rast3d_close(map);
 
-    //G_remove("grid3", "test_put_get_value_dcell_large_zeros");
+    G_remove("grid3", "test_put_get_value_dcell_large_zeros");
 
     return sum;
 }
@@ -213,8 +222,10 @@ int test_large_file_zeros(int depths, int rows, int cols, int tile_size)
 int test_large_file_random(int depths, int rows, int cols, int tile_size)
 {
     int sum = 0;
-    int x, y, z;
-    DCELL value, radnom_value;
+    int x, y, z, i;
+    DCELL value, random_value;
+    DCELL *random_value_vector = G_calloc(RAND_VALUE_VECTOR_SIZE, sizeof(DCELL));
+
 
     G_message("Testing DCELL put function for large files filled with random values");
 
@@ -239,20 +250,30 @@ int test_large_file_random(int depths, int rows, int cols, int tile_size)
 
     G_message("Creating 3D raster map filled with random values");
 
-    map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large_random", RASTER3D_USE_CACHE_XY, &region, DCELL_TYPE, tile_size);
+    map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large_random",
+    		RASTER3D_USE_CACHE_XY, &region, DCELL_TYPE, tile_size);
 
     /* The window is the same as the map region ... of course */
     Rast3d_set_window_map(map, &region);
 
     srand(1);
+    /* We fill the random value vector */
+    for(i = 0; i < RAND_VALUE_VECTOR_SIZE; i++) {
+    	random_value_vector[i] = (DCELL)rand();
+    }
+
+    i = 0;
 
     for(z = 0; z < region.depths; z++) {
 	G_percent(z, region.depths, 1);
         for(y = 0; y < region.rows; y++) {
             for(x = 0; x < region.cols; x++) {
               /* Put the counter as cell value */
-                value = (double)rand();
+                value = random_value_vector[i];
                 Rast3d_put_value(map, x, y, z, &value, DCELL_TYPE);
+                i++;
+                if(i == RAND_VALUE_VECTOR_SIZE)
+                	i = 0;
             }
         }
     }
@@ -264,9 +285,10 @@ int test_large_file_random(int depths, int rows, int cols, int tile_size)
 
     G_message("Verifying 3D raster map filled with random values");
 
-    map = Rast3d_open_cell_old("test_put_get_value_dcell_large_random", G_mapset(), &region, DCELL_TYPE, RASTER3D_USE_CACHE_XYZ);
+    map = Rast3d_open_cell_old("test_put_get_value_dcell_large_random",
+    		G_mapset(), &region, DCELL_TYPE, RASTER3D_USE_CACHE_XY);
 
-    srand(1);
+    i = 0;
 
     for(z = 0; z < region.depths; z++) {
 	G_percent(z, region.depths, 1);
@@ -274,18 +296,24 @@ int test_large_file_random(int depths, int rows, int cols, int tile_size)
             for(x = 0; x < region.cols; x++) {
                 /* Check the counter as cell value */
                 Rast3d_get_value(map, x, y, z, &value, DCELL_TYPE);
-                radnom_value = (DCELL)rand();
-                if(fabs(value - radnom_value) > EPSILON) {
-                    G_message("At: z %i y %i x %i -- value %.14lf != %.14lf\n", z, y, x, value, radnom_value);
+                random_value = random_value_vector[i];
+                if(fabs(value - random_value) > EPSILON) {
+                    G_message("At: z %i y %i x %i -- value %.14lf != %.14lf\n",
+                    		z, y, x, value, random_value);
                     sum++;
                 }
+                i++;
+                if(i == RAND_VALUE_VECTOR_SIZE)
+                	i = 0;
             }
         }
     }
     G_percent(1, 1, 1);
     Rast3d_close(map);
 
-    //G_remove("grid3", "test_put_get_value_dcell_large_random");
+    G_free(random_value_vector);
+
+    G_remove("grid3", "test_put_get_value_dcell_large_random");
 
     return sum;
 }
@@ -295,8 +323,9 @@ int test_large_file_random(int depths, int rows, int cols, int tile_size)
 int test_large_file_sparse_random(int depths, int rows, int cols, int tile_size)
 {
     int sum = 0;
-    int x, y, z;
-    DCELL value, radnom_value;
+    int x, y, z, i;
+    DCELL value, random_value;
+    DCELL *random_value_vector = G_calloc(RAND_VALUE_VECTOR_SIZE, sizeof(DCELL));
 
     G_message("Testing DCELL put function for large files filled with sparse random values");
 
@@ -321,31 +350,44 @@ int test_large_file_sparse_random(int depths, int rows, int cols, int tile_size)
 
     G_message("Creating 3D raster map filled with sparse random values");
 
-    map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large_sparse_random", RASTER3D_USE_CACHE_XY, &region, DCELL_TYPE, tile_size);
+    map = Rast3d_open_new_opt_tile_size("test_put_get_value_dcell_large_sparse_random",
+    		RASTER3D_USE_CACHE_XY, &region, DCELL_TYPE, tile_size);
 
     /* The window is the same as the map region ... of course */
     Rast3d_set_window_map(map, &region);
 
     srand(1);
 
+    /* We fill the random value vector */
+    for(i = 0; i < RAND_VALUE_VECTOR_SIZE; i++) {
+    	/* Put the counter as cell value */
+        value = (DCELL)rand();
+        value /= RAND_MAX;
+        if(value <= 0.7)
+        	value = 0.0;
+        else if(value <= 0.8)
+        	value = 1.0;
+        else if(value <= 0.9)
+        	value = 2.0;
+        else if(value <= 1.0)
+        	value = 3.0;
+        else
+        	value = 4.0;
+    	random_value_vector[i] = value;
+    }
+
+    i = 0;
+
     for(z = 0; z < region.depths; z++) {
 	G_percent(z, region.depths, 1);
         for(y = 0; y < region.rows; y++) {
             for(x = 0; x < region.cols; x++) {
-              /* Put the counter as cell value */
-                value = (DCELL)rand();
-                value /= RAND_MAX;
-                if(value <= 0.7)
-                	value = 0.0;
-                else if(value <= 0.8)
-                	value = 1.0;
-                else if(value <= 0.9)
-                	value = 2.0;
-                else if(value <= 1.0)
-                	value = 3.0;
-                else
-                	value = 4.0;
-                Rast3d_put_value(map, x, y, z, &value, DCELL_TYPE);
+                /* Put the counter as cell value */
+                  value = random_value_vector[i];
+                  Rast3d_put_value(map, x, y, z, &value, DCELL_TYPE);
+                  i++;
+                  if(i == RAND_VALUE_VECTOR_SIZE)
+                  	i = 0;
             }
         }
     }
@@ -357,9 +399,10 @@ int test_large_file_sparse_random(int depths, int rows, int cols, int tile_size)
 
     G_message("Verifying 3D raster map filled with sparse random values");
 
-    map = Rast3d_open_cell_old("test_put_get_value_dcell_large_sparse_random", G_mapset(), &region, DCELL_TYPE, RASTER3D_USE_CACHE_XYZ);
+    map = Rast3d_open_cell_old("test_put_get_value_dcell_large_sparse_random",
+    		G_mapset(), &region, DCELL_TYPE, RASTER3D_USE_CACHE_XY);
 
-    srand(1);
+    i = 0;
 
     for(z = 0; z < region.depths; z++) {
 	G_percent(z, region.depths, 1);
@@ -367,29 +410,23 @@ int test_large_file_sparse_random(int depths, int rows, int cols, int tile_size)
             for(x = 0; x < region.cols; x++) {
                 /* Check the counter as cell value */
                 Rast3d_get_value(map, x, y, z, &value, DCELL_TYPE);
-                radnom_value = (DCELL)rand();
-                radnom_value /= RAND_MAX;
-                if(radnom_value <= 0.7)
-                	radnom_value = 0.0;
-                else if(radnom_value <= 0.8)
-                	radnom_value = 1.0;
-                else if(radnom_value <= 0.9)
-                	radnom_value = 2.0;
-                else if(radnom_value <= 1.0)
-                	radnom_value = 3.0;
-                else
-                	radnom_value = 4.0;
-                if(fabs(value - radnom_value) > EPSILON) {
-                    G_message("At: z %i y %i x %i -- value %.14lf != %.14lf\n", z, y, x, value, radnom_value);
+                if(fabs(value - random_value_vector[i]) > EPSILON) {
+                    G_message("At: z %i y %i x %i -- value %.14lf != %.14lf\n",
+                    		z, y, x, value, random_value);
                     sum++;
                 }
+                i++;
+                if(i == RAND_VALUE_VECTOR_SIZE)
+                	i = 0;
             }
         }
     }
     G_percent(1, 1, 1);
     Rast3d_close(map);
 
-    //G_remove("grid3", "test_put_get_value_dcell_large_sparse_random");
+    G_free(random_value_vector);
+
+    G_remove("grid3", "test_put_get_value_dcell_large_sparse_random");
 
     return sum;
 }

+ 2 - 0
lib/raster3d/tileio.c

@@ -93,6 +93,7 @@ void *Rast3d_get_tile_ptr(RASTER3D_Map * map, int tileIndex)
 	return ptr;
     }
 
+
     if (map->currentIndex == tileIndex)
 	return map->data;
 
@@ -102,6 +103,7 @@ void *Rast3d_get_tile_ptr(RASTER3D_Map * map, int tileIndex)
 	return NULL;
     }
 
+
     return map->data;
 }
 

+ 2 - 2
lib/raster3d/tileread.c

@@ -88,7 +88,7 @@ Rast3d_xdrTile2tile(RASTER3D_Map * map, void *tile, int rows, int cols, int dept
 
 static int Rast3d_readTileUncompressed(RASTER3D_Map * map, int tileIndex, int nofNum)
 {
-    int nofBytes;
+    size_t nofBytes;
 
     nofBytes = nofNum * map->numLengthExtern;
     nofBytes = RASTER3D_MIN(nofBytes, map->fileEndPtr - map->index[tileIndex]);
@@ -139,7 +139,7 @@ static int Rast3d_readTileCompressed(RASTER3D_Map * map, int tileIndex, int nofN
  *  \param tile
  *  \param type
  *  \return 1 ... if successful,
- *          0 ... otherwise.
+ *          0 ... otherwise
  */
 
 int Rast3d_read_tile(RASTER3D_Map * map, int tileIndex, void *tile, int type)

+ 7 - 7
lib/raster3d/tilewrite.c

@@ -84,8 +84,7 @@ static int Rast3d_writeTileUncompressed(RASTER3D_Map * map, int nofNum)
 static int Rast3d_writeTileCompressed(RASTER3D_Map * map, int nofNum)
 {
     if (!Rast3d_fpcompress_write_xdr_nums(map->data_fd, xdr, nofNum, map->precision,
-				   tmpCompress, map->type == FCELL_TYPE,
-				   map->useRle, map->useLzw)) {
+				   tmpCompress, map->type == FCELL_TYPE)) {
 	Rast3d_error
 	    ("Rast3d_writeTileCompressed: error in Rast3d_fpcompress_write_xdr_nums");
 	return 0;
@@ -130,7 +129,7 @@ int Rast3d_write_tile(RASTER3D_Map * map, int tileIndex, const void *tile, int t
     int rows, cols, depths, xRedundant, yRedundant, zRedundant, nofNum;
 
     /* valid tileIndex ? */
-    if ((tileIndex >= map->nTiles) || (tileIndex < 0))
+    if ((tileIndex > map->nTiles) || (tileIndex < 0))
 	Rast3d_fatal_error("Rast3d_write_tile: tileIndex out of range");
 
     /* already written ? */
@@ -155,7 +154,7 @@ int Rast3d_write_tile(RASTER3D_Map * map, int tileIndex, const void *tile, int t
 
     if (!Rast3d_tile2xdrTile(map, tile, rows, cols, depths,
 			  xRedundant, yRedundant, zRedundant, nofNum, type)) {
-	Rast3d_error("Rast3d_writeTileCompressed: error in Rast3d_tile2xdrTile");
+	Rast3d_error("Rast3d_write_tile: error in Rast3d_tile2xdrTile");
 	return 0;
     }
 
@@ -165,9 +164,10 @@ int Rast3d_write_tile(RASTER3D_Map * map, int tileIndex, const void *tile, int t
 	    return 0;
 	}
     }
-    else if (!Rast3d_writeTileCompressed(map, nofNum)) {
-	Rast3d_error("Rast3d_write_tile: error in Rast3d_writeTileCompressed");
-	return 0;
+    else { if (!Rast3d_writeTileCompressed(map, nofNum)) {
+			Rast3d_error("Rast3d_write_tile: error in Rast3d_writeTileCompressed");
+			return 0;
+    	}
     }
 
     /* compute the length */

+ 10 - 2
raster3d/r3.cross.rast/test.r3.cross.rast.sh

@@ -33,5 +33,13 @@ r3.cross.rast --o input=volume_null elevation=elev_5 output=test_cross_section_s
 r3.cross.rast --o input=volume_null elevation=elev_NAN output=test_cross_section_slice_NAN
 r3.cross.rast --o input=volume_null elevation=elev_cross output=test_cross_section_result
 
-# Export of the references
-for i in `g.mlist type=rast pattern=test_cross_section_*` ; do r.out.ascii input=$i output=${i}.txt; done
+# Export of the text files
+for i in `g.mlist type=rast pattern=test_cross_section_*` ; do 
+    r.out.ascii input=$i output=${i}.txt; 
+done
+
+# Comparison of references and text files
+for i in `ls *.ref` ; do 
+    diff $i "`basename $i .ref`.txt" ; 
+done
+rm *.txt

+ 3 - 9
raster3d/r3.in.ascii/main.c

@@ -278,11 +278,6 @@ asciiToG3d(FILE * fp, RASTER3D_Region * region, int convertNull, char *nullValue
                 /* Write the data */
                 Rast3d_put_double(map, col, row, depth, value);
             }
-
-        if (!Rast3d_flush_tiles_in_cube(map,
-                                  0, 0, MAX(0, depth - tileZ),
-                                  region->rows - 1, region->cols - 1, depth))
-            fatalError("asciiTog3d: error flushing tiles");
     }
 
     if (fscanf(fp, "%lf", &value) == 1) {
@@ -306,7 +301,7 @@ int main(int argc, char *argv[])
     char *input, *output;
     int convertNull;
     char nullValue[256];
-    int useTypeDefault, type, useLzwDefault, doLzw, useRleDefault, doRle;
+    int useTypeDefault, type, useCompressionDefault, doCompression;
     int usePrecisionDefault, precision, useDimensionDefault, tileX, tileY,
         tileZ;
     RASTER3D_Region region;
@@ -332,8 +327,7 @@ int main(int argc, char *argv[])
 
     getParams(&input, &output, &convertNull, nullValue);
     if (!Rast3d_get_standard3d_params(&useTypeDefault, &type,
-                                 &useLzwDefault, &doLzw,
-                                 &useRleDefault, &doRle,
+                                 &useCompressionDefault, &doCompression,
                                  &usePrecisionDefault, &precision,
                                  &useDimensionDefault, &tileX, &tileY,
                                  &tileZ))
@@ -346,7 +340,7 @@ int main(int argc, char *argv[])
     /*Open the new RASTER3D map */
     map = Rast3d_open_new_param(output, RASTER3D_TILE_SAME_AS_FILE, RASTER3D_USE_CACHE_XY,
                            &region,
-                           type, doLzw, doRle, precision, tileX, tileY,
+                           type, doCompression, precision, tileX, tileY,
                            tileZ);
 
     if (map == NULL)

+ 2 - 3
raster3d/r3.in.v5d/main.c

@@ -179,7 +179,7 @@ int main(int argc, char *argv[])
     char *input, *output;
     int convertNull;
     double nullValue;
-    int useTypeDefault, type, useLzwDefault, doLzw, useRleDefault, doRle;
+    int useTypeDefault, type, useCompressionDefault, doCompression;
     int usePrecisionDefault, precision, useDimensionDefault, tileX, tileY,
 	tileZ;
     RASTER3D_Region region;
@@ -202,8 +202,7 @@ int main(int argc, char *argv[])
 
     getParams(&input, &output, &convertNull, &nullValue);
     if (!Rast3d_get_standard3d_params(&useTypeDefault, &type,
-				 &useLzwDefault, &doLzw,
-				 &useRleDefault, &doRle,
+				 &useCompressionDefault, &doCompression,
 				 &usePrecisionDefault, &precision,
 				 &useDimensionDefault, &tileX, &tileY,
 				 &tileZ))

+ 1 - 1
raster3d/r3.mask/main.c

@@ -67,7 +67,7 @@ static void makeMask(char *name, d_Mask * maskRules)
     Rast3d_get_tile_dimensions_map(map, &tileX, &tileY, &tileZ);
 
     mask = Rast3d_open_new_param(Rast3d_mask_file(), FCELL_TYPE, cacheSize,
-			    &region, FCELL_TYPE, RASTER3D_NO_LZW, RASTER3D_USE_RLE, 0,
+			    &region, FCELL_TYPE, RASTER3D_COMPRESSION, 0,
 			    tileX, tileY, tileZ);
 
     if (mask == NULL)

+ 2 - 2
raster3d/r3.null/main.c

@@ -111,11 +111,11 @@ modifyNull(char *name, d_Mask * maskRules, int changeNull, double newNullVal)
     Rast3d_get_region_struct_map(map, &region);
     Rast3d_get_tile_dimensions_map(map, &tileX, &tileY, &tileZ);
 
-    Rast3d_get_compression_mode(&doCompress, &doLzw, &doRle, &precision);
+    Rast3d_get_compression_mode(&doCompress, &precision);
 
     mapOut = Rast3d_open_new_param(name, DCELL_TYPE, RASTER3D_USE_CACHE_XY,
 			      &region, Rast3d_file_type_map(map),
-			      doLzw, doRle, Rast3d_tile_precision_map(map), tileX,
+			      doCompress, Rast3d_tile_precision_map(map), tileX,
 			      tileY, tileZ);
     if (mapOut == NULL)
 	Rast3d_fatal_error(_("modifyNull: error opening tmp file"));

+ 8 - 8
raster3d/r3.null/test.r3.null.sh

@@ -31,11 +31,11 @@ r3.null map=test_volume_double_null_1 null=-1.5
 r3.null map=test_volume_double_null_2 null=-10.5
 
 # Commands to export the references 
-# r3.out.ascii dp=3 input=test_volume_float_1 output=test_volume_float_1.ref
-# r3.out.ascii dp=3 input=test_volume_float_2 output=test_volume_float_2.ref
-# r3.out.ascii dp=3 input=test_volume_float_null_1 output=test_volume_float_null_1.ref
-# r3.out.ascii dp=3 input=test_volume_float_null_2 output=test_volume_float_null_2.ref
-# r3.out.ascii dp=3 input=test_volume_double_1 output=test_volume_double_1.ref
-# r3.out.ascii dp=3 input=test_volume_double_2 output=test_volume_double_2.ref
-# r3.out.ascii dp=3 input=test_volume_double_null_1 output=test_volume_double_null_1.ref
-# r3.out.ascii dp=3 input=test_volume_double_null_2 output=test_volume_double_null_2.ref
+r3.out.ascii dp=3 input=test_volume_float_1 output=test_volume_float_1.txt
+r3.out.ascii dp=3 input=test_volume_float_2 output=test_volume_float_2.txt
+r3.out.ascii dp=3 input=test_volume_float_null_1 output=test_volume_float_null_1.txt
+r3.out.ascii dp=3 input=test_volume_float_null_2 output=test_volume_float_null_2.txt
+r3.out.ascii dp=3 input=test_volume_double_1 output=test_volume_double_1.txt
+r3.out.ascii dp=3 input=test_volume_double_2 output=test_volume_double_2.txt
+r3.out.ascii dp=3 input=test_volume_double_null_1 output=test_volume_double_null_1.txt
+r3.out.ascii dp=3 input=test_volume_double_null_2 output=test_volume_double_null_2.txt

+ 8 - 2
raster3d/r3.out.ascii/test.r3.out.ascii.sh

@@ -63,7 +63,7 @@ r3.in.ascii --o output=test_double_nsbt_null input=test_double_sntb_null.txt nv=
 # Different precision and null values than default
 r3.in.ascii --o output=test_double_nsbt_null input=test_double_nsbt_null_prec5.txt nv=-1000
 r3.in.ascii --o output=test_double_nsbt_null input=test_double_sntb_null_prec8.txt nv=-2000
-# AImport grass6 legacy data
+# Import grass6 legacy data
 r3.in.ascii --o output=test_double_nsbt_null input=test_double_nsbt_null_grass6_comp_1.txt
 
 # In this @preprocess step for the last test we create a large region and 
@@ -77,4 +77,10 @@ r3.mapcalc --o expr="volume_double_null_large = if(row() == 1 || row() == 5, nul
 r3.out.ascii --o input=volume_double_null_large output=test_double_nsbt_null_large.txt dp=0 null=*
 r3.in.ascii --o output=test_double_nsbt_null_large input=test_double_nsbt_null_large.txt nv=*
 # Just for the logs
-r3.info test_double_nsbt_null_large
+r3.info test_double_nsbt_null_large
+
+# Show differences between references and created text files
+for i in `ls *.ref` ; do 
+    diff $i "`basename $i .ref`.txt" ; 
+done
+rm *.txt

+ 7 - 1
raster3d/r3.out.vtk/test.r3.out.vtk.sh

@@ -35,4 +35,10 @@ r3.out.vtk -p --o rgbmaps=volume_rgb,volume_rgb,volume_rgb vectormaps=volume_nul
 # The third @test uses raster maps to create volume data with an elevation surface
 # The maximum elevation should be in the south. Reference @files are present for validation.
 r3.out.vtk -s --o top=elev_top bottom=elev_bottom input=volume_null output=test_volume_null_1_cells_elevation.vtk dp=3 null=0
-r3.out.vtk -sp --o top=elev_top bottom=elev_bottom input=volume_null output=test_volume_null_1_points_elevation.vtk dp=3 null=0
+r3.out.vtk -sp --o top=elev_top bottom=elev_bottom input=volume_null output=test_volume_null_1_points_elevation.vtk dp=3 null=0
+
+# Comparison of references and vtk files
+for i in `ls *.ref` ; do 
+    diff $i "`basename $i .ref`.vtk" ; 
+done
+rm *.vtk

+ 2 - 7
raster3d/r3.retile/main.c

@@ -32,13 +32,8 @@ typedef struct {
 paramType param; /*Parameters */
 
 /*- prototypes --------------------------------------------------------------*/
-void fatal_error(void *map, int *fd, int depths, char *errorMsg); /*Simple Error message */
-void set_params(); /*Fill the paramType structure */
-void g3d_to_raster(void *map, RASTER3D_Region region, int *fd); /*Write the raster */
-int open_output_map(const char *name, int res_type); /*opens the outputmap */
-void close_output_map(int fd); /*close the map */
-
-
+static void fatal_error(void *map, int *fd, int depths, char *errorMsg); /*Simple Error message */
+static void set_params(); /*Fill the paramType structure */
 
 /* ************************************************************************* */
 /* Error handling ********************************************************** */

+ 6 - 0
raster3d/r3.retile/test.r3.retile.sh

@@ -39,3 +39,9 @@ r3.info -g map=test_retile_map_10 > test_retile_map_10_info.txt
 for map in `g.mlist type=rast3d pattern=test_retile_map_*` ; do
   r3.out.ascii input=${map} output=${map}.txt dp=0
 done
+
+# Comparison of references and text files
+for i in `ls *.ref` ; do 
+    diff $i "`basename $i .ref`.txt" ; 
+done
+rm *.txt

+ 6 - 0
raster3d/r3.stats/test.r3.stats.sh

@@ -28,3 +28,9 @@ r3.stats input=volume_double_null nsteps=9  > test_volume_double_stats_9.txt
 r3.stats input=volume_double_null nsteps=18 > test_volume_double_stats_18.txt
 r3.stats input=volume_double_null nsteps=22 > test_volume_double_stats_22.txt
 r3.stats -e input=volume_double_null > test_volume_double_stats_e.txt
+
+# Comparison of references and text files
+for i in `ls *.ref` ; do 
+    diff $i "`basename $i .ref`.txt" ; 
+done
+rm *.txt

+ 7 - 1
raster3d/r3.to.rast/test.r3.to.rast.sh

@@ -21,7 +21,7 @@ r3.to.rast --o input=volume_null output=test_raster_slice_1
 r3.to.rast --o input=volume_null_float output=test_raster_slice_float
 
 # Export of the references
-# for i in `g.mlist type=rast pattern=test_raster_slice_1*` ; do r.out.ascii input=$i output=${i}.ref; done
+for i in `g.mlist type=rast pattern=test_raster_slice_1*` ; do r.out.ascii input=$i output=${i}.txt; done
 for i in `g.mlist type=rast pattern=test_raster_slice_float*` ; do r.out.ascii input=$i output=${i}.txt; done
 
 # The next @preprocess step adjusts the raster region to increase the resolution by 2
@@ -43,3 +43,9 @@ r3.to.rast --o input=volume_null output=test_raster_slice_3
 
 # Export of the references
 for i in `g.mlist type=rast pattern=test_raster_slice_3*` ; do r.out.ascii input=$i output=${i}.txt; done
+
+# Comparison of references and text files
+for i in `ls *.ref` ; do 
+    diff $i "`basename $i .ref`.txt" ; 
+done
+rm *.txt