summaryrefslogtreecommitdiffstats
path: root/tools/h5dump/h5dump.c
blob: 650846a8840c24aa79b4798dd151a0710974991a (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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * 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 files COPYING and Copyright.html.  COPYING can be found at the root   *
 * of the source code distribution tree; Copyright.html can be found at the  *
 * root level of an installed copy of the electronic HDF5 document set and   *
 * is linked from the top-level documents page.  It can also be found at     *
 * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
 * access to either file, you may request a copy from help@hdfgroup.org.     *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <stdio.h>
#include <stdlib.h>

#include "h5dump.h"
#include "h5dump_ddl.h"
#include "h5dump_xml.h"

/* Name of tool */
#define PROGRAMNAME "h5dump"

static const char   *driver = NULL;      /* The driver to open the file with. */
const char          *outfname=NULL;
static int           doxml = 0;
static int           useschema = 1;
static const char   *xml_dtd_uri = NULL;

/* module-scoped variables for XML option */
#define DEFAULT_XSD     "http://www.hdfgroup.org/HDF5/XML/schema/HDF5-File.xsd"
#define DEFAULT_DTD     "http://www.hdfgroup.org/HDF5/XML/schema/HDF5-File.dtd"

/* Standard DDL output */
static const dump_functions ddl_function_table = {
    dump_group,
    dump_named_datatype,
    dump_dataset,
    dump_dataspace,
    dump_datatype,
    dump_attr_cb,
    dump_data
};

/* XML output */
static const dump_functions xml_function_table = {
    xml_dump_group,
    xml_dump_named_datatype,
    xml_dump_dataset,
    xml_dump_dataspace,
    xml_dump_datatype,
    xml_dump_attr,
    xml_dump_data
};

/* internal functions */
static void     init_prefix(char **prfx, size_t prfx_len);

/* a structure for handling the order command-line parameters come in */
struct handler_t {
    void (*func)(hid_t, const char *, void *, int, const char *);
    char *obj;
    struct subset_t *subset_info;
};

/*
 * Command-line options: The user can specify short or long-named
 * parameters. The long-named ones can be partially spelled. When
 * adding more, make sure that they don't clash with each other.
 */
/* The following initialization makes use of C language cancatenating */
/* "xxx" "yyy" into "xxxyyy". */
static const char *s_opts = "hnpeyBHirVa:c:d:f:g:k:l:t:w:xD:uX:o:b*F:s:S:Aq:z:m:RECM:";
static struct long_options l_opts[] = {
    { "help", no_arg, 'h' },
    { "hel", no_arg, 'h' },
    { "contents", no_arg, 'n' },
    { "properties", no_arg, 'p' },
    { "boot-block", no_arg, 'B' },
    { "boot-bloc", no_arg, 'B' },
    { "boot-blo", no_arg, 'B' },
    { "boot-bl", no_arg, 'B' },
    { "boot-b", no_arg, 'B' },
    { "boot", no_arg, 'B' },
    { "boo", no_arg, 'B' },
    { "bo", no_arg, 'B' },
    { "header", no_arg, 'H' },
    { "heade", no_arg, 'H' },
    { "head", no_arg, 'H' },
    { "hea", no_arg, 'H' },
    { "object-ids", no_arg, 'i' },
    { "object-id", no_arg, 'i' },
    { "object-i", no_arg, 'i' },
    { "object", no_arg, 'i' },
    { "objec", no_arg, 'i' },
    { "obje", no_arg, 'i' },
    { "obj", no_arg, 'i' },
    { "ob", no_arg, 'i' },
    { "version", no_arg, 'V' },
    { "versio", no_arg, 'V' },
    { "versi", no_arg, 'V' },
    { "vers", no_arg, 'V' },
    { "ver", no_arg, 'V' },
    { "ve", no_arg, 'V' },
    { "attribute", require_arg, 'a' },
    { "attribut", require_arg, 'a' },
    { "attribu", require_arg, 'a' },
    { "attrib", require_arg, 'a' },
    { "attri", require_arg, 'a' },
    { "attr", require_arg, 'a' },
    { "att", require_arg, 'a' },
    { "at", require_arg, 'a' },
    { "block", require_arg, 'k' },
    { "bloc", require_arg, 'k' },
    { "blo", require_arg, 'k' },
    { "bl", require_arg, 'k' },
    { "count", require_arg, 'c' },
    { "coun", require_arg, 'c' },
    { "cou", require_arg, 'c' },
    { "co", require_arg, 'c' },
    { "dataset", require_arg, 'd' },
    { "datase", require_arg, 'd' },
    { "datas", require_arg, 'd' },
    { "datatype", require_arg, 't' },
    { "datatyp", require_arg, 't' },
    { "dataty", require_arg, 't' },
    { "datat", require_arg, 't' },
    { "filedriver", require_arg, 'f' },
    { "filedrive", require_arg, 'f' },
    { "filedriv", require_arg, 'f' },
    { "filedri", require_arg, 'f' },
    { "filedr", require_arg, 'f' },
    { "filed", require_arg, 'f' },
    { "file", require_arg, 'f' },
    { "fil", require_arg, 'f' },
    { "fi", require_arg, 'f' },
    { "group", require_arg, 'g' },
    { "grou", require_arg, 'g' },
    { "gro", require_arg, 'g' },
    { "gr", require_arg, 'g' },
    { "output", require_arg, 'o' },
    { "outpu", require_arg, 'o' },
    { "outp", require_arg, 'o' },
    { "out", require_arg, 'o' },
    { "ou", require_arg, 'o' },
    { "soft-link", require_arg, 'l' },
    { "soft-lin", require_arg, 'l' },
    { "soft-li", require_arg, 'l' },
    { "soft-l", require_arg, 'l' },
    { "soft", require_arg, 'l' },
    { "sof", require_arg, 'l' },
    { "start", require_arg, 's' },
    { "star", require_arg, 's' },
    { "sta", require_arg, 's' },
    { "stride", require_arg, 'S' },
    { "strid", require_arg, 'S' },
    { "string", no_arg, 'r' },
    { "strin", no_arg, 'r' },
    { "use-dtd", no_arg, 'u' },
    { "use-dt", no_arg, 'u' },
    { "use-d", no_arg, 'u' },
    { "use-", no_arg, 'u' },
    { "use", no_arg, 'u' },
    { "us", no_arg, 'u' },
    { "u", no_arg, 'u' },
    { "width", require_arg, 'w' },
    { "widt", require_arg, 'w' },
    { "wid", require_arg, 'w' },
    { "wi", require_arg, 'w' },
    { "xml-dtd", require_arg, 'D' },
    { "xml-dt", require_arg, 'D' },
    { "xml-d", require_arg, 'D' },
    { "xml-ns", require_arg, 'X' },
    { "xml-n", require_arg, 'X' },
    { "xml", no_arg, 'x' },
    { "xm", no_arg, 'x' },
    { "onlyattr", no_arg, 'A' },
    { "escape", no_arg, 'e' },
    { "noindex", no_arg, 'y' },
    { "binary", optional_arg, 'b' },
    { "form", require_arg, 'F' },
    { "sort_by", require_arg, 'q' },
    { "sort_order", require_arg, 'z' },
    { "format", require_arg, 'm' },
    { "region", no_arg, 'R' },
    { "enable-error-stack", no_arg, 'E' },
    { "packed-bits", require_arg, 'M' },
    { "no-compact-subset", no_arg, 'C' },
    { NULL, 0, '\0' }
};


/*-------------------------------------------------------------------------
 * Function:    leave
 *
 * Purpose:     Shutdown MPI & HDF5 and call exit()
 *
 * Return:      Does not return
 *
 * Programmer:  Quincey Koziol
 *              Saturday, 31. January 2004
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static void
leave(int ret)
{
    h5tools_close();

    HDexit(ret);
}


/*-------------------------------------------------------------------------
 * Function:    usage
 *
 * Purpose:     Print the usage message about dumper
 *
 * Return:      void
 *
 * Programmer:  Ruey-Hsia Li
 *
 * Modifications:
 * Pedro Vicente, October 5, 2007. Add -q and -z flags
 *-------------------------------------------------------------------------
 */
static void
usage(const char *prog)
{
    HDfflush(rawoutstream);
    HDfprintf(rawoutstream, "usage: %s [OPTIONS] files\n", prog);
    HDfprintf(rawoutstream, "  OPTIONS\n");
    HDfprintf(rawoutstream, "     -h, --help           Print a usage message and exit\n");
    HDfprintf(rawoutstream, "     -n, --contents       Print a list of the file contents and exit\n");
    HDfprintf(rawoutstream, "     -B, --superblock     Print the content of the super block\n");
    HDfprintf(rawoutstream, "     -H, --header         Print the header only; no data is displayed\n");
    HDfprintf(rawoutstream, "     -A, --onlyattr       Print the header and value of attributes\n");
    HDfprintf(rawoutstream, "     -i, --object-ids     Print the object ids\n");
    HDfprintf(rawoutstream, "     -r, --string         Print 1-byte integer datasets as ASCII\n");
    HDfprintf(rawoutstream, "     -e, --escape         Escape non printing characters\n");
    HDfprintf(rawoutstream, "     -V, --version        Print version number and exit\n");
    HDfprintf(rawoutstream, "     -a P, --attribute=P  Print the specified attribute\n");
    HDfprintf(rawoutstream, "     -d P, --dataset=P    Print the specified dataset\n");
    HDfprintf(rawoutstream, "     -y, --noindex        Do not print array indices with the data\n");
    HDfprintf(rawoutstream, "     -p, --properties     Print dataset filters, storage layout and fill value\n");
    HDfprintf(rawoutstream, "     -f D, --filedriver=D Specify which driver to open the file with\n");
    HDfprintf(rawoutstream, "     -g P, --group=P      Print the specified group and all members\n");
    HDfprintf(rawoutstream, "     -l P, --soft-link=P  Print the value(s) of the specified soft link\n");
    HDfprintf(rawoutstream, "     -o F, --output=F     Output raw data into file F\n");
    HDfprintf(rawoutstream, "     -b B, --binary=B     Binary file output, of form B\n");
    HDfprintf(rawoutstream, "     -t P, --datatype=P   Print the specified named datatype\n");
    HDfprintf(rawoutstream, "     -w N, --width=N      Set the number of columns of output. A value of 0 (zero)\n");
    HDfprintf(rawoutstream, "                          sets the number of columns to the maximum (65535).\n");
    HDfprintf(rawoutstream, "                          Default width is 80 columns.\n");
    HDfprintf(rawoutstream, "     -m T, --format=T     Set the floating point output format\n");
    HDfprintf(rawoutstream, "     -q Q, --sort_by=Q    Sort groups and attributes by index Q\n");
    HDfprintf(rawoutstream, "     -z Z, --sort_order=Z Sort groups and attributes by order Z\n");
    HDfprintf(rawoutstream,
  "     -M L, --packedbits=L Print packed bits as unsigned integers, using mask\n"
  "                          format L for an integer dataset specified with\n"
  "                          option -d. L is a list of offset,length values,\n"
  "                          separated by commas. Offset is the beginning bit in\n"
  "                          the data value and length is the number of bits of\n"
  "                          the mask.\n"
  );
    HDfprintf(rawoutstream, "     -R, --region         Print dataset pointed by region references\n");
    HDfprintf(rawoutstream, "     -x, --xml            Output in XML using Schema\n");
    HDfprintf(rawoutstream, "     -u, --use-dtd        Output in XML using DTD\n");
    HDfprintf(rawoutstream, "     -D U, --xml-dtd=U    Use the DTD or schema at U\n");
    HDfprintf(rawoutstream, "     -X S, --xml-ns=S      (XML Schema) Use qualified names n the XML\n");
    HDfprintf(rawoutstream, "                          \":\": no namespace, default: \"hdf5:\"\n");
    HDfprintf(rawoutstream, "                          E.g., to dump a file called `-f', use h5dump -- -f\n");
    HDfprintf(rawoutstream, "     --enable-error-stack Prints messages from the HDF5 error stack as they\n");
    HDfprintf(rawoutstream, "                          occur.\n");
    HDfprintf(rawoutstream, "     --no-compact-subset  Disable compact form of subsetting and allow the use\n");
    HDfprintf(rawoutstream, "                          of \"[\" in datset names.\n");
    HDfprintf(rawoutstream, "\n");
    HDfprintf(rawoutstream, " Subsetting is available by using the following options with a dataset\n");
    HDfprintf(rawoutstream, " attribute. Subsetting is done by selecting a hyperslab from the data.\n");
    HDfprintf(rawoutstream, " Thus, the options mirror those for performing a hyperslab selection.\n");
    HDfprintf(rawoutstream, " One of the START, COUNT, STRIDE, or BLOCK parameters are mandatory if you do subsetting.\n");
    HDfprintf(rawoutstream, " The STRIDE, COUNT, and BLOCK parameters are optional and will default to 1 in\n");
    HDfprintf(rawoutstream, " each dimension. START is optional and will default to 0 in each dimension.\n");
    HDfprintf(rawoutstream, "\n");
    HDfprintf(rawoutstream, "      -s START,  --start=START    Offset of start of subsetting selection\n");
    HDfprintf(rawoutstream, "      -S STRIDE, --stride=STRIDE  Hyperslab stride\n");
    HDfprintf(rawoutstream, "      -c COUNT,  --count=COUNT    Number of blocks to include in selection\n");
    HDfprintf(rawoutstream, "      -k BLOCK,  --block=BLOCK    Size of block in hyperslab\n");
    HDfprintf(rawoutstream, "  START, COUNT, STRIDE, and BLOCK - is a list of integers the number of which are equal to the\n");
    HDfprintf(rawoutstream, "        number of dimensions in the dataspace being queried\n");
    HDfprintf(rawoutstream, "\n");
    HDfprintf(rawoutstream, "  D - is the file driver to use in opening the file. Acceptable values\n");
    HDfprintf(rawoutstream, "        are \"sec2\", \"family\", \"split\", \"multi\", \"direct\", and \"stream\". Without\n");
    HDfprintf(rawoutstream, "        the file driver flag, the file will be opened with each driver in\n");
    HDfprintf(rawoutstream, "        turn and in the order specified above until one driver succeeds\n");
    HDfprintf(rawoutstream, "        in opening the file.\n");
    HDfprintf(rawoutstream, "  F - is a filename.\n");
    HDfprintf(rawoutstream, "  P - is the full path from the root group to the object.\n");
    HDfprintf(rawoutstream, "  N - is an integer greater than 1.\n");
    HDfprintf(rawoutstream, "  T - is a string containing the floating point format, e.g '%%.3f'\n");
    HDfprintf(rawoutstream, "  U - is a URI reference (as defined in [IETF RFC 2396],\n");
    HDfprintf(rawoutstream, "        updated by [IETF RFC 2732])\n");
    HDfprintf(rawoutstream, "  B - is the form of binary output: NATIVE for a memory type, FILE for the\n");
    HDfprintf(rawoutstream, "        file type, LE or BE for pre-existing little or big endian types.\n");
    HDfprintf(rawoutstream, "        Must be used with -o (output file) and it is recommended that\n");
    HDfprintf(rawoutstream, "        -d (dataset) is used. B is an optional argument, defaults to NATIVE\n");
    HDfprintf(rawoutstream, "  Q - is the sort index type. It can be \"creation_order\" or \"name\" (default)\n");
    HDfprintf(rawoutstream, "  Z - is the sort order type. It can be \"descending\" or \"ascending\" (default)\n");
    HDfprintf(rawoutstream, "\n");
    HDfprintf(rawoutstream, "  Examples:\n");
    HDfprintf(rawoutstream, "\n");
    HDfprintf(rawoutstream, "  1) Attribute foo of the group /bar_none in file quux.h5\n");
    HDfprintf(rawoutstream, "\n");
    HDfprintf(rawoutstream, "      h5dump -a /bar_none/foo quux.h5\n");
    HDfprintf(rawoutstream, "\n");
    HDfprintf(rawoutstream, "  2) Selecting a subset from dataset /foo in file quux.h5\n");
    HDfprintf(rawoutstream, "\n");
    HDfprintf(rawoutstream, "      h5dump -d /foo -s \"0,1\" -S \"1,1\" -c \"2,3\" -k \"2,2\" quux.h5\n");
    HDfprintf(rawoutstream, "\n");
    HDfprintf(rawoutstream, "  3) Saving dataset 'dset' in file quux.h5 to binary file 'out.bin'\n");
    HDfprintf(rawoutstream, "        using a little-endian type\n");
    HDfprintf(rawoutstream, "\n");
    HDfprintf(rawoutstream, "      h5dump -d /dset -b LE -o out.bin quux.h5\n");
    HDfprintf(rawoutstream, "\n");
    HDfprintf(rawoutstream, "  4) Display two packed bits (bits 0-1 and bits 4-6) in the dataset /dset\n");
    HDfprintf(rawoutstream, "\n");
    HDfprintf(rawoutstream, "      h5dump -d /dset -M 0,1,4,3 quux.h5\n");
    HDfprintf(rawoutstream, "\n");
    HDfprintf(rawoutstream, "  5) Dataset foo in files multi1.h5 multi2.h5 multi3.h5\n");
    HDfprintf(rawoutstream, "\n");
    HDfprintf(rawoutstream, "      h5dump -d /foo multi1.h5 multi2.h5 multi3.h5\n");
    HDfprintf(rawoutstream, "\n");
}


/*-------------------------------------------------------------------------
 * Function: table_list_add
 *
 * Purpose: Add a new set of tables
 *
 * Return: index of added table on success, -1 on failure
 *
 * Programmer: Neil Fortner, nfortne2@hdfgroup.org
 *             Adapted from trav_addr_add in h5trav.c by Quincey Koziol
 *
 * Date: October 13, 2008
 *
 *-------------------------------------------------------------------------
 */
ssize_t
table_list_add(hid_t oid, unsigned long file_no)
{
    size_t      idx;         /* Index of table to use */
    find_objs_t info;

    /* Allocate space if necessary */
    if(table_list.nused == table_list.nalloc) {
        void        *tmp_ptr;

        table_list.nalloc = MAX(1, table_list.nalloc * 2);
        if(NULL == (tmp_ptr = HDrealloc(table_list.tables, table_list.nalloc * sizeof(table_list.tables[0]))))
            return -1;
        table_list.tables = tmp_ptr;
    } /* end if */

    /* Append it */
    idx = table_list.nused++;
    table_list.tables[idx].fileno = file_no;
    table_list.tables[idx].oid = oid;
    if(H5Iinc_ref(oid) < 0) {
        table_list.nused--;
        return -1;
    }
    if(init_objs(oid, &info, &table_list.tables[idx].group_table,
                 &table_list.tables[idx].dset_table, &table_list.tables[idx].type_table) < 0) {
        H5Idec_ref(oid);
        table_list.nused--;
        return -1;
    }

#ifdef H5DUMP_DEBUG
    dump_tables(&info);
#endif /* H5DUMP_DEBUG */

    return((ssize_t) idx);
} /* end table_list_add() */


/*-------------------------------------------------------------------------
 * Function: table_list_visited
 *
 * Purpose: Check if a table already exists for the specified fileno
 *
 * Return: The index of the matching table, or -1 if no matches found
 *
 * Programmer: Neil Fortner, nfortne2@hdfgroup.org
 *             Adapted from trav_addr_visited in h5trav.c by Quincey Koziol
 *
 * Date: October 13, 2008
 *
 *-------------------------------------------------------------------------
 */
ssize_t
table_list_visited(unsigned long file_no)
{
    size_t u;           /* Local index variable */

    /* Look for table */
    for(u = 0; u < table_list.nused; u++)
        /* Check for fileno value already in array */
        if(table_list.tables[u].fileno == file_no)
            return((ssize_t) u);

    /* Didn't find table */
    return(-1);
} /* end table_list_visited() */


/*-------------------------------------------------------------------------
 * Function: table_list_free
 *
 * Purpose: Frees the table list
 *
 * Return: void
 *
 * Programmer: Neil Fortner, nfortne2@hdfgroup.org
 *
 * Date: October 13, 2008
 *
 *-------------------------------------------------------------------------
 */
static void
table_list_free(void)
{
    size_t u;           /* Local index variable */

    /* Iterate over tables */
    for(u = 0; u < table_list.nused; u++) {
        /* Release object id */
        if(H5Idec_ref(table_list.tables[u].oid) < 0)
            h5tools_setstatus(EXIT_FAILURE);

        /* Free each table */
        free_table(table_list.tables[u].group_table);
        HDfree(table_list.tables[u].group_table);
        free_table(table_list.tables[u].dset_table);
        HDfree(table_list.tables[u].dset_table);
        free_table(table_list.tables[u].type_table);
        HDfree(table_list.tables[u].type_table);
    }

    /* Free the table list */
    HDfree(table_list.tables);
    table_list.tables = NULL;
    table_list.nalloc = table_list.nused = 0;
} /* end table_list_free() */

/*-------------------------------------------------------------------------
 * Function:    set_data_output_file
 *
 * Purpose:     Open fname as the output file for dataset raw data.
 *      Set rawdatastream as its file stream.
 *
 * Return:      0 -- succeeded
 *      negative -- failed
 *
 * Programmer:  Albert Cheng, 2000/09/30
 *
 * Modifications:
 *  pvn June, 1, 2006. Add a switch for binary output
 *
 *-------------------------------------------------------------------------
 */
static int
set_data_output_file(const char *fname, int is_bin)
{
    FILE    *f;    /* temporary holding place for the stream pointer
                    * so that rawdatastream is changed only when succeeded */

    if (rawdatastream && rawdatastream != stdout) {
        if (HDfclose(rawdatastream))
            HDperror("closing rawdatastream");
        else
            rawdatastream = NULL;
    }

    /* binary output */
    if (is_bin) {
        if ((f = HDfopen(fname, "wb")) != NULL) {
            rawdatastream = f;
            return 0;
        }
    }
    else {
        if ((f = HDfopen(fname, "w")) != NULL) {
            rawdatastream = f;
            return 0;
        }
    }

    return -1;
}

/*-------------------------------------------------------------------------
 * Function:    set_output_file
 *
 * Purpose:     Open fname as the output file for raw output.
 *      Set rawoutstream as its file stream.
 *
 * Return:      0 -- succeeded
 *      negative -- failed
 *
 *-------------------------------------------------------------------------
 */
static int
set_output_file(const char *fname)
{
    FILE    *f;    /* temporary holding place for the stream pointer
                    * so that rawoutstream is changed only when succeeded */

    if (rawoutstream && rawoutstream != stdout) {
        if (HDfclose(rawoutstream))
            HDperror("closing rawoutstream");
        else
            rawoutstream = NULL;
    }

    if ((f = HDfopen(fname, "w")) != NULL) {
        rawoutstream = f;
        return 0;
    }

    return -1;
}

/*-------------------------------------------------------------------------
 * Function:    set_error_file
 *
 * Purpose:     Open fname as the error output file for dataset raw error.
 *      Set rawerrorstream as its file stream.
 *
 * Return:      0 -- succeeded
 *      negative -- failed
 *
 *-------------------------------------------------------------------------
 */
static int
set_error_file(const char *fname)
{
    FILE    *f;    /* temporary holding place for the stream pointer
                    * so that rawerrorstream is changed only when succeeded */

    if (rawerrorstream && rawerrorstream != stderr) {
        if (HDfclose(rawerrorstream))
            HDperror("closing rawerrorstream");
        else
            rawerrorstream = NULL;
    }

    if ((f = HDfopen(fname, "w")) != NULL) {
        rawerrorstream = f;
        return 0;
    }

    return -1;
}

/*-------------------------------------------------------------------------
 * Function:    set_binary_form
 *
 * Purpose: set the binary form of output by translating from a string input
 *          parameter to a integer return value
 *
 * Return: integer form of binary output or -1 if none found
 *
 * Programmer:  Pedro Vicente Nunes
 *             June 28, 2006
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static int
set_binary_form(const char *form)
{
    int bform = -1;

    if (HDstrcmp(form,"NATIVE") == 0 || HDstrcmp(form,"MEMORY") == 0) {
        /* native form */
        bform = 0;
    }
    else if (HDstrcmp(form,"FILE") == 0) /* file type form */
        bform = 1;
    else if (HDstrcmp(form,"LE") == 0) /* convert to little endian */
        bform = 2;
    else if (HDstrcmp(form,"BE") == 0) /* convert to big endian */
        bform = 3;

    return bform;
}

/*-------------------------------------------------------------------------
 * Function:    set_sort_by
 *
 * Purpose: set the "by" form of sorting by translating from a string input
 *          parameter to a H5_index_t return value
 *          current sort values are [creation_order | name]
 *
 * Return: H5_index_t form of sort or H5_INDEX_UNKNOWN if none found
 *
 * Programmer:  Pedro Vicente Nunes
 *              October 1, 2007
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static H5_index_t
set_sort_by(const char *form)
{
    H5_index_t idx_type = H5_INDEX_UNKNOWN;

    if (HDstrcmp(form,"name")==0) /* H5_INDEX_NAME */
        idx_type = H5_INDEX_NAME;
    else if (HDstrcmp(form,"creation_order")==0) /* H5_INDEX_CRT_ORDER */
        idx_type = H5_INDEX_CRT_ORDER;

    return idx_type;
}

/*-------------------------------------------------------------------------
 * Function:    set_sort_order
 *
 * Purpose: set the order of sorting by translating from a string input
 *          parameter to a H5_iter_order_t return value
 *          current order values are [ascending | descending ]
 *
 * Return: H5_iter_order_t form of order or H5_ITER_UNKNOWN if none found
 *
 * Programmer:  Pedro Vicente Nunes
 *              October 1, 2007
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static H5_iter_order_t
set_sort_order(const char *form)
{
    H5_iter_order_t iter_order = H5_ITER_UNKNOWN;

    if (HDstrcmp(form,"ascending")==0) /* H5_ITER_INC */
        iter_order = H5_ITER_INC;
    else if (HDstrcmp(form,"descending")==0) /* H5_ITER_DEC */
        iter_order = H5_ITER_DEC;

    return iter_order;
}

/*-------------------------------------------------------------------------
 * Function:    parse_hsize_list
 *
 * Purpose:     Parse a list of comma or space separated integers and return
 *              them in a list. The string being passed into this function
 *              should be at the start of the list you want to parse. You are
 *              responsible for freeing the array returned from here.
 *
 *              Lists in the so-called "terse" syntax are separated by
 *              semicolons (;). The lists themselves can be separated by
 *              either commas (,) or white spaces.
 *
 * Return:      <none>
 *
 * Programmer:  Bill Wendling
 *              Tuesday, 6. February 2001
 *
 *-------------------------------------------------------------------------
 */
static void
parse_hsize_list(const char *h_list, subset_d *d)
{
    hsize_t        *p_list;
    const char     *ptr;
    unsigned int    size_count = 0;
    unsigned int    i = 0;
    unsigned int    last_digit = 0;

    if (!h_list || !*h_list || *h_list == ';')
        return;

    /* count how many integers do we have */
    for (ptr = h_list; ptr && *ptr && *ptr != ';' && *ptr != ']'; ptr++)
        if (HDisdigit(*ptr)) {
            if (!last_digit)
                /* the last read character wasn't a digit */
                size_count++;

            last_digit = 1;
        } 
        else {
            last_digit = 0;
        }

    if (size_count == 0)
        /* there aren't any integers to read */
        return;

    /* allocate an array for the integers in the list */
    p_list = (hsize_t *)HDcalloc(size_count, sizeof(hsize_t));

    for (ptr = h_list; i < size_count && ptr && *ptr && *ptr != ';' && *ptr != ']'; ptr++)
        if(HDisdigit(*ptr)) {
            /* we should have an integer now */
            p_list[i++] = (hsize_t)HDatof(ptr);

            while (HDisdigit(*ptr))
                /* scroll to end of integer */
                ptr++;
        }
    d->data = p_list;
    d->len = size_count;
    
    return;
}

/*-------------------------------------------------------------------------
 * Function:    parse_subset_params
 *
 * Purpose:     Parse the so-called "terse" syntax for specifying subsetting
 *              parameters.
 *
 * Return:      Success:    struct subset_t object
 *              Failure:    NULL
 *
 * Programmer:  Bill Wendling
 *              Tuesday, 6. February 2001
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static struct subset_t *
parse_subset_params(char *dset)
{
    struct subset_t *s = NULL;
    register char   *brace;

    if (!disable_compact_subset && ((brace = HDstrrchr(dset, '[')) != NULL)) {
        *brace++ = '\0';

        s = (struct subset_t *)HDcalloc(1, sizeof(struct subset_t));
        parse_hsize_list(brace, &s->start);

        while (*brace && *brace != ';')
            brace++;

        if (*brace) brace++;

        parse_hsize_list(brace, &s->stride);

        while (*brace && *brace != ';')
            brace++;

        if (*brace) brace++;

        parse_hsize_list(brace, &s->count);

        while (*brace && *brace != ';')
            brace++;

        if (*brace) brace++;

        parse_hsize_list(brace, &s->block);
    }

    return s;
}

/*-------------------------------------------------------------------------
 * Function:    parse_mask_list
 *
 * Purpose:     Parse a list of comma or space separated integers and fill
 *              the packed_bits list and counter. The string being passed into this function
 *              should be at the start of the list you want to parse. 
 *
 * Return:      Success:        SUCCEED
 *
 *              Failure:        FAIL
 *
 *
 *-------------------------------------------------------------------------
 */
static int
parse_mask_list(const char *h_list)
{
    int                offset_value;
    int                length_value;
    unsigned long long temp_mask;
    const char        *ptr = NULL;

    /* sanity check */
    HDassert(h_list);

    HDmemset(packed_mask,0,sizeof(packed_mask));

    packed_bits_num = 0;
    /* scan in pair of offset,length separated by commas. */
    ptr = h_list;
    while (*ptr) {
        /* scan for an offset which is an unsigned int */
        if (!HDisdigit(*ptr)) {
            error_msg("Bad mask list(%s)\n", h_list);
            return FAIL;
        }
        offset_value = HDatoi(ptr);
        if (offset_value < 0 || offset_value >= PACKED_BITS_SIZE_MAX) {
            error_msg("Packed Bit offset value(%d) must be between 0 and %d\n",
                    offset_value, PACKED_BITS_SIZE_MAX - 1);
            return FAIL;
        }

        /* skip to end of integer */
        while (HDisdigit(*++ptr))
            ;
        /* Look for the common separator */
        if (*ptr++ != ',') {
            error_msg("Bad mask list(%s), missing expected comma separator.\n", h_list);
            return FAIL;
        }

        /* scan for a length which is a positive int */
        if (!HDisdigit(*ptr)) {
            error_msg("Bad mask list(%s)\n", h_list);
            return FAIL;
        }
        length_value = HDatoi(ptr);
        if (length_value <= 0) {
            error_msg("Packed Bit length value(%d) must be positive.\n", length_value);
            return FAIL;
        }
        if ((offset_value + length_value) > PACKED_BITS_SIZE_MAX){
            error_msg("Packed Bit offset+length value(%d) too large. Max is %d\n",
                       offset_value+length_value, PACKED_BITS_SIZE_MAX);
            return FAIL;
        }

        /* skip to end of int */
        while (HDisdigit(*++ptr))
            ;

        /* store the offset,length pair */
        if (packed_bits_num >= PACKED_BITS_MAX) {
            /* too many requests */
            error_msg("Too many masks requested (max. %d). Mask list(%s)\n", PACKED_BITS_MAX, h_list);
            return FAIL;
        }
        packed_offset[packed_bits_num] = offset_value;
        packed_length[packed_bits_num] = length_value;
        /* create the bit mask by left shift 1's by length, then negate it. */
        /* After packed_mask is calculated, packed_length is not needed but  */
        /* keep it for debug purpose. */
        temp_mask = ~0L;
        if(length_value<8*sizeof(unsigned long long)) {
            temp_mask = temp_mask << length_value;
            packed_mask[packed_bits_num] = ~temp_mask;
        }
        else
            packed_mask[packed_bits_num] = temp_mask;
        packed_bits_num++;

        /* skip a possible comma separator */
        if (*ptr == ',') {
            if (!(*++ptr)) {
                /* unexpected end of string */
                error_msg("Bad mask list(%s), unexpected end of string.\n", h_list);
                return FAIL;
            }
        }
    }
    HDassert(packed_bits_num <= PACKED_BITS_MAX);
    if (packed_bits_num == 0) {
        /* got no masks! */
        error_msg("Bad mask list(%s)\n", h_list);
        return FAIL;
    }
    return SUCCEED;
}


/*-------------------------------------------------------------------------
 * Function:    free_handler
 *
 * Purpose:     Convenience function to free the handler_t structures. Needs a
 *              length variable (LEN) to know how many in the array it needs
 *              to free
 *
 * Return:      Nothing
 *
 * Programmer:  Bill Wendling
 *              Tuesday, 20. February 2001
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static void
free_handler(struct handler_t *hand, int len)
{
    register int i;
    
    if(hand) {
        for (i = 0; i < len; i++) {
            if(hand[i].obj) {
                HDfree(hand[i].obj);
                hand[i].obj=NULL;
            }

            if (hand[i].subset_info) {
                if(hand[i].subset_info->start.data)
                    HDfree(hand[i].subset_info->start.data);
                if(hand[i].subset_info->stride.data)
                    HDfree(hand[i].subset_info->stride.data);
                if(hand[i].subset_info->count.data)
                    HDfree(hand[i].subset_info->count.data);
                if(hand[i].subset_info->block.data)
                    HDfree(hand[i].subset_info->block.data);

                HDfree(hand[i].subset_info);
                hand[i].subset_info=NULL;
            }
        }

        HDfree(hand);
    }
}


/*-------------------------------------------------------------------------
 * Function:    parse_command_line
 *
 * Purpose:     Parse the command line for the h5dumper.
 *
 * Return:      Success:    A pointer to an array of handler_t structures.
 *                          These contain all the information needed to dump
 *                          the necessary object.
 *
 *              Failure:    Exits program with EXIT_FAILURE value.
 *
 * Programmer:  Bill Wendling
 *              Tuesday, 20. February 2001
 *
 * Modifications:
 *  pvn June, 1, 2006. Add a switch for binary output
 *
 *-------------------------------------------------------------------------
 */
static struct handler_t *
parse_command_line(int argc, const char *argv[])
{
    struct handler_t   *hand = NULL;
    struct handler_t   *last_dset = NULL;
    int                 i;
    int                 opt;
    int                 last_was_dset = FALSE;

     /* no arguments */
    if (argc == 1) {
        usage(h5tools_getprogname());
        goto error;
    }

    /* this will be plenty big enough to hold the info */
    if((hand = (struct handler_t *)HDcalloc((size_t)argc, sizeof(struct handler_t)))==NULL) {
            goto error;
    }

    /* parse command line options */
    while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) {
parse_start:
        switch ((char)opt) {
        case 'R':
            display_region = TRUE;
            region_output = TRUE;
            break;
        case 'B':
            display_bb = TRUE;
            last_was_dset = FALSE;
            break;
        case 'n':
            display_fi = TRUE;
            last_was_dset = FALSE;
            break;
        case 'p':
            display_dcpl = TRUE;
            break;
        case 'y':
            display_ai = FALSE;
            break;
        case 'e':
            display_escape = TRUE;
            break;
        case 'H':
            display_data = FALSE;
            display_attr_data = FALSE;
            last_was_dset = FALSE;
            break;
        case 'A':
            display_data = FALSE;
            display_attr_data = TRUE;
            last_was_dset = FALSE;
            break;
        case 'i':
            display_oid = TRUE;
            last_was_dset = FALSE;
            break;
        case 'r':
            display_char = TRUE;
            break;
        case 'V':
            print_version(h5tools_getprogname());
            free_handler(hand, argc);
            hand = NULL;
            h5tools_setstatus(EXIT_SUCCESS);
            goto done;
            break;
        case 'w':
            h5tools_nCols = HDatoi(opt_arg);
            last_was_dset = FALSE;
            break;
        case 'a':
            display_all = 0;

            for (i = 0; i < argc; i++)
                if (!hand[i].func) {
                    hand[i].func = handle_attributes;
                    hand[i].obj = HDstrdup(opt_arg);
                    break;
                }

            last_was_dset = FALSE;
            break;
        case 'd':
            display_all = 0;

            for (i = 0; i < argc; i++)
                if (!hand[i].func) {
                    hand[i].func = handle_datasets;
                    hand[i].obj = HDstrdup(opt_arg);
                    hand[i].subset_info = parse_subset_params(hand[i].obj);
                    last_dset = &hand[i];
                    break;
                }

            last_was_dset = TRUE;
            break;
        case 'f':
            driver = opt_arg;
            break;
        case 'g':
            display_all = 0;

            for (i = 0; i < argc; i++)
                if (!hand[i].func) {
                    hand[i].func = handle_groups;
                    hand[i].obj = HDstrdup(opt_arg);
                    break;
                }

            last_was_dset = FALSE;
            break;
        case 'l':
            display_all = 0;

            for (i = 0; i < argc; i++)
                if (!hand[i].func) {
                    hand[i].func = handle_links;
                    hand[i].obj = HDstrdup(opt_arg);
                    break;
                }

            last_was_dset = FALSE;
            break;
        case 't':
            display_all = 0;

            for (i = 0; i < argc; i++)
                if (!hand[i].func) {
                    hand[i].func = handle_datatypes;
                    hand[i].obj = HDstrdup(opt_arg);
                    break;
                }

            last_was_dset = FALSE;
            break;

        case 'o':
            if ( bin_output ) {
                if (set_data_output_file(opt_arg, 1) < 0) {
                    usage(h5tools_getprogname());
                    goto error;
                }
            }
            else {
                if (set_data_output_file(opt_arg, 0) < 0) {
                    usage(h5tools_getprogname());
                    goto error;
                }
            }

            usingdasho = TRUE;
            last_was_dset = FALSE;
            outfname = opt_arg;
            break;

        case 'b':
            if ( opt_arg != NULL) {
                if ( ( bin_form = set_binary_form(opt_arg)) < 0) {
                    /* failed to set binary form */
                    usage(h5tools_getprogname());
                    goto error;
                }
            }
            bin_output = TRUE;
            if (outfname!=NULL) {
                if (set_data_output_file(outfname, 1) < 0)  {
                    /* failed to set output file */
                    usage(h5tools_getprogname());
                    goto error;
                }

                last_was_dset = FALSE;
            }
            break;

        case 'q':
            if ( ( sort_by = set_sort_by(opt_arg)) < 0) {
                /* failed to set "sort by" form */
                usage(h5tools_getprogname());
                goto error;
            }
            break;

        case 'z':
            if ( ( sort_order = set_sort_order(opt_arg)) < 0) {
                /* failed to set "sort order" form */
                usage(h5tools_getprogname());
                goto error;
            }
            break;

        case 'M':
            if (!last_was_dset) {
                error_msg("option `-%c' can only be used after --dataset option\n", opt);
                goto error;
            }
            if (parse_mask_list(opt_arg) != SUCCEED){
                usage(h5tools_getprogname());
                goto error;
            }
            display_packed_bits = TRUE;
            break;

        /** begin XML parameters **/
        case 'x':
            /* select XML output */
            doxml = TRUE;
            useschema = TRUE;
            h5tools_dump_header_format = NULL;
            dump_function_table = &xml_function_table;
            h5tools_nCols = 0;
            break;
        case 'u':
            doxml = TRUE;
            useschema = FALSE;
            xmlnsprefix = "";
            h5tools_dump_header_format = NULL;
            dump_function_table = &xml_function_table;
            h5tools_nCols = 0;
            break;
        case 'D':
            /* specify alternative XML DTD or schema */
            /* To Do: check format of this value?  */
            xml_dtd_uri = opt_arg;
            h5tools_nCols = 0;
            break;

        case 'm':
            /* specify alternative floating point printing format */
            fp_format = opt_arg;
            h5tools_nCols = 0;
            break;

        case 'X':
            /* specify XML namespace (default="hdf5:"), or none */
            /* To Do: check format of this value?  */
            if (!useschema) {
                usage(h5tools_getprogname());
                goto error;
            }
            if (HDstrcmp(opt_arg,":") == 0) {
                xmlnsprefix = "";
            } 
            else {
                xmlnsprefix = opt_arg;
            }
            h5tools_nCols = 0;
            break;
        /** end XML parameters **/

        /** begin subsetting parameters **/
        case 's':
        case 'S':
        case 'c':
        case 'k': {
            struct subset_t *s;

            if (!last_was_dset) {
                error_msg("option `-%c' can only be used after --dataset option\n", opt);
                goto error;
            }

            if (last_dset->subset_info) {
                /*
                 * This overrides the "terse" syntax if they actually mixed
                 * the two.
                 */
                s = last_dset->subset_info;
            } 
            else {
                last_dset->subset_info = s = (struct subset_t *)HDcalloc(1, sizeof(struct subset_t));
            }

            /*
             * slightly convoluted, but...we are only interested in options
             * for subsetting: "--start", "--stride", "--count", and "--block"
             * which can come in any order. If we run out of parameters (EOF)
             * or run into one which isn't a subsetting parameter (NOT s, S,
             * c, or K), then we exit the do-while look, set the subset_info
             * to the structure we've been filling. If we've reached the end
             * of the options, we exit the parsing (goto parse_end) otherwise,
             * since we've "read" the next option, we need to parse it. So we
             * jump to the beginning of the switch statement (goto parse_start).
             */
            do {
                switch ((char)opt) {
                case 's':
                    if (s->start.data) {
                        HDfree(s->start.data);
                        s->start.data = NULL;
                    }
                    parse_hsize_list(opt_arg, &s->start);
                    break;
                case 'S':
                    if (s->stride.data) {
                        HDfree(s->stride.data);
                        s->stride.data = NULL;
                    }
                    parse_hsize_list(opt_arg, &s->stride);
                    break;
                case 'c':
                    if (s->count.data) {
                        HDfree(s->count.data);
                        s->count.data = NULL;
                }
                    parse_hsize_list(opt_arg, &s->count);
                    break;
                case 'k':
                    if (s->block.data) {
                        HDfree(s->block.data);
                        s->block.data = NULL;
                    }
                    parse_hsize_list(opt_arg, &s->block);
                    break;
                default:
                    goto end_collect;
                }
            } while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF);

end_collect:
            last_was_dset = FALSE;

            if (opt != EOF)
                goto parse_start;
            else
                goto parse_end;
        }
        /** end subsetting parameters **/

        case 'E':
            enable_error_stack = TRUE;
            break;
        case 'C':
            disable_compact_subset = TRUE;
            break;
        case 'h':
            usage(h5tools_getprogname());
            free_handler(hand, argc);
            hand = NULL;
            h5tools_setstatus(EXIT_SUCCESS);
            goto done;
        case '?':
        default:
            usage(h5tools_getprogname());
            goto error;
        }
    }

parse_end:
    /* check for file name to be processed */
    if (argc <= opt_ind) {
        error_msg("missing file name\n");
        usage(h5tools_getprogname());
        goto error;
    }
done:
    return hand;

error:
    if (hand) {
        free_handler(hand, argc);
        hand = NULL;
    }
    h5tools_setstatus(EXIT_FAILURE);

    return hand;
}

/*-------------------------------------------------------------------------
 * Function:    main
 *
 * Purpose:     HDF5 dumper
 *
 * Return:      Success:    0
 *              Failure:    1
 *
 * Programmer:  Ruey-Hsia Li
 *
 * Modifications:
 *        Albert Cheng
 *        30. September 2000
 *        Add the -o option--output file for datasets raw data
 *
 *        REMcG
 *        November 2000
 *        Changes to support XML.
 *
 *        Bill Wendling
 *        Wednesday, 10. January 2001
 *        Modified the way command line parameters are interpreted. They go
 *        through one function call now (get_option).
 *
 *        Bill Wendling
 *        Tuesday, 20. February 2001
 *        Moved command line parsing to separate function. Made various
 *        "display_*" flags global.
 *
 *        REMcG
 *        August 2003
 *        Major upgrade to XML support.
 *
 *        Pedro Vicente
 *        September 2007
 *        list objects in requested order (creation order or alphabetically)
 *
 *-------------------------------------------------------------------------
 */
int
main(int argc, const char *argv[])
{
    hid_t               fid = -1;
    hid_t               gid = -1;
    H5E_auto2_t         func;
    H5E_auto2_t         tools_func;
    H5O_info_t          oi;
    struct handler_t   *hand = NULL;
    int                 i;
    unsigned            u;
    void               *edata;
    void               *tools_edata;
    char               *fname = NULL;

    h5tools_setprogname(PROGRAMNAME);
    h5tools_setstatus(EXIT_SUCCESS);
    h5tools_dump_header_format = &h5tools_standardformat;
    dump_function_table = &ddl_function_table;
    dump_indent = 0;

    /* Disable error reporting */
    H5Eget_auto2(H5E_DEFAULT, &func, &edata);
    H5Eset_auto2(H5E_DEFAULT, NULL, NULL);

    /* Initialize h5tools lib */
    h5tools_init();
    /* Disable tools error reporting */
    H5Eget_auto2(H5tools_ERR_STACK_g, &tools_func, &tools_edata);
    H5Eset_auto2(H5tools_ERR_STACK_g, NULL, NULL);
    
    if((hand = parse_command_line(argc, argv))==NULL) {
        goto done;
    }

    if (bin_output && outfname == NULL) {
        error_msg("binary output requires a file name, use -o <filename>\n");
        h5tools_setstatus(EXIT_FAILURE);
        goto done;
    }

    if (enable_error_stack) {
        H5Eset_auto2(H5E_DEFAULT, func, edata);
        H5Eset_auto2(H5tools_ERR_STACK_g, tools_func, tools_edata);
    }

    /* Check for conflicting options */
    if (doxml) {
        if (!display_all) {
            error_msg("option \"%s\" not available for XML\n",
                    "to display selected objects");
            h5tools_setstatus(EXIT_FAILURE);
            goto done;
        } 
        else if (display_bb) {
            error_msg("option \"%s\" not available for XML\n", "--boot-block");
            h5tools_setstatus(EXIT_FAILURE);
            goto done;
        } 
        else if (display_oid == 1) {
            error_msg("option \"%s\" not available for XML\n", "--object-ids");
            h5tools_setstatus(EXIT_FAILURE);
            goto done;
        } 
        else if (display_char == TRUE) {
            error_msg("option \"%s\" not available for XML\n", "--string");
            h5tools_setstatus(EXIT_FAILURE);
            goto done;
        } 
        else if (usingdasho) {
            error_msg("option \"%s\" not available for XML\n", "--output");
            h5tools_setstatus(EXIT_FAILURE);
            goto done;
        }
    } 
    else {
        if (xml_dtd_uri) {
            warn_msg("option \"%s\" only applies with XML: %s\n", "--xml-dtd", xml_dtd_uri);
        }
    }

    if (argc <= opt_ind) {
        error_msg("missing file name\n");
        usage(h5tools_getprogname());
        h5tools_setstatus(EXIT_FAILURE);
        goto done;
    }
    while(opt_ind < argc) {
        fname = HDstrdup(argv[opt_ind++]);

        fid = h5tools_fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT, driver, NULL, 0);

        if (fid < 0) {
            error_msg("unable to open file \"%s\"\n", fname);
            h5tools_setstatus(EXIT_FAILURE);
            goto done;
        }

        /* allocate and initialize internal data structure */
        init_prefix(&prefix, prefix_len);

        /* Prepare to find objects that might be targets of a reference */
        fill_ref_path_table(fid);

        if(doxml) {
            /* initialize XML */
            /* reset prefix! */
            HDstrcpy(prefix, "");

            /* make sure the URI is initialized to something */
            if (xml_dtd_uri == NULL) {
                if (useschema) {
                    xml_dtd_uri = DEFAULT_XSD;
                } 
                else {
                    xml_dtd_uri = DEFAULT_DTD;
                    xmlnsprefix = "";
                }
            } 
            else {
                if (useschema && HDstrcmp(xmlnsprefix,"")) {
                    error_msg("Cannot set Schema URL for a qualified namespace--use -X or -U option with -D \n");
                    h5tools_setstatus(EXIT_FAILURE);
                    goto done;
                }
            }
        }

        /* Get object info for root group */
        if(H5Oget_info_by_name(fid, "/", &oi, H5P_DEFAULT) < 0) {
            error_msg("internal error (file %s:line %d)\n", __FILE__, __LINE__);
            h5tools_setstatus(EXIT_FAILURE);
            goto done;
        }

        /* Initialize object tables */
        if(table_list_add(fid, oi.fileno) < 0) {
            error_msg("internal error (file %s:line %d)\n", __FILE__, __LINE__);
            h5tools_setstatus(EXIT_FAILURE);
            goto done;
        }
        group_table = table_list.tables[0].group_table;
        dset_table = table_list.tables[0].dset_table;
        type_table = table_list.tables[0].type_table;

        /* does there exist unamed committed datatype */
        for (u = 0; u < type_table->nobjs; u++)
            if (!type_table->objs[u].recorded) {
                unamedtype = 1;
                break;
            } /* end if */

        /* start to dump - display file header information */
        if (!doxml) {
            begin_obj(h5tools_dump_header_format->filebegin, fname, h5tools_dump_header_format->fileblockbegin);
        } 
        else {
            HDfprintf(rawoutstream, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");

            /* alternative first element, depending on schema or DTD. */
            if (useschema) {
                if (HDstrcmp(xmlnsprefix,"") == 0) {
                    HDfprintf(rawoutstream, "<HDF5-File xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"%s\">\n",
                            xml_dtd_uri);
                } 
                else {
                    /*  TO DO: make -url option work in this case (may need new option) */
                    char *ns;
                    char *indx;

                    ns = HDstrdup(xmlnsprefix);
                    indx = HDstrrchr(ns,(int)':');
                    if (indx) *indx = '\0';

                    HDfprintf(rawoutstream, "<%sHDF5-File xmlns:%s=\"http://hdfgroup.org/HDF5/XML/schema/HDF5-File\" "
                            "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
                            "xsi:schemaLocation=\"http://hdfgroup.org/HDF5/XML/schema/HDF5-File "
                            "http://www.hdfgroup.org/HDF5/XML/schema/HDF5-File.xsd\">\n",xmlnsprefix,ns);
                    HDfree(ns);
                }
            } 
            else {
                HDfprintf(rawoutstream, "<!DOCTYPE HDF5-File PUBLIC \"HDF5-File.dtd\" \"%s\">\n", xml_dtd_uri);
                HDfprintf(rawoutstream, "<HDF5-File>\n");
            }
        }

        if (!doxml) {
            if (display_fi) {
                HDfprintf(rawoutstream, "\n");
                dump_fcontents(fid);
                end_obj(h5tools_dump_header_format->fileend,h5tools_dump_header_format->fileblockend);
                HDfprintf(rawoutstream, "\n");
                goto done;
            }

            if (display_bb)
                dump_fcpl(fid);
        }

        if(display_all) {
            if((gid = H5Gopen2(fid, "/", H5P_DEFAULT)) < 0) {
                error_msg("unable to open root group\n");
                h5tools_setstatus(EXIT_FAILURE);
            }
            else {
                if (!doxml)
                    dump_indent += COL;
                dump_function_table->dump_group_function(gid, "/" );
                if (!doxml)
                    dump_indent -= COL;
                HDfprintf(rawoutstream, "\n");
            }

            if(H5Gclose(gid) < 0) {
                error_msg("unable to close root group\n");
                h5tools_setstatus(EXIT_FAILURE);
            }

        }
        else {
            /* Note: this option is not supported for XML */
            if(doxml) {
                error_msg("internal error (file %s:line %d)\n", __FILE__, __LINE__);
                h5tools_setstatus(EXIT_FAILURE);
                goto done;
            } /* end if */

            for(i = 0; i < argc; i++) {
                if(hand[i].func) {
                    hand[i].func(fid, hand[i].obj, hand[i].subset_info, 1, NULL);
                }
            }
            HDfprintf(rawoutstream, "\n");
        }

        if (!doxml) {
            end_obj(h5tools_dump_header_format->fileend, h5tools_dump_header_format->fileblockend);
            HDfprintf(rawoutstream, "\n");
        } 
        else {
            HDfprintf(rawoutstream, "</%sHDF5-File>\n", xmlnsprefix);
        }
        /* Free tables for objects */
        table_list_free();

        if(fid >=0)
            if (H5Fclose(fid) < 0)
                h5tools_setstatus(EXIT_FAILURE);

        if(prefix)
            HDfree(prefix);
        if(fname)
            HDfree(fname);
    } /* end while */

    if(hand) 
        free_handler(hand, argc);

    /* To Do:  clean up XML table */

    leave(h5tools_getstatus());

done:
    /* Free tables for objects */
    table_list_free();

    if(fid >=0)
        if (H5Fclose(fid) < 0)
            h5tools_setstatus(EXIT_FAILURE);
    
    if(prefix)
        HDfree(prefix);
    if(fname)
        HDfree(fname);

    if(hand) 
        free_handler(hand, argc);

    /* To Do:  clean up XML table */

    H5Eset_auto2(H5E_DEFAULT, func, edata);

    leave(h5tools_getstatus());
}

/*-------------------------------------------------------------------------
 * Function:    h5_fileaccess
 *
 * Purpose: Returns a file access template which is the default template
 *      but with a file driver set according to the constant or
 *      environment variable HDF5_DRIVER
 *
 * Return:  Success:    A file access property list
 *
 *      Failure:    -1
 *
 * Programmer:  Robb Matzke
 *              Thursday, November 19, 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
hid_t
h5_fileaccess(void)
{
    static const char *multi_letters = "msbrglo";
    const char  *val = NULL;
    const char  *name;
    char         s[1024];
    hid_t        fapl = -1;

    /* First use the environment variable, then the constant */
    val = HDgetenv("HDF5_DRIVER");
#ifdef HDF5_DRIVER
    if (!val) val = HDF5_DRIVER;
#endif

    if ((fapl=H5Pcreate(H5P_FILE_ACCESS))<0) return -1;
    if (!val || !*val) return fapl; /*use default*/

    HDstrncpy(s, val, sizeof s);
    s[sizeof(s)-1] = '\0';
    if (NULL==(name=HDstrtok(s, " \t\n\r"))) return fapl;

    if (!HDstrcmp(name, "sec2")) {
        /* Unix read() and write() system calls */
        if (H5Pset_fapl_sec2(fapl)<0) return -1;
    } 
    else if (!HDstrcmp(name, "stdio")) {
        /* Standard C fread() and fwrite() system calls */
        if (H5Pset_fapl_stdio(fapl)<0) return -1;
    } 
    else if (!HDstrcmp(name, "core")) {
        /* In-core temporary file with 1MB increment */
        if (H5Pset_fapl_core(fapl, 1024*1024, FALSE)<0) return -1;
    } 
    else if (!HDstrcmp(name, "split")) {
        /* Split meta data and raw data each using default driver */
        if (H5Pset_fapl_split(fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT) < 0)
            return -1;
    } 
    else if (!HDstrcmp(name, "multi")) {
        /* Multi-file driver, general case of the split driver */
        H5FD_mem_t      memb_map[H5FD_MEM_NTYPES];
        hid_t           memb_fapl[H5FD_MEM_NTYPES];
        const char     *memb_name[H5FD_MEM_NTYPES];
        char            sv[H5FD_MEM_NTYPES][1024];
        haddr_t         memb_addr[H5FD_MEM_NTYPES];
        H5FD_mem_t      mt;

        HDmemset(memb_map, 0, sizeof memb_map);
        HDmemset(memb_fapl, 0, sizeof memb_fapl);
        HDmemset(memb_name, 0, sizeof memb_name);
        HDmemset(memb_addr, 0, sizeof memb_addr);

        HDassert(HDstrlen(multi_letters)==H5FD_MEM_NTYPES);
        for (mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t,mt)) {
            memb_fapl[mt] = H5P_DEFAULT;
            memb_map[mt] = mt;
            sprintf(sv[mt], "%%s-%c.h5", multi_letters[mt]);
            memb_name[mt] = sv[mt];
            memb_addr[mt] = MAX(mt-1,0)*(HADDR_MAX/10);
        }

        if (H5Pset_fapl_multi(fapl, memb_map, memb_fapl, memb_name, memb_addr, FALSE) < 0)
            return -1;
    } 
    else if (!HDstrcmp(name, "family")) {
        hsize_t fam_size = 100*1024*1024; /*100 MB*/

        /* Family of files, each 1MB and using the default driver */
        if ((val=HDstrtok(NULL, " \t\n\r")))
            fam_size = (hsize_t)(HDstrtod(val, NULL) * 1024*1024);
        if (H5Pset_fapl_family(fapl, fam_size, H5P_DEFAULT)<0)
            return -1;
    } 
    else if (!HDstrcmp(name, "log")) {
        long log_flags = H5FD_LOG_LOC_IO;

        /* Log file access */
        if ((val = HDstrtok(NULL, " \t\n\r")))
            log_flags = HDstrtol(val, NULL, 0);

        if (H5Pset_fapl_log(fapl, NULL, (unsigned)log_flags, 0) < 0)
            return -1;
    } 
    else if (!HDstrcmp(name, "direct")) {
        /* Substitute Direct I/O driver with sec2 driver temporarily because
         * some output has sec2 driver as the standard. */
        if (H5Pset_fapl_sec2(fapl)<0) return -1;
    } 
    else {
        /* Unknown driver */
        return -1;
    }

    return fapl;
}


/*-------------------------------------------------------------------------
 * Function:    init_prefix
 *
 * Purpose:     allocate and initialize prefix
 *
 * Return:      void
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static void
init_prefix(char **prfx, size_t prfx_len)
{
    HDassert(prfx_len > 0);
    *prfx = (char *)HDcalloc(prfx_len, 1);
}


/*-------------------------------------------------------------------------
 * Function:    add_prefix
 *
 * Purpose:     Add object to prefix
 *
 * Return:      void
 *
 *-------------------------------------------------------------------------
 */
void
add_prefix(char **prfx, size_t *prfx_len, const char *name)
{
    size_t new_len = HDstrlen(*prfx) + HDstrlen(name) + 2;

    /* Check if we need more space */
    if(*prfx_len <= new_len) {
        *prfx_len = new_len + 1;
        *prfx = (char *)HDrealloc(*prfx, *prfx_len);
    }

    /* Append object name to prefix */
    HDstrcat(HDstrcat(*prfx, "/"), name);
} /* end add_prefix */