forked from HDFGroup/hdf5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathh5diff_array.c
4753 lines (4332 loc) · 196 KB
/
h5diff_array.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the LICENSE file, which can be found at the root of the source code *
* distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* [email protected]. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "H5private.h"
#include "h5tools.h"
#include "h5tools_utils.h"
#include "h5diff.h"
#include "ph5diff.h"
#define ATTR_NAME_MAX 255
/*-------------------------------------------------------------------------
* printf formatting
*-------------------------------------------------------------------------
*/
#define F_FORMAT "%-15g %-15g %-15g\n"
#define LD_FORMAT "%-15Lg %-15Lg %-15Lg\n"
#define I_FORMAT "%-15d %-15d %-15d\n"
#define S_FORMAT "%-16s %-17s\n"
#define UI_FORMAT "%-15u %-15u %-15u\n"
#define LI_FORMAT "%-15ld %-15ld %-15ld\n"
#define ULI_FORMAT "%-15lu %-15lu %-15lu\n"
#define LLI_FORMAT "%-15lld %-15lld %-15lld\n"
#define ULLI_FORMAT "%-15llu %-15llu %-15llu\n"
/* with -p option */
#define F_FORMAT_P "%-15.10g %-15.10g %-15.10g %-14.10g\n"
#define LD_FORMAT_P "%-15.10Lg %-15.10Lg %-15.10Lg %-14.10Lg\n"
#define I_FORMAT_P "%-15d %-15d %-15d %-14f\n"
#define UI_FORMAT_P "%-15u %-15u %-15u %-14f\n"
#define LI_FORMAT_P "%-15ld %-15ld %-15ld %-14f\n"
#define ULI_FORMAT_P "%-15lu %-15lu %-15lu %-14f\n"
#define LLI_FORMAT_P "%-15lld %-15lld %-15lld %-14f\n"
#define ULLI_FORMAT_P "%-15llu %-15llu %-15lld %-14f\n"
#define SPACES " "
/* not comparable */
#define F_FORMAT_P_NOTCOMP "%-15.10g %-15.10g %-15.10g not comparable\n"
#define LD_FORMAT_P_NOTCOMP "%-15.10Lg %-15.10Lg %-15.10Lg not comparable\n"
#define I_FORMAT_P_NOTCOMP "%-15d %-15d %-15d not comparable\n"
#define UI_FORMAT_P_NOTCOMP "%-15u %-15u %-15u not comparable\n"
#define LI_FORMAT_P_NOTCOMP "%-15ld %-15ld %-15ld not comparable\n"
#define ULI_FORMAT_P_NOTCOMP "%-15lu %-15lu %-15lu not comparable\n"
#define LLI_FORMAT_P_NOTCOMP "%-15lld %-15lld %-15lld not comparable\n"
#define ULLI_FORMAT_P_NOTCOMP "%-15llu %-15llu %-15lld not comparable\n"
/* Since complex numbers are printed with multiple format specifiers
* and also have the "i" character on the imaginary part, a field-width
* specifier can't be directly used as above since it messes with the
* formatting. Instead, print complex number parts into temporary buffers
* so we can ultimately use a field-width specifier with %s to justify
* fields against each other.
*/
#define FC_FORMAT_SINGLE "%g%+gi"
#define DC_FORMAT_SINGLE "%g%+gi"
#define LDC_FORMAT_SINGLE "%Lg%+Lgi"
#define FC_FORMAT "%-15s %-15s %-15s\n"
#define DC_FORMAT "%-15s %-15s %-15s\n"
#define LDC_FORMAT "%-15s %-15s %-15s\n"
/* with -p option */
#define FC_FORMAT_P_SINGLE "%.10g%+.10gi"
#define DC_FORMAT_P_SINGLE "%.10g%+.10gi"
#define LDC_FORMAT_P_SINGLE "%.10Lg%+.10Lgi"
#define FC_FORMAT_P "%-15s %-15s %-15s (%-14.10g,%14.10g)\n"
#define DC_FORMAT_P "%-15s %-15s %-15s (%-14.10g,%14.10g)\n"
#define LDC_FORMAT_P "%-15s %-15s %-15s (%-14.10Lg,%14.10Lg)\n"
/* not comparable */
#define FC_FORMAT_P_NOTCOMP_SINGLE "%.10g%+.10gi"
#define DC_FORMAT_P_NOTCOMP_SINGLE "%.10g%+.10gi"
#define LDC_FORMAT_P_NOTCOMP_SINGLE "%.10Lg%+.10Lgi"
#define FC_FORMAT_P_NOTCOMP "%-15s %-15s %-15s not comparable\n"
#define DC_FORMAT_P_NOTCOMP "%-15s %-15s %-15s not comparable\n"
#define LDC_FORMAT_P_NOTCOMP "%-15s %-15s %-15s not comparable\n"
/* if system EPSILON is defined, use the system EPSILON; otherwise, use
constants that are close to most EPSILON values */
#ifndef FLT_EPSILON
#define FLT_EPSILON 1.19209E-07
#endif
#ifndef DBL_EPSILON
#define DBL_EPSILON 2.22045E-16
#endif
/*-------------------------------------------------------------------------
* -p relative error formula
*
* We assume the true value of a quantity to be A (value in first dataset)
* and the measured or inferred value to be B (value in second dataset).
* The relative error is defined by
*
* B - A
* --------
* A
*
*-------------------------------------------------------------------------
*/
static bool not_comparable;
#define PER(A, B) \
do { \
per = -1; \
not_comparable = false; \
both_zero = false; \
if (H5_DBL_ABS_EQUAL(0, (double)(A)) && H5_DBL_ABS_EQUAL(0, (double)(B))) \
both_zero = true; \
if (!H5_DBL_ABS_EQUAL(0, (double)(A))) \
per = (double)ABS((double)((B) - (A)) / (double)(A)); \
else \
not_comparable = true; \
} while (0)
#define PER_UNSIGN(TYPE, A, B) \
do { \
per = -1; \
not_comparable = false; \
both_zero = false; \
if (H5_DBL_ABS_EQUAL(0, (double)(A)) && H5_DBL_ABS_EQUAL(0, (double)(B))) \
both_zero = true; \
if (!H5_DBL_ABS_EQUAL(0, (double)(A))) \
per = ABS((double)((TYPE)((B) - (A))) / (double)(A)); \
else \
not_comparable = true; \
} while (0)
#define PDIFF(a, b) (((b) > (a)) ? ((b) - (a)) : ((a) - (b)))
typedef struct mcomp_t {
unsigned n; /* number of members */
hid_t *ids; /* member type id */
size_t *offsets;
struct mcomp_t **m; /* members */
} mcomp_t;
/*-------------------------------------------------------------------------
* local prototypes
*-------------------------------------------------------------------------
*/
static bool all_zero(const void *_mem, size_t size);
static int ull2float(unsigned long long ull_value, float *f_value);
static hsize_t character_compare(char *mem1, char *mem2, hsize_t elemtno, size_t u, diff_opt_t *opts);
static hsize_t character_compare_opt(unsigned char *mem1, unsigned char *mem2, hsize_t elemtno,
diff_opt_t *opts);
static bool equal_float(float value, float expected, diff_opt_t *opts);
static bool equal_double(double value, double expected, diff_opt_t *opts);
static bool equal_ldouble(long double value, long double expected, diff_opt_t *opts);
static int print_data(diff_opt_t *opts);
static void print_pos(diff_opt_t *opts, hsize_t elemtno, size_t u);
static void h5diff_print_char(char ch);
static hsize_t diff_region(hid_t obj1_id, hid_t obj2_id, hid_t region1_id, hid_t region2_id,
diff_opt_t *opts);
static hsize_t diff_datum(void *_mem1, void *_mem2, hsize_t elemtno, diff_opt_t *opts, hid_t container1_id,
hid_t container2_id, mcomp_t *members);
/* element diffs */
static hsize_t diff_float_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx,
diff_opt_t *opts);
static hsize_t diff_double_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx,
diff_opt_t *opts);
static hsize_t diff_ldouble_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx,
diff_opt_t *opts);
#ifdef H5_HAVE__FLOAT16
static hsize_t diff_float16_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx,
diff_opt_t *opts);
#endif
#ifdef H5_HAVE_COMPLEX_NUMBERS
static hsize_t diff_float_complex_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx,
diff_opt_t *opts);
static hsize_t diff_double_complex_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx,
diff_opt_t *opts);
static hsize_t diff_ldouble_complex_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx,
diff_opt_t *opts);
#endif
static hsize_t diff_float_complex(float real1, float imag1, float real2, float imag2, hsize_t elem_idx,
diff_opt_t *opts);
static hsize_t diff_double_complex(double real1, double imag1, double real2, double imag2, hsize_t elem_idx,
diff_opt_t *opts);
static hsize_t diff_ldouble_complex(long double real1, long double imag1, long double real2,
long double imag2, hsize_t elem_idx, diff_opt_t *opts);
static hsize_t diff_complex_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx,
diff_opt_t *opts);
static hsize_t diff_schar_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx,
diff_opt_t *opts);
static hsize_t diff_uchar_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx,
diff_opt_t *opts);
static hsize_t diff_short_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx,
diff_opt_t *opts);
static hsize_t diff_ushort_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx,
diff_opt_t *opts);
static hsize_t diff_int_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx, diff_opt_t *opts);
static hsize_t diff_uint_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx,
diff_opt_t *opts);
static hsize_t diff_long_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx,
diff_opt_t *opts);
static hsize_t diff_ulong_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx,
diff_opt_t *opts);
static hsize_t diff_llong_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx,
diff_opt_t *opts);
static hsize_t diff_ullong_element(unsigned char *mem1, unsigned char *mem2, hsize_t elem_idx,
diff_opt_t *opts);
/*-------------------------------------------------------------------------
* NaN detection
*-------------------------------------------------------------------------
*/
typedef enum dtype_t { FLT_FLOAT, FLT_DOUBLE, FLT_LDOUBLE } dtype_t;
/*-------------------------------------------------------------------------
* XCAO, 11/10/2010
* added to improve performance for compound datasets
*/
static void get_member_types(hid_t tid, mcomp_t *members);
static void close_member_types(mcomp_t *members);
/*-------------------------------------------------------------------------
* Function: diff_array
*
* Purpose: compare two memory buffers;
*
* Return: number of differences found
*-------------------------------------------------------------------------
*/
hsize_t
diff_array(void *_mem1, void *_mem2, diff_opt_t *opts, hid_t container1_id, hid_t container2_id)
{
hsize_t nfound = 0; /* number of differences found */
size_t size; /* size of datum */
unsigned char *mem1 = (unsigned char *)_mem1;
unsigned char *mem2 = (unsigned char *)_mem2;
hsize_t i;
mcomp_t members;
H5T_class_t type_class;
H5TOOLS_START_DEBUG(" - rank:%d hs_nelmts:%" PRIuHSIZE " errstat:%d", opts->rank, opts->hs_nelmts,
opts->err_stat);
opts->print_header = 1; /* enable print header */
/* get the size. */
size = H5Tget_size(opts->m_tid);
type_class = H5Tget_class(opts->m_tid);
/* Fast comparison first for atomic type by memcmp().
* It is OK not to list non-atomic type here because it will not be caught
* by the condition, but it gives more clarity for code planning
*/
if (type_class != H5T_REFERENCE && type_class != H5T_COMPOUND && type_class != H5T_STRING &&
type_class != H5T_VLEN && memcmp(mem1, mem2, size * opts->hs_nelmts) == 0) {
H5TOOLS_ENDDEBUG(":Fast comparison - errstat:%d", opts->err_stat);
return 0;
}
H5TOOLS_DEBUG("type_class:%d", type_class);
switch (type_class) {
case H5T_NO_CLASS:
case H5T_TIME:
case H5T_NCLASSES:
default:
H5TOOLS_DEBUG("type_class:INVALID");
assert(0);
break;
/*-------------------------------------------------------------------------
* float and integer atomic types
*-------------------------------------------------------------------------
*/
case H5T_FLOAT:
H5TOOLS_DEBUG("type_class:H5T_FLOAT");
#ifdef H5_HAVE__FLOAT16
if (H5Tequal(opts->m_tid, H5T_NATIVE_FLOAT16)) {
for (i = 0; i < opts->hs_nelmts; i++) {
nfound += diff_float16_element(mem1, mem2, i, opts);
mem1 += sizeof(H5__Float16);
mem2 += sizeof(H5__Float16);
if (opts->count_bool && nfound >= opts->count)
return nfound;
}
}
else
#endif
if (H5Tequal(opts->m_tid, H5T_NATIVE_FLOAT)) {
for (i = 0; i < opts->hs_nelmts; i++) {
nfound += diff_float_element(mem1, mem2, i, opts);
mem1 += sizeof(float);
mem2 += sizeof(float);
if (opts->count_bool && nfound >= opts->count)
return nfound;
} /* nelmts */
}
else if (H5Tequal(opts->m_tid, H5T_NATIVE_DOUBLE)) {
for (i = 0; i < opts->hs_nelmts; i++) {
nfound += diff_double_element(mem1, mem2, i, opts);
mem1 += sizeof(double);
mem2 += sizeof(double);
if (opts->count_bool && nfound >= opts->count)
return nfound;
} /* nelmts */
}
else if (H5Tequal(opts->m_tid, H5T_NATIVE_LDOUBLE)) {
for (i = 0; i < opts->hs_nelmts; i++) {
nfound += diff_ldouble_element(mem1, mem2, i, opts);
mem1 += sizeof(long double);
mem2 += sizeof(long double);
if (opts->count_bool && nfound >= opts->count)
return nfound;
} /* nelmts */
}
break;
case H5T_INTEGER:
H5TOOLS_DEBUG("type_class:H5T_INTEGER");
if (H5Tequal(opts->m_tid, H5T_NATIVE_SCHAR)) {
for (i = 0; i < opts->hs_nelmts; i++) {
nfound += diff_schar_element(mem1, mem2, i, opts);
mem1 += sizeof(char);
mem2 += sizeof(char);
if (opts->count_bool && nfound >= opts->count)
return nfound;
} /* nelmts */
}
else if (H5Tequal(opts->m_tid, H5T_NATIVE_UCHAR)) {
for (i = 0; i < opts->hs_nelmts; i++) {
nfound += diff_uchar_element(mem1, mem2, i, opts);
mem1 += sizeof(unsigned char);
mem2 += sizeof(unsigned char);
if (opts->count_bool && nfound >= opts->count)
return nfound;
} /* nelmts */
}
else if (H5Tequal(opts->m_tid, H5T_NATIVE_SHORT)) {
for (i = 0; i < opts->hs_nelmts; i++) {
nfound += diff_short_element(mem1, mem2, i, opts);
mem1 += sizeof(short);
mem2 += sizeof(short);
if (opts->count_bool && nfound >= opts->count)
return nfound;
} /* nelmts */
}
else if (H5Tequal(opts->m_tid, H5T_NATIVE_USHORT)) {
for (i = 0; i < opts->hs_nelmts; i++) {
nfound += diff_ushort_element(mem1, mem2, i, opts);
mem1 += sizeof(unsigned short);
mem2 += sizeof(unsigned short);
if (opts->count_bool && nfound >= opts->count)
return nfound;
} /* nelmts */
}
else if (H5Tequal(opts->m_tid, H5T_NATIVE_INT)) {
for (i = 0; i < opts->hs_nelmts; i++) {
nfound += diff_int_element(mem1, mem2, i, opts);
mem1 += sizeof(int);
mem2 += sizeof(int);
if (opts->count_bool && nfound >= opts->count)
return nfound;
} /* nelmts */
}
else if (H5Tequal(opts->m_tid, H5T_NATIVE_UINT)) {
for (i = 0; i < opts->hs_nelmts; i++) {
nfound += diff_int_element(mem1, mem2, i, opts);
mem1 += sizeof(unsigned int);
mem2 += sizeof(unsigned int);
if (opts->count_bool && nfound >= opts->count)
return nfound;
} /* nelmts */
}
else if (H5Tequal(opts->m_tid, H5T_NATIVE_LONG)) {
for (i = 0; i < opts->hs_nelmts; i++) {
nfound += diff_long_element(mem1, mem2, i, opts);
mem1 += sizeof(long);
mem2 += sizeof(long);
if (opts->count_bool && nfound >= opts->count)
return nfound;
} /* nelmts */
}
else if (H5Tequal(opts->m_tid, H5T_NATIVE_ULONG)) {
for (i = 0; i < opts->hs_nelmts; i++) {
nfound += diff_ulong_element(mem1, mem2, i, opts);
mem1 += sizeof(unsigned long);
mem2 += sizeof(unsigned long);
if (opts->count_bool && nfound >= opts->count)
return nfound;
} /* nelmts */
}
else if (H5Tequal(opts->m_tid, H5T_NATIVE_LLONG)) {
for (i = 0; i < opts->hs_nelmts; i++) {
nfound += diff_llong_element(mem1, mem2, i, opts);
mem1 += sizeof(long long);
mem2 += sizeof(long long);
if (opts->count_bool && nfound >= opts->count)
return nfound;
} /* nelmts */
}
else if (H5Tequal(opts->m_tid, H5T_NATIVE_ULLONG)) {
for (i = 0; i < opts->hs_nelmts; i++) {
nfound += diff_ullong_element(mem1, mem2, i, opts);
mem1 += sizeof(unsigned long long);
mem2 += sizeof(unsigned long long);
if (opts->count_bool && nfound >= opts->count)
return nfound;
} /* nelmts */
}
break;
case H5T_COMPLEX:
H5TOOLS_DEBUG("type_class:H5T_COMPLEX");
#ifdef H5_HAVE_COMPLEX_NUMBERS
if (H5Tequal(opts->m_tid, H5T_NATIVE_FLOAT_COMPLEX) == true) {
for (i = 0; i < opts->hs_nelmts; i++) {
nfound += diff_float_complex_element(mem1, mem2, i, opts);
mem1 += sizeof(H5_float_complex);
mem2 += sizeof(H5_float_complex);
if (opts->count_bool && nfound >= opts->count)
return nfound;
}
}
else if (H5Tequal(opts->m_tid, H5T_NATIVE_DOUBLE_COMPLEX) == true) {
for (i = 0; i < opts->hs_nelmts; i++) {
nfound += diff_double_complex_element(mem1, mem2, i, opts);
mem1 += sizeof(H5_double_complex);
mem2 += sizeof(H5_double_complex);
if (opts->count_bool && nfound >= opts->count)
return nfound;
}
}
else if (H5Tequal(opts->m_tid, H5T_NATIVE_LDOUBLE_COMPLEX) == true) {
for (i = 0; i < opts->hs_nelmts; i++) {
nfound += diff_ldouble_complex_element(mem1, mem2, i, opts);
mem1 += sizeof(H5_ldouble_complex);
mem2 += sizeof(H5_ldouble_complex);
if (opts->count_bool && nfound >= opts->count)
return nfound;
}
}
else
#endif
{
memset(&members, 0, sizeof(mcomp_t));
for (i = 0; i < opts->hs_nelmts; i++) {
H5TOOLS_DEBUG("opts->pos[%" PRIuHSIZE "]:%" PRIuHSIZE " - nelmts:%" PRIuHSIZE, i,
opts->pos[i], opts->hs_nelmts);
nfound += diff_datum(mem1 + i * size, mem2 + i * size, i, opts, container1_id,
container2_id, &members);
if (opts->count_bool && nfound >= opts->count)
break;
}
}
break;
/*-------------------------------------------------------------------------
* Other types than float, integer and complex numbers
*-------------------------------------------------------------------------
*/
case H5T_COMPOUND:
case H5T_STRING:
case H5T_BITFIELD:
case H5T_OPAQUE:
case H5T_ENUM:
case H5T_ARRAY:
case H5T_VLEN:
case H5T_REFERENCE:
H5TOOLS_DEBUG("type_class:OTHER");
memset(&members, 0, sizeof(mcomp_t));
get_member_types(opts->m_tid, &members);
for (i = 0; i < opts->hs_nelmts; i++) {
H5TOOLS_DEBUG("opts->pos[%" PRIuHSIZE "]:%" PRIuHSIZE " - nelmts:%" PRIuHSIZE, i,
opts->pos[i], opts->hs_nelmts);
nfound += diff_datum(mem1 + i * size, mem2 + i * size, i, opts, container1_id, container2_id,
&members);
if (opts->count_bool && nfound >= opts->count)
break;
} /* i */
close_member_types(&members);
} /* switch */
H5TOOLS_ENDDEBUG(":%" PRIuHSIZE " - errstat:%d", nfound, opts->err_stat);
return nfound;
}
/*-------------------------------------------------------------------------
* Function: diff_datum
*
* Purpose: compare the values pointed to in _MEM1 and _MEM2 of type M_TYPE
*
* Return: number of differences found
*
* The comparison of the 2 buffers read from the files is made datum by datum.
*
* H5T_INTEGER and H5T_FLOAT
* Copy the buffer into a compatible local datum and do a numerical
* compare of this datum
* H5T_COMPOUND
* Recursively call this function for each member
* H5T_ARRAY
* Recursively call this function for each element
* H5T_VLEN
* Recursively call this function for each element
* H5T_COMPLEX
* Recursively call this function for each part of the complex number type
* for each element
* H5T_STRING
* compare byte by byte in a cycle from 0 to type_size. this type_size is the
* value obtained by the get_size function but it is the string length for
* variable sized strings
* H5T_OPAQUE
* compare byte by byte in a cycle from 0 to type_size
* H5T_BITFIELD
* compare byte by byte in a cycle from 0 to type_size
* H5T_ENUM
* for each pair of elements being compared, both bit patterns are converted to
* their corresponding enumeration constant and a string comparison is made
* H5T_REFERENCE
* Dereference the object and compare the type (basic object type).
*-------------------------------------------------------------------------
*/
static hsize_t
diff_datum(void *_mem1, void *_mem2, hsize_t elemtno, diff_opt_t *opts, hid_t container1_id,
hid_t container2_id, mcomp_t *members)
{
unsigned char *mem1 = (unsigned char *)_mem1;
unsigned char *mem2 = (unsigned char *)_mem2;
size_t u;
size_t type_size;
H5T_sign_t type_sign;
H5T_class_t type_class;
size_t offset;
unsigned nmembs;
unsigned j;
size_t size = 0;
bool iszero1;
bool iszero2;
hsize_t nfound = 0; /* differences found */
diff_err_t ret_value = opts->err_stat;
H5TOOLS_START_DEBUG("ph:%d elemtno:%" PRIuHSIZE " - errstat:%d", opts->print_header, elemtno,
opts->err_stat);
type_size = H5Tget_size(opts->m_tid);
type_class = H5Tget_class(opts->m_tid);
/* Fast comparison first for atomic type by memcmp().
* It is OK not to list non-atomic type here because it will not be caught
* by the condition, but it gives more clarity for code planning
*/
if (type_class != H5T_REFERENCE && type_class != H5T_COMPOUND && type_class != H5T_STRING &&
type_class != H5T_VLEN && memcmp(mem1, mem2, type_size) == 0)
H5TOOLS_GOTO_DONE(opts->err_stat);
switch (H5Tget_class(opts->m_tid)) {
case H5T_NO_CLASS:
case H5T_TIME:
case H5T_NCLASSES:
default:
H5TOOLS_GOTO_ERROR(H5DIFF_ERR, "Invalid type class");
break;
/*-------------------------------------------------------------------------
* H5T_COMPOUND
*-------------------------------------------------------------------------
*/
case H5T_COMPOUND:
H5TOOLS_DEBUG("H5T_COMPOUND");
{
diff_opt_t cmpd_opts;
cmpd_opts = *opts;
nmembs = members->n;
for (j = 0; j < nmembs; j++) {
offset = members->offsets[j];
cmpd_opts.m_tid = members->ids[j];
nfound += diff_datum(mem1 + offset, mem2 + offset, elemtno, &cmpd_opts, container1_id,
container2_id, members->m[j]);
}
opts->err_stat = opts->err_stat | cmpd_opts.err_stat;
opts->print_header = cmpd_opts.print_header;
opts->not_cmp = cmpd_opts.not_cmp;
}
break;
/*-------------------------------------------------------------------------
* H5T_STRING
*-------------------------------------------------------------------------
*/
case H5T_STRING:
H5TOOLS_DEBUG("H5T_STRING");
{
char *s = NULL;
char *sx = NULL;
char *s1 = NULL;
char *s2 = NULL;
size_t size1;
size_t size2;
size_t sizex;
size_t size_mtype = H5Tget_size(opts->m_tid);
H5T_str_t pad = H5Tget_strpad(opts->m_tid);
/* if variable length string */
if (H5Tis_variable_str(opts->m_tid)) {
H5TOOLS_DEBUG("H5T_STRING variable");
/* Get pointer to first string */
s1 = *(char **)((void *)mem1);
if (s1)
size1 = strlen(s1);
else
size1 = 0;
/* Get pointer to second string */
s2 = *(char **)((void *)mem2);
if (s2)
size2 = strlen(s2);
else
size2 = 0;
}
else if (H5T_STR_NULLTERM == pad) {
H5TOOLS_DEBUG("H5T_STRING null term");
/* Get pointer to first string */
s1 = (char *)mem1;
if (s1)
size1 = strlen(s1);
else
size1 = 0;
if (size1 > size_mtype)
size1 = size_mtype;
/* Get pointer to second string */
s2 = (char *)mem2;
if (s2)
size2 = strlen(s2);
else
size2 = 0;
if (size2 > size_mtype)
size2 = size_mtype;
}
else {
/* Get pointer to first string */
s1 = (char *)mem1;
size1 = size_mtype;
/* Get pointer to second string */
s2 = (char *)mem2;
size2 = size_mtype;
}
/*
* compare for shorter string
* TODO: this code need to be improved to handle the difference
* of length of strings.
* For now mimic the previous way.
*/
H5TOOLS_DEBUG("string size:%ld", size1);
H5TOOLS_DEBUG("string size:%ld", size2);
if (size1 != size2) {
H5TOOLS_DEBUG("string sizes difference");
nfound++;
}
if (size1 < size2) {
size = size1;
s = s1;
sizex = size2;
sx = s2;
}
else {
size = size2;
s = s2;
sizex = size1;
sx = s1;
}
/* check for NULL pointer for string */
if (s != NULL) {
/* try fast compare first */
if ((memcmp(s, sx, size) == 0) && (size1 != size2)) {
for (u = size; u < sizex; u++)
character_compare(s + u, sx + u, elemtno, u, opts);
}
else
for (u = 0; u < size; u++)
nfound += character_compare(s + u, sx + u, elemtno, u, opts);
} /* end check for NULL pointer for string */
}
break;
/*-------------------------------------------------------------------------
* H5T_BITFIELD
*-------------------------------------------------------------------------
*/
case H5T_BITFIELD:
H5TOOLS_DEBUG("H5T_BITFIELD");
/* byte-by-byte comparison */
for (u = 0; u < type_size; u++)
nfound += character_compare_opt(mem1 + u, mem2 + u, elemtno, opts);
break;
/*-------------------------------------------------------------------------
* H5T_OPAQUE
*-------------------------------------------------------------------------
*/
case H5T_OPAQUE:
H5TOOLS_DEBUG("H5T_OPAQUE");
/* byte-by-byte comparison */
for (u = 0; u < type_size; u++)
nfound += character_compare_opt(mem1 + u, mem2 + u, elemtno, opts);
break;
/*-------------------------------------------------------------------------
* H5T_ENUM
*-------------------------------------------------------------------------
*/
case H5T_ENUM:
/* For enumeration types we compare the names instead of the
* integer values. For each pair of elements being
* compared, we convert both bit patterns to their corresponding
* enumeration constant and do a string comparison
*/
H5TOOLS_DEBUG("H5T_ENUM");
{
char enum_name1[1024];
char enum_name2[1024];
herr_t err1;
herr_t err2;
/* disable error reporting */
H5E_BEGIN_TRY
{
/* If the enum value cannot be converted to a string
* it is set to an error string for later output.
*/
err1 = H5Tenum_nameof(opts->m_tid, mem1, enum_name1, sizeof enum_name1);
if (err1 < 0)
snprintf(enum_name1, sizeof(enum_name1), "**INVALID VALUE**");
err2 = H5Tenum_nameof(opts->m_tid, mem2, enum_name2, sizeof enum_name2);
if (err2 < 0)
snprintf(enum_name2, sizeof(enum_name2), "**INVALID VALUE**");
/* One or more bad enum values */
if (err1 < 0 || err2 < 0) {
/* If the two values cannot be converted to a string
* (probably due to them being invalid enum values),
* don't attempt to convert them - just report errors.
*/
nfound += 1;
opts->print_percentage = 0;
print_pos(opts, elemtno, 0);
if (print_data(opts)) {
parallel_print(S_FORMAT, enum_name1, enum_name2);
}
}
else {
/* Both enum values were valid */
if (strcmp(enum_name1, enum_name2) != 0) {
nfound = 1;
opts->print_percentage = 0;
print_pos(opts, elemtno, 0);
if (print_data(opts)) {
parallel_print(S_FORMAT, enum_name1, enum_name2);
}
}
else {
for (u = 0; u < type_size; u++)
nfound += character_compare_opt(mem1 + u, mem2 + u, elemtno, opts);
}
}
/* enable error reporting */
}
H5E_END_TRY
}
break;
/*-------------------------------------------------------------------------
* H5T_ARRAY
*-------------------------------------------------------------------------
*/
case H5T_ARRAY: {
hsize_t adims[H5S_MAX_RANK];
int ndims;
diff_opt_t arr_opts;
H5TOOLS_DEBUG("H5T_ARRAY ph=%d", opts->print_header);
arr_opts = *opts;
H5TOOLS_DEBUG("Check opts: hs_nelmts:%" PRIuHSIZE " to %" PRIuHSIZE " rank:%d to %d",
opts->hs_nelmts, arr_opts.hs_nelmts, opts->rank, arr_opts.rank);
/* get the array's base datatype for each element */
arr_opts.m_tid = H5Tget_super(opts->m_tid);
size = H5Tget_size(arr_opts.m_tid);
ndims = H5Tget_array_ndims(opts->m_tid);
H5Tget_array_dims2(opts->m_tid, adims);
assert(ndims >= 1 && ndims <= H5S_MAX_RANK);
H5TOOLS_DEBUG("attr ph=%d", arr_opts.print_header);
/* calculate the number of array elements */
for (u = 0, arr_opts.hs_nelmts = 1; u < (unsigned)ndims; u++)
arr_opts.hs_nelmts *= adims[u];
for (u = 0; u < arr_opts.hs_nelmts; u++) {
nfound += diff_datum(mem1 + u * size, mem2 + u * size, elemtno, &arr_opts, container1_id,
container2_id, members);
}
opts->err_stat = opts->err_stat | arr_opts.err_stat;
opts->print_header = arr_opts.print_header;
opts->not_cmp = arr_opts.not_cmp;
H5Tclose(arr_opts.m_tid);
} break;
/*-------------------------------------------------------------------------
* H5T_REFERENCE
*-------------------------------------------------------------------------
*/
case H5T_REFERENCE:
H5TOOLS_DEBUG("H5T_REFERENCE");
iszero1 = all_zero(_mem1, H5Tget_size(opts->m_tid));
iszero2 = all_zero(_mem2, H5Tget_size(opts->m_tid));
if (iszero1 != iszero2) {
nfound++;
H5TOOLS_GOTO_DONE(opts->err_stat);
}
else if (!iszero1 && !iszero2) {
hid_t obj1_id = H5I_INVALID_HID;
hid_t obj2_id = H5I_INVALID_HID;
diff_opt_t ref_opts;
/*-------------------------------------------------------------------------
* H5T_STD_REF
* Reference
*-------------------------------------------------------------------------
*/
ref_opts = *opts;
ref_opts.obj_name[0] = NULL;
ref_opts.obj_name[1] = NULL;
if (H5Tequal(ref_opts.m_tid, H5T_STD_REF)) {
/* if (type_size == H5R_STD_REF_SIZE) */
hid_t region1_id = H5I_INVALID_HID;
hid_t region2_id = H5I_INVALID_HID;
H5R_ref_t *ref1_buf = (H5R_ref_t *)_mem1;
H5R_ref_t *ref2_buf = (H5R_ref_t *)_mem2;
H5O_type_t obj1_type = -1; /* Object type */
H5O_type_t obj2_type = -1; /* Object type */
H5R_type_t ref_type; /* Reference type */
H5TOOLS_DEBUG("H5T_REFERENCE - H5T_STD_REF");
ref_type = H5Rget_type(ref1_buf);
switch (ref_type) {
case H5R_OBJECT1:
H5TOOLS_DEBUG("ref_type is H5R_OBJECT1");
if (H5Rget_obj_type3(ref1_buf, H5P_DEFAULT, &obj1_type) >= 0) {
if (H5Rget_obj_type3(ref2_buf, H5P_DEFAULT, &obj2_type) >= 0) {
/* check object type */
if (obj1_type == obj2_type) {
switch (obj1_type) {
case H5O_TYPE_DATASET:
if ((obj1_id = H5Ropen_object(ref1_buf, H5P_DEFAULT,
H5P_DEFAULT)) >= 0) {
if ((obj2_id = H5Ropen_object(ref2_buf, H5P_DEFAULT,
H5P_DEFAULT)) >= 0) {
nfound = diff_datasetid(obj1_id, obj2_id,
opts->obj_name[0],
opts->obj_name[1], &ref_opts);
if (H5Dclose(obj2_id) < 0) {
ref_opts.err_stat = H5DIFF_ERR;
H5TOOLS_INFO("H5Dclose H5R_OBJECT1 failed");
}
}
else {
ref_opts.err_stat = H5DIFF_ERR;
H5TOOLS_INFO("H5Ropen_object object 2 failed");
}
if (H5Dclose(obj1_id) < 0) {
ref_opts.err_stat = H5DIFF_ERR;
H5TOOLS_INFO("H5Dclose H5R_OBJECT1 failed");
}
}
else {
ref_opts.err_stat = H5DIFF_ERR;
H5TOOLS_INFO("H5Ropen_object object 1 failed");
}
break;
case H5O_TYPE_GROUP:
case H5O_TYPE_NAMED_DATATYPE:
case H5O_TYPE_MAP:
case H5O_TYPE_UNKNOWN:
case H5O_TYPE_NTYPES:
default:
if (ref_opts.mode_verbose)
parallel_print("Warning: Comparison not possible of "
"object types referenced: <%s> and <%s>\n",
opts->obj_name[0], opts->obj_name[1]);
ref_opts.not_cmp = 1;
break;
} /* end switch */
}
else {
parallel_print("Different object types referenced: <%s> and <%s>",
opts->obj_name[0], opts->obj_name[1]);
ref_opts.not_cmp = 1;
ref_opts.err_stat = H5DIFF_ERR;
}
}
else {
ref_opts.err_stat = H5DIFF_ERR;
H5TOOLS_INFO("H5Rget_obj_type3 object 2 failed");
}
}
else {
ref_opts.err_stat = H5DIFF_ERR;
H5TOOLS_INFO("H5Rget_obj_type3 object 1 failed");
}
break;
case H5R_DATASET_REGION1:
H5TOOLS_DEBUG("ref_type is H5R_DATASET_REGION1");
if ((obj1_id = H5Ropen_object(ref1_buf, H5P_DEFAULT, H5P_DEFAULT)) >= 0) {
if ((obj2_id = H5Ropen_object(ref2_buf, H5P_DEFAULT, H5P_DEFAULT)) >= 0) {
if ((region1_id = H5Ropen_region(ref1_buf, H5P_DEFAULT, H5P_DEFAULT)) >=
0) {
if ((region2_id =
H5Ropen_region(ref2_buf, H5P_DEFAULT, H5P_DEFAULT)) >= 0) {
nfound = diff_region(obj1_id, obj2_id, region1_id, region2_id,
&ref_opts);
if (H5Sclose(region2_id) < 0)
H5TOOLS_INFO("H5Sclose H5R_DATASET_REGION1 failed");
}
if (H5Sclose(region1_id) < 0)
H5TOOLS_INFO("H5Sclose H5R_DATASET_REGION1 failed");
}
if (H5Dclose(obj2_id) < 0)
H5TOOLS_INFO("H5Oclose H5R_DATASET_REGION1 failed");
}
else {
H5TOOLS_INFO("H5Ropen_object H5R_DATASET_REGION1 failed");
}
if (H5Dclose(obj1_id) < 0)
H5TOOLS_INFO("H5Oclose H5R_DATASET_REGION1 failed");
}
else {
H5TOOLS_INFO("H5Ropen_object H5R_DATASET_REGION1 failed");
}
break;
case H5R_OBJECT2:
H5TOOLS_DEBUG("ref_type is H5R_OBJECT2");
if (H5Rget_obj_type3(ref1_buf, H5P_DEFAULT, &obj1_type) >= 0) {
if (H5Rget_obj_type3(ref2_buf, H5P_DEFAULT, &obj2_type) >= 0) {
/* check object type */
if (obj1_type == obj2_type) {
if ((obj1_id = H5Ropen_object(ref1_buf, H5P_DEFAULT, H5P_DEFAULT)) >=
0) {
if ((obj2_id = H5Ropen_object(ref2_buf, H5P_DEFAULT,
H5P_DEFAULT)) >= 0) {
switch (obj1_type) {
case H5O_TYPE_DATASET:
H5TOOLS_DEBUG("ref_type is H5R_OBJECT2 : DATASET");
nfound = diff_datasetid(obj1_id, obj2_id,
opts->obj_name[0],
opts->obj_name[1], &ref_opts);
break;
case H5O_TYPE_GROUP:
H5TOOLS_DEBUG("ref_type is H5R_OBJECT2 : GROUP");
if (ref_opts.mode_verbose)
parallel_print(
"Warning: Comparison not possible of group "
"object types referenced: <%s> and <%s>\n",
opts->obj_name[0], opts->obj_name[1]);
ref_opts.not_cmp = 1;
break;