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
|
<!doctype HTML public "-//W3C//DTD HTML 4.0 Frameset//EN">
<html>
<head>
<title>Chapter 7: HDF5 Dataspaces and Partial I/O</title>
<!--(Meta)==========================================================-->
<!--(Links)=========================================================-->
<!--( Begin styles definition )=====================================-->
<link href="ed_styles/NewUGelect.css" rel="stylesheet" type="text/css">
<!--( End styles definition )=======================================-->
</head>
<body>
<!-- #BeginLibraryItem "/ed_libs/Copyright.lbi" -->
<!--
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://www.hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-->
<!-- #EndLibraryItem --><!-- HEADER LEFT "HDF5 User's Guide" -->
<!-- HEADER RIGHT "HDF5 Dataspaces and Partial I/O" -->
<!--( TOC )=========================================================-->
<SCRIPT language="JavaScript">
<!--
document.writeln ('\
<table x-use-null-cells\
align="right"\
width="240"\
cellspacing="0"\
class="tocTable">\
<tr valign="top"> \
<td class="tocTableHeaderCell" colspan="2"> \
<span class="TableHead">Chapter Contents</span></td>\
</tr>\
-->
<!-- Table Version 3 -->\
<!--
<tr valign="top"> \
<td class="tocTableContentCell2"> \
<a href="#Intro">1.</a></td>\
<td class="tocTableContentCell3">\
<a href="#Intro">Introduction</a></td> \
</tr>\
<tr valign="top"> \
<td class="tocTableContentCell2"> \
<a href="#DSpaceFunctSums">2.</a></td>\
<td class="tocTableContentCell3">\
<a href="#DSpaceFunctSums">Dataspace (H5S) Function Summaries</a></td>\
</tr>\
<tr valign="top"> \
<td class="tocTableContentCell2"> \
<a href="#DefDataObjs">3.1</a></td>\
<td class="tocTableContentCell3">\
<a href="#DefDataObjs">Dataspace Objects</a></td> \
</tr>\
<tr valign="top"> \
<td class="tocTableContentCell2"> \
<a href="#ProgModel">3.2</a></td>\
<td class="tocTableContentCell3">\
<a href="#ProgModel">Programming Model</a></td>\
</tr>\
<tr valign="top"> \
<td class="tocTableContentCell2"> \
<a href="#DTransfer">4.</a></td>\
<td class="tocTableContentCell3">\
<a href="#DTransfer">Dataspaces and Data Transfer</a></td> \
</tr>\
<tr valign="top"> \
<td class="tocTableContentCell2"> \
<a href="#DSelectTransfer">5.</a></td>\
<td class="tocTableContentCell3">\
<a href="#DSelectTransfer">Selection Operations and Data Transfer</a></td> \
</tr>\
<tr valign="top"> \
<td class="tocTableContentCell2"> \
<a href="#DRegions">6.</a></td>\
<td class="tocTableContentCell3">\
<a href="#DRegions">References to Dataset Regions</a>\
</td>\
</tr>\
\
<tr valign="top"> \
<td class="tocTableContentCell"> \
-->
<!-- editingComment -- "tocTableContentCell" and "tocTableContentCell4" \
-->\
<!-- are the table-closing cell class.\
<td class="tocTableContentCell2"> \
-->\
<!--
<a href="#Programs">7.</a></td>\
<td class="tocTableContentCell4">\
<a href="#Programs">Sample Programs</a>\
</td></tr>\
</table>\
')
-->
</SCRIPT>
<!--(End TOC)=======================================================-->
<div align="center">
<a name="TOP">
<h2>Chapter 7<br /><font size="6">HDF5 Dataspaces and Partial I/O</font></h2>
</a>
</div>
<!--
<dir>
<h1 class="editingcomment" align="center">- - - DRAFT - - -</h1>
</dir>
-->
<a name="Intro">
<h3>7.1. Introduction</h3>
</a>
<p>The HDF5 <em>dataspace</em> is a required component of an HDF5 dataset
or attribute definition. The dataspace defines the size and shape of the
dataset or attribute raw data. In other words,
a dataspace defines the number of dimensions and the size of each dimension
of the multidimensional array in which the raw data is represented.
The dataspace must be defined when the dataset or attribute is created.</p>
<p>The <em>dataspace</em> is also used during dataset I/O operations,
defining the elements of the dataset that participate in the I/O operation.</p>
<p>This chapter explains the <em>dataspace</em> object and
its use in dataset and attribute creation and data transfer.
It also describes selection operations on a dataspace used to
implement sub-setting, sub-sampling, and scatter-gather access to datasets.
</p>
<p>The rest of this chapter is structured as follows:</p>
<ul>
<li>Section 2, “Dataspace Function Summaries,”
provides a categorized list of dataspace functions,
also known as the H5S APIs</li>
<li>Section 3, “Definition of Dataspace Objects and
the Dataspace Programming Model,”
describes dataspace objects and the programming model,
including the creation and use of dataspaces</li>
<li>Section 4, “Dataspaces and Data Transfer,”
describes the use of dataspaces in data transfer</li>
<li>Section 5, “Dataspace Selection Operations and Data
Transfer,” describes selection operations on dataspaces
and their usage in data transfer</li>
<li>Section 6, “References to Dataset Regions,”
briefly discusses references to dataset regions</li>
<li>Section 7, “Sample Programs,”
contains the full programs from which several of the code samples
in this chapter were derived</li>
</ul>
<SCRIPT language="JavaScript">
<!--
document.writeln ("
<a name="DSpaceFunctSums">
<div align="right">
<a href="#TOP"><font size=-1>(Top)</font></a>
</div>
</a>
");
-->
</SCRIPT>
<br />
<!-- NEW PAGE -->
<a name="DSpaceFunctSums">
<h3 class="pagebefore">7.2. Dataspace (H5S) Function Summaries</h3>
</a>
<p>This section provides a reference list of dataspace functions,
the H5S APIs, with brief descriptions.
The functions are presented in the following catagories:</p>
<ul>
<li>Dataspace management functions</li>
<li>Dataspace query functions</li>
<li>Dataspace selection functions: hyperslabs</li>
<li>Dataspace selection functions: points</li>
</ul>
<p>The rest of the chapter will provide examples and explanations
of how to use these functions.</p>
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="3" align="left" valign="bottom">
<b>Function Listing 1.
Dataspace management functions</b></td>
</tr>
<tr><td colspan="3"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td>
<b>C Function<br />Fortran Function</b>
</td><td> </td>
<td>
<b>Purpose</b>
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Screate<br />h5screate_f</code>
</td><td> </td>
<td>
Creates a new dataspace of a specified type.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Scopy<br />h5scopy_f</code>
</td><td> </td>
<td>
Creates an exact copy of a dataspace.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sclose<br />h5sclose_f</code>
</td><td> </td>
<td>
Releases and terminates access to a dataspace.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sdecode<br />h5sdecode_f</code>
</td><td> </td>
<td>
Decode a binary object description of a dataspace and return a new
object identifier.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sencode<br />h5sencode</code>
</td><td> </td>
<td>
Encode a dataspace object description into a binary buffer.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Screate_simple<br />h5screate_simple_f</code>
</td><td> </td>
<td>
Creates a new simple dataspace and opens it for access.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sis_simple<br />h5sis_simple_f</code>
</td><td> </td>
<td>
Determines whether a dataspace is a simple dataspace.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sextent_copy<br />h5sextent_copy_f</code>
</td><td> </td>
<td>
Copies the extent of a dataspace.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sextent_equal<br />h5sextent_equal_f</code>
</td><td> </td>
<td>
Determines whether two dataspace extents are equal.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sset_extent_simple<br />h5sset_extent_simple_f</code>
</td><td> </td>
<td>
Sets or resets the size of an existing dataspace.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sset_extent_none<br />h5sset_extent_none_f</code>
</td><td> </td>
<td>
Removes the extent from a dataspace.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="3" /></td></tr>
</table>
<br />
<br />
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="3" align="left" valign="bottom">
<b>Function Listing 2. Dataspace query functions</b></td>
</tr>
<tr><td colspan="3"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td>
<b>C Function<br />Fortran Function</b>
</td><td> </td>
<td>
<b>Purpose</b>
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sget_simple_extent_dims<br />h5sget_simple_extent_dims_f</code>
</td><td> </td>
<td>
Retrieves dataspace dimension size and maximum size.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sget_simple_extent_ndims<br />h5sget_simple_extent_ndims_f</code>
</td><td> </td>
<td>
Determines the dimensionality of a dataspace.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sget_simple_extent_npoints<br />
h5sget_simple_extent_npoints_f</code>
</td><td> </td>
<td>
Determines the number of elements in a dataspace.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sget_simple_extent_type<br />h5sget_simple_extent_type_f</code>
</td><td> </td>
<td>
Determine the current class of a dataspace.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="3" /></td></tr>
</table>
<br />
<br />
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="3" align="left" valign="bottom">
<b>Function Listing 3. Dataspace selection functions: hyperslabs
</b></td>
</tr>
<tr><td colspan="3"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td>
<b>C Function<br />Fortran Function</b>
</td><td> </td>
<td>
<b>Purpose</b>
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Soffset_simple<br />h5soffset_simple_f</code>
</td><td> </td>
<td>
Sets the offset of a simple dataspace.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sget_select_type<br />h5sget_select_type_f</code>
</td><td> </td>
<td>
Determines the type of the dataspace selection.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sget_select_hyper_nblocks<br />
h5sget_select_hyper_nblocks_f</code>
</td><td> </td>
<td>
Get number of hyperslab blocks.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sget_select_hyper_blocklist<br />
h5sget_select_hyper_blocklist_f</code>
</td><td> </td>
<td>
Gets the list of hyperslab blocks currently selected.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sget_select_bounds<br />h5sget_select_bounds_f</code>
</td><td> </td>
<td>
Gets the bounding box containing the current selection.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sselect_all<br />h5sselect_all_f</code>
</td><td> </td>
<td>
Selects the entire dataspace.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sselect_none<br />h5sselect_none_f</code>
</td><td> </td>
<td>
Resets the selection region to include no elements.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sselect_valid<br />h5sselect_valid_f</code>
</td><td> </td>
<td>
Verifies that the selection is within the extent of the dataspace.
</td>
</tr>
<!-- NEW PAGE -->
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sselect_hyperslab<br />h5sselect_hyperslab_f</code>
</td><td> </td>
<td>
Selects a hyperslab region to add to the current selected region.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="3" /></td></tr>
</table>
<br />
<br />
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="3" align="left" valign="bottom">
<b>Function Listing 4. Dataspace selection functions: points
</b></td>
</tr>
<tr><td colspan="3"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td>
<b>C Function<br />Fortran Function</b>
</td><td> </td>
<td>
<b>Purpose</b>
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sget_select_npoints<br />h5sget_select_npoints_f</code>
</td><td> </td>
<td>
Determines the number of elements in a dataspace selection.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sget_select_elem_npoints<br />h5sget_select_elem_npoints_f</code>
</td><td> </td>
<td>
Gets the number of element points in the current selection.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sget_select_elem_pointlist<br />
h5sget_select_elem_pointlist_f</code>
</td><td> </td>
<td>
Gets the list of element points currently selected.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Sselect_elements<br />h5sselect_elements_f</code>
</td><td> </td>
<td>
Selects array elements to be included in the selection for a dataspace.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="3" /></td></tr>
</table>
<br />
<SCRIPT language="JavaScript">
<!--
document.writeln ("
<a name="DefDataObjs">
<div align="right">
<a href="#TOP"><font size=-1>(Top)</font></a>
</div>
</a>
");
-->
</SCRIPT>
<br />
<!-- NEW PAGE -->
<a name="DefDataObjs">
<h3 class="pagebefore">7.3. Definition of Dataspace Objects and
the Dataspace Programming Model</h3></a>
<p>This section introduces the notion of the HDF5 dataspace object
and a programming model for creating and working with dataspaces.</p>
<h4>7.3.1. Dataspace Objects</h4>
<p>An HDF5 dataspace is a required component of an HDF5 dataset or attribute.
A dataspace defines the size and the shape of a dataset’s or an
attribute’s raw data.
Currently, HDF5 supports the following types of the dataspaces: </p>
<ul>
<li>Scalar dataspaces</li>
<li>Simple dataspaces</li>
<li>Null dataspaces</li>
</ul>
<p>A <em>scalar dataspace</em>, <code>H5S_SCALAR</code>,
represents just one element, a scalar.
Note that the datatype of this one element may be very complex,
e.g., a compound structure with members being of
any allowed HDF5 datatype, including
multidimensional arrays, strings, and nested compound structures.
By convention, the rank of a scalar dataspace is always
<code>0</code> (zero); think of it geometrically as a single,
dimensionless point, though that point may be complex.</p>
<p>A <i>simple dataspace</i>, <code>H5S_SIMPLE</code>,
is a multidimensional array of elements.
The dimensionality of the dataspace (or the rank of the array)
is fixed and is defined at creation time.
The size of each dimension can grow during the life time of the dataspace
from the <i>current size</i> up to the <i>maximum size</i>.
Both the current size and the maximum size are specified at
creation time.
The sizes of dimensions at any particular time in the life of a dataspace
are called the <i>current dimensions</i>, or the <i>dataspace extent</i>.
They can be queried along with the maximum sizes.</p>
<p>A <em>null dataspace</em>, <code>H5S_NULL</code>,
contains no data elements.
Note that no selections can be applied to a null dataset
as there is nothing to select.</p>
<p>As shown in the UML diagram in the figure below, an HDF5 simple
dataspace object has three attributes: the rank or number of dimensions;
the current sizes, expressed as an array of length
<span class="codeVar">rank</span> with each element of the array
denoting the current size of the corresponding dimension; and the
maximum sizes, expressed as an array of length
<span class="codeVar">rank</span> with each element of the array
denoting the maximum size of the corresponding dimension. </p>
<table width="400" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<table border="1">
<tr><td align="center">
<code>Simple dataspace</code>
</td></tr>
<tr><td align="left">
<code>
rank:int<br />
current_size:hsize_t[rank] <br />
maximum_size:hsize_t[rank]</code>
</td></tr>
<tr><td align="left">
</td></tr>
</table>
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 1. A simple dataspace</b> <br />
A simple dataspace is defined by its rank,
the current size of each dimension, and
the maximum size of each dimension.
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The size of a current dimension cannot be greater than
the maximum size, which can be unlimited,
specified as <code>H5S_UNLIMITED</code>.
Note that while the HDF5 file format and library impose no maximum size
on an unlimited dimension, practically speaking its size
will always be limited to the biggest integer available on the
particular system being used. </p>
<!-- editingComment
<span class="editingComment">[ [ [ Prior excessively casual phrasing replaced (...the caveat that the value of infinity is limited to...). ] ] ]</span>)
-->
<p>Dataspace rank is restricted to 32,
the standard limit in C on the rank of an array,
in the current implementation of the HDF5 Library.
The HDF5 file format, on the other hand, allows any rank up to the
maximum integer value on the system, so the library restriction can be
raised in the future if higher dimensionality is required.</p>
<p>Note that most of the time Fortran applications calling HDF5 will
work with dataspaces of rank less than or equal to seven,
since seven is the maximum number of dimensions in a Fortran array.
But dataspace rank is not limited to seven for Fortran applications.</p>
<!-- editingComment
<span class="editingComment">[ [ [ or "But with the use of XXX, Fortran applications can [easily?] work with dataspace rank of up to 32." ] ] ]</span>)
-->
<p>The current dimensions of a dataspace, also referred to as the
dataspace extent, define the bounding box for dataset elements that
can participate in I/O operations.</p>
<a name="ProgModel">
<h4>7.3.2. Programming Model</h4>
</a>
<p>
The programming model for creating and working with HDF5 dataspaces
can be summarized as follows:</p>
<ol><li>Create a dataspace</li>
<li>Use the dataspace to create a dataset in the file or
to describe a data array in memory</li>
<li>Modify the dataspace to define dataset elements that will
participate in I/O operations</li>
<li>Use the modified dataspace while reading/writing dataset raw
data or to create a region reference</li>
<li>Close the dataspace when no longer needed</li>
</ol>
<p>The rest of this section will address
steps 1, 2, and 5 of the programming model;
steps 3 and 4 will be discussed in later sections of this chapter.</p>
<h4>7.3.2.1. Creating a Dataspace</h4>
<p>A dataspace can be created by calling the
<span class="codeText">H5Screate</span> function
(<span class="codeText">h5screate_f</span> in Fortran).
Since the definition of a simple dataspace requires the specification of
dimensionality (or rank) and initial and maximum dimension sizes,
the HDF5 Library provides a <i>convenience</i> API,
<span class="codeText">H5Screate_simple</span>
(<span class="codeText">h5screate_simple_f</span>)
to create a simple dataspace in one step.</p>
<p>The following examples illustrate the usage of these APIs.</p>
<h4>7.3.2.2. Creating a Scalar Dataspace</h4>
<p>A scalar dataspace is created with the <code>H5Screate</code>
or the <code>h5screate_f</code> function.</p>
<p>In C:</p>
<pre>
hid_t space_id;
. . .
space_id = H5Screate(H5S_SCALAR);
</pre>
<p>In Fortran:</p>
<pre>
INTEGER(HID_T) :: space_id
. . .
CALL h5screate_f(H5S_SCALAR_F, space_id, error)
</pre>
<p>As mentioned above, the dataspace will contain only one element.
Scalar dataspaces are used more often for describing attributes
that have just one value, e.g. the attribute
<span class="codeText">temperature</span> with the value
<span class="codeText">celsius</span> is used to indicate that the
dataset with this attribute stores temperature values using the celsius scale.</p>
<h4>7.3.2.3. Creating a Null Dataspace</h4>
<p>A null dataspace is created with the <code>H5Screate</code>
or the <code>h5screate_f</code> function.</p>
<p>In C:</p>
<pre>
hid_t space_id;
. . .
space_id = H5Screate(H5S_NULL);
</pre>
<p>In Fortran: </p>
(<code>H5S_NULL</code> not yet implemented in Fortran.)
<pre>
INTEGER(HID_T) :: space_id
. . .
CALL h5screate_f(H5S_NULL_F, space_id, error)
</pre>
As mentioned above, the dataspace will contain no elements.
<!--
NEED MORE INFO.
SPECIFICALLY, HOW ARE SUCH DATASPACES USED?
AND WHAT ATTRIBUTES ARE RELEVANT?
-->
<h4>7.3.2.4. Creating a Simple Dataspace</h4>
<p>Let’s assume that an application wants to store a
two-dimensional array of data, A(20,100).
During the life of the application, the first dimension of the array
can grow up to 30; there is no restriction on the size of the
second dimension.
The following steps are used to declare a dataspace for the dataset
in which the array data will be stored.</p>
<p>In C:</p>
<pre>
hid_t space_id;
int rank = 2;
hsize_t current_dims[2] = {20, 100};
hsize_t max_dims[2] = {30, H5S_UNLIMITED};
. . .
space_id = H5Screate(H5S_SIMPLE);
H5Sset_extent_simple(space_id,rank,current_dims,max_dims);
</pre>
<p>In Fortran:</p>
<pre>
INTEGER(HID_T) :: space_id
INTEGER :: rank = 2
INTEGER(HSIZE_T) :: current dims = /( 20, 100)/
INTEGER(HSIZE_T) :: max_dims = /(30, H5S_UNLIMITED_F)/
INTEGER error
. . .
CALL h5screate_f(H5S_SIMPLE_F, space_id, error)
CALL h5sset_extent_simple_f(space_id, rank, current_dims, max_dims, error)
</pre>
<p>Alternatively, the convenience APIs
<span class="codeText">H5Screate_simple</span>/<span class="codeText">h5screate_simple_f</span>
can replace the <span class="codeText">H5Screate</span>/<span class="codeText">h5screate_f</span>
and <span class="codeText">H5Sset_extent_simple</span>/<span class="codeText">h5sset_extent_simple_f</span>
calls.</p>
<p>In C:</p>
<pre>
space_id = H5Screate_simple(rank, current_dims, max_dims);
</pre>
<p>In Fortran:</p>
<pre>
CALL h5screate_simple_f(rank, current_dims, space_id, error, max_dims)
</pre>
<p>In this example, a dataspace with current dimensions of 20 by 100
is created. The first dimension can be extended only up to 30. The
second dimension, however, is declared unlimited; it can be extended
up to the largest available integer value on the system.</p>
<p>Note that when there is a difference between the current dimensions
and the maximum dimensions of an array, then chunking storage must be
used. In other words, if the number of dimensions may change over the
life of the dataset, then chunking must be used. If the array dimensions
are fixed (if the number of current dimensions is equal to the maximum
number of dimensions when the dataset is created), then contiguous
storage can be used. See the “
<a href="10_Datasets.html#DTransfer">Data Transfer</a>”
section in the “<a href="UG_frame10Datasets.html" target=_top>
Datasets</a>” chapter.</p>
<p>Maximum dimensions can be the same as current dimensions.
In such a case, the sizes of dimensions cannot be changed during the life
of the dataspace object.
In C, <span class="codeText">NULL</span> can be used to indicate to
the <span class="codeText">H5Screate_simple</span> and
<span class="codeText">H5Sset_extent_simple</span> functions that the
maximum sizes of all dimensions are the same as the current sizes.
In Fortran, the maximum size parameter is optional for
<span class="codeText">h5screate_simple_f</span> and can be omitted
when the sizes are the same.</p>
<p>In C:</p>
<pre>
space_id = H5Screate_simple(rank, current_dims, NULL);
</pre>
<p>In Fortran:</p>
<pre>
CALL h5screate_f(rank, current_dims, space_id, error)
</pre>
<p>The created dataspace will have current and maximum dimensions
of 20 and 100 correspondingly,
and the sizes of those dimensions cannot be changed.</p>
<h4>7.3.2.5. C versus Fortran Dataspaces</h4>
<p>Dataspace dimensions are numbered from 1 to
<span class="codeVar">rank</span>. HDF5 uses C storage conventions,
assuming that the last listed dimension is the fastest-changing dimension
and the first-listed dimension is the slowest changing.
<!-- editingComment
<span class="editingComment">[ [ [ Fortran, on the other hand, .... ? ] ] ]</span>
-->
The HDF5 file format storage layout specification adheres to the C convention
and the HDF5 Library adheres to the same convention
when storing dataspace dimensions in the file.
This affects how C programs and tools interpret data written
from Fortran programs and vice versa.
The example below illustrates the issue.</p>
<p>When a Fortran application describes a dataspace to store an array
as A(20,100), it specifies the value of the first dimension to be 20
and the second to be 100.
Since Fortran stores data by columns,
the first-listed dimension with the value 20 is the fastest-changing
dimension and the last-listed dimension with the value 100 is the
slowest-changing.
In order to adhere to the HDF5 storage convention,
the HDF5 Fortran wrapper transposes dimensions,
so the first dimension becomes the last.
The dataspace dimensions stored in the file will be 100,20 instead
of 20,100 in order to correctly describe the Fortran data that is
stored in 100 columns, each containing 20 elements.</p>
<p>When a Fortran application reads the data back,
the HDF5 Fortran wrapper transposes the dimensions once more,
returning the first dimension to be 20 and the second to be 100,
describing correctly the sizes of the array that should be used
to read data in the Fortran array A(20,100).</p>
<p>When a C application reads data back,
the dimensions will come out as 100 and 20,
correctly describing the size of the array to read data into,
since the data was written as 100 records of 20 elements each.
Therefore C tools such as <span class="codeText">h5dump</span>
and <span class="codeText">h5ls</span> always display
transposed dimensions and values for the data written
by a Fortran application. </p>
<p>Consider the following simple example of equivalent
C 3 x 5 and Fortran 5 x 3 arrays.
As illustrated in the figure <!-- formerly Figure 3 -->below,
a C applications will store
a 3 x 5 2-dimensional array as three 5-element rows.
In order to store the same data in the same order,
a Fortran application must view the array as as a 5 x 3 array with
three 5-element columns.
The dataspace of this dataset, as written from Fortran,
will therefore be described as 5 x 3 in the application
but stored and described in the file according to the C convention
as a 3 x 5 array.
This ensures that C and Fortran applications will always read
the data in the order in which it was written.
The HDF5 Fortran interface handles this transposition automatically.</p>
<p>In C (from <a href="#h5_write_c"><code>h5_write.c</code></a>):</p>
<pre>
#define NX 3 /* dataset dimensions */
#define NY 5
. . .
int data[NX][NY]; /* data to write */
. . .
/*
* Data and output buffer initialization.
*/
for (j = 0; j < NX; j++) {
for (i = 0; i < NY; i++)
data[j][i] = i + 1 + j*NY;
}
/*
* 1 2 3 4 5
* 6 7 8 9 10
* 11 12 13 14 15
*/
. . .
dims[0] = NX;
dims[1] = NY;
dataspace = H5Screate_simple(RANK, dims, NULL);
</pre>
<!-- NEW PAGE -->
<p>In Fortran (from <a href="#h5_write_f90"><code>h5_write.f90</code>)</a>:</p>
<pre>
INTEGER, PARAMETER :: NX = 3
INTEGER, PARAMETER :: NY = 5
. . .
INTEGER(HSIZE_T), DIMENSION(2) :: dims = (/3,5/) ! Dataset dimensions
---
INTEGER :: data(NX,NY)
. . .
!
! Initialize data
!
do i = 1, NX
do j = 1, NY
data(i,j) = j + (i-1)*NY
enddo
enddo
!
! Data
!
! 1 2 3 4 5
! 6 7 8 9 10
! 11 12 13 14 15
. . .
CALL h5screate_simple_f(rank, dims, dspace_id, error)
</pre>
<p>In Fortran (from <a href=#h5_write_tr_f90>
<code>h5_write_tr.f90</code>):</a></p>
<pre>
INTEGER, PARAMETER :: NX = 3
INTEGER, PARAMETER :: NY = 5
. . .
INTEGER(HSIZE_T), DIMENSION(2) :: dims = (/NY, NX/) ! Dataset dimensions
. . .
!
! Initialize data
!
do i = 1, NY
do j = 1, NX
data(i,j) = i + (j-1)*NY
enddo
enddo
!
! Data
!
! 1 6 11
! 2 7 12
! 3 8 13
! 4 9 14
! 5 10 15
. . .
CALL h5screate_simple_f(rank, dims, dspace_id, error)
</pre>
<br />
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<br />
<table border="0" width="95%">
<tr align="left" valign="top">
<td width="35%">
<p>A dataset stored by a<br />C program in a 3 x 5 array:</p>
<table border="1" width="100%">
<tr align="center">
<td width="20%">1</td>
<td width="20%">2</td>
<td width="20%">3</td>
<td width="20%">4</td>
<td width="20%">5</td>
</tr>
<tr align="center">
<td width="20%">6</td>
<td width="20%">7</td>
<td width="20%">8</td>
<td width="20%">9</td>
<td width="20%">10</td>
</tr>
<tr align="center">
<td width="20%">11</td>
<td width="20%">12</td>
<td width="20%">13</td>
<td width="20%">14</td>
<td width="20%">15</td>
</tr>
</table>
</td>
<td width="15%"> </td>
<td width="45%">
<p>The same dataset stored by a<br />Fortran program in a 5 x 3 array:</p>
<table border="1" width="48%">
<tr align="center">
<td width="33%">1</td>
<td width="34%">6</td>
<td width="33%">11</td>
</tr>
<tr align="center">
<td width="33%">2</td>
<td width="34%">7</td>
<td width="33%">12</td>
</tr>
<tr align="center">
<td width="33%">3</td>
<td width="34%">8</td>
<td width="33%">13</td>
</tr>
<tr align="center">
<td width="33%">4</td>
<td width="34%">9</td>
<td width="33%">14</td>
</tr>
<tr align="center">
<td width="33%">5</td>
<td width="34%">10</td>
<td width="33%">15</td>
</tr>
</table>
</td>
<td width="5%"> </td>
</tr>
</table>
<table width="95%" align="center">
<tr>
<td align="left"><br />
The left-hand dataset above as written to an HDF5
file from C or the right-hand dataset as written from Fortran:
</td>
</tr>
</table>
<br />
<table border="1" width="95%">
<tr>
<td align="center" width="6.5%">1</td>
<td align="center" width="6.5%">2</td>
<td align="center" width="6.5%">3</td>
<td align="center" width="6.5%">4</td>
<td align="center" width="6.5%">5</td>
<td align="center" width="6.5%">6</td>
<td align="center" width="6.5%">7</td>
<td align="center" width="6.5%">8</td>
<td align="center" width="6.5%">9</td>
<td align="center" width="6.5%">10</td>
<td align="center" width="6.5%">11</td>
<td align="center" width="6.5%">12</td>
<td align="center" width="6.5%">13</td>
<td align="center" width="6.5%">14</td>
<td align="center" width="6.5%">15</td>
</tr>
</table>
<table width="95%" align="center">
<tr>
<td align="left"><br />
The left-hand dataset above as written to an HDF5
file from Fortran:
</td>
</tr>
</table>
<br />
<table border="1" width="95%">
<tr>
<td align="center" width="6.5%">1</td>
<td align="center" width="6.5%">6</td>
<td align="center" width="6.5%">11</td>
<td align="center" width="6.5%">2</td>
<td align="center" width="6.5%">7</td>
<td align="center" width="6.5%">12</td>
<td align="center" width="6.5%">3</td>
<td align="center" width="6.5%">8</td>
<td align="center" width="6.5%">13</td>
<td align="center" width="6.5%">4</td>
<td align="center" width="6.5%">9</td>
<td align="center" width="6.5%">14</td>
<td align="center" width="6.5%">5</td>
<td align="center" width="6.5%">10</td>
<td align="center" width="6.5%">15</td>
</tr>
</table>
<br />
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 2. Comparing C and Fortran dataspaces
<!-- formerly Figure 3 --></b><br />
The HDF5 Library stores arrays along the fastest-changing
dimension. This approach is often referred to as being “in
C order.” C, C++, and Java work with arrays in row-major
order. In other words, the row, or the last dimension, is the
fastest-changing dimension. Fortran, on the other hand, handles
arrays in column-major order making the column, or the first
dimension, the fastest-changing dimension. Therefore, the C and
Fortran arrays illustrated in the top portion of this figure are
stored identically in an HDF5 file. This ensures that data
written by any language can be meaningfully read, interpreted,
and manipulated by any other.
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<!-- editingComment this entire section needs to be -->
<!-- written properly then reincluded. -->
<!--
<h4>Extending a dataspace</h4>
<p>
<span class="editingComment">[ [ [ Text here describing the extension of the dataset, per the following diagram. ] ]</span>
<p>
<table x-use-null-cells
width="600"
cellspacing="0"
class="fullImgTable"
align="center">
<tr valign="top">
<td class="fullImgTableImgCell" align="center">
<img src="Images/Dspace_fig03.jpg">
</td></tr>
<tr>
<td align="center" class="fullImgTableCapCell">
<span class="figurenumber">Figure 4</span>
Extend the simple dataspace array to 12x130
-->
<!-- The next 10 lines were already commented out -->
<!-- before this entire section was removed. -->
<!--
<p align="left">
To extend (conceptual):
<br />
<code>err = H5Sset_extent_simple(id,rank,new_dims,max_dims)</code>
<br />
To extend (concrete):
<br />
<code>err = H5Sset_extent_simple(id,2,[12,130],[H5S_UNLIMITED,200])</code>
-->
<!--
</td>
</tr>
</table>
-->
<h4>7.3.2.6. Finding Dataspace Charateristics</h4>
<p>The HDF5 Library provides several APIs designed to query
the characteristics of a dataspace.</p>
<p>The function <span class="codeText">H5Sis_simple</span>
(<span class="codeText">h5sis_simple_f</span>)
returns information about the type of a dataspace.
This function is rarely used and
currently supports only simple and scalar dataspaces.</p>
<!-- editingComment
<span class="editingComment">[ [ [ Isn't that all of them? What other types are there? ] ] ]</span>
-->
<p>To find out the dimensionality, or rank, of a dataspace,
use <span class="codeText">H5Sget_simple_extent_ndims</span>
(<span class="codeText">h5sget_simple_extent_ndims_f</span>).
<span class="codeText">H5Sget_simple_extent_dims</span>
can also be used to find out the rank.
See the example below.
If both functions return <span class="codeText">0</span> for the
value of <span class="codeVar">rank</span>, then the dataspace is scalar.</p>
<p>To query the sizes of the current and maximum dimensions,
use <span class="codeText">H5Sget_simple_extent_dims</span>
(<span class="codeText">h5sget_simple_extent_dims_f)</span>. </p>
<p>The following example illustrates querying the rank and dimensions
of a dataspace using these functions. </p>
<!-- NEW PAGE -->
<p>In C:</p>
<pre>
hid_t space_id;
int rank;
hsize_t *current_dims;
hsize_t *max_dims;
---------
rank=H5Sget_simple_extent_ndims(space_id);
(or rank=H5Sget_simple_extent_dims(space_id, NULL, NULL);)
current_dims= (hsize_t)malloc(rank*sizeof(hsize_t));
max_dims=(hsize_t)malloc(rank*sizeof(hsize_t));
H5Sget_simple_extent_dims(space_id, current_dims, max_dims);
Print values here for the previous example
</pre>
<!-- editingComment
<p>In Fortran:
<pre>
Example ??????????
</pre>
-->
<SCRIPT language="JavaScript">
<!--
document.writeln ("
<a name="DTransfer">
<div align="right">
<a href="#TOP"><font size=-1>(Top)</font></a>
</div>
</a>
");
-->
</SCRIPT>
<br />
<!-- NEW PAGE -->
<a name="DTransfer">
<h3 class="pagebefore">7.4. Dataspaces and Data Transfer</h3>
</a>
<p>Read and write operations transfer data between an HDF5 file on
disk and in memory. The shape that the array data takes in the file
and in memory may be the same, but HDF5 also allows users the ability
to represent data in memory in a different shape than in the file.
If the shape of an array in the file and in memory will be the same,
then the same dataspace definition can be used for both. If the shape
of an array in memory needs to be different than the shape in the file,
then the dataspace definition for the shape of the array in memory can
be changed. During a read operation, the array will be read into the
different shape in memory, and during a write operation, the array
will be written to the file in the shape specified by the dataspace
in the file. The only qualification is that the number of elements
read or written must be the same in both the source and the destination
dataspaces.</p>
<p>Item a in the figure below shows a simple example of a read operation
in which the data is stored as a 3 by 4 array in the file (item b) on
disk, but the program wants it to be a 4 by 3 array in memory. This
is accomplished by setting the memory dataspace to describe the
desired memory layout, as in item c. The read operation reads the
data in the file array into the memory array.</p>
<table width="500" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dspace_fig4.JPG">
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 3. Data layout before and after a read operation
<!-- formerly Figure 4 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<br />
<!-- NEW PAGE -->
<table width="500" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dspace_fig5.JPG">
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 4. Moving data from disk to memory
<!-- formerly Figure 5 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>Both the source and destination are stored as contiguous blocks of storage
with the elements in the order specified by the <em>dataspace</em>.
The figure above <!-- formerly Figure 5 -->shows one way the elements might
be organized. In item a<!-- formerly Figure 5a-->,
the elements are stored as 3 blocks of 4 elements. The destination is
an array of 12 elements in memory (see item c<!-- formerly Figure 5c -->).
As the figure suggests, the transfer reads the disk blocks into a
memory buffer (see item b<!-- formerly Figure 5b-->), and then
writes the elements to the correct locations in memory. A similar
process occurs in reverse when data is written to disk.</p>
<h4>7.4.1. Data Selection</h4>
<p>In addition to rearranging data, the transfer may select the data
elements from the source and destination.</p>
<p>Data selection is implemented by creating a <em>dataspace</em>
object that describes the selected elements (within the hyper rectangle)
rather than the whole array. Two <em>dataspace</em> objects with
selections can be used in data transfers to read selected elements
from the source and write selected elements to the destination. When
data is transferred using the dataspace object, only the selected
elements will be transferred.</p>
<p>This can be used to implement partial I/O, including:</p>
<ul>
<li>Sub-setting - reading part of a large dataset</li>
<li>Sampling - reading selected elements (e.g., every second element)
of a dataset</li>
<li>Scatter-gather - read non-contiguous elements into contiguous locations
(gather) or read contiguous elements into non-contiguous locations
(scatter) or both</li>
</ul>
<p>To use selections, the following steps are followed:</p>
<ol>
<li>Get or define the dataspace for the source and destination</li>
<li>Specify one or more selections for source and destination dataspaces</li>
<li>Transfer data using the dataspaces with selections</li>
</ol>
<!-- NEW PAGE -->
<p>A selection is created by applying one or more selections to a
<em>dataspace</em>. A selection may override any other selections
(<code>H5T_SELECT_SET</code>)
or may be “Ored” with previous selections on the same dataspace
(<code>H5T_SELECT_OR</code>).
In the latter case, the resulting selection is the union of the selection and
all previously selected selections. Arbitrary sets of points from a dataspace
can be selected by specifying an appropriate set of selections.</p>
<p>Two selections are used in data transfer, so the source and destination
must be compatible, as described below.</p>
<p>There are two forms of selection, hyperslab and point. A selection must
be either a point selection or a set of hyperslab selections.
Selections cannot be mixed.</p>
<p>The definition of a selection within a dataspace, not the data
in the selection, cannot be saved to the file unless the selection
definition is saved as a region reference. See the <a href="#DRegions">
References to Dataset Regions</a> section for more information.</p>
<h4>7.4.1.1. Hyperslab selection</h4>
<p>A hyperslab is a selection of elements from a hyper rectangle.
An HDF5 hyperslab is a rectangular pattern defined by four arrays. The
four arrays are summarized in the table below <!-- formerly Table 1-->. </p>
<p>The <em>offset</em> defines the origin of the hyperslab in the original
dataspace.</p>
<p>The <em>stride</em> is the number of elements to increment between
selected elements. A stride of ‘1’ is every element, a
stride of ‘2’ is every second element, etc. Note that there
may be a different stride for each dimension of the dataspace. The
default stride is 1.</p>
<p>The <em>count</em> is the number of elements in the hyperslab selection.
When the stride is 1, the selection is a hyper rectangle with a corner at
the offset and size count[0] by count[1] by.... When stride is greater
than one, the hyperslab bounded by the offset and the corners defined
by stride[n] * count[n].</p>
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="2" align="left" valign="bottom">
<b>Table 1. Hyperslab elements</b></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="15%"><b>Parameter</b></td>
<td width="85%"><b>Description</b></td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Offset</td>
<td>The starting location for the hyperslab.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Stride</td>
<td>The number of elements to separate each element or block
to be selected.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Count</td>
<td>The number of elements or blocks to select along each
dimension.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Block</td>
<td>The size of the block selected from the dataspace.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
</table>
<br />
<p>The <em>block</em> is a count on the number of repetitions of the
hyperslab. The default block size is ‘1’, which is one
hyperslab. A block of 2 would be two hyperslabs in that dimension,
with the second starting at offset[n]+ (count[n] * stride[n]) + 1.</p>
<p>A hyperslab can be used to access a sub-set of a large dataset.
The figure below <!-- formerly Figure 6 -->shows an example of a hyperslab
that reads a rectangle from the middle of a larger two dimensional
array. The destination is the same shape as the source.</p>
<table width="500" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dspace_fig6.JPG">
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 5. Access a sub-set of data
with a hyperslab<!-- formerly Figure 6--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>Hyperslabs can be combined to select complex regions of the source and
destination. The figure below <!-- formerly Figure 7 -->shows an example
of a transfer from one non-rectangular
region into another non-rectangular region. The source is defined as the
union of two hyperslabs, and the destination is the union of three
hyperslabs.</p>
<table width="500" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dspace_fig7.JPG">
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 6. Build complex regions with
hyperslab unions<!-- formerly Figure 7--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<!-- NEW PAGE -->
<p>Hyperslabs may also be used to collect or scatter data from regular
patterns. The figure below <!-- formerly Figure 8 -->shows an example
where the source is a repeating pattern of blocks, and the destination
is a single, one dimensional array.</p>
<table width="500" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dspace_fig8.JPG">
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 7. Use hyperslabs to combine or disperse data
<!-- formerly Figure 8--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<h4>7.4.1.2. Select Points</h4>
<p>The second type of selection is an array of points, i.e., coordinates.
Essentially, this selection is a list of all the points to include.
The figure below <!-- formerly Figure 9 -->shows an example of a transfer
of seven elements from a two dimensional dataspace to a three
dimensional dataspace using a point selection to specify the points.</p>
<table width="500" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dspace_fig9.JPG">
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 8. Point selection
<!-- formerly Figure 9--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<h4>7.4.1.3. Rules for Defining Selections</h4>
<p>A selection must have the same number of dimensions (rank) as the
dataspace it is applied to, although it may select from only a small
region, e.g., a plane from a 3D dataspace. Selections do not affect the
extent of the <em>dataspace</em>, the selection may be larger than
the <em>dataspace</em>. The boundaries of selections are reconciled
with the extent at the time of the data transfer.</p>
<h4>7.4.1.4. Data Transfer with Selections</h4>
<p>A data transfer (read or write) with selections is the same as any
read or write, except the source and destination <em>dataspace</em>
have compatible selections. </p>
<p>During the data transfer, the following steps are executed by the
library:</p>
<ul>
<li>The source and destination <em>dataspaces</em> are checked to assure
that the selections are compatible.</li>
<ul>
<li>Each selection must be within the current extent of the <em>dataspace</em>.
A selection may be defined to extend outside the current extent of the
<em>dataspace</em>, but the <em>dataspace</em> cannot be accessed if the
selection is not valid at the time of the access.</li>
<li>The total number of points selected in the source and destination must
be the same. Note that the dimensionality of the source and destination can
be different (e.g., the source could be 2D, the destination 1D or 3D), and
the shape can be different, but the number of elements selected must be
the same.</li>
</ul>
<li>The data is transferred, element by element.</li>
</ul>
<p>Selections have an iteration order for the points selected, which can be
any permutation of the dimensions involved (defaulting to ‘C’
array order) or a specific order for the selected points, for selections
composed of single array elements with <code>H5Sselect_elements</code>.</p>
<p>The elements of the selections are transferred in row-major, or C order.
That is, it is assumed that the first dimension varies slowest, the second
next slowest, and so forth. For hyperslab selections, the order can be any
permutation of the dimensions involved (defaulting to ‘C’
array order). When multiple hyperslabs are combined, the hyperslabs
are coalesced into contiguous reads and writes.</p>
<p>In the case of point selections, the points are read and written in the
order specified.</p>
<h4>7.4.2. Programming Model</h4>
<h4>7.4.2.1. Selecting Hyperslabs</h4>
<p>Suppose we want to read a 3x4 hyperslab from a dataset in a file beginning
at the element <1,2> in the dataset, and read it into a 7 x 7 x 3 array
in memory. See the figure below. <!-- formerly (Figure 10).--> 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.</p>
<!-- NEW PAGE -->
<table width="400" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dspace_fig10.JPG">
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 9. Selecting a hyperslab
<!-- formerly Figure 10--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The code in the first example below <!-- formerly Figure 11 -->
illustrates the selection of the hyperslab in the
file dataspace. The second example below <!-- formerly Figure 12 -->shows
the definition of the destination dataspace in
memory. Since the in-memory dataspace has three dimensions, the hyperslab is
an array with three dimensions with the last dimension being
1: <3,4,1>. The third example below <!-- formerly Figure 13 -->
shows the read using the source and destination <em>dataspaces</em>
with selections.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
/*
* get the file dataspace.
*/
dataspace = H5Dget_space(dataset); /* dataspace identifier */
/*
* 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></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 1. Selecting a hyperslab
<!-- formerly Figure 11--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<br />
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
/*
* Define memory dataspace.
*/
dimsm[0] = 7;
dimsm[1] = 7;
dimsm[2] = 3;
memspace = H5Screate_simple(3,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></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 2. Defining the destination memory
<!-- formerly Figure 12--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<br />
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
ret = H5Dread(dataset, H5T_NATIVE_INT, memspace, dataspace, H5P_DEFAULT,
data);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 3. A sample read specifying source
and destination dataspaces
<!-- formerly Figure 13--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<h4>7.4.2.2. Example with Strides and Blocks</h4>
<p>Consider an 8 x 12 dataspace into which we want to write eight 3 x 2
blocks in a two dimensional array
from a source dataspace in memory that is a 50-element one dimensional
array.
See the figure below.<!-- formerly (Figure 14).--></p>
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<table>
<tr>
<td width="80"> </td>
<td width="440">a) The source is a 1D array with 50 elements</td>
<td width="80"> </td>
</tr>
<tr valign="top"><td> </td>
<td align="center">
<img src="Images/Dspace_fig14.JPG">
</td><td> </td></tr>
<tr>
<td width="80"> </td>
<td width="440">b) The destination on disk is a 2D array
with 48 selected elements</td>
<td width="80"> </td>
</tr>
</table>
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 10. Write from a one dimensional
array to a two dimensional array<!-- Figure 14--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The example below <!-- formerly Figure 15 -->shows code to write 48
elements from the one dimensional array to the
file dataset starting with the second element in vector. The destination
hyperslab has the following parameters: offset=(0,1), stride=(4,3),
count=(2,4), block=(3,2). The source has the parameters: offset=(1),
stride=(1), count=(48), block=(1). After these operations, the file
dataspace will have the values shown in item b in the figure above
<!-- formerly Figure 14-->. Notice that the values are inserted in
the file dataset in row-major order.</p>
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
/* Select hyperslab for the dataset in the file, using 3 x 2 blocks, (4,3) stride
* (2,4) count starting at the position (0,1).
*/
offset[0] = 0; offset[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, offset, 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
*/
offset[0] = 1;
stride[0] = 1;
count[0] = 48;
block[0] = 1;
ret = H5Sselect_hyperslab(mid1, H5S_SELECT_SET, offset, 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></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 4. Write from a one dimensional
array to a two dimensional array
<!-- formerly Figure 15--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<h4>7.4.2.3. Selecting a Union of Hyperslabs</h4>
<p>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>
<!-- NEW PAGE -->
<table width="400" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dspace_fig16a.jpg">
<br />
<img src="Images/Dspace_fig16b.jpg">
<br />
<img src="Images/Dspace_fig16c.jpg">
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 11. Transferring hyperslab unions
<!-- formerly Figure 16--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The figure above <!-- formerly Figure 16 -->shows the transfer of a
selection that is two overlapping hyperslabs
from the dataset into a union of hyperslabs in the memory dataset. Note that
the destination dataset has a different shape from the source 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,
the selection is that same shape at the destination.</p>
<p>To implement this transfer, it is necessary to:</p>
<ol>
<li>Get the source dataspace</li>
<li>Define one hyperslab selection for the source</li>
<li>Define a second hyperslab selection, unioned with the first</li>
<li>Get the destination dataspace</li>
<li>Define one hyperslab selection for the destination</li>
<li>Define a second hyperslab seletion, unioned with the first</li>
<li>Execute the data transfer (<code>H5Dread</code> or
<code>H5Dwrite</code>) using the source and
destination dataspaces</li>
</ol><br />
<p>The example below <!-- formerly Figure 17 -->shows example code to
create the selections for the source
dataspace (the file). The first hyperslab is size 3 x 4 and the left upper
corner at the position (1,2). The hyperslab is a simple rectangle, so the
stride and block are 1. The second hyperslab is 6 x 5 at the position (2,4).
The second selection is a union with the first hyperslab
(<code>H5S_SELECT_OR</code>).</p>
<br />
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
fid = H5Dget_space(dataset);
/*
* Select first hyperslab for the dataset in the file.
*
*/
offset[0] = 1; offset[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, offset, stride, count, block);
/*
* Add second selected hyperslab to the selection.
*/
offset[0] = 2; offset[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, offset, stride, count, block);</pre>
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 5. Select source hyperslabs
<!-- formerly Figure 17 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The example below <!-- formerly Figure 18 -->shows example code to
create the selection for the destination
in memory. The steps are similar. In this example, the hyperslabs are the
same shape, but located in different positions in the dataspace. The first
hyperslab is 3 x 4 and starts at (0,0), and the second is 6 x 5 and starts at (1,2).</p>
<p>Finally, the <code>H5Dread</code> call transfers the selected data from
the file dataspace
to the selection in memory.</p>
<p>In this example, the source and destination selections are two
overlapping rectangles. In general, any number of rectangles can be
OR’ed, and they do not have to be contiguous. The order of the
selections does not matter, but the first should use
<code>H5S_SELECT_SET</code>; subsequent selections are unioned
using <code>H5S_SELECT_OR</code>.</p>
<p>It is important to emphasize that the source and destination do not
have to be the same shape (or number of rectangles). As long as the two
selections have the same number of elements, the data can be transferred.</p>
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<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.
*/
offset[0] = 0; offset[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, offset, stride, count, block);
offset[0] = 1; offset[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, offset, stride, count, block);
ret = H5Dread(dataset, H5T_NATIVE_INT, mid, fid, H5P_DEFAULT, matrix_out);</pre>
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 6. Select destination hyperslabs
<!-- formerly Figure 18--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<h4>7.4.2.4. Selecting a List of Independent Points</h4>
<p>It is also possible to specify a list of elements to read or write using
the function <code>H5Sselect_elements</code>. The procedure is similar
to hyperslab selections.</p>
<ol>
<li>Get the source dataspace</li>
<li>Set the selected points</li>
<li>Get the destination dataspacev
<li>Set the selected points</li>
<li>Transfer the data using the source and destination dataspaces</li>
</ol><br />
<p>The figure below <!-- formerly Figure 19 -->shows an example where
four values are to be written to four separate points in a two
dimensional dataspace. The source dataspace is a one dimensional
array with the values 53, 59, 61, 67. The destination dataspace
is an 8 x 12 array. The elements are to be written to the points
(0,0), (3,3), (3,5), and (5,6). In this example, the source does not
require a selection. The example below the figure
<!-- formerly Figure 20 -->shows example code to implement this
transfer.</p>
<p>A point selection lists the exact points to be transferred and the order
they will be transferred. The source and destination are required to have
the same number of elements. A point selection can be used with a hyperslab
(e.g., the source could be a point selection and the destination a hyperslab,
or vice versa), so long as the number of elements selected are the same.</p>
<table width="400" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dspace_fig19a.jpg">
<br />
<img src="Images/Dspace_fig19b.jpg">
<br />
<img src="Images/Dspace_fig19c.jpg">
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 12. Write data to separate points
<!-- formerly Figure 19--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<br />
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
hsize_t dim2[] = {4};
int values[] = {53, 59, 61, 67};
hssize_t coord[4][2]; /* Array to store selected points
from the file dataspace */
/*
* Create dataspace for the second dataset.
*/
mid2 = H5Screate_simple(1, 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);
ret = H5Dwrite(dataset, H5T_NATIVE_INT, mid2, fid, H5P_DEFAULT, values);</pre>
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 7. Write data to separate points
<!-- formerly Figure 20 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<!-- NEW PAGE -->
<h4>7.4.2.5. Combinations of Selections</h4>
<p>Selections are a very flexible mechanism for reorganizing data during a
data transfer. With different combinations of <em>dataspaces</em> and
selections, it is possible to implement many kinds of data transfers
including sub-setting, sampling, and reorganizing the data. The table below
<!-- formerly Table 2 -->gives some example combinations of
source and destination, and the operations they implement.</p>
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="3" align="left" valign="bottom">
<b>Table 2. Selection operations</b></td>
</tr>
<tr><td colspan="3"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="38%"><b>Source</b></td>
<td width="37%"><b>Destination</b></td>
<td width="25%"><b>Operation</b></td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>All</td>
<td>All</td>
<td>Copy whole array</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>All</td>
<td>All (different shape)</td>
<td>Copy and reorganize array</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Hyperslab</td>
<td>All</td>
<td>Sub-set</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Hyperslab</td>
<td>Hyperslab (same shape)</td>
<td>Selection</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Hyperslab</td>
<td>Hyperslab (different shape)</td>
<td>Select and rearrange</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Hyperslab with stride or block</td>
<td>All or hyperslab with stride 1</td>
<td>Sub-sample, scatter</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Hyperslab</td>
<td>Points</td>
<td>Scatter</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Points</td>
<td>Hyperslab or all</td>
<td>Gather</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Points</td>
<td>Points (same)</td>
<td>Selection</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Points</td>
<td>Points (different)</td>
<td>Reorder points</td>
</tr>
<tr><td colspan="3"><hr color="green" size="3" /></td></tr>
</table>
<br />
<SCRIPT language="JavaScript">
<!--
document.writeln ("
<a name="DSelectTransfer">
<div align="right">
<a href="#TOP"><font size=-1>(Top)</font></a>
</div>
</a>
");
-->
</SCRIPT>
<br />
<a name="DSelectTransfer">
<h3 class="pagebefore">7.5. Dataspace Selection Operations and Data Transfer</h3>
</a>
<p><em>This section is under construction.</em></p>
<br />
<SCRIPT language="JavaScript">
<!--
document.writeln ("
<a name="DRegions">
<div align="right">
<a href="#TOP"><font size=-1>(Top)</font></a>
</div>
</a>
");
-->
</SCRIPT>
<!-- NEW PAGE -->
<a name="DRegions">
<h3 class="pagebefore">7.6. References to Dataset Regions</h3>
</a>
<p>Another use of selections is to store a reference to a region of a
dataset. An HDF5 object reference object is a pointer to an object
(dataset, group, or committed datatype) in the file. A selection can be
used to create a pointer to a set of selected elements of a
<em>dataset</em>, called a region reference. The selection can be
either a point selection or a hyperslab selection. </p>
<!-- editingComment
<span class="editingComment">
WORKING TOWARD AN IMPROVED PARAGRAPH:
In addition to the object reference, HDF5 also provides a regions reference.
An HDF5 Region Reference is a pointer to a selection within a dataset.
The selection can be either a point or hyperslab selection.
</span>
-->
A more complete description of region references can be found in the
chapter “<a href="11_Datatypes.html">HDF5 Datatypes</a>.”
<p>A region reference is an object maintained by the HDF5 Library.
The region reference can be stored in a dataset or attribute, and then read.
The dataset or attribute is defined to have the special datatype,
<code>H5T_STD_REF_DSETREG</code>. </p>
<p>To discover the elements and/or read the data, the region reference can
be dereferenced. The <code>H5Rdefrerence</code> call returns an
identifier for the <em>dataset</em>, and then the selected dataspace can
be retrieved with <code>H5Rget_select</code> call. The selected
<em>dataspace</em> can be used to read the selected data elements.</p>
<h4>7.6.1. Example Uses for Region References</h4>
<p>Region references are used to implement stored pointers to data within
a dataset. For example, features in a large dataset might be indexed
by a table. See the figure below<!-- formerly Figure 21-->. This table
could be stored as an HDF5 dataset with a compound datatype, for example,
with a field for the name of the feature and a region reference
to point to the feature in the dataset. See the second figure below.
<!-- formerly Figure 22--></p>
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dspace_fig21.JPG">
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 13. Features indexed by a table
<!-- formerly Figure 21--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<br />
<!-- NEW PAGE -->
<table width="500" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dspace_fig22.JPG">
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 14. Storing the table with a
compound datatype<!-- formerly Figure 22--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<h4>7.6.2. Creating References to Regions</h4>
<p>To create a region reference:</p>
<ol>
<li>Create or open the dataset that contains the region</li>
<li>Get the dataspace for the dataset</li>
<li>Define a selection that specifies the region</li>
<li>Create a region reference using the dataset and dataspace with
selection</li>
<li>Write the region reference(s) to the desired dataset or attribute</li>
</ol>
<p>The figure below <!-- formerly Figure 23 -->shows a diagram of a file
with three datasets. Dataset D1 and D2 are two dimensional arrays of
integers. Dataset R1 is a one dimensional array of references to
regions in D1 and D2. The regions can be any valid selection
of the dataspace of the target dataset.</p>
<!-- NEW PAGE -->
<table width="400" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
a) 1 D array of region pointers, <br />each pointer refers to a
<br />selection in one Dataset.<br />
<img src="Images/Dspace_fig23.JPG">
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 15. A file with three datasets
<!-- formerly Figure 23--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The example below <!-- formerly Figure 24 -->shows code to
create the array of region references.
The references are created in an array of type <code>hdset_reg_ref_t</code>.
Each region is defined as a selection on the dataspace of the dataset,
and a reference is created using <code>H5Rcreate()</code>. The call
to <code>H5Rcreate()</code> specifies the file, dataset, and the
dataspace with selection.</p>
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
/* create an array of 4 region references */
hdset_reg_ref_t ref[4];
/*
* Create a reference to the first hyperslab in the first Dataset.
*/
offset[0] = 1; offset[1] = 1;
count[0] = 3; count[1] = 2;
status = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, offset, NULL,
count, NULL);
status = H5Rcreate(&ref[0], file_id, "D1", H5R_DATASET_REGION,
space_id);
/*
* The second reference is to a union of hyperslabs in the first
* Dataset
*/
offset[0] = 5; offset[1] = 3;
count[0] = 1; count[1] = 4;
status = H5Sselect_none(space_id);
status = H5Sselect_hyperslab(space_id, H5S_SELECT_SET,offset,
NULL, count, NULL);
offset[0] = 6; offset[1] = 5;
count[0] = 1; count[1] = 2;
status = H5Sselect_hyperslab(space_id, H5S_SELECT_OR, offset, NULL,
count, NULL);
status = H5Rcreate(&ref[1], file_id, "D1", H5R_DATASET_REGION,
space_id);
/*
* the fourth reference is to a selection of points in the first
* Dataset
*/
status = H5Sselect_none(space_id);
coord[0][0] = 4; coord[0][1] = 4;
coord[1][0] = 2; coord[1][1] = 6;
coord[2][0] = 3; coord[2][1] = 7;
coord[3][0] = 1; coord[3][1] = 5;
coord[4][0] = 5; coord[4][1] = 8;
status = H5Sselect_elements(space_id, H5S_SELECT_SET,num_points,
(const hssize_t **)coord);
status = H5Rcreate(&ref[3], file_id, "D1", H5R_DATASET_REGION,
space_id);
/*
* the third reference is to a hyperslab in the second Dataset
*/
offset[0] = 0; offset[1] = 0;
count[0] = 4; count[1] = 6;
status = H5Sselect_hyperslab(space_id2, H5S_SELECT_SET, offset, NULL,
count, NULL);
status = H5Rcreate(&ref[2], file_id, "D2", H5R_DATASET_REGION,
space_id2);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 8. Create an array of region references
<!-- formerly Figure 24--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>When all the references are created, the array of references is written
to the dataset R1. The dataset is declared to have datatype
<code>H5T_STD_REF_DSETREG</code>. See the example below.
<!-- formerly Figure 25--></p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
Hsize_t dimsr[1];
dimsr[0] = 4;
/*
* Dataset with references.
*/
spacer_id = H5Screate_simple(1, dimsr, NULL);
dsetr_id = H5Dcreate(file_id, "R1", H5T_STD_REF_DSETREG,
spacer_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/*
* Write dataset with the references.
*/
status = H5Dwrite(dsetr_id, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL,
H5P_DEFAULT,ref);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 9. Write the array of references to a dataset
<!-- formerly Figure 25--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<p>When creating region references, the following rules are enforced.</p>
<ul>
<li>The selection must be a valid selection for the target <em>dataset</em>,
just as when transferring data</li>
<li>The <em>dataset</em> must exist in the file when the reference is
created (<code>H5Rcreate</code>)</li>
<li>The target <em>dataset</em> must be in the same file as the
stored reference</li>
</ul>
<br />
<h4>7.6.3. Reading References to Regions</h4>
<p>To retrieve data from a region reference, the reference must be read from
the file, and then the data can be retrieved. The steps are:</p>
<ol>
<li>Open the dataset or attribute containing the reference objects</li>
<li>Read the reference object(s)</li>
<li>For each region reference, get the dataset (<code>H5R_dereference</code>) and
dataspace (<code>H5Rget_space</code>)</li>
<li>Use the dataspace and datatype to discover what space is needed to
store the data, allocate the correct storage and create a dataspace
and datatype to define the memory data layout</li>
</ol>
<p>The example below <!-- formerly Figure 26 -->shows code to read an
array of region references from a
dataset, and then read the data from the first selected region. Note that the
region reference has information that records the dataset (within the file)
and the selection on the <em>dataspace</em> of the <em>dataset</em>.
After dereferencing the regions reference, the <em>datatype</em>,
number of points, and some aspects of the selection can be discovered.
(For a union of hyperslabs, it may not be possible to determine the exact
set of hyperslabs that has been combined.) The table below the code example
<!-- formerly Table 3 -->shows the inquiry functions.</p>
<!-- NEW PAGE -->
<p>When reading data from a region reference, the following rules are
enforced:</p>
<ul>
<li>The target <em>dataset</em> must be present and accessible in the
file</li>
<li>The selection must be a valid selection for the <em>dataset</em></li>
</ul>
<br />
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
dsetr_id = H5Dopen (file_id, "R1", H5P_DEFAULT);
status = H5Dread(dsetr_id, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL,
H5P_DEFAULT, ref_out);
/*
* Dereference the first reference.
* 1) get the dataset (H5Rdereference)
* 2) get the selected dataspace (H5Rget_region)
*/
dsetv_id = H5Rdereference(dsetr_id, H5R_DATASET_REGION,
&ref_out[0]);
space_id = H5Rget_region(dsetr_id, H5R_DATASET_REGION,&ref_out[0]);
/*
* Discover how many points and shape of the data
*/
ndims = H5Sget_simple_extent_ndims(space_id);
H5Sget_simple_extent_dims(space_id,dimsx,NULL);
/*
* Read and display hyperslab selection from the dataset.
*/
dimsy[0] = H5Sget_select_npoints(space_id);
spacex_id = H5Screate_simple(1, dimsy, NULL);
status = H5Dread(dsetv_id, H5T_NATIVE_INT, H5S_ALL, space_id,
H5P_DEFAULT, data_out);
printf("Selected hyperslab: ");
for (i = 0; i < 8; i++)
{
printf("\n");
for (j = 0; j < 10; j++)
printf("%d ", data_out[i][j]);
}
printf("\n");</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 10. Read an array of region references, and then
read from the first selection
<!-- formerly Figure 26--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<br />
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="2" align="left" valign="bottom">
<b>Table 3. The inquiry functions</b></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="45%"><b>Function</b></td>
<td width="55%"><b>Information</b></td>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5Sget_select_npoints</code></td>
<td>The number of elements in the selection (hyperslab
or point selection).</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5Sget_select_bounds</code></td>
<td>The bounding box that encloses the selected
points (hyperslab or point selection).</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5Sget_select_hyper_nblocks</code></td>
<td>The number of blocks in the selection.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5Sget_select_hyper_blocklist</code></td>
<td>A list of the blocks in the selection.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5Sget_select_elem_npoints</code></td>
<td>The number of points in the selection.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5Sget_select_elem_pointlist</code></td>
<td>The points.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
</table>
<br />
<SCRIPT language="JavaScript">
<!--
document.writeln ("
<a name="Programs">
<div align="right">
<a href="#TOP"><font size=-1>(Top)</font></a>
</div>
</a>
");
-->
</SCRIPT>
<br />
<!-- NEW PAGE -->
<a name="Programs">
<h3 class="pagebefore">7.7. Sample Programs</h3>
</a>
This section contains the full programs from which several of the
code examples in this chapter were derived.
The <code>h5dump</code> output from the program’s output file
immediately follows each program.
<h4>7.7.1. <a name="h5_write_c"><code>h5_write.c</code></a></h4>
<pre>
----------
#include "hdf5.h"
#define H5FILE_NAME "SDS.h5"
#define DATASETNAME "C Matrix"
#define NX 3 /* dataset dimensions */
#define NY 5
#define RANK 2
int
main (void)
{
hid_t file, dataset; /* file and dataset identifiers */
hid_t datatype, dataspace; /* identifiers */
hsize_t dims[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 + 1 + j*NY;
}
/*
* 1 2 3 4 5
* 6 7 8 9 10
* 11 12 13 14 15
*/
/*
* Create a new file using H5F_ACC_TRUNC access,
* default file creation properties, and default file
* access properties.
*/
file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/*
* Describe the size of the array and create the data space for fixed
* size dataset.
*/
dims[0] = NX;
dims[1] = NY;
dataspace = H5Screate_simple(RANK, dims, NULL);
/*
* Create a new dataset within the file using defined dataspace and
* datatype and default dataset creation properties.
*/
dataset = H5Dcreate(file, DATASETNAME, H5T_NATIVE_INT, dataspace,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);</pre>
<!-- NEW PAGE -->
<pre>
/*
* 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);
H5Dclose(dataset);
H5Fclose(file);
return 0;
}
SDS.out
-------
HDF5 "SDS.h5" {
GROUP "/" {
DATASET "C Matrix" {
DATATYPE H5T_STD_I32BE
DATASPACE SIMPLE { ( 3, 5 ) / ( 3, 5 ) }
DATA {
1, 2, 3, 4, 5,
6, 7, 8, 9, 10,
11, 12, 13, 14, 15
}
}
}
}
</pre>
<br />
<h4>7.7.2. <a name="h5_write_f90"><code>h5_write.f90</code></a></h4>
<pre>
------------
PROGRAM DSETEXAMPLE
USE HDF5 ! This module contains all necessary modules
IMPLICIT NONE
CHARACTER(LEN=7), PARAMETER :: filename = "SDSf.h5" ! File name
CHARACTER(LEN=14), PARAMETER :: dsetname = "Fortran Matrix" ! Dataset name
INTEGER, PARAMETER :: NX = 3
INTEGER, PARAMETER :: NY = 5
INTEGER(HID_T) :: file_id ! File identifier
INTEGER(HID_T) :: dset_id ! Dataset identifier
INTEGER(HID_T) :: dspace_id ! Dataspace identifier
INTEGER(HSIZE_T), DIMENSION(2) :: dims = (/3,5/) ! Dataset dimensions
INTEGER :: rank = 2 ! Dataset rank
INTEGER :: data(NX,NY)
INTEGER :: error ! Error flag
INTEGER :: i, j</pre>
<pre>
!
! Initialize data
!
do i = 1, NX
do j = 1, NY
data(i,j) = j + (i-1)*NY
enddo
enddo
!
! Data
!
! 1 2 3 4 5
! 6 7 8 9 10
! 11 12 13 14 15
!
! Initialize FORTRAN interface.
!
CALL h5open_f(error)
!
! Create a new file using default properties.
!
CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error)
!
! Create the dataspace.
!
CALL h5screate_simple_f(rank, dims, dspace_id, error)
!
! Create and write dataset using default properties.
!
CALL h5dcreate_f(file_id, dsetname, H5T_NATIVE_INTEGER, dspace_id, &
dset_id, error, H5P_DEFAULT_F, H5P_DEFAULT_F, &
H5P_DEFAULT_F)
CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, data, dims, error)
!
! End access to the dataset and release resources used by it.
!
CALL h5dclose_f(dset_id, error)
!
! Terminate access to the data space.
!
CALL h5sclose_f(dspace_id, error)
!
! Close the file.
!
CALL h5fclose_f(file_id, error)
!
! Close FORTRAN interface.
!
CALL h5close_f(error)
END PROGRAM DSETEXAMPLE</pre>
<pre>
SDSf.out
--------
HDF5 "SDSf.h5" {
GROUP "/" {
DATASET "Fortran Matrix" {
DATATYPE H5T_STD_I32BE
DATASPACE SIMPLE { ( 5, 3 ) / ( 5, 3 ) }
DATA {
1, 6, 11,
2, 7, 12,
3, 8, 13,
4, 9, 14,
5, 10, 15
}
}
}
}
</pre>
<br />
<h4>7.7.3. <a name="h5_write_tr_f90"><code>h5_write_tr.f90</code></a></h4>
<pre>
---------------
PROGRAM DSETEXAMPLE
USE HDF5 ! This module contains all necessary modules
IMPLICIT NONE
CHARACTER(LEN=10), PARAMETER :: filename = "SDSf_tr.h5" ! File name
CHARACTER(LEN=24), PARAMETER :: dsetname = "Fortran Transpose Matrix"
! Dataset name
INTEGER, PARAMETER :: NX = 3
INTEGER, PARAMETER :: NY = 5
INTEGER(HID_T) :: file_id ! File identifier
INTEGER(HID_T) :: dset_id ! Dataset identifier
INTEGER(HID_T) :: dspace_id ! Dataspace identifier
INTEGER(HSIZE_T), DIMENSION(2) :: dims = (/NY, NX/) ! Dataset dimensions
INTEGER :: rank = 2 ! Dataset rank
INTEGER :: data(NY,NX)
INTEGER :: error ! Error flag
INTEGER :: i, j
!
! Initialize data
!
do i = 1, NY
do j = 1, NX
data(i,j) = i + (j-1)*NY
enddo
enddo
!
! Data
!
! 1 6 11
! 2 7 12
! 3 8 13
! 4 9 14
! 5 10 15
!
! Initialize FORTRAN interface.
!
CALL h5open_f(error)
!
! Create a new file using default properties.
!
CALL h5fcreate_f(filename, H5F_ACC_TRUNC_F, file_id, error)
!
! Create the dataspace.
!
CALL h5screate_simple_f(rank, dims, dspace_id, error)
!
! Create and write dataset using default properties.
!
CALL h5dcreate_f(file_id, dsetname, H5T_NATIVE_INTEGER, dspace_id, &
dset_id, error, H5P_DEFAULT_F, H5P_DEFAULT_F, &
H5P_DEFAULT_F)
CALL h5dwrite_f(dset_id, H5T_NATIVE_INTEGER, data, dims, error)
!
! End access to the dataset and release resources used by it.
!
CALL h5dclose_f(dset_id, error)
!
! Terminate access to the data space.
!
CALL h5sclose_f(dspace_id, error)
!
! Close the file.
!
CALL h5fclose_f(file_id, error)
!
! Close FORTRAN interface.
!
CALL h5close_f(error)
END PROGRAM DSETEXAMPLE</pre>
<!-- NEW PAGE -->
<pre>
SDSf_tr.out
-----------
HDF5 "SDSf_tr.h5" {
GROUP "/" {
DATASET "Fortran Transpose Matrix" {
DATATYPE H5T_STD_I32LE
DATASPACE SIMPLE { ( 3, 5 ) / ( 3, 5 ) }
DATA {
1, 2, 3, 4, 5,
6, 7, 8, 9, 10,
11, 12, 13, 14, 15
}
}
}
}</pre>
<br /><br />
</body>
</html>
|