summaryrefslogtreecommitdiffstats
path: root/tools/lib/h5tools_dump.c
blob: 5a8c4017a48e7cb51d272cd4ee4f5dead44c06e2 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * 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 COPYING 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     *
 * help@hdfgroup.org.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*
 * Purpose: A library for displaying the values of a dataset in a human
 *  readable format.
 */

#include "h5tools.h"
#include "h5tools_dump.h"
#include "h5tools_ref.h"
#include "h5tools_utils.h"
#include "H5private.h"

h5tool_format_t h5tools_dataformat = {
    0, /*raw */

    "",     /*fmt_raw */
    "%d",   /*fmt_int */
    "%u",   /*fmt_uint */
    "%hhd", /*fmt_schar */
    "%u",   /*fmt_uchar */
    "%d",   /*fmt_short */
    "%u",   /*fmt_ushort */
    "%ld",  /*fmt_long */
    "%lu",  /*fmt_ulong */
    NULL,   /*fmt_llong */
    NULL,   /*fmt_ullong */
    "%g",   /*fmt_double */
    "%g",   /*fmt_float */

    0, /*ascii */
    0, /*str_locale */
    0, /*str_repeat */

    "[ ", /*arr_pre */
    ",",  /*arr_sep */
    " ]", /*arr_suf */
    1,    /*arr_linebreak */

    "",    /*cmpd_name */
    ",\n", /*cmpd_sep */
    "{",   /*cmpd_pre */
    "}",   /*cmpd_suf */
    "\n",  /*cmpd_end */
    NULL,  /* cmpd_listv */

    ", ", /*vlen_sep */
    "(",  /*vlen_pre */
    ")",  /*vlen_suf */
    "",   /*vlen_end */

    "%s", /*elmt_fmt */
    ",",  /*elmt_suf1 */
    " ",  /*elmt_suf2 */

    "", /*idx_n_fmt */
    "", /*idx_sep */
    "", /*idx_fmt */

    80,
    /*line_ncols */ /*standard default columns */
    0,              /*line_per_line */
    "",             /*line_pre */
    "%s",           /*line_1st */
    "%s",           /*line_cont */
    "",             /*line_suf */
    "",             /*line_sep */
    1,              /*line_multi_new */
    "   ",          /*line_indent */

    1, /*skip_first */

    1,              /*obj_hidefileno */
    " %" PRIuHADDR, /*obj_format */

    1,             /*dset_hidefileno */
    "DATASET %s ", /*dset_format */
    "%s",          /*dset_blockformat_pre */
    "%s",          /*dset_ptformat_pre */
    "%s",          /*dset_ptformat */
    1,             /*array indices */
    1              /*escape non printable characters */
};

const h5tools_dump_header_t h5tools_standardformat = {
    "standardformat",  /*name */
    "HDF5",            /*filebegin */
    "",                /*fileend */
    SUPER_BLOCK,       /*bootblockbegin */
    "",                /*bootblockend */
    H5_TOOLS_GROUP,    /*groupbegin */
    "",                /*groupend */
    H5_TOOLS_DATASET,  /*datasetbegin */
    "",                /*datasetend */
    ATTRIBUTE,         /*attributebegin */
    "",                /*attributeend */
    H5_TOOLS_DATATYPE, /*datatypebegin */
    "",                /*datatypeend */
    DATASPACE,         /*dataspacebegin */
    "",                /*dataspaceend */
    DATA,              /*databegin */
    "",                /*dataend */
    SOFTLINK,          /*softlinkbegin */
    "",                /*softlinkend */
    EXTLINK,           /*extlinkbegin */
    "",                /*extlinkend */
    UDLINK,            /*udlinkbegin */
    "",                /*udlinkend */
    SUBSET,            /*subsettingbegin */
    "",                /*subsettingend */
    START,             /*startbegin */
    "",                /*startend */
    STRIDE,            /*stridebegin */
    "",                /*strideend */
    COUNT,             /*countbegin */
    "",                /*countend */
    BLOCK,             /*blockbegin */
    "",                /*blockend */

    "{",                /*fileblockbegin */
    "}",                /*fileblockend */
    "{",                /*bootblockblockbegin */
    "}",                /*bootblockblockend */
    "{",                /*groupblockbegin */
    "}",                /*groupblockend */
    "{",                /*datasetblockbegin */
    "}",                /*datasetblockend */
    "{",                /*attributeblockbegin */
    "}",                /*attributeblockend */
    "",                 /*datatypeblockbegin */
    "",                 /*datatypeblockend */
    "",                 /*dataspaceblockbegin */
    "",                 /*dataspaceblockend */
    "{",                /*datablockbegin */
    "}",                /*datablockend */
    "{",                /*softlinkblockbegin */
    "}",                /*softlinkblockend */
    "{",                /*extlinkblockbegin */
    "}",                /*extlinkblockend */
    "{",                /*udlinkblockbegin */
    "}",                /*udlinkblockend */
    "H5T_ARRAY { ",     /*arrblockbegin */
    " }",               /*arrblockend */
    "H5T_COMPOUND {",   /*cmpdblockbegin */
    "}",                /*cmpdblockend */
    "H5T_ENUM {",       /*enumblockbegin */
    "}",                /*enumblockend */
    "H5T_OPAQUE {",     /*opaqblockbegin */
    "}",                /*opaqblockend */
    "H5T_REFERENCE { ", /*refblockbegin */
    " }",               /*refblockend */
    "H5T_STRING {",     /*strblockbegin */
    "}",                /*strblockend */
    "H5T_VLEN { ",      /*vlenblockbegin */
    " }",               /*vlenblockend */
    "{",                /*structblockbegin */
    "}",                /*structblockend */
    "{",                /*subsettingblockbegin */
    "}",                /*subsettingblockend */
    "(",                /*startblockbegin */
    ");",               /*startblockend */
    "(",                /*strideblockbegin */
    ");",               /*strideblockend */
    "(",                /*countblockbegin */
    ");",               /*countblockend */
    "(",                /*blockblockbegin */
    ");",               /*blockblockend */

    "",  /*dataspacedescriptionbegin */
    "",  /*dataspacedescriptionend */
    "(", /*dataspacedimbegin */
    ")", /*dataspacedimend */

    "",   /*virtualselectionbegin */
    "",   /*virtualselectionend */
    "{",  /*virtualselectionblockbegin */
    "}",  /*virtualselectionblockend */
    "\"", /*virtualfilenamebeginbegin */
    "\"", /*virtualfilenamebeginend */
    "\"", /*virtualdatasetnamebegin */
    "\"", /*virtualdtatasetnameend */
};

const h5tools_dump_header_t *h5tools_dump_header_format;
table_t                     *h5dump_type_table = NULL; /* type table reference for datatype dump  */

/* local prototypes */

static int h5tools_print_region_data_blocks(hid_t region_id, FILE *stream, const h5tool_format_t *info,
                                            h5tools_context_t *cur_ctx,
                                            h5tools_str_t     *buffer, /* string into which to render */
                                            size_t ncols, unsigned ndims, hid_t type_id, hsize_t nblocks,
                                            hsize_t *ptdata);

static int h5tools_print_region_data_points(hid_t region_space, hid_t region_id, FILE *stream,
                                            const h5tool_format_t *info, h5tools_context_t *cur_ctx,
                                            h5tools_str_t *buffer, size_t ncols, unsigned ndims,
                                            hid_t type_id, hsize_t npoints, hsize_t *ptdata);

void h5tools_print_dims(h5tools_str_t *buffer, hsize_t *s, int dims);

void h5tools_dump_subsetting_header(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx,
                                    int dims);

static void h5tools_print_virtual_selection(hid_t vspace, FILE *stream, const h5tool_format_t *info,
                                            h5tools_context_t *ctx,      /* in,out */
                                            h5tools_str_t     *buffer,   /* string into which to render */
                                            hsize_t           *curr_pos, /* total data element position */
                                            size_t             ncols);

void
h5tools_dump_init(void)
{
    h5tools_dump_header_format = &h5tools_standardformat;
}

/*-------------------------------------------------------------------------
 * Audience:    Public
 * Chapter:     H5Tools Library
 * Purpose:     Prints NELMTS data elements to output STREAM.
 * Description:
 *      Prints some (NELMTS) data elements to output STREAM. The elements are
 *      stored in _MEM as type TYPE and are printed according to the format
 *      described in INFO. The CTX struct contains context information shared
 *      between calls to this function. The FLAGS is a bit field that
 *      indicates whether the data supplied in this call falls at the
 *      beginning or end of the total data to be printed (START_OF_DATA and
 *      END_OF_DATA).
 * Return: Success:    SUCCEED
 *         Failure:    FAIL
 *
 *-------------------------------------------------------------------------
 */
int
h5tools_dump_simple_data(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, /* in,out */
                         hid_t container, unsigned flags, hsize_t nelmts, hid_t type, void *_mem)
{
    unsigned char *mem = (unsigned char *)_mem;
    hsize_t        i;    /* element counter  */
    size_t         size; /* size of each datum  */
    bool           dimension_break = true;
    size_t         ncols           = 80; /* available output width */
    h5tools_str_t  buffer;               /* string into which to render */
    hsize_t        curr_pos     = 0;     /* total data element position   */
    hsize_t        elmt_counter = 0;     /* counts the # elements printed.
                                          * I (ptl?) needed something that
                                          * isn't going to get reset when a new
                                          * line is formed. I'm going to use
                                          * this var to count elements and
                                          * break after we see a number equal
                                          * to the ctx->size_last_dim.   */
    int ret_value = 0;

    H5TOOLS_START_DEBUG(" file=%p", (void *)stream);
    H5TOOLS_DEBUG("rawdata file=%p", (void *)rawdatastream);
    /* binary dump */
    if (bin_output && (rawdatastream != NULL)) {
        H5TOOLS_DEBUG("render_bin_output");
        if (render_bin_output(rawdatastream, container, type, _mem, nelmts) < 0) {
            PRINTVALSTREAM(rawoutstream, "\nError in writing binary stream\n");
        }
    } /* end if */
    else {
        /* setup */
        memset(&buffer, 0, sizeof(h5tools_str_t));
        size = H5Tget_size(type);
        H5TOOLS_DEBUG("type size is %ld", size);

        if (info->line_ncols > 0)
            ncols = info->line_ncols;

        /* pass to the prefix in h5tools_simple_prefix the total position
         * instead of the current stripmine position i; this is necessary
         * to print the array indices
         */
        curr_pos = ctx->sm_pos;

        H5TOOLS_DEBUG("data render start:%ld", nelmts);
        for (i = 0; i < nelmts; i++, ctx->cur_elmt++, elmt_counter++) {
            void *memref = mem + i * size;

            /* Render the data element begin*/
            h5tools_str_reset(&buffer);
            h5tools_str_sprint(&buffer, info, container, type, memref, ctx);

            if (i + 1 < nelmts || (flags & END_OF_DATA) == 0)
                h5tools_str_append(&buffer, "%s", OPT(info->elmt_suf1, ","));

            dimension_break =
                h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, ncols, i, elmt_counter);
            /* Render the data element end*/
            if (false == dimension_break)
                elmt_counter = 0;
        } /* end for (i = 0; i < nelmts... */
        H5TOOLS_DEBUG("data render finish");

        h5tools_str_close(&buffer);
    } /* else bin */

    H5TOOLS_ENDDEBUG("exit");
    return ret_value;
}

/*-------------------------------------------------------------------------
 * Audience:    Public
 * Chapter:     H5Tools Library
 * Purpose: Print some values from an attribute referenced by object reference.
 *
 * Description:
 *      This is a special case subfunction to dump an attribute reference.
 *
 * Return:
 *      The function returns False if the last dimension has been reached, otherwise True
 *
 * In/Out:
 *      h5tools_context_t *ctx
 *      hsize_t *curr_pos
 *
 * Parameters Description:
 *      h5tools_str_t *buffer is the string into which to render
 *      hsize_t curr_pos is the total data element position
 *      size_t ncols
 *      hsize_t region_elmt_counter is the region element loop counter
 *      hsize_t elmt_count is the data element loop counter
 *-------------------------------------------------------------------------
 */
bool
h5tools_dump_region_attribute(hid_t region_id, FILE *stream, const h5tool_format_t *info,
                              h5tools_context_t *ctx,                    /* in,out */
                              h5tools_str_t     *buffer,                 /* string into which to render */
                              hsize_t           *curr_pos,               /* total data element position */
                              size_t ncols, hsize_t region_elmt_counter, /* element counter */
                              hsize_t elmt_counter)
{
    bool            dimension_break = true;
    hid_t           atype           = H5I_INVALID_HID;
    hid_t           type_id         = H5I_INVALID_HID;
    hid_t           region_space    = H5I_INVALID_HID;
    h5tool_format_t outputformat; /* Use to disable prefix for DATA attribute display */
    bool            past_catch = false;
    bool            ret_value  = true;

    assert(info);
    assert(ctx);
    assert(buffer);

    outputformat           = *info;
    outputformat.idx_fmt   = "";
    outputformat.idx_n_fmt = "";
    outputformat.idx_sep   = "";
    outputformat.line_pre  = "";

    H5TOOLS_DEBUG("enter file=%p", (void *)stream);
    H5TOOLS_DEBUG("rawdata file=%p", (void *)rawdatastream);

    /* Render the region { element begin */
    h5tools_str_reset(buffer);

    h5tools_str_append(buffer, " {");
    dimension_break = h5tools_render_element(stream, &outputformat, ctx, buffer, curr_pos, ncols,
                                             region_elmt_counter, elmt_counter);
    /* Render the region { element end */

    if ((region_space = H5Aget_space(region_id)) < 0)
        H5TOOLS_GOTO_ERROR(dimension_break, "H5Aget_space failed");
    if ((atype = H5Aget_type(region_id)) < 0)
        H5TOOLS_GOTO_ERROR(dimension_break, "H5Aget_type failed");
    if ((type_id = H5Tget_native_type(atype, H5T_DIR_DEFAULT)) < 0)
        H5TOOLS_GOTO_ERROR(dimension_break, "H5Tget_native_type failed");

    ctx->indent_level++;
    ctx->need_prefix = true;

    /* Render the datatype element begin */
    h5tools_str_reset(buffer);
    h5tools_str_append(buffer, "%s %s ", h5tools_dump_header_format->datatypebegin,
                       h5tools_dump_header_format->datatypeblockbegin);

    ctx->need_prefix = true;
    ctx->indent_level++;
    h5tools_print_datatype(stream, buffer, info, ctx, atype, true);
    ctx->indent_level--;

    if (strlen(h5tools_dump_header_format->datatypeblockend)) {
        h5tools_str_append(buffer, "%s", h5tools_dump_header_format->datatypeblockend);
        if (strlen(h5tools_dump_header_format->datatypeend))
            h5tools_str_append(buffer, " ");
    }
    if (strlen(h5tools_dump_header_format->datatypeend))
        h5tools_str_append(buffer, "%s", h5tools_dump_header_format->datatypeend);

    dimension_break =
        h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter);
    /* Render the datatype element end */

    ctx->need_prefix = true;

    /* Render the dataspace element begin */
    h5tools_str_reset(buffer);
    h5tools_str_append(buffer, "%s ", h5tools_dump_header_format->dataspacebegin);

    h5tools_print_dataspace(buffer, region_space);

    if (strlen(h5tools_dump_header_format->dataspaceblockend)) {
        h5tools_str_append(buffer, "%s", h5tools_dump_header_format->dataspaceblockend);
        if (strlen(h5tools_dump_header_format->dataspaceend))
            h5tools_str_append(buffer, " ");
    }
    if (strlen(h5tools_dump_header_format->dataspaceend))
        h5tools_str_append(buffer, "%s", h5tools_dump_header_format->dataspaceblockend);

    dimension_break =
        h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter);
    /* Render the dataspace element end */

    if (region_output) {
        ctx->need_prefix = true;

        h5tools_dump_data(stream, &outputformat, ctx, region_id, false);
    }

done:
    if (H5Tclose(type_id) < 0)
        H5TOOLS_ERROR(dimension_break, "H5Tclose failed");

    if (H5Tclose(atype) < 0)
        H5TOOLS_ERROR(dimension_break, "H5Tclose failed");

    if (H5Sclose(region_space) < 0)
        H5TOOLS_ERROR(dimension_break, "H5Sclose failed");

    ctx->indent_level--;
    ctx->need_prefix = true;

    /* Render the region } element begin */
    h5tools_str_reset(buffer);
    h5tools_str_append(buffer, "}");
    dimension_break =
        h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter);
    /* Render the region } element end */

    H5_LEAVE(dimension_break);

    CATCH

    H5TOOLS_ENDDEBUG(" ");
    return ret_value;
}

/*-------------------------------------------------------------------------
 * Audience:    Public
 * Chapter:     H5Tools Library
 * Purpose: Print the data values from a dataset referenced by region blocks.
 *
 * Description:
 *      This is a special case subfunction to print the data in a region reference of type blocks.
 *
 * Return:
 *      The function returns FAIL if there was an error, otherwise SUCCEED
 *
 * Parameters Description:
 *      h5tools_str_t *buffer is the string into which to render
 *      size_t ncols
 *      int ndims is the number of dimensions of the region element
 *      hssize_t nblocks is the number of blocks in the region
 *-------------------------------------------------------------------------
 */
static int
h5tools_print_region_data_blocks(hid_t region_id, FILE *stream, const h5tool_format_t *info,
                                 h5tools_context_t *cur_ctx,
                                 h5tools_str_t     *buffer, /* string into which to render */
                                 size_t ncols, unsigned ndims, hid_t type_id, hsize_t nblocks,
                                 hsize_t *ptdata)
{
    bool              dimension_break = true;
    hsize_t          *dims1           = NULL;
    hsize_t          *start           = NULL;
    hsize_t          *count           = NULL;
    hsize_t           blkndx;
    hsize_t           total_size[H5S_MAX_RANK];
    hsize_t           elmtno; /* element index  */
    hsize_t           curr_pos = 0;
    unsigned int      region_flags; /* buffer extent flags */
    hsize_t           numelem;
    hsize_t           numindex;
    unsigned          indx;
    unsigned          jndx;
    bool              past_catch = false;
    size_t            type_size;
    hid_t             mem_space = H5I_INVALID_HID;
    hid_t             sid1      = H5I_INVALID_HID;
    h5tools_context_t ctx;
    void             *region_buf = NULL;
    int               ret_value  = 0;

    assert(info);
    assert(cur_ctx);
    assert(buffer);
    assert(ptdata);

    memset(&ctx, 0, sizeof(ctx));

    H5TOOLS_START_DEBUG(" ");

    if ((type_size = H5Tget_size(type_id)) == 0)
        H5TOOLS_THROW(FAIL, "H5Tget_size failed");

    /* Get the dataspace of the dataset */
    if ((sid1 = H5Dget_space(region_id)) < 0)
        H5TOOLS_GOTO_ERROR(FAIL, "H5Dget_space failed");

    /* Allocate space for the dimension array */
    if ((dims1 = (hsize_t *)malloc((size_t)(sizeof(hsize_t) * ndims))) == NULL)
        H5TOOLS_GOTO_ERROR(FAIL, "Could not allocate buffer for dims");

    /* find the dimensions of each data space from the block coordinates */
    numelem = 1;
    for (jndx = 0; jndx < ndims; jndx++) {
        dims1[jndx] = ptdata[jndx + ndims] - ptdata[jndx] + 1;
        numelem     = dims1[jndx] * numelem;
    }

    /* Create dataspace for reading buffer */
    if ((mem_space = H5Screate_simple((int)ndims, dims1, NULL)) < 0)
        H5TOOLS_GOTO_ERROR(FAIL, "H5Screate_simple failed");

    if ((region_buf = malloc(type_size * (size_t)numelem)) == NULL)
        H5TOOLS_GOTO_ERROR(FAIL, "Could not allocate region buffer");

    /* Select (x , x , ..., x ) x (y , y , ..., y ) hyperslab for reading memory dataset */
    /*          1   2        n      1   2        n                                       */
    if ((start = (hsize_t *)malloc(sizeof(hsize_t) * ndims)) == NULL)
        H5TOOLS_GOTO_ERROR(FAIL, "Could not allocate buffer for start");

    if ((count = (hsize_t *)malloc(sizeof(hsize_t) * ndims)) == NULL)
        H5TOOLS_GOTO_ERROR(FAIL, "Could not allocate buffer for count");

    curr_pos           = 0;
    ctx.indent_level   = cur_ctx->indent_level;
    ctx.cur_column     = cur_ctx->cur_column;
    ctx.prev_multiline = cur_ctx->prev_multiline;
    ctx.ndims          = ndims;
    for (blkndx = 0; blkndx < nblocks; blkndx++) {
        ctx.need_prefix = true;
        ctx.cur_elmt    = 0;
        for (indx = 0; indx < ndims; indx++) {
            start[indx] = ptdata[indx + blkndx * ndims * 2];
            count[indx] = dims1[indx];
        }

        if (H5Sselect_hyperslab(sid1, H5S_SELECT_SET, start, NULL, count, NULL) >= 0) {
            if (H5Dread(region_id, type_id, mem_space, sid1, H5P_DEFAULT, region_buf) >= 0) {
                ctx.indent_level++;
                if (H5Sget_simple_extent_dims(mem_space, total_size, NULL) >= 0) {
                    /* assume entire data space to be printed */
                    init_acc_pos(ctx.ndims, total_size, ctx.acc, ctx.pos, ctx.p_min_idx);

                    /* reset data space to be printed */
                    for (indx = 0; indx < (unsigned)ctx.ndims; indx++)
                        ctx.p_min_idx[indx] = start[indx];

                    /* print the data */
                    region_flags = START_OF_DATA;
                    if (blkndx == nblocks - 1)
                        region_flags |= END_OF_DATA;

                    for (indx = 0; indx < (unsigned)ctx.ndims; indx++)
                        ctx.p_max_idx[indx] = dims1[indx];

                    curr_pos          = 0;
                    ctx.sm_pos        = blkndx * 2 * ndims;
                    ctx.size_last_dim = dims1[ndims - 1];

                    h5tools_region_simple_prefix(stream, info, &ctx, curr_pos, ptdata, 0);

                    H5TOOLS_DEBUG("data render start:%ld", numelem);
                    elmtno = 0;
                    for (numindex = 0; numindex < numelem; numindex++, elmtno++, ctx.cur_elmt++) {
                        /* Render the region data element begin */
                        h5tools_str_reset(buffer);

                        h5tools_str_append(buffer, "%s", numindex ? OPTIONAL_LINE_BREAK "" : "");
                        h5tools_str_sprint(buffer, info, region_id, type_id,
                                           ((char *)region_buf + numindex * type_size), &ctx);

                        if (numindex + 1 < numelem || (region_flags & END_OF_DATA) == 0)
                            h5tools_str_append(buffer, "%s", OPT(info->elmt_suf1, ","));

                        dimension_break = h5tools_render_region_element(stream, info, &ctx, buffer, &curr_pos,
                                                                        ncols, ptdata, numindex, elmtno);
                        /* Render the region data element end */

                        if (false == dimension_break)
                            elmtno = 0;
                    } /* end for (numindex = 0; numindex < numelem; numindex++, elmtno++, ctx.cur_elmt++) */
                }
                else {
                    H5TOOLS_ERROR(FAIL, "H5Sget_simple_extent_dims failed");
                }
                ctx.indent_level--;
            }
            else {
                H5TOOLS_ERROR(FAIL, "H5Dread failed");
            }
        }
        else {
            H5TOOLS_ERROR(FAIL, "H5Sselect_hyperslab failed");
        }

    } /* end for (blkndx = 0; blkndx < nblocks; blkndx++) */

done:
    free(start);
    free(count);
    free(region_buf);
    free(dims1);

    if (H5Sclose(mem_space) < 0)
        H5TOOLS_ERROR(FAIL, "H5Sclose failed");
    if (H5Sclose(sid1) < 0)
        H5TOOLS_ERROR(FAIL, "H5Sclose failed");
    CATCH
    H5TOOLS_ENDDEBUG(" ");

    return ret_value;
}

/*-------------------------------------------------------------------------
 * Audience:    Public
 * Chapter:     H5Tools Library
 * Purpose: Print some values from a dataset referenced by region blocks.
 *
 * Description:
 *      This is a special case subfunction to dump a region reference using blocks.
 *
 * Return:
 *      The function returns False if the last dimension has been reached, otherwise True
 *
 * In/Out:
 *      h5tools_context_t *ctx
 *      hsize_t *curr_pos
 *
 * Parameters Description:
 *      h5tools_str_t *buffer is the string into which to render
 *      hsize_t curr_pos is the total data element position
 *      size_t ncols
 *      hsize_t region_elmt_counter is the region element loop counter
 *      hsize_t elmt_count is the data element loop counter
 *-------------------------------------------------------------------------
 */
bool
h5tools_dump_region_data_blocks(hid_t region_space, hid_t region_id, FILE *stream,
                                const h5tool_format_t *info, h5tools_context_t *ctx, /* in,out */
                                h5tools_str_t *buffer,                     /* string into which to render */
                                hsize_t       *curr_pos,                   /* total data element position */
                                size_t ncols, hsize_t region_elmt_counter, /* element counter */
                                hsize_t elmt_counter)
{
    bool            dimension_break = true;
    hssize_t        snblocks;
    hsize_t         nblocks;
    hsize_t         alloc_size;
    hsize_t        *ptdata = NULL;
    int             sndims;
    unsigned        ndims;
    hsize_t         indx;
    hid_t           dtype   = H5I_INVALID_HID;
    hid_t           type_id = H5I_INVALID_HID;
    h5tool_format_t outputformat; /* Use to disable prefix for DATA attribute display */
    bool            past_catch = false;
    bool            ret_value  = true;

    assert(info);
    assert(ctx);
    assert(buffer);

    H5TOOLS_START_DEBUG(" ");
    outputformat           = *info;
    outputformat.idx_fmt   = "";
    outputformat.idx_n_fmt = "";
    outputformat.idx_sep   = "";
    outputformat.line_pre  = "";

    if ((snblocks = H5Sget_select_hyper_nblocks(region_space)) <= 0)
        H5TOOLS_THROW(dimension_break, "H5Sget_select_hyper_nblocks failed");
    nblocks = (hsize_t)snblocks;

    /* Print block information */
    if ((sndims = H5Sget_simple_extent_ndims(region_space)) < 0)
        H5TOOLS_THROW(dimension_break, "H5Sget_simple_extent_ndims failed");
    ndims = (unsigned)sndims;

    H5TOOLS_DEBUG("enter ndims=%d", ndims);

    /* Render the region { element begin */
    h5tools_str_reset(buffer);

    h5tools_str_append(buffer, " {");
    dimension_break = h5tools_render_element(stream, &outputformat, ctx, buffer, curr_pos, ncols,
                                             region_elmt_counter, elmt_counter);
    /* Render the region { element end */

    ctx->indent_level++;
    ctx->need_prefix = true;

    /* Render the region datatype info and indices element begin */
    h5tools_str_reset(buffer);
    h5tools_str_append(buffer, "REGION_TYPE BLOCK  ");

    alloc_size = nblocks * ndims * 2 * sizeof(ptdata[0]);
    assert(alloc_size == (hsize_t)((size_t)alloc_size)); /*check for overflow*/
    if ((ptdata = (hsize_t *)malloc((size_t)alloc_size)) == NULL)
        H5TOOLS_GOTO_ERROR(dimension_break, "Could not allocate buffer for ptdata");

    if (H5Sget_select_hyper_blocklist(region_space, (hsize_t)0, nblocks, ptdata) < 0)
        H5TOOLS_GOTO_ERROR(dimension_break, "H5Rget_select_hyper_blocklist failed");

    for (indx = 0; indx < nblocks; indx++) {
        unsigned loop_indx;

        H5_GCC_CLANG_DIAG_OFF("format-nonliteral")
        h5tools_str_append(buffer, outputformat.dset_blockformat_pre, indx ? "," OPTIONAL_LINE_BREAK " " : "",
                           (unsigned long)indx);
        H5_GCC_CLANG_DIAG_ON("format-nonliteral")

        /* Start coordinates and opposite corner */
        for (loop_indx = 0; loop_indx < ndims; loop_indx++)
            h5tools_str_append(buffer, "%s%" PRIuHSIZE, loop_indx ? "," : "(",
                               ptdata[indx * 2 * ndims + loop_indx]);

        for (loop_indx = 0; loop_indx < ndims; loop_indx++)
            h5tools_str_append(buffer, "%s%" PRIuHSIZE, loop_indx ? "," : ")-(",
                               ptdata[indx * 2 * ndims + loop_indx + ndims]);

        h5tools_str_append(buffer, ")");
    } /* end for (indx = 0; indx < nblocks; indx++) */

    dimension_break =
        h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter);
    /* Render the region datatype info and indices element end */

    ctx->need_prefix = true;

    if ((dtype = H5Dget_type(region_id)) < 0)
        H5TOOLS_GOTO_ERROR(dimension_break, "H5Dget_type failed");
    if ((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) < 0)
        H5TOOLS_GOTO_ERROR(dimension_break, "H5Tget_native_type failed");

    /* Render the datatype element begin */
    h5tools_str_reset(buffer);
    h5tools_str_append(buffer, "%s %s ", h5tools_dump_header_format->datatypebegin,
                       h5tools_dump_header_format->datatypeblockbegin);

    ctx->indent_level++;
    h5tools_print_datatype(stream, buffer, info, ctx, dtype, true);
    ctx->indent_level--;

    if (strlen(h5tools_dump_header_format->datatypeblockend)) {
        h5tools_str_append(buffer, "%s", h5tools_dump_header_format->datatypeblockend);
        if (strlen(h5tools_dump_header_format->datatypeend))
            h5tools_str_append(buffer, " ");
    }
    if (strlen(h5tools_dump_header_format->datatypeend))
        h5tools_str_append(buffer, "%s", h5tools_dump_header_format->datatypeend);

    dimension_break =
        h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter);
    /* Render the datatype element end */

    ctx->need_prefix = true;

    /* Render the dataspace element begin */
    h5tools_str_reset(buffer);
    h5tools_str_append(buffer, "%s ", h5tools_dump_header_format->dataspacebegin);

    h5tools_print_dataspace(buffer, region_space);

    if (strlen(h5tools_dump_header_format->dataspaceblockend)) {
        h5tools_str_append(buffer, "%s", h5tools_dump_header_format->dataspaceblockend);
        if (strlen(h5tools_dump_header_format->dataspaceend))
            h5tools_str_append(buffer, " ");
    }
    if (strlen(h5tools_dump_header_format->dataspaceend))
        h5tools_str_append(buffer, "%s", h5tools_dump_header_format->dataspaceblockend);

    dimension_break =
        h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter);
    /* Render the dataspace element end */

    if (region_output) {
        ctx->need_prefix = true;

        /* Render the databegin element begin */
        h5tools_str_reset(buffer);
        h5tools_str_append(buffer, "%s %s", h5tools_dump_header_format->databegin,
                           h5tools_dump_header_format->datablockbegin);
        dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols,
                                                 region_elmt_counter, elmt_counter);
        /* Render the databegin element end */

        ctx->need_prefix = true;

        h5tools_print_region_data_blocks(region_id, rawdatastream, info, ctx, buffer, ncols, ndims, type_id,
                                         nblocks, ptdata);
    }

done:
    free(ptdata);

    if (type_id > 0 && H5Tclose(type_id) < 0)
        H5TOOLS_ERROR(dimension_break, "H5Tclose failed");

    if (dtype > 0 && H5Tclose(dtype) < 0)
        H5TOOLS_ERROR(dimension_break, "H5Tclose failed");

    if (region_output) {
        ctx->need_prefix = true;

        /* Render the dataend element begin */
        h5tools_str_reset(buffer);
        if (strlen(h5tools_dump_header_format->datablockend)) {
            h5tools_str_append(buffer, "%s", h5tools_dump_header_format->datablockend);
            if (strlen(h5tools_dump_header_format->dataend))
                h5tools_str_append(buffer, " ");
        }

        if (strlen(h5tools_dump_header_format->dataend))
            h5tools_str_append(buffer, "%s", h5tools_dump_header_format->dataend);
        dimension_break = h5tools_render_element(stream, &outputformat, ctx, buffer, curr_pos, ncols,
                                                 region_elmt_counter, elmt_counter);
        /* Render the dataend element end */
    }

    ctx->indent_level--;
    ctx->need_prefix = true;

    /* Render the region } element begin */
    h5tools_str_reset(buffer);
    h5tools_str_append(buffer, "}");
    dimension_break =
        h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter);
    /* Render the region } element end */

    H5_LEAVE(dimension_break);

    CATCH

    H5TOOLS_ENDDEBUG(" ");

    return ret_value;
}

/*-------------------------------------------------------------------------
 * Audience:    Public
 * Chapter:     H5Tools Library
 * Purpose: Print the data values from a dataset referenced by region points.
 *
 * Description:
 *      This is a special case subfunction to print the data in a region reference of type points.
 *
 * Return:
 *      The function returns FAIL on error, otherwise SUCCEED
 *
 * Parameters Description:
 *      h5tools_str_t *buffer is the string into which to render
 *      size_t ncols
 *      int ndims is the number of dimensions of the region element
 *      hssize_t npoints is the number of points in the region
 *-------------------------------------------------------------------------
 */
static int
h5tools_print_region_data_points(hid_t region_space, hid_t region_id, FILE *stream,
                                 const h5tool_format_t *info, h5tools_context_t *cur_ctx,
                                 h5tools_str_t *buffer, size_t ncols, unsigned ndims, hid_t type_id,
                                 hsize_t npoints, hsize_t *ptdata)
{
    bool              dimension_break = true;
    hsize_t          *dims1           = NULL;
    hsize_t           elmtno; /* element index  */
    hsize_t           curr_pos = 0;
    hsize_t           total_size[H5S_MAX_RANK];
    hsize_t           jndx;
    unsigned          indx;
    size_t            type_size;
    unsigned int      region_flags; /* buffer extent flags */
    hid_t             mem_space  = H5I_INVALID_HID;
    void             *region_buf = NULL;
    h5tools_context_t ctx;
    bool              past_catch = false;
    int               ret_value  = 0;

    assert(info);
    assert(cur_ctx);
    assert(buffer);
    assert(ptdata);
    assert(ndims > 0);

    H5TOOLS_START_DEBUG(" ");

    memset(&ctx, 0, sizeof(ctx));
    /* Allocate space for the dimension array */
    if ((dims1 = (hsize_t *)malloc(sizeof(hsize_t) * ndims)) == NULL)
        H5TOOLS_THROW((-1), "Could not allocate buffer for dims");

    dims1[0] = npoints;

    /* Create dataspace for reading buffer */
    if ((mem_space = H5Screate_simple(1, dims1, NULL)) < 0)
        H5TOOLS_THROW((-1), "H5Screate_simple failed");

    if ((type_size = H5Tget_size(type_id)) == 0)
        H5TOOLS_THROW((-1), "H5Tget_size failed");

    if ((region_buf = malloc(type_size * (size_t)npoints)) == NULL)
        H5TOOLS_THROW((-1), "Could not allocate buffer for region");

    curr_pos           = 0;
    ctx.indent_level   = cur_ctx->indent_level;
    ctx.cur_column     = cur_ctx->cur_column;
    ctx.prev_multiline = cur_ctx->prev_multiline;
    ctx.ndims          = ndims;

    if (H5Dread(region_id, type_id, mem_space, region_space, H5P_DEFAULT, region_buf) < 0)
        H5TOOLS_GOTO_ERROR((-1), "H5Dread failed");

    H5TOOLS_DEBUG("data render start:%ld", npoints);
    elmtno = 0;
    for (jndx = 0; jndx < npoints; jndx++, elmtno++) {
        ctx.need_prefix = true;
        ctx.cur_elmt    = 0; /* points are always 0 */
        ctx.indent_level++;

        if (H5Sget_simple_extent_dims(mem_space, total_size, NULL) >= 0) {
            /* assume entire data space to be printed */
            init_acc_pos(ctx.ndims, total_size, ctx.acc, ctx.pos, ctx.p_min_idx);

            /* print the data */
            region_flags = START_OF_DATA;
            if (jndx == npoints - 1)
                region_flags |= END_OF_DATA;

            for (indx = 0; indx < ctx.ndims; indx++)
                ctx.p_max_idx[indx] = cur_ctx->p_max_idx[indx];

            ctx.sm_pos = jndx * ndims;
            if (ctx.ndims > 0)
                ctx.size_last_dim = ctx.p_max_idx[ctx.ndims - 1];
            else
                ctx.size_last_dim = 0;

            curr_pos = 0; /* points requires constant 0 */
            h5tools_region_simple_prefix(stream, info, &ctx, curr_pos, ptdata, 0);

            /* Render the point element begin */
            h5tools_str_reset(buffer);

            h5tools_str_append(buffer, "%s", jndx ? OPTIONAL_LINE_BREAK "" : "");
            h5tools_str_sprint(buffer, info, region_id, type_id, ((char *)region_buf + jndx * type_size),
                               &ctx);

            if (jndx + 1 < npoints || (region_flags & END_OF_DATA) == 0)
                h5tools_str_append(buffer, "%s", OPT(info->elmt_suf1, ","));

            dimension_break = h5tools_render_region_element(stream, info, &ctx, buffer, &curr_pos, ncols,
                                                            ptdata, (hsize_t)0, elmtno);
            /* Render the point element end */
            if (false == dimension_break)
                elmtno = 0;
        }
        else {
            H5TOOLS_ERROR((-1), "H5Sget_simple_extent_dims failed");
        }
        ctx.indent_level--;
    } /* end for (jndx = 0; jndx < npoints; jndx++, elmtno++) */

done:
    free(region_buf);
    CATCH
    free(dims1);

    if (H5Sclose(mem_space) < 0)
        H5TOOLS_ERROR((-1), "H5Sclose failed");

    H5TOOLS_ENDDEBUG(" ");

    return ret_value;
}

/*-------------------------------------------------------------------------
 * Audience:    Public
 * Chapter:     H5Tools Library
 * Purpose: Print some values from a dataset referenced by region points.
 *
 * Description:
 *      This is a special case subfunction to dump a region reference using points.
 *
 * Return:
 *      The function returns False if the last dimension has been reached, otherwise True
 *
 * In/Out:
 *      h5tools_context_t *ctx
 *      hsize_t *curr_pos
 *
 * Parameters Description:
 *      h5tools_str_t *buffer is the string into which to render
 *      hsize_t curr_pos is the total data element position
 *      size_t ncols
 *      hsize_t region_elmt_counter is the region element loop counter
 *      hsize_t elmt_count is the data element loop counter
 *-------------------------------------------------------------------------
 */
bool
h5tools_dump_region_data_points(hid_t region_space, hid_t region_id, FILE *stream,
                                const h5tool_format_t *info, h5tools_context_t *ctx, h5tools_str_t *buffer,
                                hsize_t *curr_pos, size_t ncols, hsize_t region_elmt_counter,
                                hsize_t elmt_counter)
{
    bool            dimension_break = true;
    hssize_t        snpoints;
    hsize_t         npoints;
    hsize_t         alloc_size;
    hsize_t        *ptdata;
    int             sndims;
    unsigned        ndims;
    hsize_t         indx;
    hid_t           dtype   = H5I_INVALID_HID;
    hid_t           type_id = H5I_INVALID_HID;
    h5tool_format_t outputformat; /* Use to disable prefix for DATA attribute display */
    bool            past_catch = false;
    bool            ret_value  = true;

    assert(info);
    assert(ctx);
    assert(buffer);

    H5TOOLS_START_DEBUG(" ");
    outputformat           = *info;
    outputformat.idx_fmt   = "";
    outputformat.idx_n_fmt = "";
    outputformat.idx_sep   = "";
    outputformat.line_pre  = "";

    if ((snpoints = H5Sget_select_elem_npoints(region_space)) <= 0)
        H5TOOLS_THROW(dimension_break, "H5Sget_select_elem_npoints failed");
    npoints = (hsize_t)snpoints;

    /* Allocate space for the dimension array */
    if ((sndims = H5Sget_simple_extent_ndims(region_space)) < 0)
        H5TOOLS_THROW(dimension_break, "H5Sget_simple_extent_ndims failed");
    ndims = (unsigned)sndims;

    H5TOOLS_DEBUG("enter ndims=%d", ndims);

    /* Render the region { element begin */
    h5tools_str_reset(buffer);

    h5tools_str_append(buffer, "{");
    dimension_break = h5tools_render_element(stream, &outputformat, ctx, buffer, curr_pos, ncols,
                                             region_elmt_counter, elmt_counter);
    /* Render the region { element end */

    ctx->indent_level++;
    ctx->need_prefix = true;

    /* Render the region datatype info and indices element begin */
    h5tools_str_reset(buffer);
    h5tools_str_append(buffer, "REGION_TYPE POINT  ");

    alloc_size = npoints * ndims * sizeof(ptdata[0]);
    assert(alloc_size == (hsize_t)((size_t)alloc_size)); /*check for overflow*/
    if (NULL == (ptdata = (hsize_t *)malloc((size_t)alloc_size)))
        H5TOOLS_GOTO_ERROR(dimension_break, "Could not allocate buffer for ptdata");

    if (H5Sget_select_elem_pointlist(region_space, (hsize_t)0, npoints, ptdata) < 0)
        H5TOOLS_GOTO_ERROR(dimension_break, "H5Sget_select_elem_pointlist failed");

    for (indx = 0; indx < npoints; indx++) {
        unsigned loop_indx;

        H5_GCC_CLANG_DIAG_OFF("format-nonliteral")
        h5tools_str_append(buffer, outputformat.dset_ptformat_pre, indx ? "," OPTIONAL_LINE_BREAK " " : "",
                           (unsigned long)indx);
        H5_GCC_CLANG_DIAG_ON("format-nonliteral")

        for (loop_indx = 0; loop_indx < ndims; loop_indx++)
            h5tools_str_append(buffer, "%s%" PRIuHSIZE, loop_indx ? "," : "(",
                               ptdata[indx * ndims + loop_indx]);

        h5tools_str_append(buffer, ")");
    } /* end for (indx = 0; indx < npoints; indx++) */

    dimension_break =
        h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter);
    /* Render the region datatype info and indices element end */

    ctx->need_prefix = true;

    if ((dtype = H5Dget_type(region_id)) < 0)
        H5TOOLS_GOTO_ERROR(dimension_break, "H5Dget_type failed");
    if ((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) < 0)
        H5TOOLS_GOTO_ERROR(dimension_break, "H5Tget_native_type failed");

    /* Render the datatype element begin */
    h5tools_str_reset(buffer);
    h5tools_str_append(buffer, "%s %s ", h5tools_dump_header_format->datatypebegin,
                       h5tools_dump_header_format->datatypeblockbegin);

    ctx->indent_level++;
    h5tools_print_datatype(stream, buffer, info, ctx, dtype, true);
    ctx->indent_level--;

    if (strlen(h5tools_dump_header_format->datatypeblockend)) {
        h5tools_str_append(buffer, "%s", h5tools_dump_header_format->datatypeblockend);
        if (strlen(h5tools_dump_header_format->datatypeend))
            h5tools_str_append(buffer, " ");
    }
    if (strlen(h5tools_dump_header_format->datatypeend))
        h5tools_str_append(buffer, "%s", h5tools_dump_header_format->datatypeend);

    dimension_break =
        h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter);
    /* Render the datatype element end */

    ctx->need_prefix = true;

    /* Render the dataspace element begin */
    h5tools_str_reset(buffer);
    h5tools_str_append(buffer, "%s ", h5tools_dump_header_format->dataspacebegin);

    h5tools_print_dataspace(buffer, region_space);

    if (strlen(h5tools_dump_header_format->dataspaceblockend)) {
        h5tools_str_append(buffer, "%s", h5tools_dump_header_format->dataspaceblockend);
        if (strlen(h5tools_dump_header_format->dataspaceend))
            h5tools_str_append(buffer, " ");
    }
    if (strlen(h5tools_dump_header_format->dataspaceend))
        h5tools_str_append(buffer, "%s", h5tools_dump_header_format->dataspaceblockend);

    dimension_break =
        h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter);
    /* Render the dataspace element end */

    if (region_output) {
        ctx->need_prefix = true;

        /* Render the databegin element begin */
        h5tools_str_reset(buffer);

        h5tools_str_append(buffer, "%s %s", h5tools_dump_header_format->databegin,
                           h5tools_dump_header_format->datablockbegin);

        dimension_break = h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols,
                                                 region_elmt_counter, elmt_counter);

        ctx->need_prefix = true;

        h5tools_print_region_data_points(region_space, region_id, rawdatastream, info, ctx, buffer, ncols,
                                         ndims, type_id, npoints, ptdata);
    }

done:
    free(ptdata);

    if (type_id > 0 && H5Tclose(type_id) < 0)
        H5TOOLS_ERROR(dimension_break, "H5Tclose failed");

    if (dtype > 0 && H5Tclose(dtype) < 0)
        H5TOOLS_ERROR(dimension_break, "H5Tclose failed");

    if (region_output) {
        ctx->need_prefix = true;

        /* Render the dataend element begin */
        h5tools_str_reset(buffer);
        if (strlen(h5tools_dump_header_format->datablockend)) {
            h5tools_str_append(buffer, "%s", h5tools_dump_header_format->datablockend);
            if (strlen(h5tools_dump_header_format->dataend))
                h5tools_str_append(buffer, " ");
        }

        if (strlen(h5tools_dump_header_format->dataend))
            h5tools_str_append(buffer, "%s", h5tools_dump_header_format->dataend);
        dimension_break = h5tools_render_element(stream, &outputformat, ctx, buffer, curr_pos, ncols,
                                                 region_elmt_counter, elmt_counter);
        /* Render the dataend element end*/
    }

    ctx->indent_level--;
    ctx->need_prefix = true;

    /* Render the region } element begin */
    h5tools_str_reset(buffer);
    h5tools_str_append(buffer, "}");
    dimension_break =
        h5tools_render_element(stream, info, ctx, buffer, curr_pos, ncols, region_elmt_counter, elmt_counter);
    /* Render the region } element end */

    H5_LEAVE(dimension_break);
    CATCH

    H5TOOLS_ENDDEBUG(" ");

    return ret_value;
}

/*-------------------------------------------------------------------------
 * Audience:    Public
 * Chapter:     H5Tools Library
 * Purpose:     print out the data for a subset of a dataset.
 * Description:
 *
 *  Select a hyperslab from the dataset DSET using the parameters
 *   specified in SSET. Dump this out to STREAM.
 *
 *  Hyperslabs select "count" blocks of size "block", spaced "stride" elements
 *   from each other, starting at coordinate "start".
 *
 * Return:
 *      On success, return SUCCEED. Otherwise, the function returns FAIL.
 *
 * Algorithm
 *
 * The parameters from SSET are translated into temporary
 * variables so that 1 row is printed at a time (getting the coordinate indices
 * at each row).
 * We define the stride, count and block to be 1 in the row dimension to achieve
 * this and advance until all points are printed.
 *
 * The element position is obtained from the matrix according to:
 *       Given an index I(z,y,x) its position from the beginning of an array
 *       of sizes A(size_z, size_y,size_x) is given by
 *       Position of I(z,y,x) = index_z * size_y * size_x
 *                             + index_y * size_x
 *                             + index_x
 *
 *-------------------------------------------------------------------------
 */
static herr_t
h5tools_print_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hid_t dset,
                            hid_t p_type, hid_t f_space, hsize_t hyperslab_count,
                            hsize_t       *temp_start,  /* start inside offset count loop */
                            hsize_t       *temp_count,  /* count inside offset count loop  */
                            hsize_t       *temp_block,  /* block size used in loop  */
                            hsize_t       *temp_stride, /* stride size used in loop  */
                            const hsize_t *total_size,  /* total size of dataset */
                            unsigned int   row_dim)       /* index of row_counter dimension */
{
    size_t         i;                          /* counters  */
    size_t         j;                          /* counters  */
    hsize_t        zero[1] = {0};              /* vector of zeros */
    unsigned int   flags;                      /* buffer extent flags */
    hsize_t        low[H5S_MAX_RANK];          /* low bound of hyperslab */
    hsize_t        high[H5S_MAX_RANK];         /* higher bound of hyperslab */
    size_t         p_type_nbytes;              /* size of memory type */
    hsize_t        sm_size[H5S_MAX_RANK];      /* stripmine size */
    hsize_t        sm_nbytes;                  /* bytes per stripmine */
    hssize_t       ssm_nelmts;                 /* elements per stripmine*/
    hsize_t        sm_nelmts;                  /* elements per stripmine*/
    unsigned char *sm_buf   = NULL;            /* buffer for raw data */
    hid_t          sm_space = H5I_INVALID_HID; /* stripmine data space */
    hsize_t        size_row_block;             /* size for blocks along rows */
    hsize_t        row_counter = 0;
    bool           past_catch  = false;
    /* VL data special information */
    unsigned int vl_data   = 0; /* contains VL datatypes */
    herr_t       ret_value = SUCCEED;

    H5TOOLS_START_DEBUG(" ");
    if ((size_t)ctx->ndims > NELMTS(sm_size))
        H5TOOLS_THROW(FAIL, "ndims and sm_size comparison failed");

    size_row_block = ctx->sset->block.data[row_dim];

    /* Check if we have VL data in the dataset's datatype */
    if (h5tools_detect_vlen(p_type) == true)
        vl_data = true;

    /* display loop */
    for (; hyperslab_count > 0; temp_start[row_dim] += temp_stride[row_dim], hyperslab_count--) {
        /* jump rows if size of block exceeded
         cases where block > 1 only and stride > block */
        if (size_row_block > 1 && row_counter == size_row_block &&
            ctx->sset->stride.data[row_dim] > ctx->sset->block.data[row_dim]) {

            hsize_t increase_rows = ctx->sset->stride.data[row_dim] - ctx->sset->block.data[row_dim];
            temp_start[row_dim] += increase_rows;
            row_counter = 0;
        }

        row_counter++;

        /* calculate the potential number of elements we're going to print */
        if (H5Sselect_hyperslab(f_space, H5S_SELECT_SET, temp_start, temp_stride, temp_count, temp_block) < 0)
            H5TOOLS_THROW(FAIL, "H5Sselect_hyperslab failed");

        if ((ssm_nelmts = H5Sget_select_npoints(f_space)) < 0)
            H5TOOLS_THROW(FAIL, "H5Sget_select_npoints failed");
        sm_nelmts = (hsize_t)ssm_nelmts;

        if (sm_nelmts > 0) {
            /*
             * determine the strip mine size and allocate a buffer. the strip mine is
             * a hyperslab whose size is manageable.
             */
            if ((sm_nbytes = p_type_nbytes = H5Tget_size(p_type)) == 0)
                H5TOOLS_THROW(FAIL, "H5Tget_size failed");

            if (ctx->ndims > 0)
                for (i = ctx->ndims; i > 0; --i) {
                    hsize_t size = H5TOOLS_BUFSIZE / sm_nbytes;
                    if (size == 0) /* datum size > H5TOOLS_BUFSIZE */
                        size = 1;
                    sm_size[i - 1] = MIN(total_size[i - 1], size);
                    sm_nbytes *= sm_size[i - 1];
                    assert(sm_nbytes > 0);
                }

            assert(sm_nbytes == (hsize_t)((size_t)sm_nbytes)); /*check for overflow*/
            if (NULL == (sm_buf = (unsigned char *)malloc((size_t)sm_nelmts * p_type_nbytes)))
                H5TOOLS_THROW(FAIL, "Could not allocate buffer for strip-mine");

            if ((sm_space = H5Screate_simple(1, &sm_nelmts, NULL)) < 0)
                H5TOOLS_THROW(FAIL, "H5Screate_simple failed");

            if (H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, zero, NULL, &sm_nelmts, NULL) < 0)
                H5TOOLS_THROW(FAIL, "H5Sselect_hyperslab failed");

            /* read the data */
            if (H5Dread(dset, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf) < 0)
                H5TOOLS_THROW(FAIL, "H5Dread failed");

            /* print the data */
            flags = START_OF_DATA;

            if (hyperslab_count == 1)
                flags |= END_OF_DATA;

            for (i = 0; i < ctx->ndims; i++)
                ctx->p_max_idx[i] = ctx->p_min_idx[i] + MIN(total_size[i], sm_size[i]);

            /* print array indices. get the lower bound of the hyperslab and calculate
               the element position at the start of hyperslab */
            if (H5Sget_select_bounds(f_space, low, high) < 0)
                H5TOOLS_THROW(FAIL, "H5Sget_select_bounds failed");

            /* initialize the current stripmine position; this is necessary to print the array indices */
            ctx->sm_pos = 0;
            for (i = 0; i < (size_t)ctx->ndims - 1; i++) {
                hsize_t offset = 1; /* accumulation of the previous dimensions */
                for (j = i + 1; j < (size_t)ctx->ndims; j++)
                    offset *= total_size[j];
                ctx->sm_pos += low[i] * offset;
            }
            ctx->sm_pos += low[ctx->ndims - 1];

            ctx->need_prefix = true;

            if (h5tools_dump_simple_data(stream, info, ctx, dset, flags, sm_nelmts, p_type, sm_buf) < 0)
                H5TOOLS_THROW(FAIL, "h5tools_dump_simple_data failed");

            /* Reclaim any VL memory, if necessary */
            if (vl_data)
                H5Treclaim(p_type, sm_space, H5P_DEFAULT, sm_buf);

            if (H5Sclose(sm_space) < 0)
                H5TOOLS_THROW(FAIL, "H5Sclose failed");
            if (sm_buf)
                free(sm_buf);
            sm_buf = NULL;
        }
        else
            H5TOOLS_THROW(SUCCEED, "nothing to print");

        ctx->continuation++;

    } /* hyperslab_count loop */

    CATCH
    if (sm_buf)
        free(sm_buf);

    H5TOOLS_ENDDEBUG(" ");
    return ret_value;
}

/*-------------------------------------------------------------------------
 * Audience:    Public
 * Chapter:     H5Tools Library
 * Purpose:     print out the data for a subset of a dataset.
 * Description:
 *
 *  Select a hyperslab from the dataset DSET using the parameters
 *   specified in SSET. Dump this out to STREAM.
 *
 *  Hyperslabs select "count" blocks of size "block", spaced "stride" elements
 *   from each other, starting at coordinate "start".
 *
 * Return:
 *      On success, return SUCCEED. Otherwise, the function returns FAIL.
 *
 * Algorithm
 *
 * The parameters from SSET are translated into temporary
 * variables so that 1 row is printed at a time (getting the coordinate indices
 * at each row).
 * We define the stride, count and block to be 1 in the row dimension to achieve
 * this and advance until all points are printed.
 *
 * The element position is obtained from the matrix according to:
 *       Given an index I(z,y,x) its position from the beginning of an array
 *       of sizes A(size_z, size_y,size_x) is given by
 *       Position of I(z,y,x) = index_z * size_y * size_x
 *                             + index_y * size_x
 *                             + index_x
 *
 *-------------------------------------------------------------------------
 */
static herr_t
h5tools_display_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hid_t dset,
                              hid_t p_type, hid_t f_space, hsize_t *total_size)
{
    size_t       i;                         /* counters  */
    hsize_t      n;                         /* counters  */
    hsize_t      count;                     /* hyperslab count */
    hsize_t      outer_count;               /* offset count */
    unsigned int row_dim;                   /* index of row_counter dimension */
    int          current_outer_dim;         /* dimension for start */
    hsize_t      temp_start[H5S_MAX_RANK];  /* temporary start inside offset count loop */
    hsize_t      max_start[H5S_MAX_RANK];   /* maximum start inside offset count loop */
    hsize_t      temp_count[H5S_MAX_RANK];  /* temporary count inside offset count loop  */
    hsize_t      temp_block[H5S_MAX_RANK];  /* temporary block size used in loop  */
    hsize_t      temp_stride[H5S_MAX_RANK]; /* temporary stride size used in loop  */
    int          reset_dim;
    herr_t       ret_value = SUCCEED;

    if (ctx->ndims == 1)
        row_dim = 0;
    else
        row_dim = ctx->ndims - 2;

    /* get the offset count */
    outer_count = 1;
    if (ctx->ndims > 2)
        for (i = 0; i < (size_t)ctx->ndims - 2; i++) {
            /* block size is handled by containing h5tools_print_simple_subset call */
            outer_count = outer_count * ctx->sset->count.data[i];
        }

    /* initialize temporary start, count and maximum start */
    for (i = 0; i < ctx->ndims; i++) {
        temp_start[i]  = ctx->sset->start.data[i];
        temp_count[i]  = ctx->sset->count.data[i];
        temp_block[i]  = ctx->sset->block.data[i];
        temp_stride[i] = ctx->sset->stride.data[i];
        max_start[i]   = 0;
    }

    if (ctx->ndims > 2) {
        for (i = 0; i < (size_t)ctx->ndims - 2; i++) {
            max_start[i]  = temp_start[i] + ctx->sset->count.data[i] * ctx->sset->stride.data[i];
            temp_count[i] = 1;
        }
    }

    /* offset loop */
    for (n = 0; n < outer_count; n++) {
        /* number of read iterations in inner loop, read by rows, to match 2D display */
        if (ctx->ndims > 1) {
            /* count is the number of iterations to display all the rows,
             the block size count times */
            count = ctx->sset->count.data[row_dim] * ctx->sset->block.data[row_dim];

            /* always 1 row_counter at a time, that is a block of size 1, 1 time */
            temp_count[row_dim] = 1;
            temp_block[row_dim] = 1;

            /* advance 1 row_counter at a time  */
            if (ctx->sset->block.data[row_dim] > 1)
                temp_stride[row_dim] = 1;
        }
        /* for the 1D case */
        else {
            count = 1;
        }

        h5tools_print_simple_subset(stream, info, ctx, dset, p_type, f_space, count, temp_start, temp_count,
                                    temp_block, temp_stride, total_size, row_dim);

        if (ctx->ndims > 2) {
            /* dimension for start */
            current_outer_dim = (int)(ctx->ndims - 2) - 1;

            /* set start to original from current_outer_dim up */
            for (i = (size_t)(current_outer_dim + 1); i < ctx->ndims; i++)
                temp_start[i] = ctx->sset->start.data[i];

            /* increment start dimension */
            do {
                reset_dim = 0;
                temp_start[current_outer_dim] += ctx->sset->stride.data[current_outer_dim];
                if (temp_start[current_outer_dim] >= max_start[current_outer_dim]) {
                    temp_start[current_outer_dim] = ctx->sset->start.data[current_outer_dim];

                    current_outer_dim--;
                    reset_dim = 1;
                }
            } while (current_outer_dim >= 0 && reset_dim);

        } /* ctx.ndims > 1 */

    } /* outer_count */

    return ret_value;
}

/*-------------------------------------------------------------------------
 * Audience:    Public
 * Chapter:     H5Tools Library
 * Purpose:     Dump out a subset of a dataset.
 * Description:
 *
 *  Select a hyperslab from the dataset DSET using the parameters
 *   specified in SSET. Dump this out to STREAM.
 *
 *  Hyperslabs select "count" blocks of size "block", spaced "stride" elements
 *   from each other, starting at coordinate "start".
 *
 * Return:
 *      On success, return SUCCEED. Otherwise, the function returns FAIL.
 *
 * Algorithm
 *
 * In a inner loop, the parameters from SSET are translated into temporary
 * variables so that 1 row is printed at a time (getting the coordinate indices
 * at each row).
 * We define the stride, count and block to be 1 in the row dimension to achieve
 * this and advance until all points are printed.
 * An outer loop for cases where dimensionality is greater than 2D is made.
 * In each iteration, the 2D block is displayed in the inner loop. The remaining
 * slower dimensions above the first 2 are incremented one at a time in the outer loop
 *
 * The element position is obtained from the matrix according to:
 *       Given an index I(z,y,x) its position from the beginning of an array
 *       of sizes A(size_z, size_y,size_x) is given by
 *       Position of I(z,y,x) = index_z * size_y * size_x
 *                             + index_y * size_x
 *                             + index_x
 *
 *-------------------------------------------------------------------------
 */
static herr_t
h5tools_dump_simple_subset(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hid_t dset,
                           hid_t p_type)
{
    int     sndims;
    hid_t   f_space = H5I_INVALID_HID; /* file data space */
    hsize_t total_size[H5S_MAX_RANK];  /* total size of dataset*/
    bool    past_catch = false;
    herr_t  ret_value  = SUCCEED;

    H5TOOLS_START_DEBUG(" ");
    if ((f_space = H5Dget_space(dset)) < 0)
        H5TOOLS_THROW(FAIL, "H5Dget_space failed");

    if ((sndims = H5Sget_simple_extent_ndims(f_space)) < 0)
        H5TOOLS_THROW(FAIL, "H5Sget_simple_extent_ndims failed");
    ctx->ndims = (unsigned)sndims;

    /* assume entire data space to be printed */
    if (H5Sget_simple_extent_dims(f_space, total_size, NULL) < 0)
        H5TOOLS_THROW(FAIL, "H5Sget_simple_extent_dims failed");
    init_acc_pos(ctx->ndims, total_size, ctx->acc, ctx->pos, ctx->p_min_idx);

    ctx->size_last_dim = total_size[ctx->ndims - 1];

    /* Set the compound datatype field list for display */
    ctx->cmpd_listv = info->cmpd_listv;

    h5tools_display_simple_subset(stream, info, ctx, dset, p_type, f_space, total_size);

    CATCH
    if (f_space >= 0 && H5Sclose(f_space) < 0)
        H5TOOLS_THROW(FAIL, "H5Sclose failed");

    H5TOOLS_ENDDEBUG(" ");
    return ret_value;
}

/*-------------------------------------------------------------------------
 * Audience:    Public
 * Chapter:     H5Tools Library
 * Purpose: Print some values from a dataset with a simple data space.
 * Description:
 *      This is a special case of h5tools_dump_dset(). This function only
 *      intended for dumping datasets -- it does strip mining and some other
 *      things which are unnecessary for smaller objects such as attributes
 *      (to print small objects like attributes simply read the attribute and
 *      call h5tools_dump_simple_mem()).
 * Return:
 *      On success, the function returns SUCCEED. Otherwise, the function
 *      returns FAIL.
 *-------------------------------------------------------------------------
 */
static int
h5tools_dump_simple_dset(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hid_t dset,
                         hid_t p_type)
{
    hid_t        f_space = H5I_INVALID_HID; /* file data space */
    hsize_t      elmtno;                    /* counter  */
    size_t       i = 0;                     /* counter  */
    int          sndims;                    /* rank of dataspace */
    int          carry;                     /* counter carry value */
    hsize_t      zero[8];                   /* vector of zeros */
    unsigned int flags;                     /* buffer extent flags */
    hsize_t      total_size[H5S_MAX_RANK];  /* total size of dataset*/
    bool         past_catch = false;

    /* Print info */
    size_t  p_type_nbytes; /* size of memory type */
    hsize_t p_nelmts;      /* total selected elmts */

    /* Stripmine info */
    hsize_t        sm_size[H5S_MAX_RANK];      /* stripmine size */
    hsize_t        sm_nbytes;                  /* bytes per stripmine */
    hsize_t        sm_nelmts;                  /* elements per stripmine*/
    unsigned char *sm_buf   = NULL;            /* buffer for raw data */
    hid_t          sm_space = H5I_INVALID_HID; /* stripmine data space */

    /* Hyperslab info */
    hsize_t hs_offset[H5S_MAX_RANK]; /* starting offset */
    hsize_t hs_size[H5S_MAX_RANK];   /* size this pass */
    hsize_t hs_nelmts;               /* elements in request */

    /* VL data special information */
    unsigned int vl_data   = 0; /* contains VL datatypes */
    int          ret_value = 0;

    H5TOOLS_START_DEBUG(" ");
    if (H5I_INVALID_HID == (f_space = H5Dget_space(dset)))
        H5TOOLS_GOTO_ERROR((-1), "H5Dget_space failed");

    sndims = H5Sget_simple_extent_ndims(f_space);
    if (sndims < 0)
        H5TOOLS_GOTO_ERROR((-1), "H5Dget_simple_extent_ndims failed");
    ctx->ndims = (unsigned)sndims;
    H5TOOLS_DEBUG("sndims:%d", sndims);

    if ((size_t)ctx->ndims > NELMTS(sm_size))
        H5TOOLS_GOTO_ERROR((-1), "ctx->ndims > NELMTS(sm_size) failed");

    /* Assume entire data space to be printed */
    H5Sget_simple_extent_dims(f_space, total_size, NULL);
    init_acc_pos(ctx->ndims, total_size, ctx->acc, ctx->pos, ctx->p_min_idx);

    /* calculate the number of elements we're going to print */
    p_nelmts = 1;

    if (ctx->ndims > 0) {
        for (i = 0; i < ctx->ndims; i++)
            p_nelmts *= total_size[i];
        ctx->size_last_dim = (total_size[ctx->ndims - 1]);
    } /* end if */
    else
        ctx->size_last_dim = 0;

    if (p_nelmts == 0) {
        H5_LEAVE(SUCCEED); /* nothing to print */
    }

    /* Check if we have VL data in the dataset's datatype */
    if (h5tools_detect_vlen(p_type) == true)
        vl_data = true;

    /*
     * Determine the strip mine size and allocate a buffer. The strip mine is
     * a hyperslab whose size is manageable.
     */
    sm_nbytes = p_type_nbytes = H5Tget_size(p_type);
    if (ctx->ndims > 0) {
        for (i = ctx->ndims; i > 0; --i) {
            hsize_t size = H5TOOLS_BUFSIZE / sm_nbytes;
            if (size == 0) /* datum size > H5TOOLS_BUFSIZE */
                size = 1;
            sm_size[i - 1] = MIN(total_size[i - 1], size);
            sm_nbytes *= sm_size[i - 1];
        }
    }
    if (!sm_nbytes)
        goto done;

    assert(sm_nbytes == (hsize_t)((size_t)sm_nbytes)); /*check for overflow*/
    if (NULL != (sm_buf = (unsigned char *)malloc((size_t)sm_nbytes))) {
        H5TOOLS_DEBUG("stripmine size:%ld", sm_nbytes);

        sm_nelmts = sm_nbytes / p_type_nbytes;
        sm_space  = H5Screate_simple(1, &sm_nelmts, NULL);
        H5TOOLS_DEBUG("sm_nelmts size:%ld", sm_nelmts);

        H5TOOLS_DEBUG("ctx->ndims:%d", ctx->ndims);

        /* The stripmine loop */
        memset(hs_offset, 0, sizeof hs_offset);
        memset(zero, 0, sizeof zero);

        for (elmtno = 0; elmtno < p_nelmts; elmtno += hs_nelmts) {
            H5TOOLS_DEBUG("stripmine read loop:%d", i);
            /* Calculate the hyperslab size */
            if (ctx->ndims > 0) {
                for (i = 0, hs_nelmts = 1; i < ctx->ndims; i++) {
                    hs_size[i]        = MIN(total_size[i] - hs_offset[i], sm_size[i]);
                    ctx->p_max_idx[i] = ctx->p_min_idx[i] + hs_size[i];
                    hs_nelmts *= hs_size[i];
                }

                if (H5Sselect_hyperslab(f_space, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL) < 0)
                    H5TOOLS_ERROR((-1), "H5Sselect_hyperslab hs_offset failed");
                if (H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, zero, NULL, &hs_nelmts, NULL) < 0)
                    H5TOOLS_ERROR((-1), "H5Sselect_hyperslab zero failed");
            }
            else {
                if (H5Sselect_all(f_space) < 0)
                    H5TOOLS_ERROR((-1), "H5Sselect_all f_space failed");
                if (H5Sselect_all(sm_space) < 0)
                    H5TOOLS_ERROR((-1), "H5Sselect_all sm_space failed");
                hs_nelmts = 1;
            }

            H5TOOLS_DEBUG("Read the data");
            /* Read the data */
            if (H5Dread(dset, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf) >= 0) {
                /* Print the data */
                flags = (elmtno == 0) ? START_OF_DATA : 0;
                flags |= ((elmtno + hs_nelmts) >= p_nelmts) ? END_OF_DATA : 0;

                /* initialize the current stripmine position; this is necessary to print the array
                indices */
                ctx->sm_pos = elmtno;

                if (h5tools_dump_simple_data(stream, info, ctx, dset, flags, hs_nelmts, p_type, sm_buf) < 0)
                    H5TOOLS_ERROR((-1), "h5tools_dump_simple_data failed");

                /* Reclaim any VL memory, if necessary */
                if (vl_data)
                    H5Treclaim(p_type, sm_space, H5P_DEFAULT, sm_buf);

                H5TOOLS_DEBUG("Calculate the next hyperslab offset");
                /* Calculate the next hyperslab offset */
                for (i = ctx->ndims, carry = 1; i > 0 && carry; --i) {
                    ctx->p_min_idx[i - 1] = ctx->p_max_idx[i - 1];
                    hs_offset[i - 1] += hs_size[i - 1];

                    if (hs_offset[i - 1] == total_size[i - 1])
                        hs_offset[i - 1] = 0;
                    else
                        carry = 0;
                }
            }
            else
                H5TOOLS_ERROR((-1), "H5Dread failed");

            ctx->continuation++;
            H5TOOLS_DEBUG("stripmine read loop:%d complete", i);
        }
        free(sm_buf);
    } /* if (NULL != (sm_buf...)) */

done:
    if (sm_space >= 0 && H5Sclose(sm_space) < 0)
        H5TOOLS_ERROR((-1), "H5Sclose failed");
    if (f_space >= 0 && H5Sclose(f_space) < 0)
        H5TOOLS_ERROR((-1), "H5Sclose failed");
    CATCH
    H5TOOLS_ENDDEBUG(" ");
    return ret_value;
}

/*-------------------------------------------------------------------------
 * Function: h5tools_dump_simple_mem
 *
 * Purpose: Print some values from memory with a simple data space.
 *  This is a special case of h5tools_dump_mem().
 *
 * Return: Success:    SUCCEED
 *         Failure:    FAIL
 *-------------------------------------------------------------------------
 */
static int
h5tools_dump_simple_mem(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hid_t attr_id,
                        hid_t p_type)
{
    hid_t          f_space = H5I_INVALID_HID; /* file data space */
    hsize_t        alloc_size;
    int            sndims;                   /* rank of dataspace */
    unsigned       i;                        /* counters  */
    hsize_t        total_size[H5S_MAX_RANK]; /* total size of dataset*/
    hsize_t        p_nelmts;                 /* total selected elmts */
    bool           past_catch = false;
    unsigned char *buf        = NULL; /* buffer for raw data */
    int            ret_value  = 0;

    /* VL data special information */
    unsigned int vl_data = 0; /* contains VL datatypes */

    H5TOOLS_START_DEBUG(" ");
    if (H5I_INVALID_HID == (f_space = H5Aget_space(attr_id)))
        H5TOOLS_GOTO_ERROR((-1), "H5Dget_space failed");

    sndims = H5Sget_simple_extent_ndims(f_space);
    if (sndims < 0)
        H5TOOLS_THROW((-1), "H5Dget_simple_extent_ndims failed");
    ctx->ndims = (unsigned)sndims;
    H5TOOLS_DEBUG("sndims:%d", sndims);

    if ((size_t)ctx->ndims > NELMTS(ctx->p_min_idx))
        H5TOOLS_THROW((-1), "ctx->ndims > NELMTS(ctx->p_min_idx) failed");

    /* Assume entire data space to be printed */
    H5Sget_simple_extent_dims(f_space, total_size, NULL);
    init_acc_pos(ctx->ndims, total_size, ctx->acc, ctx->pos, ctx->p_min_idx);

    /* calculate the number of elements we're going to print */
    p_nelmts = 1;

    if (ctx->ndims > 0) {
        for (i = 0; i < ctx->ndims; i++)
            p_nelmts *= total_size[i];
        ctx->size_last_dim = (total_size[ctx->ndims - 1]);
    } /* end if */
    else
        ctx->size_last_dim = 0;

    if (p_nelmts == 0)
        H5_LEAVE(SUCCEED); /* nothing to print */

    /* Check if we have VL data in the dataset's datatype */
    if (h5tools_detect_vlen(p_type) == true)
        vl_data = true;

    alloc_size = p_nelmts * H5Tget_size(p_type);
    assert(alloc_size == (hsize_t)((size_t)alloc_size)); /*check for overflow*/
    if (NULL != (buf = (unsigned char *)malloc((size_t)alloc_size))) {
        H5TOOLS_DEBUG("ctx->ndims:%d", ctx->ndims);

        H5TOOLS_DEBUG("Read the data");
        /* Read the data */
        if (H5Aread(attr_id, p_type, buf) >= 0) {
            if (h5tools_dump_simple_data(stream, info, ctx, attr_id, START_OF_DATA | END_OF_DATA, p_nelmts,
                                         p_type, buf) < 0)
                H5TOOLS_ERROR((-1), "h5tools_dump_simple_data failed");

            /* Reclaim any VL memory, if necessary */
            if (vl_data)
                H5Treclaim(p_type, f_space, H5P_DEFAULT, buf);
        }
        else
            H5TOOLS_ERROR((-1), "H5Aread failed");
        free(buf);
    } /* if (NULL != (buf...)) */
done:
    if (f_space >= 0 && H5Sclose(f_space) < 0)
        H5TOOLS_ERROR((-1), "H5Sclose failed");
    CATCH
    H5TOOLS_ENDDEBUG(" ");
    return ret_value;
}

/*-------------------------------------------------------------------------
 * Function: h5tools_dump_dset
 *
 * Purpose: Print some values from a dataset DSET to the file STREAM
 *  after converting all types to P_TYPE (which should be a
 *  native type).  If P_TYPE is a negative value then it will be
 *  computed from the dataset type using only native types.
 *
 * Note: This function is intended only for datasets since it does
 *  some things like strip mining which are unnecessary for
 *  smaller objects such as attributes. The easiest way to print
 *  small objects is to read the object into memory and call
 *  h5tools_dump_mem().
 *
 * Return: Success:    SUCCEED
 *         Failure:    FAIL
 *-------------------------------------------------------------------------
 */
int
h5tools_dump_dset(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hid_t dset)
{
    hid_t           f_space = H5I_INVALID_HID;
    hid_t           p_type  = H5I_INVALID_HID;
    hid_t           f_type  = H5I_INVALID_HID;
    H5S_class_t     space_type;
    h5tool_format_t info_dflt;
    int             ret_value = 0;

    H5TOOLS_START_DEBUG(" ");
    /* Use default values */
    if (!stream)
        stream = rawoutstream;

    if (!info) {
        memset(&info_dflt, 0, sizeof info_dflt);
        info = &info_dflt;
    }

    f_type = H5Dget_type(dset);
    if (f_type < 0)
        goto done;

    if (info->raw || bin_form == 1)
        p_type = H5Tcopy(f_type);
    else if (bin_form == 2)
        p_type = h5tools_get_little_endian_type(f_type);
    else if (bin_form == 3)
        p_type = h5tools_get_big_endian_type(f_type);
    else
        p_type = H5Tget_native_type(f_type, H5T_DIR_DEFAULT);

    if (p_type < 0)
        goto done;

    /* Check the data space */
    f_space = H5Dget_space(dset);
    if (f_space < 0)
        goto done;

    space_type = H5Sget_simple_extent_type(f_space);

    /* Print the data */
    if (space_type == H5S_SIMPLE || space_type == H5S_SCALAR) {
        if (!ctx->sset)
            ret_value = h5tools_dump_simple_dset(rawdatastream, info, ctx, dset, p_type);
        else
            ret_value = h5tools_dump_simple_subset(rawdatastream, info, ctx, dset, p_type);
    }
    else {
        /* space is H5S_NULL */
        ret_value = SUCCEED;
    }
done:
    if (f_type > 0)
        H5Tclose(f_type);
    if (p_type > 0)
        H5Tclose(p_type);
    if (f_space > 0)
        H5Sclose(f_space);

    H5TOOLS_ENDDEBUG(" ");
    return ret_value;
}

/*-------------------------------------------------------------------------
 * Function: h5tools_dump_mem
 *
 * Purpose: Displays the data contained in MEM. MEM must have the
 *  specified data TYPE and SPACE.  Currently only simple data
 *  spaces are allowed and only the `all' selection.
 *
 * Return: Success:    SUCCEED
 *         Failure:    FAIL
 *-------------------------------------------------------------------------
 */
int
h5tools_dump_mem(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hid_t attr_id)
{
    hid_t           f_space = H5I_INVALID_HID;
    hid_t           p_type  = H5I_INVALID_HID;
    hid_t           f_type  = H5I_INVALID_HID;
    h5tool_format_t info_dflt;
    int             ret_value = 0;

    H5TOOLS_START_DEBUG(" ");
    /* Use default values */
    if (!stream)
        stream = rawoutstream;

    if (!info) {
        memset(&info_dflt, 0, sizeof(info_dflt));
        info = &info_dflt;
    }

    f_type = H5Aget_type(attr_id);
    if (f_type < 0)
        goto done;

    if (info->raw || bin_form == 1)
        p_type = H5Tcopy(f_type);
    else if (bin_form == 2)
        p_type = h5tools_get_little_endian_type(f_type);
    else if (bin_form == 3)
        p_type = h5tools_get_big_endian_type(f_type);
    else
        p_type = H5Tget_native_type(f_type, H5T_DIR_DEFAULT);

    if (p_type < 0)
        goto done;

    /* Check the data space */
    f_space = H5Aget_space(attr_id);
    if (f_space < 0)
        goto done;

    /* Check the data space */
    if (H5Sis_simple(f_space) <= 0) {
        H5TOOLS_ERROR((-1), "H5Sis_simple failed");
    }
    else {
        ret_value = h5tools_dump_simple_mem(rawattrstream, info, ctx, attr_id, p_type);
    }
done:
    if (f_type > 0)
        H5Tclose(f_type);
    if (p_type > 0)
        H5Tclose(p_type);
    if (f_space > 0)
        H5Sclose(f_space);

    H5TOOLS_ENDDEBUG(" ");
    return ret_value;
}

/*-------------------------------------------------------------------------
 * Function:    print_datatype
 *
 * Purpose:     print the datatype - do not prefix.
 *
 * Return:      void
 *
 * In/Out:      h5tools_str_t *buffer
 *              h5tools_context_t *ctx
 *-------------------------------------------------------------------------
 */
int
h5tools_print_datatype(FILE *stream, h5tools_str_t *buffer, const h5tool_format_t *info,
                       h5tools_context_t *ctx, hid_t type, int object_search)
{
    char       *mname;
    hid_t       mtype    = H5I_INVALID_HID;
    hid_t       str_type = H5I_INVALID_HID;
    hid_t       super    = H5I_INVALID_HID;
    hid_t       tmp_type = H5I_INVALID_HID;
    int         snmembers;
    int         sndims;
    unsigned    nmembers;
    unsigned    i;
    size_t      size  = 0;
    size_t      ncols = 80; /*available output width */
    hsize_t     dims[H5TOOLS_DUMP_MAX_RANK];
    hsize_t     curr_pos = 0; /* total data element position   */
    H5T_str_t   str_pad;
    H5T_cset_t  cset;
    H5T_order_t order;
    H5T_class_t type_class;
    H5T_sign_t  sign; /* sign scheme value */
    htri_t      is_vlstr   = false;
    bool        past_catch = false;
    const char *sign_s     = NULL; /* sign scheme string */
    const char *order_s    = NULL; /* byte order string */
    int         ret_value  = 0;

    H5TOOLS_START_DEBUG(" ");
    if ((type_class = H5Tget_class(type)) < 0)
        H5TOOLS_THROW((-1), "H5Tget_class failed");
    if (object_search && H5Tcommitted(type) > 0) {
        H5O_info2_t oinfo;
        obj_t      *obj = NULL; /* Found object */

        H5Oget_info3(type, &oinfo, H5O_INFO_BASIC);
        obj = search_obj(h5dump_type_table, &oinfo.token);

        if (obj) {
            if (!obj->recorded) {
                char *obj_tok_str = NULL;

                H5Otoken_to_str(type, &oinfo.token, &obj_tok_str);
                h5tools_str_append(buffer, "\"/#%s\"", obj_tok_str);
                H5free_memory(obj_tok_str);
            }
            else
                h5tools_str_append(buffer, "\"%s\"", obj->objname);
        }
        else {
            error_msg("unknown committed type.\n");
            h5tools_setstatus(EXIT_FAILURE);
        }

        return ret_value;
    }

    if (info->line_ncols > 0)
        ncols = info->line_ncols;

    switch (type_class) {
        case H5T_INTEGER:
            if (H5Tequal(type, H5T_STD_I8BE) == true)
                h5tools_str_append(buffer, "H5T_STD_I8BE");
            else if (H5Tequal(type, H5T_STD_I8LE) == true)
                h5tools_str_append(buffer, "H5T_STD_I8LE");
            else if (H5Tequal(type, H5T_STD_I16BE) == true)
                h5tools_str_append(buffer, "H5T_STD_I16BE");
            else if (H5Tequal(type, H5T_STD_I16LE) == true)
                h5tools_str_append(buffer, "H5T_STD_I16LE");
            else if (H5Tequal(type, H5T_STD_I32BE) == true)
                h5tools_str_append(buffer, "H5T_STD_I32BE");
            else if (H5Tequal(type, H5T_STD_I32LE) == true)
                h5tools_str_append(buffer, "H5T_STD_I32LE");
            else if (H5Tequal(type, H5T_STD_I64BE) == true)
                h5tools_str_append(buffer, "H5T_STD_I64BE");
            else if (H5Tequal(type, H5T_STD_I64LE) == true)
                h5tools_str_append(buffer, "H5T_STD_I64LE");
            else if (H5Tequal(type, H5T_STD_U8BE) == true)
                h5tools_str_append(buffer, "H5T_STD_U8BE");
            else if (H5Tequal(type, H5T_STD_U8LE) == true)
                h5tools_str_append(buffer, "H5T_STD_U8LE");
            else if (H5Tequal(type, H5T_STD_U16BE) == true)
                h5tools_str_append(buffer, "H5T_STD_U16BE");
            else if (H5Tequal(type, H5T_STD_U16LE) == true)
                h5tools_str_append(buffer, "H5T_STD_U16LE");
            else if (H5Tequal(type, H5T_STD_U32BE) == true)
                h5tools_str_append(buffer, "H5T_STD_U32BE");
            else if (H5Tequal(type, H5T_STD_U32LE) == true)
                h5tools_str_append(buffer, "H5T_STD_U32LE");
            else if (H5Tequal(type, H5T_STD_U64BE) == true)
                h5tools_str_append(buffer, "H5T_STD_U64BE");
            else if (H5Tequal(type, H5T_STD_U64LE) == true)
                h5tools_str_append(buffer, "H5T_STD_U64LE");
            else if (H5Tequal(type, H5T_NATIVE_SCHAR) == true)
                h5tools_str_append(buffer, "H5T_NATIVE_SCHAR");
            else if (H5Tequal(type, H5T_NATIVE_UCHAR) == true)
                h5tools_str_append(buffer, "H5T_NATIVE_UCHAR");
            else if (H5Tequal(type, H5T_NATIVE_SHORT) == true)
                h5tools_str_append(buffer, "H5T_NATIVE_SHORT");
            else if (H5Tequal(type, H5T_NATIVE_USHORT) == true)
                h5tools_str_append(buffer, "H5T_NATIVE_USHORT");
            else if (H5Tequal(type, H5T_NATIVE_INT) == true)
                h5tools_str_append(buffer, "H5T_NATIVE_INT");
            else if (H5Tequal(type, H5T_NATIVE_UINT) == true)
                h5tools_str_append(buffer, "H5T_NATIVE_UINT");
            else if (H5Tequal(type, H5T_NATIVE_LONG) == true)
                h5tools_str_append(buffer, "H5T_NATIVE_LONG");
            else if (H5Tequal(type, H5T_NATIVE_ULONG) == true)
                h5tools_str_append(buffer, "H5T_NATIVE_ULONG");
            else if (H5Tequal(type, H5T_NATIVE_LLONG) == true)
                h5tools_str_append(buffer, "H5T_NATIVE_LLONG");
            else if (H5Tequal(type, H5T_NATIVE_ULLONG) == true)
                h5tools_str_append(buffer, "H5T_NATIVE_ULLONG");
            else {

                /* byte order */
                if (H5Tget_size(type) > 1) {
                    order = H5Tget_order(type);
                    if (H5T_ORDER_LE == order)
                        order_s = " little-endian";
                    else if (H5T_ORDER_BE == order)
                        order_s = " big-endian";
                    else if (H5T_ORDER_VAX == order)
                        order_s = " mixed-endian";
                    else
                        order_s = " unknown-byte-order";
                }
                else
                    order_s = "";

                /* sign */
                if ((sign = H5Tget_sign(type)) >= 0) {
                    if (H5T_SGN_NONE == sign)
                        sign_s = " unsigned";
                    else if (H5T_SGN_2 == sign)
                        sign_s = "";
                    else
                        sign_s = " unknown-sign";
                }
                else
                    sign_s = " unknown-sign";

                /* print size, order, sign, and precision */
                h5tools_str_append(buffer, "%zu-bit%s%s integer %zu-bit precision", 8 * H5Tget_size(type),
                                   order_s, sign_s, H5Tget_precision(type));
            }
            break;

        case H5T_FLOAT:
            if (H5Tequal(type, H5T_IEEE_F16BE) == true)
                h5tools_str_append(buffer, "H5T_IEEE_F16BE");
            else if (H5Tequal(type, H5T_IEEE_F16LE) == true)
                h5tools_str_append(buffer, "H5T_IEEE_F16LE");
            else if (H5Tequal(type, H5T_IEEE_F32BE) == true)
                h5tools_str_append(buffer, "H5T_IEEE_F32BE");
            else if (H5Tequal(type, H5T_IEEE_F32LE) == true)
                h5tools_str_append(buffer, "H5T_IEEE_F32LE");
            else if (H5Tequal(type, H5T_IEEE_F64BE) == true)
                h5tools_str_append(buffer, "H5T_IEEE_F64BE");
            else if (H5Tequal(type, H5T_IEEE_F64LE) == true)
                h5tools_str_append(buffer, "H5T_IEEE_F64LE");
            else if (H5Tequal(type, H5T_VAX_F32) == true)
                h5tools_str_append(buffer, "H5T_VAX_F32");
            else if (H5Tequal(type, H5T_VAX_F64) == true)
                h5tools_str_append(buffer, "H5T_VAX_F64");
#ifdef H5_HAVE__FLOAT16
            else if (H5Tequal(type, H5T_NATIVE_FLOAT16) == true)
                h5tools_str_append(buffer, "H5T_NATIVE_FLOAT16");
#endif
            else if (H5Tequal(type, H5T_NATIVE_FLOAT) == true)
                h5tools_str_append(buffer, "H5T_NATIVE_FLOAT");
            else if (H5Tequal(type, H5T_NATIVE_DOUBLE) == true)
                h5tools_str_append(buffer, "H5T_NATIVE_DOUBLE");
            else {
                /* print what the library knows */
                /* byte order */
                if (H5Tget_size(type) > 1) {
                    order = H5Tget_order(type);
                    if (H5T_ORDER_LE == order)
                        order_s = " little-endian";
                    else if (H5T_ORDER_BE == order)
                        order_s = " big-endian";
                    else if (H5T_ORDER_VAX == order)
                        order_s = " mixed-endian";
                    else
                        order_s = " unknown-byte-order";
                }
                else
                    order_s = "";

                /* print size. byte order, and precision */
                h5tools_str_append(buffer, "%zu-bit%s floating-point %zu-bit precision",
                                   8 * H5Tget_size(type), order_s, H5Tget_precision(type));
            }
            break;

        case H5T_TIME:
            h5tools_str_append(buffer, "H5T_TIME: not yet implemented");
            break;

        case H5T_STRING:
            /* Make a copy of type in memory in case when TYPE is on disk, the size
             * will be bigger than in memory.  This makes it easier to compare
             * types in memory. */
            tmp_type = H5Tcopy(type);
            size     = H5Tget_size(tmp_type);
            str_pad  = H5Tget_strpad(tmp_type);
            cset     = H5Tget_cset(tmp_type);
            is_vlstr = H5Tis_variable_str(tmp_type);

            curr_pos = ctx->cur_column;
            h5tools_str_append(buffer, "%s", h5tools_dump_header_format->strblockbegin);
            h5tools_render_element(stream, info, ctx, buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                   (hsize_t)0);

            ctx->indent_level++;

            ctx->need_prefix = true;

            h5tools_str_reset(buffer);

            if (is_vlstr)
                h5tools_str_append(buffer, "%s H5T_VARIABLE;", STRSIZE);
            else
                h5tools_str_append(buffer, "%s %d;", STRSIZE, (int)size);
            h5tools_render_element(stream, info, ctx, buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                   (hsize_t)0);

            ctx->need_prefix = true;

            h5tools_str_reset(buffer);

            h5tools_str_append(buffer, "%s ", STRPAD);
            switch (str_pad) {
                case H5T_STR_NULLTERM:
                    h5tools_str_append(buffer, "H5T_STR_NULLTERM;");
                    break;
                case H5T_STR_NULLPAD:
                    h5tools_str_append(buffer, "H5T_STR_NULLPAD;");
                    break;
                case H5T_STR_SPACEPAD:
                    h5tools_str_append(buffer, "H5T_STR_SPACEPAD;");
                    break;
                case H5T_STR_RESERVED_3:
                case H5T_STR_RESERVED_4:
                case H5T_STR_RESERVED_5:
                case H5T_STR_RESERVED_6:
                case H5T_STR_RESERVED_7:
                case H5T_STR_RESERVED_8:
                case H5T_STR_RESERVED_9:
                case H5T_STR_RESERVED_10:
                case H5T_STR_RESERVED_11:
                case H5T_STR_RESERVED_12:
                case H5T_STR_RESERVED_13:
                case H5T_STR_RESERVED_14:
                case H5T_STR_RESERVED_15:
                    h5tools_str_append(buffer, "H5T_STR_UNKNOWN;");
                    break;
                case H5T_STR_ERROR:
                    h5tools_str_append(buffer, "H5T_STR_ERROR;");
                    break;
                default:
                    h5tools_str_append(buffer, "ERROR;");
                    break;
            }
            h5tools_render_element(stream, info, ctx, buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                   (hsize_t)0);

            ctx->need_prefix = true;

            h5tools_str_reset(buffer);

            h5tools_str_append(buffer, "%s ", CSET);

            switch (cset) {
                case H5T_CSET_ASCII:
                    h5tools_str_append(buffer, "H5T_CSET_ASCII;");
                    break;
                case H5T_CSET_UTF8:
                    h5tools_str_append(buffer, "H5T_CSET_UTF8;");
                    break;
                case H5T_CSET_RESERVED_2:
                case H5T_CSET_RESERVED_3:
                case H5T_CSET_RESERVED_4:
                case H5T_CSET_RESERVED_5:
                case H5T_CSET_RESERVED_6:
                case H5T_CSET_RESERVED_7:
                case H5T_CSET_RESERVED_8:
                case H5T_CSET_RESERVED_9:
                case H5T_CSET_RESERVED_10:
                case H5T_CSET_RESERVED_11:
                case H5T_CSET_RESERVED_12:
                case H5T_CSET_RESERVED_13:
                case H5T_CSET_RESERVED_14:
                case H5T_CSET_RESERVED_15:
                    h5tools_str_append(buffer, "H5T_CSET_UNKNOWN;");
                    break;
                case H5T_CSET_ERROR:
                    h5tools_str_append(buffer, "H5T_CSET_ERROR;");
                    break;
                default:
                    h5tools_str_append(buffer, "ERROR;");
                    break;
            }
            h5tools_render_element(stream, info, ctx, buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                   (hsize_t)0);

            ctx->need_prefix = true;

            h5tools_str_reset(buffer);

            str_type = H5Tcopy(H5T_C_S1);
            if (is_vlstr)
                H5Tset_size(str_type, H5T_VARIABLE);
            else
                H5Tset_size(str_type, size);
            H5Tset_cset(str_type, cset);
            H5Tset_strpad(str_type, str_pad);

            h5tools_str_append(buffer, "%s ", CTYPE);

            /* Check C variable-length string first. Are the two types equal? */
            if (H5Tequal(tmp_type, str_type)) {
                h5tools_str_append(buffer, "H5T_C_S1;");
                goto found_string_type;
            }

            /* Change the endianness and see if they're equal. */
            order = H5Tget_order(tmp_type);
            if (order == H5T_ORDER_LE) {
                if (H5Tset_order(str_type, H5T_ORDER_LE) < 0)
                    H5TOOLS_ERROR((-1), "H5Tset_order failed");
            } /* end if */
            else if (order == H5T_ORDER_BE) {
                if (H5Tset_order(str_type, H5T_ORDER_BE) < 0)
                    H5TOOLS_ERROR((-1), "H5Tset_order failed");
            } /* end if */

            if (H5Tequal(tmp_type, str_type)) {
                h5tools_str_append(buffer, "H5T_C_S1;");
                goto found_string_type;
            }

            /* If not equal to C variable-length string, check Fortran type. */
            if (H5Tclose(str_type) < 0)
                H5TOOLS_ERROR((-1), "H5Tclose failed");
            str_type = H5Tcopy(H5T_FORTRAN_S1);

            H5Tset_cset(str_type, cset);
            H5Tset_size(str_type, size);
            H5Tset_strpad(str_type, str_pad);

            /* Are the two types equal? */
            if (H5Tequal(tmp_type, str_type)) {
                h5tools_str_append(buffer, "H5T_FORTRAN_S1;");
                goto found_string_type;
            }

            /* Change the endianness and see if they're equal. */
            order = H5Tget_order(tmp_type);
            if (order == H5T_ORDER_LE) {
                if (H5Tset_order(str_type, H5T_ORDER_LE) < 0)
                    H5TOOLS_ERROR((-1), "H5Tset_order failed");
            } /* end if */
            else if (order == H5T_ORDER_BE) {
                if (H5Tset_order(str_type, H5T_ORDER_BE) < 0)
                    H5TOOLS_ERROR((-1), "H5Tset_order failed");
            } /* end if */

            if (H5Tequal(tmp_type, str_type)) {
                h5tools_str_append(buffer, "H5T_FORTRAN_S1;");
                goto found_string_type;
            }

            /* Type doesn't match any of above. */
            h5tools_str_append(buffer, "unknown_one_character_type;");

found_string_type:
            h5tools_render_element(stream, info, ctx, buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                   (hsize_t)0);
            ctx->indent_level--;

            ctx->need_prefix = true;

            h5tools_str_reset(buffer);
            if (H5Tclose(str_type) < 0)
                H5TOOLS_ERROR((-1), "H5Tclose failed");
            if (H5Tclose(tmp_type) < 0)
                H5TOOLS_ERROR((-1), "H5Tclose failed");

            h5tools_str_append(buffer, "%s", h5tools_dump_header_format->strblockend);
            break;

        case H5T_BITFIELD:
            if (H5Tequal(type, H5T_STD_B8BE) == true)
                h5tools_str_append(buffer, "H5T_STD_B8BE");
            else if (H5Tequal(type, H5T_STD_B8LE) == true)
                h5tools_str_append(buffer, "H5T_STD_B8LE");
            else if (H5Tequal(type, H5T_STD_B16BE) == true)
                h5tools_str_append(buffer, "H5T_STD_B16BE");
            else if (H5Tequal(type, H5T_STD_B16LE) == true)
                h5tools_str_append(buffer, "H5T_STD_B16LE");
            else if (H5Tequal(type, H5T_STD_B32BE) == true)
                h5tools_str_append(buffer, "H5T_STD_B32BE");
            else if (H5Tequal(type, H5T_STD_B32LE) == true)
                h5tools_str_append(buffer, "H5T_STD_B32LE");
            else if (H5Tequal(type, H5T_STD_B64BE) == true)
                h5tools_str_append(buffer, "H5T_STD_B64BE");
            else if (H5Tequal(type, H5T_STD_B64LE) == true)
                h5tools_str_append(buffer, "H5T_STD_B64LE");
            else
                h5tools_str_append(buffer, "undefined bitfield");
            break;

        case H5T_OPAQUE:
            h5tools_str_append(buffer, "%s", h5tools_dump_header_format->opaqblockbegin);
            h5tools_render_element(stream, info, ctx, buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                   (hsize_t)0);
            ctx->indent_level++;
            {
                char *ttag;

                if (NULL == (ttag = H5Tget_tag(type)))
                    H5TOOLS_THROW((-1), "H5Tget_tag failed");

                ctx->need_prefix = true;

                h5tools_str_reset(buffer);
                h5tools_str_append(buffer, "OPAQUE_TAG \"%s\";", ttag);
                h5tools_render_element(stream, info, ctx, buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                       (hsize_t)0);

                H5free_memory(ttag);

                if ((size = H5Tget_size(type)) <= 0) {
                    ctx->need_prefix = true;

                    h5tools_str_reset(buffer);
                    h5tools_str_append(buffer, "OPAQUE_SIZE \"%zu\";", size);
                    h5tools_render_element(stream, info, ctx, buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                           (hsize_t)0);
                }
            }
            ctx->indent_level--;

            ctx->need_prefix = true;

            h5tools_str_reset(buffer);
            h5tools_str_append(buffer, "%s", h5tools_dump_header_format->opaqblockend);
            break;

        case H5T_COMPOUND:
            if ((snmembers = H5Tget_nmembers(type)) < 0)
                H5TOOLS_THROW((-1), "H5Tget_nmembers failed");
            nmembers = (unsigned)snmembers;

            h5tools_str_append(buffer, "%s", h5tools_dump_header_format->cmpdblockbegin);
            h5tools_render_element(stream, info, ctx, buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                   (hsize_t)0);

            ctx->indent_level++;
            for (i = 0; i < nmembers; i++) {
                mname = H5Tget_member_name(type, i);
                if ((mtype = H5Tget_member_type(type, i)) >= 0) {
                    ctx->need_prefix = true;

                    h5tools_str_reset(buffer);
                    h5tools_print_datatype(stream, buffer, info, ctx, mtype, true);

                    h5tools_str_append(buffer, " \"%s\";", mname);
                    h5tools_render_element(stream, info, ctx, buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                           (hsize_t)0);
                    if (H5Tclose(mtype) < 0)
                        H5TOOLS_ERROR((-1), "H5Tclose failed");
                }
                else
                    H5TOOLS_ERROR((-1), "H5Tget_member_type failed");
                H5free_memory(mname);
            }
            ctx->indent_level--;

            ctx->need_prefix = true;

            h5tools_str_reset(buffer);
            h5tools_str_append(buffer, "%s", h5tools_dump_header_format->cmpdblockend);
            break;

        case H5T_REFERENCE:
            h5tools_str_append(buffer, "%s", h5tools_dump_header_format->refblockbegin);
            if (H5Tequal(type, H5T_STD_REF_DSETREG) == true) {
                h5tools_str_append(buffer, "H5T_STD_REF_DSETREG");
            }
            else if (H5Tequal(type, H5T_STD_REF_OBJ) == true) {
                h5tools_str_append(buffer, "H5T_STD_REF_OBJECT");
            }
            else if (H5Tequal(type, H5T_STD_REF) == true) {
                h5tools_str_append(buffer, "H5T_STD_REF");
            }
            else {
                h5tools_str_append(buffer, "UNDEFINED");
            }
            h5tools_str_append(buffer, "%s", h5tools_dump_header_format->refblockend);
            break;

        case H5T_ENUM:
            if ((super = H5Tget_super(type)) < 0)
                H5TOOLS_THROW((-1), "H5Tget_super failed");

            h5tools_str_append(buffer, "%s", h5tools_dump_header_format->enumblockbegin);
            h5tools_render_element(stream, info, ctx, buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                   (hsize_t)0);
            ctx->indent_level++;

            ctx->need_prefix = true;

            h5tools_str_reset(buffer);
            h5tools_print_datatype(stream, buffer, info, ctx, super, true);

            if (H5Tclose(super) < 0)
                H5TOOLS_ERROR((-1), "H5Tclose failed");

            h5tools_str_append(buffer, ";");
            h5tools_render_element(stream, info, ctx, buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                   (hsize_t)0);

            h5tools_print_enum(stream, buffer, info, ctx, type);

            ctx->indent_level--;

            ctx->need_prefix = true;

            h5tools_str_reset(buffer);
            h5tools_str_append(buffer, "%s", h5tools_dump_header_format->enumblockend);

            break;

        case H5T_VLEN:
            if ((super = H5Tget_super(type)) < 0)
                H5TOOLS_THROW((-1), "H5Tget_super failed");

            h5tools_str_append(buffer, "%s", h5tools_dump_header_format->vlenblockbegin);

            h5tools_print_datatype(stream, buffer, info, ctx, super, true);

            if (H5Tclose(super) < 0)
                H5TOOLS_ERROR((-1), "H5Tclose failed");

            h5tools_str_append(buffer, "%s", h5tools_dump_header_format->vlenblockend);

            break;

        case H5T_ARRAY:
            h5tools_str_append(buffer, "%s", h5tools_dump_header_format->arrblockbegin);

            /* Get array information */
            if ((sndims = H5Tget_array_ndims(type)) >= 0) {
                unsigned ndims = (unsigned)sndims;

                if (H5Tget_array_dims2(type, dims) >= 0) {
                    /* Print array dimensions */
                    for (i = 0; i < ndims; i++)
                        h5tools_str_append(buffer, "[%" PRIuHSIZE "]", dims[i]);

                    h5tools_str_append(buffer, " ");
                }
                else
                    H5TOOLS_ERROR((-1), "H5Tget_array_dims2 failed");
            }
            else
                H5TOOLS_ERROR((-1), "H5Tget_array_ndims failed");

            /* Get array base type */
            if ((super = H5Tget_super(type)) >= 0) {
                /* Print base type */
                h5tools_print_datatype(stream, buffer, info, ctx, super, true);
                /* Close array base type */
                if (H5Tclose(super) < 0)
                    H5TOOLS_ERROR((-1), "H5Tclose failed");
            }
            else
                H5TOOLS_ERROR((-1), "H5Tget_super failed");

            h5tools_str_append(buffer, "%s", h5tools_dump_header_format->arrblockend);

            break;

        case H5T_NO_CLASS:
        case H5T_NCLASSES:
        default:
            h5tools_str_append(buffer, "unknown datatype");
            break;
    }

    CATCH
    H5TOOLS_ENDDEBUG(" ");
    return ret_value;
}

/*-------------------------------------------------------------------------
 * Function:    print_dataspace
 *
 * Purpose:     print the dataspace.
 *
 * Return:      void
 *
 * In/Out:      h5tools_str_t *buffer
 *              h5tools_context_t *ctx
 *-------------------------------------------------------------------------
 */
int
h5tools_print_dataspace(h5tools_str_t *buffer, hid_t space)
{
    hsize_t     size[H5TOOLS_DUMP_MAX_RANK];
    hsize_t     maxsize[H5TOOLS_DUMP_MAX_RANK];
    int         ndims      = -1;
    H5S_class_t space_type = -1;
    bool        past_catch = false;
    int         i;
    int         ret_value = 0;

    H5TOOLS_START_DEBUG(" ");
    if ((ndims = H5Sget_simple_extent_dims(space, size, maxsize)) < 0)
        H5TOOLS_THROW((-1), "H5Sget_simple_extent_dims failed");

    if ((space_type = H5Sget_simple_extent_type(space)) < 0)
        H5TOOLS_THROW((-1), "H5Sget_simple_extent_type failed");

    switch (space_type) {
        case H5S_SCALAR:
            /* scalar dataspace */
            h5tools_str_append(buffer, "%s %s", h5tools_dump_header_format->dataspacedescriptionbegin,
                               S_SCALAR);
            break;

        case H5S_SIMPLE:
            /* simple dataspace */
            h5tools_str_append(buffer, "%s %s { %s %" PRIuHSIZE,
                               h5tools_dump_header_format->dataspacedescriptionbegin, S_SIMPLE,
                               h5tools_dump_header_format->dataspacedimbegin, size[0]);

            for (i = 1; i < ndims; i++)
                h5tools_str_append(buffer, ", %" PRIuHSIZE, size[i]);

            h5tools_str_append(buffer, " %s / ", h5tools_dump_header_format->dataspacedimend);

            if (maxsize[0] == H5S_UNLIMITED)
                h5tools_str_append(buffer, "%s %s", h5tools_dump_header_format->dataspacedimbegin,
                                   "H5S_UNLIMITED");
            else
                h5tools_str_append(buffer, "%s %" PRIuHSIZE, h5tools_dump_header_format->dataspacedimbegin,
                                   maxsize[0]);

            for (i = 1; i < ndims; i++)
                if (maxsize[i] == H5S_UNLIMITED)
                    h5tools_str_append(buffer, ", %s", "H5S_UNLIMITED");
                else
                    h5tools_str_append(buffer, ", %" PRIuHSIZE, maxsize[i]);

            h5tools_str_append(buffer, " %s }", h5tools_dump_header_format->dataspacedimend);
            break;

        case H5S_NULL:
            /* null dataspace */
            h5tools_str_append(buffer, "%s %s", h5tools_dump_header_format->dataspacedescriptionbegin,
                               S_NULL);
            break;

        case H5S_NO_CLASS:
        default:
            h5tools_str_append(buffer, "%s unknown dataspace %s\n", BEGIN, END);
            break;
    } /* end switch */

    CATCH
    H5TOOLS_ENDDEBUG(" ");
    return ret_value;
}

/*-------------------------------------------------------------------------
 * Function:    print_enum
 *
 * Purpose:     prints the enum data
 *
 * Return:      void
 *
 * In/Out:      h5tools_str_t *buffer
 *              h5tools_context_t *ctx
 *
 *-----------------------------------------------------------------------*/
int
h5tools_print_enum(FILE *stream, h5tools_str_t *buffer, const h5tool_format_t *info, h5tools_context_t *ctx,
                   hid_t type)
{
    char         **name  = NULL; /*member names                   */
    unsigned char *value = NULL; /*value array                    */
    unsigned       i;
    unsigned       nmembs = 0; /*number of members              */
    int            snmembs;
    hid_t          super  = H5I_INVALID_HID; /*enum base integer type         */
    hid_t          native = H5I_INVALID_HID; /*native integer datatype        */
    H5T_sign_t     sign_type;                /*sign of value type             */
    size_t         type_size;                /*value type size                */
    size_t         dst_size;                 /*destination value type size    */
    size_t         ncols      = 80;          /*available output width */
    hsize_t        curr_pos   = 0;           /* total data element position   */
    bool           past_catch = false;
    int            ret_value  = 0;

    H5TOOLS_START_DEBUG(" ");
    if (info->line_ncols > 0)
        ncols = info->line_ncols;

    if ((snmembs = H5Tget_nmembers(type)) < 0)
        H5TOOLS_THROW((-1), "H5Tget_nmembers failed");
    nmembs = (unsigned)snmembs;
    assert(nmembs > 0);

    if ((super = H5Tget_super(type)) < 0)
        H5TOOLS_THROW((-1), "H5Tget_super failed");

    if ((type_size = H5Tget_size(type)) <= 0)
        H5TOOLS_THROW((-1), "H5Tget_size(type) failed");

    /*
     * Determine what datatype to use for the native values.  To simplify
     * things we entertain three possibilities:
     *  1. long long -- the largest native signed integer
     *  2. unsigned long long -- the largest native unsigned integer
     *  3. raw format
     */
    if (type_size <= sizeof(long long)) {
        dst_size = sizeof(long long);

        if ((sign_type = H5Tget_sign(type)) < 0)
            H5TOOLS_THROW((-1), "H5Tget_sign failed");
        if (H5T_SGN_NONE == sign_type)
            native = H5T_NATIVE_ULLONG;
        else
            native = H5T_NATIVE_LLONG;
    } /* end if */
    else
        dst_size = type_size;

    /* Get the names and raw values of all members */
    if (NULL == (name = (char **)calloc((size_t)nmembs, sizeof(char *))))
        H5TOOLS_THROW((-1), "Could not allocate buffer for member name");
    if (NULL == (value = (unsigned char *)calloc((size_t)nmembs, MAX(type_size, dst_size))))
        H5TOOLS_THROW((-1), "Could not allocate buffer for member value");

    for (i = 0; i < nmembs; i++) {
        name[i] = H5Tget_member_name(type, i);
        if (H5Tget_member_value(type, i, value + i * type_size) < 0)
            H5TOOLS_THROW((-1), "H5Tget_member_value failed");
    }

    /* Convert values to native datatype */
    if (native > 0)
        if (H5Tconvert(super, native, (size_t)nmembs, value, NULL, H5P_DEFAULT) < 0)
            H5TOOLS_THROW((-1), "H5Tconvert failed");

    /*
     * Sort members by increasing value
     *    ***not implemented yet***
     */

    /* Print members */
    for (i = 0; i < nmembs; i++) {
        int nchars; /*number of output characters    */

        ctx->need_prefix = true;
        h5tools_simple_prefix(stream, info, ctx, (hsize_t)0, 0);

        h5tools_str_reset(buffer);
        h5tools_str_append(buffer, "\"%s\"", name[i]);
        nchars = (int)strlen(name[i]);
        h5tools_str_append(buffer, "%*s ", MAX(0, 16 - nchars), "");

        if (native < 0) {
            size_t j;

            h5tools_str_append(buffer, "0x");

            for (j = 0; j < dst_size; j++)
                h5tools_str_append(buffer, "%02x", value[i * dst_size + j]);
        }
        else if (H5T_SGN_NONE == H5Tget_sign(native)) {
            unsigned long long copy;

            memcpy(&copy, value + i * dst_size, sizeof(copy));
            h5tools_str_append(buffer, "%llu", copy);
        }
        else {
            long long copy;

            memcpy(&copy, value + i * dst_size, sizeof(copy));
            h5tools_str_append(buffer, "%lld", copy);
        }

        h5tools_str_append(buffer, ";");
        h5tools_render_element(stream, info, ctx, buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);
    }

    CATCH
    if (name) {
        /* Release resources */
        for (i = 0; i < nmembs; i++)
            if (name[i])
                H5free_memory(name[i]);
        free(name);
    } /* end if */

    if (value)
        free(value);

    if (super >= 0 && H5Tclose(super) < 0)
        H5TOOLS_THROW((-1), "Could not close datatype's super class");

    if (0 == nmembs)
        h5tools_str_append(buffer, "\n<empty>");

    H5TOOLS_ENDDEBUG(" ");
    return ret_value;
}

/*-------------------------------------------------------------------------
 * Function:    dump_datatype
 *
 * Purpose:     Dump the datatype. Datatype can be HDF5 predefined
 *              atomic datatype or committed/transient datatype.
 *
 * Return:      void
 *
 * In/Out:      h5tools_context_t *ctx
 *-------------------------------------------------------------------------
 */
void
h5tools_dump_datatype(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hid_t type)
{
    h5tools_str_t buffer;                 /* string into which to render   */
    size_t        ncols    = 80;          /* available output width        */
    hsize_t       curr_pos = ctx->sm_pos; /* total data element position   */
                                          /* pass to the prefix in h5tools_simple_prefix the total position
                                           * instead of the current stripmine position i; this is necessary
                                           * to print the array indices
                                           */

    /* setup */
    memset(&buffer, 0, sizeof(h5tools_str_t));

    if (info->line_ncols > 0)
        ncols = info->line_ncols;

    ctx->need_prefix = true;

    h5tools_str_reset(&buffer);
    h5tools_str_append(&buffer, "%s %s ", h5tools_dump_header_format->datatypebegin,
                       h5tools_dump_header_format->datatypeblockbegin);
    h5tools_print_datatype(stream, &buffer, info, ctx, type, true);
    if (strlen(h5tools_dump_header_format->datatypeblockend)) {
        h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->datatypeblockend);
        if (strlen(h5tools_dump_header_format->datatypeend))
            h5tools_str_append(&buffer, " ");
    }
    if (strlen(h5tools_dump_header_format->datatypeend))
        h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->datatypeend);

    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);

    h5tools_str_close(&buffer);
}

/*-------------------------------------------------------------------------
 * Function:    dump_dataspace
 *
 * Purpose:     Dump the dataspace.
 *
 * Return:      void
 *
 * In/Out:      h5tools_context_t *ctx
 *-------------------------------------------------------------------------
 */
void
h5tools_dump_dataspace(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hid_t type)
{
    h5tools_str_t buffer;                 /* string into which to render   */
    size_t        ncols    = 80;          /* available output width        */
    hsize_t       curr_pos = ctx->sm_pos; /* total data element position   */
                                          /* pass to the prefix in h5tools_simple_prefix the total position
                                           * instead of the current stripmine position i; this is necessary
                                           * to print the array indices
                                           */

    /* setup */
    memset(&buffer, 0, sizeof(h5tools_str_t));

    if (info->line_ncols > 0)
        ncols = info->line_ncols;

    ctx->need_prefix = true;

    h5tools_str_reset(&buffer);
    h5tools_str_append(&buffer, "%s ", h5tools_dump_header_format->dataspacebegin);

    h5tools_print_dataspace(&buffer, type);

    if (strlen(h5tools_dump_header_format->dataspaceblockend)) {
        h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->dataspaceblockend);
        if (strlen(h5tools_dump_header_format->dataspaceend))
            h5tools_str_append(&buffer, " ");
    }
    if (strlen(h5tools_dump_header_format->dataspaceend))
        h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->dataspaceend);

    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);

    h5tools_str_close(&buffer);
}

/*-------------------------------------------------------------------------
 * Function:    dump_oid
 *
 * Purpose:     Dump the oid.
 *
 * Return:      void
 *
 * In/Out:      h5tools_context_t *ctx
 *-------------------------------------------------------------------------
 */
void
h5tools_dump_oid(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hid_t oid)
{
    h5tools_str_t buffer;                 /* string into which to render   */
    size_t        ncols    = 80;          /* available output width        */
    hsize_t       curr_pos = ctx->sm_pos; /* total data element position   */
                                          /* pass to the prefix in h5tools_simple_prefix the total position
                                           * instead of the current stripmine position i; this is necessary
                                           * to print the array indices
                                           */

    /* setup */
    memset(&buffer, 0, sizeof(h5tools_str_t));

    if (info->line_ncols > 0)
        ncols = info->line_ncols;

    ctx->need_prefix = true;

    h5tools_str_reset(&buffer);
    h5tools_str_append(&buffer, "%s %s %" PRId64 " %s", OBJID, BEGIN, oid, END);
    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);

    h5tools_str_close(&buffer);
}

/*-------------------------------------------------------------------------
 * Function:    print_virtual_selection
 *
 * Purpose:     Print the virtual dataset selection.
 *
 * Return:      void
 *-------------------------------------------------------------------------
 */
static void
h5tools_print_virtual_selection(hid_t vspace, FILE *stream, const h5tool_format_t *info,
                                h5tools_context_t *ctx,      /* in,out*/
                                h5tools_str_t     *buffer,   /* string into which to render */
                                hsize_t           *curr_pos, /* total data element position */
                                size_t             ncols)
{
    switch (H5Sget_select_type(vspace)) {
        case H5S_SEL_NONE: /* Nothing selected         */
            ctx->need_prefix = true;

            h5tools_str_reset(buffer);
            h5tools_str_append(buffer, "%s", VDS_NONE);
            break;
        case H5S_SEL_POINTS: /* Sequence of points selected  */
            h5tools_str_reset(buffer);
            h5tools_str_append(buffer, "%s %s ", VDS_POINT,
                               h5tools_dump_header_format->virtualselectionblockbegin);
            h5tools_str_dump_space_points(buffer, vspace, info);
            h5tools_str_append(buffer, " %s", h5tools_dump_header_format->virtualselectionblockend);
            break;
        case H5S_SEL_HYPERSLABS: /* "New-style" hyperslab selection defined  */
            ctx->need_prefix = true;

            h5tools_str_reset(buffer);
            if (H5Sis_regular_hyperslab(vspace)) {
                h5tools_str_append(buffer, "%s %s ", VDS_REG_HYPERSLAB,
                                   h5tools_dump_header_format->virtualselectionblockbegin);
                h5tools_render_element(stream, info, ctx, buffer, curr_pos, (size_t)ncols, (hsize_t)0,
                                       (hsize_t)0);

                h5tools_str_reset(buffer);
                h5tools_str_dump_space_slabs(buffer, vspace, info, ctx);
            }
            else {
                h5tools_str_append(buffer, "%s %s ", VDS_IRR_HYPERSLAB,
                                   h5tools_dump_header_format->virtualselectionblockbegin);
                h5tools_render_element(stream, info, ctx, buffer, curr_pos, (size_t)ncols, (hsize_t)0,
                                       (hsize_t)0);
                ctx->indent_level++;
                ctx->need_prefix = true;
                h5tools_simple_prefix(stream, info, ctx, *curr_pos, 0);

                h5tools_str_reset(buffer);
                h5tools_str_dump_space_blocks(buffer, vspace, info);
                ctx->indent_level--;
            }
            h5tools_render_element(stream, info, ctx, buffer, curr_pos, (size_t)ncols, (hsize_t)0,
                                   (hsize_t)0);
            ctx->need_prefix = true;

            h5tools_str_reset(buffer);
            h5tools_str_append(buffer, "%s", h5tools_dump_header_format->virtualselectionblockend);
            break;
        case H5S_SEL_ALL: /* Entire extent selected   */
            ctx->need_prefix = true;

            h5tools_str_reset(buffer);
            h5tools_str_append(buffer, "%s", VDS_ALL);
            break;
        case H5S_SEL_ERROR:
        case H5S_SEL_N:
        default:
            h5tools_str_append(buffer, "Unknown Selection");
    }
    h5tools_render_element(stream, info, ctx, buffer, curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);
}

/*-------------------------------------------------------------------------
 * Function:    dump_fill_value
 *
 * Purpose:     prints the fill value
 *
 * Return:      void
 *-------------------------------------------------------------------------
 */
void
h5tools_print_fill_value(h5tools_str_t *buffer /*in,out*/, const h5tool_format_t *info,
                         h5tools_context_t *ctx /*in,out*/, hid_t dcpl, hid_t type_id, hid_t obj_id)
{
    size_t size;
    hid_t  n_type  = H5I_INVALID_HID;
    void  *buf     = NULL;
    bool   vl_data = false;

    n_type = H5Tget_native_type(type_id, H5T_DIR_DEFAULT);

    if (h5tools_detect_vlen(type_id) == true)
        vl_data = true;

    size = H5Tget_size(n_type);
    buf  = malloc(size);

    H5Pget_fill_value(dcpl, n_type, buf);

    h5tools_str_sprint(buffer, info, obj_id, n_type, buf, ctx);

    H5Tclose(n_type);

    if (vl_data) {
        hsize_t dims[1]  = {1};
        hid_t   space_id = H5I_INVALID_HID;

        space_id = H5Screate_simple(1, dims, NULL);

        H5Treclaim(type_id, space_id, H5P_DEFAULT, buf);

        H5Sclose(space_id);
    }

    if (buf)
        free(buf);
}

/*-------------------------------------------------------------------------
 * Function:    dump_dcpl
 *
 * Purpose:     prints several dataset create property list properties
 *
 * Return:      void
 *-------------------------------------------------------------------------
 */
void
h5tools_dump_dcpl(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hid_t dcpl_id,
                  hid_t type_id, hid_t dset_id)
{
    int              nfilters = -1; /* number of filters */
    int              rank;          /* rank */
    int              i;
    unsigned         j;
    unsigned         filt_flags;    /* filter flags */
    unsigned         cd_values[20]; /* filter client data values */
    unsigned         szip_options_mask;
    unsigned         szip_pixels_per_block;
    H5Z_filter_t     filtn; /* filter identification number */
    H5D_fill_value_t fvstatus = H5D_FILL_VALUE_ERROR;
    H5D_alloc_time_t at       = H5D_ALLOC_TIME_ERROR;
    H5D_fill_time_t  ft       = H5D_FILL_TIME_ERROR;
    H5D_layout_t     stl      = H5D_LAYOUT_ERROR;
    size_t           ncols    = 80; /* available output width        */
    size_t           cd_nelmts;     /* filter client number of values */
    off_t            offset;        /* offset of external file     */
    char             f_name[256];   /* filter name */
    char             name[256];     /* external or virtual file name       */
    hsize_t          chsize[64];    /* chunk size in elements */
    hsize_t          size;          /* size of external file   */
    hsize_t          storage_size;
    hsize_t          curr_pos = 0; /* total data element position   */
    h5tools_str_t    buffer;       /* string into which to render   */

    /* setup */
    memset(&buffer, 0, sizeof(h5tools_str_t));
    if (info->line_ncols > 0)
        ncols = info->line_ncols;

    storage_size = H5Dget_storage_size(dset_id);
    if (dcpl_id >= 0)
        nfilters = H5Pget_nfilters(dcpl_id);

    strcpy(f_name, "\0");

    /*-------------------------------------------------------------------------
     * STORAGE_LAYOUT
     *-------------------------------------------------------------------------
     */
    ctx->need_prefix = true;

    h5tools_str_reset(&buffer);
    h5tools_str_append(&buffer, "%s %s", STORAGE_LAYOUT, BEGIN);
    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);

    if (dcpl_id >= 0)
        stl = H5Pget_layout(dcpl_id);

    switch (stl) {
        case H5D_CHUNKED:
            ctx->indent_level++;
            ctx->need_prefix = true;

            h5tools_str_reset(&buffer);
            h5tools_str_append(&buffer, "%s ", CHUNKED);

            rank = H5Pget_chunk(dcpl_id, (int)NELMTS(chsize), chsize);
            h5tools_str_append(&buffer, "%s %" PRIuHSIZE, h5tools_dump_header_format->dataspacedimbegin,
                               chsize[0]);
            for (i = 1; i < rank; i++)
                h5tools_str_append(&buffer, ", %" PRIuHSIZE, chsize[i]);
            h5tools_str_append(&buffer, " %s", h5tools_dump_header_format->dataspacedimend);
            h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                   (hsize_t)0);

            ctx->need_prefix = true;

            h5tools_str_reset(&buffer);

            /* if there are filters, print a compression ratio */
            if (nfilters) {
                hsize_t dims[H5S_MAX_RANK];
                hsize_t nelmts = 1;
                double  ratio  = 0;
                int     ok     = 0;

                hid_t  tid        = H5Dget_type(dset_id);
                hid_t  sid        = H5Dget_space(dset_id);
                size_t datum_size = H5Tget_size(tid);
                int    ndims      = H5Sget_simple_extent_dims(sid, dims, NULL);

                /* only print the compression ratio for these filters */
                for (i = 0; i < nfilters && !ok; i++) {
                    cd_nelmts = NELMTS(cd_values);
                    filtn     = H5Pget_filter2(dcpl_id, (unsigned)i, &filt_flags, &cd_nelmts, cd_values,
                                               sizeof(f_name), f_name, NULL);
                    ok        = (filtn >= 0);
                }

                if (ndims && ok) {
                    hsize_t uncomp_size;

                    for (i = 0; i < ndims; i++) {
                        nelmts *= dims[i];
                    }
                    uncomp_size = nelmts * datum_size;

                    /* compression ratio = uncompressed size /  compressed size */

                    if (storage_size != 0)
                        ratio = (double)uncomp_size / (double)storage_size;

                    h5tools_str_append(&buffer, "SIZE %" PRIuHSIZE " (%.3f:1 COMPRESSION)", storage_size,
                                       ratio);
                }
                else
                    h5tools_str_append(&buffer, "SIZE %" PRIuHSIZE, storage_size);

                H5Sclose(sid);
                H5Tclose(tid);
            }
            else {
                h5tools_str_append(&buffer, "SIZE %" PRIuHSIZE, storage_size);
            }
            h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                   (hsize_t)0);
            ctx->indent_level--;
            break;
        case H5D_COMPACT:
            ctx->indent_level++;
            ctx->need_prefix = true;

            h5tools_str_reset(&buffer);
            h5tools_str_append(&buffer, "%s", COMPACT);
            h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                   (hsize_t)0);

            ctx->need_prefix = true;

            h5tools_str_reset(&buffer);
            h5tools_str_append(&buffer, "SIZE %" PRIuHSIZE, storage_size);
            h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                   (hsize_t)0);
            ctx->indent_level--;
            break;
        case H5D_CONTIGUOUS: {
            int n_external;

            n_external = H5Pget_external_count(dcpl_id);

            ctx->indent_level++;
            if (n_external) {

                /* EXTERNAL FILE */

                ctx->need_prefix = true;

                h5tools_str_reset(&buffer);
                h5tools_str_append(&buffer, "%s", CONTIGUOUS);
                h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                       (hsize_t)0);

                ctx->need_prefix = true;

                h5tools_str_reset(&buffer);
                h5tools_str_append(&buffer, "%s %s", EXTERNAL, BEGIN);
                h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                       (hsize_t)0);

                ctx->indent_level++;
                for (j = 0; j < (unsigned)n_external; j++) {
                    H5Pget_external(dcpl_id, j, sizeof(name), name, &offset, &size);

                    ctx->need_prefix = true;

                    h5tools_str_reset(&buffer);
                    h5tools_str_append(&buffer, "FILENAME %s SIZE %" PRIuHSIZE, name, size);
                    /* Using %lld with a cast to (long long) is probably the only portable
                     * way to print off_t values. There's no real standard for off_t other
                     * than it must be signed, according to POSIX.
                     */
                    h5tools_str_append(&buffer, " OFFSET %lld", (long long)offset);
                    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                           (hsize_t)0);
                }
                ctx->indent_level--;

                ctx->need_prefix = true;

                h5tools_str_reset(&buffer);
                h5tools_str_append(&buffer, "%s", END);
                h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                       (hsize_t)0);
            }
            else {
                haddr_t  ioffset;
                uint64_t supported = 0;

                /* NORMAL FILE */

                ctx->need_prefix = true;

                h5tools_str_reset(&buffer);
                h5tools_str_append(&buffer, "%s", CONTIGUOUS);
                h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                       (hsize_t)0);

                ctx->need_prefix = true;

                h5tools_str_reset(&buffer);
                h5tools_str_append(&buffer, "SIZE %" PRIuHSIZE, storage_size);
                h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                       (hsize_t)0);

                /* Only dump the offset if the VOL connector implements
                 * the functionality.
                 */
                H5VLquery_optional(dset_id, H5VL_SUBCLS_DATASET, H5VL_NATIVE_DATASET_GET_OFFSET, &supported);

                if (supported & H5VL_OPT_QUERY_SUPPORTED) {

                    ctx->need_prefix = true;

                    h5tools_str_reset(&buffer);
                    ioffset = H5Dget_offset(dset_id);
                    if (HADDR_UNDEF == ioffset)
                        h5tools_str_append(&buffer, "OFFSET HADDR_UNDEF");
                    else
                        h5tools_str_append(&buffer, "OFFSET %" PRIuHADDR, ioffset);
                    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                           (hsize_t)0);
                }
            }
            ctx->indent_level--;
        } break;

        case H5D_VIRTUAL: {
            char   dsetname[256]; /* virtual dataset name       */
            size_t n_vmaps;

            H5Pget_virtual_count(dcpl_id, &n_vmaps);

            if (n_vmaps) {
                size_t                        curr_vmap;
                ssize_t H5_ATTR_NDEBUG_UNUSED ssize_out;

                ctx->indent_level++;
                for (curr_vmap = 0; curr_vmap < n_vmaps; curr_vmap++) {
                    hid_t virtual_vspace   = H5Pget_virtual_vspace(dcpl_id, curr_vmap);
                    hid_t virtual_srcspace = H5Pget_virtual_srcspace(dcpl_id, curr_vmap);

                    ctx->need_prefix = true;

                    h5tools_str_reset(&buffer);
                    h5tools_str_append(&buffer, "%s %zu %s ", VDS_MAPPING, curr_vmap, BEGIN);
                    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                           (hsize_t)0);

                    ctx->indent_level++;

                    ctx->need_prefix = true;

                    h5tools_str_reset(&buffer);
                    h5tools_str_append(&buffer, "%s %s", VDS_VIRTUAL, BEGIN);
                    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                           (hsize_t)0);

                    ctx->indent_level++;

                    h5tools_print_virtual_selection(virtual_vspace, stream, info, ctx, &buffer, &curr_pos,
                                                    (size_t)ncols);

                    ctx->indent_level--;

                    ctx->need_prefix = true;

                    h5tools_str_reset(&buffer);
                    h5tools_str_append(&buffer, "%s", END);
                    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                           (hsize_t)0);

                    ctx->need_prefix = true;

                    h5tools_str_reset(&buffer);
                    h5tools_str_append(&buffer, "%s %s", VDS_SOURCE, BEGIN);
                    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                           (hsize_t)0);

                    ctx->indent_level++;

                    ssize_out = H5Pget_virtual_filename(dcpl_id, curr_vmap, NULL, 0);
                    assert(ssize_out > 0);
                    assert((size_t)ssize_out < sizeof(name));
                    H5Pget_virtual_filename(dcpl_id, curr_vmap, name, sizeof(name));
                    ssize_out = H5Pget_virtual_dsetname(dcpl_id, curr_vmap, NULL, 0);
                    assert(ssize_out > 0);
                    assert((size_t)ssize_out < sizeof(name));
                    H5Pget_virtual_dsetname(dcpl_id, curr_vmap, dsetname, sizeof(dsetname));

                    ctx->need_prefix = true;

                    h5tools_str_reset(&buffer);
                    h5tools_str_append(&buffer, "%s %s", VDS_SRC_FILE,
                                       h5tools_dump_header_format->virtualfilenamebegin);
                    h5tools_str_append(&buffer, "%s", name);
                    h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->virtualfilenameend);
                    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                           (hsize_t)0);

                    ctx->need_prefix = true;

                    h5tools_str_reset(&buffer);
                    h5tools_str_append(&buffer, "%s %s", VDS_SRC_DATASET,
                                       h5tools_dump_header_format->virtualdatasetnamebegin);
                    h5tools_str_append(&buffer, "%s", dsetname);
                    h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->virtualdatasetnameend);
                    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                           (hsize_t)0);

                    h5tools_print_virtual_selection(virtual_srcspace, stream, info, ctx, &buffer, &curr_pos,
                                                    (size_t)ncols);

                    ctx->indent_level--;

                    ctx->need_prefix = true;

                    h5tools_str_reset(&buffer);
                    h5tools_str_append(&buffer, "%s", END);
                    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                           (hsize_t)0);

                    ctx->indent_level--;

                    ctx->need_prefix = true;

                    h5tools_str_reset(&buffer);
                    h5tools_str_append(&buffer, "%s", END);
                    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                           (hsize_t)0);
                }
                ctx->indent_level--;
            }
        } break;

        case H5D_LAYOUT_ERROR:
        case H5D_NLAYOUTS:
        default:
            h5tools_str_reset(&buffer);
            h5tools_str_append(&buffer, "%s", "Unknown layout");
            h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                   (hsize_t)0);
    } /*switch*/

    ctx->need_prefix = true;

    h5tools_str_reset(&buffer);
    h5tools_str_append(&buffer, "%s", END);
    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);

    /*-------------------------------------------------------------------------
     * FILTERS
     *-------------------------------------------------------------------------
     */
    if (H5D_VIRTUAL != stl) {
        ctx->need_prefix = true;

        h5tools_str_reset(&buffer);
        h5tools_str_append(&buffer, "%s %s", FILTERS, BEGIN);
        h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);

        ctx->indent_level++;

        if (nfilters) {
            for (i = 0; i < nfilters; i++) {
                cd_nelmts = NELMTS(cd_values);
                filtn     = H5Pget_filter2(dcpl_id, (unsigned)i, &filt_flags, &cd_nelmts, cd_values,
                                           sizeof(f_name), f_name, NULL);

                if (filtn < 0)
                    continue; /* nothing to print for invalid filter */

                ctx->need_prefix = true;

                h5tools_str_reset(&buffer);
                switch (filtn) {
                    case H5Z_FILTER_DEFLATE:
                        h5tools_str_append(&buffer, "%s %s %s %d %s", DEFLATE, BEGIN, DEFLATE_LEVEL,
                                           cd_values[0], END);
                        h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols,
                                               (hsize_t)0, (hsize_t)0);
                        break;
                    case H5Z_FILTER_SHUFFLE:
                        h5tools_str_append(&buffer, "%s", SHUFFLE);
                        h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols,
                                               (hsize_t)0, (hsize_t)0);
                        break;
                    case H5Z_FILTER_FLETCHER32:
                        h5tools_str_append(&buffer, "%s", FLETCHER32);
                        h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols,
                                               (hsize_t)0, (hsize_t)0);
                        break;
                    case H5Z_FILTER_SZIP:
                        szip_options_mask     = cd_values[0];
                        szip_pixels_per_block = cd_values[1];

                        h5tools_str_append(&buffer, "%s %s", SZIP, BEGIN);
                        h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols,
                                               (hsize_t)0, (hsize_t)0);

                        ctx->indent_level++;

                        ctx->need_prefix = true;

                        h5tools_str_reset(&buffer);
                        h5tools_str_append(&buffer, "PIXELS_PER_BLOCK %d", szip_pixels_per_block);
                        h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols,
                                               (hsize_t)0, (hsize_t)0);

                        ctx->need_prefix = true;

                        h5tools_str_reset(&buffer);
                        if (szip_options_mask & H5_SZIP_CHIP_OPTION_MASK)
                            h5tools_str_append(&buffer, "MODE %s", "HARDWARE");
                        else if (szip_options_mask & H5_SZIP_ALLOW_K13_OPTION_MASK)
                            h5tools_str_append(&buffer, "MODE %s", "K13");
                        h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols,
                                               (hsize_t)0, (hsize_t)0);

                        ctx->need_prefix = true;

                        h5tools_str_reset(&buffer);
                        if (szip_options_mask & H5_SZIP_EC_OPTION_MASK)
                            h5tools_str_append(&buffer, "CODING %s", "ENTROPY");
                        else if (szip_options_mask & H5_SZIP_NN_OPTION_MASK)
                            h5tools_str_append(&buffer, "CODING %s", "NEAREST NEIGHBOUR");
                        h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols,
                                               (hsize_t)0, (hsize_t)0);

                        ctx->need_prefix = true;

                        h5tools_str_reset(&buffer);
                        if (szip_options_mask & H5_SZIP_LSB_OPTION_MASK)
                            h5tools_str_append(&buffer, "BYTE_ORDER %s", "LSB");
                        else if (szip_options_mask & H5_SZIP_MSB_OPTION_MASK)
                            h5tools_str_append(&buffer, "BYTE_ORDER %s", "MSB");
                        h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols,
                                               (hsize_t)0, (hsize_t)0);

                        if (szip_options_mask & H5_SZIP_RAW_OPTION_MASK) {
                            ctx->need_prefix = true;

                            h5tools_str_reset(&buffer);
                            h5tools_str_append(&buffer, "HEADER %s", "RAW");
                            h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols,
                                                   (hsize_t)0, (hsize_t)0);
                        }

                        ctx->indent_level--;

                        ctx->need_prefix = true;

                        h5tools_str_reset(&buffer);
                        h5tools_str_append(&buffer, "%s", END);
                        h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols,
                                               (hsize_t)0, (hsize_t)0);
                        break;
                    case H5Z_FILTER_NBIT:
                        h5tools_str_append(&buffer, "%s", NBIT);
                        h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols,
                                               (hsize_t)0, (hsize_t)0);
                        break;
                    case H5Z_FILTER_SCALEOFFSET:
                        h5tools_str_append(&buffer, "%s %s %s %d %s", SCALEOFFSET, BEGIN, SCALEOFFSET_MINBIT,
                                           cd_values[0], END);
                        h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols,
                                               (hsize_t)0, (hsize_t)0);
                        break;
                    default:
                        h5tools_str_append(&buffer, "%s %s", "USER_DEFINED_FILTER", BEGIN);
                        h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols,
                                               (hsize_t)0, (hsize_t)0);

                        ctx->indent_level++;

                        ctx->need_prefix = true;

                        h5tools_str_reset(&buffer);
                        h5tools_str_append(&buffer, "FILTER_ID %d", filtn);
                        h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols,
                                               (hsize_t)0, (hsize_t)0);

                        if (f_name[0] != '\0') {
                            ctx->need_prefix = true;

                            h5tools_str_reset(&buffer);
                            h5tools_str_append(&buffer, "COMMENT %s", f_name);
                            h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols,
                                                   (hsize_t)0, (hsize_t)0);
                        }
                        if (cd_nelmts) {
                            ctx->need_prefix = true;

                            h5tools_str_reset(&buffer);
                            h5tools_str_append(&buffer, "%s %s ", "PARAMS", BEGIN);
                            for (j = 0; j < cd_nelmts; j++)
                                h5tools_str_append(&buffer, "%d ", cd_values[j]);
                            h5tools_str_append(&buffer, "%s", END);
                            h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols,
                                                   (hsize_t)0, (hsize_t)0);
                        }
                        ctx->indent_level--;

                        ctx->need_prefix = true;

                        h5tools_str_reset(&buffer);
                        h5tools_str_append(&buffer, "%s", END);
                        h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols,
                                               (hsize_t)0, (hsize_t)0);
                        break;
                } /*switch*/
            }     /*i*/
        }         /*nfilters*/
        else {
            ctx->need_prefix = true;

            h5tools_str_reset(&buffer);
            h5tools_str_append(&buffer, "NONE");
            h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                   (hsize_t)0);
        }
        ctx->indent_level--;

        ctx->need_prefix = true;

        h5tools_str_reset(&buffer);
        h5tools_str_append(&buffer, "%s", END);
        h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);
    } /* end if (H5D_VIRTUAL != stl) */

    /*-------------------------------------------------------------------------
     * FILLVALUE
     *-------------------------------------------------------------------------
     */
    ctx->need_prefix = true;

    h5tools_str_reset(&buffer);
    h5tools_str_append(&buffer, "%s %s", FILLVALUE, BEGIN);
    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);

    ctx->indent_level++;

    ctx->need_prefix = true;

    h5tools_str_reset(&buffer);
    h5tools_str_append(&buffer, "FILL_TIME ");

    if (dcpl_id >= 0)
        H5Pget_fill_time(dcpl_id, &ft);

    switch (ft) {
        case H5D_FILL_TIME_ALLOC:
            h5tools_str_append(&buffer, "%s", "H5D_FILL_TIME_ALLOC");
            break;
        case H5D_FILL_TIME_NEVER:
            h5tools_str_append(&buffer, "%s", "H5D_FILL_TIME_NEVER");
            break;
        case H5D_FILL_TIME_IFSET:
            h5tools_str_append(&buffer, "%s", "H5D_FILL_TIME_IFSET");
            break;
        case H5D_FILL_TIME_ERROR:
        default:
            h5tools_str_append(&buffer, "%s", "INVALID");
            break;
    }
    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);

    ctx->need_prefix = true;

    h5tools_str_reset(&buffer);
    h5tools_str_append(&buffer, "%s ", "VALUE ");

    if (dcpl_id >= 0)
        H5Pfill_value_defined(dcpl_id, &fvstatus);

    switch (fvstatus) {
        case H5D_FILL_VALUE_UNDEFINED:
            h5tools_str_append(&buffer, "%s", "H5D_FILL_VALUE_UNDEFINED");
            break;
        case H5D_FILL_VALUE_DEFAULT:
            h5tools_str_append(&buffer, "%s", "H5D_FILL_VALUE_DEFAULT");
            break;
        case H5D_FILL_VALUE_USER_DEFINED:
            ctx->indent_level--;
            h5tools_print_fill_value(&buffer, info, ctx, dcpl_id, type_id, dset_id);
            ctx->indent_level++;
            break;
        case H5D_FILL_VALUE_ERROR:
        default:
            h5tools_str_append(&buffer, "%s", "INVALID");
            break;
    }
    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);
    ctx->indent_level--;

    ctx->need_prefix = true;

    h5tools_str_reset(&buffer);
    h5tools_str_append(&buffer, "%s", END);
    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);

    /*-------------------------------------------------------------------------
     * ALLOCATION_TIME
     *-------------------------------------------------------------------------
     */
    if (H5D_VIRTUAL != stl) {
        ctx->need_prefix = true;

        h5tools_str_reset(&buffer);
        h5tools_str_append(&buffer, "ALLOCATION_TIME %s", BEGIN);
        h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);

        ctx->indent_level++;

        ctx->need_prefix = true;

        h5tools_str_reset(&buffer);

        if (dcpl_id >= 0)
            H5Pget_alloc_time(dcpl_id, &at);

        switch (at) {
            case H5D_ALLOC_TIME_EARLY:
                h5tools_str_append(&buffer, "%s", "H5D_ALLOC_TIME_EARLY");
                break;
            case H5D_ALLOC_TIME_INCR:
                h5tools_str_append(&buffer, "%s", "H5D_ALLOC_TIME_INCR");
                break;
            case H5D_ALLOC_TIME_LATE:
                h5tools_str_append(&buffer, "%s", "H5D_ALLOC_TIME_LATE");
                break;
            case H5D_ALLOC_TIME_ERROR:
            case H5D_ALLOC_TIME_DEFAULT:
            default:
                h5tools_str_append(&buffer, "%s", "INVALID");
                break;
        }
        h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);

        ctx->indent_level--;

        ctx->need_prefix = true;

        h5tools_str_reset(&buffer);
        h5tools_str_append(&buffer, "%s", END);
        h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);
    } /* end if (H5D_VIRTUAL != stl) */

    h5tools_str_close(&buffer);
}

/*-------------------------------------------------------------------------
 * Function:    dump_comment
 *
 * Purpose:     prints the comment for the object name
 *
 * Return:      void
 *-------------------------------------------------------------------------
 */
void
h5tools_dump_comment(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hid_t obj_id)
{
    char         *comment     = NULL;
    ssize_t       cmt_bufsize = -1;
    size_t        buf_size    = 0;
    size_t        ncols       = 80;       /* available output width        */
    h5tools_str_t buffer;                 /* string into which to render   */
    hsize_t       curr_pos = ctx->sm_pos; /* total data element position   */
                                          /* pass to the prefix in h5tools_simple_prefix the total position
                                           * instead of the current stripmine position i; this is necessary
                                           * to print the array indices
                                           */
    uint64_t supported = 0;

    /* Check if comments are supported and return if not */
    H5VLquery_optional(obj_id, H5VL_SUBCLS_OBJECT, H5VL_NATIVE_OBJECT_GET_COMMENT, &supported);

    if (!(supported & H5VL_OPT_QUERY_SUPPORTED))
        return;

    /* setup */
    memset(&buffer, 0, sizeof(h5tools_str_t));

    if (info->line_ncols > 0)
        ncols = info->line_ncols;

    cmt_bufsize = H5Oget_comment(obj_id, comment, buf_size);

    /* call H5Oget_comment again with the correct value */
    if (cmt_bufsize > 0) {
        comment = (char *)malloc((size_t)(cmt_bufsize + 1)); /* new_size including null terminator */
        if (comment) {
            cmt_bufsize = H5Oget_comment(obj_id, comment, (size_t)cmt_bufsize);
            if (cmt_bufsize > 0) {
                comment[cmt_bufsize] = '\0'; /* necessary because null char is not returned */

                ctx->need_prefix = true;

                h5tools_str_reset(&buffer);
                h5tools_str_append(&buffer, "COMMENT \"%s\"", comment);
                h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                                       (hsize_t)0);

                h5tools_str_close(&buffer);
            }
            free(comment);
        }
    }
} /* end dump_comment() */

/*-------------------------------------------------------------------------
 * Function:    dump_attribute
 *
 * Purpose:     Dump the attribute.
 *
 * Return:      void
 *
 * In/Out:      h5tools_context_t *ctx
 *-------------------------------------------------------------------------
 */
void
h5tools_dump_attribute(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx,
                       const char *attr_name, hid_t attr_id)
{
    h5tools_str_t buffer;                 /* string into which to render   */
    size_t        ncols    = 80;          /* available output width        */
    hsize_t       curr_pos = ctx->sm_pos; /* total data element position   */
                                          /* pass to the prefix in h5tools_simple_prefix the total position
                                           * instead of the current stripmine position i; this is necessary
                                           * to print the array indices
                                           */

    /* setup */
    memset(&buffer, 0, sizeof(h5tools_str_t));

    if (info->line_ncols > 0)
        ncols = info->line_ncols;

    ctx->need_prefix = true;

    h5tools_str_reset(&buffer);
    h5tools_str_append(&buffer, "%s \"%s\" %s", h5tools_dump_header_format->attributebegin, attr_name,
                       h5tools_dump_header_format->attributeblockbegin);
    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);

    if (attr_id < 0) {
        error_msg("unable to open attribute \"%s\"\n", attr_name);
    }
    else {
        hid_t type  = H5I_INVALID_HID;
        hid_t space = H5I_INVALID_HID;

        ctx->indent_level++;

        type = H5Aget_type(attr_id);
        h5tools_dump_datatype(stream, info, ctx, type);

        space = H5Aget_space(attr_id);
        h5tools_dump_dataspace(stream, info, ctx, space);

        if (oid_output)
            h5tools_dump_oid(stream, info, ctx, attr_id);

        if (data_output || attr_data_output)
            h5tools_dump_data(stream, info, ctx, attr_id, false);

        ctx->indent_level--;

        H5Tclose(type);
        H5Sclose(space);
        H5Aclose(attr_id);
    }

    ctx->need_prefix = true;

    h5tools_str_reset(&buffer);

    if (strlen(h5tools_dump_header_format->attributeblockend)) {
        h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->attributeblockend);
        if (strlen(h5tools_dump_header_format->attributeend))
            h5tools_str_append(&buffer, " ");
    }
    if (strlen(h5tools_dump_header_format->attributeend))
        h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->attributeend);

    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);

    h5tools_str_close(&buffer);
}

/*-------------------------------------------------------------------------
 * Function:    dump_dims
 *
 * Purpose:     Dump the dimensions handed to it in a comma separated list
 *
 * Return:      void
 *-------------------------------------------------------------------------
 */
void
h5tools_print_dims(h5tools_str_t *buffer, hsize_t *s, int dims)
{
    int i;

    for (i = 0; i < dims; i++) {
        h5tools_str_append(buffer, "%" PRIuHSIZE, s[i]);

        if (i + 1 != dims)
            h5tools_str_append(buffer, ", ");
    }
}

/*-------------------------------------------------------------------------
 * Function:    print_packed_bits
 *
 * Purpose:     Prints the packed bits offset and length
 *
 * Return:      void
 *-------------------------------------------------------------------------
 */
void
h5tools_print_packed_bits(h5tools_str_t *buffer, hid_t type)
{
    unsigned packed_bits_size = 0;
    hid_t    n_type           = H5Tget_native_type(type, H5T_DIR_DEFAULT);

    if (H5Tget_class(n_type) == H5T_INTEGER) {
        if (H5Tequal(n_type, H5T_NATIVE_SCHAR) == true)
            packed_bits_size = 8 * sizeof(char);
        else if (H5Tequal(n_type, H5T_NATIVE_UCHAR) == true)
            packed_bits_size = 8 * sizeof(unsigned char);
        else if (H5Tequal(n_type, H5T_NATIVE_SHORT) == true)
            packed_bits_size = 8 * sizeof(short);
        else if (H5Tequal(n_type, H5T_NATIVE_USHORT) == true)
            packed_bits_size = 8 * sizeof(unsigned short);
        else if (H5Tequal(n_type, H5T_NATIVE_INT) == true)
            packed_bits_size = 8 * sizeof(int);
        else if (H5Tequal(n_type, H5T_NATIVE_UINT) == true)
            packed_bits_size = 8 * sizeof(unsigned int);
        else if (H5Tequal(n_type, H5T_NATIVE_LONG) == true)
            packed_bits_size = 8 * sizeof(long);
        else if (H5Tequal(n_type, H5T_NATIVE_ULONG) == true)
            packed_bits_size = 8 * sizeof(unsigned long);
        else if (H5Tequal(n_type, H5T_NATIVE_LLONG) == true)
            packed_bits_size = 8 * sizeof(long long);
        else if (H5Tequal(n_type, H5T_NATIVE_ULLONG) == true)
            packed_bits_size = 8 * sizeof(unsigned long long);
        else
            error_msg("Packed Bit not valid for this datatype");
    }

    if ((packed_bits_size > 0) && (packed_data_offset + packed_data_length) > packed_bits_size) {
        error_msg("Packed Bit offset+length value(%u) too large. Max is %d\n",
                  packed_data_offset + packed_data_length, packed_bits_size);
        packed_data_mask = 0;
    }
    h5tools_str_append(buffer, "%s %s=%u %s=%u", PACKED_BITS, PACKED_OFFSET, packed_data_offset,
                       PACKED_LENGTH, packed_data_length);
}

/*-------------------------------------------------------------------------
 * Function:    dump_subsetting_header
 *
 * Purpose:     Dump the subsetting header like specified in the DDL.
 *
 * Return:      void
 *-------------------------------------------------------------------------
 */
void
h5tools_dump_subsetting_header(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, int dims)
{
    h5tools_str_t buffer;        /* string into which to render   */
    hsize_t       curr_pos = 0;  /* total data element position   */
    size_t        ncols    = 80; /* available output width        */

    /* setup */
    memset(&buffer, 0, sizeof(h5tools_str_t));
    if (info->line_ncols > 0)
        ncols = info->line_ncols;

    ctx->need_prefix = true;

    h5tools_str_reset(&buffer);
    h5tools_str_append(&buffer, "%s %s", h5tools_dump_header_format->subsettingbegin,
                       h5tools_dump_header_format->subsettingblockbegin);
    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);

    ctx->indent_level++;

    ctx->need_prefix = true;

    h5tools_str_reset(&buffer);
    h5tools_str_append(&buffer, "%s %s ", h5tools_dump_header_format->startbegin,
                       h5tools_dump_header_format->startblockbegin);
    h5tools_print_dims(&buffer, ctx->sset->start.data, dims);
    h5tools_str_append(&buffer, "%s %s", h5tools_dump_header_format->startend,
                       h5tools_dump_header_format->startblockend);
    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);

    ctx->need_prefix = true;

    h5tools_str_reset(&buffer);
    h5tools_str_append(&buffer, "%s %s ", h5tools_dump_header_format->stridebegin,
                       h5tools_dump_header_format->strideblockbegin);
    h5tools_print_dims(&buffer, ctx->sset->stride.data, dims);
    h5tools_str_append(&buffer, "%s %s", h5tools_dump_header_format->strideend,
                       h5tools_dump_header_format->strideblockend);
    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);

    ctx->need_prefix = true;

    h5tools_str_reset(&buffer);
    h5tools_str_append(&buffer, "%s %s ", h5tools_dump_header_format->countbegin,
                       h5tools_dump_header_format->countblockbegin);

    if (ctx->sset->count.data)
        h5tools_print_dims(&buffer, ctx->sset->count.data, dims);
    else
        h5tools_str_append(&buffer, "DEFAULT");

    h5tools_str_append(&buffer, "%s %s", h5tools_dump_header_format->countend,
                       h5tools_dump_header_format->countblockend);
    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);

    ctx->need_prefix = true;

    h5tools_str_reset(&buffer);
    h5tools_str_append(&buffer, "%s %s ", h5tools_dump_header_format->blockbegin,
                       h5tools_dump_header_format->blockblockbegin);

    if (ctx->sset->block.data)
        h5tools_print_dims(&buffer, ctx->sset->block.data, dims);
    else
        h5tools_str_append(&buffer, "DEFAULT");

    h5tools_str_append(&buffer, "%s %s", h5tools_dump_header_format->blockend,
                       h5tools_dump_header_format->blockblockend);
    h5tools_render_element(stream, info, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0, (hsize_t)0);

    ctx->indent_level--;

    h5tools_str_close(&buffer);
}

/*-------------------------------------------------------------------------
 * Function:    dump_reference
 *
 * Purpose:     Dump reference data
 *
 * Return:      void
 *-------------------------------------------------------------------------
 */
void
h5tools_dump_reference(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hid_t container,
                       H5R_ref_t *ref_buf, int ndims)
{
    hid_t             new_obj_id   = H5I_INVALID_HID;
    hid_t             new_obj_sid  = H5I_INVALID_HID;
    hsize_t           elmt_counter = 0;  /*counts the # elements printed. */
    size_t            ncols        = 80; /* available output width        */
    int               i;
    hsize_t           curr_pos = 0; /* total data element position   */
    h5tools_str_t     buffer;       /* string into which to render   */
    h5tools_context_t datactx;      /* print context  */

    H5TOOLS_START_DEBUG(" ");

    datactx = *ctx; /* print context  */
    /* Assume entire data space to be printed */
    datactx.need_prefix = true;

    memset(&buffer, 0, sizeof(h5tools_str_t));
    for (i = 0; i < ndims; i++, datactx.cur_elmt++, elmt_counter++) {
        H5O_type_t obj_type = -1; /* Object type */
        H5R_type_t ref_type;      /* Reference type */

        H5TOOLS_DEBUG("reference loop:%d with curr_pos=%ld", i, curr_pos);

        datactx.need_prefix = true;
        h5tools_str_reset(&buffer);
        H5TOOLS_DEBUG("reference loop - h5tools_str_sprint with H5T_STD_REF:%d", i);
        h5tools_str_sprint(&buffer, info, container, H5T_STD_REF, &ref_buf[i], &datactx);
        h5tools_render_element(stream, info, &datactx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)i,
                               (hsize_t)ndims);

        ref_type = H5Rget_type((const H5R_ref_t *)&ref_buf[i]);
        switch (ref_type) {
            case H5R_OBJECT1:
                H5TOOLS_DEBUG("ref_type is H5R_OBJECT1");
                if (H5Rget_obj_type3(&ref_buf[i], H5P_DEFAULT, &obj_type) >= 0) {
                    switch (obj_type) {
                        case H5O_TYPE_DATASET:
                            if ((new_obj_id = H5Ropen_object(&ref_buf[i], H5P_DEFAULT, H5P_DEFAULT)) >= 0) {
                                datactx.indent_level++;
                                h5tools_dump_data(stream, info, &datactx, new_obj_id, true);
                                // h5tools_dump_dset(stream, info, &datactx, new_obj_id);
                                datactx.indent_level--;
                                if (H5Dclose(new_obj_id) < 0)
                                    H5TOOLS_INFO("H5Dclose H5R_OBJECT1:H5O_TYPE_DATASET failed");
                            }
                            else
                                H5TOOLS_INFO("H5Ropen_object H5R_OBJECT1:H5O_TYPE_DATASET failed");
                            break;

                        case H5O_TYPE_GROUP:
                        case H5O_TYPE_NAMED_DATATYPE:
                        case H5O_TYPE_MAP:
                        case H5O_TYPE_UNKNOWN:
                        case H5O_TYPE_NTYPES:
                        default:
                            break;
                    } /* end switch */
                }
                else
                    H5TOOLS_INFO("H5Rget_obj_type3 H5R_OBJECT1 failed");
                break;
            case H5R_DATASET_REGION1:
                H5TOOLS_DEBUG("ref_type is H5R_DATASET_REGION1");
                if ((new_obj_id = H5Ropen_object(&ref_buf[i], H5P_DEFAULT, H5P_DEFAULT)) >= 0) {
                    datactx.indent_level++;
                    h5tools_dump_data(stream, info, &datactx, new_obj_id, true);
                    // h5tools_dump_dset(stream, info, &datactx, new_obj_id);
                    datactx.indent_level--;
                    if (H5Dclose(new_obj_id) < 0)
                        H5TOOLS_INFO("H5Dclose 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(&ref_buf[i], H5P_DEFAULT, &obj_type) >= 0) {
                    switch (obj_type) {
                        case H5O_TYPE_GROUP:
                            break;

                        case H5O_TYPE_DATASET:
                            if ((new_obj_id = H5Ropen_object(&ref_buf[i], H5P_DEFAULT, H5P_DEFAULT)) >= 0) {
                                datactx.indent_level++;
                                h5tools_dump_data(stream, info, &datactx, new_obj_id, true);
                                // h5tools_dump_dset(stream, info, &datactx, new_obj_id);
                                datactx.indent_level--;
                                if (H5Oclose(new_obj_id) < 0)
                                    H5TOOLS_INFO("H5Oclose H5R_OBJECT2 failed");
                            }
                            else
                                H5TOOLS_INFO("H5Ropen_object H5R_OBJECT2 failed");
                            break;

                        case H5O_TYPE_NAMED_DATATYPE:
                            break;

                        case H5O_TYPE_MAP:
                        case H5O_TYPE_UNKNOWN:
                        case H5O_TYPE_NTYPES:
                        default:
                            break;
                    } /* end switch */
                }
                else
                    H5TOOLS_INFO("H5Rget_obj_type3 H5R_OBJECT2 failed");
                break;
            case H5R_DATASET_REGION2:
                H5TOOLS_DEBUG("ref_type is H5R_DATASET_REGION2");

                if (info->line_ncols > 0)
                    ncols = info->line_ncols;

                /* if (new_obj_id < 0) - could mean that no reference was written do not throw failure */
                if ((new_obj_id = H5Ropen_object(&ref_buf[i], H5P_DEFAULT, H5P_DEFAULT)) < 0)
                    H5TOOLS_INFO("H5Ropen_object H5R_DATASET_REGION2 failed");
                else {
                    if ((new_obj_sid = H5Ropen_region(&ref_buf[i], H5P_DEFAULT, H5P_DEFAULT)) >= 0) {
                        if (h5tools_is_zero(&ref_buf[i], H5Tget_size(H5T_STD_REF))) {
                            H5TOOLS_DEBUG("NULL H5R_DATASET_REGION2");

                            h5tools_str_reset(&buffer);
                            h5tools_str_append(&buffer, " {");
                            h5tools_render_element(stream, info, &datactx, &buffer, &curr_pos, (size_t)ncols,
                                                   (hsize_t)0, (hsize_t)0);

                            datactx.need_prefix = true;
                            datactx.indent_level++;
                            h5tools_str_reset(&buffer);
                            h5tools_str_append(&buffer, "NULL");
                            h5tools_render_element(stream, info, &datactx, &buffer, &curr_pos, (size_t)ncols,
                                                   (hsize_t)0, (hsize_t)0);
                            datactx.indent_level--;
                            datactx.need_prefix = true;

                            h5tools_str_reset(&buffer);
                            h5tools_str_append(&buffer, "}");
                            h5tools_render_element(stream, info, &datactx, &buffer, &curr_pos, (size_t)ncols,
                                                   (hsize_t)0, (hsize_t)0);
                        }
                        else {
                            H5S_sel_type region_type;

                            region_type = H5Sget_select_type(new_obj_sid);
                            if (region_type == H5S_SEL_POINTS) {
                                /* Print point information */
                                H5TOOLS_DEBUG("H5S_SEL_POINTS H5R_DATASET_REGION2");
                                h5tools_dump_region_data_points(new_obj_sid, new_obj_id, stream, info,
                                                                &datactx, &buffer, &curr_pos, ncols,
                                                                (hsize_t)i, elmt_counter);
                            }
                            else if (region_type == H5S_SEL_HYPERSLABS) {
                                /* Print block information */
                                H5TOOLS_DEBUG("H5S_SEL_HYPERSLABS H5R_DATASET_REGION2");
                                h5tools_dump_region_data_blocks(new_obj_sid, new_obj_id, stream, info,
                                                                &datactx, &buffer, &curr_pos, ncols,
                                                                (hsize_t)i, elmt_counter);
                            }
                            else
                                H5TOOLS_INFO("invalid region type");
                        } /* end else to if (h5tools_is_zero(... */
                        if (H5Sclose(new_obj_sid) < 0)
                            H5TOOLS_INFO("H5Sclose H5R_DATASET_REGION2 failed");
                    }
                    else
                        H5TOOLS_INFO("H5Ropen_region H5R_DATASET_REGION2 failed");
                    if (H5Dclose(new_obj_id) < 0)
                        H5TOOLS_INFO("H5Dclose H5R_DATASET_REGION2 failed");
                }
                break;
            case H5R_ATTR:
                H5TOOLS_DEBUG("ref_type is H5R_ATTR");
                if ((new_obj_id = H5Ropen_attr(&ref_buf[i], H5P_DEFAULT, H5P_DEFAULT)) >= 0) {
                    h5tools_dump_region_attribute(new_obj_id, stream, info, &datactx, &buffer, &curr_pos,
                                                  (size_t)ncols, (hsize_t)0, (hsize_t)0);
                    if (H5Aclose(new_obj_id) < 0)
                        H5TOOLS_INFO("H5Aclose H5R_ATTR failed");
                }
                else {
                    H5TOOLS_DEBUG("NULL H5R_ATTR");

                    h5tools_str_reset(&buffer);
                    h5tools_str_append(&buffer, " {");
                    h5tools_render_element(stream, info, &datactx, &buffer, &curr_pos, (size_t)ncols,
                                           (hsize_t)0, (hsize_t)0);

                    datactx.need_prefix = true;
                    datactx.indent_level++;
                    h5tools_str_reset(&buffer);
                    h5tools_str_append(&buffer, "NULL");
                    h5tools_render_element(stream, info, &datactx, &buffer, &curr_pos, (size_t)ncols,
                                           (hsize_t)0, (hsize_t)0);
                    datactx.indent_level--;
                    datactx.need_prefix = true;

                    h5tools_str_reset(&buffer);
                    h5tools_str_append(&buffer, "}");
                    h5tools_render_element(stream, info, &datactx, &buffer, &curr_pos, (size_t)ncols,
                                           (hsize_t)0, (hsize_t)0);

                    H5TOOLS_INFO("H5Ropen_attr H5R_ATTR failed");
                }
                break;
            case H5R_BADTYPE:
            case H5R_MAXTYPE:
            default:
                break;
        } /* end switch */

        if (H5Rdestroy(&ref_buf[i]) < 0)
            H5TOOLS_INFO("H5Rdestroy failed");

        H5TOOLS_DEBUG("finished reference loop:%d", i);
    } /* end for(i = 0; i < ndims; i++, ctx->cur_elmt++, elmt_counter++) */

    h5tools_str_close(&buffer);

    H5TOOLS_ENDDEBUG(" ");
}

/*-------------------------------------------------------------------------
 * Function:    dump_data
 *
 * Purpose:     Dump attribute, obj_data is false, or dataset data, obj_data is true
 *
 * Return:      void
 *-------------------------------------------------------------------------
 */
void
h5tools_dump_data(FILE *stream, const h5tool_format_t *info, h5tools_context_t *ctx, hid_t obj_id,
                  int obj_data)
{
    H5S_class_t       space_type;
    int               ndims;
    hid_t             space  = H5I_INVALID_HID;
    hid_t             f_type = H5I_INVALID_HID;
    hsize_t           total_size[H5S_MAX_RANK];
    int               status = -1;
    h5tools_context_t datactx;       /* print context  */
    h5tools_str_t     buffer;        /* string into which to render   */
    hsize_t           curr_pos = 0;  /* total data element position   */
    size_t            ncols    = 80; /* available output width        */
    h5tool_format_t   string_dataformat;
    h5tool_format_t   outputformat;
    H5R_ref_t        *ref_buf = NULL;

    H5TOOLS_START_DEBUG(" file=%p", (void *)stream);
    H5TOOLS_DEBUG("rawdata file=%p", (void *)rawdatastream);
    /* setup */
    memset(&buffer, 0, sizeof(h5tools_str_t));
    if (info->line_ncols > 0)
        ncols = info->line_ncols;

    outputformat      = *info;
    string_dataformat = *info;
    /* print the matrix indices */
    string_dataformat.pindex = ctx->display_index;

    if (obj_data) {
        H5TOOLS_DEBUG("dataset");
        f_type = H5Dget_type(obj_id);
        space  = H5Dget_space(obj_id);
    }
    else {
        H5TOOLS_DEBUG("attribute");
        f_type = H5Aget_type(obj_id);
        space  = H5Aget_space(obj_id);
    }

    if (string_dataformat.pindex) {
        string_dataformat.idx_fmt   = "(%s): ";
        string_dataformat.idx_n_fmt = "%" PRIuHSIZE;
        string_dataformat.idx_sep   = ",";
        string_dataformat.line_pre  = "%s";
    }
    info = &string_dataformat;

    if (ctx->sset && obj_data) {

        h5tools_dump_subsetting_header(stream, &outputformat, ctx, H5Sget_simple_extent_ndims(space));

        ctx->indent_level++;
    }

    ctx->need_prefix = true;
    h5tools_str_reset(&buffer);
    h5tools_str_append(&buffer, "%s %s", h5tools_dump_header_format->databegin,
                       h5tools_dump_header_format->datablockbegin);
    h5tools_render_element(stream, &outputformat, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                           (hsize_t)0);

    if (H5Tget_class(f_type) == H5T_REFERENCE) {
        ctx->indent_level++;
        datactx = *ctx;
        H5TOOLS_DEBUG("reference class type");
        if (!H5Tequal(f_type, H5T_STD_REF) && !H5Tequal(f_type, H5T_STD_REF_DSETREG) &&
            !H5Tequal(f_type, H5T_STD_REF_OBJ)) {
            H5TOOLS_GOTO_DONE_NO_RET();
        }

        ndims = (int)H5Sget_simple_extent_npoints(space);
        H5TOOLS_DEBUG("ndims=%d - datactx.ndims=%d", ndims, datactx.ndims);

        /* Assume entire data space to be printed */
        H5Sget_simple_extent_dims(space, total_size, NULL);
        init_acc_pos(datactx.ndims, total_size, datactx.acc, datactx.pos, datactx.p_min_idx);

        datactx.need_prefix = true;

        if (NULL !=
            (ref_buf = (H5R_ref_t *)calloc(MAX(sizeof(unsigned), sizeof(H5R_ref_t)), (size_t)ndims))) {
            if (obj_data) {
                if (H5Dread(obj_id, H5T_STD_REF, H5S_ALL, H5S_ALL, H5P_DEFAULT, ref_buf) < 0) {
                    free(ref_buf);
                    H5TOOLS_INFO("H5Dread reference failed");
                    H5TOOLS_GOTO_DONE_NO_RET();
                }
            }
            else {
                if (H5Aread(obj_id, H5T_STD_REF, ref_buf) < 0) {
                    free(ref_buf);
                    H5TOOLS_INFO("H5Aread reference failed");
                    H5TOOLS_GOTO_DONE_NO_RET();
                }
            }
            h5tools_dump_reference(stream, &outputformat, &datactx, obj_id, ref_buf, ndims);
            free(ref_buf);
        }
        ctx->indent_level--;
    }
    else {
        H5TOOLS_DEBUG("Print all the values");
        datactx           = *ctx;
        string_dataformat = *info;
        if ((datactx.display_char && H5Tget_size(f_type) == 1) && (H5Tget_class(f_type) == H5T_INTEGER)) {
            H5TOOLS_DEBUG("Print 1-byte integer data as an ASCII character string");
            /*
             * Print 1-byte integer data as an ASCII character string
             * instead of integers if the `-r' or `--string' command-line
             * option was given.
             *
             * We don't want to modify the global dataformat, so make a
             * copy of it instead.
             */
            string_dataformat.idx_fmt = "\"";
            datactx.indent_level++;
            datactx.need_prefix = true;
            h5tools_simple_prefix(stream, &string_dataformat, &datactx, (hsize_t)0, 0);

            string_dataformat.line_multi_new = 1;
            string_dataformat.str_repeat     = 8;
            string_dataformat.ascii          = true;
            string_dataformat.elmt_suf1      = "";
            string_dataformat.elmt_suf2      = "";
            string_dataformat.line_suf       = "\"";
        }
        else {
            datactx.need_prefix = true;
        }

        /* Print all the values. */
        if (obj_data) {
            H5TOOLS_DEBUG("h5tools_dump_dset");
            status = h5tools_dump_dset(stream, &string_dataformat, &datactx, obj_id);
        }
        else {
            /* need to call h5tools_dump_mem for the attribute data */
            space_type = H5Sget_simple_extent_type(space);
            if (space_type == H5S_NULL || space_type == H5S_NO_CLASS) {
                status = SUCCEED;
            }
            else {
                H5TOOLS_DEBUG("call h5tools_dump_mem");
                status = h5tools_dump_mem(stream, &string_dataformat, &datactx, obj_id);
            }
        }
        if (datactx.display_char && H5Tget_size(f_type) == 1 && H5Tget_class(f_type) == H5T_INTEGER) {
            H5TOOLS_DEBUG("Print 1-byte integer data as an ASCII character string eol=%s",
                          string_dataformat.line_suf);
            datactx.need_prefix              = false;
            string_dataformat.arr_linebreak  = 0;
            string_dataformat.idx_fmt        = "";
            string_dataformat.line_multi_new = 0;
            string_dataformat.line_suf       = "";
            h5tools_str_reset(&buffer);
            h5tools_str_append(&buffer, "\"");
            h5tools_render_element(stream, &string_dataformat, &datactx, &buffer, &curr_pos, (size_t)ncols,
                                   (hsize_t)0, (hsize_t)0);
        }
        H5TOOLS_DEBUG("Print all the values Complete");

        if (status == FAIL) {
            error_msg("unable to print data\n");
            h5tools_setstatus(EXIT_FAILURE);
        }
    }
done:
    H5Sclose(space);
    H5Tclose(f_type);

    ctx->need_prefix = true;
    h5tools_simple_prefix(stream, &outputformat, ctx, (hsize_t)0, 0);

    h5tools_str_reset(&buffer);
    if (strlen(h5tools_dump_header_format->datablockend)) {
        h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->datablockend);
        if (strlen(h5tools_dump_header_format->dataend))
            h5tools_str_append(&buffer, " ");
    }

    if (strlen(h5tools_dump_header_format->dataend))
        h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->dataend);
    h5tools_render_element(stream, &outputformat, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                           (hsize_t)0);

    if (ctx->sset && obj_data) {
        ctx->indent_level--;

        ctx->need_prefix = true;
        h5tools_simple_prefix(stream, &outputformat, ctx, (hsize_t)0, 0);

        h5tools_str_reset(&buffer);
        if (strlen(h5tools_dump_header_format->subsettingblockend)) {
            h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->subsettingblockend);
            if (strlen(h5tools_dump_header_format->subsettingend))
                h5tools_str_append(&buffer, " ");
        }
        if (strlen(h5tools_dump_header_format->subsettingend))
            h5tools_str_append(&buffer, "%s", h5tools_dump_header_format->subsettingend);
        h5tools_render_element(stream, &outputformat, ctx, &buffer, &curr_pos, (size_t)ncols, (hsize_t)0,
                               (hsize_t)0);
    }

    h5tools_str_close(&buffer);
    H5TOOLS_ENDDEBUG(" ");
}