11 static unsigned char clearMask[9] =
12 { 255, 128, 192, 224, 240, 248, 252, 254, 255 };
16 static void G3d_float2xdrFloat(
float *f,
float *xdrf)
20 xdrmem_create(&xdrEncodeStream, (caddr_t) xdrf, 4, XDR_ENCODE);
22 if (!xdr_setpos(&xdrEncodeStream, 0))
25 if (!xdr_float(&xdrEncodeStream, f))
28 xdr_destroy(&xdrEncodeStream);
33 static void G3d_double2xdrDouble(
double *d,
double *xdrd)
37 xdrmem_create(&xdrEncodeStream, (caddr_t) xdrd, 8, XDR_ENCODE);
39 if (!xdr_setpos(&xdrEncodeStream, 0))
42 if (!xdr_double(&xdrEncodeStream, d))
45 xdr_destroy(&xdrEncodeStream);
50 static void G3d_truncFloat(
float *f,
int p)
54 if ((p == -1) || (p >= 23))
57 c = (
unsigned char *)f;
61 *c++ &= clearMask[(p + 1) % 8];
69 *c++ &= clearMask[(p + 1) % 8];
75 *c &= clearMask[(p + 1) % 8];
81 static void G3d_truncDouble(
double *d,
int p)
85 if ((p == -1) || (p >= 52))
88 c = (
unsigned char *)d;
92 *c++ &= clearMask[(p + 4) % 8];
104 *c++ &= clearMask[(p + 4) % 8];
115 *c++ &= clearMask[(p + 4) % 8];
125 *c++ &= clearMask[(p + 4) % 8];
134 *c++ &= clearMask[(p + 4) % 8];
142 *c++ &= clearMask[(p + 4) % 8];
148 *c &= clearMask[(p + 4) % 8];
154 static void G3d_float2Double(
float *f,
double *d)
156 unsigned char *c1, *c2,
sign, c;
159 c1 = (
unsigned char *)f;
160 c2 = (
unsigned char *)d;
162 sign = (*c1 & (
unsigned char)128);
163 e = (((*c1 & (
unsigned char)127) << 1) |
164 ((*(c1 + 1) & (
unsigned char)128) >> 7));
166 if ((*c1 != 0) || (*(c1 + 1) != 0) || (*(c1 + 2) != 0) ||
177 *c2++ |= ((*c1 & (
unsigned char)127) >> 3);
179 *c2 = ((*c1++ & (
unsigned char)7) << 5);
182 *c2 = ((*c1++ & (
unsigned char)7) << 5);
185 *c2++ = ((*c1 & (
unsigned char)7) << 5);
187 *c2++ = (
unsigned char)0;
188 *c2++ = (
unsigned char)0;
189 *c2 = (
unsigned char)0;
194 static int G3d_compareFloats(
float *f1,
int p1,
float *f2,
int p2)
196 unsigned char *c1, *c2;
202 G3d_float2xdrFloat(f1, &xdrf1);
203 G3d_float2xdrFloat(f2, &xdrf2);
205 c1 = (
unsigned char *)&xdrf1;
206 c2 = (
unsigned char *)&xdrf2;
210 if ((p1 != -1) && (p1 < 23) && ((p1 < p2) || (p2 == -1)))
211 G3d_truncFloat(&xdrf2, p1);
212 if ((p2 != -1) && (p2 < 23) && ((p2 < p1) || (p1 == -1)))
213 G3d_truncFloat(&xdrf1, p2);
217 return (*c1 == *c2) && (*(c1 + 1) == *(c2 + 1)) &&
218 (*(c1 + 2) == *(c2 + 2))
219 && (*(c1 + 3) == *(c2 + 3));
225 static int G3d_compareDoubles(
double *d1,
int p1,
double *d2,
int p2)
227 unsigned char *c1, *c2;
233 G3d_double2xdrDouble(d1, &xdrd1);
234 G3d_double2xdrDouble(d2, &xdrd2);
236 c1 = (
unsigned char *)&xdrd1;
237 c2 = (
unsigned char *)&xdrd2;
241 if ((p1 != -1) && (p1 < 52) && ((p1 < p2) || (p2 == -1)))
242 G3d_truncDouble(&xdrd2, p1);
243 if ((p2 != -1) && (p2 < 52) && ((p2 < p1) || (p1 == -1)))
244 G3d_truncDouble(&xdrd1, p2);
248 return (*c1 == *c2) && (*(c1 + 1) == *(c2 + 1)) &&
249 (*(c1 + 2) == *(c2 + 2))
250 && (*(c1 + 3) == *(c2 + 3)) && (*(c1 + 4) == *(c2 + 4))
251 && (*(c1 + 5) == *(c2 + 5)) && (*(c1 + 6) == *(c2 + 6))
252 && (*(c1 + 7) == *(c2 + 7));
258 static int G3d_compareFloatDouble(
float *f,
int p1,
double *d,
int p2)
260 unsigned char *c1, *c2;
262 double xdrd, xdrd2, dTmp;
275 G3d_float2xdrFloat(f, &xdrf);
276 G3d_float2Double(&xdrf, &xdrd2);
277 G3d_double2xdrDouble(&dTmp, &xdrd);
279 c1 = (
unsigned char *)&xdrd2;
280 c2 = (
unsigned char *)&xdrd;
285 if (((p1 != -1) && ((p1 < p2) || (p2 == -1))) ||
286 ((p1 == -1) && ((p2 > 23) || (p2 == -1))))
287 G3d_truncDouble(&xdrd, (p1 != -1 ? p1 : 23));
288 if ((p2 != -1) && (p2 < 23) && ((p2 < p1) || (p1 == -1)))
289 G3d_truncDouble(&xdrd2, p2);
293 return (*c1 == *c2) && (*(c1 + 1) == *(c2 + 1)) &&
294 (*(c1 + 2) == *(c2 + 2))
295 && (*(c1 + 3) == *(c2 + 3)) && (*(c1 + 4) == *(c2 + 4))
296 && (*(c1 + 5) == *(c2 + 5)) && (*(c1 + 6) == *(c2 + 6))
297 && (*(c1 + 7) == *(c2 + 7));
302 static void compareFilesNocache(
void *map,
void *map2)
304 double n1 = 0, n2 = 0;
307 int x,
y, z, correct;
309 int tileX, tileY, tileZ, typeIntern, typeIntern2;
325 for (z = 0; z < nz * tileZ; z++) {
326 printf(
"comparing: z = %d\n", z);
328 for (y = 0; y < ny * tileY; y++) {
329 for (x = 0; x < nx * tileX; x++) {
334 if (typeIntern == FCELL_TYPE) {
335 if (typeIntern2 == FCELL_TYPE)
336 correct = G3d_compareFloats(f1p, p1, f2p, p2);
338 correct = G3d_compareFloatDouble(f1p, p1, n2p, p2);
341 if (typeIntern2 == FCELL_TYPE)
342 correct = G3d_compareFloatDouble(f2p, p2, n1p, p1);
344 correct = G3d_compareDoubles(n1p, p1, n2p, p2);
348 int xTile, yTile, zTile, xOffs, yOffs, zOffs;
351 &xOffs, &yOffs, &zOffs);
352 printf(
"(%d %d %d) (%d %d %d) (%d %d %d) %.20f %.20f\n",
353 x, y, z, xTile, yTile, zTile, xOffs, yOffs, zOffs,
356 (
"compareFilesNocache: files don't match\n");
362 printf(
"Files are identical up to precision.\n");
390 double n1 = 0, n2 = 0;
393 int x,
y, z, correct;
395 int rows,
cols, depths;
396 int tileX, tileY, tileZ, typeIntern, typeIntern2, tileX2, tileY2, tileZ2;
399 printf(
"\nComparing %s and %s\n", f1, f2);
402 G3D_TILE_SAME_AS_FILE, G3D_USE_CACHE_DEFAULT);
409 G3D_TILE_SAME_AS_FILE, G3D_USE_CACHE_DEFAULT);
427 compareFilesNocache(map, map2);
446 for (z = 0; z < depths; z++) {
447 printf(
"comparing: z = %d\n", z);
449 if ((z % tileZ) == 0) {
453 if ((z % tileZ2) == 0) {
458 for (y = 0; y < rows; y++) {
459 for (x = 0; x <
cols; x++) {
466 if (typeIntern == FCELL_TYPE) {
467 if (typeIntern2 == FCELL_TYPE)
468 correct = G3d_compareFloats(f1p, p1, f2p, p2);
470 correct = G3d_compareFloatDouble(f1p, p1, n2p, p2);
473 if (typeIntern2 == FCELL_TYPE)
474 correct = G3d_compareFloatDouble(f2p, p2, n1p, p1);
476 correct = G3d_compareDoubles(n1p, p1, n2p, p2);
480 int xTile, yTile, zTile, xOffs, yOffs, zOffs;
483 &xOffs, &yOffs, &zOffs);
490 printf(
"Files are identical up to precision.\n");