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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>HDF5: HDF5 Datasets</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function() { init_search(); });
/* @license-end */
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="hdf5doxy.css" rel="stylesheet" type="text/css">
<!-- <link href="hdf5doxy.css" rel="stylesheet" type="text/css"/>
-->
<script type="text/javascript" src="hdf5_navtree_hacks.js"></script>
</head>
<body>
<div style="background:#FFDDDD;font-size:120%;text-align:center;margin:0;padding:5px">Please, help us to better serve our user community by answering the following short survey: <a href="https://www.hdfgroup.org/website-survey/">https://www.hdfgroup.org/website-survey/</a></div>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="HDFG-logo.png"/></td>
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname"><a href="https://www.hdfgroup.org">HDF5</a>
 <span id="projectnumber">1.15.0.627fba0</span>
</div>
<div id="projectbrief">API Reference</div>
</td>
<td> <div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.svg"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('_h5_d__u_g.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="PageDoc"><div class="header">
<div class="headertitle">
<div class="title">HDF5 Datasets </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><h1><a class="anchor" id="sec_dataset"></a>
HDF5 Datasets</h1>
<h2><a class="anchor" id="subsec_dataset_intro"></a>
Introduction</h2>
<p>An HDF5 dataset is an object composed of a collection of data elements, or raw data, and metadata that stores a description of the data elements, data layout, and all other information necessary to write, read, and interpret the stored data. From the viewpoint of the application the raw data is stored as a one-dimensional or multi-dimensional array of elements (the raw data), those elements can be any of several numerical or character types, small arrays, or even compound types similar to C structs. The dataset object may have attribute objects. See the figure below.</p>
<table class="doxtable">
<tr>
<td><div class="image">
<img src="Dsets_fig1.gif" alt=""/>
<div class="caption">
Application view of a dataset</div></div>
</td></tr>
</table>
<p>A dataset object is stored in a file in two parts: a header and a data array. The header contains information that is needed to interpret the array portion of the dataset, as well as metadata (or pointers to metadata) that describes or annotates the dataset. Header information includes the name of the object, its dimensionality, its number-type, information about how the data itself is stored on disk (the storage layout), and other information used by the library to speed up access to the dataset or maintain the file's integrity.</p>
<p>The HDF5 dataset interface, comprising the <a class="el" href="group___h5_d.html">Datasets (H5D)</a> functions, provides a mechanism for managing HDF5 datasets including the transfer of data between memory and disk and the description of dataset properties.</p>
<p>A dataset is used by other HDF5 APIs, either by name or by an identifier. For more information, </p><dl class="section see"><dt>See also</dt><dd><a class="el" href="api-compat-macros.html">API Compatibility Macros</a>.</dd></dl>
<h3><a class="anchor" id="subsubsec_dataset_intro_link"></a>
Link/Unlink</h3>
<p>A dataset can be added to a group with one of the H5Lcreate calls, and deleted from a group with <a class="el" href="group___h5_l.html#ga5b4e7f59f5d4bdae94fd8ce6875295cf" title="Removes a link from a group.">H5Ldelete</a>. The link and unlink operations use the name of an object, which may be a dataset. The dataset does not have to open to be linked or unlinked.</p>
<h3><a class="anchor" id="subsubsec_dataset_intro_obj"></a>
Object Reference</h3>
<p>A dataset may be the target of an object reference. The object reference is created by <a class="el" href="group___h5_r.html#ga0ac6997b5de26b11d91a95de2869950d" title="Creates a reference.">H5Rcreate</a> with the name of an object which may be a dataset and the reference type <a class="el" href="_h5_rpublic_8h.html#ae1ffa09875ca6778df3a577592dacbd2">H5R_OBJECT</a>. The dataset does not have to be open to create a reference to it.</p>
<p>An object reference may also refer to a region (selection) of a dataset. The reference is created with <a class="el" href="group___h5_r.html#ga0ac6997b5de26b11d91a95de2869950d" title="Creates a reference.">H5Rcreate</a> and a reference type of <a class="el" href="_h5_rpublic_8h.html#a2a28c48c03a4616a02f9157fca4b2df0">H5R_DATASET_REGION</a>.</p>
<p>An object reference can be accessed by a call to <a class="el" href="group___h5_r.html#ga5dc19b9d1833af66c5e1f819f2c05c4a">H5Rdereference</a>. When the reference is to a dataset or dataset region, the <a class="el" href="group___h5_r.html#ga5dc19b9d1833af66c5e1f819f2c05c4a">H5Rdereference</a> call returns an identifier to the dataset just as if <a class="el" href="_h5version_8h.html#a7dba2e5b2045f31c0932123ffb54f7a3">H5Dopen</a> has been called.</p>
<h3><a class="anchor" id="subsubsec_dataset_intro_attr"></a>
Adding Attributes</h3>
<p>A dataset may have user-defined attributes which are created with <a class="el" href="group___h5_a.html#ga4a76e4e5ab6eb0fd2aa7990d38d55f24">H5Acreate</a> and accessed through the <a class="el" href="group___h5_a.html">Attributes (H5A)</a> API. To create an attribute for a dataset, the dataset must be open, and the identifier is passed to <a class="el" href="group___h5_a.html#ga4a76e4e5ab6eb0fd2aa7990d38d55f24">H5Acreate</a>. The attributes of a dataset are discovered and opened using <a class="el" href="group___h5_a.html#ga5c05fade96b6b7e2299f56a5b1edb1c1" title="Opens an attribute specified by name.">H5Aopen_name</a>, <a class="el" href="group___h5_a.html#gadaa85276f2731ad78462a6fd27118470" title="Opens the attribute specified by its index.">H5Aopen_idx</a>, or <a class="el" href="group___h5_a.html#gab9dcfc543cd4282f32b8ea19e08ffa6c">H5Aiterate</a>; these functions use the identifier of the dataset. An attribute can be deleted with <a class="el" href="group___h5_a.html#gada9fa3d6db52329f1fd55662de6ff6ba" title="Deletes an attribute from a specified location.">H5Adelete</a> which also uses the identifier of the dataset.</p>
<h2><a class="anchor" id="subsec_dataset_function"></a>
Dataset Function Summaries</h2>
<p>Functions that can be used with datasets (<a class="el" href="group___h5_d.html">Datasets (H5D)</a> functions) and property list functions that can used with datasets (<a class="el" href="group___h5_p.html">Property Lists (H5P)</a> functions) are listed below.</p>
<table class="doxtable">
<caption>Dataset functions</caption>
<tr>
<th>Function </th><th>Purpose </th></tr>
<tr>
<td><a class="el" href="group___h5_d.html#ga0647ba4bbd26d5230cc07f3a5685b2cf">H5Dcreate</a> </td><td>Creates a dataset at the specified location. The C function is a macro: <dl class="section see"><dt>See also</dt><dd><a class="el" href="api-compat-macros.html">API Compatibility Macros</a>. </dd></dl>
</td></tr>
<tr>
<td><a class="el" href="group___h5_d.html#ga15a77e82383d821fee8ecbf9ab8408cb" title="Creates a dataset in a file without linking it into the file structure.">H5Dcreate_anon</a> </td><td>Creates a dataset in a file without linking it into the file structure. </td></tr>
<tr>
<td><a class="el" href="_h5version_8h.html#a7dba2e5b2045f31c0932123ffb54f7a3">H5Dopen</a> </td><td>Opens an existing dataset. The C function is a macro: <dl class="section see"><dt>See also</dt><dd><a class="el" href="api-compat-macros.html">API Compatibility Macros</a>. </dd></dl>
</td></tr>
<tr>
<td><a class="el" href="group___h5_d.html#gae47c3f38db49db127faf221624c30609" title="Closes the specified dataset.">H5Dclose</a> </td><td>Closes the specified dataset. </td></tr>
<tr>
<td><a class="el" href="group___h5_d.html#gad42a46be153d895d8c28a11ebf5a0d0a" title="Returns an identifier for a copy of the dataspace for a dataset.">H5Dget_space</a> </td><td>Returns an identifier for a copy of the dataspace for a dataset. </td></tr>
<tr>
<td><a class="el" href="group___h5_d.html#ga7639ef5c12cb906c71670ce73b856a4c" title="Determines whether space has been allocated for a dataset.">H5Dget_space_status</a> </td><td>Determines whether space has been allocated for a dataset. </td></tr>
<tr>
<td><a class="el" href="group___h5_d.html#ga7cd04b8332e8a0939b9973fbc500cadb" title="Returns an identifier for a copy of the datatype for a dataset.">H5Dget_type</a> </td><td>Returns an identifier for a copy of the datatype for a dataset. </td></tr>
<tr>
<td><a class="el" href="group___h5_d.html#ga8848f14f4aba8e6160c3d8bb7f1be163" title="Returns an identifier for a copy of the dataset creation property list for a dataset.">H5Dget_create_plist</a> </td><td>Returns an identifier for a copy of the dataset creation property list for a dataset. </td></tr>
<tr>
<td><a class="el" href="group___h5_d.html#ga252c0ddac7a7817bd757190e7398353b" title="Returns the dataset access property list associated with a dataset.">H5Dget_access_plist</a> </td><td>Returns the dataset access property list associated with a dataset. </td></tr>
<tr>
<td><a class="el" href="group___h5_d.html#ga70ce7ab523b06c6c6a93fb28e916c2b3" title="Returns dataset address in file.">H5Dget_offset</a> </td><td>Returns the dataset address in a file. </td></tr>
<tr>
<td><a class="el" href="group___h5_d.html#gafb249479a493e80891f0c7f5d8a91b00" title="Returns the amount of storage allocated for a dataset.">H5Dget_storage_size</a> </td><td>Returns the amount of storage required for a dataset. </td></tr>
<tr>
<td><a class="el" href="group___h5_d.html#ga0e97bbd8a8ee4a8b5b78ccce8547ce76" title="Determines the number of bytes required to store variable-length (VL) data.">H5Dvlen_get_buf_size</a> </td><td>Determines the number of bytes required to store variable-length (VL) data. </td></tr>
<tr>
<td><a class="el" href="group___h5_d.html#ga222a2fd93868e2524b2e42c3c6146119" title="Reclaims variable-length (VL) datatype memory buffers.">H5Dvlen_reclaim</a> </td><td>Reclaims VL datatype memory buffers. </td></tr>
<tr>
<td><a class="el" href="group___h5_d.html#ga8287d5a7be7b8e55ffeff68f7d26811c" title="Reads raw data from a dataset into a provided buffer.">H5Dread</a> </td><td>Reads raw data from a dataset into a buffer. </td></tr>
<tr>
<td><a class="el" href="group___h5_d.html#ga98f44998b67587662af8b0d8a0a75906" title="Writes raw data from a buffer to a dataset.">H5Dwrite</a> </td><td>Writes raw data from a buffer to a dataset. </td></tr>
<tr>
<td><a class="el" href="group___h5_d.html#ga71421c684884ab49765748720fe938db" title="Iterates over all selected elements in a dataspace.">H5Diterate</a> </td><td>Iterates over all selected elements in a dataspace. </td></tr>
<tr>
<td><a class="el" href="group___h5_d.html#ga1f6a428a8234d7c2ccba7da4742d79be" title="Gathers data from a selection within a memory buffer raw data chunk in a dataset.">H5Dgather</a> </td><td>Gathers data from a selection within a memory buffer. </td></tr>
<tr>
<td><a class="el" href="group___h5_d.html#ga3525b15235ba1fd415f988899e48dc5c" title="Scatters data into a selection within a memory buffer.">H5Dscatter</a> </td><td>Scatters data into a selection within a memory buffer. </td></tr>
<tr>
<td><a class="el" href="group___h5_d.html#ga8d4a57e2b2b8c95cfecf6f75bdaa8343" title="Fills dataspace elements with a fill value in a memory buffer.">H5Dfill</a> </td><td>Fills dataspace elements with a fill value in a memory buffer. </td></tr>
<tr>
<td><a class="el" href="group___h5_d.html#gad31e1e0129f4520c531ce524de2a056f" title="Changes the sizes of a dataset's dimensions.">H5Dset_extent</a> </td><td>Changes the sizes of a dataset's dimensions. </td></tr>
</table>
<p><a class="anchor" id="dcpl_table_tag"></a>Dataset creation property list functions (H5P) <a class="anchor" id="table_dcpl_id"></a>
<table class="doxtable">
<caption border="1" style="background-color:whitesmoke;">Dataset creation property list functions (H5P)</caption>
<tr>
<th>Function </th><th>Purpose </th></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga75d80991a8f467e0d454c53a383ae7f9" title="Sets the type of storage used to store the raw data for a dataset.">H5Pset_layout</a> </td><td>Sets the type of storage used to store the raw data for a dataset. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga655530b0f40990507fedeef6b3068db3" title="Returns the layout of the raw data for a dataset.">H5Pget_layout</a> </td><td>Returns the layout of the raw data for a dataset. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga3584d592e377da3604b7604e266dcf5b" title="Sets the size of the chunks used to store a chunked layout dataset.">H5Pset_chunk</a> </td><td>Sets the size of the chunks used to store a chunked layout dataset. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga4ef814034f601f48ab1ed6db79b4354c" title="Retrieves the size of chunks for the raw data of a chunked layout dataset.">H5Pget_chunk</a> </td><td>Retrieves the size of chunks for the raw data of a chunked layout dataset. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga8e60618d9030dc1b99ad9c8ff7867873" title="Sets the edge chunk option in a dataset creation property list.">H5Pset_chunk_opts</a>/<a class="el" href="group___d_c_p_l.html#ga6e8d8f6a14b79bd110e27666d95031cf" title="Retrieves the edge chunk option setting from a dataset creation property list.">H5Pget_chunk_opts</a> </td><td>Sets/gets the edge chunk option setting from a dataset creation property list. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#gaf1f569bfc54552bdb9317d2b63318a0d" title="Sets deflate (GNU gzip) compression method and compression level.">H5Pset_deflate</a> </td><td>Sets compression method and compression level. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga4335bb45b35386daa837b4ff1b9cd4a4" title="Sets the fill value for a dataset.">H5Pset_fill_value</a> </td><td>Sets the fill value for a dataset. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga82bbe8c77c7eb9c460bfd1eb26881355" title="Retrieves a dataset fill value.">H5Pget_fill_value</a> </td><td>Retrieves a dataset fill value. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga14f9bc2a0d6f9e62ab95661fc1045ad6" title="Determines whether fill value is defined.">H5Pfill_value_defined</a> </td><td>Determines whether the fill value is defined. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga6bd822266b31f86551a9a1d79601b6a2" title="Sets the time when fill values are written to a dataset.">H5Pset_fill_time</a> </td><td>Sets the time when fill values are written to a dataset. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga92c5eb5ee19bfd4a9184cf0428d1b00c" title="Retrieves the time when fill values are written to a dataset.">H5Pget_fill_time</a> </td><td>Retrieves the time when fill value are written to a dataset. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga85faefca58387bba409b65c470d7d851" title="Sets the timing for storage space allocation.">H5Pset_alloc_time</a> </td><td>Sets the timing for storage space allocation. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#gaf507a3efa5d1f37448baea089fc053d8" title="Retrieves the timing for storage space allocation.">H5Pget_alloc_time</a> </td><td>Retrieves the timing for storage space allocation. </td></tr>
<tr>
<td><a class="el" href="group___o_c_p_l.html#ga191c567ee50b2063979cdef156a768c5" title="Adds a filter to the filter pipeline.">H5Pset_filter</a> </td><td>Adds a filter to the filter pipeline. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga70f5346250698afc950532e9593c3988" title="Verifies that all required filters are available.">H5Pall_filters_avail</a> </td><td>Verifies that all required filters are available. </td></tr>
<tr>
<td><a class="el" href="group___o_c_p_l.html#gacbad1ca36a61246b439a25f28e7575fb" title="Returns the number of filters in the pipeline.">H5Pget_nfilters</a> </td><td>Returns the number of filters in the pipeline. </td></tr>
<tr>
<td><a class="el" href="_h5version_8h.html#a7e070dfec9cb3a3aaf9c188a987e6a15">H5Pget_filter</a> </td><td>Returns information about a filter in a pipeline. The C function is a macro: <dl class="section see"><dt>See also</dt><dd><a class="el" href="api-compat-macros.html">API Compatibility Macros</a>. </dd></dl>
</td></tr>
<tr>
<td><a class="el" href="_h5version_8h.html#ac7aa336e7b1b9033cea2448ba623951f">H5Pget_filter_by_id</a> </td><td>Returns information about the specified filter. The C function is a macro: <dl class="section see"><dt>See also</dt><dd><a class="el" href="api-compat-macros.html">API Compatibility Macros</a>. </dd></dl>
</td></tr>
<tr>
<td><a class="el" href="group___o_c_p_l.html#ga12a358b3725a889c1768bbd2b5f541d8" title="Modifies a filter in the filter pipeline.">H5Pmodify_filter</a> </td><td>Modifies a filter in the filter pipeline. </td></tr>
<tr>
<td><a class="el" href="group___o_c_p_l.html#gabffbf6d013c090fa052ac4bafce8e532" title="Delete one or more filters in the filter pipeline.">H5Premove_filter</a> </td><td>Deletes one or more filters in the filter pipeline. </td></tr>
<tr>
<td><a class="el" href="group___o_c_p_l.html#ga8bc81abfbd0393b0a46e121f817a3f81" title="Sets up use of the Fletcher32 checksum filter.">H5Pset_fletcher32</a> </td><td>Sets up use of the Fletcher32 checksum filter. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#gad58a9c0e766ef71d4075b2c2a755e91c" title="Sets up the use of the N-Bit filter.">H5Pset_nbit</a> </td><td>Sets up use of the n-bit filter. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga5c10165b670e0e984db431aee818cc7e" title="Sets up the use of the scale-offset filter.">H5Pset_scaleoffset</a> </td><td>Sets up use of the scale-offset filter. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga31e09cb0bf2da2893eed8a72220e6521" title="Sets up use of the shuffle filter.">H5Pset_shuffle</a> </td><td>Sets up use of the shuffle filter. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga37de4b6071a94574cfab5cd6de9c3fc6" title="Sets up use of the SZIP compression filter.">H5Pset_szip</a> </td><td>Sets up use of the Szip compression filter. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga85ff7c9c827fa524041cd58c199b77b8" title="Adds an external file to the list of external files.">H5Pset_external</a> </td><td>Adds an external file to the list of external files. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga4c45d90845ea7627b6238f95168c41ce" title="Returns the number of external files for a dataset.">H5Pget_external_count</a> </td><td>Returns the number of external files for a dataset. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga78253b80b6c86faf7ff0db135146521d" title="Returns information about an external file.">H5Pget_external</a> </td><td>Returns information about an external file. </td></tr>
<tr>
<td><a class="el" href="group___a_c_p_l.html#gad4fa8e2d17236786f770cf17eef908cc" title="Sets the character encoding used to encode link and attribute names.">H5Pset_char_encoding</a> </td><td>Sets the character encoding used to encode a string. Use to set ASCII or UTF-8 character encoding for object names. </td></tr>
<tr>
<td><a class="el" href="group___a_c_p_l.html#ga9b35ef9add6463997330e9b4b606603d" title="Retrieves the character encoding used to create a link or attribute name.">H5Pget_char_encoding</a> </td><td>Retrieves the character encoding used to create a string. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#gadec895092dbbedb94f85d9cacf8924f5" title="Sets the mapping between virtual and source datasets.">H5Pset_virtual</a> </td><td>Sets the mapping between virtual and source datasets. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga83dcce1ce110d1ff6eae0fb77d4a7c85" title="Gets the number of mappings for the virtual dataset.">H5Pget_virtual_count</a> </td><td>Gets the number of mappings for the virtual dataset. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#gaf50620fd5d83dc9ca1e5c3f374c5a952" title="Gets the name of a source dataset used in the mapping.">H5Pget_virtual_dsetname</a> </td><td>Gets the name of a source dataset used in the mapping. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga5c17780cc9a72a0f62d70f6138510afa" title="Gets the filename of a source dataset used in the mapping.">H5Pget_virtual_filename</a> </td><td>Gets the filename of a source dataset used in the mapping. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga8319e9386cdb9b3881a8b698edfc78fc" title="Gets a dataspace identifier for the selection within the source dataset used in the mapping.">H5Pget_virtual_srcspace</a> </td><td>Gets a dataspace identifier for the selection within the source dataset used in the mapping. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga6425cabbc055b66e218b4728d6eb911d" title="Gets a dataspace identifier for the selection within the virtual dataset used in the mapping.">H5Pget_virtual_vspace</a> </td><td>Gets a dataspace identifier for the selection within the virtual dataset used in the mapping. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#gaf5ae8c0257c02e3fbe50bde70b1eb8be" title="Sets the flag to create minimized dataset object headers.">H5Pset_dset_no_attrs_hint</a>/<a class="el" href="group___d_c_p_l.html#ga2fd4f0446a38186db8256cef4c97a970" title="Retrieves the setting for whether or not to create minimized dataset object headers.">H5Pget_dset_no_attrs_hint</a> </td><td>Sets/gets the flag to create minimized dataset object headers. </td></tr>
</table>
<a class="anchor" id="dapl_table_tag"></a>Dataset access property list functions (H5P) <a class="anchor" id="table_dapl_id"></a>
<table class="doxtable">
<caption border="1" style="background-color:whitesmoke;">Dataset access property list functions (H5P)</caption>
<tr>
<th>Function </th><th>Purpose </th></tr>
<tr>
<td><a class="el" href="group___d_x_p_l.html#ga777e8c171c9e462230a9fa40874b38ce" title="Sets type conversion and background buffers.">H5Pset_buffer</a> </td><td>Sets type conversion and background buffers. </td></tr>
<tr>
<td><a class="el" href="group___d_x_p_l.html#ga1278b9979cc833e77d699cc878c6dab4" title="Reads buffer settings.">H5Pget_buffer</a> </td><td>Reads buffer settings. </td></tr>
<tr>
<td><a class="el" href="group___d_a_p_l.html#ga2f685a7b3f3a4fa35ddcd1659ab4a835" title="Sets two actions to perform when the size of a dataset's dimension being appended reaches a specified...">H5Pset_append_flush</a>/<a class="el" href="group___d_a_p_l.html#gacd6803640eebd20e408c330192b09fa6" title="Retrieves the values of the append property that is set up in the dataset access property list.">H5Pget_append_flush</a> </td><td>Sets/gets the values of the append property that is set up in the dataset access property list. </td></tr>
<tr>
<td><a class="el" href="group___d_a_p_l.html#ga104d00442c31714ee073dee518f661f1" title="Sets the raw data chunk cache parameters.">H5Pset_chunk_cache</a>/<a class="el" href="group___d_a_p_l.html#gaeda015dfee4167cc60baab1d1f0560fe" title="Retrieves the raw data chunk cache parameters.">H5Pget_chunk_cache</a> </td><td>Sets/gets the raw data chunk cache parameters. </td></tr>
<tr>
<td><a class="el" href="group___d_a_p_l.html#gad487f84157fd0944cbe1cbd4dea4e1b8" title="Sets the external dataset storage file prefix in the dataset access property list.">H5Pset_efile_prefix</a>/<a class="el" href="group___d_a_p_l.html#ga442647d48171db920c71a7baf6fdeee6" title="Retrieves the prefix for external raw data storage files as set in the dataset access property list.">H5Pget_efile_prefix</a> </td><td>Sets/gets the prefix for external raw data storage files as set in the dataset access property list. </td></tr>
<tr>
<td><a class="el" href="group___d_a_p_l.html#ga6816e0de35a335f636922c3cd5569819" title="Sets prefix to be applied to VDS source file paths.">H5Pset_virtual_prefix</a>/<a class="el" href="group___d_a_p_l.html#ga9a48c80955877c20d53e8fd3f49a2995" title="Retrieves prefix applied to VDS source file paths.">H5Pget_virtual_prefix</a> </td><td>Sets/gets the prefix to be applied to VDS source file paths. </td></tr>
<tr>
<td><a class="el" href="group___d_a_p_l.html#ga8bb25e402e860133b8af3715e429bacf" title="Sets the maximum number of missing source files and/or datasets with the printf-style names when gett...">H5Pset_virtual_printf_gap</a>/<a class="el" href="group___d_a_p_l.html#ga833dfc6d9c87738c9d94b610e70a818f" title="Returns the maximum number of missing source files and/or datasets with the printf-style names when g...">H5Pget_virtual_printf_gap</a> </td><td>Sets/gets the maximum number of missing source files and/or datasets with the printf-style names when getting the extent for an unlimited virtual dataset. </td></tr>
<tr>
<td><a class="el" href="group___d_a_p_l.html#gac65520e7cd7748f93d94c4a42abd01b4" title="Sets the view of the virtual dataset (VDS) to include or exclude missing mapped elements.">H5Pset_virtual_view</a>/<a class="el" href="group___d_a_p_l.html#ga7173663654b085e8583ab609c988b47c" title="Retrieves the view of a virtual dataset accessed with dapl_id.">H5Pget_virtual_view</a> </td><td>Sets/gets the view of the virtual dataset (VDS) to include or exclude missing mapped elements. </td></tr>
</table>
</p>
<h2><a class="anchor" id="subsec_dataset_program"></a>
Programming Model for Datasets</h2>
<p>This section explains the programming model for datasets.</p>
<h3><a class="anchor" id="subsubsec_dataset_program_general"></a>
General Model</h3>
<p>The programming model for using a dataset has three main phases: </p><ul>
<li>Obtain access to the dataset </li>
<li>Operate on the dataset using the dataset identifier returned at access </li>
<li>Release the dataset</li>
</ul>
<p>These three phases or steps are described in more detail below the figure.</p>
<p>A dataset may be opened several times and operations performed with several different identifiers to the same dataset. All the operations affect the dataset although the calling program must synchronize if necessary to serialize accesses.</p>
<p>Note that the dataset remains open until every identifier is closed. The figure below shows the basic sequence of operations.</p>
<table class="doxtable">
<tr>
<td><div class="image">
<img src="Dsets_fig2.gif" alt=""/>
<div class="caption">
Dataset programming sequence</div></div>
</td></tr>
</table>
<p>Creation and data access operations may have optional parameters which are set with property lists. The general programming model is: </p><ul>
<li>Create property list of appropriate class (dataset create, dataset transfer) </li>
<li>Set properties as needed; each type of property has its own format and datatype </li>
<li>Pass the property list as a parameter of the API call</li>
</ul>
<p>The steps below describe the programming phases or steps for using a dataset. </p><h4>Step 1. Obtain Access</h4>
<p>A new dataset is created by a call to <a class="el" href="group___h5_d.html#ga0647ba4bbd26d5230cc07f3a5685b2cf">H5Dcreate</a>. If successful, the call returns an identifier for the newly created dataset.</p>
<p>Access to an existing dataset is obtained by a call to <a class="el" href="_h5version_8h.html#a7dba2e5b2045f31c0932123ffb54f7a3">H5Dopen</a>. This call returns an identifier for the existing dataset.</p>
<p>An object reference may be dereferenced to obtain an identifier to the dataset it points to.</p>
<p>In each of these cases, the successful call returns an identifier to the dataset. The identifier is used in subsequent operations until the dataset is closed.</p>
<h4>Step 2. Operate on the Dataset</h4>
<p>The dataset identifier can be used to write and read data to the dataset, to query and set properties, and to perform other operations such as adding attributes, linking in groups, and creating references.</p>
<p>The dataset identifier can be used for any number of operations until the dataset is closed.</p>
<h4>Step 3. Close the Dataset</h4>
<p>When all operations are completed, the dataset identifier should be closed with a call to <a class="el" href="group___h5_d.html#gae47c3f38db49db127faf221624c30609" title="Closes the specified dataset.">H5Dclose</a>. This releases the dataset.</p>
<p>After the identifier is closed, it cannot be used for further operations.</p>
<h3><a class="anchor" id="subsubsec_dataset_program_create"></a>
Create Dataset</h3>
<p>A dataset is created and initialized with a call to <a class="el" href="group___h5_d.html#ga0647ba4bbd26d5230cc07f3a5685b2cf">H5Dcreate</a>. The dataset create operation sets permanent properties of the dataset: </p><ul>
<li>Name </li>
<li>Dataspace </li>
<li>Datatype </li>
<li>Storage properties</li>
</ul>
<p>These properties cannot be changed for the life of the dataset, although the dataspace may be expanded up to its maximum dimensions.</p>
<h4>Name</h4>
<p>A dataset name is a sequence of alphanumeric ASCII characters. The full name would include a tracing of the group hierarchy from the root group of the file. An example is /rootGroup/groupA/subgroup23/dataset1. The local name or relative name within the lowest- level group containing the dataset would include none of the group hierarchy. An example is Dataset1.</p>
<h4>Dataspace</h4>
<p>The dataspace of a dataset defines the number of dimensions and the size of each dimension. The dataspace defines the number of dimensions, and the maximum dimension sizes and current size of each dimension. The maximum dimension size can be a fixed value or the constant <a class="el" href="_h5_spublic_8h.html#a5af9ab788797b2ea9a4843857674ac18">H5S_UNLIMITED</a>, in which case the actual dimension size can be changed with calls to <a class="el" href="group___h5_d.html#gad31e1e0129f4520c531ce524de2a056f" title="Changes the sizes of a dataset's dimensions.">H5Dset_extent</a>, up to the maximum set with the maxdims parameter in the <a class="el" href="group___h5_s.html#ga8e35eea5738b4805856eac7d595254ae" title="Creates a new simple dataspace and opens it for access.">H5Screate_simple</a> call that established the dataset's original dimensions. The maximum dimension size is set when the dataset is created and cannot be changed.</p>
<h4>Datatype</h4>
<p>Raw data has a datatype which describes the layout of the raw data stored in the file. The datatype is set when the dataset is created and can never be changed. When data is transferred to and from the dataset, the HDF5 library will assure that the data is transformed to and from the stored format.</p>
<h4>Storage Properties</h4>
<p>Storage properties of the dataset are set when it is created. The required inputs table below shows the categories of storage properties. The storage properties cannot be changed after the dataset is created.</p>
<h4>Filters</h4>
<p>When a dataset is created, optional filters are specified. The filters are added to the data transfer pipeline when data is read or written. The standard library includes filters to implement compression, data shuffling, and error detection code. Additional user-defined filters may also be used.</p>
<p>The required filters are stored as part of the dataset, and the list may not be changed after the dataset is created. The HDF5 library automatically applies the filters whenever data is transferred.</p>
<h4>Summary</h4>
<p>A newly created dataset has no attributes and no data values. The dimensions, datatype, storage properties, and selected filters are set. The table below lists the required inputs, and the second table below lists the optional inputs.</p>
<table class="doxtable">
<caption>Required inputs</caption>
<tr>
<th>Required Inputs </th><th>Description </th></tr>
<tr>
<td>Dataspace </td><td>The shape of the array. </td></tr>
<tr>
<td>Datatype </td><td>The layout of the stored elements. </td></tr>
<tr>
<td>Name </td><td>The name of the dataset in the group. </td></tr>
</table>
<table class="doxtable">
<caption>Optional inputs</caption>
<tr>
<th>Optional Inputs </th><th>Description </th></tr>
<tr>
<td>Storage Layout </td><td>How the data is organized in the file including chunking. </td></tr>
<tr>
<td>Fill Value </td><td>The behavior and value for uninitialized data. </td></tr>
<tr>
<td>External Storage </td><td>Option to store the raw data in an external file. </td></tr>
<tr>
<td>Filters </td><td>Select optional filters to be applied. One of the filters that might be applied is compression. </td></tr>
</table>
<h4>Example</h4>
<p>To create a new dataset, go through the following general steps: </p><ul>
<li>Set dataset characteristics (optional where default settings are acceptable) </li>
<li>Datatype </li>
<li>Dataspace </li>
<li>Dataset creation property list </li>
<li>Create the dataset </li>
<li>Close the datatype, dataspace, and property list (as necessary) </li>
<li>Close the dataset</li>
</ul>
<p>Example 1 below shows example code to create an empty dataset. The dataspace is 7 x 8, and the datatype is a big-endian integer. The dataset is created with the name “dset1” and is a member of the root group, “/”.</p>
<p><em> Example 1. Create an empty dataset</em> </p><div class="fragment"><div class="line"><a class="code" href="_h5_ipublic_8h.html#a0045db7ff9c22ad35db6ae91662e1943">hid_t</a> dataset, datatype, dataspace;</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Create dataspace: Describe the size of the array and create the dataspace for fixed-size dataset.</span></div>
<div class="line">dimsf[0] = 7;</div>
<div class="line">dimsf[1] = 8;</div>
<div class="line">dataspace = <a class="code" href="group___h5_s.html#ga8e35eea5738b4805856eac7d595254ae">H5Screate_simple</a>(2, dimsf, NULL);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Define datatype for the data in the file.</span></div>
<div class="line"><span class="comment">// For this example, store little-endian integer numbers.</span></div>
<div class="line">datatype = <a class="code" href="group___h5_t.html#gaec07efbab84f4e5b4ed22f010786be8e">H5Tcopy</a>(<a class="code" href="group___p_d_t_n_a_t.html#ga3cf93ffc6782be68070ef8e00f219ec2">H5T_NATIVE_INT</a>);</div>
<div class="line">status = <a class="code" href="group___a_t_o_m.html#gab1aab76b1214a819281f2156c6d45d71">H5Tset_order</a>(datatype, <a class="code" href="_h5_tpublic_8h.html#a2a6a8eb856a0829fecaac60f803c9fd0ae5668f73f6c28feddb7af175ac53012d">H5T_ORDER_LE</a>);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Create a new dataset within the file using defined</span></div>
<div class="line"><span class="comment">// dataspace and datatype. No properties are set.</span></div>
<div class="line">dataset = <a class="code" href="group___h5_d.html#ga0647ba4bbd26d5230cc07f3a5685b2cf">H5Dcreate</a>(file, <span class="stringliteral">"/dset"</span>, datatype, dataspace, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>);</div>
<div class="line"><a class="code" href="group___h5_d.html#gae47c3f38db49db127faf221624c30609">H5Dclose</a>(dataset);</div>
<div class="line"><a class="code" href="group___h5_s.html#ga2b53128a39c8f104c1c9c2a91590fcc1">H5Sclose</a>(dataspace);</div>
<div class="line"><a class="code" href="group___h5_t.html#gafcba4db244f6a4d71e99c6e72b8678f0">H5Tclose</a>(datatype);</div>
<div class="ttc" id="a_h5_ipublic_8h_html_a0045db7ff9c22ad35db6ae91662e1943"><div class="ttname"><a href="_h5_ipublic_8h.html#a0045db7ff9c22ad35db6ae91662e1943">hid_t</a></div><div class="ttdeci">int64_t hid_t</div><div class="ttdef"><b>Definition:</b> H5Ipublic.h:60</div></div>
<div class="ttc" id="a_h5_ppublic_8h_html_afa85e97bfbf9bf1c58e39263846c568f"><div class="ttname"><a href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a></div><div class="ttdeci">#define H5P_DEFAULT</div><div class="ttdef"><b>Definition:</b> H5Ppublic.h:102</div></div>
<div class="ttc" id="a_h5_tpublic_8h_html_a2a6a8eb856a0829fecaac60f803c9fd0ae5668f73f6c28feddb7af175ac53012d"><div class="ttname"><a href="_h5_tpublic_8h.html#a2a6a8eb856a0829fecaac60f803c9fd0ae5668f73f6c28feddb7af175ac53012d">H5T_ORDER_LE</a></div><div class="ttdeci">@ H5T_ORDER_LE</div><div class="ttdef"><b>Definition:</b> H5Tpublic.h:54</div></div>
<div class="ttc" id="agroup___a_t_o_m_html_gab1aab76b1214a819281f2156c6d45d71"><div class="ttname"><a href="group___a_t_o_m.html#gab1aab76b1214a819281f2156c6d45d71">H5Tset_order</a></div><div class="ttdeci">herr_t H5Tset_order(hid_t type_id, H5T_order_t order)</div><div class="ttdoc">Sets the byte order of a datatype.</div></div>
<div class="ttc" id="agroup___h5_d_html_ga0647ba4bbd26d5230cc07f3a5685b2cf"><div class="ttname"><a href="group___h5_d.html#ga0647ba4bbd26d5230cc07f3a5685b2cf">H5Dcreate</a></div><div class="ttdeci">#define H5Dcreate</div><div class="ttdef"><b>Definition:</b> H5version.h:892</div></div>
<div class="ttc" id="agroup___h5_d_html_gae47c3f38db49db127faf221624c30609"><div class="ttname"><a href="group___h5_d.html#gae47c3f38db49db127faf221624c30609">H5Dclose</a></div><div class="ttdeci">herr_t H5Dclose(hid_t dset_id)</div><div class="ttdoc">Closes the specified dataset.</div></div>
<div class="ttc" id="agroup___h5_s_html_ga2b53128a39c8f104c1c9c2a91590fcc1"><div class="ttname"><a href="group___h5_s.html#ga2b53128a39c8f104c1c9c2a91590fcc1">H5Sclose</a></div><div class="ttdeci">herr_t H5Sclose(hid_t space_id)</div><div class="ttdoc">Releases and terminates access to a dataspace.</div></div>
<div class="ttc" id="agroup___h5_s_html_ga8e35eea5738b4805856eac7d595254ae"><div class="ttname"><a href="group___h5_s.html#ga8e35eea5738b4805856eac7d595254ae">H5Screate_simple</a></div><div class="ttdeci">hid_t H5Screate_simple(int rank, const hsize_t dims[], const hsize_t maxdims[])</div><div class="ttdoc">Creates a new simple dataspace and opens it for access.</div></div>
<div class="ttc" id="agroup___h5_t_html_gaec07efbab84f4e5b4ed22f010786be8e"><div class="ttname"><a href="group___h5_t.html#gaec07efbab84f4e5b4ed22f010786be8e">H5Tcopy</a></div><div class="ttdeci">hid_t H5Tcopy(hid_t type_id)</div><div class="ttdoc">Copies an existing datatype.</div></div>
<div class="ttc" id="agroup___h5_t_html_gafcba4db244f6a4d71e99c6e72b8678f0"><div class="ttname"><a href="group___h5_t.html#gafcba4db244f6a4d71e99c6e72b8678f0">H5Tclose</a></div><div class="ttdeci">herr_t H5Tclose(hid_t type_id)</div><div class="ttdoc">Releases a datatype.</div></div>
<div class="ttc" id="agroup___p_d_t_n_a_t_html_ga3cf93ffc6782be68070ef8e00f219ec2"><div class="ttname"><a href="group___p_d_t_n_a_t.html#ga3cf93ffc6782be68070ef8e00f219ec2">H5T_NATIVE_INT</a></div><div class="ttdeci">#define H5T_NATIVE_INT</div><div class="ttdef"><b>Definition:</b> H5Tpublic.h:767</div></div>
</div><!-- fragment --><p>Example 2, below, shows example code to create a similar dataset with a fill value of ‘-1’. This code has the same steps as in the example above, but uses a non-default property list. A file creation property list is created, and then the fill value is set to the desired value. Then the property list is passed to the <a class="el" href="group___h5_d.html#ga0647ba4bbd26d5230cc07f3a5685b2cf">H5Dcreate</a> call.</p>
<p><em> Example 2. Create a dataset with fill value set</em> </p><div class="fragment"><div class="line"><a class="code" href="_h5_ipublic_8h.html#a0045db7ff9c22ad35db6ae91662e1943">hid_t</a> plist; <span class="comment">// property list</span></div>
<div class="line"><a class="code" href="_h5_ipublic_8h.html#a0045db7ff9c22ad35db6ae91662e1943">hid_t</a> dataset, datatype, dataspace;</div>
<div class="line"><span class="keywordtype">int</span> fillval = -1;</div>
<div class="line"> </div>
<div class="line">dimsf[0] = 7;</div>
<div class="line">dimsf[1] = 8;</div>
<div class="line">dataspace = <a class="code" href="group___h5_s.html#ga8e35eea5738b4805856eac7d595254ae">H5Screate_simple</a>(2, dimsf, NULL);</div>
<div class="line">datatype = <a class="code" href="group___h5_t.html#gaec07efbab84f4e5b4ed22f010786be8e">H5Tcopy</a>(<a class="code" href="group___p_d_t_n_a_t.html#ga3cf93ffc6782be68070ef8e00f219ec2">H5T_NATIVE_INT</a>);</div>
<div class="line">status = <a class="code" href="group___a_t_o_m.html#gab1aab76b1214a819281f2156c6d45d71">H5Tset_order</a>(datatype, <a class="code" href="_h5_tpublic_8h.html#a2a6a8eb856a0829fecaac60f803c9fd0ae5668f73f6c28feddb7af175ac53012d">H5T_ORDER_LE</a>);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Example of Dataset Creation property list: set fill value to '-1'</span></div>
<div class="line">plist = <a class="code" href="group___p_l_c_r.html#gaf1b11da01d4d45d788c45f8bc5f0cbfa">H5Pcreate</a>(<a class="code" href="_h5_ppublic_8h.html#afcd7f8186c404f3a1d768632eacba102">H5P_DATASET_CREATE</a>);</div>
<div class="line">status = <a class="code" href="group___d_c_p_l.html#ga4335bb45b35386daa837b4ff1b9cd4a4">H5Pset_fill_value</a>(plist, datatype, &fillval);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Same as above, but use the property list</span></div>
<div class="line">dataset = <a class="code" href="group___h5_d.html#ga0647ba4bbd26d5230cc07f3a5685b2cf">H5Dcreate</a>(file, <span class="stringliteral">"/dset"</span>, datatype, dataspace, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>, plist, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>);</div>
<div class="line"><a class="code" href="group___h5_d.html#gae47c3f38db49db127faf221624c30609">H5Dclose</a>(dataset);</div>
<div class="line"><a class="code" href="group___h5_s.html#ga2b53128a39c8f104c1c9c2a91590fcc1">H5Sclose</a>(dataspace);</div>
<div class="line"><a class="code" href="group___h5_t.html#gafcba4db244f6a4d71e99c6e72b8678f0">H5Tclose</a>(datatype);</div>
<div class="line"><a class="code" href="group___p_l_c_r.html#ga5dce61149211d3ef319452aa598887fb">H5Pclose</a>(plist);</div>
<div class="ttc" id="a_h5_ppublic_8h_html_afcd7f8186c404f3a1d768632eacba102"><div class="ttname"><a href="_h5_ppublic_8h.html#afcd7f8186c404f3a1d768632eacba102">H5P_DATASET_CREATE</a></div><div class="ttdeci">#define H5P_DATASET_CREATE</div><div class="ttdef"><b>Definition:</b> H5Ppublic.h:53</div></div>
<div class="ttc" id="agroup___d_c_p_l_html_ga4335bb45b35386daa837b4ff1b9cd4a4"><div class="ttname"><a href="group___d_c_p_l.html#ga4335bb45b35386daa837b4ff1b9cd4a4">H5Pset_fill_value</a></div><div class="ttdeci">herr_t H5Pset_fill_value(hid_t plist_id, hid_t type_id, const void *value)</div><div class="ttdoc">Sets the fill value for a dataset.</div></div>
<div class="ttc" id="agroup___p_l_c_r_html_ga5dce61149211d3ef319452aa598887fb"><div class="ttname"><a href="group___p_l_c_r.html#ga5dce61149211d3ef319452aa598887fb">H5Pclose</a></div><div class="ttdeci">herr_t H5Pclose(hid_t plist_id)</div><div class="ttdoc">Terminates access to a property list.</div></div>
<div class="ttc" id="agroup___p_l_c_r_html_gaf1b11da01d4d45d788c45f8bc5f0cbfa"><div class="ttname"><a href="group___p_l_c_r.html#gaf1b11da01d4d45d788c45f8bc5f0cbfa">H5Pcreate</a></div><div class="ttdeci">hid_t H5Pcreate(hid_t cls_id)</div><div class="ttdoc">Creates a new property list as an instance of a property list class.</div></div>
</div><!-- fragment --><p>After this code is executed, the dataset has been created and written to the file. The data array is uninitialized. Depending on the storage strategy and fill value options that have been selected, some or all of the space may be allocated in the file, and fill values may be written in the file.</p>
<h3><a class="anchor" id="subsubsec_dataset_program_transfer"></a>
Data Transfer Operations on a Dataset</h3>
<p>Data is transferred between memory and the raw data array of the dataset through <a class="el" href="group___h5_d.html#ga98f44998b67587662af8b0d8a0a75906" title="Writes raw data from a buffer to a dataset.">H5Dwrite</a> and <a class="el" href="group___h5_d.html#ga8287d5a7be7b8e55ffeff68f7d26811c" title="Reads raw data from a dataset into a provided buffer.">H5Dread</a> operations. A data transfer has the following basic steps: </p><ul>
<li>1. Allocate and initialize memory space as needed </li>
<li>2. Define the datatype of the memory elements </li>
<li>3. Define the elements to be transferred (a selection, or all the elements) </li>
<li>4. Set data transfer properties (including parameters for filters or file drivers) as needed </li>
<li>5. Call the <a class="el" href="group___h5_d.html">Datasets (H5D)</a> API</li>
</ul>
<p>Note that the location of the data in the file, the datatype of the data in the file, the storage properties, and the filters do not need to be specified because these are stored as a permanent part of the dataset. A selection of elements from the dataspace is specified; the selected elements may be the whole dataspace.</p>
<p>The following figure shows a diagram of a write operation which transfers a data array from memory to a dataset in the file (usually on disk). A read operation has similar parameters with the data flowing the other direction.</p>
<table class="doxtable">
<tr>
<td><div class="image">
<img src="Dsets_fig3.gif" alt=""/>
<div class="caption">
A write operation</div></div>
</td></tr>
</table>
<h4>Memory Space</h4>
<p>The calling program must allocate sufficient memory to store the data elements to be transferred. For a write (from memory to the file), the memory must be initialized with the data to be written to the file. For a read, the memory must be large enough to store the elements that will be read. The amount of storage needed can be computed from the memory datatype (which defines the size of each data element) and the number of elements in the selection.</p>
<h4>Memory Datatype</h4>
<p>The memory layout of a single data element is specified by the memory datatype. This specifies the size, alignment, and byte order of the element as well as the datatype class. Note that the memory datatype must be the same datatype class as the file, but may have different byte order and other properties. The HDF5 Library automatically transforms data elements between the source and destination layouts. For more information, <a class="el" href="_h5_t__u_g.html#sec_datatype">HDF5 Datatypes</a>.</p>
<p>For a write, the memory datatype defines the layout of the data to be written; an example is IEEE floating-point numbers in native byte order. If the file datatype (defined when the dataset is created) is different but compatible, the HDF5 Library will transform each data element when it is written. For example, if the file byte order is different than the native byte order, the HDF5 library will swap the bytes.</p>
<p>For a read, the memory datatype defines the desired layout of the data to be read. This must be compatible with the file datatype, but should generally use native formats such as byte orders. The HDF5 library will transform each data element as it is read.</p>
<h4>Selection</h4>
<p>The data transfer will transfer some or all of the elements of the dataset depending on the dataspace selection. The selection has two dataspace objects: one for the source, and one for the destination. These objects describe which elements of the dataspace to be transferred. Some (partial I/O) or all of the data may be transferred. Partial I/O is defined by defining hyperslabs or lists of elements in a dataspace object.</p>
<p>The dataspace selection for the source defines the indices of the elements to be read or written. The two selections must define the same number of points, but the order and layout may be different. The HDF5 Library automatically selects and distributes the elements according to the selections. It might, for example, perform a scatter-gather or sub-set of the data.</p>
<h4>Data Transfer Properties</h4>
<p>For some data transfers, additional parameters should be set using the transfer property list. The table below lists the categories of transfer properties. These properties set parameters for the HDF5 Library and may be used to pass parameters for optional filters and file drivers. For example, transfer properties are used to select independent or collective operation when using MPI-I/O.</p>
<table class="doxtable">
<caption>Categories of transfer properties</caption>
<tr>
<th>Properties </th><th>Description </th></tr>
<tr>
<td>Library parameters </td><td>Internal caches, buffers, B-Trees, etc. </td></tr>
<tr>
<td>Memory management </td><td>Variable-length memory management, data overwrite </td></tr>
<tr>
<td>File driver management </td><td>Parameters for file drivers </td></tr>
<tr>
<td>Filter management </td><td>Parameters for filters </td></tr>
</table>
<h4>Data Transfer Operation (Read or Write)</h4>
<p>The data transfer is done by calling <a class="el" href="group___h5_d.html#ga8287d5a7be7b8e55ffeff68f7d26811c" title="Reads raw data from a dataset into a provided buffer.">H5Dread</a> or <a class="el" href="group___h5_d.html#ga98f44998b67587662af8b0d8a0a75906" title="Writes raw data from a buffer to a dataset.">H5Dwrite</a> with the parameters described above. The HDF5 Library constructs the required pipeline, which will scatter-gather, transform datatypes, apply the requested filters, and use the correct file driver.</p>
<p>During the data transfer, the transformations and filters are applied to each element of the data in the required order until all the data is transferred.</p>
<h4>Summary</h4>
<p>To perform a data transfer, it is necessary to allocate and initialize memory, describe the source and destination, set required and optional transfer properties, and call the <a class="el" href="group___h5_d.html">Datasets (H5D)</a> API.</p>
<h4>Examples</h4>
<p>The basic procedure to write to a dataset is the following: </p><ul>
<li>Open the dataset. </li>
<li>Set the dataset dataspace for the write (optional if dataspace is <a class="el" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>). </li>
<li>Write data. </li>
<li>Close the datatype, dataspace, and property list (as necessary). </li>
<li>Close the dataset.</li>
</ul>
<p>Example 3 below shows example code to write a 4 x 6 array of integers. In the example, the data is initialized in the memory array dset_data. The dataset has already been created in the file, so it is opened with H5Dopen.</p>
<p>The data is written with <a class="el" href="group___h5_d.html#ga98f44998b67587662af8b0d8a0a75906" title="Writes raw data from a buffer to a dataset.">H5Dwrite</a>. The arguments are the dataset identifier, the memory datatype (<a class="el" href="group___p_d_t_n_a_t.html#ga3cf93ffc6782be68070ef8e00f219ec2">H5T_NATIVE_INT</a>), the memory and file selections (<a class="el" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a> in this case: the whole array), and the default (empty) property list. The last argument is the data to be transferred.</p>
<p><em> Example 3. Write an array of integers</em> </p><div class="fragment"><div class="line"><a class="code" href="_h5_ipublic_8h.html#a0045db7ff9c22ad35db6ae91662e1943">hid_t</a> file_id, dataset_id; <span class="comment">// identifiers</span></div>
<div class="line"><a class="code" href="_h5public_8h.html#a3b079ecf932a5c599499cf7e298af160">herr_t</a> status;</div>
<div class="line"><span class="keywordtype">int</span> i, j, dset_data[4][6];</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Initialize the dataset.</span></div>
<div class="line"><span class="keywordflow">for</span> (i = 0; i < 4; i++)</div>
<div class="line"> <span class="keywordflow">for</span> (j = 0; j < 6; j++)</div>
<div class="line"> dset_data[i][j] = i * 6 + j + 1;</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Open an existing file.</span></div>
<div class="line">file_id = <a class="code" href="group___h5_f.html#gaa3f4f877b9bb591f3880423ed2bf44bc">H5Fopen</a>(<span class="stringliteral">"dset.h5"</span>, <a class="code" href="_h5_fpublic_8h.html#a402673dec5c537b27a49a9a8bd6140b4">H5F_ACC_RDWR</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Open an existing dataset.</span></div>
<div class="line">dataset_id = <a class="code" href="_h5version_8h.html#a7dba2e5b2045f31c0932123ffb54f7a3">H5Dopen</a>(file_id, <span class="stringliteral">"/dset"</span>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Write the entire dataset, using 'dset_data': memory type is 'native int'</span></div>
<div class="line"><span class="comment">// write the entire dataspace to the entire dataspace, no transfer properties</span></div>
<div class="line">status = <a class="code" href="group___h5_d.html#ga98f44998b67587662af8b0d8a0a75906">H5Dwrite</a>(dataset_id, <a class="code" href="group___p_d_t_n_a_t.html#ga3cf93ffc6782be68070ef8e00f219ec2">H5T_NATIVE_INT</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>, dset_data);</div>
<div class="line"> </div>
<div class="line">status = <a class="code" href="group___h5_d.html#gae47c3f38db49db127faf221624c30609">H5Dclose</a>(dataset_id);</div>
<div class="ttc" id="a_h5_fpublic_8h_html_a402673dec5c537b27a49a9a8bd6140b4"><div class="ttname"><a href="_h5_fpublic_8h.html#a402673dec5c537b27a49a9a8bd6140b4">H5F_ACC_RDWR</a></div><div class="ttdeci">#define H5F_ACC_RDWR</div><div class="ttdef"><b>Definition:</b> H5Fpublic.h:49</div></div>
<div class="ttc" id="a_h5_spublic_8h_html_a5f96eeee84b987f18470737f85af0484"><div class="ttname"><a href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a></div><div class="ttdeci">#define H5S_ALL</div><div class="ttdef"><b>Definition:</b> H5Spublic.h:32</div></div>
<div class="ttc" id="a_h5public_8h_html_a3b079ecf932a5c599499cf7e298af160"><div class="ttname"><a href="_h5public_8h.html#a3b079ecf932a5c599499cf7e298af160">herr_t</a></div><div class="ttdeci">int herr_t</div><div class="ttdef"><b>Definition:</b> H5public.h:235</div></div>
<div class="ttc" id="a_h5version_8h_html_a7dba2e5b2045f31c0932123ffb54f7a3"><div class="ttname"><a href="_h5version_8h.html#a7dba2e5b2045f31c0932123ffb54f7a3">H5Dopen</a></div><div class="ttdeci">#define H5Dopen</div><div class="ttdef"><b>Definition:</b> H5version.h:903</div></div>
<div class="ttc" id="agroup___h5_d_html_ga98f44998b67587662af8b0d8a0a75906"><div class="ttname"><a href="group___h5_d.html#ga98f44998b67587662af8b0d8a0a75906">H5Dwrite</a></div><div class="ttdeci">herr_t H5Dwrite(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t dxpl_id, const void *buf)</div><div class="ttdoc">Writes raw data from a buffer to a dataset.</div></div>
<div class="ttc" id="agroup___h5_f_html_gaa3f4f877b9bb591f3880423ed2bf44bc"><div class="ttname"><a href="group___h5_f.html#gaa3f4f877b9bb591f3880423ed2bf44bc">H5Fopen</a></div><div class="ttdeci">hid_t H5Fopen(const char *filename, unsigned flags, hid_t fapl_id)</div><div class="ttdoc">Opens an existing HDF5 file.</div></div>
</div><!-- fragment --><p>Example 4 below shows a similar write except for setting a non-default value for the transfer buffer. The code is the same as Example 3, but a transfer property list is created, and the desired buffer size is set. The <a class="el" href="group___h5_d.html#ga98f44998b67587662af8b0d8a0a75906" title="Writes raw data from a buffer to a dataset.">H5Dwrite</a> function has the same arguments, but uses the property list to set the buffer.</p>
<p><em> Example 4. Write an array using a property list</em> </p><div class="fragment"><div class="line"><a class="code" href="_h5_ipublic_8h.html#a0045db7ff9c22ad35db6ae91662e1943">hid_t</a> file_id, dataset_id;</div>
<div class="line"><a class="code" href="_h5_ipublic_8h.html#a0045db7ff9c22ad35db6ae91662e1943">hid_t</a> xferplist;</div>
<div class="line"><a class="code" href="_h5public_8h.html#a3b079ecf932a5c599499cf7e298af160">herr_t</a> status;</div>
<div class="line"><span class="keywordtype">int</span> i, j, dset_data[4][6];</div>
<div class="line"> </div>
<div class="line">file_id = <a class="code" href="group___h5_f.html#gaa3f4f877b9bb591f3880423ed2bf44bc">H5Fopen</a>(<span class="stringliteral">"dset.h5"</span>, <a class="code" href="_h5_fpublic_8h.html#a402673dec5c537b27a49a9a8bd6140b4">H5F_ACC_RDWR</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>);</div>
<div class="line">dataset_id = <a class="code" href="_h5version_8h.html#a7dba2e5b2045f31c0932123ffb54f7a3">H5Dopen</a>(file_id, <span class="stringliteral">"/dset"</span>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Example: set type conversion buffer to 64MB</span></div>
<div class="line">xferplist = <a class="code" href="group___p_l_c_r.html#gaf1b11da01d4d45d788c45f8bc5f0cbfa">H5Pcreate</a>(<a class="code" href="_h5_ppublic_8h.html#a6f9c8a5aba72c0445fff384bf418a80d">H5P_DATASET_XFER</a>);</div>
<div class="line">status = <a class="code" href="group___d_x_p_l.html#ga777e8c171c9e462230a9fa40874b38ce">H5Pset_buffer</a>( xferplist, 64 * 1024 *1024, NULL, NULL);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Write the entire dataset, using 'dset_data': memory type is 'native int'</span></div>
<div class="line">write the entire dataspace to the entire dataspace, set the buffer size with the <span class="keyword">property</span> list</div>
<div class="line">status = <a class="code" href="group___h5_d.html#ga98f44998b67587662af8b0d8a0a75906">H5Dwrite</a>(dataset_id, <a class="code" href="group___p_d_t_n_a_t.html#ga3cf93ffc6782be68070ef8e00f219ec2">H5T_NATIVE_INT</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, xferplist, dset_data);</div>
<div class="line"> </div>
<div class="line">status = <a class="code" href="group___h5_d.html#gae47c3f38db49db127faf221624c30609">H5Dclose</a>(dataset_id);</div>
<div class="ttc" id="a_h5_ppublic_8h_html_a6f9c8a5aba72c0445fff384bf418a80d"><div class="ttname"><a href="_h5_ppublic_8h.html#a6f9c8a5aba72c0445fff384bf418a80d">H5P_DATASET_XFER</a></div><div class="ttdeci">#define H5P_DATASET_XFER</div><div class="ttdef"><b>Definition:</b> H5Ppublic.h:55</div></div>
<div class="ttc" id="agroup___d_x_p_l_html_ga777e8c171c9e462230a9fa40874b38ce"><div class="ttname"><a href="group___d_x_p_l.html#ga777e8c171c9e462230a9fa40874b38ce">H5Pset_buffer</a></div><div class="ttdeci">herr_t H5Pset_buffer(hid_t plist_id, size_t size, void *tconv, void *bkg)</div><div class="ttdoc">Sets type conversion and background buffers.</div></div>
</div><!-- fragment --><p>The basic procedure to read from a dataset is the following: </p><ul>
<li>Define the memory dataspace of the read (optional if dataspace is <a class="el" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>). </li>
<li>Open the dataset. </li>
<li>Get the dataset dataspace (if using <a class="el" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a> above).</li>
</ul>
<p>Else define dataset dataspace of read. </p><ul>
<li>Define the memory datatype (optional). </li>
<li>Define the memory buffer. </li>
<li>Open the dataset. </li>
<li>Read data. </li>
<li>Close the datatype, dataspace, and property list (as necessary). </li>
<li>Close the dataset.</li>
</ul>
<p>The example below shows code that reads a 4 x 6 array of integers from a dataset called “dset1”. First, the dataset is opened. The <a class="el" href="group___h5_d.html#ga8287d5a7be7b8e55ffeff68f7d26811c" title="Reads raw data from a dataset into a provided buffer.">H5Dread</a> call has parameters: </p><ul>
<li>The dataset identifier (from <a class="el" href="_h5version_8h.html#a7dba2e5b2045f31c0932123ffb54f7a3">H5Dopen</a>) </li>
<li>The memory datatype (<a class="el" href="group___p_d_t_n_a_t.html#ga3cf93ffc6782be68070ef8e00f219ec2">H5T_NATIVE_INT</a>) </li>
<li>The memory and file dataspace (<a class="el" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, the whole array) </li>
<li>A default (empty) property list </li>
<li>The memory to be filled</li>
</ul>
<p><em> Example 5. Read an array from a dataset</em> </p><div class="fragment"><div class="line"><a class="code" href="_h5_ipublic_8h.html#a0045db7ff9c22ad35db6ae91662e1943">hid_t</a> file_id, dataset_id;</div>
<div class="line"><a class="code" href="_h5public_8h.html#a3b079ecf932a5c599499cf7e298af160">herr_t</a> status;</div>
<div class="line"><span class="keywordtype">int</span> i, j, dset_data[4][6];</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Open an existing file.</span></div>
<div class="line">file_id = <a class="code" href="group___h5_f.html#gaa3f4f877b9bb591f3880423ed2bf44bc">H5Fopen</a>(<span class="stringliteral">"dset.h5"</span>, <a class="code" href="_h5_fpublic_8h.html#a402673dec5c537b27a49a9a8bd6140b4">H5F_ACC_RDWR</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Open an existing dataset.</span></div>
<div class="line">dataset_id = <a class="code" href="_h5version_8h.html#a7dba2e5b2045f31c0932123ffb54f7a3">H5Dopen</a>(file_id, <span class="stringliteral">"/dset"</span>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// read the entire dataset, into 'dset_data': memory type is 'native int'</span></div>
<div class="line"><span class="comment">// read the entire dataspace to the entire dataspace, no transfer properties,</span></div>
<div class="line">status = <a class="code" href="group___h5_d.html#ga8287d5a7be7b8e55ffeff68f7d26811c">H5Dread</a>(dataset_id, <a class="code" href="group___p_d_t_n_a_t.html#ga3cf93ffc6782be68070ef8e00f219ec2">H5T_NATIVE_INT</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>, dset_data);</div>
<div class="line"> </div>
<div class="line">status = <a class="code" href="group___h5_d.html#gae47c3f38db49db127faf221624c30609">H5Dclose</a>(dataset_id);</div>
<div class="ttc" id="agroup___h5_d_html_ga8287d5a7be7b8e55ffeff68f7d26811c"><div class="ttname"><a href="group___h5_d.html#ga8287d5a7be7b8e55ffeff68f7d26811c">H5Dread</a></div><div class="ttdeci">herr_t H5Dread(hid_t dset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t dxpl_id, void *buf)</div><div class="ttdoc">Reads raw data from a dataset into a provided buffer.</div></div>
</div><!-- fragment --><h3><a class="anchor" id="subsubsec_dataset_program_read"></a>
Retrieve the Properties of a Dataset</h3>
<p>The functions listed below allow the user to retrieve information regarding a dataset including the datatype, the dataspace, the dataset creation property list, and the total stored size of the data.</p>
<table class="doxtable">
<caption>Retrieve dataset information</caption>
<tr>
<th>Query Function </th><th>Description </th></tr>
<tr>
<td>H5Dget_space </td><td>Retrieve the dataspace of the dataset as stored in the file. </td></tr>
<tr>
<td>H5Dget_type </td><td>Retrieve the datatype of the dataset as stored in the file. </td></tr>
<tr>
<td>H5Dget_create_plist </td><td>Retrieve the dataset creation properties. </td></tr>
<tr>
<td>H5Dget_storage_size </td><td>Retrieve the total bytes for all the data of the dataset. </td></tr>
<tr>
<td>H5Dvlen_get_buf_size </td><td>Retrieve the total bytes for all the variable-length data of the dataset. </td></tr>
</table>
<p>The example below illustrates how to retrieve dataset information.</p>
<p><em> Example 6. Retrieve dataset</em> </p><div class="fragment"><div class="line"><a class="code" href="_h5_ipublic_8h.html#a0045db7ff9c22ad35db6ae91662e1943">hid_t</a> file_id, dataset_id;</div>
<div class="line"><a class="code" href="_h5_ipublic_8h.html#a0045db7ff9c22ad35db6ae91662e1943">hid_t</a> dspace_id, dtype_id, plist_id;</div>
<div class="line"><a class="code" href="_h5public_8h.html#a3b079ecf932a5c599499cf7e298af160">herr_t</a> status;</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Open an existing file.</span></div>
<div class="line">file_id = <a class="code" href="group___h5_f.html#gaa3f4f877b9bb591f3880423ed2bf44bc">H5Fopen</a>(<span class="stringliteral">"dset.h5"</span>, <a class="code" href="_h5_fpublic_8h.html#a402673dec5c537b27a49a9a8bd6140b4">H5F_ACC_RDWR</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Open an existing dataset.</span></div>
<div class="line">dataset_id = <a class="code" href="_h5version_8h.html#a7dba2e5b2045f31c0932123ffb54f7a3">H5Dopen</a>(file_id, <span class="stringliteral">"/dset"</span>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>);</div>
<div class="line">dspace_id = <a class="code" href="group___h5_d.html#gad42a46be153d895d8c28a11ebf5a0d0a">H5Dget_space</a>(dataset_id);</div>
<div class="line">dtype_id = <a class="code" href="group___h5_d.html#ga7cd04b8332e8a0939b9973fbc500cadb">H5Dget_type</a>(dataset_id);</div>
<div class="line">plist_id = <a class="code" href="group___h5_d.html#ga8848f14f4aba8e6160c3d8bb7f1be163">H5Dget_create_plist</a>(dataset_id);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// use the objects to discover the properties of the dataset</span></div>
<div class="line">status = <a class="code" href="group___h5_d.html#gae47c3f38db49db127faf221624c30609">H5Dclose</a>(dataset_id);</div>
<div class="ttc" id="agroup___h5_d_html_ga7cd04b8332e8a0939b9973fbc500cadb"><div class="ttname"><a href="group___h5_d.html#ga7cd04b8332e8a0939b9973fbc500cadb">H5Dget_type</a></div><div class="ttdeci">hid_t H5Dget_type(hid_t dset_id)</div><div class="ttdoc">Returns an identifier for a copy of the datatype for a dataset.</div></div>
<div class="ttc" id="agroup___h5_d_html_ga8848f14f4aba8e6160c3d8bb7f1be163"><div class="ttname"><a href="group___h5_d.html#ga8848f14f4aba8e6160c3d8bb7f1be163">H5Dget_create_plist</a></div><div class="ttdeci">hid_t H5Dget_create_plist(hid_t dset_id)</div><div class="ttdoc">Returns an identifier for a copy of the dataset creation property list for a dataset.</div></div>
<div class="ttc" id="agroup___h5_d_html_gad42a46be153d895d8c28a11ebf5a0d0a"><div class="ttname"><a href="group___h5_d.html#gad42a46be153d895d8c28a11ebf5a0d0a">H5Dget_space</a></div><div class="ttdeci">hid_t H5Dget_space(hid_t dset_id)</div><div class="ttdoc">Returns an identifier for a copy of the dataspace for a dataset.</div></div>
</div><!-- fragment --><h2><a class="anchor" id="subsec_dataset_transfer"></a>
Data Transfer</h2>
<p>The HDF5 library implements data transfers through a pipeline which implements data transformations (according to the datatype and selections), chunking (as requested), and I/O operations using different mechanisms (file drivers). The pipeline is automatically configured by the HDF5 library. Metadata is stored in the file so that the correct pipeline can be constructed to retrieve the data. In addition, optional filters such as compression may be added to the standard pipeline.</p>
<p>The figure below illustrates data layouts for different layers of an application using HDF5. The application data is organized as a multidimensional array of elements. The HDF5 format specification defines the stored layout of the data and metadata. The storage layout properties define the organization of the abstract data. This data is written to and read from some storage medium.</p>
<table class="doxtable">
<tr>
<td><div class="image">
<img src="Dsets_fig4.gif" alt=""/>
<div class="caption">
Data layouts in an application</div></div>
</td></tr>
</table>
<p>The last stage of a write (and first stage of a read) is managed by an HDF5 file driver module. The virtual file layer of the HDF5 Library implements a standard interface to alternative I/O methods, including memory (AKA “core”) files, single serial file I/O, multiple file I/O, and parallel I/O. The file driver maps a simple abstract HDF5 file to the specific access methods.</p>
<p>The raw data of an HDF5 dataset is conceived to be a multidimensional array of data elements. This array may be stored in the file according to several storage strategies: </p><ul>
<li>Contiguous </li>
<li>Chunked </li>
<li>Compact</li>
</ul>
<p>The storage strategy does not affect data access methods except that certain operations may be more or less efficient depending on the storage strategy and the access patterns.</p>
<p>Overall, the data transfer operations (<a class="el" href="group___h5_d.html#ga8287d5a7be7b8e55ffeff68f7d26811c" title="Reads raw data from a dataset into a provided buffer.">H5Dread</a> and <a class="el" href="group___h5_d.html#ga98f44998b67587662af8b0d8a0a75906" title="Writes raw data from a buffer to a dataset.">H5Dwrite</a>) work identically for any storage method, for any file driver, and for any filters and transformations. The HDF5 library automatically manages the data transfer process. In some cases, transfer properties should or must be used to pass additional parameters such as MPI/IO directives when using the parallel file driver.</p>
<h3><a class="anchor" id="subsubsec_dataset_transfer_pipe"></a>
The Data Pipeline</h3>
<p>When data is written or read to or from an HDF5 file, the HDF5 library passes the data through a sequence of processing steps which are known as the HDF5 data pipeline. This data pipeline performs operations on the data in memory such as byte swapping, alignment, scatter-gather, and hyperslab selections. The HDF5 library automatically determines which operations are needed and manages the organization of memory operations such as extracting selected elements from a data block. The data pipeline modules operate on data buffers: each module processes a buffer and passes the transformed buffer to the next stage.</p>
<p>The table below lists the stages of the data pipeline. The figure below the table shows the order of processing during a read or write.</p>
<table class="doxtable">
<caption>Stages of the data pipeline</caption>
<tr>
<th>Layers </th><th>Description </th></tr>
<tr>
<td>I/O initiation </td><td>Initiation of HDF5 I/O activities (<a class="el" href="group___h5_d.html#ga98f44998b67587662af8b0d8a0a75906" title="Writes raw data from a buffer to a dataset.">H5Dwrite</a> and <a class="el" href="group___h5_d.html#ga8287d5a7be7b8e55ffeff68f7d26811c" title="Reads raw data from a dataset into a provided buffer.">H5Dread</a>) in a user's application program. </td></tr>
<tr>
<td>Memory hyperslab operation </td><td>Data is scattered to (for read), or gathered from (for write) the application's memory buffer (bypassed if no datatype conversion is needed). </td></tr>
<tr>
<td>Datatype conversion </td><td>Datatype is converted if it is different between memory and storage (bypassed if no datatype conversion is needed). </td></tr>
<tr>
<td>File hyperslab operation </td><td>Data is gathered from (for read), or scattered to (for write) to file space in memory (bypassed if no datatype conversion is needed). </td></tr>
<tr>
<td>Filter pipeline </td><td>Data is processed by filters when it passes. Data can be modified and restored here (bypassed if no datatype conversion is needed, no filter is enabled, or dataset is not chunked). </td></tr>
<tr>
<td>Virtual File Layer </td><td>Facilitate easy plug-in file drivers such as MPIO or POSIX I/O. </td></tr>
<tr>
<td>Actual I/O </td><td>Actual file driver used by the library such as MPIO or STDIO. </td></tr>
</table>
<table class="doxtable">
<tr>
<td><div class="image">
<img src="Dsets_fig5.gif" alt=""/>
<div class="caption">
The processing order in the data pipeline</div></div>
</td></tr>
</table>
<p>The HDF5 library automatically applies the stages as needed.</p>
<p>When the memory dataspace selection is other than the whole dataspace, the memory hyperslab stage scatters/gathers the data elements between the application memory (described by the selection) and a contiguous memory buffer for the pipeline. On a write, this is a gather operation; on a read, this is a scatter operation.</p>
<p>When the memory datatype is different from the file datatype, the datatype conversion stage transforms each data element. For example, if data is written from 32-bit big-endian memory, and the file datatype is 32-bit little-endian, the datatype conversion stage will swap the bytes of every element. Similarly, when data is read from the file to native memory, byte swapping will be applied automatically when needed.</p>
<p>The file hyperslab stage is similar to the memory hyperslab stage, but is managing the arrangement of the elements according to the dataspace selection. When data is read, data elements are gathered from the data blocks from the file to fill the contiguous buffers which are then processed by the pipeline. When data is read, the elements from a buffer are scattered to the data blocks of the file.</p>
<h3><a class="anchor" id="subsubsec_dataset_transfer_filter"></a>
Data Pipeline Filters</h3>
<p>In addition to the standard pipeline, optional stages, called filters, can be inserted in the pipeline. The standard distribution includes optional filters to implement compression and error checking. User applications may add custom filters as well.</p>
<p>The HDF5 library distribution includes or employs several optional filters. These are listed in the table below. The filters are applied in the pipeline between the virtual file layer and the file hyperslab operation. See the figure above. The application can use any number of filters in any order.</p>
<table class="doxtable">
<caption>Data pipeline filters</caption>
<tr>
<th>Filter </th><th>Description </th></tr>
<tr>
<td>gzip compression </td><td>Data compression using zlib. </td></tr>
<tr>
<td>Szip compression </td><td>Data compression using the Szip library. See The HDF Group website for more information regarding the Szip filter. </td></tr>
<tr>
<td>N-bit compression </td><td>Data compression using an algorithm specialized for n-bit datatypes. </td></tr>
<tr>
<td>Scale-offset compression </td><td>Data compression using a “scale and offset” algorithm. </td></tr>
<tr>
<td>Shuffling </td><td>To improve compression performance, data is regrouped by its byte position in the data unit. In other words, the 1st, 2nd, 3rd, and 4th bytes of integers are stored together respectively. </td></tr>
<tr>
<td>Fletcher32 </td><td>Fletcher32 checksum for error-detection. </td></tr>
</table>
<p>Filters may be used only for chunked data and are applied to chunks of data between the file hyperslab stage and the virtual file layer. At this stage in the pipeline, the data is organized as fixed-size blocks of elements, and the filter stage processes each chunk separately.</p>
<p>Filters are selected by dataset creation properties, and some behavior may be controlled by data transfer properties. The library determines what filters must be applied and applies them in the order in which they were set by the application. That is, if an application calls <a class="el" href="group___d_c_p_l.html#ga31e09cb0bf2da2893eed8a72220e6521" title="Sets up use of the shuffle filter.">H5Pset_shuffle</a> and then <a class="el" href="group___d_c_p_l.html#gaf1f569bfc54552bdb9317d2b63318a0d" title="Sets deflate (GNU gzip) compression method and compression level.">H5Pset_deflate</a> when creating a dataset's creation property list, the library will apply the shuffle filter first and then the deflate filter.</p>
<p>For more information, </p><ul>
<li><dl class="section see"><dt>See also</dt><dd><a class="el" href="_h5_d__u_g.html#subsubsec_dataset_filters_nbit">Using the N‐bit Filter</a> </dd></dl>
</li>
<li><dl class="section see"><dt>See also</dt><dd><a class="el" href="_h5_d__u_g.html#subsubsec_dataset_filters_scale">Using the Scale‐offset Filter</a></dd></dl>
</li>
</ul>
<h3><a class="anchor" id="subsubsec_dataset_transfer_drive"></a>
File Drivers</h3>
<p>I/O is performed by the HDF5 virtual file layer. The file driver interface writes and reads blocks of data; each driver module implements the interface using different I/O mechanisms. The table below lists the file drivers currently supported. Note that the I/O mechanisms are separated from the pipeline processing: the pipeline and filter operations are identical no matter what data access mechanism is used.</p>
<p><a class="anchor" id="table_lcpl_id"></a>
<table class="doxtable">
<caption border="1" style="background-color:whitesmoke;">Link creation property list functions (H5P)</caption>
<tr>
<th>Function </th><th>Purpose </th></tr>
<tr>
<td><a class="el" href="group___l_c_p_l.html#ga66c4c5d3f34e5cf65d00e47a5387383c" title="Specifies in property list whether to create missing intermediate groups.">H5Pset_create_intermediate_group</a>/<a class="el" href="group___l_c_p_l.html#gaf7db1b7ce19703f30f1827b7c899c3b0" title="Determines whether property is set to enable creating missing intermediate groups.">H5Pget_create_intermediate_group</a> </td><td>Specifies/retrieves whether to create missing intermediate groups. </td></tr>
</table>
Each file driver writes/reads contiguous blocks of bytes from a logically contiguous address space. The file driver is responsible for managing the details of the different physical storage methods.</p>
<p>In serial environments, everything above the virtual file layer tends to work identically no matter what storage method is used.</p>
<p>Some options may have substantially different performance depending on the file driver that is used. In particular, multi-file and parallel I/O may perform considerably differently from serial drivers depending on chunking and other settings.</p>
<h3><a class="anchor" id="subsubsec_dataset_transfer_props"></a>
Data Transfer Properties to Manage the Pipeline</h3>
<p>Data transfer properties set optional parameters that control parts of the data pipeline. The function listing below shows transfer properties that control the behavior of the library.</p>
<p><table class="doxtable">
<caption>I/O file drivers</caption>
<tr>
<th>File Driver </th><th>Description </th></tr>
<tr>
<td><a class="el" href="_h5_f_dcore_8h.html#ae449696f6b86abcd1120beab21fff76a">H5FD_CORE</a> </td><td>Store in memory (optional backing store to disk file). </td></tr>
<tr>
<td><a class="el" href="_h5_f_dfamily_8h.html#adbf24f060712550a2a9649589a6060c6">H5FD_FAMILY</a> </td><td>Store in a set of files. </td></tr>
<tr>
<td><a class="el" href="_h5_f_dlog_8h.html#a027aaf28f5104c77c4f51ecd29a5f7f4">H5FD_LOG</a> </td><td>Store in logging file. </td></tr>
<tr>
<td><a class="el" href="_h5_f_dmpio_8h.html#a7a231bc1d78744088a4e1d297284cabf">H5FD_MPIO</a> </td><td>Store using MPI/IO. </td></tr>
<tr>
<td><a class="el" href="_h5_f_dmulti_8h.html#a754e05ae5e0f2d86f64002b338c0fd5c">H5FD_MULTI</a> </td><td>Store in multiple files. There are several options to control layout. </td></tr>
<tr>
<td><a class="el" href="_h5_f_dsec2_8h.html#a15ae1f958e1cf11cb239916d76b10606">H5FD_SEC2</a> </td><td>Serial I/O to file using Unix “section 2” functions. </td></tr>
<tr>
<td><a class="el" href="_h5_f_dstdio_8h.html#a030a03b96a9f6e46035ce64e25389085">H5FD_STDIO</a> </td><td>Serial I/O to file using Unix “stdio” functions. </td></tr>
</table>
Some filters and file drivers require or use additional parameters from the application program. These can be passed in the data transfer property list. The table below shows file driver property list functions.</p>
<table class="doxtable">
<caption>File driver property list functions</caption>
<tr>
<th>C Function </th><th>Purpose </th></tr>
<tr>
<td><a class="el" href="group___d_x_p_l.html#ga001a22b64f60b815abf5de8b4776f09e" title="Sets data transfer mode.">H5Pset_dxpl_mpio</a> </td><td>Control the MPI I/O transfer mode (independent or collective) during data I/O operations. </td></tr>
<tr>
<td><a class="el" href="group___f_a_p_l.html#ga5a99962a79412814b79be830f14c23dd" title="Sets the size of a contiguous block reserved for small data.">H5Pset_small_data_block_size</a> </td><td>Reserves blocks of size bytes for the contiguous storage of the raw data portion of small datasets. The HDF5 Library then writes the raw data from small datasets to this reserved space which reduces unnecessary discontinuities within blocks of metadata and improves I/O performance. </td></tr>
<tr>
<td><a class="el" href="group___d_x_p_l.html#ga0d95dfa506784acc9aed850c99713609" title="Sets the dataset transfer property list to enable or disable error detection when reading data.">H5Pset_edc_check</a> </td><td>Disable/enable EDC checking for read. When selected, EDC is always written. </td></tr>
</table>
<p>The transfer properties are set in a property list which is passed as a parameter of the <a class="el" href="group___h5_d.html#ga8287d5a7be7b8e55ffeff68f7d26811c" title="Reads raw data from a dataset into a provided buffer.">H5Dread</a> or <a class="el" href="group___h5_d.html#ga98f44998b67587662af8b0d8a0a75906" title="Writes raw data from a buffer to a dataset.">H5Dwrite</a> call. The transfer properties are passed to each pipeline stage. Each stage may use or ignore any property in the list. In short, there is one property list that contains all the properties.</p>
<h3><a class="anchor" id="subsubsec_dataset_transfer_store"></a>
Storage Strategies</h3>
<p>The raw data is conceptually a multi-dimensional array of elements that is stored as a contiguous array of bytes. The data may be physically stored in the file in several ways. The table below lists the storage strategies for a dataset.</p>
<table class="doxtable">
<caption>Dataset storage strategies</caption>
<tr>
<th>Storage Strategy </th><th>Description </th></tr>
<tr>
<td>Contiguous </td><td>The dataset is stored as one continuous array of bytes. </td></tr>
<tr>
<td>Chunked </td><td>The dataset is stored as fixed-size chunks. </td></tr>
<tr>
<td>Compact </td><td>A small dataset is stored in the metadata header. </td></tr>
</table>
<p>The different storage strategies do not affect the data transfer operations of the dataset: reads and writes work the same for any storage strategy.</p>
<p>These strategies are described in the following sections.</p>
<h4>Contiguous</h4>
<p>A contiguous dataset is stored in the file as a header and a single continuous array of bytes. See the figure below. In the case of a multi-dimensional array, the data is serialized in row major order. By default, data is stored contiguously.</p>
<table class="doxtable">
<tr>
<td><div class="image">
<img src="Dsets_fig6.gif" alt=""/>
<div class="caption">
Contiguous data storage</div></div>
</td></tr>
</table>
<p>Contiguous storage is the simplest model. It has several limitations. First, the dataset must be a fixed-size: it is not possible to extend the limit of the dataset or to have unlimited dimensions. In other words, if the number of dimensions of the array might change over time, then chunking storage must be used instead of contiguous. Second, because data is passed through the pipeline as fixed-size blocks, compression and other filters cannot be used with contiguous data.</p>
<h4>Chunked</h4>
<p>The data of a dataset may be stored as fixed-size chunks. A chunk is a hyper- rectangle of any shape. When a dataset is chunked, each chunk is read or written as a single I/O operation, and individually passed from stage to stage of the data pipeline.</p>
<table class="doxtable">
<tr>
<td><div class="image">
<img src="Dsets_fig7.gif" alt=""/>
<div class="caption">
Chunked data storage</div></div>
</td></tr>
</table>
<p>Chunks may be any size and shape that fits in the dataspace of the dataset. For example, a three dimensional dataspace can be chunked as 3-D cubes, 2-D planes, or 1-D lines. The chunks may extend beyond the size of the dataspace. For example, a 3 x 3 dataset might by chunked in 2 x 2 chunks. Sufficient chunks will be allocated to store the array, and any extra space will not be accessible. So, to store the 3 x 3 array, four 2 x 2 chunks would be allocated with 5 unused elements stored.</p>
<p>Chunked datasets can be unlimited in any direction and can be compressed or filtered.</p>
<p>Since the data is read or written by chunks, chunking can have a dramatic effect on performance by optimizing what is read and written. Note, too, that for specific access patterns such as parallel I/O, decomposition into chunks can have a large impact on performance.</p>
<p>Two restrictions have been placed on chunk shape and size: </p><ul>
<li>
The rank of a chunk must be less than or equal to the rank of the dataset </li>
<li>
Chunk size cannot exceed the size of a fixed-size dataset; for example, a dataset consisting of a 5 x 4 fixed-size array cannot be defined with 10 x 10 chunks</li>
</ul>
<h4>Compact</h4>
<p>For contiguous and chunked storage, the dataset header information and data are stored in two (or more) blocks. Therefore, at least two I/O operations are required to access the data: one to access the header, and one (or more) to access data. For a small dataset, this is considerable overhead.</p>
<p>A small dataset may be stored in a continuous array of bytes in the header block using the compact storage option. This dataset can be read entirely in one operation which retrieves the header and data. The dataset must fit in the header. This may vary depending on the metadata that is stored. In general, a compact dataset should be approximately 30 KB or less total size.</p>
<table class="doxtable">
<tr>
<td><div class="image">
<img src="Dsets_fig8.gif" alt=""/>
<div class="caption">
Compact data storage</div></div>
</td></tr>
</table>
<h3><a class="anchor" id="subsubsec_dataset_transfer_partial"></a>
Partial I/O Sub‐setting and Hyperslabs</h3>
<p>Data transfers can write or read some of the data elements of the dataset. This is controlled by specifying two selections: one for the source and one for the destination. Selections are specified by creating a dataspace with selections.</p>
<p>Selections may be a union of hyperslabs or a list of points. A hyperslab is a contiguous hyper- rectangle from the dataspace. Selected fields of a compound datatype may be read or written. In this case, the selection is controlled by the memory and file datatypes.</p>
<p>Summary of procedure: </p><ul>
<li>1. Open the dataset </li>
<li>2. Define the memory datatype </li>
<li>3. Define the memory dataspace selection and file dataspace selection </li>
<li>4. Transfer data (<a class="el" href="group___h5_d.html#ga8287d5a7be7b8e55ffeff68f7d26811c" title="Reads raw data from a dataset into a provided buffer.">H5Dread</a> or <a class="el" href="group___h5_d.html#ga98f44998b67587662af8b0d8a0a75906" title="Writes raw data from a buffer to a dataset.">H5Dwrite</a>)</li>
</ul>
<p>For more information, </p><dl class="section see"><dt>See also</dt><dd><a class="el" href="_h5_s__u_g.html#sec_dataspace">HDF5 Dataspaces and Partial I/O</a></dd></dl>
<h2><a class="anchor" id="subsec_dataset_allocation"></a>
Allocation of Space in the File</h2>
<p>When a dataset is created, space is allocated in the file for its header and initial data. The amount of space allocated when the dataset is created depends on the storage properties. When the dataset is modified (data is written, attributes added, or other changes), additional storage may be allocated if necessary.</p>
<table class="doxtable">
<caption>Initial dataset size</caption>
<tr>
<th>Object </th><th>Size </th></tr>
<tr>
<td>Header </td><td>Variable, but typically around 256 bytes at the creation of a simple dataset with a simple datatype. </td></tr>
<tr>
<td>Data </td><td>Size of the data array (number of elements x size of element). Space allocated in the file depends on the storage strategy and the allocation strategy. </td></tr>
</table>
<h4>Header</h4>
<p>A dataset header consists of one or more header messages containing persistent metadata describing various aspects of the dataset. These records are defined in the HDF5 File Format Specification. The amount of storage required for the metadata depends on the metadata to be stored. The table below summarizes the metadata.</p>
<table class="doxtable">
<caption>Metadata storage sizes</caption>
<tr>
<th>Header Information </th><th>Approximate Storage Size </th></tr>
<tr>
<td>Datatype (required) </td><td>Bytes or more. Depends on type. </td></tr>
<tr>
<td>Dataspace (required) </td><td>Bytes or more. Depends on number of dimensions and hsize_t. </td></tr>
<tr>
<td>Layout (required) </td><td>Points to the stored data. Bytes or more. Depends on hsize_t and number of dimensions. </td></tr>
<tr>
<td>Filters </td><td>Depends on the number of filters. The size of the filter message depends on the name and data that will be passed. </td></tr>
</table>
<p>The header blocks also store the name and values of attributes, so the total storage depends on the number and size of the attributes.</p>
<p>In addition, the dataset must have at least one link, including a name, which is stored in the file and in the group it is linked from.</p>
<p>The different storage strategies determine when and how much space is allocated for the data array. See the discussion of fill values below for a detailed explanation of the storage allocation.</p>
<h4>Contiguous Storage</h4>
<p>For a continuous storage option, the data is stored in a single, contiguous block in the file. The data is nominally a fixed-size, (number of elements x size of element). The figure below shows an example of a two dimensional array stored as a contiguous dataset.</p>
<p>Depending on the fill value properties, the space may be allocated when the dataset is created or when first written (default), and filled with fill values if specified. For parallel I/O, by default the space is allocated when the dataset is created.</p>
<table class="doxtable">
<tr>
<td><div class="image">
<img src="Dsets_fig9.gif" alt=""/>
<div class="caption">
A two dimensional array stored as a contiguous dataset</div></div>
</td></tr>
</table>
<h4>Chunked Storage</h4>
<p>For chunked storage, the data is stored in one or more chunks. Each chunk is a continuous block in the file, but chunks are not necessarily stored contiguously. Each chunk has the same size. The data array has the same nominal size as a contiguous array (number of elements x size of element), but the storage is allocated in chunks, so the total size in the file can be larger than the nominal size of the array. See the figure below.</p>
<p>If a fill value is defined, each chunk will be filled with the fill value. Chunks must be allocated when data is written, but they may be allocated when the file is created, as the file expands, or when data is written.</p>
<p>For serial I/O, by default chunks are allocated incrementally, as data is written to the chunk. For a sparse dataset, chunks are allocated only for the parts of the dataset that are written. In this case, if the dataset is extended, no storage is allocated.</p>
<p>For parallel I/O, by default chunks are allocated when the dataset is created or extended with fill values written to the chunk.</p>
<p>In either case, the default can be changed using fill value properties. For example, using serial I/O, the properties can select to allocate chunks when the dataset is created.</p>
<table class="doxtable">
<tr>
<td><div class="image">
<img src="Dsets_fig10.gif" alt=""/>
<div class="caption">
A two dimensional array stored in chunks</div></div>
</td></tr>
</table>
<h4>Changing Dataset Dimensions</h4>
<p><a class="el" href="group___h5_d.html#gad31e1e0129f4520c531ce524de2a056f" title="Changes the sizes of a dataset's dimensions.">H5Dset_extent</a> is used to change the current dimensions of the dataset within the limits of the dataspace. Each dimension can be extended up to its maximum or unlimited. Extending the dataspace may or may not allocate space in the file and may or may not write fill values, if they are defined. See the example code below.</p>
<p>The dimensions of the dataset can also be reduced. If the sizes specified are smaller than the dataset's current dimension sizes, <a class="el" href="group___h5_d.html#gad31e1e0129f4520c531ce524de2a056f" title="Changes the sizes of a dataset's dimensions.">H5Dset_extent</a> will reduce the dataset's dimension sizes to the specified values. It is the user's responsibility to ensure that valuable data is not lost; <a class="el" href="group___h5_d.html#gad31e1e0129f4520c531ce524de2a056f" title="Changes the sizes of a dataset's dimensions.">H5Dset_extent</a> does not check.</p>
<p><em>Using <a class="el" href="group___h5_d.html#gad31e1e0129f4520c531ce524de2a056f" title="Changes the sizes of a dataset's dimensions.">H5Dset_extent</a> to increase the size of a dataset</em> </p><div class="fragment"><div class="line"><a class="code" href="_h5_ipublic_8h.html#a0045db7ff9c22ad35db6ae91662e1943">hid_t</a> file_id, dataset_id;</div>
<div class="line"><a class="code" href="_h5public_8h.html#a3b079ecf932a5c599499cf7e298af160">herr_t</a> status;</div>
<div class="line"><span class="keywordtype">size_t</span> newdims[2];</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Open an existing file.</span></div>
<div class="line">file_id = <a class="code" href="group___h5_f.html#gaa3f4f877b9bb591f3880423ed2bf44bc">H5Fopen</a>(<span class="stringliteral">"dset.h5"</span>, <a class="code" href="_h5_fpublic_8h.html#a402673dec5c537b27a49a9a8bd6140b4">H5F_ACC_RDWR</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Open an existing dataset.</span></div>
<div class="line">dataset_id = <a class="code" href="_h5version_8h.html#a7dba2e5b2045f31c0932123ffb54f7a3">H5Dopen</a>(file_id, <span class="stringliteral">"/dset"</span>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// Example: dataset is 2 x 3, each dimension is UNLIMITED</span></div>
<div class="line"><span class="comment">// extend to 2 x 7</span></div>
<div class="line">newdims[0] = 2;</div>
<div class="line">newdims[1] = 7;</div>
<div class="line">status = <a class="code" href="group___h5_d.html#gad31e1e0129f4520c531ce524de2a056f">H5Dset_extent</a>(dataset_id, newdims);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// dataset is now 2 x 7</span></div>
<div class="line"> </div>
<div class="line">status = <a class="code" href="group___h5_d.html#gae47c3f38db49db127faf221624c30609">H5Dclose</a>(dataset_id);</div>
<div class="ttc" id="agroup___h5_d_html_gad31e1e0129f4520c531ce524de2a056f"><div class="ttname"><a href="group___h5_d.html#gad31e1e0129f4520c531ce524de2a056f">H5Dset_extent</a></div><div class="ttdeci">herr_t H5Dset_extent(hid_t dset_id, const hsize_t size[])</div><div class="ttdoc">Changes the sizes of a dataset's dimensions.</div></div>
</div><!-- fragment --><h3><a class="anchor" id="subsubsec_dataset_allocation_store"></a>
Storage Allocation in the File: Early, Incremental, Late</h3>
<p>The HDF5 Library implements several strategies for when storage is allocated if and when it is filled with fill values for elements not yet written by the user. Different strategies are recommended for different storage layouts and file drivers. In particular, a parallel program needs storage allocated during a collective call (for example, create or extend), while serial programs may benefit from delaying the allocation until the data is written.</p>
<p>Two file creation properties control when to allocate space, when to write the fill value, and the actual fill value to write.</p>
<h4>When to Allocate Space</h4>
<p>The table below shows the options for when data is allocated in the file. Early allocation is done during the dataset create call. Certain file drivers (especially MPI-I/O and MPI-POSIX) require space to be allocated when a dataset is created, so all processors will have the correct view of the data.</p>
<table class="doxtable">
<caption>File storage allocation options</caption>
<tr>
<th>Strategy </th><th>Description </th></tr>
<tr>
<td>Early </td><td>Allocate storage for the dataset immediately when the dataset is created. </td></tr>
<tr>
<td>Late </td><td>Defer allocating space for storing the dataset until the dataset is written. </td></tr>
<tr>
<td>Incremental </td><td>Defer allocating space for storing each chunk until the chunk is written. </td></tr>
<tr>
<td>Default </td><td>Use the strategy (Early, Late, or Incremental) for the storage method and access method. This is the recommended strategy. </td></tr>
</table>
<p>Late allocation is done at the time of the first write to dataset. Space for the whole dataset is allocated at the first write.</p>
<p>Incremental allocation (chunks only) is done at the time of the first write to the chunk. Chunks that have never been written are not allocated in the file. In a sparsely populated dataset, this option allocates chunks only where data is actually written.</p>
<p>The “Default” property selects the option recommended as appropriate for the storage method and access method. The defaults are shown in the table below. Note that Early allocation is recommended for all Parallel I/O, while other options are recommended as the default for serial I/O cases.</p>
<table class="doxtable">
<caption>Default storage options</caption>
<tr>
<th>Storage Type </th><th>Serial I/O </th><th>Parallel I/O </th></tr>
<tr>
<td>Contiguous </td><td>Late </td><td>Early </td></tr>
<tr>
<td>Chunked </td><td>Incremental </td><td>Early </td></tr>
<tr>
<td>Compact </td><td>Early </td><td>Early </td></tr>
</table>
<h4>When to Write the Fill Value</h4>
<p>The second property is when to write the fill value. The possible values are “Never” and “Allocation”. The table below shows these options.</p>
<table class="doxtable">
<caption>When to write fill values</caption>
<tr>
<th>When </th><th>Description </th></tr>
<tr>
<td>Never </td><td>Fill value will never be written. </td></tr>
<tr>
<td>Allocation </td><td>Fill value is written when space is allocated. (Default for chunked and contiguous data storage.) </td></tr>
</table>
<h4>What Fill Value to Write</h4>
<p>The third property is the fill value to write. The table below shows the values. By default, the data is filled with zeros. The application may choose no fill value (Undefined). In this case, uninitialized data may have random values. The application may define a fill value of an appropriate type. For more information, </p><dl class="section see"><dt>See also</dt><dd><a class="el" href="_h5_t__u_g.html#subsec_datatype_fill">Fill Values</a>.</dd></dl>
<table class="doxtable">
<caption>Fill values to write</caption>
<tr>
<th>What to Write </th><th>Description </th></tr>
<tr>
<td>Default </td><td>By default, the library fills allocated space with zeros. </td></tr>
<tr>
<td>Undefined </td><td>Allocated space is filled with random values. </td></tr>
<tr>
<td>User-defined </td><td>The application specifies the fill value. </td></tr>
</table>
<p>Together these three properties control the library's behavior. The table below summarizes the possibilities during the dataset create-write-close cycle.</p>
<table class="doxtable">
<caption>Storage allocation and fill summary</caption>
<tr>
<th>When to allocate space </th><th>When to write fill value </th><th>What fill value to write </th><th>Library create-write-close behavior </th></tr>
<tr>
<td>Early </td><td>Never </td><td>- </td><td>Library allocates space when dataset is created, but never writes a fill value to dataset. A read of unwritten data returns undefined values. </td></tr>
<tr>
<td>Late </td><td>Never </td><td>- </td><td>Library allocates space when dataset is written to, but never writes a fill value to the dataset. A read of unwritten data returns undefined values. </td></tr>
<tr>
<td>Incremental </td><td>Never </td><td>- </td><td>Library allocates space when a dataset or chunk (whichever is the smallest unit of space) is written to, but it never writes a fill value to a dataset or a chunk. A read of unwritten data returns undefined values. </td></tr>
<tr>
<td>- </td><td>Allocation </td><td>Undefined </td><td>Error on creating the dataset. The dataset is not created. </td></tr>
<tr>
<td>Early </td><td>Allocation </td><td>Default or User-defined </td><td>Allocate space for the dataset when the dataset is created. Write the fill value (default or user-defined) to the entire dataset when the dataset is created. </td></tr>
<tr>
<td>Late </td><td>Allocation </td><td>Default or User-define </td><td>Allocate space for the dataset when the application first writes data values to the dataset. Write the fill value to the entire dataset before writing application data values. </td></tr>
<tr>
<td>Incremental </td><td>Allocation </td><td>Default or User-define </td><td>Allocate space for the dataset when the application first writes data values to the dataset or chunk (whichever is the smallest unit of space). Write the fill value to the entire dataset or chunk before writing application data values. </td></tr>
</table>
<p>During the <a class="el" href="group___h5_d.html#ga8287d5a7be7b8e55ffeff68f7d26811c" title="Reads raw data from a dataset into a provided buffer.">H5Dread</a> function call, the library behavior depends on whether space has been allocated, whether the fill value has been written to storage, how the fill value is defined, and when to write the fill value. The table below summarizes the different behaviors.</p>
<table class="doxtable">
<caption>H5Dread summary</caption>
<tr>
<th>Is space allocated in the file? </th><th>What is the fill value? </th><th>When to write the fill value? </th><th>Library read behavior </th></tr>
<tr>
<td>No </td><td>Undefined </td><td>anytime </td><td>Error. Cannot create this dataset. </td></tr>
<tr>
<td>No </td><td>Default or User-define </td><td>anytime </td><td>Fill the memory buffer with the fill value. </td></tr>
<tr>
<td>Yes </td><td>Undefined </td><td>anytime </td><td>Return data from storage (dataset). Trash is possible if the application has not written data to the portion of the dataset being read. </td></tr>
<tr>
<td>Yes </td><td>Default or User-define </td><td>Never </td><td>Return data from storage (dataset). Trash is possible if the application has not written data to the portion of the dataset being read. </td></tr>
<tr>
<td>Yes </td><td>Default or User-define </td><td>Allocation </td><td>Return data from storage (dataset). </td></tr>
</table>
<p>There are two cases to consider depending on whether the space in the file has been allocated before the read or not. When space has not yet been allocated and if a fill value is defined, the memory buffer will be filled with the fill values and returned. In other words, no data has been read from the disk. If space has been allocated, the values are returned from the stored data. The unwritten elements will be filled according to the fill value.</p>
<h3><a class="anchor" id="subsubsec_dataset_allocation_delete"></a>
Deleting a Dataset from a File and Reclaiming Space</h3>
<p>HDF5 does not at this time provide an easy mechanism to remove a dataset from a file or to reclaim the storage space occupied by a deleted object.</p>
<p>Removing a dataset and reclaiming the space it used can be done with the <a class="el" href="group___h5_l.html#ga5b4e7f59f5d4bdae94fd8ce6875295cf" title="Removes a link from a group.">H5Ldelete</a> function and the h5repack utility program. With the H5Ldelete function, links to a dataset can be removed from the file structure. After all the links have been removed, the dataset becomes inaccessible to any application and is effectively removed from the file. The way to recover the space occupied by an unlinked dataset is to write all of the objects of the file into a new file. Any unlinked object is inaccessible to the application and will not be included in the new file. Writing objects to a new file can be done with a custom program or with the h5repack utility program.</p>
<p>For more information, </p><dl class="section see"><dt>See also</dt><dd><a class="el" href="_h5_g__u_g.html#sec_group">HDF5 Groups</a></dd></dl>
<h3><a class="anchor" id="subsubsec_dataset_allocation_release"></a>
Releasing Memory Resources</h3>
<p>The system resources required for HDF5 objects such as datasets, datatypes, and dataspaces should be released once access to the object is no longer needed. This is accomplished via the appropriate close function. This is not unique to datasets but a general requirement when working with the HDF5 Library; failure to close objects will result in resource leaks.</p>
<p>In the case where a dataset is created or data has been transferred, there are several objects that must be closed. These objects include datasets, datatypes, dataspaces, and property lists.</p>
<p>The application program must free any memory variables and buffers it allocates. When accessing data from the file, the amount of memory required can be determined by calculating the size of the memory datatype and the number of elements in the memory selection.</p>
<p>Variable-length data are organized in two or more areas of memory. For more information, </p><dl class="section see"><dt>See also</dt><dd><a class="el" href="_h5_t__u_g.html#h4_vlen_datatype">Variable-length Datatypes</a>.</dd></dl>
<p>When writing data, the application creates an array of vl_info_t which contains pointers to the elements. The elements might be, for example, strings. In the file, the variable-length data is stored in two parts: a heap with the variable-length values of the data elements and an array of vl_info_t elements. When the data is read, the amount of memory required for the heap can be determined with the <a class="el" href="group___h5_d.html#ga0e97bbd8a8ee4a8b5b78ccce8547ce76" title="Determines the number of bytes required to store variable-length (VL) data.">H5Dvlen_get_buf_size</a> call.</p>
<p>The data transfer property may be used to set a custom memory manager for allocating variable- length data for a <a class="el" href="group___h5_d.html#ga8287d5a7be7b8e55ffeff68f7d26811c" title="Reads raw data from a dataset into a provided buffer.">H5Dread</a>. This is set with the <a class="el" href="group___d_x_p_l.html#ga2220ab75de470b6a6d5b1173d12aa0cf" title="Sets the memory manager for variable-length datatype allocation in H5Dread() and H5Dvlen_reclaim()">H5Pset_vlen_mem_manager</a> call. To free the memory for variable-length data, it is necessary to visit each element, free the variable-length data, and reset the element. The application must free the memory it has allocated. For memory allocated by the HDF5 Library during a read, the <a class="el" href="group___h5_d.html#ga222a2fd93868e2524b2e42c3c6146119" title="Reclaims variable-length (VL) datatype memory buffers.">H5Dvlen_reclaim</a> function can be used to perform this operation.</p>
<h3><a class="anchor" id="subsubsec_dataset_allocation_ext"></a>
External Storage Properties</h3>
<p>The external storage format allows data to be stored across a set of non-HDF5 files. A set of segments (offsets and sizes) in one or more files is defined as an external file list, or EFL, and the contiguous logical addresses of the data storage are mapped onto these segments. Currently, only the <a class="el" href="_h5_dpublic_8h.html#a57e163d4c263b585ca2d904996f5e06ea6161acec1a11680d488b5bb8694c79f1">H5D_CONTIGUOUS</a> storage format allows external storage. External storage is enabled by a dataset creation property. The table below shows the API.</p>
<table class="doxtable">
<caption>External storage API</caption>
<tr>
<th>Function </th><th>Description </th></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga85ff7c9c827fa524041cd58c199b77b8" title="Adds an external file to the list of external files.">H5Pset_external</a> </td><td>This function adds a new segment to the end of the external file list of the specified dataset creation property list. The segment begins a byte offset of file name and continues for size bytes. The space represented by this segment is adjacent to the space already represented by the external file list. The last segment in a file list may have the size <a class="el" href="_h5_fpublic_8h.html#a2a667df33694861e41d1b9eb3a55b373">H5F_UNLIMITED</a>, in which case the external file may be of unlimited size and no more files can be added to the external files list. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga4c45d90845ea7627b6238f95168c41ce" title="Returns the number of external files for a dataset.">H5Pget_external_count</a> </td><td>Calling this function returns the number of segments in an external file list. If the dataset creation property list has no external data, then zero is returned. </td></tr>
<tr>
<td><a class="el" href="group___d_c_p_l.html#ga78253b80b6c86faf7ff0db135146521d" title="Returns information about an external file.">H5Pget_external</a> </td><td>This is the counterpart for the <a class="el" href="group___d_c_p_l.html#ga85ff7c9c827fa524041cd58c199b77b8" title="Adds an external file to the list of external files.">H5Pset_external</a> function. Given a dataset creation property list and a zero-based index into that list, the file name, byte offset, and segment size are returned through non-null arguments. At most name_size characters are copied into the name argument which is not null terminated if the file name is longer than the supplied name buffer (this is similar to strncpy()). </td></tr>
</table>
<p>The figure below shows an example of how a contiguous, one-dimensional dataset is partitioned into three parts and each of those parts is stored in a segment of an external file. The top rectangle represents the logical address space of the dataset while the bottom rectangle represents an external file.</p>
<table class="doxtable">
<tr>
<td><div class="image">
<img src="Dsets_fig11.gif" alt=""/>
<div class="caption">
External file storage</div></div>
</td></tr>
</table>
<p>The example below shows code that defines the external storage for the example. Note that the segments are defined in order of the logical addresses they represent, not their order within the external file. It would also have been possible to put the segments in separate files. Care should be taken when setting up segments in a single file since the library does not automatically check for segments that overlap.</p>
<p><em>External storage</em> </p><div class="fragment"><div class="line">plist = <a class="code" href="group___p_l_c_r.html#gaf1b11da01d4d45d788c45f8bc5f0cbfa">H5Pcreate</a> (<a class="code" href="_h5_ppublic_8h.html#afcd7f8186c404f3a1d768632eacba102">H5P_DATASET_CREATE</a>);</div>
<div class="line"><a class="code" href="group___d_c_p_l.html#ga85ff7c9c827fa524041cd58c199b77b8">H5Pset_external</a> (plist, <span class="stringliteral">"velocity.data"</span>, 3000, 1000);</div>
<div class="line"><a class="code" href="group___d_c_p_l.html#ga85ff7c9c827fa524041cd58c199b77b8">H5Pset_external</a> (plist, <span class="stringliteral">"velocity.data"</span>, 0, 2500);</div>
<div class="line"><a class="code" href="group___d_c_p_l.html#ga85ff7c9c827fa524041cd58c199b77b8">H5Pset_external</a> (plist, <span class="stringliteral">"velocity.data"</span>, 4500, 1500);</div>
<div class="ttc" id="agroup___d_c_p_l_html_ga85ff7c9c827fa524041cd58c199b77b8"><div class="ttname"><a href="group___d_c_p_l.html#ga85ff7c9c827fa524041cd58c199b77b8">H5Pset_external</a></div><div class="ttdeci">herr_t H5Pset_external(hid_t plist_id, const char *name, off_t offset, hsize_t size)</div><div class="ttdoc">Adds an external file to the list of external files.</div></div>
</div><!-- fragment --><p>The figure below shows an example of how a contiguous, two-dimensional dataset is partitioned into three parts and each of those parts is stored in a separate external file. The top rectangle represents the logical address space of the dataset while the bottom rectangles represent external files.</p>
<table class="doxtable">
<tr>
<td><div class="image">
<img src="Dsets_fig12.gif" alt=""/>
<div class="caption">
Partitioning a 2-D dataset for external storage</div></div>
</td></tr>
</table>
<p>The example below shows code for the partitioning described above. In this example, the library maps the multi-dimensional array onto a linear address space as defined by the HDF5 format specification, and then maps that address space into the segments defined in the external file list.</p>
<p><em>Partitioning a 2-D dataset for external storage</em> </p><div class="fragment"><div class="line">plist = <a class="code" href="group___p_l_c_r.html#gaf1b11da01d4d45d788c45f8bc5f0cbfa">H5Pcreate</a> (<a class="code" href="_h5_ppublic_8h.html#afcd7f8186c404f3a1d768632eacba102">H5P_DATASET_CREATE</a>);</div>
<div class="line"><a class="code" href="group___d_c_p_l.html#ga85ff7c9c827fa524041cd58c199b77b8">H5Pset_external</a> (plist, <span class="stringliteral">"scan1.data"</span>, 0, 24);</div>
<div class="line"><a class="code" href="group___d_c_p_l.html#ga85ff7c9c827fa524041cd58c199b77b8">H5Pset_external</a> (plist, <span class="stringliteral">"scan2.data"</span>, 0, 24);</div>
<div class="line"><a class="code" href="group___d_c_p_l.html#ga85ff7c9c827fa524041cd58c199b77b8">H5Pset_external</a> (plist, <span class="stringliteral">"scan3.data"</span>, 0, 16);</div>
</div><!-- fragment --><p>The segments of an external file can exist beyond the end of the (external) file. The library reads that part of a segment as zeros. When writing to a segment that exists beyond the end of a file, the external file is automatically extended. Using this feature, one can create a segment (or set of segments) which is larger than the current size of the dataset. This allows the dataset to be extended at a future time (provided the dataspace also allows the extension).</p>
<p>All referenced external data files must exist before performing raw data I/O on the dataset. This is normally not a problem since those files are being managed directly by the application or indirectly through some other library. However, if the file is transferred from its original context, care must be taken to assure that all the external files are accessible in the new location.</p>
<h2><a class="anchor" id="subsec_dataset_filters"></a>
Using HDF5 Filters</h2>
<p>This section describes in detail how to use the n-bit, scale-offset filters and szip filters.</p>
<h3><a class="anchor" id="subsubsec_dataset_filters_nbit"></a>
Using the N‐bit Filter</h3>
<p>N-bit data has n significant bits, where n may not correspond to a precise number of bytes. On the other hand, computing systems and applications universally, or nearly so, run most efficiently when manipulating data as whole bytes or multiple bytes.</p>
<p>Consider the case of 12-bit integer data. In memory, that data will be handled in at least 2 bytes, or 16 bits, and on some platforms in 4 or even 8 bytes. The size of such a dataset can be significantly reduced when written to disk if the unused bits are stripped out.</p>
<p>The n-bit filter is provided for this purpose, packing n-bit data on output by stripping off all unused bits and unpacking on input, restoring the extra bits required by the computational processor.</p>
<h4>N-bit Datatype</h4>
<p>An n-bit datatype is a datatype of n significant bits. Unless it is packed, an n-bit datatype is presented as an n-bit bitfield within a larger-sized value. For example, a 12-bit datatype might be presented as a 12-bit field in a 16-bit, or 2-byte, value.</p>
<p>Currently, the datatype classes of n-bit datatype or n-bit field of a compound datatype or an array datatype are limited to integer or floating-point.</p>
<p>The HDF5 user can create an n-bit datatype through a series of function calls. For example, the following calls create a 16-bit datatype that is stored in a 32-bit value with a 4-bit offset: </p><div class="fragment"><div class="line"><a class="code" href="_h5_ipublic_8h.html#a0045db7ff9c22ad35db6ae91662e1943">hid_t</a> nbit_datatype = <a class="code" href="group___h5_t.html#gaec07efbab84f4e5b4ed22f010786be8e">H5Tcopy</a>(<a class="code" href="group___p_d_t_s_t_d.html#ga8db8c9c2bcc457f9f8526c8fcb81218b">H5T_STD_I32LE</a>);</div>
<div class="line"><a class="code" href="group___a_t_o_m.html#gab0f4dccfc2fb47bf2c7e06c9bf84c1f7">H5Tset_precision</a>(nbit_datatype, 16);</div>
<div class="line"><a class="code" href="group___a_t_o_m.html#gafd22e4b0aecbe6dad9a899c5bf567e2f">H5Tset_offset</a>(nbit_datatype, 4);</div>
<div class="ttc" id="agroup___a_t_o_m_html_gab0f4dccfc2fb47bf2c7e06c9bf84c1f7"><div class="ttname"><a href="group___a_t_o_m.html#gab0f4dccfc2fb47bf2c7e06c9bf84c1f7">H5Tset_precision</a></div><div class="ttdeci">herr_t H5Tset_precision(hid_t type_id, size_t prec)</div><div class="ttdoc">Sets the precision of an atomic datatype.</div></div>
<div class="ttc" id="agroup___a_t_o_m_html_gafd22e4b0aecbe6dad9a899c5bf567e2f"><div class="ttname"><a href="group___a_t_o_m.html#gafd22e4b0aecbe6dad9a899c5bf567e2f">H5Tset_offset</a></div><div class="ttdeci">herr_t H5Tset_offset(hid_t type_id, size_t offset)</div><div class="ttdoc">Sets the bit offset of the first significant bit.</div></div>
<div class="ttc" id="agroup___p_d_t_s_t_d_html_ga8db8c9c2bcc457f9f8526c8fcb81218b"><div class="ttname"><a href="group___p_d_t_s_t_d.html#ga8db8c9c2bcc457f9f8526c8fcb81218b">H5T_STD_I32LE</a></div><div class="ttdeci">#define H5T_STD_I32LE</div><div class="ttdef"><b>Definition:</b> H5Tpublic.h:310</div></div>
</div><!-- fragment --><p>In memory, one value of the above example n-bit datatype would be stored on a little-endian machine as follows: </p><table class="doxtable">
<tr>
<th>byte 3 </th><th>byte 2 </th><th>byte 1 </th><th>byte 0 </th></tr>
<tr>
<td>???????? </td><td>????SPPP </td><td>PPPPPPPP </td><td>PPPP???? </td></tr>
<tr>
<td colspan="4"><em>Note: Key: S - sign bit, E - exponent bit, M - mantissa bit, ? - padding bit. Sign bit is included in signed integer datatype precision.</em> </td></tr>
</table>
<h4>N-bit Filter</h4>
<p>When data of an n-bit datatype is stored on disk using the n-bit filter, the filter packs the data by stripping off the padding bits; only the significant bits are retained and stored. The values on disk will appear as follows: </p><table class="doxtable">
<tr>
<th>1st value </th><th>2nd value </th><th>nth value </th></tr>
<tr>
<td>SPPPPPPP PPPPPPPP </td><td>SPPPPPPP PPPPPPPP </td><td>... </td></tr>
<tr>
<td colspan="3"><em>Note: Key: S - sign bit, E - exponent bit, M - mantissa bit, ? - padding bit. Sign bit is included in signed integer datatype precision.</em> </td></tr>
</table>
<h4>How Does the N-bit Filter Work?</h4>
<p>The n-bit filter always compresses and decompresses according to dataset properties supplied by the HDF5 library in the datatype, dataspace, or dataset creation property list.</p>
<p>The dataset datatype refers to how data is stored in an HDF5 file while the memory datatype refers to how data is stored in memory. The HDF5 library will do datatype conversion when writing data in memory to the dataset or reading data from the dataset to memory if the memory datatype differs from the dataset datatype. Datatype conversion is performed by HDF5 library before n-bit compression and after n-bit decompression.</p>
<p>The following sub-sections examine the common cases: </p><ul>
<li>N-bit integer conversions </li>
<li>N-bit floating-point conversions</li>
</ul>
<h4>N-bit Integer Conversions</h4>
<p>Integer data with a dataset of integer datatype of less than full precision and a memory datatype of <a class="el" href="group___p_d_t_n_a_t.html#ga3cf93ffc6782be68070ef8e00f219ec2">H5T_NATIVE_INT</a>, provides the simplest application of the n-bit filter.</p>
<p>The precision of <a class="el" href="group___p_d_t_n_a_t.html#ga3cf93ffc6782be68070ef8e00f219ec2">H5T_NATIVE_INT</a> is 8 multiplied by sizeof(int). This value, the size of an int in bytes, differs from platform to platform; we assume a value of 4 for the following illustration. We further assume the memory byte order to be little-endian.</p>
<p>In memory, therefore, the precision of <a class="el" href="group___p_d_t_n_a_t.html#ga3cf93ffc6782be68070ef8e00f219ec2">H5T_NATIVE_INT</a> is 32 and the offset is 0. One value of <a class="el" href="group___p_d_t_n_a_t.html#ga3cf93ffc6782be68070ef8e00f219ec2">H5T_NATIVE_INT</a> is laid out in memory as follows: </p><table class="doxtable">
<tr>
<td><div class="image">
<img src="Dsets_NbitInteger1.gif" alt=""/>
<div class="caption">
H5T_NATIVE_INT in memory</div></div>
<br />
<em>Note: Key: S - sign bit, E - exponent bit, M - mantissa bit, ? - padding bit. Sign bit is included in signed integer datatype precision.</em> </td></tr>
</table>
<p>Suppose the dataset datatype has a precision of 16 and an offset of 4. After HDF5 converts values from the memory datatype to the dataset datatype, it passes something like the following to the n-bit filter for compression: </p><table class="doxtable">
<tr>
<td><div class="image">
<img src="Dsets_NbitInteger2.gif" alt=""/>
<div class="caption">
Passed to the n-bit filter</div></div>
<br />
<em>Note: Key: S - sign bit, E - exponent bit, M - mantissa bit, ? - padding bit. Sign bit is included in signed integer datatype precision.</em> </td></tr>
</table>
<p>Notice that only the specified 16 bits (15 significant bits and the sign bit) are retained in the conversion. All other significant bits of the memory datatype are discarded because the dataset datatype calls for only 16 bits of precision. After n-bit compression, none of these discarded bits, known as padding bits will be stored on disk.</p>
<h4>N-bit Floating-point Conversions</h4>
<p>Things get more complicated in the case of a floating-point dataset datatype class. This sub- section provides an example that illustrates the conversion from a memory datatype of <a class="el" href="group___p_d_t_n_a_t.html#gae2523b63144b498f555fa4d04f59ee1c">H5T_NATIVE_FLOAT</a> to a dataset datatype of class floating-point.</p>
<p>As before, let the <a class="el" href="group___p_d_t_n_a_t.html#gae2523b63144b498f555fa4d04f59ee1c">H5T_NATIVE_FLOAT</a> be 4 bytes long, and let the memory byte order be little-endian. Per the IEEE standard, one value of <a class="el" href="group___p_d_t_n_a_t.html#gae2523b63144b498f555fa4d04f59ee1c">H5T_NATIVE_FLOAT</a> is laid out in memory as follows: </p><table class="doxtable">
<tr>
<td><div class="image">
<img src="Dsets_NbitFloating1.gif" alt=""/>
<div class="caption">
H5T_NATIVE_FLOAT in memory</div></div>
<br />
<em>Note: Key: S - sign bit, E - exponent bit, M - mantissa bit, ? - padding bit. Sign bit is included in floating-point datatype precision.</em> </td></tr>
</table>
<p>Suppose the dataset datatype has a precision of 20, offset of 7, mantissa size of 13, mantissa position of 7, exponent size of 6, exponent position of 20, and sign position of 26. For more information, </p><dl class="section see"><dt>See also</dt><dd><a class="el" href="_h5_t__u_g.html#subsubsec_datatype_program_define">Definition of Datatypes</a>.</dd></dl>
<p>After HDF5 converts values from the memory datatype to the dataset datatype, it passes something like the following to the n-bit filter for compression: </p><table class="doxtable">
<tr>
<td><div class="image">
<img src="Dsets_NbitFloating2.gif" alt=""/>
<div class="caption">
Passed to the n-bit filter</div></div>
<br />
<em>Note: Key: S - sign bit, E - exponent bit, M - mantissa bit, ? - padding bit. Sign bit is included in floating-point datatype precision.</em> </td></tr>
</table>
<p>The sign bit and truncated mantissa bits are not changed during datatype conversion by the HDF5 library. On the other hand, the conversion of the 8-bit exponent to a 6-bit exponent is a little tricky:</p>
<p>The bias for the new exponent in the n-bit datatype is: <code> 2<sup>(n-1)</sup>-1 </code></p>
<p>The following formula is used for this exponent conversion:<br />
<code> exp8 - (2<sup>(8-1)</sup> -1) = exp6 - (2<sup>(6-1)</sup>-1) = actual exponent value </code><br />
where exp8 is the stored decimal value as represented by the 8-bit exponent, and exp6 is the stored decimal value as represented by the 6-bit exponent.</p>
<p>In this example, caution must be taken to ensure that, after conversion, the actual exponent value is within the range that can be represented by a 6-bit exponent. For example, an 8-bit exponent can represent values from -127 to 128 while a 6-bit exponent can represent values only from -31 to 32.</p>
<h4>N-bit Filter Behavior</h4>
<p>The n-bit filter was designed to treat the incoming data byte by byte at the lowest level. The purpose was to make the n-bit filter as generic as possible so that no pointer cast related to the datatype is needed.</p>
<p>Bitwise operations are employed for packing and unpacking at the byte level.</p>
<p>Recursive function calls are used to treat compound and array datatypes.</p>
<h4>N-bit Compression</h4>
<p>The main idea of n-bit compression is to use a loop to compress each data element in a chunk. Depending on the datatype of each element, the n-bit filter will call one of four functions. Each of these functions performs one of the following tasks: </p><ul>
<li>Compress a data element of a no-op datatype </li>
<li>Compress a data element of an atomic datatype </li>
<li>Compress a data element of a compound datatype </li>
<li>Compress a data element of an array datatype</li>
</ul>
<p>No-op datatypes: The n-bit filter does not actually compress no-op datatypes. Rather, it copies the data buffer of the no-op datatype from the non-compressed buffer to the proper location in the compressed buffer; the compressed buffer has no holes. The term “compress” is used here simply to distinguish this function from the function that performs the reverse operation during decompression.</p>
<p>Atomic datatypes: The n-bit filter will find the bytes where significant bits are located and try to compress these bytes, one byte at a time, using a loop. At this level, the filter needs the following information: </p><ul>
<li>
The byte offset of the beginning of the current data element with respect to the beginning of the input data buffer </li>
<li>
Datatype size, precision, offset, and byte order</li>
</ul>
<p>The n-bit filter compresses from the most significant byte containing significant bits to the least significant byte. For big-endian data, therefore, the loop index progresses from smaller to larger while for little-endian, the loop index progresses from larger to smaller.</p>
<p>In the extreme case of when the n-bit datatype has full precision, this function copies the content of the entire non-compressed datatype to the compressed output buffer.</p>
<p>Compound datatypes: The n-bit filter will compress each data member of the compound datatype. If the member datatype is of an integer or floating-point datatype, the n-bit filter will call the function described above. If the member datatype is of a no-op datatype, the filter will call the function described above. If the member datatype is of a compound datatype, the filter will make a recursive call to itself. If the member datatype is of an array datatype, the filter will call the function described below.</p>
<p>Array datatypes: The n-bit filter will use a loop to compress each array element in the array. If the base datatype of array element is of an integer or floating-point datatype, the n-bit filter will call the function described above. If the base datatype is of a no-op datatype, the filter will call the function described above. If the base datatype is of a compound datatype, the filter will call the function described above. If the member datatype is of an array datatype, the filter will make a recursive call of itself.</p>
<h4>N-bit Decompression</h4>
<p>The n-bit decompression algorithm is very similar to n-bit compression. The only difference is that at the byte level, compression packs out all padding bits and stores only significant bits into a continuous buffer (unsigned char) while decompression unpacks significant bits and inserts padding bits (zeros) at the proper positions to recover the data bytes as they existed before compression.</p>
<h4>Storing N-bit Parameters to Array cd_value[]</h4>
<p>All of the information, or parameters, required by the n-bit filter are gathered and stored in the array cd_values[] by the private function H5Z__set_local_nbit and are passed to another private function, H5Z__filter_nbit, by the HDF5 Library. These parameters are as follows: </p><ul>
<li>Parameters related to the datatype </li>
<li>The number of elements within the chunk </li>
<li>A flag indicating whether compression is needed</li>
</ul>
<p>The first and second parameters can be obtained using the HDF5 dataspace and datatype interface calls.</p>
<p>A compound datatype can have members of array or compound datatype. An array datatype's base datatype can be a complex compound datatype. Recursive calls are required to set parameters for these complex situations.</p>
<p>Before setting the parameters, the number of parameters should be calculated to dynamically allocate the array cd_values[], which will be passed to the HDF5 Library. This also requires recursive calls.</p>
<p>For an atomic datatype (integer or floating-point), parameters that will be stored include the datatype's size, endianness, precision, and offset.</p>
<p>For a no-op datatype, only the size is required.</p>
<p>For a compound datatype, parameters that will be stored include the datatype's total size and number of members. For each member, its member offset needs to be stored. Other parameters for members will depend on the respective datatype class.</p>
<p>For an array datatype, the total size parameter should be stored. Other parameters for the array's base type depend on the base type's datatype class.</p>
<p>Further, to correctly retrieve the parameter for use of n-bit compression or decompression later, parameters for distinguishing between datatype classes should be stored.</p>
<h4>Implementation</h4>
<p>Three filter callback functions were written for the n-bit filter: </p><ul>
<li>H5Z__can_apply_nbit </li>
<li>H5Z__set_local_nbit </li>
<li>H5Z__filter_nbit</li>
</ul>
<p>These functions are called internally by the HDF5 library. A number of utility functions were written for the function H5Z__set_local_nbit. Compression and decompression functions were written and are called by function H5Z__filter_nbit. All these functions are included in the file H5Znbit.c.</p>
<p>The public function <a class="el" href="group___d_c_p_l.html#gad58a9c0e766ef71d4075b2c2a755e91c" title="Sets up the use of the N-Bit filter.">H5Pset_nbit</a> is called by the application to set up the use of the n-bit filter. This function is included in the file H5Pdcpl.c. The application does not need to supply any parameters.</p>
<h4>How N-bit Parameters are Stored</h4>
<p>A scheme of storing parameters required by the n-bit filter in the array cd_values[] was developed utilizing recursive function calls.</p>
<p>Four private utility functions were written for storing the parameters associated with atomic (integer or floating-point), no-op, array, and compound datatypes: </p><ul>
<li>H5Z__set_parms_atomic </li>
<li>H5Z__set_parms_array </li>
<li>H5Z__set_parms_nooptype </li>
<li>H5Z__set_parms_compound</li>
</ul>
<p>The scheme is briefly described below.</p>
<p>First, assign a numeric code for datatype class atomic (integer or float), no-op, array, and compound datatype. The code is stored before other datatype related parameters are stored.</p>
<p>The first three parameters of cd_values[] are reserved for: </p><ul>
<li>1. The number of valid entries in the array cd_values[] </li>
<li>2. A flag indicating whether compression is needed </li>
<li>3. The number of elements in the chunk</li>
</ul>
<p>Throughout the balance of this explanation, i represents the index of cd_values[]. In the function H5Z__set_local_nbit: </p><ul>
<li>
1. i = 2 </li>
<li>
2. Get the number of elements in the chunk and store in cd_value[i]; increment i </li>
<li>
3. Get the class of the datatype: <ul>
<li>
For an integer or floating-point datatype, call H5Z__set_parms_atomic </li>
<li>
For an array datatype, call H5Z__set_parms_array </li>
<li>
For a compound datatype, call H5Z__set_parms_compound </li>
<li>
For none of the above, call H5Z__set_parms_noopdatatype</li>
</ul>
</li>
<li>
4. Store i in cd_value[0] and flag in cd_values[1]</li>
</ul>
<p>In the function H5Z__set_parms_atomic: </p><ul>
<li>1. Store the assigned numeric code for the atomic datatype in cd_value[i]; increment i </li>
<li>2. Get the size of the atomic datatype and store in cd_value[i]; increment i </li>
<li>3. Get the order of the atomic datatype and store in cd_value[i]; increment i </li>
<li>4. Get the precision of the atomic datatype and store in cd_value[i]; increment i </li>
<li>5. Get the offset of the atomic datatype and store in cd_value[i]; increment i </li>
<li>6. Determine the need to do compression at this point</li>
</ul>
<p>In the function H5Z__set_parms_nooptype: </p><ul>
<li>1. Store the assigned numeric code for the no-op datatype in cd_value[i]; increment i </li>
<li>2. Get the size of the no-op datatype and store in cd_value[i]; increment i</li>
</ul>
<p>In the function H5Z__set_parms_array: </p><ul>
<li>
1. Store the assigned numeric code for the array datatype in cd_value[i]; increment i </li>
<li>
2. Get the size of the array datatype and store in cd_value[i]; increment i </li>
<li>
3. Get the class of the array's base datatype. <ul>
<li>
For an integer or floating-point datatype, call H5Z__set_parms_atomic </li>
<li>
For an array datatype, call H5Z__set_parms_array </li>
<li>
For a compound datatype, call H5Z__set_parms_compound </li>
<li>
If none of the above, call H5Z__set_parms_noopdatatype</li>
</ul>
</li>
</ul>
<p>In the function H5Z__set_parms_compound: </p><ul>
<li>
1. Store the assigned numeric code for the compound datatype in cd_value[i]; increment i </li>
<li>
2. Get the size of the compound datatype and store in cd_value[i]; increment i </li>
<li>
3. Get the number of members and store in cd_values[i]; increment i </li>
<li>
4. For each member <ul>
<li>
Get the member offset and store in cd_values[i]; increment i </li>
<li>
Get the class of the member datatype </li>
<li>
For an integer or floating-point datatype, call H5Z__set_parms_atomic </li>
<li>
For an array datatype, call H5Z__set_parms_array </li>
<li>
For a compound datatype, call H5Z__set_parms_compound </li>
<li>
If none of the above, call H5Z__set_parms_noopdatatype</li>
</ul>
</li>
</ul>
<h4>N-bit Compression and Decompression Functions</h4>
<p>The n-bit compression and decompression functions above are called by the private HDF5 function H5Z__filter_nbit. The compress and decompress functions retrieve the n-bit parameters from cd_values[] as it was passed by H5Z__filter_nbit. Parameters are retrieved in exactly the same order in which they are stored and lower-level compression and decompression functions for different datatype classes are called.</p>
<p>N-bit compression is not implemented in place. Due to the difficulty of calculating actual output buffer size after compression, the same space as that of the input buffer is allocated for the output buffer as passed to the compression function. However, the size of the output buffer passed by reference to the compression function will be changed (smaller) after the compression is complete.</p>
<h4>Usage Examples</h4>
<p>The following code example illustrates the use of the n-bit filter for writing and reading n-bit integer data.</p>
<p><em>N-bit compression for integer data</em> </p><div class="fragment"><div class="line"><span class="preprocessor">#include "hdf5.h"</span></div>
<div class="line"><span class="preprocessor">#include "stdlib.h"</span></div>
<div class="line"><span class="preprocessor">#include "math.h"</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#define H5FILE_NAME "nbit_test_int.h5"</span></div>
<div class="line"><span class="preprocessor">#define DATASET_NAME "nbit_int"</span></div>
<div class="line"><span class="preprocessor">#define NX 200</span></div>
<div class="line"><span class="preprocessor">#define NY 300</span></div>
<div class="line"><span class="preprocessor">#define CH_NX 10</span></div>
<div class="line"><span class="preprocessor">#define CH_NY 15</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line"> <a class="code" href="_h5_ipublic_8h.html#a0045db7ff9c22ad35db6ae91662e1943">hid_t</a> file, dataspace, dataset, datatype, mem_datatype, dset_create_props;</div>
<div class="line"> <a class="code" href="_h5public_8h.html#a7f81cce70fb546af88da24d9285d3c1c">hsize_t</a> dims[2], chunk_size[2];</div>
<div class="line"> <span class="keywordtype">int</span> orig_data[NX][NY];</div>
<div class="line"> <span class="keywordtype">int</span> new_data[NX][NY];</div>
<div class="line"> <span class="keywordtype">int</span> i, j;</div>
<div class="line"> <span class="keywordtype">size_t</span> precision, offset;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Define dataset datatype (integer), and set precision, offset</span></div>
<div class="line"> datatype = <a class="code" href="group___h5_t.html#gaec07efbab84f4e5b4ed22f010786be8e">H5Tcopy</a>(<a class="code" href="group___p_d_t_n_a_t.html#ga3cf93ffc6782be68070ef8e00f219ec2">H5T_NATIVE_INT</a>);</div>
<div class="line"> precision = 17; <span class="comment">// precision includes sign bit</span></div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___a_t_o_m.html#gab0f4dccfc2fb47bf2c7e06c9bf84c1f7">H5Tset_precision</a>(datatype,precision) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to set precision\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> offset = 4;</div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___a_t_o_m.html#gafd22e4b0aecbe6dad9a899c5bf567e2f">H5Tset_offset</a>(datatype,offset) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to set offset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Copy to memory datatype</span></div>
<div class="line"> mem_datatype = <a class="code" href="group___h5_t.html#gaec07efbab84f4e5b4ed22f010786be8e">H5Tcopy</a>(datatype);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Set order of dataset datatype</span></div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___a_t_o_m.html#gab1aab76b1214a819281f2156c6d45d71">H5Tset_order</a>(datatype, <a class="code" href="_h5_tpublic_8h.html#a2a6a8eb856a0829fecaac60f803c9fd0acb00548c30987f873e6836c16dbccec2">H5T_ORDER_BE</a>) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to set endianness\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Initialize data buffer with random data within correct</span></div>
<div class="line"> <span class="comment">// range corresponding to the memory datatype's precision</span></div>
<div class="line"> <span class="comment">// and offset.</span></div>
<div class="line"> <span class="keywordflow">for</span> (i = 0; i < NX; i++)</div>
<div class="line"> <span class="keywordflow">for</span> (j = 0; j < NY; j++)</div>
<div class="line"> orig_data[i][j] = rand() % (int)pow(2, precision-1) << offset;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Describe the size of the array.</span></div>
<div class="line"> dims[0] = NX;</div>
<div class="line"> dims[1] = NY;</div>
<div class="line"> <span class="keywordflow">if</span>((dataspace = <a class="code" href="group___h5_s.html#ga8e35eea5738b4805856eac7d595254ae">H5Screate_simple</a> (2, dims, NULL)) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to create dataspace\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Create a new file using read/write access, default file</span></div>
<div class="line"> <span class="comment">// creation properties, and default file access properties.</span></div>
<div class="line"> <span class="keywordflow">if</span>((file = <a class="code" href="group___h5_f.html#gae64b51ee9ac0781bc4ccc599d98387f4">H5Fcreate</a> (H5FILE_NAME, <a class="code" href="_h5_fpublic_8h.html#a5a2d6726f9ad8d2bca8df2b817e5ad6a">H5F_ACC_TRUNC</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>)) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to create file\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Set the dataset creation property list to specify that</span></div>
<div class="line"> <span class="comment">// the raw data is to be partitioned into 10 x 15 element</span></div>
<div class="line"> <span class="comment">// chunks and that each chunk is to be compressed.</span></div>
<div class="line"> chunk_size[0] = CH_NX;</div>
<div class="line"> chunk_size[1] = CH_NY;</div>
<div class="line"> <span class="keywordflow">if</span>((dset_create_props = <a class="code" href="group___p_l_c_r.html#gaf1b11da01d4d45d788c45f8bc5f0cbfa">H5Pcreate</a> (<a class="code" href="_h5_ppublic_8h.html#afcd7f8186c404f3a1d768632eacba102">H5P_DATASET_CREATE</a>)) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to create dataset property\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___d_c_p_l.html#ga3584d592e377da3604b7604e266dcf5b">H5Pset_chunk</a> (dset_create_props, 2, chunk_size) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to set chunk\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Set parameters for n-bit compression; check the description</span></div>
<div class="line"> <span class="comment">// of the H5Pset_nbit function in the HDF5 Reference Manual</span></div>
<div class="line"> <span class="comment">// for more information.</span></div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___d_c_p_l.html#gad58a9c0e766ef71d4075b2c2a755e91c">H5Pset_nbit</a> (dset_create_props) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to set nbit filter\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Create a new dataset within the file. The datatype</span></div>
<div class="line"> <span class="comment">// and dataspace describe the data on disk, which may</span></div>
<div class="line"> <span class="comment">// be different from the format used in the application's</span></div>
<div class="line"> <span class="comment">// memory.</span></div>
<div class="line"> <span class="keywordflow">if</span>((dataset = <a class="code" href="group___h5_d.html#ga0647ba4bbd26d5230cc07f3a5685b2cf">H5Dcreate</a>(file, DATASET_NAME, datatype, dataspace,</div>
<div class="line"> <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>, dset_create_props, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>)) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to create dataset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Write the array to the file. The datatype and dataspace</span></div>
<div class="line"> <span class="comment">// describe the format of the data in the 'orig_data' buffer.</span></div>
<div class="line"> <span class="comment">// The raw data is translated to the format required on disk,</span></div>
<div class="line"> <span class="comment">// as defined above. We use default raw data transfer</span></div>
<div class="line"> <span class="comment">// properties.</span></div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___h5_d.html#ga98f44998b67587662af8b0d8a0a75906">H5Dwrite</a> (dataset, mem_datatype, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>, orig_data) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to write to dataset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> <a class="code" href="group___h5_d.html#gae47c3f38db49db127faf221624c30609">H5Dclose</a> (dataset);</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">if</span>((dataset = <a class="code" href="_h5version_8h.html#a7dba2e5b2045f31c0932123ffb54f7a3">H5Dopen</a>(file, DATASET_NAME, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>)) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to open dataset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Read the array. This is similar to writing data,</span></div>
<div class="line"> <span class="comment">// except the data flows in the opposite direction.</span></div>
<div class="line"> <span class="comment">// Note: Decompression is automatic.</span></div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___h5_d.html#ga8287d5a7be7b8e55ffeff68f7d26811c">H5Dread</a> (dataset, mem_datatype, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>, new_data) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to read from dataset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <a class="code" href="group___h5_t.html#gafcba4db244f6a4d71e99c6e72b8678f0">H5Tclose</a> (datatype);</div>
<div class="line"> <a class="code" href="group___h5_t.html#gafcba4db244f6a4d71e99c6e72b8678f0">H5Tclose</a> (mem_datatype);</div>
<div class="line"> <a class="code" href="group___h5_d.html#gae47c3f38db49db127faf221624c30609">H5Dclose</a> (dataset);</div>
<div class="line"> <a class="code" href="group___h5_s.html#ga2b53128a39c8f104c1c9c2a91590fcc1">H5Sclose</a> (dataspace);</div>
<div class="line"> <a class="code" href="group___p_l_c_r.html#ga5dce61149211d3ef319452aa598887fb">H5Pclose</a> (dset_create_props);</div>
<div class="line"> <a class="code" href="group___h5_f.html#gac55cd91d80822e4f8c2a7f04ea71b124">H5Fclose</a> (file);</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="ttc" id="a_h5_fpublic_8h_html_a5a2d6726f9ad8d2bca8df2b817e5ad6a"><div class="ttname"><a href="_h5_fpublic_8h.html#a5a2d6726f9ad8d2bca8df2b817e5ad6a">H5F_ACC_TRUNC</a></div><div class="ttdeci">#define H5F_ACC_TRUNC</div><div class="ttdef"><b>Definition:</b> H5Fpublic.h:50</div></div>
<div class="ttc" id="a_h5_tpublic_8h_html_a2a6a8eb856a0829fecaac60f803c9fd0acb00548c30987f873e6836c16dbccec2"><div class="ttname"><a href="_h5_tpublic_8h.html#a2a6a8eb856a0829fecaac60f803c9fd0acb00548c30987f873e6836c16dbccec2">H5T_ORDER_BE</a></div><div class="ttdeci">@ H5T_ORDER_BE</div><div class="ttdef"><b>Definition:</b> H5Tpublic.h:55</div></div>
<div class="ttc" id="a_h5public_8h_html_a7f81cce70fb546af88da24d9285d3c1c"><div class="ttname"><a href="_h5public_8h.html#a7f81cce70fb546af88da24d9285d3c1c">hsize_t</a></div><div class="ttdeci">uint64_t hsize_t</div><div class="ttdef"><b>Definition:</b> H5public.h:291</div></div>
<div class="ttc" id="agroup___d_c_p_l_html_ga3584d592e377da3604b7604e266dcf5b"><div class="ttname"><a href="group___d_c_p_l.html#ga3584d592e377da3604b7604e266dcf5b">H5Pset_chunk</a></div><div class="ttdeci">herr_t H5Pset_chunk(hid_t plist_id, int ndims, const hsize_t dim[])</div><div class="ttdoc">Sets the size of the chunks used to store a chunked layout dataset.</div></div>
<div class="ttc" id="agroup___d_c_p_l_html_gad58a9c0e766ef71d4075b2c2a755e91c"><div class="ttname"><a href="group___d_c_p_l.html#gad58a9c0e766ef71d4075b2c2a755e91c">H5Pset_nbit</a></div><div class="ttdeci">herr_t H5Pset_nbit(hid_t plist_id)</div><div class="ttdoc">Sets up the use of the N-Bit filter.</div></div>
<div class="ttc" id="agroup___h5_f_html_gac55cd91d80822e4f8c2a7f04ea71b124"><div class="ttname"><a href="group___h5_f.html#gac55cd91d80822e4f8c2a7f04ea71b124">H5Fclose</a></div><div class="ttdeci">herr_t H5Fclose(hid_t file_id)</div><div class="ttdoc">Terminates access to an HDF5 file.</div></div>
<div class="ttc" id="agroup___h5_f_html_gae64b51ee9ac0781bc4ccc599d98387f4"><div class="ttname"><a href="group___h5_f.html#gae64b51ee9ac0781bc4ccc599d98387f4">H5Fcreate</a></div><div class="ttdeci">hid_t H5Fcreate(const char *filename, unsigned flags, hid_t fcpl_id, hid_t fapl_id)</div><div class="ttdoc">Creates an HDF5 file.</div></div>
</div><!-- fragment --><p>The following code example illustrates the use of the n-bit filter for writing and reading n-bit floating-point data.</p>
<p><em>N-bit compression for floating-point data</em> </p><div class="fragment"><div class="line"><span class="preprocessor">#include "hdf5.h"</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#define H5FILE_NAME "nbit_test_float.h5"</span></div>
<div class="line"><span class="preprocessor">#define DATASET_NAME "nbit_float"</span></div>
<div class="line"><span class="preprocessor">#define NX 2</span></div>
<div class="line"><span class="preprocessor">#define NY 5</span></div>
<div class="line"><span class="preprocessor">#define CH_NX 2</span></div>
<div class="line"><span class="preprocessor">#define CH_NY 5</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line"> <a class="code" href="_h5_ipublic_8h.html#a0045db7ff9c22ad35db6ae91662e1943">hid_t</a> file, dataspace, dataset, datatype, dset_create_props;</div>
<div class="line"> <a class="code" href="_h5public_8h.html#a7f81cce70fb546af88da24d9285d3c1c">hsize_t</a> dims[2], chunk_size[2];</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// orig_data[] are initialized to be within the range that</span></div>
<div class="line"> <span class="comment">// can be represented by dataset datatype (no precision</span></div>
<div class="line"> <span class="comment">// loss during datatype conversion)</span></div>
<div class="line"> <span class="comment">//</span></div>
<div class="line"> <span class="keywordtype">float</span> orig_data[NX][NY] = {{188384.00, 19.103516,-1.0831790e9, -84.242188, 5.2045898},</div>
<div class="line"> {-49140.000, 2350.2500, -3.2110596e-1, 6.4998865e-5, -0.0000000}};</div>
<div class="line"> <span class="keywordtype">float</span> new_data[NX][NY];</div>
<div class="line"> <span class="keywordtype">size_t</span> precision, offset;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Define single-precision floating-point type for dataset</span></div>
<div class="line"> <span class="comment">//---------------------------------------------------------------</span></div>
<div class="line"> <span class="comment">// size=4 byte, precision=20 bits, offset=7 bits,</span></div>
<div class="line"> <span class="comment">// mantissa size=13 bits, mantissa position=7,</span></div>
<div class="line"> <span class="comment">// exponent size=6 bits, exponent position=20,</span></div>
<div class="line"> <span class="comment">// exponent bias=31.</span></div>
<div class="line"> <span class="comment">// It can be illustrated in little-endian order as:</span></div>
<div class="line"> <span class="comment">// (S - sign bit, E - exponent bit, M - mantissa bit, ? - padding bit)</span></div>
<div class="line"> <span class="comment">//</span></div>
<div class="line"> <span class="comment">// 3 2 1 0</span></div>
<div class="line"> <span class="comment">// ?????SEE EEEEMMMM MMMMMMMM M???????</span></div>
<div class="line"> <span class="comment">//</span></div>
<div class="line"> <span class="comment">// To create a new floating-point type, the following</span></div>
<div class="line"> <span class="comment">// properties must be set in the order of</span></div>
<div class="line"> <span class="comment">// set fields -> set offset -> set precision -> set size.</span></div>
<div class="line"> <span class="comment">// All these properties must be set before the type can</span></div>
<div class="line"> <span class="comment">// function. Other properties can be set anytime. Derived</span></div>
<div class="line"> <span class="comment">// type size cannot be expanded bigger than original size</span></div>
<div class="line"> <span class="comment">// but can be decreased. There should be no holes</span></div>
<div class="line"> <span class="comment">// among the significant bits. Exponent bias usually</span></div>
<div class="line"> <span class="comment">// is set 2^(n-1)-1, where n is the exponent size.</span></div>
<div class="line"> <span class="comment">//---------------------------------------------------------------</span></div>
<div class="line"> datatype = <a class="code" href="group___h5_t.html#gaec07efbab84f4e5b4ed22f010786be8e">H5Tcopy</a>(<a class="code" href="group___p_d_t_i_e_e_e.html#ga71d24a7d4c373ed9a003d7a0d8133f1e">H5T_IEEE_F32BE</a>);</div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___a_t_o_m.html#gafbdc98b45749e5cfbaf1a8689f3c403d">H5Tset_fields</a>(datatype, 26, 20, 6, 7, 13) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to set fields\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> offset = 7;</div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___a_t_o_m.html#gafd22e4b0aecbe6dad9a899c5bf567e2f">H5Tset_offset</a>(datatype,offset) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to set offset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> precision = 20;</div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___a_t_o_m.html#gab0f4dccfc2fb47bf2c7e06c9bf84c1f7">H5Tset_precision</a>(datatype,precision) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to set precision\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___h5_t.html#gae5f38bfd4a4c557496b3194b5180212c">H5Tset_size</a>(datatype, 4) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to set size\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___a_t_o_m.html#gad2c4a8f09672f4166f39efe83d44dba2">H5Tset_ebias</a>(datatype, 31) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to set exponent bias\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Describe the size of the array.</span></div>
<div class="line"> dims[0] = NX;</div>
<div class="line"> dims[1] = NY;</div>
<div class="line"> <span class="keywordflow">if</span>((dataspace = <a class="code" href="group___h5_s.html#ga8e35eea5738b4805856eac7d595254ae">H5Screate_simple</a> (2, dims, NULL)) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to create dataspace\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Create a new file using read/write access, default file</span></div>
<div class="line"> <span class="comment">// creation properties, and default file access properties.</span></div>
<div class="line"> <span class="keywordflow">if</span>((file = <a class="code" href="group___h5_f.html#gae64b51ee9ac0781bc4ccc599d98387f4">H5Fcreate</a> (H5FILE_NAME, <a class="code" href="_h5_fpublic_8h.html#a5a2d6726f9ad8d2bca8df2b817e5ad6a">H5F_ACC_TRUNC</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>)) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to create file\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Set the dataset creation property list to specify that</span></div>
<div class="line"> <span class="comment">// the raw data is to be partitioned into 2 x 5 element</span></div>
<div class="line"> <span class="comment">// chunks and that each chunk is to be compressed.</span></div>
<div class="line"> chunk_size[0] = CH_NX;</div>
<div class="line"> chunk_size[1] = CH_NY;</div>
<div class="line"> <span class="keywordflow">if</span>((dset_create_props = <a class="code" href="group___p_l_c_r.html#gaf1b11da01d4d45d788c45f8bc5f0cbfa">H5Pcreate</a> (<a class="code" href="_h5_ppublic_8h.html#afcd7f8186c404f3a1d768632eacba102">H5P_DATASET_CREATE</a>)) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to create dataset property\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___d_c_p_l.html#ga3584d592e377da3604b7604e266dcf5b">H5Pset_chunk</a> (dset_create_props, 2, chunk_size) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to set chunk\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Set parameters for n-bit compression; check the description</span></div>
<div class="line"> <span class="comment">// of the H5Pset_nbit function in the HDF5 Reference Manual</span></div>
<div class="line"> <span class="comment">// for more information.</span></div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___d_c_p_l.html#gad58a9c0e766ef71d4075b2c2a755e91c">H5Pset_nbit</a> (dset_create_props) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to set nbit filter\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Create a new dataset within the file. The datatype</span></div>
<div class="line"> <span class="comment">// and dataspace describe the data on disk, which may</span></div>
<div class="line"> <span class="comment">// be different from the format used in the application's memory.</span></div>
<div class="line"> <span class="keywordflow">if</span>((dataset = <a class="code" href="group___h5_d.html#ga0647ba4bbd26d5230cc07f3a5685b2cf">H5Dcreate</a>(file, DATASET_NAME, datatype, dataspace, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>,</div>
<div class="line"> dset_create_plists, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>)) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to create dataset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Write the array to the file. The datatype and dataspace</span></div>
<div class="line"> <span class="comment">// describe the format of the data in the 'orig_data' buffer.</span></div>
<div class="line"> <span class="comment">// The raw data is translated to the format required on disk,</span></div>
<div class="line"> <span class="comment">// as defined above. We use default raw data transfer properties.</span></div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___h5_d.html#ga98f44998b67587662af8b0d8a0a75906">H5Dwrite</a> (dataset, <a class="code" href="group___p_d_t_n_a_t.html#gae2523b63144b498f555fa4d04f59ee1c">H5T_NATIVE_FLOAT</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>, orig_data) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to write to dataset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> <a class="code" href="group___h5_d.html#gae47c3f38db49db127faf221624c30609">H5Dclose</a> (dataset);</div>
<div class="line"> <span class="keywordflow">if</span>((dataset = <a class="code" href="_h5version_8h.html#a7dba2e5b2045f31c0932123ffb54f7a3">H5Dopen</a>(file, DATASET_NAME, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>))<0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to open dataset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Read the array. This is similar to writing data,</span></div>
<div class="line"> <span class="comment">// except the data flows in the opposite direction.</span></div>
<div class="line"> <span class="comment">// Note: Decompression is automatic.</span></div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___h5_d.html#ga8287d5a7be7b8e55ffeff68f7d26811c">H5Dread</a> (dataset, <a class="code" href="group___p_d_t_n_a_t.html#gae2523b63144b498f555fa4d04f59ee1c">H5T_NATIVE_FLOAT</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>, new_data) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to read from dataset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> <a class="code" href="group___h5_t.html#gafcba4db244f6a4d71e99c6e72b8678f0">H5Tclose</a> (datatype);</div>
<div class="line"> <a class="code" href="group___h5_d.html#gae47c3f38db49db127faf221624c30609">H5Dclose</a> (dataset);</div>
<div class="line"> <a class="code" href="group___h5_s.html#ga2b53128a39c8f104c1c9c2a91590fcc1">H5Sclose</a> (dataspace);</div>
<div class="line"> <a class="code" href="group___p_l_c_r.html#ga5dce61149211d3ef319452aa598887fb">H5Pclose</a> (dset_create_props);</div>
<div class="line"> <a class="code" href="group___h5_f.html#gac55cd91d80822e4f8c2a7f04ea71b124">H5Fclose</a> (file);</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">return</span> 0</div>
<div class="line">}</div>
<div class="ttc" id="agroup___a_t_o_m_html_gad2c4a8f09672f4166f39efe83d44dba2"><div class="ttname"><a href="group___a_t_o_m.html#gad2c4a8f09672f4166f39efe83d44dba2">H5Tset_ebias</a></div><div class="ttdeci">herr_t H5Tset_ebias(hid_t type_id, size_t ebias)</div><div class="ttdoc">Sets the exponent bias of a floating-point type.</div></div>
<div class="ttc" id="agroup___a_t_o_m_html_gafbdc98b45749e5cfbaf1a8689f3c403d"><div class="ttname"><a href="group___a_t_o_m.html#gafbdc98b45749e5cfbaf1a8689f3c403d">H5Tset_fields</a></div><div class="ttdeci">herr_t H5Tset_fields(hid_t type_id, size_t spos, size_t epos, size_t esize, size_t mpos, size_t msize)</div><div class="ttdoc">Sets locations and sizes of floating point bit fields.</div></div>
<div class="ttc" id="agroup___h5_t_html_gae5f38bfd4a4c557496b3194b5180212c"><div class="ttname"><a href="group___h5_t.html#gae5f38bfd4a4c557496b3194b5180212c">H5Tset_size</a></div><div class="ttdeci">herr_t H5Tset_size(hid_t type_id, size_t size)</div><div class="ttdoc">Sets size for a datatype.</div></div>
<div class="ttc" id="agroup___p_d_t_i_e_e_e_html_ga71d24a7d4c373ed9a003d7a0d8133f1e"><div class="ttname"><a href="group___p_d_t_i_e_e_e.html#ga71d24a7d4c373ed9a003d7a0d8133f1e">H5T_IEEE_F32BE</a></div><div class="ttdeci">#define H5T_IEEE_F32BE</div><div class="ttdef"><b>Definition:</b> H5Tpublic.h:256</div></div>
<div class="ttc" id="agroup___p_d_t_n_a_t_html_gae2523b63144b498f555fa4d04f59ee1c"><div class="ttname"><a href="group___p_d_t_n_a_t.html#gae2523b63144b498f555fa4d04f59ee1c">H5T_NATIVE_FLOAT</a></div><div class="ttdeci">#define H5T_NATIVE_FLOAT</div><div class="ttdef"><b>Definition:</b> H5Tpublic.h:797</div></div>
</div><!-- fragment --><h4>Limitations</h4>
<p>Because the array cd_values[] has to fit into an object header message of 64K, the n-bit filter has an upper limit on the number of n-bit parameters that can be stored in it. To be conservative, a maximum of 4K is allowed for the number of parameters.</p>
<p>The n-bit filter currently only compresses n-bit datatypes or fields derived from integer or floating-point datatypes. The n-bit filter assumes padding bits of zero. This may not be true since the HDF5 user can set padding bit to be zero, one, or leave the background alone. However, it is expected the n-bit filter will be modified to adjust to such situations.</p>
<p>The n-bit filter does not have a way to handle the situation where the fill value of a dataset is defined and the fill value is not of an n-bit datatype although the dataset datatype is.</p>
<h3><a class="anchor" id="subsubsec_dataset_filters_scale"></a>
Using the Scale‐offset Filter</h3>
<p>Generally speaking, scale-offset compression performs a scale and/or offset operation on each data value and truncates the resulting value to a minimum number of bits (minimum-bits) before storing it.</p>
<p>The current scale-offset filter supports integer and floating-point datatypes only. For the floating- point datatype, float and double are supported, but long double is not supported.</p>
<p>Integer data compression uses a straight-forward algorithm. Floating-point data compression adopts the GRiB data packing mechanism which offers two alternate methods: a fixed minimum- bits method, and a variable minimum-bits method. Currently, only the variable minimum-bits method is implemented.</p>
<p>Like other I/O filters supported by the HDF5 library, applications using the scale-offset filter must store data with chunked storage.</p>
<p>Integer type: The minimum-bits of integer data can be determined by the filter. For example, if the maximum value of data to be compressed is 7065 and the minimum value is 2970. Then the “span” of dataset values is equal to (max-min+1), which is 4676. If no fill value is defined for the dataset, the minimum-bits is: ceiling(log2(span)) = 12. With fill value set, the minimum-bits is: ceiling(log2(span+1)) = 13.</p>
<p>HDF5 users can also set the minimum-bits. However, if the user gives a minimum-bits that is less than that calculated by the filter, the compression will be lossy.</p>
<p>Floating-point type: The basic idea of the scale-offset filter for the floating-point type is to transform the data by some kind of scaling to integer data, and then to follow the procedure of the scale-offset filter for the integer type to do the data compression. Due to the data transformation from floating-point to integer, the scale-offset filter is lossy in nature.</p>
<p>Two methods of scaling the floating-point data are used: the so-called D-scaling and E-scaling. D-scaling is more straightforward and easy to understand. For HDF5 1.8 release, only the D-scaling method had been implemented.</p>
<h4>Design</h4>
<p>Before the filter does any real work, it needs to gather some information from the HDF5 Library through API calls. The parameters the filter needs are: </p><ul>
<li>The minimum-bits of the data value </li>
<li>The number of data elements in the chunk </li>
<li>The datatype class, size, sign (only for integer type), byte order, and fill value if defined</li>
</ul>
<p>Size and sign are needed to determine what kind of pointer cast to use when retrieving values from the data buffer.</p>
<p>The pipeline of the filter can be divided into four parts: (1)pre-compression; (2)compression; (3)decompression; (4)post-decompression.</p>
<p>Depending on whether a fill value is defined or not, the filter will handle pre-compression and post-decompression differently.</p>
<p>The scale-offset filter only needs the memory byte order, size of datatype, and minimum-bits for compression and decompression.</p>
<p>Since decompression has no access to the original data, the minimum-bits and the minimum value need to be stored with the compressed data for decompression and post-decompression.</p>
<h4>Integer Type</h4>
<p>Pre-compression: During pre-compression minimum-bits is calculated if it is not set by the user. For more information on how minimum-bits are calculated, </p><dl class="section see"><dt>See also</dt><dd><a class="el" href="_h5_d__u_g.html#subsubsec_dataset_filters_nbit">Using the N‐bit Filter</a>.</dd></dl>
<p>If the fill value is defined, finding the maximum and minimum values should ignore the data element whose value is equal to the fill value.</p>
<p>If no fill value is defined, the value of each data element is subtracted by the minimum value during this stage.</p>
<p>If the fill value is defined, the fill value is assigned to the maximum value. In this way minimum- bits can represent a data element whose value is equal to the fill value and subtracts the minimum value from a data element whose value is not equal to the fill value.</p>
<p>The fill value (if defined), the number of elements in a chunk, the class of the datatype, the size of the datatype, the memory order of the datatype, and other similar elements will be stored in the HDF5 object header for the post-decompression usage.</p>
<p>After pre-compression, all values are non-negative and are within the range that can be stored by minimum-bits.</p>
<p>Compression: All modified data values after pre-compression are packed together into the compressed data buffer. The number of bits for each data value decreases from the number of bits of integer (32 for most platforms) to minimum-bits. The value of minimum-bits and the minimum value are added to the data buffer and the whole buffer is sent back to the library. In this way, the number of bits for each modified value is no more than the size of minimum-bits.</p>
<p>Decompression: In this stage, the number of bits for each data value is resumed from minimum- bits to the number of bits of integer.</p>
<p>Post-decompression: For the post-decompression stage, the filter does the opposite of what it does during pre-compression except that it does not calculate the minimum-bits or the minimum value. These values were saved during compression and can be retrieved through the resumed data buffer. If no fill value is defined, the filter adds the minimum value back to each data element.</p>
<p>If the fill value is defined, the filter assigns the fill value to the data element whose value is equal to the maximum value that minimum-bits can represent and adds the minimum value back to each data element whose value is not equal to the maximum value that minimum-bits can represent.</p>
<p><a class="anchor" id="h4_float_datatype"></a></p><h4>Floating-point Type</h4>
<p>The filter will do data transformation from floating-point type to integer type and then handle the data by using the procedure for handling the integer data inside the filter. Insignificant bits of floating-point data will be cut off during data transformation, so this filter is a lossy compression method.</p>
<p>There are two scaling methods: D-scaling and E-scaling. The HDF5 1.8 release only supports D- scaling. D-scaling is short for decimal scaling. E-scaling should be similar conceptually. In order to transform data from floating-point to integer, a scale factor is introduced. The minimum value will be calculated. Each data element value will subtract the minimum value. The modified data will be multiplied by 10 (Decimal) to the power of scale_factor, and only the integer part will be kept and manipulated through the routines for the integer type of the filter during pre- compression and compression. Integer data will be divided by 10 to the power of scale_factor to transform back to floating-point data during decompression and post-decompression. Each data element value will then add the minimum value, and the floating-point data are resumed. However, the resumed data will lose some insignificant bits compared with the original value.</p>
<p>For example, the following floating-point data are manipulated by the filter, and the D-scaling factor is 2. <em>{104.561, 99.459, 100.545, 105.644}</em></p>
<p>The minimum value is 99.459, each data element subtracts 99.459, the modified data is <em>{5.102, 0, 1.086, 6.185}</em></p>
<p>Since the D-scaling factor is 2, all floating-point data will be multiplied by 10^2 with this result: <em>{510.2, 0, 108.6, 618.5}</em></p>
<p>The digit after decimal point will be rounded off, and then the set looks like: <em>{510, 0, 109, 619}</em></p>
<p>After decompression, each value will be divided by 10^2 and will be added to the offset 99.459. The floating-point data becomes <em>{104.559, 99.459, 100.549, 105.649}</em></p>
<p>The relative error for each value should be no more than 5* (10^(D-scaling factor +1)). D-scaling sometimes is also referred as a variable minimum-bits method since for different datasets the minimum-bits to represent the same decimal precision will vary. The data value is modified to 2 to power of scale_factor for E-scaling. E-scaling is also called fixed-bits method since for different datasets the minimum-bits will always be fixed to the scale factor of E-scaling. Currently, HDF5 ONLY supports the D-scaling (variable minimum-bits) method.</p>
<h4>Implementation</h4>
<p>The scale-offset filter implementation was written and included in the file H5Zscaleoffset.c. Function <a class="el" href="group___d_c_p_l.html#ga5c10165b670e0e984db431aee818cc7e" title="Sets up the use of the scale-offset filter.">H5Pset_scaleoffset</a> was written and included in the file “H5Pdcpl.c”. The HDF5 user can supply minimum-bits by calling function <a class="el" href="group___d_c_p_l.html#ga5c10165b670e0e984db431aee818cc7e" title="Sets up the use of the scale-offset filter.">H5Pset_scaleoffset</a>.</p>
<p>The scale-offset filter was implemented based on the design outlined in this section. However, the following factors need to be considered: </p><ol>
<li>
The filter needs the appropriate cast pointer whenever it needs to retrieve data values. </li>
<li>
The HDF5 Library passes to the filter the to-be-compressed data in the format of the dataset datatype, and the filter passes back the decompressed data in the same format. If a fill value is defined, it is also in dataset datatype format. For example, if the byte order of the dataset data- type is different from that of the memory datatype of the platform, compression or decompression performs an endianness conversion of data buffer. Moreover, it should be aware that memory byte order can be different during compression and decompression. </li>
<li>
The difference of endianness and datatype between file and memory should be considered when saving and retrieval of minimum-bits, minimum value, and fill value. </li>
<li>
If the user sets the minimum-bits to full precision of the datatype, no operation is needed at the filter side. If the full precision is a result of calculation by the filter, then the minimum-bits needs to be saved for decompression but no compression or decompression is needed (only a copy of the input buffer is needed). </li>
<li>
If by calculation of the filter, the minimum-bits is equal to zero, special handling is needed. Since it means all values are the same, no compression or decompression is needed. But the minimum-bits and minimum value still need to be saved during compression. </li>
<li>
For floating-point data, the minimum value of the dataset should be calculated at first. Each data element value will then subtract the minimum value to obtain the “offset” data. The offset data will then follow the steps outlined above in the discussion of floating-point types to do data transformation to integer and rounding. For more information, <dl class="section see"><dt>See also</dt><dd><a class="el" href="_h5_d__u_g.html#h4_float_datatype">h4_float_datatype</a>. </dd></dl>
</li>
</ol>
<h4>Usage Examples</h4>
<p>The following code example illustrates the use of the scale-offset filter for writing and reading integer data.</p>
<p><em>Scale-offset compression integer data</em> </p><div class="fragment"><div class="line"><span class="preprocessor">#include "hdf5.h"</span></div>
<div class="line"><span class="preprocessor">#include "stdlib.h"</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#define H5FILE_NAME "scaleoffset_test_int.h5"</span></div>
<div class="line"><span class="preprocessor">#define DATASET_NAME "scaleoffset_int"</span></div>
<div class="line"><span class="preprocessor">#define NX 200</span></div>
<div class="line"><span class="preprocessor">#define NY 300</span></div>
<div class="line"><span class="preprocessor">#define CH_NX 10</span></div>
<div class="line"><span class="preprocessor">#define CH_NY 15</span></div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line"> <a class="code" href="_h5_ipublic_8h.html#a0045db7ff9c22ad35db6ae91662e1943">hid_t</a> file, dataspace, dataset, datatype, dset_create_props;</div>
<div class="line"> <a class="code" href="_h5public_8h.html#a7f81cce70fb546af88da24d9285d3c1c">hsize_t</a> dims[2], chunk_size[2];</div>
<div class="line"> <span class="keywordtype">int</span> orig_data[NX][NY];</div>
<div class="line"> <span class="keywordtype">int</span> new_data[NX][NY];</div>
<div class="line"> <span class="keywordtype">int</span> i, j, fill_val;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Define dataset datatype</span></div>
<div class="line"> datatype = <a class="code" href="group___h5_t.html#gaec07efbab84f4e5b4ed22f010786be8e">H5Tcopy</a>(<a class="code" href="group___p_d_t_n_a_t.html#ga3cf93ffc6782be68070ef8e00f219ec2">H5T_NATIVE_INT</a>);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Initialize data buffer</span></div>
<div class="line"> <span class="keywordflow">for</span> (i=0; i < NX; i++)</div>
<div class="line"> <span class="keywordflow">for</span> (j=0; j < NY; j++)</div>
<div class="line"> orig_data[i][j] = rand() % 10000;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Describe the size of the array.</span></div>
<div class="line"> dims[0] = NX;</div>
<div class="line"> dims[1] = NY;</div>
<div class="line"> <span class="keywordflow">if</span>((dataspace = <a class="code" href="group___h5_s.html#ga8e35eea5738b4805856eac7d595254ae">H5Screate_simple</a> (2, dims, NULL)) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to create dataspace\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Create a new file using read/write access, default file</span></div>
<div class="line"> <span class="comment">// creation properties, and default file access properties.</span></div>
<div class="line"> <span class="keywordflow">if</span>((file = <a class="code" href="group___h5_f.html#gae64b51ee9ac0781bc4ccc599d98387f4">H5Fcreate</a> (H5FILE_NAME, <a class="code" href="_h5_fpublic_8h.html#a5a2d6726f9ad8d2bca8df2b817e5ad6a">H5F_ACC_TRUNC</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>)) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to create file\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Set the dataset creation property list to specify that</span></div>
<div class="line"> <span class="comment">// the raw data is to be partitioned into 10 x 15 element</span></div>
<div class="line"> <span class="comment">// chunks and that each chunk is to be compressed.</span></div>
<div class="line"> chunk_size[0] = CH_NX;</div>
<div class="line"> chunk_size[1] = CH_NY;</div>
<div class="line"> <span class="keywordflow">if</span>((dset_create_props = <a class="code" href="group___p_l_c_r.html#gaf1b11da01d4d45d788c45f8bc5f0cbfa">H5Pcreate</a> (<a class="code" href="_h5_ppublic_8h.html#afcd7f8186c404f3a1d768632eacba102">H5P_DATASET_CREATE</a>)) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to create dataset property\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___d_c_p_l.html#ga3584d592e377da3604b7604e266dcf5b">H5Pset_chunk</a> (dset_create_props, 2, chunk_size) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to set chunk\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Set the fill value of dataset</span></div>
<div class="line"> fill_val = 10000;</div>
<div class="line"> <span class="keywordflow">if</span> (<a class="code" href="group___d_c_p_l.html#ga4335bb45b35386daa837b4ff1b9cd4a4">H5Pset_fill_value</a>(dset_create_props, <a class="code" href="group___p_d_t_n_a_t.html#ga3cf93ffc6782be68070ef8e00f219ec2">H5T_NATIVE_INT</a>, &fill_val)<0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: can not set fill value for dataset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Set parameters for scale-offset compression. Check the</span></div>
<div class="line"> <span class="comment">// description of the H5Pset_scaleoffset function in the</span></div>
<div class="line"> <span class="comment">// HDF5 Reference Manual for more information.</span></div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___d_c_p_l.html#ga5c10165b670e0e984db431aee818cc7e">H5Pset_scaleoffset</a> (dset_create_props, <a class="code" href="group___s_c_a_l_e_o_f_f_s_e_t.html#gga53d85c0570e17f6e1ddbf569462b1516a9fc45fdf1844739c145130e8c324a3a3">H5Z_SO_INT</a>, H5Z_SO_INT_MINIMUMBITS_DEFAULT) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to set scaleoffset filter\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Create a new dataset within the file. The datatype</span></div>
<div class="line"> <span class="comment">// and dataspace describe the data on disk, which may</span></div>
<div class="line"> <span class="comment">// or may not be different from the format used in the</span></div>
<div class="line"> <span class="comment">// application's memory. The link creation and</span></div>
<div class="line"> <span class="comment">// dataset access property list parameters are passed</span></div>
<div class="line"> <span class="comment">// with default values.</span></div>
<div class="line"> <span class="keywordflow">if</span>((dataset = <a class="code" href="group___h5_d.html#ga0647ba4bbd26d5230cc07f3a5685b2cf">H5Dcreate</a> (file, DATASET_NAME, datatype, dataspace, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>,</div>
<div class="line"> dset_create_props, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>)) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to create dataset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Write the array to the file. The datatype and dataspace</span></div>
<div class="line"> <span class="comment">// describe the format of the data in the 'orig_data' buffer.</span></div>
<div class="line"> <span class="comment">// We use default raw data transfer properties.</span></div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___h5_d.html#ga98f44998b67587662af8b0d8a0a75906">H5Dwrite</a> (dataset, <a class="code" href="group___p_d_t_n_a_t.html#ga3cf93ffc6782be68070ef8e00f219ec2">H5T_NATIVE_INT</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>, orig_data) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to write to dataset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <a class="code" href="group___h5_d.html#gae47c3f38db49db127faf221624c30609">H5Dclose</a> (dataset);</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">if</span>((dataset = <a class="code" href="_h5version_8h.html#a7dba2e5b2045f31c0932123ffb54f7a3">H5Dopen</a>(file, DATASET_NAME, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>)) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to open dataset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Read the array. This is similar to writing data,</span></div>
<div class="line"> <span class="comment">// except the data flows in the opposite direction.</span></div>
<div class="line"> <span class="comment">// Note: Decompression is automatic.</span></div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___h5_d.html#ga8287d5a7be7b8e55ffeff68f7d26811c">H5Dread</a> (dataset, <a class="code" href="group___p_d_t_n_a_t.html#ga3cf93ffc6782be68070ef8e00f219ec2">H5T_NATIVE_INT</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>, new_data) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to read from dataset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <a class="code" href="group___h5_t.html#gafcba4db244f6a4d71e99c6e72b8678f0">H5Tclose</a> (datatype);</div>
<div class="line"> <a class="code" href="group___h5_d.html#gae47c3f38db49db127faf221624c30609">H5Dclose</a> (dataset);</div>
<div class="line"> <a class="code" href="group___h5_s.html#ga2b53128a39c8f104c1c9c2a91590fcc1">H5Sclose</a> (dataspace);</div>
<div class="line"> <a class="code" href="group___p_l_c_r.html#ga5dce61149211d3ef319452aa598887fb">H5Pclose</a> (dset_create_props);</div>
<div class="line"> <a class="code" href="group___h5_f.html#gac55cd91d80822e4f8c2a7f04ea71b124">H5Fclose</a> (file);</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="ttc" id="agroup___d_c_p_l_html_ga5c10165b670e0e984db431aee818cc7e"><div class="ttname"><a href="group___d_c_p_l.html#ga5c10165b670e0e984db431aee818cc7e">H5Pset_scaleoffset</a></div><div class="ttdeci">herr_t H5Pset_scaleoffset(hid_t plist_id, H5Z_SO_scale_type_t scale_type, int scale_factor)</div><div class="ttdoc">Sets up the use of the scale-offset filter.</div></div>
<div class="ttc" id="agroup___s_c_a_l_e_o_f_f_s_e_t_html_gga53d85c0570e17f6e1ddbf569462b1516a9fc45fdf1844739c145130e8c324a3a3"><div class="ttname"><a href="group___s_c_a_l_e_o_f_f_s_e_t.html#gga53d85c0570e17f6e1ddbf569462b1516a9fc45fdf1844739c145130e8c324a3a3">H5Z_SO_INT</a></div><div class="ttdeci">@ H5Z_SO_INT</div><div class="ttdef"><b>Definition:</b> H5Zpublic.h:200</div></div>
</div><!-- fragment --><p>The following code example illustrates the use of the scale-offset filter (set for variable minimum-bits method) for writing and reading floating-point data.</p>
<p><em>Scale-offset compression floating-point data</em> </p><div class="fragment"><div class="line"><span class="preprocessor">#include "hdf5.h"</span></div>
<div class="line"><span class="preprocessor">#include "stdlib.h"</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#define H5FILE_NAME "scaleoffset_test_float_Dscale.h5"</span></div>
<div class="line"><span class="preprocessor">#define DATASET_NAME "scaleoffset_float_Dscale"</span></div>
<div class="line"><span class="preprocessor">#define NX 200</span></div>
<div class="line"><span class="preprocessor">#define NY 300</span></div>
<div class="line"><span class="preprocessor">#define CH_NX 10</span></div>
<div class="line"><span class="preprocessor">#define CH_NY 15</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main(<span class="keywordtype">void</span>)</div>
<div class="line">{</div>
<div class="line"> <a class="code" href="_h5_ipublic_8h.html#a0045db7ff9c22ad35db6ae91662e1943">hid_t</a> file, dataspace, dataset, datatype, dset_create_props;</div>
<div class="line"> <a class="code" href="_h5public_8h.html#a7f81cce70fb546af88da24d9285d3c1c">hsize_t</a> dims[2], chunk_size[2];</div>
<div class="line"> <span class="keywordtype">float</span> orig_data[NX][NY];</div>
<div class="line"> <span class="keywordtype">float</span> new_data[NX][NY];</div>
<div class="line"> <span class="keywordtype">float</span> fill_val;</div>
<div class="line"> <span class="keywordtype">int</span> i, j;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Define dataset datatype</span></div>
<div class="line"> datatype = <a class="code" href="group___h5_t.html#gaec07efbab84f4e5b4ed22f010786be8e">H5Tcopy</a>(<a class="code" href="group___p_d_t_n_a_t.html#gae2523b63144b498f555fa4d04f59ee1c">H5T_NATIVE_FLOAT</a>);</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Initialize data buffer</span></div>
<div class="line"> <span class="keywordflow">for</span> (i=0; i < NX; i++)</div>
<div class="line"> <span class="keywordflow">for</span> (j=0; j < NY; j++)</div>
<div class="line"> orig_data[i][j] = (rand() % 10000) / 1000.0;</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Describe the size of the array.</span></div>
<div class="line"> dims[0] = NX;</div>
<div class="line"> dims[1] = NY;</div>
<div class="line"> <span class="keywordflow">if</span>((dataspace = <a class="code" href="group___h5_s.html#ga8e35eea5738b4805856eac7d595254ae">H5Screate_simple</a> (2, dims, NULL)) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to create dataspace\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Create a new file using read/write access, default file</span></div>
<div class="line"> <span class="comment">// creation properties, and default file access properties.</span></div>
<div class="line"> <span class="keywordflow">if</span>((file = <a class="code" href="group___h5_f.html#gae64b51ee9ac0781bc4ccc599d98387f4">H5Fcreate</a> (H5FILE_NAME, <a class="code" href="_h5_fpublic_8h.html#a5a2d6726f9ad8d2bca8df2b817e5ad6a">H5F_ACC_TRUNC</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>)) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to create file\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Set the dataset creation property list to specify that</span></div>
<div class="line"> <span class="comment">// the raw data is to be partitioned into 10 x 15 element</span></div>
<div class="line"> <span class="comment">// chunks and that each chunk is to be compressed.</span></div>
<div class="line"> chunk_size[0] = CH_NX;</div>
<div class="line"> chunk_size[1] = CH_NY;</div>
<div class="line"> <span class="keywordflow">if</span>((dset_create_props = <a class="code" href="group___p_l_c_r.html#gaf1b11da01d4d45d788c45f8bc5f0cbfa">H5Pcreate</a> (<a class="code" href="_h5_ppublic_8h.html#afcd7f8186c404f3a1d768632eacba102">H5P_DATASET_CREATE</a>)) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to create dataset property\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___d_c_p_l.html#ga3584d592e377da3604b7604e266dcf5b">H5Pset_chunk</a> (dset_create_props, 2, chunk_size) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to set chunk\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Set the fill value of dataset</span></div>
<div class="line"> fill_val = 10000.0;</div>
<div class="line"> <span class="keywordflow">if</span> (<a class="code" href="group___d_c_p_l.html#ga4335bb45b35386daa837b4ff1b9cd4a4">H5Pset_fill_value</a>(dset_create_props, <a class="code" href="group___p_d_t_n_a_t.html#gae2523b63144b498f555fa4d04f59ee1c">H5T_NATIVE_FLOAT</a>, &fill_val) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: can not set fill value for dataset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Set parameters for scale-offset compression; use variable</span></div>
<div class="line"> <span class="comment">// minimum-bits method, set decimal scale factor to 3. Check</span></div>
<div class="line"> <span class="comment">// the description of the H5Pset_scaleoffset function in the</span></div>
<div class="line"> <span class="comment">// HDF5 Reference Manual for more information.</span></div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___d_c_p_l.html#ga5c10165b670e0e984db431aee818cc7e">H5Pset_scaleoffset</a> (dset_create_props, <a class="code" href="group___s_c_a_l_e_o_f_f_s_e_t.html#gga53d85c0570e17f6e1ddbf569462b1516aa3d402f72492b3f34929fb2b99805adb">H5Z_SO_FLOAT_DSCALE</a>, 3) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to set scaleoffset filter\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Create a new dataset within the file. The datatype</span></div>
<div class="line"> <span class="comment">// and dataspace describe the data on disk, which may</span></div>
<div class="line"> <span class="comment">// or may not be different from the format used in the</span></div>
<div class="line"> <span class="comment">// application's memory.</span></div>
<div class="line"> <span class="keywordflow">if</span>((dataset = <a class="code" href="group___h5_d.html#ga0647ba4bbd26d5230cc07f3a5685b2cf">H5Dcreate</a> (file, DATASET_NAME, datatype, dataspace, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>,</div>
<div class="line"> dset_create_props, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>)) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to create dataset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Write the array to the file. The datatype and dataspace</span></div>
<div class="line"> <span class="comment">// describe the format of the data in the 'orig_data' buffer.</span></div>
<div class="line"> <span class="comment">// We use default raw data transfer properties.</span></div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___h5_d.html#ga98f44998b67587662af8b0d8a0a75906">H5Dwrite</a> (dataset, <a class="code" href="group___p_d_t_n_a_t.html#gae2523b63144b498f555fa4d04f59ee1c">H5T_NATIVE_FLOAT</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>, orig_data) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to write to dataset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <a class="code" href="group___h5_d.html#gae47c3f38db49db127faf221624c30609">H5Dclose</a> (dataset);</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">if</span>((dataset = <a class="code" href="_h5version_8h.html#a7dba2e5b2045f31c0932123ffb54f7a3">H5Dopen</a>(file, DATASET_NAME, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>)) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to open dataset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Read the array. This is similar to writing data,</span></div>
<div class="line"> <span class="comment">// except the data flows in the opposite direction.</span></div>
<div class="line"> <span class="comment">// Note: Decompression is automatic.</span></div>
<div class="line"> <span class="keywordflow">if</span>(<a class="code" href="group___h5_d.html#ga8287d5a7be7b8e55ffeff68f7d26811c">H5Dread</a> (dataset, <a class="code" href="group___p_d_t_n_a_t.html#gae2523b63144b498f555fa4d04f59ee1c">H5T_NATIVE_FLOAT</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_spublic_8h.html#a5f96eeee84b987f18470737f85af0484">H5S_ALL</a>, <a class="code" href="_h5_ppublic_8h.html#afa85e97bfbf9bf1c58e39263846c568f">H5P_DEFAULT</a>, new_data) < 0) {</div>
<div class="line"> printf(<span class="stringliteral">"Error: fail to read from dataset\n"</span>);</div>
<div class="line"> <span class="keywordflow">return</span> -1;</div>
<div class="line"> }</div>
<div class="line"> </div>
<div class="line"> <a class="code" href="group___h5_t.html#gafcba4db244f6a4d71e99c6e72b8678f0">H5Tclose</a> (datatype);</div>
<div class="line"> <a class="code" href="group___h5_d.html#gae47c3f38db49db127faf221624c30609">H5Dclose</a> (dataset);</div>
<div class="line"> <a class="code" href="group___h5_s.html#ga2b53128a39c8f104c1c9c2a91590fcc1">H5Sclose</a> (dataspace);</div>
<div class="line"> <a class="code" href="group___p_l_c_r.html#ga5dce61149211d3ef319452aa598887fb">H5Pclose</a> (dset_create_props);</div>
<div class="line"> <a class="code" href="group___h5_f.html#gac55cd91d80822e4f8c2a7f04ea71b124">H5Fclose</a> (file);</div>
<div class="line"> </div>
<div class="line"> <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
<div class="ttc" id="agroup___s_c_a_l_e_o_f_f_s_e_t_html_gga53d85c0570e17f6e1ddbf569462b1516aa3d402f72492b3f34929fb2b99805adb"><div class="ttname"><a href="group___s_c_a_l_e_o_f_f_s_e_t.html#gga53d85c0570e17f6e1ddbf569462b1516aa3d402f72492b3f34929fb2b99805adb">H5Z_SO_FLOAT_DSCALE</a></div><div class="ttdeci">@ H5Z_SO_FLOAT_DSCALE</div><div class="ttdef"><b>Definition:</b> H5Zpublic.h:198</div></div>
</div><!-- fragment --><h4>Limitations</h4>
<p>For floating-point data handling, there are some algorithmic limitations to the GRiB data packing mechanism: </p><ol>
<li>
Both the E-scaling and D-scaling methods are lossy compression </li>
<li>
For the D-scaling method, since data values have been rounded to integer values (positive) before truncating to the minimum-bits, their range is limited by the maximum value that can be represented by the corresponding unsigned integer type (the same size as that of the floating- point type) </li>
</ol>
<h4>Suggestions</h4>
<p>The following are some suggestions for using the filter for floating-point data: </p><ol>
<li>
It is better to convert the units of data so that the units are within certain common range (for example, 1200m to 1.2km) </li>
<li>
If data values to be compressed are very near to zero, it is strongly recommended that the user sets the fill value away from zero (for example, a large positive number); if the user does nothing, the HDF5 library will set the fill value to zero, and this may cause undesirable compression results </li>
<li>
Users are not encouraged to use a very large decimal scale factor (for example, 100) for the D-scaling method; this can cause the filter not to ignore the fill value when finding maximum and minimum values, and they will get a much larger minimum-bits (poor compression) </li>
</ol>
<h3><a class="anchor" id="subsubsec_dataset_filters_szip"></a>
Using the Szip Filter</h3>
<p>See The HDF Group website for further information regarding the Szip filter.</p>
<p>Previous Chapter <a class="el" href="_h5_g__u_g.html#sec_group">HDF5 Groups</a> - Next Chapter <a class="el" href="_h5_t__u_g.html#sec_datatype">HDF5 Datatypes</a> </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated on Fri Sep 1 2023 00:32:45 for HDF5 by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.9.1 </li>
</ul>
</div>
</body>
</html>
|