1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
|
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<META NAME="Generator" CONTENT="Microsoft Word 97">
<TITLE>Introduction to HDF5</TITLE>
</HEAD>
<BODY LINK="#0000ff" VLINK="#800080" bgcolor="#FFFFFF">
<hr>
<center>
<table border=0 width=98%>
<tr><td valign=top align=left>
Introduction to HDF5 <br>
<a href="H5.user.html">HDF5 User Guide</a>
<!--
<a href="Glossary.html">Glossary</a><br>
-->
</td>
<td valign=top align=right>
<a href="RM_H5Front.html">HDF5 Reference Manual</a> <br>
<a href="index.html">Other HDF5 documents and links</a>
</td></tr>
</table>
</center>
<hr>
<a name="Intro-Intro">
<h1 ALIGN="CENTER">Introduction to HDF5 Release 1.2</h1></a>
</FONT><FONT FACE="Times"><P>This is an introduction to the HDF5 data model and programming model. Being a <I>Getting Started</I> or <I>QuickStart</I> document, this </FONT><I>Introduction to HDF5</I> <FONT FACE="Times">is intended to provide enough information for you to develop a basic understanding of how HDF5 works and is meant to be used. Knowledge of the current version of HDF will make it easier to follow the text, but it is not required. More complete information of the sort you will need to actually use HDF5 is available in <A HREF="index.html">the HDF5 documentation</FONT></a><FONT FACE="Times">. Available documents include the following:
<UL>
</FONT><LI><A HREF="H5.user.html"><I>HDF5 User’s Guide</I></A>. Where appropriate, this <I>Introduction</I> will refer to specific sections of the <I>User’s Guide</I>.
<LI><I><A HREF="RM_H5Front.html">HDF5 Reference Manual</I></A>.</UL>
<FONT FACE="Times"><P>Code examples are available in the source code tree when you install HDF5.
<UL>
</FONT><LI>The directories <code>hdf5/examples</code> and
<code>hdf5/doc/html/Tutor/examples/</code> contain the examples
used in this document.
<LI>The directory<FONT FACE="Courier" SIZE=2> hdf5/test</FONT> contains the development tests used by the HDF5 developers. Since these codes are intended to fully exercise the system, they provide more diverse and sophisticated examples of what HDF5 can do.</UL>
<a name="Intro-TOC">
<hr>
<center>
<table border=0 width=90%>
<tr><th colspan=3>Table of Contents</th></tr></a>
<tr><td valign=top align=left width=42%>
<a href="#Intro-Intro">Introduction to HDF5 Release 1.2</a><p>
<a href="#Intro-WhatIs">1. What Is HDF5?</a><br>
<font size=-1>
  <a href="#Intro-Why">Why HDF5?</a><br>
  <a href="#Intro-Limits">Limitations of the
Current Release</a><br>
  <a href="#Intro-Changes">Changes in the
Current Release</a><p>
</font>
<a href="#Intro-FileOrg">2. HDF5 File Organization and</a></br>
<font size=-1>   </font><a href="#Intro-FileOrg">Data Model</a><br>
<font size=-1>
  <a href="#Intro-OGroups">HDF5 Groups</a><br>
  <a href="#Intro-ODatasets">HDF5 Datasets</a><br>
  <a href="#Intro-OAttributes">HDF5 Attributes</a><br>
  <a href="#Intro-FileTech">The File as Written to Media</a><p>
</font>
<a href="#Intro-APIs">3. The HDF5 API</a><br>
<font size=-1>
  <a href="#Intro-NameConv">Naming
Conventions</a><br>
  <a href="#Intro-Include">Include Files</a><br>
  <a href="#Intro-ProgModels">Programming
Models</a><br>
   
<A href="#Intro-PMCreateFile">Creating an HDF5 file</A><br>
   
<A href="#Intro-PMDiscard">Discarding objects</A><br>
   
<A href="#Intro-PMWriteNew">Writing a dataset to a
new file</A><br>
   
<A href="#Intro-PMGetInfo">Getting information about
a dataset</A><br>
   
<A href="#Intro-PMRdWrPortion">Reading/writing a portion of
a dataset</A><br>
   
<A href="#Intro-PMSelectHyper">Selecting hyperslabs</A><br>
   
<A href="#Intro-PMSelectPoints">Selecting of independent
points</A><br>
   
<A href="#Intro-PMCreateCompound">Creating compound
datatypes</A>
</td><td width=6%> </td><td valign=top align=left width=42%>
<a href="#Intro-APIs">3. The HDF5 API</a> <i>(continued)</i><br>
<font size=-1>
  <a href="#Intro-ProgModels">Programming
Models</a> <i>(continued)</i><br>
   
<A href="#Intro-PMCreateExtendible">Creating/writing extendible and</a> <br>
   
   
<A href="#Intro-PMCreateExtendible">chunked datasets</A><br>
   
<A href="#Intro-PMWorkGroups">Working with groups</A><br>
   
<A href="#Intro-PMWorkAttributes">Working with attributes</A><br>
   
<A href="#Intro-PMWorkRefObjects">Working with references to
objects</A><br>
   
<A href="#Intro-PMWorkRefRegions">Working with references to dataset</a> <br>
   
   
<A href="#Intro-PMWorkRefRegions">regions</A><p>
</font>
<a href="#Intro-Examples">4. Example Codes</a><br>
<font size=-1>
   
<A href="#CreateExample">1: Creating and writing a
dataset</A><br>
   
<A href="#CheckAndReadExample">2. Reading a hyperslab</A><br>
   
<A href="#WriteSelected">3. Writing selected data</A><br>
   
<A href="#Compound">4. Working with compound datatypes</A><br>
   
<A href="#CreateExtendWrite">5. Creating and writing an extendible</a> <br>
   
   
<A href="#CreateExtendWrite">dataset</A><br>
   
<A href="#ReadExtended">6. Reading data</A><br>
   
<A href="#CreateGroups">7. Creating groups</A><br>
   
<A href="#ReadWriteAttributes">8. Writing and reading
attributes</A><br>
   
<a href="#CreateWriteRefObj">9. Creating and writing references</a><br>
   
   
<a href="#CreateWriteRefObj">to objects</a><br>
   
<a href="#ReadRefObj">10. Reading references to objects</a><br>
   
<a href="#CreateWriteRefReg">11. Creating and writing references</a><br>
   
   
<a href="#CreateWriteRefReg">to dataset regions</a><br>
   
<a href="#ReadRefReg">12. Reading references to dataset</a><br>
   
   
<a href="#ReadRefReg">regions</a>
</font>
</td></tr>
</table>
</center>
<p>
<hr>
<H2><A NAME="Intro-WhatIs">1. What Is HDF5?</A></H2>
<FONT FACE="Times"><P>HDF5 is a completely new Hierarchical Data Format
product consisting of a data format specification and a
supporting library implementation. HDF5 is designed to address some
of the limitations of the older HDF product and to address current and
anticipated requirements of modern systems and applications.
<sup><a href="#H4H5footnote">1</a></sup>
<P>We urge you to look at HDF5, the format and the library, and give us
feedback on what you like or do not like about it, and what features
you would like to see added to it.
<a name="Intro-Why">
<P><B>Why HDF5?</B></a>
The development of HDF5 is motivated by a number of limitations in the
older HDF format and library. Some of these limitations are:
<UL>
</FONT><LI>A single file cannot store more than 20,000 complex objects, and a single file cannot be larger than 2 gigabytes.
<LI>The data models are less consistent than they should be, there are more object types than necessary, and datatypes are too restricted.
<LI>The library source is old and overly complex, does not support parallel I/O effectively, and is difficult to use in threaded applications.</UL>
<FONT FACE="Times"><P>HDF5 includes the following improvements.
<UL>
</FONT><LI>A new file format designed to address some of the deficiencies of HDF4.x, particularly the need to store larger files and more objects per file.
<LI>A simpler, more comprehensive data model that includes only two basic structures: a multidimensional array of record structures, and a grouping structure.
<LI>A simpler, better-engineered library and API, with improved support for parallel I/O, threads, and other requirements imposed by modern systems and applications.</UL>
<font size=-1>
<a name="H4H5footnote">1.</a>
Note that HDF and HDF5 are two different products.
HDF is a data format first developed in the 1980s and currently
in Release 4.<i>x</i> (HDF Release 4.<i>x</i>).
HDF5 is a new data format first released in <i>Beta</i> in 1998 and
designed to better meet the ever-increasing demands of scientific computing
and to take better advantage of the ever-increasing capabilities of
computing systems.
HDF5 is currently in Release 1.<i>x</i> (HDF5 Release 1.<i>x</i>).
</font>
<H3><A NAME="Intro-Limits">Limitations of the Current Release</A></H3>
<FONT FACE="Times"><P>This release includes the basic functionality that was planned for the HDF5 library. However, the library does not implement all of the features detailed in the format and API specifications. Here is a listing of some of the limitations of the current release:
<UL>
</FONT><LI>Data compression is supported, though only GZIP is implemented. GZIP, or GNU Zip, is a compression function from the GNU Project.
<LI>The library is not currently thread aware although we have planned for that possibility and intend eventually to implement it.
</UL>
<H3><A NAME="Intro-Changes">Changes in the Current Release</A></H3>
<P>A detailed list of changes in HDF5 since the last release,
HDF5 Release 1.0, can be found in the file <CODE>hdf5/RELEASE</CODE>
in the source code installation. At a higher level, those changes include:
<UL>
<li>Support for bitfield, opaque, enumeration, and variable-length datatypes
<li>Support for object and dataset region pointers
<li>Improved parallel performance and support for additional parallel platforms
<li>Improved and expanded documentation
<li>Enhancements to the <code>h5ls</code> and <code>h5dump</code> tools
and a new HDF5 to HDF4 conversion tool, <code>h5toh4</code>
<li>Over 30 new API functions
</UL>
<P>The changes as HDF5 has evolved from the first Alpha release
to the present are summarized in the file <CODE>hdf5/HISTORY</CODE>
in the source code installation.
<p align=right><font size=-1><a href="#Intro-TOC">(Return to TOC)</a></font>
<hr>
<H2><A NAME="Intro-FileOrg">2. HDF5 File Organization and Data Model</A></H2>
<FONT FACE="Times"><P>HDF5 files are organized in a hierarchical structure, with two primary structures: <I>groups</I> and <I>datasets</I>.
<UL>
</FONT><I><LI>HDF5 group: </I>a grouping structure containing instances of zero or more groups or datasets, together with supporting metadata.
<I><LI>HDF5 dataset:</I> a multidimensional array of data elements, together with supporting metadata. </UL>
<FONT FACE="Times"><P>Working with groups and group members is similar in many ways to working with directories and files in UNIX. As with UNIX directories and files, objects in an HDF5 file are often described by giving their full (or absolute) path names.
</FONT><CODE><DL>
<DD>/</CODE> signifies the root group. </DD>
<CODE><DD>/foo</CODE> signifies a member of the root group called <CODE>foo</CODE>.</DD>
<CODE><DD>/foo/zoo</CODE> signifies a member of the group <CODE>foo</CODE>, which in turn is a member of the root group.</DD>
</DL>
<FONT FACE="Times"><P>Any HDF5 group or dataset may have an associated <I>attribute list.</I> An HDF5 <I>attribute</I> is a user-defined HDF5 structure that provides extra information about an HDF5 object. Attributes are described in more detail below.
</FONT><H3><A NAME="Intro-OGroups">HDF5 Groups</A></H3>
<FONT FACE="Times"><P>An<I> HDF5 group</I> is a structure containing zero or more HDF5 objects. A group has two parts:
<UL>
</FONT><LI>A <I>group header</I>, which contains a group name and a list of group attributes.
<LI>A group symbol table, which is a list of the HDF5 objects that belong to the group.</UL>
<H3><A NAME="Intro-ODatasets">HDF5 Datasets</A></H3>
<FONT FACE="Times"><P>A dataset is stored in a file in two parts: a header and a data array.
<P>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, and other information used by the library to speed up access to the dataset or maintain the file's integrity.
<P>There are four essential classes of information in any header: <I>name</I>, <I>datatype</I>, <I>dataspace</I>, and <I>storage layout</I>:
</FONT><B><DFN><P>Name.</B></DFN><FONT FACE="Times"> A dataset <I>name</I> is a sequence of alphanumeric ASCII characters.
</FONT><B><DFN><P>Datatype.</B></DFN><FONT FACE="Times"> HDF5 allows one to define many different kinds of datatypes. There are two categories of datatypes: <I>atomic</I> datatypes and <I>compound</I> datatypes.
Atomic datatypes can also be system-specific, or <I><CODE>NATIVE</CODE></I>, and all datatypes can be <I>named</I>:
<ul>
<li><em>Atomic</em> datatypes are those that are not decomposed at the datatype interface level, such as integers and floats.
<li><I><CODE>NATIVE</CODE></I> datatypes are system-specific instances of atomic datatypes.
<li>Compound datatypes are made up of atomic datatypes.
<li><em>Named</em> datatypes are either atomic or compound datatypes that have been specifically designated to be shared across datasets.
</ul>
<I><P>Atomic datatypes</I> include integers and floating-point numbers. Each atomic type belongs to a particular class and has several properties: size, order, precision, and offset. In this introduction, we consider only a few of these properties.
<P>Atomic classes include integer, float, date and time, string, bit field, and opaque. <I>(Note: Only integer, float and string classes are available in the current implementation.)
</I><P>Properties of integer types include size, order (endian-ness), and signed-ness (signed/unsigned).
<P>Properties of float types include the size and location of the exponent and mantissa, and the location of the sign bit.
<P>The datatypes that are supported in the current implementation are:
<UL>
</FONT><LI>Integer datatypes: 8-bit, 16-bit, 32-bit, and 64-bit integers in both little and big-endian format.
<LI>Floating-point numbers: IEEE 32-bit and 64-bit floating-point numbers in both little and big-endian format.
<li>References.
<LI>Strings.</UL>
<p>
<em><code>NATIVE</code> datatypes.</em> Although it is possible to describe nearly any kind of atomic datatype, most applications will use predefined datatypes that are supported by their compiler. In HDF5 these are called <i>native</i> datatypes. <CODE>NATIVE</CODE> datatypes are C-like datatypes that are generally supported by the hardware of the machine on which the library was compiled. In order to be portable, applications should almost always use the <CODE>NATIVE </CODE>designation to describe data values in memory.
<P>The <CODE>NATIVE</CODE> architecture has base names which do not follow the same rules as the others. Instead, native type names are similar to the C type names. The following figure shows several examples.
<p>
<center>
<b>Examples of Native Datatypes and Corresponding C Types</b><br>
<TABLE BORDER CELLSPACING=1 CELLPADDING=7 WIDTH=462>
<TR><TD WIDTH="49%" VALIGN="TOP">
<B><P ALIGN="CENTER">Example</B></TD>
<TD WIDTH="51%" VALIGN="TOP">
<B><P ALIGN="CENTER">Corresponding C Type</B></TD>
</TR>
<TR><TD WIDTH="49%" VALIGN="TOP">
<code>H5T_NATIVE_CHAR</code></TD>
<TD WIDTH="51%" VALIGN="TOP">
<code>signed char</code></TD>
</TR>
<TR><TD WIDTH="49%" VALIGN="TOP">
<code>H5T_NATIVE_UCHAR</code></TD>
<TD WIDTH="51%" VALIGN="TOP">
<code>unsigned char</code></TD>
</TR>
<TR><TD WIDTH="49%" VALIGN="TOP">
<code>H5T_NATIVE_SHORT</code></TD>
<TD WIDTH="51%" VALIGN="TOP">
<code>short</code></TD>
</TR>
<TR><TD WIDTH="49%" VALIGN="TOP">
<code>H5T_NATIVE_USHORT</code></TD>
<TD WIDTH="51%" VALIGN="TOP">
<code>unsigned short</code></TD>
</TR>
<TR><TD WIDTH="49%" VALIGN="TOP">
<code>H5T_NATIVE_INT</code></TD>
<TD WIDTH="51%" VALIGN="TOP">
<code>int</code></TD>
</TR>
<TR><TD WIDTH="49%" VALIGN="TOP">
<code>H5T_NATIVE_UINT</code></TD>
<TD WIDTH="51%" VALIGN="TOP">
<code>unsigned</code></TD>
</TR>
<TR><TD WIDTH="49%" VALIGN="TOP">
<code>H5T_NATIVE_LONG</code></TD>
<TD WIDTH="51%" VALIGN="TOP">
<code>long</code></TD>
</TR>
<TR><TD WIDTH="49%" VALIGN="TOP">
<code>H5T_NATIVE_ULONG</code></TD>
<TD WIDTH="51%" VALIGN="TOP">
<code>unsigned long</code></TD>
</TR>
<TR><TD WIDTH="49%" VALIGN="TOP">
<code>H5T_NATIVE_LLONG</code></TD>
<TD WIDTH="51%" VALIGN="TOP">
<code>long long</code></TD>
</TR>
<TR><TD WIDTH="49%" VALIGN="TOP">
<code>H5T_NATIVE_ULLONG</code></TD>
<TD WIDTH="51%" VALIGN="TOP">
<code>unsigned long long</code></TD>
</TR>
<TR><TD WIDTH="49%" VALIGN="TOP">
<code>H5T_NATIVE_FLOAT</code></TD>
<TD WIDTH="51%" VALIGN="TOP">
<code>float</code></TD>
</TR>
<TR><TD WIDTH="49%" VALIGN="TOP">
<code>H5T_NATIVE_DOUBLE</code></TD>
<TD WIDTH="51%" VALIGN="TOP">
<code>double</code></TD>
</TR>
<TR><TD WIDTH="49%" VALIGN="TOP">
<code>H5T_NATIVE_LDOUBLE</code></TD>
<TD WIDTH="51%" VALIGN="TOP">
<code>long double</code></TD>
</TR>
<TR><TD WIDTH="49%" VALIGN="TOP">
<CODE>H5T_NATIVE_HSIZE</CODE></TD>
<TD WIDTH="51%" VALIGN="TOP">
<CODE>hsize_t</CODE></TD>
</TR>
<TR><TD WIDTH="49%" VALIGN="TOP">
<CODE>H5T_NATIVE_HSSIZE</CODE></TD>
<TD WIDTH="51%" VALIGN="TOP">
<CODE>hssize_t</CODE></TD>
</TR>
<TR><TD WIDTH="49%" VALIGN="TOP">
<CODE>H5T_NATIVE_HERR</CODE></TD>
<TD WIDTH="51%" VALIGN="TOP">
<CODE>herr_t</CODE></TD>
</TR>
<TR><TD WIDTH="49%" VALIGN="TOP">
<CODE>H5T_NATIVE_HBOOL</CODE></TD>
<TD WIDTH="51%" VALIGN="TOP">
<CODE>hbool_t</CODE></TD>
</TR>
</TABLE>
</CENTER>
<FONT FACE="Times"><P>See <A HREF="Datatypes.html"><I>Datatypes</I></A> in the<I> HDF User’s Guide</I> for further information.</font>
<FONT FACE="Times"><P>A <I>compound datatype</I> is one in which a collection of simple datatypes are represented as a single unit, similar to a <I>struct</I> in C. The parts of a compound datatype are called <I>members.</I> The members of a compound datatype may be of any datatype, including another compound datatype. It is possible to read members from a compound type without reading the whole type.
<p>
<ta/FONT><I><P>Named datatypes.</I> Normally each dataset has its own datatype, but sometimes we may want to share a datatype among several datasets. This can be done using a <I>named </I>datatype. A named datatype is stored in the file independently of any dataset, and referenced by all datasets that have that datatype. Named datatypes may have an associated attributes list.
See <A HREF="Datatypes.html"><I>Datatypes</I></A></font><FONT FACE="Times"> in the<I> HDF User’s Guide</I> for further information.
<B><DFN><P>Dataspace.</B> </DFN>A dataset <I>dataspace </I>describes the dimensionality of the dataset. The dimensions of a dataset can be fixed (unchanging), or they may be <I>unlimited</I>, which means that they are extendible (i.e. they can grow larger).
<P>Properties of a dataspace consist of the <I>rank </I>(number of dimensions) of the data array, the <I>actual sizes of the dimensions</I> of the array, and the <I>maximum sizes of the dimensions </I>of the array. For a fixed-dimension dataset, the actual size is the same as the maximum size of a dimension. When a dimension is unlimited, the maximum size is set to the </FONT>value <CODE>H5P_UNLIMITED</CODE>.<FONT FACE="Times"> (An example below shows how to create extendible datasets.)
<P>A dataspace can also describe portions of a dataset, making it possible to do partial I/O operations on <I>selections</I>. <I>Selection</I> is supported by the dataspace interface (H5S). Given an n-dimensional dataset, there are currently four ways to do partial selection:
<OL>
</FONT><LI>Select a logically contiguous n-dimensional hyperslab.
<LI>Select a non-contiguous hyperslab consisting of elements or blocks of elements (hyperslabs) that are equally spaced.
<li>Select a union of hyperslabs.
<LI>Select a list of independent points. </OL>
<FONT FACE="Times"><P>Since I/O operations have two end-points, the raw data transfer functions require two dataspace arguments: one describes the application memory dataspace or subset thereof, and the other describes the file dataspace or subset thereof.
<P>See <A HREF="Dataspaces.html"><I>Dataspaces</I></A></font><FONT FACE="Times"> in the<I> HDF User’s Guide</I> for further information.
</FONT><B><DFN><P>Storage layout.</B></DFN><FONT FACE="Times"> The HDF5 format makes it possible to store data in a variety of ways. The default storage layout format is <I>contiguous</I>, meaning that data is stored in the same linear way that it is organized in memory. Two other storage layout formats are currently defined for HDF5: <I>compact, </I>and<I> chunked. </I>In the future, other storage layouts may be added.<I>
<P>Compact</I> storage is used when the amount of data is small and can be stored directly in the object header. <I>(Note: Compact storage is not supported in this release.)</I>
<I><P>Chunked</I> storage involves dividing the dataset into equal-sized "chunks" that are stored separately. Chunking has three important benefits.
<OL>
<LI>It makes it possible to achieve good performance when accessing subsets of the datasets, even when the subset to be chosen is orthogonal to the normal storage order of the dataset.
<LI>It makes it possible to compress large datasets and still achieve good performance when accessing subsets of the dataset.
<LI>It makes it possible efficiently to extend the dimensions of a dataset in any direction.</OL>
<P>
See <A HREF="Datasets.html"><I>Datasets</I></A> and <A HREF="Chunking.html"><I>Dataset Chunking Issues</I></A></font><FONT FACE="Times"> in the<I> HDF User’s Guide</I> for further information.
We particularly encourage you to read <A HREF="Chunking.html"><I>Dataset Chunking Issues</I></A> since the issue is complex and beyond the scope of this document.
</FONT><H3><A NAME="Intro-OAttributes">HDF5 Attributes</A></H3>
<I>Attributes </I>are small named datasets that are attached to primary datasets, groups, or named datatypes. Attributes can be used to describe the nature and/or the intended usage of a dataset or group. An attribute has two parts: (1) a <I>name</I> and (2) a <I>value</I>. The value part contains one or more data entries of the same datatype.
<FONT FACE="Times"><P>The Attribute API (H5A) is used to read or write attribute information. When accessing attributes, they can be identified by name or by an <I>index value</I>. The use of an index value makes it possible to iterate through all of the attributes associated with a given object.
<P>The HDF5 format and I/O library are designed with the assumption that attributes are small datasets. They are always stored in the object header of the object they are attached to. Because of this, large datasets should not be stored as attributes. How large is "large" is not defined by the library and is up to the user's interpretation. (Large datasets with metadata can be stored as supplemental datasets in a group with the primary dataset.)
<P>See <A HREF="Attributes.html"><I>Attributes</I></A></font><FONT FACE="Times"> in the<I> HDF User’s Guide</I> for further information.
</FONT>
<H3><A NAME="Intro-FileTech">The File as Written to Media</A></H3>
<p>For those who are interested, this section takes a look at
the low-level elements of the file as the file is written to disk
(or other storage media) and the relation of those low-level
elements to the higher level elements with which users typically
are more familiar. The HDF5 API generally exposes only the
high-level elements to the user; the low-level elements are
often hidden.
The rest of this <cite>Introduction</cite> does not assume
an understanding of this material.
<P>The format of an HDF5 file on disk encompasses several
key ideas of the HDF4 and AIO file formats as well as
addressing some shortcomings therein. The new format is
more self-describing than the HDF4 format and is more
uniformly applied to data objects in the file.
<table align=left width=100>
<tr><td align=center>
<hr>
<img src="FF-IH_FileGroup.gif" alt="HDF5 Groups" hspace=15 vspace=15>
</td><td> </td></tr><tr><td align=center>
<strong>Figure 1:</strong> Relationships among the
HDF5 root group, other groups, and objects
<hr>
</td><td> </td></tr>
</table>
<P>An HDF5 file appears to the user as a directed graph.
The nodes of this graph are the higher-level HDF5 objects
that are exposed by the HDF5 APIs:
<ul>
<li>Groups
<li>Datasets
<li>Datatypes
<li>Dataspaces
</ul>
<P>At the lowest level, as information is actually written to the disk,
an HDF5 file is made up of the following objects:
<ul>
<li>A boot block
<li>B-tree nodes (containing either symbol nodes or raw data chunks)
<li>Object headers
<table align=right width=95>
<tr><td> </td><td align=center>
<hr>
<img src="FF-IH_FileObject.gif" alt="HDF5 Objects" hspace=15 vspace=15>
</td></tr><tr><td> </td><td align=center>
<strong>Figure 2:</strong> HDF5 objects -- datasets, datatypes, or dataspaces
<hr>
</td></tr>
</table>
<li>Collections
<li>Local heaps
<li>Free space
</ul>
The HDF5 library uses these lower-level objects to represent the
higher-level objects that are then presented to the user or
to applications through the APIs.
For instance, a group is an object header that contains a message that
points to a local heap and to a B-tree which points to symbol nodes.
A dataset is an object header that contains messages that describe
datatype, space, layout, filters, external files, fill value, etc
with the layout message pointing to either a raw data chunk or to a
B-tree that points to raw data chunks.
<P>See the <A HREF="H5.format.html"><cite>HDF5 File Format
Specification</cite></A><FONT FACE="Times"> for further information.
<p align=right><font size=-1><a href="#Intro-TOC">(Return to TOC)</a></font>
<hr>
</FONT><H2><A NAME="Intro-APIs">3. The HDF5 Applications Programming Interface (API)</A></H2>
<FONT FACE="Times"><P>The current HDF5 API is implemented only in C. The API provides routines for creating HDF5 files, creating and writing groups, datasets, and their attributes to HDF5 files, and reading groups, datasets and their attributes from HDF5 files.
</FONT><H3><A NAME="Intro-NameConv">Naming conventions</A></H3>
<FONT FACE="Times"><P>All C routines in the HDF 5 library begin with a prefix of the form <B>H5*</B>, where <B>*</B> is a single letter indicating the object on which the operation is to be performed:
<UL>
</FONT><B><LI>H5F</B>: <B>F</B>ile-level access routines. <BR>
Example: <CODE>H5Fopen</CODE>, which opens an HDF5 file.
<B><LI>H5G</B>: <B>G</B>roup functions, for creating and operating on groups of objects. <BR>
Example: <CODE>H5Gset</CODE><FONT FACE="Courier">,</FONT>which sets the working group to the specified group.
<B><LI>H5T: </B>Data<B>T</B>ype functions, for creating and operating on simple and compound datatypes to be used as the elements in data arrays.<B><BR>
</B>Example: <CODE>H5Tcopy</CODE><FONT FACE="Courier">,</FONT>which creates a copy of an existing datatype.
<B><LI>H5S: </B>Data<B>S</B>pace functions, which create and manipulate the dataspace in which the elements of a data array are stored.<BR>
Example: <CODE>H5Screate_simple</CODE>, which creates simple dataspaces.
<B><LI>H5D: D</B>ataset functions, which manipulate the data within datasets and determine how the data is to be stored in the file. <BR>
Example: <CODE>H5Dread</CODE>, which reads all or part of a dataset into a buffer in memory.
<B><LI>H5P</B>: <B>P</B>roperty list functions, for manipulating object creation and access properties. <BR>
Example: <CODE>H5Pset_chunk</CODE>, which sets the number of dimensions and the size of a chunk.
<B><LI>H5A</B>: <B>A</B>ttribute access and manipulating routines. <BR>
Example: <CODE>H5Aget_name</CODE>, which retrieves name of an attribute.
<B><LI>H5Z</B>: <B>C</B>ompression registration routine. <BR>
Example: <CODE>H5Zregister</CODE>, which registers new compression and uncompression functions for use with the HDF5 library.
<B><LI>H5E</B>: <B>E</B>rror handling routines. <BR>
Example: <CODE>H5Eprint</CODE>, which prints the current error stack.
<B><LI>H5R</B>: <B>R</B>eference routines. <BR>
Example: <CODE>H5Rcreate</CODE>, which creates a reference.
<B><LI>H5I</B>: <B>I</B>dentifier routine. <BR>
Example: <CODE>H5Iget_type</CODE>, which retrieves the type of an object.</UL>
<H3><A NAME="Intro-Include">Include Files</A> </H3>
<FONT FACE="Times"><P>There are a number definitions and declarations that should be included with any HDF5 program. These definitions and declarations are contained in several <I>include</I> files. The main include </FONT>file is <CODE>hdf5.h</CODE>. This file<FONT FACE="Times"> includes all of the other files that your program is likely to need. <I>Be sure to include </i><code>hdf5.h</code><i> in any program that uses the HDF5 library.</I></FONT>
<H3><A NAME="Intro-ProgModels">Programming Models</A></H3>
<FONT FACE="Times"><P>In this section we describe how to program some basic operations on files, including how to
<UL>
</FONT><LI>Create a file.
<LI>Create and initialize a dataset.
<LI>Discard objects when they are no longer needed.
<LI>Write a dataset to a new file.
<LI>Obtain information about a dataset.
<LI>Read a portion of a dataset.
<LI>Create and write compound datatypes.
<LI>Create and write extendible datasets.
<LI>Create and populate groups.
<LI>Work with attributes. </UL>
<h3><A NAME="Intro-PMCreateFile">How to create an HDF5 file</A></h3>
<P>This programming model shows how to create a file and also how to close the file.
<OL>
<LI>Create the file.
<LI>Close the file.
</ol>
<P>The following code fragment implements the specified model. If there is a possibility that the file already exists, the user must add the flag <CODE>H5ACC_TRUNC</CODE> to the access mode to overwrite the previous file's information.
</font>
<CODE><PRE>hid_t file; /* identifier */
/*
* Create a new file using H5ACC_TRUNC access,
* default file creation properties, and default file
* access properties.
* Then close the file.
*/
file = H5Fcreate(FILE, H5ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
status = H5Fclose(file); </PRE>
</CODE><DL>
<DT> </DT>
</DL>
<h3><A NAME="Intro-PMComponents">How to create and initialize the essential components of a dataset for writing to a file</A></h3>
<P>Recall that datatypes and dimensionality (dataspace) are independent objects, which are created separately from any dataset that they might be attached to. Because of this the creation of a dataset requires, at a minimum, separate definitions of datatype, dimensionality, and dataset. Hence, to create a dataset the following steps need to be taken:
<ol>
<FONT FACE="Times"><LI VALUE=1>Create and initialize a dataspace for the dataset to be written.
<LI>Define the datatype for the dataset to be written.
<LI>Create and initialize the dataset itself.</OL>
</FONT><FONT FACE="Times"><P>The following code illustrates the creation of these three components of a dataset object.
</FONT><CODE><PRE>hid_t dataset, datatype, dataspace; /* declare identifiers */
/*
* Create dataspace: Describe the size of the array and
* create the data space for fixed size dataset.
*/
dimsf[0] = NX;
dimsf[1] = NY;
dataspace = H5Screate_simple(RANK, dimsf, NULL);
/*
* Define datatype for the data in the file.
* We will store little endian integer numbers.
*/
datatype = H5Tcopy(H5T_NATIVE_INT);
status = H5Tset_order(datatype, H5T_ORDER_LE);
/*
* Create a new dataset within the file using defined
* dataspace and datatype and default dataset creation
* properties.
* NOTE: H5T_NATIVE_INT can be used as datatype if conversion
* to little endian is not needed.
*/
dataset = H5Dcreate(file, DATASETNAME, datatype, dataspace, H5P_DEFAULT);</PRE>
</CODE><h3><A NAME="Intro-PMDiscard">How to discard objects when they are no longer needed</A></h3>
<FONT FACE="Times"><P>The datatype, dataspace and dataset objects should be released once they are no longer needed by a program. Since each is an independent object, the must be released (or <I>closed</I>) separately. The following lines of code close the datatype, dataspace, and datasets that were created in the preceding section.
</FONT><CODE><P>H5Tclose(datatype);
<P>H5Dclose(dataset);
<P>H5Sclose(dataspace);
</CODE><h3><A NAME="Intro-PMWriteNew">How to write a dataset to a new file</A></h3>
<FONT FACE="Times"><P>Having defined the datatype, dataset, and dataspace parameters, you write out the data with a call to </FONT><CODE>H5Dwrite</CODE><FONT FACE="Courier">.
</FONT><CODE><PRE>/*
* Write the data to the dataset using default transfer
* properties.
*/
status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
H5P_DEFAULT, data);</PRE>
</CODE><FONT FACE="Times"><P>The third and fourth parameters of </FONT><CODE>H5Dwrite</CODE><FONT FACE="Times"> in the example describe the dataspaces in memory and in the file, respectively. They are set to the value </FONT><CODE>H5S_ALL</CODE><FONT FACE="Times"> to indicate that an entire dataset is to be written. In a later section we look at how we would access a portion of a dataset.
</FONT><P><A HREF="#CreateExample"><FONT FACE="Times">Example 1</FONT></A><FONT FACE="Times"> contains a program that creates a file and a dataset, and writes the dataset to the file.
<P>Reading is analogous to writing. If, in the previous example, we wish to read an entire dataset, we would use the same basic calls with the same parameters. Of course, the routine </FONT><CODE>H5Dread</CODE><FONT FACE="Times"> would replace </FONT><CODE>H5Dwrite</CODE><FONT FACE="Courier">.</FONT><FONT FACE="Times">
</FONT><h3><A NAME="Intro-PMGetInfo">Getting information about a dataset</A></h3>
<FONT FACE="Times"><P>Although reading is analogous to writing, it is often necessary to query a file to obtain information about a dataset. For instance, we often need to know about the datatype associated with a dataset, as well dataspace information (e.g. rank and dimensions). There are several "get" routines for obtaining this information. The following code segment illustrates how we would get this kind of information:
</FONT><CODE><PRE>/*
* Get datatype and dataspace identifiers and then query
* dataset class, order, size, rank and dimensions.
*/
datatype = H5Dget_type(dataset); /* datatype identifier */
class = H5Tget_class(datatype);
if (class == H5T_INTEGER) printf("Data set has INTEGER type \n");
order = H5Tget_order(datatype);
if (order == H5T_ORDER_LE) printf("Little endian order \n");
size = H5Tget_size(datatype);
printf(" Data size is %d \n", size);
dataspace = H5Dget_space(dataset); /* dataspace identifier */
rank = H5Sget_simple_extent_ndims(dataspace);
status_n = H5Sget_simple_extent_dims(dataspace, dims_out);
printf("rank %d, dimensions %d x %d \n", rank, dims_out[0], dims_out[1]);</PRE>
</CODE><h3><A NAME="Intro-PMRdWrPortion">Reading and writing a portion of a dataset</A></h3>
<P>In the previous discussion, we describe how to access an entire dataset with one write (or read) operation. HDF5 also supports access to portions (or selections) of a dataset in one read/write operation. Currently selections are limited to hyperslabs, their unions, and the lists of independent points. Both types of selection will be discussed in the following sections. Several sample cases of selection reading/writing are shown on the following figure.
<center>
<table bgcolor="#FFFFFF" border=1>
<tr><td align=center>
<img src="IH_mapHead.gif">
</tr></td><tr><td align=center>
a <img src="IH_map1.gif">
</tr></td><tr><td align=center>
b <img src="IH_map2.gif">
</tr></td><tr><td align=center>
c <img src="IH_map3.gif">
</tr></td><tr><td align=center>
d <img src="IH_map4.gif">
</tr></td><tr><td align=center>
<img src="IH_mapFoot.gif">
</tr></td>
</table>
</center>
</B><P>In example (a) a single hyperslab is read from the midst of a two-dimensional array in a file and stored in the corner of a smaller two-dimensional array in memory. In (b) a regular series of blocks is read from a two-dimensional array in the file and stored as a contiguous sequence of values at a certain offset in a one-dimensional array in memory. In (c) a sequence of points with no regular pattern is read from a two-dimensional array in a file and stored as a sequence of points with no regular pattern in a three-dimensional array in memory.
In (d) a union of hyperslabs in the file dataspace is read and
the data is stored in another union of hyperslabs in the memory dataspace.
<P>As these examples illustrate, whenever we perform partial read/write operations on the data, the following information must be provided: file dataspace, file dataspace selection, memory dataspace and memory dataspace selection. After the required information is specified, actual read/write operation on the portion of data is done in a single call to the HDF5 read/write functions H5Dread(write).
<H5><A NAME="Intro-PMSelectHyper">Selecting hyperslabs</A></H5>
<FONT FACE="Times"><P>Hyperslabs are portions of datasets. A hyperslab selection can be a logically contiguous collection of points in a dataspace, or it can be regular pattern of points or blocks in a dataspace. The following picture illustrates a selection of regularly spaced 3x2 blocks in an 8x12 dataspace.</FONT>
<p>
<center>
<b>Hyperslab selection</b><br>
<TABLE BORDER CELLSPACING=1 CELLPADDING=7 WIDTH=345>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
</TR>
</TABLE>
</center>
<FONT FACE="Times"><P>Four parameters are required to describe a completely general hyperslab. Each parameter is an array whose rank is the same as that of the dataspace:
<UL>
</FONT><CODE><LI>start</CODE>: a starting location for the hyperslab. In the example <CODE>start</CODE> is (0,1).
<CODE><LI>stride</CODE>: the number of elements to separate each element or block to be selected. In the example <CODE>stride</CODE><I> </I> is (4,3). If the stride parameter is set to NULL, the stride size defaults to 1 in each dimension.
<CODE><LI>count</CODE>: the number of elements or blocks to select along each dimension. In the example, <CODE>count</CODE> is (2,4).
<CODE><LI>block</CODE>: the size of the block selected from the dataspace. In the example, <CODE>block</CODE> is (3,2). If the block parameter is set to NULL, the block size defaults to a single element in each dimension, as if the block array was set to all 1s.</UL>
<B><P>In what order is data copied? </B>When actual I/O is performed data values are copied by default from one dataspace to another in so-called row-major, or C order. That is, it is assumed that the first dimension varies slowest, the second next slowest, and so forth.
<p><B>Example without strides or blocks.</B> Suppose we want to read a 3x4 hyperslab from a dataset in a file beginning at the element <CODE><1,2></CODE><FONT FACE="Times"> in the dataset. In order to do this, we must create a dataspace that describes the overall rank and dimensions of the dataset in the file, as well as the position and size of the hyperslab that we are extracting from that dataset. The following code illustrates the selection of the hyperslab in the file dataspace.
</FONT><CODE><PRE>
/*
* Define file dataspace.
*/
dataspace = H5Dget_space(dataset); /* dataspace identifier */
rank = H5Sget_simple_extent_ndims(dataspace);
status_n = H5Sget_simple_extent_dims(dataspace, dims_out, NULL);
/*
* Define hyperslab in the dataset.
*/
offset[0] = 1;
offset[1] = 2;
count[0] = 3;
count[1] = 4;
status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, NULL,
count, NULL);</PRE>
</CODE><FONT FACE="Times"><P>This describes the dataspace from which we wish to read. We need to define the dataspace in memory analogously. Suppose, for instance, that we have in memory a 3 dimensional 7x7x3 array into which we wish to read the 3x4 hyperslab described above beginning at the element </FONT><CODE><3,0,0></CODE><FONT FACE="Times">. Since the in-memory dataspace has three dimensions, we have to describe the hyperslab as an array with three dimensions, with the last dimension being 1: </FONT><CODE><3,4,1></CODE><FONT FACE="Times">.
<P>Notice that we must describe two things: the dimensions of the in-memory array, and the size and position of the hyperslab that we wish to read in. The following code illustrates how this would be done.
</FONT><CODE><PRE>/*
* Define memory dataspace.
*/
dimsm[0] = 7;
dimsm[1] = 7;
dimsm[2] = 3;
memspace = H5Screate_simple(RANK_OUT,dimsm,NULL);
/*
* Define memory hyperslab.
*/
offset_out[0] = 3;
offset_out[1] = 0;
offset_out[2] = 0;
count_out[0] = 3;
count_out[1] = 4;
count_out[2] = 1;
status = H5Sselect_hyperslab(memspace, H5S_SELECT_SET, offset_out, NULL,
count_out, NULL);
/*</PRE>
</CODE><P><A HREF="#CheckAndReadExample"><FONT FACE="Times">Example 2</FONT></A><FONT FACE="Times"> contains a complete program that performs these operations.
<B><P>Example with strides and blocks</B>. Consider the 8x12 dataspace described above, in which we selected eight 3x2 blocks. Suppose we wish to fill these eight blocks. </FONT>
<p>
<center>
<b>Hyperslab selection</b><br>
<TABLE BORDER CELLSPACING=1 CELLPADDING=7 WIDTH=345>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>X</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
</TR>
</TABLE>
</center>
<P>This hyperslab has the following parameters:<FONT FACE="Times"> </FONT><CODE>start=(0,1), stride=(4,3), count=(2,4), block=(3,2).
</CODE><FONT FACE="Times"><P>Suppose that the source dataspace in memory is this 50-element one dimensional array called </FONT><CODE>vector</CODE><FONT FACE="Times">:</FONT>
<p>
<center>
<b>A 50-element one dimensional array</b><br>
<TABLE BORDER CELLSPACING=1 CELLPADDING=7 WIDTH=457>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>-1</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>1</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>2</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>3</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>4</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>5</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>6</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>7</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<FONT FACE="Courier"><CODE><P>... </FONT></CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>47</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>48</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>-1</CODE></TD>
</TR>
</TABLE>
</center>
<FONT FACE="Times"><P>The following code will write 48 elements from </FONT><CODE>vector</code> to our file dataset, starting with the second element in <code>vector</code>.
<pre>
/* Select hyperslab for the dataset in the file, using 3x2 blocks, (4,3) stride
* (2,4) count starting at the position (0,1).
*/
start[0] = 0; start[1] = 1;
stride[0] = 4; stride[1] = 3;
count[0] = 2; count[1] = 4;
block[0] = 3; block[1] = 2;
ret = H5Sselect_hyperslab(fid, H5S_SELECT_SET, start, stride, count, block);
/*
* Create dataspace for the first dataset.
*/
mid1 = H5Screate_simple(MSPACE1_RANK, dim1, NULL);
/*
* Select hyperslab.
* We will use 48 elements of the vector buffer starting at the second element.
* Selected elements are 1 2 3 . . . 48
*/
start[0] = 1;
stride[0] = 1;
count[0] = 48;
block[0] = 1;
ret = H5Sselect_hyperslab(mid1, H5S_SELECT_SET, start, stride, count, block);
/*
* Write selection from the vector buffer to the dataset in the file.
*
ret = H5Dwrite(dataset, H5T_NATIVE_INT, midd1, fid, H5P_DEFAULT, vector)
</pre><CODE><P>
</CODE><P>After these operations, the file dataspace will have the following values.
<p>
<center>
<b>Hyperslab selection with assigned values</b><br>
<TABLE BORDER CELLSPACING=1 CELLPADDING=7 WIDTH=460>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>1</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>2</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>3</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>4</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>5</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>6</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>7</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>8</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>9</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>10</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>11</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>12</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>13</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>14</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>15</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>16</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>17</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>18</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>19</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>20</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>21</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>22</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>23</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>24</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>25</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>26</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>27</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>28</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>29</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>30</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>31</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>32</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>33</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>34</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>35</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>36</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>37</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>38</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>39</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>40</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>41</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>42</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>43</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>44</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>45</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>46</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>47</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>48</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
</TR>
</TABLE>
</center>
<P>Notice that the values are inserted in the file dataset in row-major order.
<P><a href="#WriteSelected">Example 3</a> includes this code and other example code illustrating the use of hyperslab selection.
<H5><A NAME="Intro-PMSelectPoints">Selecting a list of independent points</A></H5>
A hyperslab specifies a regular pattern of elements in a dataset. It is also possible to specify a list of independent elements to read or write using the function <CODE>H5Sselect_elements</CODE>. Suppose, for example, that we wish to write the values 53, 59, 61, 67 to the following elements of the 8x12 array used in the previous example: (0,0), (3,3), (3,5), and (5,6). The following code selects the points and writes them to the dataset:
<pre>
#define FSPACE_RANK 2 /* Dataset rank as it is stored in the file */
#define NPOINTS 4 /* Number of points that will be selected
and overwritten */
#define MSPACE2_RANK 1 /* Rank of the second dataset in memory */
#define MSPACE2_DIM 4 /* Dataset size in memory */
hsize_t dim2[] = {MSPACE2_DIM}; /* Dimension size of the second
dataset (in memory) */
int values[] = {53, 59, 61, 67}; /* New values to be written */
hssize_t coord[NPOINTS][FSPACE_RANK]; /* Array to store selected points
from the file dataspace */
/*
* Create dataspace for the second dataset.
*/
mid2 = H5Screate_simple(MSPACE2_RANK, dim2, NULL);
/*
* Select sequence of NPOINTS points in the file dataspace.
*/
coord[0][0] = 0; coord[0][1] = 0;
coord[1][0] = 3; coord[1][1] = 3;
coord[2][0] = 3; coord[2][1] = 5;
coord[3][0] = 5; coord[3][1] = 6;
ret = H5Sselect_elements(fid, H5S_SELECT_SET, NPOINTS,
(const hssize_t **)coord);
/*
* Write new selection of points to the dataset.
*/
ret = H5Dwrite(dataset, H5T_NATIVE_INT, mid2, fid, H5P_DEFAULT, values);
</pre>
<P>
</FONT><P>After these operations, the file dataspace will have the following values:
<p>
<center>
<b>Hyperslab selection with an overlay of independent points</b><br>
<TABLE BORDER CELLSPACING=1 CELLPADDING=7 WIDTH=460>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<B><CODE><P>53</B></CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>1</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>2</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>3</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>4</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>5</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>6</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>7</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>8</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>9</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>10</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>11</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>12</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>13</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>14</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>15</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>16</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>17</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>18</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>19</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>20</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>21</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>22</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>23</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>24</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<B><CODE><P>59</B></CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<B><CODE><P>61</B></CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>25</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>26</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>27</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>28</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>29</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>30</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>31</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>32</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>33</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>34</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>35</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>36</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<B><CODE><P>67</B></CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>37</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>38</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>39</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>40</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>41</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>42</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>43</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>44</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>45</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>46</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>47</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>48</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
</TR>
</TABLE>
</center>
<P><A HREF="#WriteSelected"><FONT FACE="Times">Example 3</FONT></A><FONT FACE="Times"> contains a complete program that performs these subsetting operations.
<H5><A NAME="_SelectUnion">Selecting a union of hyperslabs</A></H5>
</font>
The HDF5 Library allows the user to select a union of hyperslabs and
write or read the selection into another selection. The shapes of
the two selections may differ, but the number of elements must be equal.
<p>
Suppose that we want to read two overlapping hyperslabs from the dataset
written in the previous example into a union of hyperslabs in the memory
dataset. This exercise is illustrated in the two figures immediately below.
Note that the memory dataset has a different shape from the previously
written dataset. Similarly, the selection in the memory dataset
could have a different shape than the selected union of hyperslabs in
the original file; for simplicity, we will preserve the selection's shape
in this example.
<p>
<center>
<b>Selection of a union of hyperslabs in a file dataset</b><br>
<TABLE BORDER CELLSPACING=1 CELLPADDING=7 WIDTH=460>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<B><CODE><P>53</B></CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>1</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>2</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>3</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>4</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>5</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>6</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>7</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>8</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>9</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#44FFFF">
<CODE><P>10</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#44FFFF"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#44FFFF">
<CODE><P>11</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#44FFFF">
<CODE><P>12</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>13</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>14</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>15</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>16</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>17</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#44FFFF">
<CODE><P>18</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#44FFFF"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#88FF88">
<CODE><P>19</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#88FF88">
<CODE><P>20</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>21</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44" border=1>
<CODE><P>22</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>23</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>24</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#44FFFF"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#44FFFF">
<B><CODE><P>59</B></CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#88FF88"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#88FF88">
<B><CODE><P>61</B></CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>25</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>26</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>27</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>28</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>29</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>30</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>31</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>32</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>33</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>34</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>35</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>36</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<B><CODE><P>67</B></CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>37</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>38</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>39</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>40</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>41</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>42</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>43</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>44</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>45</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>46</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>47</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1>
<CODE><P>48</CODE></TD>
</TR>
<TR><TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
</TR>
</TABLE>
<font size=-1><i>(Note: The above table highlights hyperslab selections
with green, blue, and yellow <br> shading. This shading may not
appear properly in black-and-white printed copies.)</i></font>
</center>
<p>
<center>
<b>Selection of a union of hyperslabs in a memory dataset</b><br>
<font size=-1>Blank cells in this figure actually contain values written
when the dataset was initialized.</font>
<TABLE BORDER CELLSPACING=1 CELLPADDING=7 WIDTH=345>
<TR>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#44FFFF">
<CODE><P>10</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#44FFFF"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#44FFFF">
<CODE><P>11</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#44FFFF">
<CODE><P>12</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
</TR>
<TR>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#44FFFF">
<CODE><P>18</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#44FFFF"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#88FF88">
<CODE><P>19</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#88FF88">
<CODE><P>20</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>21</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44" border=1>
<CODE><P>22</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
</TR>
<TR>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#44FFFF"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#44FFFF">
<B><CODE><P>59</B></CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#88FF88"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#88FF88">
<B><CODE><P>61</B></CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
</TR>
<TR>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>27</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>28</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>29</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>30</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
</TR>
<TR>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>35</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>36</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<B><CODE><P>67</B></CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>37</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>38</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
</TR>
<TR>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>43</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>44</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44"> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>45</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1 bgcolor="#FFFF44">
<CODE><P>46</CODE></TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
</TR>
<TR>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
</TR>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
<TD WIDTH="8%" VALIGN="TOP" HEIGHT=1> </TD>
</TR>
</TABLE>
<font size=-1><i>(Note: The above table highlights hyperslab selections
with green, blue, and yellow <br> shading. This shading may not
appear properly in black-and-white printed copies.)</i></font>
</center>
<p>
The following lines of code show the required steps.
<p>
First obtain the dataspace identifier for the dataset in the file.
<pre>
/*
* Get dataspace of the open dataset.
*/
fid = H5Dget_space(dataset);
</pre>
Then select the hyperslab with the size 3x4 and
the left upper corner at the position (1,2):
<pre>
/*
* Select first hyperslab for the dataset in the file. The following
* elements are selected:
* 10 0 11 12
* 18 0 19 20
* 0 59 0 61
*
*/
start[0] = 1; start[1] = 2;
block[0] = 1; block[1] = 1;
stride[0] = 1; stride[1] = 1;
count[0] = 3; count[1] = 4;
ret = H5Sselect_hyperslab(fid, H5S_SELECT_SET, start, stride, count, block);
</pre>
Now select the second hyperslab with the size 6x5 at the position (2,4),
and create the union with the first hyperslab.
<pre>
/*
* Add second selected hyperslab to the selection.
* The following elements are selected:
* 19 20 0 21 22
* 0 61 0 0 0
* 27 28 0 29 30
* 35 36 67 37 38
* 43 44 0 45 46
* 0 0 0 0 0
* Note that two hyperslabs overlap. Common elements are:
* 19 20
* 0 61
*/
start[0] = 2; start[1] = 4;
block[0] = 1; block[1] = 1;
stride[0] = 1; stride[1] = 1;
count[0] = 6; count[1] = 5;
ret = H5Sselect_hyperslab(fid, H5S_SELECT_OR, start, stride, count, block);
</pre>
Note that when we add the selected hyperslab to the union, the
second argument to the <code>H5Sselect_hyperslab</code> function
has to be <code>H5S_SELECT_OR</code> instead of <code>H5S_SELECT_SET</code>.
Using <code>H5S_SELECT_SET</code> would reset the selection to
the second hyperslab.
<p>
Now define the memory dataspace and select the union of the hyperslabs
in the memory dataset.
<pre>
/*
* Create memory dataspace.
*/
mid = H5Screate_simple(MSPACE_RANK, mdim, NULL);
/*
* Select two hyperslabs in memory. Hyperslabs has the same
* size and shape as the selected hyperslabs for the file dataspace.
*/
start[0] = 0; start[1] = 0;
block[0] = 1; block[1] = 1;
stride[0] = 1; stride[1] = 1;
count[0] = 3; count[1] = 4;
ret = H5Sselect_hyperslab(mid, H5S_SELECT_SET, start, stride, count, block);
start[0] = 1; start[1] = 2;
block[0] = 1; block[1] = 1;
stride[0] = 1; stride[1] = 1;
count[0] = 6; count[1] = 5;
ret = H5Sselect_hyperslab(mid, H5S_SELECT_OR, start, stride, count, block);
</pre>
Finally we can read the selected data from the file dataspace to the selection
in memory with one call to the <code>H5Dread</code> function.
<pre> ret = H5Dread(dataset, H5T_NATIVE_INT, mid, fid, H5P_DEFAULT, matrix_out);
</pre>
<P>
<A HREF="#WriteSelected">Example 3</a> includes this code along with
the previous selection example.
</FONT><h3><A NAME="Intro-PMCreateCompound">Creating compound datatypes</A></h3>
<B><P>Properties of compound datatypes. </B>A compound datatype is similar to a struct in C or a common block in Fortran. It is a collection of one or more atomic types or small arrays of such types. To create and use of a compound datatype you need to refer to various <i>properties</i> of the data compound datatype:
<UL>
<LI>It is of class <i>compound</i><I>.</I>
<LI>It has a fixed total <i>size</i>, in bytes.
<LI>It consists of zero or more <i>members</i> (defined in any order) with unique names and which occupy non-overlapping regions within the datum.
<LI>Each member has its own <i>datatype</i>.
<LI>Each member is referenced by an <i>index number</i> between zero and N-1, where N is the number of members in the compound datatype.
<LI>Each member has a <i>name</i> which is unique among its siblings in a compound datatype.
<LI>Each member has a fixed <i>byte offset</i>, which is the first byte (smallest byte address) of that member in a compound datatype.
<LI>Each member can be a small array of up to four dimensions.</UL>
<FONT FACE="Times"><P>Properties of members of a compound datatype are defined when the member is added to the compound type and cannot be subsequently modified.
<B><P>Defining compound datatypes. </B>Compound datatypes must be built out of other datatypes. First, one creates an empty compound datatype and specifies its total size. Then members are added to the compound datatype in any order.
<I><P>Member names. </I>Each member must have a descriptive name, which is the key used to uniquely identify the member within the compound datatype. A member name in an HDF5 datatype does not necessarily have to be the same as the name of the corresponding member in the C struct in memory, although this is often the case. Nor does one need to define all members of the C struct in the HDF5 compound datatype (or vice versa).
<I><P>Offsets. </I>Usually a C struct will be defined to hold a data point in memory, and the offsets of the members in memory will be the offsets of the struct members from the beginning of an instance of the struct. The library defines the macro to compute the offset of a member within a struct:
</FONT><CODE><br> HOFFSET(s,m)<FONT SIZE=5> </FONT></CODE>
<br><FONT FACE="Times">This macro computes the offset of member </FONT><FONT FACE="Courier"><EM>m</EM> </FONT><FONT FACE="Times">within a struct variable <EM>s</EM>.
<P>Here is an example in which a compound datatype is created to describe complex numbers whose type is defined by the </FONT><CODE>complex_t</CODE><FONT FACE="Times" SIZE=2> </FONT><FONT FACE="Times">struct.
</FONT><CODE><PRE>typedef struct {
double re; /*real part */
double im; /*imaginary part */
} complex_t;
complex_t tmp; /*used only to compute offsets */
hid_t complex_id = H5Tcreate (H5T_COMPOUND, sizeof tmp);
H5Tinsert (complex_id, "real", HOFFSET(tmp,re),
H5T_NATIVE_DOUBLE);
H5Tinsert (complex_id, "imaginary", HOFFSET(tmp,im),
H5T_NATIVE_DOUBLE);</PRE>
</CODE><P><A HREF="#Compound">Example 4</A><FONT FACE="Times"> shows how to create a compound datatype, write an array that has the compound datatype to the file, and read back subsets of the members.
</FONT><h3><A NAME="Intro-PMCreateExtendible">Creating and writing extendible and chunked datasets</A></h3>
<FONT FACE="Times"><P>An <I>extendible</I> dataset is one whose dimensions can grow. In HDF5, it is possible to define a dataset to have certain initial dimensions, then later to increase the size of any of the initial dimensions.
<P>For example, you can create and store the following 3x3 HDF5 dataset:
</FONT><PRE> 1 1 1
1 1 1
1 1 1 </PRE>
<FONT FACE="Times"><P>then later to extend this into a 10x3 dataset by adding 7 rows, such as this:
</FONT><PRE> 1 1 1
1 1 1
1 1 1
2 2 2
2 2 2
2 2 2
2 2 2
2 2 2
2 2 2
2 2 2</PRE>
<FONT FACE="Times"><P>then further extend it to a 10x5 dataset by adding two columns, such as this:
</FONT><PRE> 1 1 1 3 3
1 1 1 3 3
1 1 1 3 3
2 2 2 3 3
2 2 2 3 3
2 2 2 3 3
2 2 2 3 3
2 2 2 3 3
2 2 2 3 3
2 2 2 3 3</PRE>
<FONT FACE="Times"><P>HDF 5 requires you to use <I>chunking</I> in order to define extendible datasets. Chunking makes it possible to extend datasets efficiently, without having to reorganize storage excessively.
<P>The following operations are required in order to write an extendible dataset:
<OL>
<LI>Declare the dataspace of the dataset to have <I>unlimited dimensions</I> for all dimensions that might eventually be extended.
<LI>Set dataset creation properties to enable chunking and create a dataset.
<LI>Extend the size of the dataset.</OL>
<P>For example, suppose we wish to create a dataset similar to the one shown above. We want to start with a 3x3 dataset, then later extend it in both directions.
<B><P>Declaring unlimited dimensions. </B>We could declare the dataspace to have unlimited dimensions with the following code, which uses the predefined constant </FONT><CODE>H5S_UNLIMITED</CODE><FONT FACE="Times"> to specify unlimited dimensions.
</FONT><PRE>hsize_t dims[2] = { 3, 3}; /* dataset dimensions
at the creation time */
hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED};
/*
* Create the data space with unlimited dimensions.
*/
dataspace = H5Screate_simple(RANK, dims, maxdims); </PRE>
<B><P>Enabling chunking. </B>We can then set the dataset storage layout properties to enable chunking. We do this using the routine <CODE>H5Pset_chunk</CODE><FONT SIZE=4>:
</FONT><PRE>hid_t cparms;
hsize_t chunk_dims[2] ={2, 5};
/*
* Modify dataset creation properties to enable chunking.
*/
cparms = H5Pcreate (H5P_DATASET_CREATE);
status = H5Pset_chunk( cparms, RANK, chunk_dims);
</PRE>
Then create a dataset.
<pre>
/*
* Create a new dataset within the file using cparms
* creation properties.
*/
dataset = H5Dcreate(file, DATASETNAME, H5T_NATIVE_INT, dataspace,
cparms);
</pre>
<B><P>Extending dataset size. </B>Finally, when we want to extend the size of the dataset, we invoke <CODE>H5Dextend </CODE>to extend the size of the dataset. In the following example, we extend the dataset along the first dimension, by seven rows, so that the new dimensions are <CODE><10,3></CODE>:
<PRE>/*
* Extend the dataset. Dataset becomes 10 x 3.
*/
dims[0] = dims[0] + 7;
size[0] = dims[0];
size[1] = dims[1];
status = H5Dextend (dataset, size);</PRE>
<FONT FACE="Courier" SIZE=2><P>
</FONT><P><A HREF="#CreateExtendWrite">Example 5</A> shows how to create a 3x3 extendible dataset, write the dataset, extend the dataset to 10x3, write the dataset again, extend it again to 10x5, write the dataset again.
<P><A HREF="#ReadExtended">Example 6</A> shows how to read the data written by Example 5.
<h3><A NAME="Intro-PMWorkGroups">Working with groups in a file</A></h3>
<P>Groups provide a mechanism for organizing meaningful and extendible sets of datasets within an HDF5 file. The H5G API contains routines for working with groups.
<B><P>Creating a group. </B>To create a group, use
<CODE>H5Gcreate</CODE>. For example, the following code
creates a group called <code>Data</code> in the root group.
<pre>
/*
* Create a group in the file.
*/
grp = H5Gcreate(file, "/Data", 0);
</pre>
A group may be created in another group by providing the
absolute name of the group to the <code>H5Gcreate</code>
function or by specifying its location. For example,
to create the group <code>Data_new</code> in the
<code>Data</code> group, one can use the following sequence
of calls:
<pre>
/*
* Create group "Data_new" in the group "Data" by specifying
* absolute name of the group.
*/
grp_new = H5Gcreate(file, "/Data/Data_new", 0);
</pre>
or
<pre>
/*
* Create group "Data_new" in the "Data" group.
*/
grp_new = H5Gcreate(grp, "Data_new", 0);
</pre>
Note that the group identifier <code>grp</code> is used
as the first parameter in the <code>H5Gcreate</code> function
when the relative name is provided.
<p>
The third parameter in <code>H5Gcreate</code> optionally
specifies how much file space to reserve to store the names
that will appear in this group. If a non-positive
value is supplied, then a default size is chosen.
<p>
<code>H5Gclose</code> closes the group and releases the
group identifier.
<p>
<b>Creating a dataset in a particular group.</b>
As with groups, a dataset can be created in a particular
group by specifying its absolute name as illustrated in
the following example:
<pre>
/*
* Create the dataset "Compressed_Data" in the group using the
* absolute name. The dataset creation property list is modified
* to use GZIP compression with the compression effort set to 6.
* Note that compression can be used only when the dataset is
* chunked.
*/
dims[0] = 1000;
dims[1] = 20;
cdims[0] = 20;
cdims[1] = 20;
dataspace = H5Screate_simple(RANK, dims, NULL);
plist = H5Pcreate(H5P_DATASET_CREATE);
H5Pset_chunk(plist, 2, cdims);
H5Pset_deflate( plist, 6);
dataset = H5Dcreate(file, "/Data/Compressed_Data", H5T_NATIVE_INT,
dataspace, plist);
</pre>
A relative dataset name may also be used when a dataset is
created. First obtain the identifier of the group in which
the dataset is to be created. Then create the dataset
with <code>H5Dcreate</code> as illustrated in the following
example:
<pre>
/*
* Open the group.
*/
grp = H5Gopen(file, "Data");
/*
* Create the dataset "Compressed_Data" in the "Data" group
* by providing a group identifier and a relative dataset
* name as parameters to the H5Dcreate function.
*/
dataset = H5Dcreate(grp, "Compressed_Data", H5T_NATIVE_INT,
dataspace, plist);
</pre>
<p>
<b>Accessing an object in a group.</b>
Any object in a group can be accessed by its absolute or
relative name. The following lines of code show how to use
the absolute name to access the dataset
<code>Compressed_Data</code> in the group <code>Data</code>
created in the examples above:
<pre>
/*
* Open the dataset "Compressed_Data" in the "Data" group.
*/
dataset = H5Dopen(file, "/Data/Compressed_Data");
</pre>
The same dataset can be accessed in another manner. First
access the group to which the dataset belongs, then open
the dataset.
<pre>
/*
* Open the group "data" in the file.
*/
grp = H5Gopen(file, "Data");
/*
* Access the "Compressed_Data" dataset in the group.
*/
dataset = H5Dopen(grp, "Compressed_Data");
</pre>
<p>
<A HREF="#CreateGroups">Example 7</A> shows
how to create a group in a file and a
dataset in a group. It uses the iterator function
<code>H5Giterate</code> to find the names of the objects
in the root group, and <code>H5Glink</code> and <code>H5Gunlink</code>
to create a new group name and delete the original name.
<h3><A NAME="Intro-PMWorkAttributes">Working with attributes</A></h3>
<P>Think of an attribute as a small datasets that is attached to a normal dataset or group. The H5A API contains routines for working with attributes. Since attributes share many of the characteristics of datasets, the programming model for working with attributes is analogous in many ways to the model for working with datasets. The primary differences are that an attribute must be attached to a dataset or a group, and subsetting operations cannot be performed on attributes.
<B><P>To create an attribute </B>belonging to a particular dataset or group<B>, </B>first create a dataspace for the attribute with the call to <CODE>H5Screate</CODE>, then create the attribute using <CODE>H5Acreate</CODE>. For example, the following code creates an attribute called <CODE> Integer_attribute </CODE>that is a member of a dataset whose identifier is <CODE>dataset</CODE>. The attribute identifier is <CODE>attr2</CODE>.<CODE> H5Awrite</CODE> then sets the value of the attribute of that of the integer variable <CODE>point</code>. <code>H5Aclose</code> <FONT FACE="Times">then releases the attribute identifier.
</CODE>
</FONT>
<pre>
int point = 1; /* Value of the scalar attribute */
/*
* Create scalar attribute.
*/
aid2 = H5Screate(H5S_SCALAR);
attr2 = H5Acreate(dataset, "Integer attribute", H5T_NATIVE_INT, aid2,
H5P_DEFAULT);
/*
* Write scalar attribute.
*/
ret = H5Awrite(attr2, H5T_NATIVE_INT, &point);
/*
* Close attribute dataspace.
*/
ret = H5Sclose(aid2);
/*
* Close attribute.
*/
ret = H5Aclose(attr2);
</pre>
<CODE><P>
</CODE><B><P>To read a scalar attribute whose name and datatype are known</B>, first open the attribute using <CODE>H5Aopen_name</CODE>, then use H5Aread to get its value. For example the following reads a scalar attribute called <CODE>Integer_attribute</CODE> whose datatype is a native integer, and whose parent dataset has the identifier <CODE>dataset</CODE>.
<pre>
/*
* Attach to the scalar attribute using attribute name, then read and
* display its value.
*/
attr = H5Aopen_name(dataset,"Integer attribute");
ret = H5Aread(attr, H5T_NATIVE_INT, &point_out);
printf("The value of the attribute \"Integer attribute\" is %d \n", point_out);
ret = H5Aclose(attr);
</pre>
</FONT><B><P>Reading an attribute whose characteristics are not known. </B>It may be necessary to query a<FONT FACE="Times"> file to obtain information about an attribute, namely its name, datatype, rank and dimensions. The following code opens an attribute by its index value using </FONT><CODE>H5Aopen_index</CODE><FONT FACE="Times">, then reads in information about its datatype.
</FONT>
<pre>
/*
* Attach to the string attribute using its index, then read and display the value.
*/
attr = H5Aopen_idx(dataset, 2);
atype = H5Tcopy(H5T_C_S1);
H5Tset_size(atype, 4);
ret = H5Aread(attr, atype, string_out);
printf("The value of the attribute with the index 2 is %s \n", string_out);
</pre>
<code>
</CODE><P>In practice, if the characteristics of attributes are not known,
the code involved in accessing and processing the attribute can be quite
complex. For this reason, HDF5 includes a function called
<CODE>H5Aiterate</CODE>, which applies a user-supplied function to each
of a set of attributes. The user-supplied function can contain the code
that interprets, accesses and processes each attribute.
<p>
<a href="#ReadWriteAttributes">Example 8</a> <A NAME="_Toc429885323">illustrates the use of the <code>H5Aiterate</code> function, as well as the other attribute examples described above.</A>
<h3><A NAME="Intro-PMWorkRefObjects">Working with references to objects</A></h3>
In HDF5, objects (i.e. groups, datasets, and named datatypes) are usually
accessed by name. This access method was discussed in previous sections.
There is another way to access stored objects -- by reference.
<P>
An object reference is based on the relative file address of the object header
in the file and is constant for the life of the object. Once a reference to
an object is created and stored in a dataset in the file, it can be used
to dereference the object it points to. References are handy for creating
a file index or for grouping related objects by storing references to them in
one dataset.
<P>
<h5>Creating and Storing References to Objects</h5>
The following steps are involved in creating and storing file references
to objects:
<OL>
<LI> Create the objects or open them if they already exist in the file.
<LI> Create a dataset to store the objects' references.
<LI> Create and store references to the objects in a buffer.
<LI> Write a buffer with the references to the dataset.
</OL>
<h5> Programming Example</h5>
<b>Description:</b>
The example below [also <a href="#CreateWriteRefObj">Example 9</a>]
creates a group and two datasets and a named datatype in the group.
References to these four objects are stored in the dataset in the
root group.
<PRE>
#include <hdf5.h>
#define FILE1 "trefer1.h5"
/* 1-D dataset with fixed dimensions */
#define SPACE1_NAME "Space1"
#define SPACE1_RANK 1
#define SPACE1_DIM1 4
/* 2-D dataset with fixed dimensions */
#define SPACE2_NAME "Space2"
#define SPACE2_RANK 2
#define SPACE2_DIM1 10
#define SPACE2_DIM2 10
int
main(void) {
hid_t fid1; /* HDF5 File IDs */
hid_t dataset; /* Dataset ID */
hid_t group; /* Group ID */
hid_t sid1; /* Dataspace ID */
hid_t tid1; /* Datatype ID */
hsize_t dims1[] = {SPACE1_DIM1};
hobj_ref_t *wbuf; /* buffer to write to disk */
int *tu32; /* Temporary pointer to int data */
int i; /* counting variables */
const char *write_comment="Foo!"; /* Comments for group */
herr_t ret; /* Generic return value */
/* Compound datatype */
typedef struct s1_t {
unsigned int a;
unsigned int b;
float c;
} s1_t;
/* Allocate write buffers */
wbuf=(hobj_ref_t *)malloc(sizeof(hobj_ref_t)*SPACE1_DIM1);
tu32=malloc(sizeof(int)*SPACE1_DIM1);
/* Create file */
fid1 = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create dataspace for datasets */
sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
/* Create a group */
group=H5Gcreate(fid1,"Group1",-1);
/* Set group's comment */
ret=H5Gset_comment(group,".",write_comment);
/* Create a dataset (inside Group1) */
dataset=H5Dcreate(group,"Dataset1",H5T_STD_U32LE,sid1,H5P_DEFAULT);
for(i=0; i < SPACE1_DIM1; i++)
tu32[i] = i*3;
/* Write selection to disk */
ret=H5Dwrite(dataset,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,tu32);
/* Close Dataset */
ret = H5Dclose(dataset);
/* Create another dataset (inside Group1) */
dataset=H5Dcreate(group,"Dataset2",H5T_NATIVE_UCHAR,sid1,H5P_DEFAULT);
/* Close Dataset */
ret = H5Dclose(dataset);
/* Create a datatype to refer to */
tid1 = H5Tcreate (H5T_COMPOUND, sizeof(s1_t));
/* Insert fields */
ret=H5Tinsert (tid1, "a", HOFFSET(s1_t,a), H5T_NATIVE_INT);
ret=H5Tinsert (tid1, "b", HOFFSET(s1_t,b), H5T_NATIVE_INT);
ret=H5Tinsert (tid1, "c", HOFFSET(s1_t,c), H5T_NATIVE_FLOAT);
/* Save datatype for later */
ret=H5Tcommit (group, "Datatype1", tid1);
/* Close datatype */
ret = H5Tclose(tid1);
/* Close group */
ret = H5Gclose(group);
/* Create a dataset to store references */
dataset=H5Dcreate(fid1,"Dataset3",H5T_STD_REF_OBJ,sid1,H5P_DEFAULT);
/* Create reference to dataset */
ret = H5Rcreate(&wbuf[0],fid1,"/Group1/Dataset1",H5R_OBJECT,-1);
/* Create reference to dataset */
ret = H5Rcreate(&wbuf[1],fid1,"/Group1/Dataset2",H5R_OBJECT,-1);
/* Create reference to group */
ret = H5Rcreate(&wbuf[2],fid1,"/Group1",H5R_OBJECT,-1);
/* Create reference to named datatype */
ret = H5Rcreate(&wbuf[3],fid1,"/Group1/Datatype1",H5R_OBJECT,-1);
/* Write selection to disk */
ret=H5Dwrite(dataset,H5T_STD_REF_OBJ,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf);
/* Close disk dataspace */
ret = H5Sclose(sid1);
/* Close Dataset */
ret = H5Dclose(dataset);
/* Close file */
ret = H5Fclose(fid1);
free(wbuf);
free(tu32);
return 0;
}
</PRE>
<b>Remarks:</b>
<UL>
<LI> The following code,
<PRE>
dataset = H5Dcreate ( fid1,"Dataset3",H5T_STD_REF_OBJ,sid1,H5P_DEFAULT );
</PRE>
creates a dataset to store references. Notice that the
<code>H5T_SDT_REF_OBJ</code> datatype is used to specify that
references to objects will be stored.
The datatype <code>H5T_STD_REF_DSETREG</code> is used to store the
dataset region references and is be discussed later.
<LI>The next few calls to the <code>H5Rcreate</code> function create
references to the objects and store them in the buffer <I>wbuf</I>.
The signature of the <code>H5Rcreate</code> function is:
<PRE>
herr_t H5Rcreate ( void* buf, hid_t loc_id, const char *name,
H5R_type_t ref_type, hid_t space_id )
</PRE>
<UL>
<LI> The first argument specifies the buffer to store the reference.
<LI> The second and third arguments specify the name of the referenced
object. In the example, the file identifier <I>fid1</I> and
absolute name of the dataset <code>/Group1/Dataset1</code>
identify the dataset. One could also use the group identifier
of group <code>Group1</code> and the relative name of the dataset
<code>Dataset1</code> to create the same reference.
<LI> The fourth argument specifies the type of the reference.
The example uses references to the objects (<code>H5R_OBJECT</code>).
Another type of reference, reference to the dataset region
(<code>H5R_DATASET_REGION</code>), is discussed later.
<LI> The fifth argument specifies the space identifier. When references
to the objects are created, it should be set to <code>-1</code>.
</UL>
<LI>The <code>H5Dwrite</code> function writes a dataset with the
references to the file. Notice that the <code>H5T_SDT_REF_OBJ</code>
datatype is used to describe the dataset's memory datatype.
</UL>
<b>File Contents:</b>
The contents of the <code>trefer1.h5</code> file created by this example
are as follows:
<PRE>
HDF5 "trefer1.h5" {
GROUP "/" {
DATASET "Dataset3" {
DATATYPE { H5T_REFERENCE }
DATASPACE { SIMPLE ( 4 ) / ( 4 ) }
DATA {
DATASET 0:1696, DATASET 0:2152, GROUP 0:1320, DATATYPE 0:2268
}
}
GROUP "Group1" {
DATASET "Dataset1" {
DATATYPE { H5T_STD_U32LE }
DATASPACE { SIMPLE ( 4 ) / ( 4 ) }
DATA {
0, 3, 6, 9
}
}
DATASET "Dataset2" {
DATATYPE { H5T_STD_U8LE }
DATASPACE { SIMPLE ( 4 ) / ( 4 ) }
DATA {
0, 0, 0, 0
}
}
DATATYPE "Datatype1" {
H5T_STD_I32BE "a";
H5T_STD_I32BE "b";
H5T_IEEE_F32BE "c";
}
}
}
}
</PRE>
Notice how the data in dataset <code>Dataset3</code> is described.
The two numbers with the colon in between represent a unique identifier
of the object. These numbers are constant for the life of the object.
<h5>Reading References and Accessing Objects Using References</h5>
The following steps are involved:
<OL>
<LI> Open the dataset with the references and read them.
The <code>H5T_STD_REF_OBJ</code> datatype must be used to
describe the memory datatype.
<LI> Use the read reference to obtain the identifier of the object the
reference points to.
<LI> Open the dereferenced object and perform the desired operations.
<LI> Close all objects when the task is complete.
</OL>
<h5>Programming Example</h5>
<b>Description:</b>
The following example [also <a href="#ReadRefObj">Example 10</a>]
below opens and reads dataset <code>Dataset3</code> from
the file created previously. Then the program dereferences the references
to dataset <code>Dataset1</code>, the group and the named datatype,
and opens those objects.
The program reads and displays the dataset's data, the group's comment, and
the number of members of the compound datatype.
<PRE>
#include <stdlib.h>
#include <hdf5.h>
#define FILE1 "trefer1.h5"
/* dataset with fixed dimensions */
#define SPACE1_NAME "Space1"
#define SPACE1_RANK 1
#define SPACE1_DIM1 4
int
main(void)
{
hid_t fid1; /* HDF5 File IDs */
hid_t dataset, /* Dataset ID */
dset2; /* Dereferenced dataset ID */
hid_t group; /* Group ID */
hid_t sid1; /* Dataspace ID */
hid_t tid1; /* Datatype ID */
hobj_ref_t *rbuf; /* buffer to read from disk */
int *tu32; /* temp. buffer read from disk */
int i; /* counting variables */
char read_comment[10];
herr_t ret; /* Generic return value */
/* Allocate read buffers */
rbuf = malloc(sizeof(hobj_ref_t)*SPACE1_DIM1);
tu32 = malloc(sizeof(int)*SPACE1_DIM1);
/* Open the file */
fid1 = H5Fopen(FILE1, H5F_ACC_RDWR, H5P_DEFAULT);
/* Open the dataset */
dataset=H5Dopen(fid1,"/Dataset3");
/* Read selection from disk */
ret=H5Dread(dataset,H5T_STD_REF_OBJ,H5S_ALL,H5S_ALL,H5P_DEFAULT,rbuf);
/* Open dataset object */
dset2 = H5Rdereference(dataset,H5R_OBJECT,&rbuf[0]);
/* Check information in referenced dataset */
sid1 = H5Dget_space(dset2);
ret=H5Sget_simple_extent_npoints(sid1);
/* Read from disk */
ret=H5Dread(dset2,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,tu32);
printf("Dataset data : \n");
for (i=0; i < SPACE1_DIM1 ; i++) printf (" %d ", tu32[i]);
printf("\n");
printf("\n");
/* Close dereferenced Dataset */
ret = H5Dclose(dset2);
/* Open group object */
group = H5Rdereference(dataset,H5R_OBJECT,&rbuf[2]);
/* Get group's comment */
ret=H5Gget_comment(group,".",10,read_comment);
printf("Group comment is %s \n", read_comment);
printf(" \n");
/* Close group */
ret = H5Gclose(group);
/* Open datatype object */
tid1 = H5Rdereference(dataset,H5R_OBJECT,&rbuf[3]);
/* Verify correct datatype */
{
H5T_class_t tclass;
tclass= H5Tget_class(tid1);
if ((tclass == H5T_COMPOUND))
printf ("Number of compound datatype members is %d \n", H5Tget_nmembers(tid1));
printf(" \n");
}
/* Close datatype */
ret = H5Tclose(tid1);
/* Close Dataset */
ret = H5Dclose(dataset);
/* Close file */
ret = H5Fclose(fid1);
/* Free memory buffers */
free(rbuf);
free(tu32);
return 0;
}
</PRE>
The output of this program is as follows:
<PRE>
Dataset data :
0 3 6 9
Group comment is Foo!
Number of compound datatype members is 3
</PRE>
<b>Remarks:</b>
<UL>
<LI> The <code>H5Dread</code> function was used to read dataset
<code>Dataset3</code> containing the references to the objects.
The <code>H5T_STD_REF_OBJ</code> memory datatype was
used to read references to memory.
<LI> <code>H5Rdereference</code> obtains the object's identifier.
The signature of this function is:
<PRE>
hid_t H5Rdereference (hid_t datatset, H5R_type_t ref_type, void *ref)
</PRE>
<UL>
<LI> The first argument is an identifier of the dataset with the
references.
<LI> The second argument specifies the reference type.
<code>H5R_OBJECT</code> was used to specify a reference to an
object. Another type, used to specifiy a reference to a dataset
region and discussed later, is <code>H5R_DATASET_REGION</code>.
<LI> The third argument is a buffer to store the reference to be read.
<LI> The function returns an identifier of the object the reference
points to. In this simplified situation, the type that was
stored in the dataset is known. When the type of the object is
unknown, <code>H5Rget_object_type</code> should be used to
identify the type of object the reference points to.
</UL>
</UL>
<h3><A NAME="Intro-PMWorkRefRegions">Working with references to dataset regions</A></h3>
A dataset region reference points to the dataset selection by storing the
relative file address of the dataset header and the global heap offset of
the referenced selection. The selection referenced is located by retrieving
the coordinates of the areas in the selection from the global heap. This
internal mechanism of storing and retrieving dataset selections is transparent
to the user. A reference to the dataset selection (region) is constant for
the life of the dataset.
<H5>Creating and Storing References to Dataset Regions</H5>
The following steps are involved in creating and storing references to
the dataset regions:
<OL>
<LI> Create a dataset to store the dataset regions (selections).
<P>
<LI> Create selections in the dataset(s). Dataset(s) should already exist
in the file.
<P>
<LI> Create references to the selections and store them in a buffer.
<P>
<LI> Write references to the dataset regions in the file.
<P>
<LI> Close all objects.
</OL>
<H5> Programming Example</H5>
<B>Description:</B>
The example below [also <a href="#CreateWriteRefReg">Example 11</a>]
creates a dataset in the file. Then it creates a dataset to store
references to the dataset regions (selections).
The first selection is a 6 x 6 hyperslab.
The second selection is a point selection in the same dataset.
References to both selections are created and stored in the buffer,
and then written to the dataset in the file.
<PRE>
#include <stdlib.h>
#include <hdf5.h>
#define FILE2 "trefer2.h5"
#define SPACE1_NAME "Space1"
#define SPACE1_RANK 1
#define SPACE1_DIM1 4
/* Dataset with fixed dimensions */
#define SPACE2_NAME "Space2"
#define SPACE2_RANK 2
#define SPACE2_DIM1 10
#define SPACE2_DIM2 10
/* Element selection information */
#define POINT1_NPOINTS 10
int
main(void)
{
hid_t fid1; /* HDF5 File IDs */
hid_t dset1, /* Dataset ID */
dset2; /* Dereferenced dataset ID */
hid_t sid1, /* Dataspace ID #1 */
sid2; /* Dataspace ID #2 */
hsize_t dims1[] = {SPACE1_DIM1},
dims2[] = {SPACE2_DIM1, SPACE2_DIM2};
hssize_t start[SPACE2_RANK]; /* Starting location of hyperslab */
hsize_t stride[SPACE2_RANK]; /* Stride of hyperslab */
hsize_t count[SPACE2_RANK]; /* Element count of hyperslab */
hsize_t block[SPACE2_RANK]; /* Block size of hyperslab */
hssize_t coord1[POINT1_NPOINTS][SPACE2_RANK];
/* Coordinates for point selection */
hdset_reg_ref_t *wbuf; /* buffer to write to disk */
int *dwbuf; /* Buffer for writing numeric data to disk */
int i; /* counting variables */
herr_t ret; /* Generic return value */
/* Allocate write & read buffers */
wbuf=calloc(sizeof(hdset_reg_ref_t), SPACE1_DIM1);
dwbuf=malloc(sizeof(int)*SPACE2_DIM1*SPACE2_DIM2);
/* Create file */
fid1 = H5Fcreate(FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create dataspace for datasets */
sid2 = H5Screate_simple(SPACE2_RANK, dims2, NULL);
/* Create a dataset */
dset2=H5Dcreate(fid1,"Dataset2",H5T_STD_U8LE,sid2,H5P_DEFAULT);
for(i=0; i < SPACE2_DIM1*SPACE2_DIM2; i++)
dwbuf[i]=i*3;
/* Write selection to disk */
ret=H5Dwrite(dset2,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,dwbuf);
/* Close Dataset */
ret = H5Dclose(dset2);
/* Create dataspace for the reference dataset */
sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
/* Create a dataset */
dset1=H5Dcreate(fid1,"Dataset1",H5T_STD_REF_DSETREG,sid1,H5P_DEFAULT);
/* Create references */
/* Select 6x6 hyperslab for first reference */
start[0]=2; start[1]=2;
stride[0]=1; stride[1]=1;
count[0]=6; count[1]=6;
block[0]=1; block[1]=1;
ret = H5Sselect_hyperslab(sid2,H5S_SELECT_SET,start,stride,count,block);
/* Store first dataset region */
ret = H5Rcreate(&wbuf[0],fid1,"/Dataset2",H5R_DATASET_REGION,sid2);
/* Select sequence of ten points for second reference */
coord1[0][0]=6; coord1[0][1]=9;
coord1[1][0]=2; coord1[1][1]=2;
coord1[2][0]=8; coord1[2][1]=4;
coord1[3][0]=1; coord1[3][1]=6;
coord1[4][0]=2; coord1[4][1]=8;
coord1[5][0]=3; coord1[5][1]=2;
coord1[6][0]=0; coord1[6][1]=4;
coord1[7][0]=9; coord1[7][1]=0;
coord1[8][0]=7; coord1[8][1]=1;
coord1[9][0]=3; coord1[9][1]=3;
ret = H5Sselect_elements(sid2,H5S_SELECT_SET,POINT1_NPOINTS,(const hssize_t **)coord1);
/* Store second dataset region */
ret = H5Rcreate(&wbuf[1],fid1,"/Dataset2",H5R_DATASET_REGION,sid2);
/* Write selection to disk */
ret=H5Dwrite(dset1,H5T_STD_REF_DSETREG,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf);
/* Close all objects */
ret = H5Sclose(sid1);
ret = H5Dclose(dset1);
ret = H5Sclose(sid2);
/* Close file */
ret = H5Fclose(fid1);
free(wbuf);
free(dwbuf);
return 0;
}
</PRE>
<b>Remarks:</b>
<UL>
<LI> The code,
<PRE>
dset1=H5Dcreate(fid1,"Dataset1",H5T_STD_REF_DSETREG,sid1,H5P_DEFAULT);
</PRE>
creates a dataset to store references to the dataset(s) regions (selections).
Notice that the <code>H5T_STD_REF_DSETREG</code> datatype is used.
<LI> This program uses hyperslab and point selections. The dataspace
handle <I>sid2</I> is used for the calls to <code>H5Sselect_hyperslab</code>
and <code>H5Sselect_elements</code>. The handle was created when dataset
<code><b>Dataset2</b></code> was created and it describes the dataset's
dataspace. It was not closed when the dataset was closed to decrease
the number of function calls used in the example.
In a real application program, one should open the dataset and determine
its dataspace using the <code>H5Dget_space</code> function.
<LI> <code>H5Rcreate</code> is used to create a dataset region reference
and store it in a buffer. The signature of the function is:
<PRE>
herr_t H5Rcreate(void *buf, hid_t loc_id, const char *name,
H5R_type_t ref_type, hid_t space_id)
</PRE>
<UL>
<LI> The first argument specifies the buffer to store the reference.
<LI> The second and third arguments specify the name of the referenced
dataset. In the example, the file identifier <I>fid1</I> and the
absolute name of the dataset <code><b>/Dataset2</b></code> were
used to identify the dataset. The reference to the region of this
dataset is stored in the buffer <I>buf</I>.
<LI> The fourth argument specifies the type of the reference. Since
the example creates references to the dataset regions, the
<code>H5R_DATASET_REGION</code> datatype is used.
<LI> The fifth argument is a dataspace identifier of the referenced
dataset.
</UL>
</UL>
<b>File Contents:</b>
The contents of the file <code>trefer2.h5</code> created by this program
are as follows:
<PRE>
HDF5 "trefer2.h5" {
GROUP "/" {
DATASET "Dataset1" {
DATATYPE { H5T_REFERENCE }
DATASPACE { SIMPLE ( 4 ) / ( 4 ) }
DATA {
DATASET 0:744 {(2,2)-(7,7)}, DATASET 0:744 {(6,9), (2,2), (8,4), (1,6),
(2,8), (3,2), (0,4), (9,0), (7,1), (3,3)}, NULL, NULL
}
}
DATASET "Dataset2" {
DATATYPE { H5T_STD_U8LE }
DATASPACE { SIMPLE ( 10, 10 ) / ( 10, 10 ) }
DATA {
0, 3, 6, 9, 12, 15, 18, 21, 24, 27,
30, 33, 36, 39, 42, 45, 48, 51, 54, 57,
60, 63, 66, 69, 72, 75, 78, 81, 84, 87,
90, 93, 96, 99, 102, 105, 108, 111, 114, 117,
120, 123, 126, 129, 132, 135, 138, 141, 144, 147,
150, 153, 156, 159, 162, 165, 168, 171, 174, 177,
180, 183, 186, 189, 192, 195, 198, 201, 204, 207,
210, 213, 216, 219, 222, 225, 228, 231, 234, 237,
240, 243, 246, 249, 252, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255
}
}
}
}
</PRE>
Notice how raw data of the dataset with the dataset regions is displayed.
Each element of the raw data consists of a reference to the dataset
(<code>DATASET number1:number2</code>) and its selected region.
If the selection is a hyperslab, the corner coordinates of the hyperslab
are displayed.
For the point selection, the coordinates of each point are displayed.
Since only two selections were stored, the third and fourth elements of the
dataset <code>Dataset1</code> are set to <code>NULL</code>.
This was done by the buffer inizialization in the program.
<H5>Reading references to dataset regions</H5>
The following steps are involved in reading references to dataset
regions and referenced dataset regions (selections).
<OL>
<LI> Open and read the dataset containing references to the dataset regions.
The datatype <code>H5T_STD_REF_DSETREG</code> must be used during
read operation.
<LI>Use <code>H5Rdereference</code> to obtain the dataset identifier
from the read dataset region reference.
<PRE> <B>OR</B>
</PRE>
Use <code>H5Rget_region</code> to obtain the dataspace identifier for
the dataset containing the selection from the read dataset region reference.
<LI> With the dataspace identifier, the H5S interface functions,
<code>H5Sget_select_</code>*, can be used to obtain information
about the selection.
<LI> Close all objects when they are no longer needed.
</OL>
<H5>Programming Example</H5>
<b>Description:</b>
The following example [also <a href="#ReadRefReg">Example 12</a>]
reads a dataset containing dataset region references.
It reads data from the dereferenced dataset and displays the number of
elements and raw data. Then it reads two selections:
a hyperslab selection and a point selection. The program queries a
number of points in the hyperslab and the coordinates and displays them.
Then it queries a number of selected points and their coordinates and
displays the information.
<PRE>
#include <stdlib.h>
#include <hdf5.h>
#define FILE2 "trefer2.h5"
#define NPOINTS 10
/* 1-D dataset with fixed dimensions */
#define SPACE1_NAME "Space1"
#define SPACE1_RANK 1
#define SPACE1_DIM1 4
/* 2-D dataset with fixed dimensions */
#define SPACE2_NAME "Space2"
#define SPACE2_RANK 2
#define SPACE2_DIM1 10
#define SPACE2_DIM2 10
int
main(void)
{
hid_t fid1; /* HDF5 File IDs */
hid_t dset1, /* Dataset ID */
dset2; /* Dereferenced dataset ID */
hid_t sid1, /* Dataspace ID #1 */
sid2; /* Dataspace ID #2 */
hsize_t * coords; /* Coordinate buffer */
hsize_t low[SPACE2_RANK]; /* Selection bounds */
hsize_t high[SPACE2_RANK]; /* Selection bounds */
hdset_reg_ref_t *rbuf; /* buffer to to read disk */
int *drbuf; /* Buffer for reading numeric data from disk */
int i, j; /* counting variables */
herr_t ret; /* Generic return value */
/* Output message about test being performed */
/* Allocate write & read buffers */
rbuf=malloc(sizeof(hdset_reg_ref_t)*SPACE1_DIM1);
drbuf=calloc(sizeof(int),SPACE2_DIM1*SPACE2_DIM2);
/* Open the file */
fid1 = H5Fopen(FILE2, H5F_ACC_RDWR, H5P_DEFAULT);
/* Open the dataset */
dset1=H5Dopen(fid1,"/Dataset1");
/* Read selection from disk */
ret=H5Dread(dset1,H5T_STD_REF_DSETREG,H5S_ALL,H5S_ALL,H5P_DEFAULT,rbuf);
/* Try to open objects */
dset2 = H5Rdereference(dset1,H5R_DATASET_REGION,&rbuf[0]);
/* Check information in referenced dataset */
sid1 = H5Dget_space(dset2);
ret=H5Sget_simple_extent_npoints(sid1);
printf(" Number of elements in the dataset is : %d\n",ret);
/* Read from disk */
ret=H5Dread(dset2,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,drbuf);
for(i=0; i < SPACE2_DIM1; i++) {
for (j=0; j < SPACE2_DIM2; j++) printf (" %d ", drbuf[i*SPACE2_DIM2+j]);
printf("\n"); }
/* Get the hyperslab selection */
sid2=H5Rget_region(dset1,H5R_DATASET_REGION,&rbuf[0]);
/* Verify correct hyperslab selected */
ret = H5Sget_select_npoints(sid2);
printf(" Number of elements in the hyperslab is : %d \n", ret);
ret = H5Sget_select_hyper_nblocks(sid2);
coords=malloc(ret*SPACE2_RANK*sizeof(hsize_t)*2); /* allocate space for the hyperslab blocks */
ret = H5Sget_select_hyper_blocklist(sid2,0,ret,coords);
printf(" Hyperslab coordinates are : \n");
printf (" ( %lu , %lu ) ( %lu , %lu ) \n", \
(unsigned long)coords[0],(unsigned long)coords[1],(unsigned long)coords[2],(unsigned long)coords[3]);
free(coords);
ret = H5Sget_select_bounds(sid2,low,high);
/* Close region space */
ret = H5Sclose(sid2);
/* Get the element selection */
sid2=H5Rget_region(dset1,H5R_DATASET_REGION,&rbuf[1]);
/* Verify correct elements selected */
ret = H5Sget_select_elem_npoints(sid2);
printf(" Number of selected elements is : %d\n", ret);
/* Allocate space for the element points */
coords= malloc(ret*SPACE2_RANK*sizeof(hsize_t));
ret = H5Sget_select_elem_pointlist(sid2,0,ret,coords);
printf(" Coordinates of selected elements are : \n");
for (i=0; i < 2*NPOINTS; i=i+2)
printf(" ( %lu , %lu ) \n", (unsigned long)coords[i],(unsigned long)coords[i+1]);
free(coords);
ret = H5Sget_select_bounds(sid2,low,high);
/* Close region space */
ret = H5Sclose(sid2);
/* Close first space */
ret = H5Sclose(sid1);
/* Close dereferenced Dataset */
ret = H5Dclose(dset2);
/* Close Dataset */
ret = H5Dclose(dset1);
/* Close file */
ret = H5Fclose(fid1);
/* Free memory buffers */
free(rbuf);
free(drbuf);
return 0;
}
</PRE>
<p>
The output of this program is :
<PRE>
Number of elements in the dataset is : 100
0 3 6 9 12 15 18 21 24 27
30 33 36 39 42 45 48 51 54 57
60 63 66 69 72 75 78 81 84 87
90 93 96 99 102 105 108 111 114 117
120 123 126 129 132 135 138 141 144 147
150 153 156 159 162 165 168 171 174 177
180 183 186 189 192 195 198 201 204 207
210 213 216 219 222 225 228 231 234 237
240 243 246 249 252 255 255 255 255 255
255 255 255 255 255 255 255 255 255 255
Number of elements in the hyperslab is : 36
Hyperslab coordinates are :
( 2 , 2 ) ( 7 , 7 )
Number of selected elements is : 10
Coordinates of selected elements are :
( 6 , 9 )
( 2 , 2 )
( 8 , 4 )
( 1 , 6 )
( 2 , 8 )
( 3 , 2 )
( 0 , 4 )
( 9 , 0 )
( 7 , 1 )
( 3 , 3 )
</PRE>
<b>Remarks:</b>
<UL>
<LI> The dataset with the region references was read by <code>H5Dread</code>
with the <code>H5T_STD_REF_DSETREG</code> datatype specified.
<LI> The read reference can be used to obtain the dataset identifier
with the following call:
<PRE>
dset2 = H5Rdereference (dset1,H5R_DATASET_REGION,&rbuf[0]);
</PRE>
or to obtain spacial information (dataspace and selection) with the call
to <code>H5Rget_region</code>:
<PRE>
sid2=H5Rget_region(dset1,H5R_DATASET_REGION,&rbuf[0]);
</PRE>
The reference to the dataset region has information for both the dataset
itself and its selection. In both functions:
<UL>
<LI> The first parameter is an identifier of the dataset with the
region references.
<LI> The second parameter specifies the type of reference stored.
In this example, a reference to the dataset region is stored.
<LI> The third parameter is a buffer containing the reference of the
specified type.
</UL>
<LI> This example introduces several <code>H5Sget_select</code>*
functions used to obtain information about selections:
<UL>
<code>H5Sget_select_npoints:</code> returns the number of elements in
the hyperslab<BR>
<code>H5Sget_select_hyper_nblocks:</code> returns the number of blocks
in the hyperslab<BR>
<code>H5Sget_select_blocklist:</code> returns the "lower left" and
"upper right" coordinates of the blocks in the hyperslab selection<BR>
<code>H5Sget_select_bounds:</code> returns the coordinates of the
"minimal" block containing a hyperslab selection<BR>
<code>H5Sget_select_elem_npoints:</code> returns the number of points
in the element selection<BR>
<code>H5Sget_select_elem_points:</code> returns the coordinates of
the element selection
</UL>
</UL>
<p align=right><font size=-1><a href="#Intro-TOC">(Return to TOC)</a></font>
<hr>
<H2><A NAME="Intro-Examples">4. Example Codes</A></H2>
<H4><A NAME="CreateExample">Example 1: How to create a homogeneous multi-dimensional dataset</A> and write it to a file.</A></H4>
<P>This example creates a 2-dimensional HDF 5 dataset of little endian 32-bit integers.
<PRE>
<!-- Insert Example 1, h5_write.c, here. -->
/*
* This example writes data to the HDF5 file.
* Data conversion is performed during write operation.
*/
#include <hdf5.h>
#define FILE "SDS.h5"
#define DATASETNAME "IntArray"
#define NX 5 /* dataset dimensions */
#define NY 6
#define RANK 2
int
main (void)
{
hid_t file, dataset; /* file and dataset handles */
hid_t datatype, dataspace; /* handles */
hsize_t dimsf[2]; /* dataset dimensions */
herr_t status;
int data[NX][NY]; /* data to write */
int i, j;
/*
* Data and output buffer initialization.
*/
for (j = 0; j < NX; j++) {
for (i = 0; i < NY; i++)
data[j][i] = i + j;
}
/*
* 0 1 2 3 4 5
* 1 2 3 4 5 6
* 2 3 4 5 6 7
* 3 4 5 6 7 8
* 4 5 6 7 8 9
*/
/*
* Create a new file using H5F_ACC_TRUNC access,
* default file creation properties, and default file
* access properties.
*/
file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/*
* Describe the size of the array and create the data space for fixed
* size dataset.
*/
dimsf[0] = NX;
dimsf[1] = NY;
dataspace = H5Screate_simple(RANK, dimsf, NULL);
/*
* Define datatype for the data in the file.
* We will store little endian INT numbers.
*/
datatype = H5Tcopy(H5T_NATIVE_INT);
status = H5Tset_order(datatype, H5T_ORDER_LE);
/*
* Create a new dataset within the file using defined dataspace and
* datatype and default dataset creation properties.
*/
dataset = H5Dcreate(file, DATASETNAME, datatype, dataspace,
H5P_DEFAULT);
/*
* Write the data to the dataset using default transfer properties.
*/
status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
H5P_DEFAULT, data);
/*
* Close/release resources.
*/
H5Sclose(dataspace);
H5Tclose(datatype);
H5Dclose(dataset);
H5Fclose(file);
return 0;
}
</pre>
<A NAME="CheckAndReadExample"> </a>
<H4><A NAME="_Toc429885326">Example 2.</A> How to read a hyperslab from file into memory.</A></H4>
<P>This example reads a hyperslab from a 2-d HDF5 dataset into a 3-d dataset in memory.
<PRE>
<!-- Insert Example 2, h5_read.c, here. -->
/*
* This example reads hyperslab from the SDS.h5 file
* created by h5_write.c program into two-dimensional
* plane of the three-dimensional array.
* Information about dataset in the SDS.h5 file is obtained.
*/
#include "hdf5.h"
#define FILE "SDS.h5"
#define DATASETNAME "IntArray"
#define NX_SUB 3 /* hyperslab dimensions */
#define NY_SUB 4
#define NX 7 /* output buffer dimensions */
#define NY 7
#define NZ 3
#define RANK 2
#define RANK_OUT 3
int
main (void)
{
hid_t file, dataset; /* handles */
hid_t datatype, dataspace;
hid_t memspace;
H5T_class_t class; /* datatype class */
H5T_order_t order; /* data order */
size_t size; /*
* size of the data element
* stored in file
*/
hsize_t dimsm[3]; /* memory space dimensions */
hsize_t dims_out[2]; /* dataset dimensions */
herr_t status;
int data_out[NX][NY][NZ ]; /* output buffer */
hsize_t count[2]; /* size of the hyperslab in the file */
hssize_t offset[2]; /* hyperslab offset in the file */
hsize_t count_out[3]; /* size of the hyperslab in memory */
hssize_t offset_out[3]; /* hyperslab offset in memory */
int i, j, k, status_n, rank;
for (j = 0; j < NX; j++) {
for (i = 0; i < NY; i++) {
for (k = 0; k < NZ ; k++)
data_out[j][i][k] = 0;
}
}
/*
* Open the file and the dataset.
*/
file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
dataset = H5Dopen(file, DATASETNAME);
/*
* Get datatype and dataspace handles and then query
* dataset class, order, size, rank and dimensions.
*/
datatype = H5Dget_type(dataset); /* datatype handle */
class = H5Tget_class(datatype);
if (class == H5T_INTEGER) printf("Data set has INTEGER type \n");
order = H5Tget_order(datatype);
if (order == H5T_ORDER_LE) printf("Little endian order \n");
size = H5Tget_size(datatype);
printf(" Data size is %d \n", size);
dataspace = H5Dget_space(dataset); /* dataspace handle */
rank = H5Sget_simple_extent_ndims(dataspace);
status_n = H5Sget_simple_extent_dims(dataspace, dims_out, NULL);
printf("rank %d, dimensions %lu x %lu \n", rank,
(unsigned long)(dims_out[0]), (unsigned long)(dims_out[1]));
/*
* Define hyperslab in the dataset.
*/
offset[0] = 1;
offset[1] = 2;
count[0] = NX_SUB;
count[1] = NY_SUB;
status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, NULL,
count, NULL);
/*
* Define the memory dataspace.
*/
dimsm[0] = NX;
dimsm[1] = NY;
dimsm[2] = NZ ;
memspace = H5Screate_simple(RANK_OUT,dimsm,NULL);
/*
* Define memory hyperslab.
*/
offset_out[0] = 3;
offset_out[1] = 0;
offset_out[2] = 0;
count_out[0] = NX_SUB;
count_out[1] = NY_SUB;
count_out[2] = 1;
status = H5Sselect_hyperslab(memspace, H5S_SELECT_SET, offset_out, NULL,
count_out, NULL);
/*
* Read data from hyperslab in the file into the hyperslab in
* memory and display.
*/
status = H5Dread(dataset, H5T_NATIVE_INT, memspace, dataspace,
H5P_DEFAULT, data_out);
for (j = 0; j < NX; j++) {
for (i = 0; i < NY; i++) printf("%d ", data_out[j][i][0]);
printf("\n");
}
/*
* 0 0 0 0 0 0 0
* 0 0 0 0 0 0 0
* 0 0 0 0 0 0 0
* 3 4 5 6 0 0 0
* 4 5 6 7 0 0 0
* 5 6 7 8 0 0 0
* 0 0 0 0 0 0 0
*/
/*
* Close/release resources.
*/
H5Tclose(datatype);
H5Dclose(dataset);
H5Sclose(dataspace);
H5Sclose(memspace);
H5Fclose(file);
return 0;
}
</pre>
<H4><A NAME="_Toc429885331"><A NAME="WriteSelected"></A>Example 3. Writing selected data from memory to a file.</A></H4>
<P>This example shows how to use the selection capabilities of HDF5 to write selected data to a file. It includes the examples discussed in the text.
<pre>
<!-- Insert Example 3, h5_select.c, here. -->
/*
* This program shows how the H5Sselect_hyperslab and H5Sselect_elements
* functions are used to write selected data from memory to the file.
* Program takes 48 elements from the linear buffer and writes them into
* the matrix using 3x2 blocks, (4,3) stride and (2,4) count.
* Then four elements of the matrix are overwritten with the new values and
* file is closed. Program reopens the file and reads and displays the result.
*/
#include <hdf5.h>
#define FILE "Select.h5"
#define MSPACE1_RANK 1 /* Rank of the first dataset in memory */
#define MSPACE1_DIM 50 /* Dataset size in memory */
#define MSPACE2_RANK 1 /* Rank of the second dataset in memory */
#define MSPACE2_DIM 4 /* Dataset size in memory */
#define FSPACE_RANK 2 /* Dataset rank as it is stored in the file */
#define FSPACE_DIM1 8 /* Dimension sizes of the dataset as it is
stored in the file */
#define FSPACE_DIM2 12
/* We will read dataset back from the file
to the dataset in memory with these
dataspace parameters. */
#define MSPACE_RANK 2
#define MSPACE_DIM1 8
#define MSPACE_DIM2 12
#define NPOINTS 4 /* Number of points that will be selected
and overwritten */
int main (void)
{
hid_t file, dataset; /* File and dataset identifiers */
hid_t mid1, mid2, fid; /* Dataspace identifiers */
hsize_t dim1[] = {MSPACE1_DIM}; /* Dimension size of the first dataset
(in memory) */
hsize_t dim2[] = {MSPACE2_DIM}; /* Dimension size of the second dataset
(in memory */
hsize_t fdim[] = {FSPACE_DIM1, FSPACE_DIM2};
/* Dimension sizes of the dataset (on disk) */
hssize_t start[2]; /* Start of hyperslab */
hsize_t stride[2]; /* Stride of hyperslab */
hsize_t count[2]; /* Block count */
hsize_t block[2]; /* Block sizes */
hssize_t coord[NPOINTS][FSPACE_RANK]; /* Array to store selected points
from the file dataspace */
herr_t ret;
uint i,j;
int matrix[MSPACE_DIM1][MSPACE_DIM2];
int vector[MSPACE1_DIM];
int values[] = {53, 59, 61, 67}; /* New values to be written */
/*
* Buffers' initialization.
*/
vector[0] = vector[MSPACE1_DIM - 1] = -1;
for (i = 1; i < MSPACE1_DIM - 1; i++) vector[i] = i;
for (i = 0; i < MSPACE_DIM1; i++) {
for (j = 0; j < MSPACE_DIM2; j++)
matrix[i][j] = 0;
}
/*
* Create a file.
*/
file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create dataspace for the dataset in the file.
*/
fid = H5Screate_simple(FSPACE_RANK, fdim, NULL);
/*
* Create dataset and write it into the file.
*/
dataset = H5Dcreate(file, "Matrix in file", H5T_NATIVE_INT, fid, H5P_DEFAULT);
ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, matrix);
/*
* Select hyperslab for the dataset in the file, using 3x2 blocks,
* (4,3) stride and (2,4) count starting at the position (0,1).
*/
start[0] = 0; start[1] = 1;
stride[0] = 4; stride[1] = 3;
count[0] = 2; count[1] = 4;
block[0] = 3; block[1] = 2;
ret = H5Sselect_hyperslab(fid, H5S_SELECT_SET, start, stride, count, block);
/*
* Create dataspace for the first dataset.
*/
mid1 = H5Screate_simple(MSPACE1_RANK, dim1, NULL);
/*
* Select hyperslab.
* We will use 48 elements of the vector buffer starting at the second element.
* Selected elements are 1 2 3 . . . 48
*/
start[0] = 1;
stride[0] = 1;
count[0] = 48;
block[0] = 1;
ret = H5Sselect_hyperslab(mid1, H5S_SELECT_SET, start, stride, count, block);
/*
* Write selection from the vector buffer to the dataset in the file.
*
* File dataset should look like this:
* 0 1 2 0 3 4 0 5 6 0 7 8
* 0 9 10 0 11 12 0 13 14 0 15 16
* 0 17 18 0 19 20 0 21 22 0 23 24
* 0 0 0 0 0 0 0 0 0 0 0 0
* 0 25 26 0 27 28 0 29 30 0 31 32
* 0 33 34 0 35 36 0 37 38 0 39 40
* 0 41 42 0 43 44 0 45 46 0 47 48
* 0 0 0 0 0 0 0 0 0 0 0 0
*/
ret = H5Dwrite(dataset, H5T_NATIVE_INT, mid1, fid, H5P_DEFAULT, vector);
/*
* Reset the selection for the file dataspace fid.
*/
ret = H5Sselect_none(fid);
/*
* Create dataspace for the second dataset.
*/
mid2 = H5Screate_simple(MSPACE2_RANK, dim2, NULL);
/*
* Select sequence of NPOINTS points in the file dataspace.
*/
coord[0][0] = 0; coord[0][1] = 0;
coord[1][0] = 3; coord[1][1] = 3;
coord[2][0] = 3; coord[2][1] = 5;
coord[3][0] = 5; coord[3][1] = 6;
ret = H5Sselect_elements(fid, H5S_SELECT_SET, NPOINTS,
(const hssize_t **)coord);
/*
* Write new selection of points to the dataset.
*/
ret = H5Dwrite(dataset, H5T_NATIVE_INT, mid2, fid, H5P_DEFAULT, values);
/*
* File dataset should look like this:
* 53 1 2 0 3 4 0 5 6 0 7 8
* 0 9 10 0 11 12 0 13 14 0 15 16
* 0 17 18 0 19 20 0 21 22 0 23 24
* 0 0 0 59 0 61 0 0 0 0 0 0
* 0 25 26 0 27 28 0 29 30 0 31 32
* 0 33 34 0 35 36 67 37 38 0 39 40
* 0 41 42 0 43 44 0 45 46 0 47 48
* 0 0 0 0 0 0 0 0 0 0 0 0
*
*/
/*
* Close memory file and memory dataspaces.
*/
ret = H5Sclose(mid1);
ret = H5Sclose(mid2);
ret = H5Sclose(fid);
/*
* Close dataset.
*/
ret = H5Dclose(dataset);
/*
* Close the file.
*/
ret = H5Fclose(file);
/*
* Open the file.
*/
file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
/*
* Open the dataset.
*/
dataset = dataset = H5Dopen(file,"Matrix in file");
/*
* Read data back to the buffer matrix.
*/
ret = H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
H5P_DEFAULT, matrix);
/*
* Display the result.
*/
for (i=0; i < MSPACE_DIM1; i++) {
for(j=0; j < MSPACE_DIM2; j++) printf("%3d ", matrix[i][j]);
printf("\n");
}
return 0;
}
</pre>
<H4><A NAME="Compound"><A NAME="_Toc429885327"></A>Example 4. Working with compound datatypes.</A></H4>
<P>This example shows how to create a compound datatype, write an array which has the compound datatype to the file, and read back subsets of fields.
<PRE>
<!-- Insert Example 4, h5_compound.c, here. -->
/*
* This example shows how to create a compound datatype,
* write an array which has the compound datatype to the file,
* and read back fields' subsets.
*/
#include "hdf5.h"
#define FILE "SDScompound.h5"
#define DATASETNAME "ArrayOfStructures"
#define LENGTH 10
#define RANK 1
int
main(void)
{
/* First structure and dataset*/
typedef struct s1_t {
int a;
float b;
double c;
} s1_t;
s1_t s1[LENGTH];
hid_t s1_tid; /* File datatype identifier */
/* Second structure (subset of s1_t) and dataset*/
typedef struct s2_t {
double c;
int a;
} s2_t;
s2_t s2[LENGTH];
hid_t s2_tid; /* Memory datatype handle */
/* Third "structure" ( will be used to read float field of s1) */
hid_t s3_tid; /* Memory datatype handle */
float s3[LENGTH];
int i;
hid_t file, dataset, space; /* Handles */
herr_t status;
hsize_t dim[] = {LENGTH}; /* Dataspace dimensions */
/*
* Initialize the data
*/
for (i = 0; i< LENGTH; i++) {
s1[i].a = i;
s1[i].b = i*i;
s1[i].c = 1./(i+1);
}
/*
* Create the data space.
*/
space = H5Screate_simple(RANK, dim, NULL);
/*
* Create the file.
*/
file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create the memory datatype.
*/
s1_tid = H5Tcreate (H5T_COMPOUND, sizeof(s1_t));
H5Tinsert(s1_tid, "a_name", HOFFSET(s1_t, a), H5T_NATIVE_INT);
H5Tinsert(s1_tid, "c_name", HOFFSET(s1_t, c), H5T_NATIVE_DOUBLE);
H5Tinsert(s1_tid, "b_name", HOFFSET(s1_t, b), H5T_NATIVE_FLOAT);
/*
* Create the dataset.
*/
dataset = H5Dcreate(file, DATASETNAME, s1_tid, space, H5P_DEFAULT);
/*
* Wtite data to the dataset;
*/
status = H5Dwrite(dataset, s1_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, s1);
/*
* Release resources
*/
H5Tclose(s1_tid);
H5Sclose(space);
H5Dclose(dataset);
H5Fclose(file);
/*
* Open the file and the dataset.
*/
file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
dataset = H5Dopen(file, DATASETNAME);
/*
* Create a datatype for s2
*/
s2_tid = H5Tcreate(H5T_COMPOUND, sizeof(s2_t));
H5Tinsert(s2_tid, "c_name", HOFFSET(s2_t, c), H5T_NATIVE_DOUBLE);
H5Tinsert(s2_tid, "a_name", HOFFSET(s2_t, a), H5T_NATIVE_INT);
/*
* Read two fields c and a from s1 dataset. Fields in the file
* are found by their names "c_name" and "a_name".
*/
status = H5Dread(dataset, s2_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, s2);
/*
* Display the fields
*/
printf("\n");
printf("Field c : \n");
for( i = 0; i < LENGTH; i++) printf("%.4f ", s2[i].c);
printf("\n");
printf("\n");
printf("Field a : \n");
for( i = 0; i < LENGTH; i++) printf("%d ", s2[i].a);
printf("\n");
/*
* Create a datatype for s3.
*/
s3_tid = H5Tcreate(H5T_COMPOUND, sizeof(float));
status = H5Tinsert(s3_tid, "b_name", 0, H5T_NATIVE_FLOAT);
/*
* Read field b from s1 dataset. Field in the file is found by its name.
*/
status = H5Dread(dataset, s3_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, s3);
/*
* Display the field
*/
printf("\n");
printf("Field b : \n");
for( i = 0; i < LENGTH; i++) printf("%.4f ", s3[i]);
printf("\n");
/*
* Release resources
*/
H5Tclose(s2_tid);
H5Tclose(s3_tid);
H5Dclose(dataset);
H5Fclose(file);
return 0;
}
</pre>
<H4><A NAME="CreateExtendWrite"><A NAME="_Toc429885328"></A>Example 5. Creating and writing an extendible dataset.</A></H4>
<P>This example shows how to create a 3x3 extendible dataset, to extend the dataset to 10x3, then to extend it again to 10x5.
<PRE>
<!-- Insert Example 5, h5_extend_write.c, here. -->
/*
* This example shows how to work with extendible dataset.
* In the current version of the library dataset MUST be
* chunked.
*
*/
#include "hdf5.h"
#define FILE "SDSextendible.h5"
#define DATASETNAME "ExtendibleArray"
#define RANK 2
#define NX 10
#define NY 5
int
main (void)
{
hid_t file; /* handles */
hid_t dataspace, dataset;
hid_t filespace;
hid_t cparms;
hsize_t dims[2] = { 3, 3}; /*
* dataset dimensions
* at the creation time
*/
hsize_t dims1[2] = { 3, 3}; /* data1 dimensions */
hsize_t dims2[2] = { 7, 1}; /* data2 dimensions */
hsize_t dims3[2] = { 2, 2}; /* data3 dimensions */
hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED};
hsize_t chunk_dims[2] ={2, 5};
hsize_t size[2];
hssize_t offset[2];
herr_t status;
int data1[3][3] = { {1, 1, 1}, /* data to write */
{1, 1, 1},
{1, 1, 1} };
int data2[7] = { 2, 2, 2, 2, 2, 2, 2};
int data3[2][2] = { {3, 3},
{3, 3} };
/*
* Create the data space with unlimited dimensions.
*/
dataspace = H5Screate_simple(RANK, dims, maxdims);
/*
* Create a new file. If file exists its contents will be overwritten.
*/
file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/*
* Modify dataset creation properties, i.e. enable chunking.
*/
cparms = H5Pcreate (H5P_DATASET_CREATE);
status = H5Pset_chunk( cparms, RANK, chunk_dims);
/*
* Create a new dataset within the file using cparms
* creation properties.
*/
dataset = H5Dcreate(file, DATASETNAME, H5T_NATIVE_INT, dataspace,
cparms);
/*
* Extend the dataset. This call assures that dataset is at least 3 x 3.
*/
size[0] = 3;
size[1] = 3;
status = H5Dextend (dataset, size);
/*
* Select a hyperslab.
*/
filespace = H5Dget_space (dataset);
offset[0] = 0;
offset[1] = 0;
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
dims1, NULL);
/*
* Write the data to the hyperslab.
*/
status = H5Dwrite(dataset, H5T_NATIVE_INT, dataspace, filespace,
H5P_DEFAULT, data1);
/*
* Extend the dataset. Dataset becomes 10 x 3.
*/
dims[0] = dims1[0] + dims2[0];
size[0] = dims[0];
size[1] = dims[1];
status = H5Dextend (dataset, size);
/*
* Select a hyperslab.
*/
filespace = H5Dget_space (dataset);
offset[0] = 3;
offset[1] = 0;
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
dims2, NULL);
/*
* Define memory space
*/
dataspace = H5Screate_simple(RANK, dims2, NULL);
/*
* Write the data to the hyperslab.
*/
status = H5Dwrite(dataset, H5T_NATIVE_INT, dataspace, filespace,
H5P_DEFAULT, data2);
/*
* Extend the dataset. Dataset becomes 10 x 5.
*/
dims[1] = dims1[1] + dims3[1];
size[0] = dims[0];
size[1] = dims[1];
status = H5Dextend (dataset, size);
/*
* Select a hyperslab
*/
filespace = H5Dget_space (dataset);
offset[0] = 0;
offset[1] = 3;
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
dims3, NULL);
/*
* Define memory space.
*/
dataspace = H5Screate_simple(RANK, dims3, NULL);
/*
* Write the data to the hyperslab.
*/
status = H5Dwrite(dataset, H5T_NATIVE_INT, dataspace, filespace,
H5P_DEFAULT, data3);
/*
* Resulting dataset
*
* 3 3 3 2 2
* 3 3 3 2 2
* 3 3 3 0 0
* 2 0 0 0 0
* 2 0 0 0 0
* 2 0 0 0 0
* 2 0 0 0 0
* 2 0 0 0 0
* 2 0 0 0 0
* 2 0 0 0 0
*/
/*
* Close/release resources.
*/
H5Dclose(dataset);
H5Sclose(dataspace);
H5Sclose(filespace);
H5Fclose(file);
return 0;
}
</pre>
<H4><A NAME="ReadExtended"><A NAME="_Toc429885329"></A>Example 6. Reading data.</A></H4>
<P>This example shows how to read information the chunked dataset written by <A HREF="#CreateExtendWrite">Example 5</A>.
<PRE>
<!-- Insert Example 6, h5_chunk_read.c, here. -->
/*
* This example shows how to read data from a chunked dataset.
* We will read from the file created by h5_extend_write.c
*/
#include "hdf5.h"
#define FILE "SDSextendible.h5"
#define DATASETNAME "ExtendibleArray"
#define RANK 2
#define RANKC 1
#define NX 10
#define NY 5
int
main (void)
{
hid_t file; /* handles */
hid_t dataset;
hid_t filespace;
hid_t memspace;
hid_t cparms;
hsize_t dims[2]; /* dataset and chunk dimensions*/
hsize_t chunk_dims[2];
hsize_t col_dims[1];
hsize_t count[2];
hssize_t offset[2];
herr_t status, status_n;
int data_out[NX][NY]; /* buffer for dataset to be read */
int chunk_out[2][5]; /* buffer for chunk to be read */
int column[10]; /* buffer for column to be read */
int rank, rank_chunk;
hsize_t i, j;
/*
* Open the file and the dataset.
*/
file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
dataset = H5Dopen(file, DATASETNAME);
/*
* Get dataset rank and dimension.
*/
filespace = H5Dget_space(dataset); /* Get filespace handle first. */
rank = H5Sget_simple_extent_ndims(filespace);
status_n = H5Sget_simple_extent_dims(filespace, dims, NULL);
printf("dataset rank %d, dimensions %lu x %lu\n",
rank, (unsigned long)(dims[0]), (unsigned long)(dims[1]));
/*
* Get creation properties list.
*/
cparms = H5Dget_create_plist(dataset); /* Get properties handle first. */
/*
* Check if dataset is chunked.
*/
if (H5D_CHUNKED == H5Pget_layout(cparms)) {
/*
* Get chunking information: rank and dimensions
*/
rank_chunk = H5Pget_chunk(cparms, 2, chunk_dims);
printf("chunk rank %d, dimensions %lu x %lu\n", rank_chunk,
(unsigned long)(chunk_dims[0]), (unsigned long)(chunk_dims[1]));
}
/*
* Define the memory space to read dataset.
*/
memspace = H5Screate_simple(RANK,dims,NULL);
/*
* Read dataset back and display.
*/
status = H5Dread(dataset, H5T_NATIVE_INT, memspace, filespace,
H5P_DEFAULT, data_out);
printf("\n");
printf("Dataset: \n");
for (j = 0; j < dims[0]; j++) {
for (i = 0; i < dims[1]; i++) printf("%d ", data_out[j][i]);
printf("\n");
}
/*
* dataset rank 2, dimensions 10 x 5
* chunk rank 2, dimensions 2 x 5
* Dataset:
* 1 1 1 3 3
* 1 1 1 3 3
* 1 1 1 0 0
* 2 0 0 0 0
* 2 0 0 0 0
* 2 0 0 0 0
* 2 0 0 0 0
* 2 0 0 0 0
* 2 0 0 0 0
* 2 0 0 0 0
*/
/*
* Read the third column from the dataset.
* First define memory dataspace, then define hyperslab
* and read it into column array.
*/
col_dims[0] = 10;
memspace = H5Screate_simple(RANKC, col_dims, NULL);
/*
* Define the column (hyperslab) to read.
*/
offset[0] = 0;
offset[1] = 2;
count[0] = 10;
count[1] = 1;
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
count, NULL);
status = H5Dread(dataset, H5T_NATIVE_INT, memspace, filespace,
H5P_DEFAULT, column);
printf("\n");
printf("Third column: \n");
for (i = 0; i < 10; i++) {
printf("%d \n", column[i]);
}
/*
* Third column:
* 1
* 1
* 1
* 0
* 0
* 0
* 0
* 0
* 0
* 0
*/
/*
* Define the memory space to read a chunk.
*/
memspace = H5Screate_simple(rank_chunk,chunk_dims,NULL);
/*
* Define chunk in the file (hyperslab) to read.
*/
offset[0] = 2;
offset[1] = 0;
count[0] = chunk_dims[0];
count[1] = chunk_dims[1];
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
count, NULL);
/*
* Read chunk back and display.
*/
status = H5Dread(dataset, H5T_NATIVE_INT, memspace, filespace,
H5P_DEFAULT, chunk_out);
printf("\n");
printf("Chunk: \n");
for (j = 0; j < chunk_dims[0]; j++) {
for (i = 0; i < chunk_dims[1]; i++) printf("%d ", chunk_out[j][i]);
printf("\n");
}
/*
* Chunk:
* 1 1 1 0 0
* 2 0 0 0 0
*/
/*
* Close/release resources.
*/
H5Pclose(cparms);
H5Dclose(dataset);
H5Sclose(filespace);
H5Sclose(memspace);
H5Fclose(file);
return 0;
</pre>
<H4><A NAME="CreateGroups"><A NAME="_Toc429885330"></A>Example 7. Creating groups.</A></H4>
<P>This example shows how to create and access a group in an
HDF5 file and to place a dataset within this group.
It also illustrates the usage of the <code>H5Giterate</code>,
<code>H5Glink</code>, and <code>H5Gunlink</code> functions.
<PRE>
<!-- Insert Example 7, h5_group.c, here. -->
/*
* This example creates a group in the file and dataset in the group.
* Hard link to the group object is created and the dataset is accessed
* under different names.
* Iterator function is used to find the object names in the root group.
*/
#include "hdf5.h"
#define FILE "group.h5"
#define RANK 2
herr_t file_info(hid_t loc_id, const char *name, void *opdata);
/* Operator function */
int
main(void)
{
hid_t file;
hid_t grp;
hid_t dataset, dataspace;
hid_t plist;
herr_t status;
hsize_t dims[2];
hsize_t cdims[2];
int idx;
/*
* Create a file.
*/
file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create a group in the file.
*/
grp = H5Gcreate(file, "/Data", 0);
/*
* Create dataset "Compressed Data" in the group using absolute
* name. Dataset creation property list is modified to use
* GZIP compression with the compression effort set to 6.
* Note that compression can be used only when dataset is chunked.
*/
dims[0] = 1000;
dims[1] = 20;
cdims[0] = 20;
cdims[1] = 20;
dataspace = H5Screate_simple(RANK, dims, NULL);
plist = H5Pcreate(H5P_DATASET_CREATE);
H5Pset_chunk(plist, 2, cdims);
H5Pset_deflate( plist, 6);
dataset = H5Dcreate(file, "/Data/Compressed_Data", H5T_NATIVE_INT,
dataspace, plist);
/*
* Close the dataset and the file.
*/
H5Sclose(dataspace);
H5Dclose(dataset);
H5Fclose(file);
/*
* Now reopen the file and group in the file.
*/
file = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
grp = H5Gopen(file, "Data");
/*
* Access "Compressed_Data" dataset in the group.
*/
dataset = H5Dopen(grp, "Compressed_Data");
if( dataset < 0) printf(" Dataset is not found. \n");
printf("\"/Data/Compressed_Data\" dataset is open \n");
/*
* Close the dataset.
*/
status = H5Dclose(dataset);
/*
* Create hard link to the Data group.
*/
status = H5Glink(file, H5G_LINK_HARD, "Data", "Data_new");
/*
* We can access "Compressed_Data" dataset using created
* hard link "Data_new".
*/
dataset = H5Dopen(file, "/Data_new/Compressed_Data");
if( dataset < 0) printf(" Dataset is not found. \n");
printf("\"/Data_new/Compressed_Data\" dataset is open \n");
/*
* Close the dataset.
*/
status = H5Dclose(dataset);
/*
* Use iterator to see the names of the objects in the file
* root directory.
*/
idx = H5Giterate(file, "/", NULL, file_info, NULL);
/*
* Unlink name "Data" and use iterator to see the names
* of the objects in the file root direvtory.
*/
if (H5Gunlink(file, "Data") < 0)
printf(" H5Gunlink failed \n");
else
printf("\"Data\" is unlinked \n");
idx = H5Giterate(file, "/", NULL, file_info, NULL);
/*
* Close the file.
*/
status = H5Fclose(file);
return 0;
}
/*
* Operator function.
*/
herr_t
file_info(hid_t loc_id, const char *name, void *opdata)
{
hid_t grp;
/*
* Open the group using its name.
*/
grp = H5Gopen(loc_id, name);
/*
* Display group name.
*/
printf("\n");
printf("Name : ");
puts(name);
H5Gclose(grp);
return 0;
}
</pre>
<H4><A NAME="_Toc429885332"><A NAME="ReadWriteAttributes">Example 8</A>. Writing and reading attributes.</A></H4>
<P>This example shows how to create HDF5 attributes, to attach them to a dataset, and to read through all of the attributes of a dataset.
<pre>
<!-- Insert Example 8, h5_attribute.c, here. -->
/*
* This program illustrates the usage of the H5A Interface functions.
* It creates and writes a dataset, and then creates and writes array,
* scalar, and string attributes of the dataset.
* Program reopens the file, attaches to the scalar attribute using
* attribute name and reads and displays its value. Then index of the
* third attribute is used to read and display attribute values.
* The H5Aiterate function is used to iterate through the dataset attributes,
* and display their names. The function is also reads and displays the values
* of the array attribute.
*/
#include <stdlib.h>
#include <hdf5.h>
#define FILE "Attributes.h5"
#define RANK 1 /* Rank and size of the dataset */
#define SIZE 7
#define ARANK 2 /* Rank and dimension sizes of the first dataset attribute */
#define ADIM1 2
#define ADIM2 3
#define ANAME "Float attribute" /* Name of the array attribute */
#define ANAMES "Character attribute" /* Name of the string attribute */
herr_t attr_info(hid_t loc_id, const char *name, void *opdata);
/* Operator function */
int
main (void)
{
hid_t file, dataset; /* File and dataset identifiers */
hid_t fid; /* Dataspace identifier */
hid_t attr1, attr2, attr3; /* Attribute identifiers */
hid_t attr;
hid_t aid1, aid2, aid3; /* Attribute dataspace identifiers */
hid_t atype; /* Attribute type */
hsize_t fdim[] = {SIZE};
hsize_t adim[] = {ADIM1, ADIM2}; /* Dimensions of the first attribute */
float matrix[ADIM1][ADIM2]; /* Attribute data */
herr_t ret; /* Return value */
uint i,j; /* Counters */
int idx; /* Attribute index */
char string_out[80]; /* Buffer to read string attribute back */
int point_out; /* Buffer to read scalar attribute back */
/*
* Data initialization.
*/
int vector[] = {1, 2, 3, 4, 5, 6, 7}; /* Dataset data */
int point = 1; /* Value of the scalar attribute */
char string[] = "ABCD"; /* Value of the string attribute */
for (i=0; i < ADIM1; i++) { /* Values of the array attribute */
for (j=0; j < ADIM2; j++)
matrix[i][j] = -1.;
}
/*
* Create a file.
*/
file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create the dataspace for the dataset in the file.
*/
fid = H5Screate(H5S_SIMPLE);
ret = H5Sset_extent_simple(fid, RANK, fdim, NULL);
/*
* Create the dataset in the file.
*/
dataset = H5Dcreate(file, "Dataset", H5T_NATIVE_INT, fid, H5P_DEFAULT);
/*
* Write data to the dataset.
*/
ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL , H5S_ALL, H5P_DEFAULT, vector);
/*
* Create dataspace for the first attribute.
*/
aid1 = H5Screate(H5S_SIMPLE);
ret = H5Sset_extent_simple(aid1, ARANK, adim, NULL);
/*
* Create array attribute.
*/
attr1 = H5Acreate(dataset, ANAME, H5T_NATIVE_FLOAT, aid1, H5P_DEFAULT);
/*
* Write array attribute.
*/
ret = H5Awrite(attr1, H5T_NATIVE_FLOAT, matrix);
/*
* Create scalar attribute.
*/
aid2 = H5Screate(H5S_SCALAR);
attr2 = H5Acreate(dataset, "Integer attribute", H5T_NATIVE_INT, aid2,
H5P_DEFAULT);
/*
* Write scalar attribute.
*/
ret = H5Awrite(attr2, H5T_NATIVE_INT, &point);
/*
* Create string attribute.
*/
aid3 = H5Screate(H5S_SCALAR);
atype = H5Tcopy(H5T_C_S1);
H5Tset_size(atype, 4);
attr3 = H5Acreate(dataset, ANAMES, atype, aid3, H5P_DEFAULT);
/*
* Write string attribute.
*/
ret = H5Awrite(attr3, atype, string);
/*
* Close attribute and file dataspaces.
*/
ret = H5Sclose(aid1);
ret = H5Sclose(aid2);
ret = H5Sclose(aid3);
ret = H5Sclose(fid);
/*
* Close the attributes.
*/
ret = H5Aclose(attr1);
ret = H5Aclose(attr2);
ret = H5Aclose(attr3);
/*
* Close the dataset.
*/
ret = H5Dclose(dataset);
/*
* Close the file.
*/
ret = H5Fclose(file);
/*
* Reopen the file.
*/
file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
/*
* Open the dataset.
*/
dataset = H5Dopen(file,"Dataset");
/*
* Attach to the scalar attribute using attribute name, then read and
* display its value.
*/
attr = H5Aopen_name(dataset,"Integer attribute");
ret = H5Aread(attr, H5T_NATIVE_INT, &point_out);
printf("The value of the attribute \"Integer attribute\" is %d \n", point_out);
ret = H5Aclose(attr);
/*
* Attach to the string attribute using its index, then read and display the value.
*/
attr = H5Aopen_idx(dataset, 2);
atype = H5Tcopy(H5T_C_S1);
H5Tset_size(atype, 4);
ret = H5Aread(attr, atype, string_out);
printf("The value of the attribute with the index 2 is %s \n", string_out);
ret = H5Aclose(attr);
ret = H5Tclose(atype);
/*
* Get attribute info using iteration function.
*/
idx = H5Aiterate(dataset, NULL, attr_info, NULL);
/*
* Close the dataset and the file.
*/
H5Dclose(dataset);
H5Fclose(file);
return 0;
}
/*
* Operator function.
*/
herr_t
attr_info(hid_t loc_id, const char *name, void *opdata)
{
hid_t attr, atype, aspace; /* Attribute, datatype and dataspace identifiers */
int rank;
hsize_t sdim[64];
herr_t ret;
int i;
size_t npoints; /* Number of elements in the array attribute. */
float *float_array; /* Pointer to the array attribute. */
/*
* Open the attribute using its name.
*/
attr = H5Aopen_name(loc_id, name);
/*
* Display attribute name.
*/
printf("\n");
printf("Name : ");
puts(name);
/*
* Get attribute datatype, dataspace, rank, and dimensions.
*/
atype = H5Aget_type(attr);
aspace = H5Aget_space(attr);
rank = H5Sget_simple_extent_ndims(aspace);
ret = H5Sget_simple_extent_dims(aspace, sdim, NULL);
/*
* Display rank and dimension sizes for the array attribute.
*/
if(rank > 0) {
printf("Rank : %d \n", rank);
printf("Dimension sizes : ");
for (i=0; i< rank; i++) printf("%d ", (int)sdim[i]);
printf("\n");
}
/*
* Read array attribute and display its type and values.
*/
if (H5T_FLOAT == H5Tget_class(atype)) {
printf("Type : FLOAT \n");
npoints = H5Sget_simple_extent_npoints(aspace);
float_array = (float *)malloc(sizeof(float)*(int)npoints);
ret = H5Aread(attr, atype, float_array);
printf("Values : ");
for( i = 0; i < (int)npoints; i++) printf("%f ", float_array[i]);
printf("\n");
free(float_array);
}
/*
* Release all identifiers.
*/
H5Tclose(atype);
H5Sclose(aspace);
H5Aclose(attr);
return 0;
}
</pre>
<H4><A NAME="CreateWriteRefObj">Example 9</A>. Creating and storing references to objects.</A></H4>
This example creates a group and two datasets and a named datatype
in the group. References to these four objects are stored in the dataset
in the root group.
<PRE>
#include <hdf5.h>
#define FILE1 "trefer1.h5"
/* 1-D dataset with fixed dimensions */
#define SPACE1_NAME "Space1"
#define SPACE1_RANK 1
#define SPACE1_DIM1 4
/* 2-D dataset with fixed dimensions */
#define SPACE2_NAME "Space2"
#define SPACE2_RANK 2
#define SPACE2_DIM1 10
#define SPACE2_DIM2 10
int
main(void) {
hid_t fid1; /* HDF5 File IDs */
hid_t dataset; /* Dataset ID */
hid_t group; /* Group ID */
hid_t sid1; /* Dataspace ID */
hid_t tid1; /* Datatype ID */
hsize_t dims1[] = {SPACE1_DIM1};
hobj_ref_t *wbuf; /* buffer to write to disk */
int *tu32; /* Temporary pointer to int data */
int i; /* counting variables */
const char *write_comment="Foo!"; /* Comments for group */
herr_t ret; /* Generic return value */
/* Compound datatype */
typedef struct s1_t {
unsigned int a;
unsigned int b;
float c;
} s1_t;
/* Allocate write buffers */
wbuf=(hobj_ref_t *)malloc(sizeof(hobj_ref_t)*SPACE1_DIM1);
tu32=malloc(sizeof(int)*SPACE1_DIM1);
/* Create file */
fid1 = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create dataspace for datasets */
sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
/* Create a group */
group=H5Gcreate(fid1,"Group1",-1);
/* Set group's comment */
ret=H5Gset_comment(group,".",write_comment);
/* Create a dataset (inside Group1) */
dataset=H5Dcreate(group,"Dataset1",H5T_STD_U32LE,sid1,H5P_DEFAULT);
for(i=0; i < SPACE1_DIM1; i++)
tu32[i] = i*3;
/* Write selection to disk */
ret=H5Dwrite(dataset,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,tu32);
/* Close Dataset */
ret = H5Dclose(dataset);
/* Create another dataset (inside Group1) */
dataset=H5Dcreate(group,"Dataset2",H5T_NATIVE_UCHAR,sid1,H5P_DEFAULT);
/* Close Dataset */
ret = H5Dclose(dataset);
/* Create a datatype to refer to */
tid1 = H5Tcreate (H5T_COMPOUND, sizeof(s1_t));
/* Insert fields */
ret=H5Tinsert (tid1, "a", HOFFSET(s1_t,a), H5T_NATIVE_INT);
ret=H5Tinsert (tid1, "b", HOFFSET(s1_t,b), H5T_NATIVE_INT);
ret=H5Tinsert (tid1, "c", HOFFSET(s1_t,c), H5T_NATIVE_FLOAT);
/* Save datatype for later */
ret=H5Tcommit (group, "Datatype1", tid1);
/* Close datatype */
ret = H5Tclose(tid1);
/* Close group */
ret = H5Gclose(group);
/* Create a dataset to store references */
dataset=H5Dcreate(fid1,"Dataset3",H5T_STD_REF_OBJ,sid1,H5P_DEFAULT);
/* Create reference to dataset */
ret = H5Rcreate(&wbuf[0],fid1,"/Group1/Dataset1",H5R_OBJECT,-1);
/* Create reference to dataset */
ret = H5Rcreate(&wbuf[1],fid1,"/Group1/Dataset2",H5R_OBJECT,-1);
/* Create reference to group */
ret = H5Rcreate(&wbuf[2],fid1,"/Group1",H5R_OBJECT,-1);
/* Create reference to named datatype */
ret = H5Rcreate(&wbuf[3],fid1,"/Group1/Datatype1",H5R_OBJECT,-1);
/* Write selection to disk */
ret=H5Dwrite(dataset,H5T_STD_REF_OBJ,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf);
/* Close disk dataspace */
ret = H5Sclose(sid1);
/* Close Dataset */
ret = H5Dclose(dataset);
/* Close file */
ret = H5Fclose(fid1);
free(wbuf);
free(tu32);
return 0;
}
</PRE>
<H4><A NAME="ReadRefObj">Example 10</A>. Reading references to objects.</A></H4>
This example opens and reads dataset <code>Dataset3</code> from
the file created in Example 9. Then the program dereferences the references
to dataset <code>Dataset1</code>, the group and the named datatype,
and opens those objects.
The program reads and displays the dataset's data, the group's comment, and
the number of members of the compound datatype.
<PRE>
#include <stdlib.h>
#include <hdf5.h>
#define FILE1 "trefer1.h5"
/* dataset with fixed dimensions */
#define SPACE1_NAME "Space1"
#define SPACE1_RANK 1
#define SPACE1_DIM1 4
int
main(void)
{
hid_t fid1; /* HDF5 File IDs */
hid_t dataset, /* Dataset ID */
dset2; /* Dereferenced dataset ID */
hid_t group; /* Group ID */
hid_t sid1; /* Dataspace ID */
hid_t tid1; /* Datatype ID */
hobj_ref_t *rbuf; /* buffer to read from disk */
int *tu32; /* temp. buffer read from disk */
int i; /* counting variables */
char read_comment[10];
herr_t ret; /* Generic return value */
/* Allocate read buffers */
rbuf = malloc(sizeof(hobj_ref_t)*SPACE1_DIM1);
tu32 = malloc(sizeof(int)*SPACE1_DIM1);
/* Open the file */
fid1 = H5Fopen(FILE1, H5F_ACC_RDWR, H5P_DEFAULT);
/* Open the dataset */
dataset=H5Dopen(fid1,"/Dataset3");
/* Read selection from disk */
ret=H5Dread(dataset,H5T_STD_REF_OBJ,H5S_ALL,H5S_ALL,H5P_DEFAULT,rbuf);
/* Open dataset object */
dset2 = H5Rdereference(dataset,H5R_OBJECT,&rbuf[0]);
/* Check information in referenced dataset */
sid1 = H5Dget_space(dset2);
ret=H5Sget_simple_extent_npoints(sid1);
/* Read from disk */
ret=H5Dread(dset2,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,tu32);
printf("Dataset data : \n");
for (i=0; i < SPACE1_DIM1 ; i++) printf (" %d ", tu32[i]);
printf("\n");
printf("\n");
/* Close dereferenced Dataset */
ret = H5Dclose(dset2);
/* Open group object */
group = H5Rdereference(dataset,H5R_OBJECT,&rbuf[2]);
/* Get group's comment */
ret=H5Gget_comment(group,".",10,read_comment);
printf("Group comment is %s \n", read_comment);
printf(" \n");
/* Close group */
ret = H5Gclose(group);
/* Open datatype object */
tid1 = H5Rdereference(dataset,H5R_OBJECT,&rbuf[3]);
/* Verify correct datatype */
{
H5T_class_t tclass;
tclass= H5Tget_class(tid1);
if ((tclass == H5T_COMPOUND))
printf ("Number of compound datatype members is %d \n", H5Tget_nmembers(tid1));
printf(" \n");
}
/* Close datatype */
ret = H5Tclose(tid1);
/* Close Dataset */
ret = H5Dclose(dataset);
/* Close file */
ret = H5Fclose(fid1);
/* Free memory buffers */
free(rbuf);
free(tu32);
return 0;
}
</PRE>
<H4><A NAME="CreateWriteRefReg">Example 11</A>. Creating and writing a reference to a region.</A></H4>
This example creates a dataset in the file. Then it creates a dataset
to store references to the dataset regions (selections).
The first selection is a 6 x 6 hyperslab.
The second selection is a point selection in the same dataset.
References to both selections are created and stored in the buffer,
and then written to the dataset in the file.
<pre>
#include <stdlib.h>
#include <hdf5.h>
#define FILE2 "trefer2.h5"
#define SPACE1_NAME "Space1"
#define SPACE1_RANK 1
#define SPACE1_DIM1 4
/* Dataset with fixed dimensions */
#define SPACE2_NAME "Space2"
#define SPACE2_RANK 2
#define SPACE2_DIM1 10
#define SPACE2_DIM2 10
/* Element selection information */
#define POINT1_NPOINTS 10
int
main(void)
{
hid_t fid1; /* HDF5 File IDs */
hid_t dset1, /* Dataset ID */
dset2; /* Dereferenced dataset ID */
hid_t sid1, /* Dataspace ID #1 */
sid2; /* Dataspace ID #2 */
hsize_t dims1[] = {SPACE1_DIM1},
dims2[] = {SPACE2_DIM1, SPACE2_DIM2};
hssize_t start[SPACE2_RANK]; /* Starting location of hyperslab */
hsize_t stride[SPACE2_RANK]; /* Stride of hyperslab */
hsize_t count[SPACE2_RANK]; /* Element count of hyperslab */
hsize_t block[SPACE2_RANK]; /* Block size of hyperslab */
hssize_t coord1[POINT1_NPOINTS][SPACE2_RANK];
/* Coordinates for point selection */
hdset_reg_ref_t *wbuf; /* buffer to write to disk */
int *dwbuf; /* Buffer for writing numeric data to disk */
int i; /* counting variables */
herr_t ret; /* Generic return value */
/* Allocate write & read buffers */
wbuf=calloc(sizeof(hdset_reg_ref_t), SPACE1_DIM1);
dwbuf=malloc(sizeof(int)*SPACE2_DIM1*SPACE2_DIM2);
/* Create file */
fid1 = H5Fcreate(FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create dataspace for datasets */
sid2 = H5Screate_simple(SPACE2_RANK, dims2, NULL);
/* Create a dataset */
dset2=H5Dcreate(fid1,"Dataset2",H5T_STD_U8LE,sid2,H5P_DEFAULT);
for(i=0; i < SPACE2_DIM1*SPACE2_DIM2; i++)
dwbuf[i]=i*3;
/* Write selection to disk */
ret=H5Dwrite(dset2,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,dwbuf);
/* Close Dataset */
ret = H5Dclose(dset2);
/* Create dataspace for the reference dataset */
sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
/* Create a dataset */
dset1=H5Dcreate(fid1,"Dataset1",H5T_STD_REF_DSETREG,sid1,H5P_DEFAULT);
/* Create references */
/* Select 6x6 hyperslab for first reference */
start[0]=2; start[1]=2;
stride[0]=1; stride[1]=1;
count[0]=6; count[1]=6;
block[0]=1; block[1]=1;
ret = H5Sselect_hyperslab(sid2,H5S_SELECT_SET,start,stride,count,block);
/* Store first dataset region */
ret = H5Rcreate(&wbuf[0],fid1,"/Dataset2",H5R_DATASET_REGION,sid2);
/* Select sequence of ten points for second reference */
coord1[0][0]=6; coord1[0][1]=9;
coord1[1][0]=2; coord1[1][1]=2;
coord1[2][0]=8; coord1[2][1]=4;
coord1[3][0]=1; coord1[3][1]=6;
coord1[4][0]=2; coord1[4][1]=8;
coord1[5][0]=3; coord1[5][1]=2;
coord1[6][0]=0; coord1[6][1]=4;
coord1[7][0]=9; coord1[7][1]=0;
coord1[8][0]=7; coord1[8][1]=1;
coord1[9][0]=3; coord1[9][1]=3;
ret = H5Sselect_elements(sid2,H5S_SELECT_SET,POINT1_NPOINTS,(const hssize_t **)coord1);
/* Store second dataset region */
ret = H5Rcreate(&wbuf[1],fid1,"/Dataset2",H5R_DATASET_REGION,sid2);
/* Write selection to disk */
ret=H5Dwrite(dset1,H5T_STD_REF_DSETREG,H5S_ALL,H5S_ALL,H5P_DEFAULT,wbuf);
/* Close all objects */
ret = H5Sclose(sid1);
ret = H5Dclose(dset1);
ret = H5Sclose(sid2);
/* Close file */
ret = H5Fclose(fid1);
free(wbuf);
free(dwbuf);
return 0;
}
</pre>
<H4><A NAME="ReadRefReg">Example 12</A>. Reading a reference to a region.</A></H4>
This example reads a dataset containing dataset region references.
It reads data from the dereferenced dataset and displays the number of
elements and raw data. Then it reads two selections:
a hyperslab selection and a point selection. The program queries a
number of points in the hyperslab and the coordinates and displays them.
Then it queries a number of selected points and their coordinates and
displays the information.
<PRE>
#include <stdlib.h>
#include <hdf5.h>
#define FILE2 "trefer2.h5"
#define NPOINTS 10
/* 1-D dataset with fixed dimensions */
#define SPACE1_NAME "Space1"
#define SPACE1_RANK 1
#define SPACE1_DIM1 4
/* 2-D dataset with fixed dimensions */
#define SPACE2_NAME "Space2"
#define SPACE2_RANK 2
#define SPACE2_DIM1 10
#define SPACE2_DIM2 10
int
main(void)
{
hid_t fid1; /* HDF5 File IDs */
hid_t dset1, /* Dataset ID */
dset2; /* Dereferenced dataset ID */
hid_t sid1, /* Dataspace ID #1 */
sid2; /* Dataspace ID #2 */
hsize_t * coords; /* Coordinate buffer */
hsize_t low[SPACE2_RANK]; /* Selection bounds */
hsize_t high[SPACE2_RANK]; /* Selection bounds */
hdset_reg_ref_t *rbuf; /* buffer to to read disk */
int *drbuf; /* Buffer for reading numeric data from disk */
int i, j; /* counting variables */
herr_t ret; /* Generic return value */
/* Output message about test being performed */
/* Allocate write & read buffers */
rbuf=malloc(sizeof(hdset_reg_ref_t)*SPACE1_DIM1);
drbuf=calloc(sizeof(int),SPACE2_DIM1*SPACE2_DIM2);
/* Open the file */
fid1 = H5Fopen(FILE2, H5F_ACC_RDWR, H5P_DEFAULT);
/* Open the dataset */
dset1=H5Dopen(fid1,"/Dataset1");
/* Read selection from disk */
ret=H5Dread(dset1,H5T_STD_REF_DSETREG,H5S_ALL,H5S_ALL,H5P_DEFAULT,rbuf);
/* Try to open objects */
dset2 = H5Rdereference(dset1,H5R_DATASET_REGION,&rbuf[0]);
/* Check information in referenced dataset */
sid1 = H5Dget_space(dset2);
ret=H5Sget_simple_extent_npoints(sid1);
printf(" Number of elements in the dataset is : %d\n",ret);
/* Read from disk */
ret=H5Dread(dset2,H5T_NATIVE_INT,H5S_ALL,H5S_ALL,H5P_DEFAULT,drbuf);
for(i=0; i < SPACE2_DIM1; i++) {
for (j=0; j < SPACE2_DIM2; j++) printf (" %d ", drbuf[i*SPACE2_DIM2+j]);
printf("\n"); }
/* Get the hyperslab selection */
sid2=H5Rget_region(dset1,H5R_DATASET_REGION,&rbuf[0]);
/* Verify correct hyperslab selected */
ret = H5Sget_select_npoints(sid2);
printf(" Number of elements in the hyperslab is : %d \n", ret);
ret = H5Sget_select_hyper_nblocks(sid2);
coords=malloc(ret*SPACE2_RANK*sizeof(hsize_t)*2); /* allocate space for the hyperslab blocks */
ret = H5Sget_select_hyper_blocklist(sid2,0,ret,coords);
printf(" Hyperslab coordinates are : \n");
printf (" ( %lu , %lu ) ( %lu , %lu ) \n", \
(unsigned long)coords[0],(unsigned long)coords[1],(unsigned long)coords[2],(unsigned long)coords[3]);
free(coords);
ret = H5Sget_select_bounds(sid2,low,high);
/* Close region space */
ret = H5Sclose(sid2);
/* Get the element selection */
sid2=H5Rget_region(dset1,H5R_DATASET_REGION,&rbuf[1]);
/* Verify correct elements selected */
ret = H5Sget_select_elem_npoints(sid2);
printf(" Number of selected elements is : %d\n", ret);
/* Allocate space for the element points */
coords= malloc(ret*SPACE2_RANK*sizeof(hsize_t));
ret = H5Sget_select_elem_pointlist(sid2,0,ret,coords);
printf(" Coordinates of selected elements are : \n");
for (i=0; i < 2*NPOINTS; i=i+2)
printf(" ( %lu , %lu ) \n", (unsigned long)coords[i],(unsigned long)coords[i+1]);
free(coords);
ret = H5Sget_select_bounds(sid2,low,high);
/* Close region space */
ret = H5Sclose(sid2);
/* Close first space */
ret = H5Sclose(sid1);
/* Close dereferenced Dataset */
ret = H5Dclose(dset2);
/* Close Dataset */
ret = H5Dclose(dset1);
/* Close file */
ret = H5Fclose(fid1);
/* Free memory buffers */
free(rbuf);
free(drbuf);
return 0;
}
</PRE>
<P>
<p align=right><font size=-1><a href="#Intro-TOC">(Return to TOC)</a></font>
<hr>
<center>
<table border=0 width=98%>
<tr><td valign=top align=left>
Introduction to HDF5 <br>
<a href="H5.user.html">HDF5 User Guide</a>
<!--
<a href="Glossary.html">Glossary</a><br>
-->
</td>
<td valign=top align=right>
<a href="RM_H5Front.html">HDF5 Reference Manual</a> <br>
<a href="index.html">Other HDF5 documents and links</a>
</td></tr>
</table>
</center>
<hr>
<address>
<table width=100% border=0>
<tr><td align=left valign=top>
<a href="mailto:hdfhelp@ncsa.uiuc.edu">HDF Help Desk</a>
<br>
Last modified: 16 October 1999
</td><td align=right valign=top>
<a href="Copyright.html">Copyright</a>
</td></tr>
</table>
</BODY>
</HTML>
|