9 static unsigned char clearMask[9] = {255, 128, 192, 224, 240,
14 static void Rast3d_float2xdrFloat(
const float *f,
float *xdrf)
21 static void Rast3d_double2xdrDouble(
const double *d,
double *xdrd)
28 static void Rast3d_truncFloat(
float *f,
int p)
32 if ((p == -1) || (p >= 23))
35 c = (
unsigned char *)f;
39 *c++ &= clearMask[(p + 1) % 8];
47 *c++ &= clearMask[(p + 1) % 8];
53 *c &= clearMask[(p + 1) % 8];
59 static void Rast3d_truncDouble(
double *d,
int p)
63 if ((p == -1) || (p >= 52))
66 c = (
unsigned char *)d;
70 *c++ &= clearMask[(p + 4) % 8];
82 *c++ &= clearMask[(p + 4) % 8];
93 *c++ &= clearMask[(p + 4) % 8];
103 *c++ &= clearMask[(p + 4) % 8];
112 *c++ &= clearMask[(p + 4) % 8];
120 *c++ &= clearMask[(p + 4) % 8];
126 *c &= clearMask[(p + 4) % 8];
132 static void Rast3d_float2Double(
float *f,
double *d)
134 unsigned char *c1, *c2,
sign, c;
137 c1 = (
unsigned char *)f;
138 c2 = (
unsigned char *)d;
140 sign = (*c1 & (
unsigned char)128);
141 e = (((*c1 & (
unsigned char)127) << 1) |
142 ((*(c1 + 1) & (
unsigned char)128) >> 7));
144 if ((*c1 != 0) || (*(c1 + 1) != 0) || (*(c1 + 2) != 0) || (*(c1 + 3) != 0))
154 *c2++ |= ((*c1 & (
unsigned char)127) >> 3);
156 *c2 = ((*c1++ & (
unsigned char)7) << 5);
159 *c2 = ((*c1++ & (
unsigned char)7) << 5);
162 *c2++ = ((*c1 & (
unsigned char)7) << 5);
164 *c2++ = (
unsigned char)0;
165 *c2++ = (
unsigned char)0;
166 *c2 = (
unsigned char)0;
171 static int Rast3d_compareFloats(
float *f1,
int p1,
float *f2,
int p2)
173 unsigned char *c1, *c2;
179 Rast3d_float2xdrFloat(f1, &xdrf1);
180 Rast3d_float2xdrFloat(f2, &xdrf2);
182 c1 = (
unsigned char *)&xdrf1;
183 c2 = (
unsigned char *)&xdrf2;
189 if ((p1 != -1) && (p1 < 23) && ((p1 < p2) || (p2 == -1)))
190 Rast3d_truncFloat(&xdrf2, p1);
191 if ((p2 != -1) && (p2 < 23) && ((p2 < p1) || (p1 == -1)))
192 Rast3d_truncFloat(&xdrf1, p2);
198 return (*c1 == *c2) && (*(c1 + 1) == *(c2 + 1)) &&
199 (*(c1 + 2) == *(c2 + 2)) && (*(c1 + 3) == *(c2 + 3));
204 static int Rast3d_compareDoubles(
double *d1,
int p1,
double *d2,
int p2)
206 unsigned char *c1, *c2;
212 Rast3d_double2xdrDouble(d1, &xdrd1);
213 Rast3d_double2xdrDouble(d2, &xdrd2);
215 c1 = (
unsigned char *)&xdrd1;
216 c2 = (
unsigned char *)&xdrd2;
223 if ((p1 != -1) && (p1 < 52) && ((p1 < p2) || (p2 == -1)))
224 Rast3d_truncDouble(&xdrd2, p1);
225 if ((p2 != -1) && (p2 < 52) && ((p2 < p1) || (p1 == -1)))
226 Rast3d_truncDouble(&xdrd1, p2);
233 return (*c1 == *c2) && (*(c1 + 1) == *(c2 + 1)) &&
234 (*(c1 + 2) == *(c2 + 2)) && (*(c1 + 3) == *(c2 + 3)) &&
235 (*(c1 + 4) == *(c2 + 4)) && (*(c1 + 5) == *(c2 + 5)) &&
236 (*(c1 + 6) == *(c2 + 6)) && (*(c1 + 7) == *(c2 + 7));
241 static int Rast3d_compareFloatDouble(
float *f,
int p1,
double *d,
int p2)
243 unsigned char *c1, *c2;
245 double xdrd, xdrd2, dTmp;
260 Rast3d_float2xdrFloat(f, &xdrf);
261 Rast3d_float2Double(&xdrf, &xdrd2);
262 Rast3d_double2xdrDouble(&dTmp, &xdrd);
264 c1 = (
unsigned char *)&xdrd2;
265 c2 = (
unsigned char *)&xdrd;
274 if (((p1 != -1) && ((p1 < p2) || (p2 == -1))) ||
275 ((p1 == -1) && ((p2 > 23) || (p2 == -1))))
276 Rast3d_truncDouble(&xdrd, (p1 != -1 ? p1 : 23));
277 if ((p2 != -1) && (p2 < 23) && ((p2 < p1) || (p1 == -1)))
278 Rast3d_truncDouble(&xdrd2, p2);
287 return (*c1 == *c2) && (*(c1 + 1) == *(c2 + 1)) &&
288 (*(c1 + 2) == *(c2 + 2)) && (*(c1 + 3) == *(c2 + 3)) &&
289 (*(c1 + 4) == *(c2 + 4)) && (*(c1 + 5) == *(c2 + 5)) &&
290 (*(c1 + 6) == *(c2 + 6)) && (*(c1 + 7) == *(c2 + 7));
295 static void compareFilesNocache(
void *map,
void *map2)
297 double n1 = 0, n2 = 0;
300 int x, y, z, correct;
302 int tileX, tileY, tileZ, typeIntern, typeIntern2;
318 for (z = 0; z < nz * tileZ; z++) {
319 printf(
"comparing: z = %d\n", z);
321 for (y = 0; y < ny * tileY; y++) {
322 for (
x = 0;
x < nx * tileX;
x++) {
329 correct = Rast3d_compareFloats(f1p, p1, f2p, p2);
331 correct = Rast3d_compareFloatDouble(f1p, p1, n2p, p2);
335 correct = Rast3d_compareFloatDouble(f2p, p2, n1p, p1);
337 correct = Rast3d_compareDoubles(n1p, p1, n2p, p2);
341 int xTile, yTile, zTile, xOffs, yOffs, zOffs;
344 &zTile, &xOffs, &yOffs, &zOffs);
345 printf(
"(%d %d %d) (%d %d %d) (%d %d %d) %.20f %.20f\n",
x,
346 y, z, xTile, yTile, zTile, xOffs, yOffs, zOffs, *n1p,
349 "compareFilesNocache: files don't match\n");
355 printf(
"Files are identical up to precision.\n");
381 double n1 = 0, n2 = 0;
384 int x, y, z, correct;
386 int rows, cols, depths;
387 int tileX, tileY, tileZ, typeIntern, typeIntern2, tileX2, tileY2, tileZ2;
390 printf(
"\nComparing %s and %s\n", f1, f2);
397 "Rast3d_compare_files: error in Rast3d_open_cell_old");
406 "Rast3d_compare_files: error in Rast3d_open_cell_old");
423 compareFilesNocache(map, map2);
442 for (z = 0; z < depths; z++) {
443 printf(
"comparing: z = %d\n", z);
445 if ((z % tileZ) == 0) {
448 "Rast3d_compare_files: error in Rast3d_unlock_all");
450 if ((z % tileZ2) == 0) {
453 "Rast3d_compare_files: error in Rast3d_unlock_all");
456 for (y = 0; y < rows; y++) {
457 for (
x = 0;
x < cols;
x++) {
466 correct = Rast3d_compareFloats(f1p, p1, f2p, p2);
468 correct = Rast3d_compareFloatDouble(f1p, p1, n2p, p2);
472 correct = Rast3d_compareFloatDouble(f2p, p2, n1p, p1);
474 correct = Rast3d_compareDoubles(n1p, p1, n2p, p2);
478 int xTile, yTile, zTile, xOffs, yOffs, zOffs;
481 &zTile, &xOffs, &yOffs, &zOffs);
483 "Rast3d_compare_files: files don't match\n");
489 printf(
"Files are identical up to precision.\n");
void G_xdr_put_float(void *, const float *)
void G_xdr_put_double(void *, const double *)
int Rast3d_tile_type_map(RASTER3D_Map *)
Returns the type in which tiles of map are stored in memory.
void Rast3d_get_nof_tiles_map(RASTER3D_Map *, int *, int *, int *)
Returns the dimensions of the tile-cube used to tile the region of map. These numbers include partial...
void Rast3d_autolock_on(RASTER3D_Map *)
Turns autolock mode on.
void * Rast3d_open_cell_old(const char *, const char *, RASTER3D_Region *, int, int)
Opens existing g3d-file name in mapset. Tiles are stored in memory with type which must be any of FCE...
void Rast3d_get_tile_dimensions_map(RASTER3D_Map *, int *, int *, int *)
Returns the tile dimensions used for map.
int Rast3d_unlock_all(RASTER3D_Map *)
Unlocks every tile in cache of map.
void Rast3d_min_unlocked(RASTER3D_Map *, int)
Sets the minimum number of unlocked tiles to minUnlocked. This function should be used in combination...
int Rast3d_is_null_value_num(const void *, int)
int Rast3d_tile_precision_map(RASTER3D_Map *)
Returns the precision used to store map.
void Rast3d_get_coords_map(RASTER3D_Map *, int *, int *, int *)
Returns the size of the region of map in cells.
void Rast3d_get_block(RASTER3D_Map *, int, int, int, int, int, int, void *, int)
Copies the cells contained in the block (cube) with vertices (x0, y0, z0) and (x0 + nx - 1,...
int Rast3d_tile_use_cache_map(RASTER3D_Map *)
Returns 1 if map uses cache, returns 0 otherwise.
void Rast3d_print_header(RASTER3D_Map *)
Prints the header information of map.
void Rast3d_get_value_region(RASTER3D_Map *, int, int, int, void *, int)
Returns in *value the cell-value of the cell with region-coordinate (x, y, z). The value returned is ...
void Rast3d_coord2tile_coord(RASTER3D_Map *, int, int, int, int *, int *, int *, int *, int *, int *)
Converts cell-coordinates (x, y, z) into tile-coordinates (xTile, yTile, zTile) and the coordinate of...
void Rast3d_fatal_error(const char *,...) __attribute__((format(printf
int Rast3d_close(RASTER3D_Map *)
Close 3D raster map files.
void Rast3d_compare_files(const char *f1, const char *mapset1, const char *f2, const char *mapset2)
Compares the cell-values of file f1 in mapset mapset1 and file f2 in mapset mapset2....
dglInt32_t sign(dglInt32_t x)
#define RASTER3D_DEFAULT_WINDOW
#define RASTER3D_USE_CACHE_DEFAULT
#define RASTER3D_TILE_SAME_AS_FILE