1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494
|
<!doctype HTML public "-//W3C//DTD HTML 4.0 Frameset//EN">
<html>
<head>
<title>Chapter 6: HDF5 Datatypes</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 Datatypes" -->
<!--( 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="#DtypesUsed">2.</a></td>\
<td class="tocTableContentCell3">\
<a href="#DtypesUsed">How Datatypes Are Used</a></td>\
</tr>\
<tr valign="top"> \
<td class="tocTableContentCell2"> \
<a href="#FileFunctSums">3.</a></td>\
<td class="tocTableContentCell3">\
<a href="#FileFunctSums">Datatype (H5T) Function Summaries</a></td> \
</tr>\
<tr valign="top"> \
<td class="tocTableContentCell2"> \
<a href="#Pmodel">4.</a></td>\
<td class="tocTableContentCell3">\
<a href="#Pmodel">The Programming Model</a></td>\
</tr>\
<tr valign="top"> \
<td class="tocTableContentCell2"> \
<a href="#NonNumDtypes">5.</a></td>\
<td class="tocTableContentCell3">\
<a href="#NonNumDtypes">Other Non-numeric Datatypes</a></td> \
</tr>\
<tr valign="top"> \
<td class="tocTableContentCell2"> \
<a href="#Fvalues">6.</a></td>\
<td class="tocTableContentCell3">\
<a href="#Fvalues">Fill Values</a></td>\
</tr>\
<tr valign="top"> \
<td class="tocTableContentCell2"> \
<a href="#CCDtypes">7.</a></td>\
<td class="tocTableContentCell3">\
<a href="#CCDtypes">Complex Combinations of Datatypes</a>\
</td>\
</tr>\
<tr valign="top"> \
<td class="tocTableContentCell2"> \
<a href="#LCDtypeObj">8.</a></td>\
<td class="tocTableContentCell3">\
<a href="#LCDtypeObj">Life Cycle of the Datatype Object</a>\
</td>\
</tr>\
\
<tr valign="top"> \
<td class="tocTableContentCell"> \
-->
<!-- editingComment -- "tocTableContentCell" and "tocTableContentCell4" \
\-->
<!-- are the table-closing cell class.\
<td class="tocTableContentCell2"> \
\-->
<!--
<a href="#Dtransfer">9.</a></td>\
<td class="tocTableContentCell4">\
<a href="#Dtransfer">Data Transfer: Datatype Conversion and Selection</a>\
</td></tr>\
</table>\
')
-->
<!-- </SCRIPT> -->
<!--(End TOC)=======================================================-->
<!-- editingComment
<span class="editingComment">[ [ [
] ] ]</span>
-->
<!-- editingComment
-->
<div align="center">
<a name="top">
<h2>Chapter 6<br /><font size="7">HDF5 Datatypes</font></h2>
</a>
</div>
<dir>
<!-- editingComment
<span class="editingComment">[ [ [
<h1 class=editingComment align=center>- - - DRAFT - - -</h1>
<p class="editingComment">- - - This is an early draft of the Datatypes chapter
of the new HDF5 User's Guide; much of this material will appear in the published
version of the new UG, but some will appear in other documents, such as the
HDF5 Reference Manual or the HDF5 Tutorial. A PDF version of this draft is
being made available to HDF5 users prior to publication of the new UG because
it contains a great deal of information that is not otherwise available.
] ] ]</span>
-->
</dir>
<a name="Intro">
<h3>6.1. Introduction</h3>
</a>
<h4>6.1.1. Introduction and Definitions</h4>
<p>An HDF5 dataset is an array of data elements, arranged according to the
specifications of the dataspace. In general, a data element is the smallest
addressable unit of storage in the HDF5 file. (Compound datatypes are the
exception to this rule.) The HDF5 datatype defines the storage format for a
single data element. See the figure below.</p>
<p>The model for HDF5 attributes is extremely similar to datasets:
an attribute has a dataspace and a datatype, as shown in the figure below.
The information in this chapter applies to both datasets and attributes.</p>
<table width="500" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dtypes_fig1.JPG">
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 1. Datatypes, dataspaces, and datasets</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>Abstractly, each data element within the dataset is a sequence of bits,
interpreted as a single value from a set of values (e.g., a number or a
character). For a given datatype, there is a standard or convention for
representing the values as bits, and when the bits are represented in
a particular storage the bits are laid out in a specific storage
scheme, e.g., as 8-bit bytes, with a specific ordering and alignment
of bytes within the storage array.</p>
<p>HDF5 datatypes implement a flexible, extensible, and portable mechanism
for specifying and discovering the storage layout of the data elements,
determining how to interpret the elements (e.g., as floating point numbers),
and for transferring data from different compatible layouts.</p>
<!-- NEW PAGE -->
<p>An HDF5 datatype describes one specific layout of bits. A dataset has a
single datatype which applies to every data element. When a dataset is
created, the storage datatype is defined. After the dataset or attribute
is created, the datatype cannot be changed.</p>
<ul>
<li>The datatype describes the storage layout of a single data element</li>
<li>All elements of the dataset must have the same type</li>
<li>The datatype of a dataset is immutable</li>
</ul>
<p>When data is transferred (e.g., a read or write), each end point of the
transfer has a datatype, which describes the correct storage for the elements.
The source and destination may have different (but compatible) layouts, in which
case the data elements are automatically transformed during the transfer.</p>
<p>HDF5 datatypes describe commonly used binary formats for numbers (integers
and floating point) and characters (ASCII). A given computing architecture and
programming language supports certain number and character representations.
For example, a computer may support 8-, 16-, 32-, and 64-bit signed integers,
stored in memory in little-endian byte order. These would presumably correspond
to the C programming language types ‘char’, ‘short’,
‘int’, and ‘long’.</p>
<p>When reading and writing from memory, the HDF5 library must know the
appropriate datatype that describes the architecture specific layout.
The HDF5 library provides the platform independent ‘NATIVE’
types, which are mapped to an appropriate datatype for each platform. So
the type ‘<code>H5T_NATIVE_INT</code>’ is an alias for
the appropriate descriptor for each platform.</p>
<p>Data in memory has a datatype:</p>
<ul>
<li>The storage layout in memory is architecture-specific</li>
<li>The HDF5 ‘NATIVE’ types are predefined aliases for the
architecture-specific memory layout</li>
<li>The memory datatype need not be the same as the stored datatype of
the dataset</li>
</ul>
<p>In addition to numbers and characters, an HDF5 datatype can describe more
abstract classes of types, including
<!-- date-times,
(TIME REFERENCES COMMENTED OUT 6 FEB 2006,
UNTIL TIME DATATYPE IS PROPERLY SUPPORTED IN THE LIBRARY) -->
enumerations, strings, bit strings, and references (pointers to objects
in the HDF5 file). HDF5 supports several classes of composite datatypes
which are combinations of one or more other datatypes. In addition to
the standard predefined datatypes, users can define new datatypes
within the datatype classes.</p>
<p>The HDF5 datatype model is very general and flexible:</p>
<ul>
<li>For common simple purposes, only predefined types will be needed</li>
<li>Datatypes can be combined to create complex structured datatypes</li>
<li>If needed, users can define custom atomic datatypes</li>
<li>Committed datatypes can be shared by datasets or attributes</li>
</ul>
<!-- NEW PAGE -->
<h4>6.1.2. HDF5 Datatype Model</h4>
<p>The HDF5 Library implements an object-oriented model of datatypes.
HDF5 datatypes are organized as a logical set of base types, or datatype
classes. Each datatype class defines a format for representing logical
values as a sequence of bits. For example the <code>H5T_INTEGER</code>
class is a format for representing twos complement integers of various
sizes.</p>
<p>A datatype class is defined as a set of one or more datatype properties.
A datatype property is a property of the bit string. The datatype properties
are defined by the logical model of the datatype class. For example, the
integer class (twos complement integers) has properties such as
“signed or unsigned”, “length”, and
“byte-order”. The float class (IEEE floating point
numbers) has these properties, plus “exponent bits”,
“exponent sign”, etc.</p>
<p>A datatype is derived from one datatype class: a given datatype has
a specific value for the datatype properties defined by the class.
For example, for 32-bit signed integers, stored big-endian, the HDF5
datatype is a sub-type of integer with the properties set to
<code>signed=1</code>, <code>size=4</code> (bytes), and
<code>byte-order=BE</code>.</p>
<p>The HDF5 datatype API (H5T functions) provides methods to create
datatypes of different datatype classes, to set the datatype properties
of a new datatype, and to discover the datatype properties of an
existing datatype.</p>
<p>The datatype for a dataset is stored in the HDF5 file as part of
the metadata for the dataset.</p>
<p>A datatype can be shared by more than one dataset in the file if the
datatype is saved to the file with a name. This shareable datatype is known
as a committed datatype. In the past, this kind of datatype was called
a named datatype. </p>
<p>When transferring data (e.g., a read or write), the data elements of
the source and destination storage must have compatible types. As a
general rule, data elements with the same datatype class are compatible
while elements from different datatype classes are not compatible. When
transferring data of one datatype to another compatible datatype, the
HDF5 Library uses the datatype properties of the source and
destination to automatically transform each data element. For
example, when reading from data stored as 32-bit signed integers,
big-endian into 32-bit signed integers, little-endian, the HDF5
Library will automatically swap the bytes.</p>
<p>Thus, data transfer operations (<code>H5Dread</code>,
<code>H5Dwrite</code>, <code>H5Aread</code>, <code>H5Awrite</code>) require
a datatype for both the source and the destination.</p>
<!-- NEW PAGE -->
<table width="500" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dtypes_fig2.JPG">
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 2. The datatype model</b>
<hr color="green" size="3"/></td></tr>
</table>
<br />
<p>The HDF5 Library defines a set of predefined datatypes, corresponding to
commonly used storage formats, such as twos complement integers, IEEE Floating
point numbers, etc., 4- and 8-byte sizes, big-endian and little-endian
byte orders. In addition, a user can derive types with custom values
for the properties. For example, a user program may create a datatype
to describe a 6-bit integer, or a 600-bit floating point number.</p>
<p>In addition to atomic datatypes, the HDF5 Library supports
composite datatypes. A composite datatype is an aggregation of one
or more datatypes. Each class of composite datatypes has properties
that describe the organization of the composite datatype. See the
figure below. Composite datatypes include:</p>
<ul>
<li>Compound datatypes: structured records</li>
<li>Array: a multidimensional array of a datatype</li>
<li>Variable-length: a one-dimensional array of a datatype</li>
</ul>
<br />
<!-- NEW PAGE -->
<table width="400" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dtypes_fig3.JPG">
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 3. Composite datatypes</b>
<hr color="green" size="3"/></td></tr>
</table>
<br />
<h4><em>6.1.2.1. Datatype Classes and Properties</em></h4>
<p>The figure below shows the HDF5 datatype classes. Each class is
defined to have a set of properties which describe the layout of the
data element and the interpretation of the bits. The table below
lists the properties for the datatype classes.</p>
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dtypes_fig4.JPG">
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 4. Datatype classes</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="7" align="left" valign="bottom">
<b>Table 1. Datatype classes and their properties</b></td>
</tr>
<tr><td colspan="7"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="20%"><b>Class</b></td>
<td width="2%"> </td>
<td width="18%"><b>Description</b></td>
<td width="2%"> </td>
<td width="28%"><b>Properties</b></td>
<td width="2%"> </td>
<td width="28%"><b>Notes</b></td>
</tr>
<tr><td colspan="7"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Integer</td>
<td> </td>
<td>Twos complement integers</td>
<td> </td>
<td>Size (bytes), precision (bits), offset (bits),
pad, byte order, signed/unsigned</td>
<td> </td>
<td> </td>
</tr>
<tr><td colspan="7"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Float</td>
<td> </td>
<td>Floating Point numbers</td>
<td> </td>
<td>Size (bytes), precision (bits), offset (bits),
pad, byte order, sign position, exponent position, exponent size (bits),
exponent sign, exponent bias, mantissa position, mantissa (size) bits,
mantissa sign, mantissa normalization, internal padding</td>
<td> </td>
<td>See IEEE 754 for a definition of these properties. These
properties describe non-IEEE 754 floating point formats as well.</td>
</tr>
<tr><td colspan="7"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Character</td>
<td> </td>
<td>Array of 1-byte character encoding </td>
<td> </td>
<td>Size (characters), Character set, byte order,
pad/no pad, pad character</td>
<td> </td>
<td>Currently, ASCII and UTF-8 are supported.</td>
</tr>
<tr><td colspan="7"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Bitfield</td>
<td> </td>
<td>String of bits</td>
<td> </td>
<td>Size (bytes), precision (bits), offset (bits),
pad, byte order</td>
<td> </td>
<td>A sequence of bit values packed into one or more bytes.</td>
</tr>
<tr><td colspan="7"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Opaque</td>
<td> </td>
<td>Uninterpreted data</td>
<td> </td>
<td>Size (bytes), precision (bits), offset (bits),
pad, byte order, tag</td>
<td> </td>
<td>A sequence of bytes, stored and retrieved as a block. The
‘tag’ is a string that can be used to label
the value.</td>
</tr>
<tr><td colspan="7"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Enumeration</td>
<td> </td>
<td>A list of discrete values, with symbolic names
in the form of strings.</td>
<td> </td>
<td>Number of elements, element names, element values</td>
<td> </td>
<td>Enumeration is a list of pairs, (name, value). The name is
a string, the value is an unsigned integer.</td>
</tr>
<tr><td colspan="7"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Reference</td>
<td> </td>
<td>Reference to object or region within the HDF5 file</td>
<td> </td>
<td> </td>
<td> </td>
<td> See the Reference API, H5R</td>
</tr>
<tr><td colspan="7"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Array</td>
<td> </td>
<td>Array (1-4 dimensions) of data elements</td>
<td> </td>
<td>Number of dimensions, dimension sizes, base datatype</td>
<td> </td>
<td>The array is accessed atomically: no selection or sub-setting.</td>
</tr>
<!-- NEW PAGE -->
<tr><td colspan="7"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Variable-length</td>
<td> </td>
<td>A variable-length 1-dimensional array of data data elements</td>
<td> </td>
<td>Current size, base type</td>
<td> </td>
<td> </td>
</tr>
<tr><td colspan="7"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Compound</td>
<td> </td>
<td>A Datatype of a sequence of Datatypes</td>
<td> </td>
<td>Number of members, member names, member types,
member offset, member class, member size, byte order </td>
<td> </td>
<td> </td>
</tr>
<tr><td colspan="7"><hr color="green" size="3" /></td></tr>
</table>
<br />
<h4><em>6.1.2.2. Predefined Datatypes</em></h4>
<p>The HDF5 library predefines a modest number of commonly used datatypes.
These types have standard symbolic names of the form
<code>H5T_<em>arch_base</em></code> where <em>arch</em> is an architecture
name and <em>base</em> is a programming type name (Table 2). New types can
be derived from the predefined types by copying the predefined type (see
<code>H5Tcopy()</code>) and then modifying the result. </p>
<p>The base name of most types consists of a letter to indicate the class
(Table 3), a precision in bits, and an indication of the byte order (Table 4).</p>
<p>Table 5 shows examples of predefined datatypes.
The full list can be found in the “HDF5 Predefined Datatypes”
section of the <a href="../RM/RM_H5Front.html">
<cite>HDF5 Reference Manual</cite></a>.</p>
<!-- editingComment
<span class="editingComment">[ [ [
Link to ../PredefDTypes.html
] ] ]</span>
-->
<br />
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="2" align="left" valign="bottom">
<b>Table 2. Architectures used in predefined datatypes</b></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="20%">
<b>Architecture<br />Name</b></td>
<td width="80%">
<b>Description</b></td>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>IEEE</code> </td>
<td>IEEE-754 standard floating point types in
various byte orders.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>STD</code> </td>
<td>
This is an architecture that contains semi-standard
datatypes like signed two’s complement integers, unsigned
integers, and bitfields in various byte orders.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>C <br /> FORTRAN</code> </td>
<td>Types which are specific to the C or Fortran
programming languages are defined in these architectures. For instance,
<code>H5T_C_S1</code> defines a base string type with null termination
which can be used to derive string types of other lengths.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>NATIVE</code> </td>
<td>This architecture contains C-like
datatypes for the machine on which the library was compiled. The
types were actually defined by running the <code>H5detect</code>
program when the library was compiled. In order to be portable,
applications should almost always use this architecture to describe
things in memory.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>CRAY</code> </td>
<td>Cray architectures. These are
word-addressable, big-endian systems with non-IEEE floating point.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>INTEL</code> </td>
<td>All Intel and compatible CPU’s
including 80286, 80386, 80486, Pentium, Pentium-Pro, and Pentium-II.
These are little-endian systems with IEEE floating-point.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>MIPS</code> </td>
<td>All MIPS CPU’s commonly used in
SGI systems. These are big-endian systems with IEEE floating-point.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>ALPHA</code> </td>
<td>All DEC Alpha CPU’s,
little-endian systems with IEEE floating-point.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
</table>
<br />
<br />
<table width="200" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="2" align="left" valign="bottom">
<b>Table 3. Base types</b></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="50">B</td>
<td width="150">Bitfield</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>F</td>
<td>Floating point</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>I</td>
<td>Signed integer</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>R</td>
<td>References</td>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>S</td>
<td>Character string</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>U</td>
<td>Unsigned integer</td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
</table>
<br />
<br />
<!-- NEW PAGE -->
<table width="200" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="2" align="left" valign="bottom">
<b>Table 4. Byte order</b></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="50">BE</td>
<td width="150">Big-endian</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>LE</td>
<td>Little-endian</td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
</table>
<br />
<br />
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="2" align="left" valign="bottom">
<b>Table 5. Some predefined datatypes</b></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="25%">
<b>Example</b></td>
<td width="75%">
<b>Description</b></td>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_IEEE_F64LE</code> </td>
<td>Eight-byte, little-endian, IEEE floating-point</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_IEEE_F32BE</code> </td>
<td>Four-byte, big-endian, IEEE floating point</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_STD_I32LE</code> </td>
<td>Four-byte, little-endian, signed two’s complement
integer</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_STD_U16BE</code> </td>
<td>Two-byte, big-endian, unsigned integer</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_C_S1</code> </td>
<td>One-byte, null-terminated string of eight-bit characters</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_INTEL_B64</code> </td>
<td>Eight-byte bit field on an Intel CPU</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_CRAY_F64</code> </td>
<td>Eight-byte Cray floating point</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_STD_ROBJ</code> </td>
<td>Reference to an entire object in a file</td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
</table>
<br />
<p>The HDF5 Library predefines a set of <code>NATIVE</code> datatypes which
are similar to C type names. The native types are set to be an alias for the
appropriate HDF5 datatype for each platform. For example,
<code>H5T_NATIVE_INT</code> corresponds to a C <code>int</code> type.
On an Intel based PC, this type is the same as <code>H5T_STD_I32LE</code>,
while on a MIPS system this would be equivalent to <code>H5T_STD_I32BE</code>.
Table 6 shows examples of <code>NATIVE</code> types and corresponding
C types for a common 32-bit workstation.</p>
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="2" align="left" valign="bottom">
<b>Table 6. Native and 32-bit C datatypes</b></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td><b>Example</b></td>
<td><b>Corresponding C Type</b></td>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_CHAR</code> </td>
<td>char</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_SCHAR</code> </td>
<td>signed char</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_UCHAR</code> </td>
<td>unsigned char</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_SHORT</code> </td>
<td>short</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_USHORT</code> </td>
<td>unsigned short</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_INT</code> </td>
<td>int</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_UINT</code> </td>
<td>unsigned</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_LONG</code> </td>
<td>long</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_ULONG</code> </td>
<td>unsigned long</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_LLONG</code> </td>
<td>long long</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_ULLONG</code> </td>
<td>unsigned long long</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_FLOAT</code> </td>
<td>float</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_DOUBLE</code> </td>
<td>double</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_LDOUBLE</code> </td>
<td>long double</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_HSIZE</code> </td>
<td>hsize_t</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_HSSIZE</code> </td>
<td>hssize_t</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_HERR</code> </td>
<td>herr_t</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_HBOOL</code> </td>
<td>hbool_t</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_B8</code> </td>
<td>8-bit unsigned integer or 8-bit buffer in memory</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_B16</code> </td>
<td>16-bit unsigned integer or 16-bit buffer in memory</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_B32</code> </td>
<td>32-bit unsigned integer or 32-bit buffer in memory</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_NATIVE_B64</code> </td>
<td>64-bit unsigned integer or 64-bit buffer in memory</td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
</table>
<br />
<SCRIPT language="JavaScript">
<!--
document.writeln ("
<a name="DtypesUsed">
<div align=right>
<a href="#TOP"><font size="-1">(Top)</font></a>
</div>
</a>
");
-->
</SCRIPT>
<!-- NEW PAGE -->
<a name="DtypesUsed">
<h3 class=pagebefore>6.2. How Datatypes are Used</h3>
</a>
<h4>6.2.1. The Datatype Object and the HDF5 Datatype API</h4>
<p>The HDF5 Library manages datatypes as objects. The HDF5 datatype API
manipulates the datatype objects through C function calls. New datatypes
can be created from scratch or copied from existing datatypes. When a
datatype is no longer needed its resources should be released by calling
<code>H5Tclose()</code>. </p>
<p>The datatype object is used in several roles in the HDF5 data model
and library. Essentially, a datatype is used whenever the format of
data elements is needed. There are four major uses of datatypes in
the HDF5 Library: at dataset creation, during data transfers, when
discovering the contents of a file, and for specifying user-defined
datatypes. See the table below.</p>
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="2" align="left" valign="bottom">
<b>Table 7. Datatype uses</b></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td>
<b>Use</b></td>
<td>
<b>Description</b></td>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Dataset creation</td>
<td>The datatype of the data elements must be
declared when the dataset is created.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Data transfer</td>
<td>The datatype (format) of the data elements
must be defined for both the source and destination.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Discovery</td>
<td>The datatype of a dataset can be
interrogated to retrieve a complete description of the storage layout.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Creating user-defined datatypes</td>
<td>Users can define their own datatypes by
creating datatype objects and setting their properties.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
</table>
<br />
<h4>6.2.2. Dataset Creation</h4>
<p>All the data elements of a dataset have the same datatype. When a dataset
is created, the datatype for the data elements must be specified. The
datatype of a dataset can never be changed. The example below shows
the use of a datatype to create a dataset called “/dset”. In
this example, the dataset will be stored as 32-bit signed integers in
big-endian order.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
hid_t dt;
dt = H5Tcopy(H5T_STD_I32BE);
dataset_id = H5Dcreate(file_id, “/dset”, dt, dataspace_id,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 1. Using a datatype to create a dataset </b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<h4>6.2.3. Data Transfer (Read and Write)</h4>
<p>Probably the most common use of datatypes is to write or read data from a
dataset or attribute. In these operations, each data element is transferred
from the source to the destination (possibly rearranging the order of the
elements). Since the source and destination do not need to be identical
(i.e., one is disk and the other is memory) the transfer requires both the
format of the source element and the destination element. Therefore, data
transfers use two datatype objects, for the source and destination.</p>
<p>When data is written, the source is memory and the destination is disk
(file). The memory datatype describes the format of the data element in the
machine memory, and the file datatype describes the desired format of the data
element on disk. Similarly, when reading, the source datatype describes the
format of the data element on disk, and the destination datatype describes the
format in memory.</p>
<p>In the most common cases, the file datatype is the datatype specified
when the dataset was created, and the memory datatype should be the
appropriate NATIVE type.</p>
<p>The examples below show samples of writing data to and reading data
from a dataset. The data in memory is declared C type ‘int’,
and the datatype <code>H5T_NATIVE_INT</code> corresponds to this type.
The datatype of the dataset should be of datatype class
<code>H5T_INTEGER</code>.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
int dset_data[DATA_SIZE];
status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
H5P_DEFAULT, dset_data);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 2. Writing to a dataset</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>
int dset_data[DATA_SIZE];
status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
H5P_DEFAULT, dset_data);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 3. Reading from a dataset</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<h4>6.2.4. Discovery of Data Format</h4>
<p>The HDF5 Library enables a program to determine the datatype class and
properties for any datatype. In order to discover the storage format of data
in a dataset, the datatype is obtained, and the properties are determined
by queries to the datatype object. The example below shows code that
analyzes the datatype for an integer and prints out a description of
its storage properties (byte order, signed, size.)</p>
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
switch (H5Tget_class(type)) {
case H5T_INTEGER:
ord = H5Tget_order(type);
sgn = H5Tget_sign(type);
printf(“Integer ByteOrder= ”);
switch (ord) {
case H5T_ORDER_LE:
printf(“LE”);
break;
case H5T_ORDER_BE:
printf(“BE”);
break;
}
printf(“ Sign= ”);
switch (sgn) {
case H5T_SGN_NONE:
printf(“false”);
break;
case H5T_SGN_2:
printf(“true”);
break;
}
printf(“ Size= ”);
sz = H5Tget_size(type);
printf(“%d”, sz);
printf(“\n”);
break;</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 4. Discovering datatype properties</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<h4>6.2.5. Creating and Using User-defined Datatypes</h4>
<p>Most programs will primarily use the predefined datatypes described above,
possibly in composite datatypes such as compound or array datatypes.
However, the HDF5 datatype model is extremely general; a user program can
define a great variety of atomic datatypes (storage layouts). In particular,
the datatype properties can define signed and unsigned integers of any size
and byte order, and floating point numbers with different formats, size, and
byte order. The HDF5 datatype API provides methods to set these properties.</p>
<p>User-defined types can be used to define the layout of data in memory,
e.g., to match some platform specific number format or application
defined bit-field. The user-defined type can also describe data in
the file, e.g., some application-defined format. The user-defined
types can be translated to and from standard types of the same class,
as described above.</p>
<!-- editingComment
<span class="editingComment">[ [ [
<p><em>{Simple programming example}</em>
] ] ]</span>
-->
<SCRIPT language="JavaScript">
<!--
document.writeln ("
<a name="FileFunctSums">
<div align=right>
<a href="#TOP"><font size="-1">(Top)</font></a>
</div>
</a>
");
-->
</SCRIPT>
<!-- NEW PAGE -->
<a name="FileFunctSums">
<h3 class=pagebefore>6.3. Datatype (H5T) Function Summaries</h3>
</a>
<p>Functions that can be used with datatypes (H5T functions) and property
list functions that can be used with datatypes (H5P functions) are listed
below.</p>
<br />
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="3" align="left" valign="bottom">
<b>Function Listing 1. General datatype operations
</b></td>
</tr>
<tr><td colspan="3"><hr color="green" size="3" /></td></tr>
<tr valign="top"><td width="25%"><b>C Function<br />Fortran Function</b></td>
<td width="2%"> </td>
<td width="73%"><b>Purpose</b></td>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tcreate<br />h5tcreate_f</code>
</td><td> </td>
<td>
Creates a new datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Topen<br />h5topen_f</code>
</td><td> </td>
<td>
Opens a committed datatype. The C function is a
macro: see <a href="../RM/APICompatMacros.html">“API
Compatibility Macros in HDF5.”</a>
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tcommit<br />h5tcommit_f</code>
</td><td> </td>
<td>
Commits a transient datatype to a file. The datatype is now a
committed datatype. The C function is a
macro: see <a href="../RM/APICompatMacros.html">“API
Compatibility Macros in HDF5.”</a>
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tcommit_anon<br />h5tcommit_anon_f</code>
</td><td> </td>
<td>
Commits a transient datatype to a file. The datatype is now a
committed datatype, but it is not linked into the file structure.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tcommitted<br />h5tcommitted_f</code>
</td><td> </td>
<td>
Determines whether a datatype is a committed or a transient type.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tcopy<br />h5tcopy_f</code>
</td><td> </td>
<td>
Copies an existing datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tequal<br />h5tequal_f</code>
</td><td> </td>
<td>
Determines whether two datatype identifiers refer to the same datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tlock<br />(none)</code>
</td><td> </td>
<td>
Locks a datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_class<br />h5tget_class_f</code>
</td><td> </td>
<td>
Returns the datatype class identifier.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_create_plist<br />h5tget_create_plist_f</code>
</td><td> </td>
<td>
Returns a copy of a datatype creation property list.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_size<br />h5tget_size_f</code>
</td><td> </td>
<td>
Returns the size of a datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_super<br />h5tget_super_f</code>
</td><td> </td>
<td>
Returns the base datatype from which a datatype is derived.
</td>
</tr>
<!-- NEW PAGE -->
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_native_type<br />h5tget_native_type_f</code>
</td><td> </td>
<td>
Returns the native datatype of a specified datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tdetect_class<br />(none)</code>
</td><td> </td>
<td>
Determines whether a datatype is of the given datatype class.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_order<br />h5tget_order_f</code>
</td><td> </td>
<td>
Returns the byte order of a datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tset_order<br />h5tset_order_f</code>
</td><td> </td>
<td>
Sets the byte ordering of a datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tdecode<br />h5tdecode_f</code>
</td><td> </td>
<td>
Decode a binary object description of datatype and return a new
object identifier.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tencode<br />h5tencode</code>
</td><td> </td>
<td>
Encode a datatype object description into a binary buffer.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tclose<br />h5tclose_f</code>
</td><td> </td>
<td>
Releases a datatype.
</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. Conversion 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>H5Tconvert<br />h5tconvert_f</code>
</td><td> </td>
<td>
Converts data between specified datatypes.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tcompiler_conv<br />h5tcompiler_conv_f</code>
</td><td> </td>
<td>
Check whether the librarys default conversion is hard conversion.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tfind<br />(none)</code>
</td><td> </td>
<td>
Finds a conversion function.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tregister<br />(none)</code>
</td><td> </td>
<td>
Registers a conversion function.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tunregister<br />(none)</code>
</td><td> </td>
<td>
Removes a conversion function from all conversion paths.
</td>
</tr>
<tr><td colspan="3"><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="3" align="left" valign="bottom">
<b>Function Listing 3. Atomic datatype properties
</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>H5Tset_size<br />h5tset_size_f</code>
</td><td> </td>
<td>
Sets the total size for an atomic datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_precision<br />h5tget_precision_f</code>
</td><td> </td>
<td>
Returns the precision of an atomic datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tset_precision<br />h5tset_precision_f</code>
</td><td> </td>
<td>
Sets the precision of an atomic datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_offset<br />h5tget_offset_f</code>
</td><td> </td>
<td>
Retrieves the bit offset of the first significant bit.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tset_offset<br />h5tset_offset_f</code>
</td><td> </td>
<td>
Sets the bit offset of the first significant bit.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_pad<br />h5tget_pad_f</code>
</td><td> </td>
<td>
Retrieves the padding type of the least and most-significant bit
padding.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tset_pad<br />h5tset_pad_f</code>
</td><td> </td>
<td>
Sets the least and most-significant bits padding types.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_sign<br />h5tget_sign_f</code>
</td><td> </td>
<td>
Retrieves the sign type for an integer type.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tset_sign<br />h5tset_sign_f</code>
</td><td> </td>
<td>
Sets the sign property for an integer type.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_fields<br />h5tget_fields_f</code>
</td><td> </td>
<td>
Retrieves floating point datatype bit field information.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tset_fields<br />h5tset_fields_f</code>
</td><td> </td>
<td>
Sets locations and sizes of floating point bit fields.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_ebias<br />h5tget_ebias_f</code>
</td><td> </td>
<td>
Retrieves the exponent bias of a floating-point type.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tset_ebias<br />h5tset_ebias_f</code>
</td><td> </td>
<td>
Sets the exponent bias of a floating-point type.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_norm<br />h5tget_norm_f</code>
</td><td> </td>
<td>
Retrieves mantissa normalization of a floating-point datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tset_norm<br />h5tset_norm_f</code>
</td><td> </td>
<td>
Sets the mantissa normalization of a floating-point datatype.
</td>
</tr>
<!-- NEW PAGE -->
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_inpad<br />h5tget_inpad_f</code>
</td><td> </td>
<td>
Retrieves the internal padding type for unused bits in floating-point
datatypes.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tset_inpad<br />h5tset_inpad_f</code>
</td><td> </td>
<td>
Fills unused internal floating point bits.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_cset<br />h5tget_cset_f</code>
</td><td> </td>
<td>
Retrieves the character set type of a string datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tset_cset<br />h5tset_cset_f</code>
</td><td> </td>
<td>
Sets character set to be used.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_strpad<br />h5tget_strpad_f</code>
</td><td> </td>
<td>
Retrieves the storage mechanism for a string datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tset_strpad<br />h5tset_strpad_f</code>
</td><td> </td>
<td>
Defines the storage mechanism for character strings.
</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. Enumeration datatypes
</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>H5Tenum_create<br />h5tenum_create_f</code>
</td><td> </td>
<td>
Creates a new enumeration datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tenum_insert<br />h5tenum_insert_f</code>
</td><td> </td>
<td>
Inserts a new enumeration datatype member.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tenum_nameof<br />h5tenum_nameof_f</code>
</td><td> </td>
<td>
Returns the symbol name corresponding to a specified member of an
enumeration datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tenum_valueof<br />h5tenum_valueof_f</code>
</td><td> </td>
<td>
Returns the value corresponding to a specified member of an
enumeration datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_member_value<br />h5tget_member_value_f</code>
</td><td> </td>
<td>
Returns the value of an enumeration datatype member.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_nmembers<br />h5tget_nmembers_f</code>
</td><td> </td>
<td>
Retrieves the number of elements in a compound or enumeration datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_member_name<br />h5tget_member_name_f</code>
</td><td> </td>
<td>
Retrieves the name of a compound or enumeration datatype member.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_member_index<br />(none)</code>
</td><td> </td>
<td>
Retrieves the index of a compound or enumeration datatype member.
</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 5. Compound datatype properties
</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>H5Tget_nmembers<br />h5tget_nmembers_f</code>
</td><td> </td>
<td>
Retrieves the number of elements in a compound or enumeration datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_member_class<br />h5tget_member_class_f</code>
</td><td> </td>
<td>
Returns datatype class of compound datatype member.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_member_name<br />h5tget_member_name_f</code>
</td><td> </td>
<td>
Retrieves the name of a compound or enumeration datatype member.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_member_index<br />h5tget_member_index_f</code>
</td><td> </td>
<td>
Retrieves the index of a compound or enumeration datatype member.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_member_offset<br />h5tget_member_offset_f</code>
</td><td> </td>
<td>
Retrieves the offset of a field of a compound datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_member_type<br />h5tget_member_type_f</code>
</td><td> </td>
<td>
Returns the datatype of the specified member.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tinsert<br />h5tinsert_f</code>
</td><td> </td>
<td>
Adds a new member to a compound datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tpack<br />h5tpack_f</code>
</td><td> </td>
<td>
Recursively removes padding from within a compound datatype.
</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 6. Array datatypes
</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>H5Tarray_create<br />h5tarray_create_f</code>
</td><td> </td>
<td>
Creates an array datatype object. The C function is a
macro: see <a href="../RM/APICompatMacros.html">“API
Compatibility Macros in HDF5.”</a>
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_array_ndims<br />h5tget_array_ndims_f</code>
</td><td> </td>
<td>
Returns the rank of an array datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_array_dims<br />h5tget_array_dims_f</code>
</td><td> </td>
<td>
Returns sizes of array dimensions and dimension permutations.
The C function is a
macro: see <a href="../RM/APICompatMacros.html">“API
Compatibility Macros in HDF5.”</a>
</td>
</tr>
<tr><td colspan="3"><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="3" align="left" valign="bottom">
<b>Function Listing 7. Variable-length datatypes
</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>H5Tvlen_create<br />h5tvlen_create_f</code>
</td><td> </td>
<td>
Creates a new variable-length datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tis_variable_str<br />h5tis_variable_str_f</code>
</td><td> </td>
<td>
Determines whether datatype is a variable-length string.
</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 8. Opaque datatypes
</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>H5Tset_tag<br />h5tset_tag_f</code>
</td><td> </td>
<td>
Tags an opaque datatype.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Tget_tag<br />h5tget_tag_f</code>
</td><td> </td>
<td>
Gets the tag associated with an opaque datatype.
</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 9. Conversions between datatype and text
</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>H5LTtext_to_dtype<br />(none)</code>
</td><td> </td>
<td>
Creates a datatype from a text description.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5LTdtype_to_text<br />(none)</code>
</td><td> </td>
<td>
Generates a text description of a datatype.
</td>
</tr>
<tr><td colspan="3"><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="3" align="left" valign="bottom">
<b>Function Listing 10. Datatype creation property list
functions (H5P)</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>H5Pset_char_encoding<br />h5pset_char_encoding_f</code>
</td><td> </td>
<td>
Sets the character encoding used to encode a string.
Use to set ASCII or UTF-8 character encoding for object names.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Pget_char_encoding<br />h5pget_char_encoding_f</code>
</td><td> </td>
<td>
Retrieves the character encoding used to create a string.
</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 11. Datatype access property list
functions (H5P)</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>H5Pset_type_conv_cb<br />(none)</code>
</td><td> </td>
<td>
Sets user-defined datatype conversion callback function.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>
<code>H5Pget_type_conv_cb<br />(none)</code>
</td><td> </td>
<td>
Gets user-defined datatype conversion callback function.
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="3" /></td></tr>
</table>
<br />
<br />
<SCRIPT language="JavaScript">
<!--
document.writeln ("
<a name="Pmodel">
<div align=right>
<a href="#TOP"><font size="-1">(Top)</font></a>
</div>
</a>
");
-->
</SCRIPT>
<!-- NEW PAGE -->
<a name="Pmodel">
<h3 class=pagebefore>6.4. The Programming Model</h3>
</a>
<h4>6.4.1. Introduction</h4>
<p>The HDF5 Library implements an object-oriented model of datatypes. HDF5
datatypes
are organized as a logical set of base types, or datatype classes. The HDF5
Library manages datatypes as objects. The HDF5 datatype API manipulates the
datatype objects through C function calls. The figure below shows the
abstract view
of the datatype object. The table below shows the methods (C functions)
that operate on datatype objects. New datatypes can be created from
scratch or copied from existing datatypes.</p>
<table width="550" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<table align="center" border="1">
<tr>
<td valign="middle" align="center"><code>Datatype</code></td>
</tr>
<tr>
<td valign="middle" align="left">
<code> size:int?<br />
byteOrder:BOtype</code></td>
</tr>
<tr>
<td valign="middle" align="left">
<code> open(hid_t loc, char *, name):return hid_t<br />
copy(hid_t tid) return hid_t<br />
create(hid_class_t clss, size_t size)
return hid_t </code>
</td>
</tr>
</table>
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 5. The datatype object</b>
<hr color="green" size="3"/></td></tr>
</table>
<br />
<br />
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="2" align="left" valign="bottom">
<b>Table 8. General operations on datatype objects</b></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="50%"><b>API Function</b></td>
<td width="50%"><b>Description</b></td>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>hid_t H5Tcreate (H5T_class_t
<i>class</i>, size_t <i>size</i>)</code></td>
<td>Create a new datatype object of
datatype class <i>class</i>. The following datatype classes are
supported with this function:
<ul>
<li><code>H5T_COMPOUND</code></li>
<li><code>H5T_OPAQUE</code> </li>
<li><code>H5T_ENUM </code></li>
</ul>
Other datatypes are created with <code>H5Tcopy()</code>.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>hid_t H5Tcopy (hid_t <i>type</i>)
</code></td>
<td>Obtain a modifiable transient datatype
which is a copy of <i>type</i>. If <i>type</i> is a dataset
identifier then the type returned is a modifiable transient copy
of the datatype of the specified dataset. </td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>hid_t H5Topen (hid_t <i>location</i>, <br />
const char *<i>name</i>, H5P_DEFAULT)</code></td>
<td>Open a committed datatype. The
committed datatype returned by this function is read-only.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>htri_t H5Tequal (hid_t <i>type1</i>, <br />
hid_t <i>type2</i>)</code></td>
<td>Determines if two types are equal. </td>
</tr>
<!-- NEW PAGE -->
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tclose (hid_t <i>type</i>)
</code></td>
<td>Releases resources associated with a
datatype obtained from <code>H5Tcopy</code>, <code>H5Topen</code>, or
<code>H5Tcreate</code>. It is illegal to close an
immutable transient datatype (e.g., predefined types).</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tcommit (hid_t
<i>location</i>, const char *<i>name</i>, hid_t <i>type</i>,
H5P_DEFAULT, H5P_DEFAULT, <br />H5P_DEFAULT)</code></td>
<td>Commit a transient datatype (not immutable)
to a file to become a committed datatype. Committed datatypes can be shared.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>htri_t H5Tcommitted (hid_t
<i>type</i>)</code></td>
<td>Test whether the datatype is
transient or committed (named).</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tlock (hid_t
<i>type</i>)</code></td>
<td>Make a transient datatype immutable
(read-only and not closable). Predefined types are locked.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
</table>
<br />
<p>In order to use a datatype, the object must be created
(<code>H5Tcreate</code>), or a reference obtained by cloning from an
existing type (<code>H5Tcopy</code>), or opened (<code>H5Topen</code>).
In addition, a reference to the datatype of a dataset or attribute
can be obtained with <code>H5Dget_type</code> or
<code>H5Aget_type</code>. For composite datatypes a reference
to the datatype for members or base types can be obtained
(<code>H5Tget_member_type</code>, <code>H5Tget_super</code>).
When the datatype object is no longer needed, the reference is
discarded with <code>H5Tclose</code>. </p>
<p>Two datatype objects can be tested to see if they are the same with
<code>H5Tequal</code>. This function returns true if the two datatype
references refer to the same datatype object. However, if two datatype
objects define equivalent datatypes (the same datatype class and
datatype properties), they will not be considered ‘equal’.</p>
<p>A datatype can be written to the file as a first class object
(<code>H5Tcommit</code>). This is a committed datatype and can be used
in the same way as any other datatype.</p>
<h4>6.4.2. Discovery of Datatype Properties</h4>
<p>Any HDF5 datatype object can be queried to discover all of its
datatype properties. For each datatype class, there are a set of
API functions to retrieve the datatype properties for this class. </p>
<h4>6.4.2.1. Properties of Atomic Datatypes</h4>
<p>Table 9 lists the functions to discover the properties of atomic
datatypes. Table 10 lists the queries relevant to specific numeric
types. Table 11 gives the properties for atomic string datatype, and
Table 12 gives the property of the opaque datatype.</p>
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="2" align="left" valign="bottom">
<b>Table 9. Functions to discover properties of atomic datatypes</b></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="50%"><b>Functions</b></td>
<td width="50%"><b>Description</b></td>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_class_t H5Tget_class (hid_t
<i>type</i>)</code></td>
<td>The datatype class: <code>H5T_INTEGER,
H5T_FLOAT, H5T_STRING, or H5T_BITFIELD, H5T_OPAQUE,
H5T_COMPOUND, H5T_REFERENCE, H5T_ENUM, H5T_VLEN, H5T_ARRAY</code></td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>size_t H5Tget_size
(hid_t <i>type</i>)</code></td>
<td>The total size of the element in bytes, including padding
which may appear on either side of the actual value.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_order_t H5Tget_order
(hid_t <i>type</i>)</code></td>
<td>The byte order describes how the bytes of the datatype are
laid out in memory. If the lowest memory address contains the
least significant byte of the datum then it is
said to be <i>little-endian</i> or <code>H5T_ORDER_LE</code>. If
the bytes are in the opposite order then they are said to be
<i>big-endian</i> or <code>H5T_ORDER_BE.</code></td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>size_t H5Tget_precision
(hid_t <i>type</i>)</code></td>
<td>The <code>precision</code> property identifies the number
of significant bits of a datatype and the
<code>offset</code> property (defined below) identifies its location.
Some datatypes occupy more bytes than what is needed to store the
value. For instance, a <code>short</code> on a Cray is 32 significant
bits in an eight-byte field.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>int H5Tget_offset (hid_t <i>type</i>)</code></td>
<td>The <code>offset</code> property defines the bit location
of the least significant bit of a bit
field whose length is <code>precision</code>.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tget_pad
(hid_t <i>type</i>, H5T_pad_t <i>*lsb</i>, H5T_pad_t
<i>*msb</i>)</code></td>
<td>Padding is the bits of a data element
which are not significant as defined by the <code>precision</code>
and <code>offset</code> properties. Padding in the low-numbered
bits is <i>lsb</i> padding and padding in the high-numbered
bits is <i>msb</i> padding. Padding bits can be set to zero
(<code>H5T_PAD_ZERO</code>) or one (<code>H5T_PAD_ONE</code>).</td>
</tr>
<tr><td colspan="2"><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 10. Functions to discover properties of atomic
numeric datatypes</b> </td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="50%"><b>Functions</b></td>
<td width="50%"><b>Description</b></td>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_sign_t H5Tget_sign
(hid_t <i>type</i>)</code></td>
<td><b>(INTEGER)</b> Integer data can be signed two’s
complement (<code>H5T_SGN_2</code>)
or unsigned (<code>H5T_SGN_NONE</code>).</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tget_fields
(hid_t <i>type</i>, size_t *<i>spos</i>, size_t *<i>epos</i>,
size_t *<i>esize</i>, size_t *<i>mpos</i>,
size_t *<i>msize</i>)</code> </td>
<td><b>(FLOAT)</b> A floating-point
data element has bit fields which are the exponent and mantissa
as well as a mantissa sign bit. These properties define the
location (bit position of least significant bit of the field)
and size (in bits) of each field. The sign bit is always of
length one and none of the fields are allowed to overlap.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>size_t H5Tget_ebias
(hid_t <i>type</i>)</code></td>
<td><b>(FLOAT)</b> The exponent is stored as a non-negative
value which is <code>ebias</code> larger than the true exponent. </td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_norm_t H5Tget_norm
(hid_t <i>type</i>)</code></td>
<td><b>(FLOAT)</b> This property describes the normalization
method of the mantissa.
<ul>
<li><code>H5T_NORM_MSBSET</code>: the mantissa is shifted left
(if non-zero) until the first bit after the radix point is
set and the exponent is adjusted accordingly. All bits of
the mantissa after the radix point are stored. </li>
<li><code>H5T_NORM_IMPLIED</code>: the mantissa is shifted left \
(if non-zero) until the first bit after the radix point is set
and the exponent is adjusted accordingly. The first bit after
the radix point is not stored since it’s always set. </li>
<li><code>H5T_NORM_NONE</code>: the fractional part of the
mantissa is stored without normalizing it. </li>
</ul></td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_pad_t H5Tget_inpad
(hid_t <i>type</i>)</code></td>
<td><b>(FLOAT)</b> If any internal bits (that is, bits between
the sign bit, the mantissa field, and the exponent field but
within the precision field) are unused, then they will be
filled according to the value of this property. The padding can
be: <code>H5T_PAD_NONE</code>, <code>H5T_PAD_ZERO</code>
or <code>H5T_PAD_ONE</code>.</td>
</tr>
<tr><td colspan="2"><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 11. Functions to discover properties of atomic
string datatypes</b></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="50%"><b>Functions</b></td>
<td width="50%"><b>Description</b></td>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_cset_t H5Tget_cset
(hid_t <em>type</em>)</code></td>
<td>Two character sets are currently
supported: ASCII (<code>H5T_CSET_ASCII</code>) and UTF-8
(<code>H5T_CSET_UTF8</code>).</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_str_t H5Tget_strpad
(hid_t <em>type</em>)</code></td>
<td>The string datatype has a fixed
length, but the string may be shorter than the length. This
property defines the storage mechanism for the left over bytes.
The options are: <code>H5T_STR_NULLTERM</code>,
<code>H5T_STR_NULLPAD</code>, or <code>H5T_STR_SPACEPAD</code>.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
</table>
<br />
<br />
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="2" align="left" valign="bottom">
<b>Table 12. Functions to discover properties of atomic opaque
datatypes</b></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="50%"><b>Functions</b></td>
<td width="50%"><b>Description</b></td>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>char *H5Tget_tag(hid_t type_id)</code></td>
<td>A user-defined string.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
</table>
<br />
<h4><em>6.4.2.2. Properties of Composite Datatypes</em></h4>
<p>The composite datatype classes can also be analyzed to discover their
datatype properties and the datatypes that are members or base types
of the composite datatype. The member or base type can, in turn, be
analyzed. The table below lists the functions that can access the
datatype properties of the different composite datatypes.</p>
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="2" align="left" valign="bottom">
<b>Table 13. Functions to discover properties of composite datatypes</b>
</td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="50%"><b>Functions</b></td>
<td width="50%"><b>Description</b></td>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>int H5Tget_nmembers(hid_t type_id)</code></td>
<td><b>(COMPOUND)</b>The number of fields in the compound
datatype.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>H5T_class_t H5Tget_member_class<br />
(hid_t cdtype_id, unsigned member_no)</code></td>
<td><b>(COMPOUND)</b> The datatype class of compound datatype
member <code>member_no</code>.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>char * H5Tget_member_name
(hid_t type_id, unsigned field_idx)</code></td>
<td><b>(COMPOUND)</b> The name of field <code>field_idx</code>
of a compound datatype.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>size_t H5Tget_member_offset
(hid_t type_id, unsigned memb_no)</code></td>
<td><b>(COMPOUND)</b> The byte offset
of the beginning of a field within a compound datatype.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>hid_t H5Tget_member_type
(hid_t type_id, unsigned field_idx)</code></td>
<td><b>(COMPOUND)</b> The datatype of the specified member.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>int H5Tget_array_ndims
(hid_t adtype_id)</code></td>
<td><b>(ARRAY)</b> The number of dimensions (rank) of the array
datatype object.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>int H5Tget_array_dims
(hid_t adtype_id, hsize_t *dims[])</code></td>
<td><b>(ARRAY)</b> The sizes of the dimensions and the dimension
permutations of the array datatype object.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>hid_t H5Tget_super(hid_t type)
</code></td>
<td><b>(ARRAY, VL, ENUM)</b>The base datatype from which the
datatype type is derived.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tenum_nameof(hid_t type <br />
void *value, char *name, size_t size)</code></td>
<td><b>(ENUM)</b> The symbol name
that corresponds to the specified value of the enumeration datatype</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tenum_valueof(hid_t type <br />
char *name, void *value)</code></td>
<td><b>(ENUM)</b> The value that corresponds to the specified
name of the enumeration datatype</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tget_member_value<br />
(hid_t type unsigned memb_no, <br />void *value)</code></td>
<td><b>(ENUM)</b> The value of the
enumeration datatype member <code>memb_no</code></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
</table>
<br />
<!-- NEW PAGE -->
<h4>6.4.3. Definition of Datatypes</h4>
<p>The HDF5 Library enables user programs to create and modify datatypes. The
essential steps are:
<ol>
<li>a) Create a new datatype object of a specific composite datatype class,
or <br />
b) Copy an existing atomic datatype object</li>
<li>Set properties of the datatype object</li>
<li>Use the datatype object</li>
<li>Close the datatype object</li>
</ol>
<p>To create a user-defined atomic datatype, the procedure is to clone
a predefined datatype of the appropriate datatype class
(<code>H5Tcopy</code>), and then set the datatype properties appropriate
to the datatype class. The table below shows how to create a datatype
to describe a 1024-bit unsigned integer.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
hid_t new_type = H5Tcopy (H5T_NATIVE_INT);
H5Tset_precision(new_type, 1024);
H5Tset_sign(new_type, H5T_SGN_NONE);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 5. Create a new datatype</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>Composite datatypes are created with a specific API call for each datatype
class. The table below shows the creation method for each datatype class. A
newly created
datatype cannot be used until the datatype properties are set. For example,
a newly created compound datatype has no members and cannot be used.</p>
<table width="400" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="2" align="left" valign="bottom">
<b>Table 14. Functions to create each datatype class</b></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="50%"><b>Datatype Class</b></td>
<td width="50%"><b>Function to Create</b></td>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>COMPOUND</td>
<td><code>H5Tcreate</code></td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>OPAQUE</td>
<td><code>H5Tcreate</code></td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>ENUM</td>
<td><code>H5Tenum_create</code></td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>ARRAY</td>
<td><code>H5Tarray_create</code></td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>VL</td>
<td><code>H5Tvlen_create</code></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
</table>
<br />
<p>Once the datatype is created and the datatype properties set, the datatype
object can be used. </p>
<p>Predefined datatypes are defined by the library during initialization
using the same mechanisms as described here. Each predefined datatype is
locked (<code>H5Tlock</code>), so that it cannot be changed or destroyed.
User-defined datatypes may also be locked using <code>H5Tlock</code>. </p>
<!-- NEW PAGE -->
<h4><em>6.4.3.1. User-defined Atomic Datatypes</em></h4>
<p>Table 15 summarizes the API methods that set properties of atomic
types. Table 16 shows properties specific to numeric types, Table 17
shows properties specific to the string datatype class. Note that
offset, pad, etc. do not apply to strings. Table 18 shows the specific
property of the OPAQUE datatype class.</p>
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="2" align="left" valign="bottom">
<b>Table 15. API methods that set properties of atomic datatypes</b></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="50%"><b>Functions</b></td>
<td width="50%"><b>Description</b></td>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tset_size (hid_t <i>type</i>,
<br />size_t <i>size</i>)</code></td>
<td>Set the total size of the element
in bytes. This includes padding which may appear on either side of the
actual value. If this property is reset to a smaller value which
would cause the significant part of the data to extend beyond the
edge of the datatype, then the offset property is decremented a
bit at a time. If the offset reaches zero and the significant
part of the data still extends beyond the edge of the datatype
then the precision property is decremented a bit at a time.
Decreasing the size of a datatype may fail if the
<code>H5T_FLOAT</code> bit fields would extend beyond the significant
part of the type. </td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tset_order
(hid_t <i>type</i>, H5T_order_t <i>order</i>)</code></td>
<td>Set the byte order to little-endian
(<code>H5T_ORDER_LE</code>) or big-endian (<code>H5T_ORDER_BE</code>).</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tset_precision
(hid_t <i>type</i>, size_t <i>precision</i>)</code></td>
<td>Set the number of significant bits
of a datatype. The <code>offset</code> property (defined below)
identifies its location. The size property defined above represents
the entire size (in bytes) of the datatype. If the precision is
decreased then padding bits are inserted on the MSB side of the
significant bits (this will fail for <code>H5T_FLOAT</code> types
if it results in the sign, mantissa, or exponent bit field extending
beyond the edge of the significant bit field). On the other hand,
if the precision is increased so that it “hangs over”
the edge of the total size then the offset property is decremented
a bit at a time. If the offset reaches zero and the significant
bits still hang over the edge, then the total size is increased
a byte at a time. </td>
</tr>
<!-- NEW PAGE -->
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tset_offset
(hid_t <i>type</i>, size_t <i>offset</i>)</code></td>
<td>Set the bit location of the least
significant bit of a bit field whose length is <code>precision</code>.
The bits of the entire data are numbered beginning at zero at the
least significant bit of the least significant byte (the byte at
the lowest memory address for a little-endian type or the byte
at the highest address for a big-endian type). The offset property
defines the bit location of the least significant bit of a bit field
whose length is precision. If the offset is increased so the
significant bits “hang over” the edge of the datum, then
the size property is automatically incremented.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tset_pad (hid_t
<i>type</i>, H5T_pad_t <i>lsb</i>, H5T_pad_t <i>msb</i>)</code></td>
<td>Set the padding to zeros
(<code>H5T_PAD_ZERO</code>) or ones (<code>H5T_PAD_ONE</code>). Padding
is the bits of a data element which are not significant as defined
by the <code>precision</code> and <code>offset</code> properties.
Padding in the low-numbered bits is <code><i>lsb</i></code>
padding and padding in the high-numbered bits is
<code><i>msb</i></code> padding. </td>
</tr>
<tr><td colspan="2"><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 16. API methods that set properties of numeric datatypes</b></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="50%"><b>Functions</b></td>
<td width="50%"><b>Description</b></td>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tset_sign
(hid_t <i>type</i>, H5T_sign_t <i>sign</i>)</code></td>
<td><b>(INTEGER)</b> Integer
data can be signed two’s complement (<code>H5T_SGN_2</code>)
or unsigned (<code>H5T_SGN_NONE</code>).</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tset_fields
(hid_t <i>type</i>, size_t <i>spos</i>, size_t <i>epos</i>,
size_t <i>esize</i>, size_t <i>mpos</i>, size_t <i>msize</i>)
</code></td>
<td><b>(FLOAT)</b> Set the
properties define the location (bit position of least significant
bit of the field) and size (in bits) of each field. The sign bit
is always of length one and none of the fields are allowed to overlap.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tset_ebias (hid_t <i>type</i>,
size_t <i>ebias</i>)</code></td>
<td><b>(FLOAT)</b> The exponent
is stored as a non-negative value which is <code>ebias</code> larger
than the true exponent.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tset_norm
(hid_t <i>type</i>, H5T_norm_t <i>norm</i>)</code></td>
<td><b>(FLOAT)</b> This
property describes the normalization method of the mantissa.
<ul>
<li><code>H5T_NORM_MSBSET</code>: the mantissa is shifted left
(if non-zero) until the first bit after the radix point is set and
the exponent is adjusted accordingly. All bits of the mantissa
after the radix point are stored. </li>
<li><code>H5T_NORM_IMPLIED</code>: the mantissa is shifted left
(if non-zero) until the first bit after the radix point is set and
the exponent is adjusted accordingly. The first bit after the
radix point is not stored since it is always set. </li>
<li><code>H5T_NORM_NONE</code>: the fractional part of the
mantissa is stored without normalizing it. </li></ul></td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tset_inpad
(hid_t <i>type</i>, H5T_pad_t <i>inpad</i>)</code></td>
<td><b>(FLOAT)</b> If any
internal bits (that is, bits between the sign bit, the mantissa field,
and the exponent field but within the precision field) are unused,
then they will be filled according to the value of this property.
The padding can be: <code>H5T_PAD_NONE</code>, <code>H5T_PAD_ZERO</code>
or <code>H5T_PAD_ONE</code>.</td>
</tr>
<tr><td colspan="2"><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 17. API methods that set properties of string datatypes</b></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="50%"><b>Functions</b></td>
<td width="50%"><b>Description</b></td>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tset_size (hid_t <i>type</i>,
<br />size_t <i>size</i>)</code></td>
<td>Set the length of the string, in bytes.
The precision is automatically set to 8*<code>size</code>.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tset_precision
(hid_t <i>type</i>, size_t <i>precision</i>)</code></td>
<td>The precision must be a multiple of 8.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tset_cset
(hid_t type_id, H5T_cset_t cset )</code></td>
<td>Two character sets are currently
supported: ASCII (<code>H5T_CSET_ASCII</code>) and UTF-8
(<code>H5T_CSET_UTF8</code>).</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tset_strpad
(hid_t type_id, H5T_str_t strpad )</code></td>
<td>The string datatype has a fixed
length, but the string may be shorter than the length. This property
defines the storage mechanism for the left over bytes. The method
used to store character strings differs with the programming language:
<ul>
<li>C usually null terminates strings </li>
<li>Fortran left-justifies and space-pads strings</li>
</ul>
<p>Valid string padding values, as passed in the parameter strpad,
are as follows: </p>
<dl>
<dt><code>H5T_STR_NULLTERM</code> (0)
<dd>Null terminate (as C does)
<dt><code>H5T_STR_NULLPAD</code> (1)
<dd>Pad with zeros
<dt><code>H5T_STR_SPACEPAD</code> (2)
<dd>Pad with spaces (as FORTRAN does).
</dl></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
</table>
<br />
<br />
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="2" align="left" valign="bottom">
<b>Table 18. API methods that set properties of opaque datatypes</b></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="50%"><b>Functions</b></td>
<td width="50%"><b>Description</b></td>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tset_tag (hid_t type_id
<br />const char *tag )</code></td>
<td>Tags the opaque datatype type_id
with an ASCII identifier tag.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
</table>
<br />
<!-- NEW PAGE -->
<h4>Examples</h4>
<p>The example below shows how to create a 128-bit little-endian signed
integer type. Increasing the precision of a type automatically increases
the total size. Note that the proper procedure is to begin from a type
of the intended datatype class which in this case is a
<code>NATIVE INT</code>.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
hid_t new_type = H5Tcopy (H5T_NATIVE_INT);
H5Tset_precision (new_type, 128);
H5Tset_order (new_type, H5T_ORDER_LE);</pre> </td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 6. Create a new 128-bit little-endian signed integer
datatype</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The figure below shows the storage layout as the type is defined. The
<code>H5Tcopy</code> creates a datatype that is the same as
<code>H5T_NATIVE_INT</code>. In this example, suppose this is a 32-bit
big-endian number (Figure a). The precision is set to 128 bits,
which automatically extends the size to 8 bytes (Figure b). Finally,
the byte order is set to little-endian (Figure c).</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<table align="center" border="0" width="100%">
<tr><td>
<table border="1" align="left">
<tr>
<td valign="middle" align="center"><code>Byte 0</code></td>
<td valign="middle" align="center"><code>Byte 1</code></td>
<td valign="middle" align="center"><code>Byte 2</code></td>
<td valign="middle" align="center"><code>Byte 3</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>01234567</code></td>
<td valign="middle" align="center"><code>89012345</code></td>
<td valign="middle" align="center"><code>67890123</code></td>
<td valign="middle" align="center"><code>45678901</code></td>
</tr>
</table>
</td></tr>
<tr><td>
<table border="0" align="left">
<tr>
<td>a) The <code>H5T_NATIVE_INT</code> datatype<br /> </td></tr>
</table>
</td></tr>
<tr><td>
<table border="1" align="left">
<tr>
<td valign="middle" align="center"><code>Byte 0</code></td>
<td valign="middle" align="center"><code>Byte 1</code></td>
<td valign="middle" align="center"><code>Byte 2</code></td>
<td valign="middle" align="center"><code>Byte 3</code></td>
<td valign="middle" align="center"><code>Byte 4</code></td>
<td valign="middle" align="center"><code>Byte 5</code></td>
<td valign="middle" align="center"><code>Byte 6</code></td>
<td valign="middle" align="center"><code>Byte 7</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>01234567</code></td>
<td valign="middle" align="center"><code>89012345</code></td>
<td valign="middle" align="center"><code>67890123</code></td>
<td valign="middle" align="center"><code>45678901</code></td>
<td valign="middle" align="center"><code>23456789</code></td>
<td valign="middle" align="center"><code>01234567</code></td>
<td valign="middle" align="center"><code>89012345</code></td>
<td valign="middle" align="center"><code>67890123</code></td>
</tr>
</table>
</td></tr>
<tr><td>
<table border="0" align="left">
<tr>
<td>b) Precision is extended to 128-bits, and the size is
automatically adjusted.<br /> </td></tr>
</table>
</td></tr>
<tr><td>
<table border="1" align="left">
<tr>
<td valign="middle" align="center"><code>Byte 0</code></td>
<td valign="middle" align="center"><code>Byte 1</code></td>
<td valign="middle" align="center"><code>Byte 2</code></td>
<td valign="middle" align="center"><code>Byte 3</code></td>
<td valign="middle" align="center"><code>Byte 4</code></td>
<td valign="middle" align="center"><code>Byte 5</code></td>
<td valign="middle" align="center"><code>Byte 6</code></td>
<td valign="middle" align="center"><code>Byte 7</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>01234567</code></td>
<td valign="middle" align="center"><code>89012345</code></td>
<td valign="middle" align="center"><code>67890123</code></td>
<td valign="middle" align="center"><code>45678901</code></td>
<td valign="middle" align="center"><code>23456789</code></td>
<td valign="middle" align="center"><code>01234567</code></td>
<td valign="middle" align="center"><code>89012345</code></td>
<td valign="middle" align="center"><code>67890123</code></td>
</tr>
</table>
</td></tr>
<tr><td>
<table border="0" align="left">
<tr><td>c) The byte order is switched.</td></tr>
</table>
</td></tr>
</table>
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 6. The storage layout for a new 128-bit little-endian
signed integer datatype</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The significant bits of a data element can be offset from the beginning of
the memory for that element by an amount of padding. The <code>offset</code>
property specifies the number of bits of padding that appear to the
“right of” the value. The table and figure below show how
a 32-bit unsigned integer with 16-bits of precision having the value
<code>0x1122</code> will be laid out in memory.</p>
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="5" align="left" valign="bottom">
<b>Table 19. Memory Layout for a 32-bit unsigned integer</b></td>
</tr>
<tr><td colspan="5"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td><b>Byte Position</b></td>
<td><b>Big-Endian <br />Offset=0</b></td>
<td><b>Big-Endian <br />Offset=16</b></td>
<td><b>Little-Endian <br />Offset=0</b></td>
<td><b>Little-Endian <br />Offset=16</b></td>
<tr><td colspan="5"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>0:</td>
<td>[pad]</td>
<td>[0x11]</td>
<td>[0x22]</td>
<td>[pad]</td>
</tr>
<tr><td colspan="5"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>1:</td>
<td>[pad]</td>
<td>[0x22]</td>
<td>[0x11]</td>
<td>[pad]</td>
</tr>
<tr><td colspan="5"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>2:</td>
<td>[0x11]</td>
<td>[pad]</td>
<td>[pad]</td>
<td>[0x22]</td>
</tr>
<tr><td colspan="5"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>3:</td>
<td>[0x22]</td>
<td>[pad]</td>
<td>[pad]</td>
<td>[0x11]</td>
</tr>
<tr><td colspan="5"><hr color="green" size="3" /></td></tr>
</table>
<br />
<br />
<table width="400" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<table align="center" border="0" width="100%">
<tr>
<td valign="middle" align="center">Big-Endian: Offset = 0</td>
</tr>
<tr><td>
<table border="1" align="center">
<tr>
<td valign="middle" align="center"><code>Byte 0</code></td>
<td valign="middle" align="center"><code>Byte 1</code></td>
<td valign="middle" align="center"><code>Byte 2</code></td>
<td valign="middle" align="center"><code>Byte 3</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>01234567</code></td>
<td valign="middle" align="center"><code>89012345</code></td>
<td valign="middle" align="center"><code>67890123</code></td>
<td valign="middle" align="center"><code>45678901</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code><em>PPPPPPPP</em></code></td>
<td valign="middle" align="center"><code><em>PPPPPPPP</em></code></td>
<td valign="middle" align="center"><code>00010001</code></td>
<td valign="middle" align="center"><code>00100010</code></td>
</tr>
</table>
</td></tr>
<tr>
<td valign="middle" align="center"> <br />Big-Endian: Offset = 16</td>
</tr>
<tr>
<td>
<table border="1" align="center">
<tr>
<td valign="middle" align="center"><code>Byte 0</code></td>
<td valign="middle" align="center"><code>Byte 1</code></td>
<td valign="middle" align="center"><code>Byte 2</code></td>
<td valign="middle" align="center"><code>Byte 3</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>01234567</code></td>
<td valign="middle" align="center"><code>89012345</code></td>
<td valign="middle" align="center"><code>67890123</code></td>
<td valign="middle" align="center"><code>45678901</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>00010001</code></td>
<td valign="middle" align="center"><code>00100010</code></td>
<td valign="middle" align="center"><code><em>PPPPPPPP</em></code></td>
<td valign="middle" align="center"><code><em>PPPPPPPP</em></code></td>
</tr>
</table>
</td></tr>
<tr>
<td valign="middle" align="center"> <br />Little-Endian:
Offset = 0</td>
</tr>
<tr>
<td>
<table border="1" align="center">
<tr>
<td valign="middle" align="center"><code>Byte 0</code></td>
<td valign="middle" align="center"><code>Byte 1</code></td>
<td valign="middle" align="center"><code>Byte 2</code></td>
<td valign="middle" align="center"><code>Byte 3</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>01234567</code></td>
<td valign="middle" align="center"><code>89012345</code></td>
<td valign="middle" align="center"><code>67890123</code></td>
<td valign="middle" align="center"><code>45678901</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>00010001</code></td>
<td valign="middle" align="center"><code>00100010</code></td>
<td valign="middle" align="center"><code><em>PPPPPPPP</em></code></td>
<td valign="middle" align="center"><code><em>PPPPPPPP</em></code></td>
</tr>
</table>
</td></tr>
<tr>
<td valign="middle" align="center"> <br />Little-Endian:
Offset = 16</td>
</tr>
<tr>
<td>
<table border="1" align="center">
<tr>
<td valign="middle" align="center"><code>Byte 0</code></td>
<td valign="middle" align="center"><code>Byte 1</code></td>
<td valign="middle" align="center"><code>Byte 2</code></td>
<td valign="middle" align="center"><code>Byte 3</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>01234567</code></td>
<td valign="middle" align="center"><code>89012345</code></td>
<td valign="middle" align="center"><code>67890123</code></td>
<td valign="middle" align="center"><code>45678901</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code><em>PPPPPPPP</em></code></td>
<td valign="middle" align="center"><code><em>PPPPPPPP</em></code></td>
<td valign="middle" align="center"><code>00010001</code></td>
<td valign="middle" align="center"><code>00100010</code></td>
</tr>
</table>
</td></tr>
</table>
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 7. Memory Layout for a 32-bit unsigned integer</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>If the offset is incremented then the total size is incremented also
if necessary to prevent significant bits of the value from hanging over
the edge of the datatype. </p>
<p>The bits of the entire data are numbered beginning at zero at the
least significant bit of the least significant byte (the byte at the
lowest memory address for a little-endian type or the byte at the
highest address for a big-endian type). The <code>offset</code>
property defines the bit location of the least signficant bit of a
bit field whose length is <code>precision</code>. If the offset is
increased so the significant bits “hang over” the edge
of the datum, then the <code>size</code> property is automatically
incremented. </p>
<p>To illustrate the properties of the integer datatype class, the example
below shows how to create a user-defined datatype that describes a
24-bit signed integer that starts on the third bit of a 32-bit word.
The datatype is specialized from a 32-bit integer, the <em>precision</em>
is set to 24 bits, and the <em>offset</em> is set to 3.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
hid_t dt;
dt = H5Tcopy(H5T_SDT_I32LE);
H5Tset_precision(dt, 24);
H5Tset_offset(dt,3);
H5Tset_pad(dt, H5T_PAD_ZERO, H5T_PAD_ONE);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 7. A user-defined datatype with a 24-bit signed integer</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The figure below shows the storage layout for a data element. Note that
the unused bits in the offset will be set to zero and the unused bits at
the end will be
set to one, as specified in the <code>H5Tset_pad</code> call.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<br />
<table border="1" align="center" width="67%">
<tr>
<td valign="middle" align="center"><code>Byte 0</code></td>
<td valign="middle" align="center"><code>Byte 1</code></td>
<td valign="middle" align="center"><code>Byte 2</code></td>
<td valign="middle" align="center"><code>Byte 3</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>01234567</code></td>
<td valign="middle" align="center"><code>89012345</code></td>
<td valign="middle" align="center"><code>67890123</code></td>
<td valign="middle" align="center"><code>45678901</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code><strong><em>ooo</em></strong>00000</code></td>
<td valign="middle" align="center"><code>00000000</code></td>
<td valign="middle" align="center"><code>00000000</code></td>
<td valign="middle" align="center"><code>00s<strong><em>ppppp</em></strong></code></td>
</tr>
<tr>
<td valign="middle" align="center" colspan="4">
<img src="Images/Dtypes_fig14.JPG">
</td>
</tr>
</table>
<br />
<tr><td>
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 8. A user-defined integer datatype a range of -1,048,583
to 1,048,584</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>To illustrate a user-defined floating point number, the example below
shows how to create a 24-bit floating point number that starts 5 bits
into a 4 byte word. The floating point number is defined to have a
mantissa of 19 bits (bits 5-23), an exponent of 3 bits (25-27), and
the sign bit is bit 28. (Note that this is an illustration of what
can be done and is not necessarily a floating point format that a
user would require.)</p>
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
hid_t dt;
dt = H5Tcopy(H5T_IEEE_F32LE);
H5Tset_precision(dt, 24);
H5Tset_fields (dt, 28, 25, 3, 5, 19);
H5Tset_pad(dt, H5T_PAD_ZERO, H5T_PAD_ONE);
H5Tset_inpad(dt, H5T_PAD_ZERO);</pre> </td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 8. A user-defined 24-bit floating point datatype</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<br />
<table width="500" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<table border="1" align="center" width="67%">
<tr>
<td valign="middle" align="center"><code>Byte 0</code></td>
<td valign="middle" align="center"><code>Byte 1</code></td>
<td valign="middle" align="center"><code>Byte 2</code></td>
<td valign="middle" align="center"><code>Byte 3</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>01234567</code></td>
<td valign="middle" align="center"><code>89012345</code></td>
<td valign="middle" align="center"><code>67890123</code></td>
<td valign="middle" align="center"><code>45678901</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code><strong><em>ooooo</em>
</strong>mmm</code></td>
<td valign="middle" align="center"><code>mmmmmmmm</code></td>
<td valign="middle" align="center"><code>mmmmmmmm</code></td>
<td valign="middle" align="center"><code><strong>i</strong>eees<strong>
<em>ppp</em></strong></code></td>
</tr>
<tr>
<td valign="middle" align="center" colspan="4">
<img src="Images/Dtypes_fig16.JPG">
</td>
</tr>
</table>
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 9. A user-defined floating point datatype</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The figure above shows the storage layout of a data element for this
datatype. Note that there is an unused bit (24) between the mantissa and
the exponent. This bit is filled with the <em>inpad</em> value which
in this case is 0. </p>
<p>The sign bit is always of length one and none of the fields are allowed
to overlap. When expanding a floating-point type one should set the
precision first; when decreasing the size one should set the field
positions and sizes first. </p>
<h4>6.4.3.2. Composite Datatypes</h4>
<p>All composite datatypes must be user-defined;
there are no predefined composite datatypes. </p>
<h4>6.4.3.2.1. Compound Datatypes</h4>
<p>The subsections below describe how to create a compound datatype
and how to write and read data of a compound datatype.
<h4>6.4.3.2.1.1. Defining Compound Datatypes</h4>
<p>Compound datatypes are conceptually similar to a C struct or
Fortran derived types. The compound datatype defines a contiguous
sequence of bytes, which are formatted using one up to 2^16 datatypes
(members). A compound datatype may have any number of members, in
any order, and the members may have any datatype, including compound.
Thus, complex nested compound datatypes can be created. The total
size of the compound datatype is greater than or equal to the sum
of the size of its members, up to a maximum of 2^32 bytes. HDF5 does
not support datatypes with distinguished records or the equivalent
of C unions or Fortran EQUIVALENCE statements.</p>
<p>Usually a C struct or Fortran derived type will be defined to hold
a data point in memory, and the offsets of the members in memory will
be the offsets of the struct members from the beginning of an instance
of the struct. The HDF5 C library provides a macro
<code>HOFFSET (s,m)</code> to calculate the member’s offset. The HDF5
Fortran applications have to calculate offsets by using sizes of members
datatypes and by taking in consideration the order of members in the
Fortran derived type.</p>
<dl>
<dt><code>HOFFSET(s,m)</code>
<dd>This macro computes the offset of member <em>m</em> within a struct
<em>s</em></dd>
<dt><code>offsetof(s,m)</code>
<dd>This macro defined in <code>stddef.h</code> does exactly the same
thing as the <code>HOFFSET()</code> macro.</dd>
</dl>
<p><em>Note for Fortran users</em>: Offsets of Fortran structure members
correspond to the offsets within a packed datatype (see explanation below)
stored in an HDF5 file.</p>
<p>Each member of a compound datatype must have a descriptive name which
is the key used to uniquely identify the member within the compound
datatype. A member name in an HDF5 datatype does not necessarily have
to be the same as the name of the member in the C struct or Fortran
derived type, although this is often the case. Nor does one need to
define all members of the C struct or Fortran derived type in the HDF5
compound datatype (or vice versa).</p>
<p>Unlike atomic datatypes which are derived from other atomic datatypes,
compound datatypes are created from scratch. First, one creates an empty
compound datatype and specifies its total size. Then members are added to
the compound datatype in any order. Each member type is inserted at a
designated offset. Each member has a name which is the key used to uniquely
identify the member within the compound datatype.</p>
<p>The example below shows a way of creating an HDF5 C compound datatype to
describe a complex number. This is a structure with two components,
“real” and “imaginary”, and each component
is a double. An equivalent C struct whose type is defined by the
<code>complex_t</code> struct is shown.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
typedef struct {
double re; /*real part*/
double im; /*imaginary part*/
} complex_t;
hid_t complex_id = H5Tcreate (H5T_COMPOUND, sizeof (complex_t));
H5Tinsert (complex_id, “real”, HOFFSET(complex_t,re),
H5T_NATIVE_DOUBLE);
H5Tinsert (complex_id, “imaginary”, HOFFSET(complex_t,im),
H5T_NATIVE_DOUBLE);</pre> </td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 9. A compound datatype for complex numbers in C</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The example below shows a way of creating an HDF5 Fortran compound
datatype to describe a complex number. This is a Fortran derived type
with two components, “real” and “imaginary”,
and each component is DOUBLE PRECISION. An equivalent Fortran TYPE
whose type is defined by the TYPE <code>complex_t</code> is shown.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
TYPE complex_t
DOUBLE PRECISION re ! real part
DOUBLE PRECISION im; ! imaginary part
END TYPE complex_t
CALL h5tget_size_f(H5T_NATIVE_DOUBLE, re_size, error)
CALL h5tget_size_f(H5T_NATIVE_DOUBLE, im_size, error)
complex_t_size = re_size + im_size
CALL h5tcreate_f(H5T_COMPOUND_F, complex_t_size, type_id)
offset = 0
CALL h5tinsert_f(type_id, “real”, offset, H5T_NATIVE_DOUBLE, error)
offset = offset + re_size
CALL h5tinsert_f(type_id, “imaginary”, offset, H5T_NATIVE_DOUBLE, error)</pre> </td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 10. A compound datatype for complex numbers in Fortran</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p><em>Important Note</em>: The compound datatype is created with a size
sufficient to hold all its members. In the C example above, the size of
the C struct and the <code>HOFFSET</code> macro are used as a convenient
mechanism to determine the appropriate size and offset. Alternatively, the
size and offset could be manually determined: the size can be set to
16 with “real” at offset 0 and “imaginary” at
offset 8. However, different platforms and compilers have different
sizes for “double” and may have alignment restrictions
which require additional padding within the structure. It is much
more portable to use the <code>HOFFSET</code> macro which assures
that the values will be correct for any platform.</p>
<p>The figure below shows how the compound datatype would be laid out
assuming that <code>NATIVE_DOUBLE</code> are 64-bit numbers and that
there are no alignment requirements. The total size of the compound
datatype will be 16 bytes, the “real” component will
start at byte 0, and “imaginary” will start at byte 8.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<table border="1" align="center" width="550">
<tr>
<td valign="top" align="right" rowspan="4" width="150">
<img src="Images/Dtypes_fig18_a.jpg">
</td>
<td valign="middle" align="center" width="100"><code>Byte 0</code></td>
<td valign="middle" align="center" width="100"><code>Byte 1</code></td>
<td valign="middle" align="center" width="100"><code>Byte 2</code></td>
<td valign="middle" align="center" width="100"><code>Byte 3</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>Byte 4</code></td>
<td valign="middle" align="center"><code>Byte 5</code></td>
<td valign="middle" align="center"><code>Byte 6</code></td>
<td valign="middle" align="center"><code>Byte 7</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
</tr>
<tr>
<td valign="top" align="right" rowspan="4" width="150">
<img src="Images/Dtypes_fig18_b.jpg">
</td>
<td valign="middle" align="center"><code>Byte 8</code></td>
<td valign="middle" align="center"><code>Byte 9</code></td>
<td valign="middle" align="center"><code>Byte 10</code></td>
<td valign="middle" align="center"><code>Byte 11</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>Byte 12</code></td>
<td valign="middle" align="center"><code>Byte 13</code></td>
<td valign="middle" align="center"><code>Byte 14</code></td>
<td valign="middle" align="center"><code>Byte 15</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
</tr>
</table>
<table align="center" border="0" width="550">
<tr>
<td valign="top" align="right" width="150"> </td>
<td valign="top" align="left" colspan="4">Total size of
compound datatype is 16 bytes</td>
</tr>
</table>
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 10. Layout of a compound datatype</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The members of a compound datatype may be any HDF5 datatype
including the compound, array, and variable-length (VL) types. The
figure and example below show the memory layout and code
which creates a compound datatype composed of two complex
values, and each complex value is also a compound datatype as in the
figure above.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<table border="1" align="center" width="550">
<tr>
<td valign="top" align="right" rowspan="4" width="150">
<img src="Images/Dtypes_fig19_a.jpg">
</td>
<td valign="middle" align="center" width="100"><code>Byte 0</code></td>
<td valign="middle" align="center" width="100"><code>Byte 1</code></td>
<td valign="middle" align="center" width="100"><code>Byte 2</code></td>
<td valign="middle" align="center" width="100"><code>Byte 3</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>Byte 4</code></td>
<td valign="middle" align="center"><code>Byte 5</code></td>
<td valign="middle" align="center"><code>Byte 6</code></td>
<td valign="middle" align="center"><code>Byte 7</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
</tr>
<tr>
<td valign="top" align="right" rowspan="4">
<img src="Images/Dtypes_fig19_b.jpg" align="middle">
</td>
<td valign="middle" align="center"><code>Byte 8</code></td>
<td valign="middle" align="center"><code>Byte 9</code></td>
<td valign="middle" align="center"><code>Byte 10</code></td>
<td valign="middle" align="center"><code>Byte 11</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>Byte 12</code></td>
<td valign="middle" align="center"><code>Byte 13</code></td>
<td valign="middle" align="center"><code>Byte 14</code></td>
<td valign="middle" align="center"><code>Byte 15</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
</tr>
<tr>
<td valign="top" align="right" rowspan="4">
<img src="Images/Dtypes_fig19_c.jpg"></td>
<td valign="middle" align="center" width="100"><code>Byte 16</code></td>
<td valign="middle" align="center" width="100"><code>Byte 17</code></td>
<td valign="middle" align="center" width="100"><code>Byte 18</code></td>
<td valign="middle" align="center" width="100"><code>Byte 19</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>Byte 20</code></td>
<td valign="middle" align="center"><code>Byte 21</code></td>
<td valign="middle" align="center"><code>Byte 22</code></td>
<td valign="middle" align="center"><code>Byte 23</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
<td valign="middle" align="center"><code><strong>rrrrrrrr</strong></code></td>
</tr>
<tr>
<td valign="top" align="right" rowspan="4">
<img src="Images/Dtypes_fig19_d.jpg"></td>
<td valign="middle" align="center"><code>Byte 24</code></td>
<td valign="middle" align="center"><code>Byte 25</code></td>
<td valign="middle" align="center"><code>Byte 26</code></td>
<td valign="middle" align="center"><code>Byte 27</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>Byte 28</code></td>
<td valign="middle" align="center"><code>Byte 29</code></td>
<td valign="middle" align="center"><code>Byte 30</code></td>
<td valign="middle" align="center"><code>Byte 31</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
<td valign="middle" align="center"><code><strong>iiiiiiii</strong></code></td>
</tr>
</table>
<table align="center" width="550">
<tr>
<td width="150"> </td>
<td>Total size of compound datatype is 32 bytes.</td>
</tr>
</table>
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 11. Layout of a compound datatype nested within a compound
datatype</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>
typedef struct {
complex_t x;
complex_t y;
} surf_t;
hid_t complex_id, surf_id; /*hdf5 datatypes*/
complex_id = H5Tcreate (H5T_COMPOUND, sizeof(complex_t));
H5Tinsert (complex_id, “re”, HOFFSET(complex_t,re),
H5T_NATIVE_DOUBLE);
H5Tinsert (complex_id, “im”, HOFFSET(complex_t,im),
H5T_NATIVE_DOUBLE);
surf_id = H5Tcreate (H5T_COMPOUND, sizeof(surf_t));
H5Tinsert (surf_id, “x”, HOFFSET(surf_t,x), complex_id);
H5Tinsert (surf_id, “y”, HOFFSET(surf_t,y), complex_id);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 11. Code for a compound datatype nested within a compound
datatype</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>Note that a similar result could be accomplished by creating a
compound datatype and inserting four fields. See the figure below. This
results in the same layout as the figure above. The difference
would be how the fields are addressed. In the first case, the
real part of ‘y’ is called ‘y.re’; in the
second case it is ‘y-re’.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
typedef struct {
complex_t x;
complex_t y;
} surf_t;
hid_t surf_id = H5Tcreate (H5T_COMPOUND, sizeof(surf_t));
H5Tinsert (surf_id, “x-re”, HOFFSET(surf_t,x.re),
H5T_NATIVE_DOUBLE);
H5Tinsert (surf_id, “x-im”, HOFFSET(surf_t,x.im),
H5T_NATIVE_DOUBLE);
H5Tinsert (surf_id, “y-re”, HOFFSET(surf_t,y.re),
H5T_NATIVE_DOUBLE);
H5Tinsert (surf_id, “y-im”, HOFFSET(surf_t,y.im),
H5T_NATIVE_DOUBLE); </pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 12. Another compound datatype nested within a
compound datatype </b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The members of a compound datatype do not always
fill all the bytes. The <code>HOFFSET</code> macro
assures that the members will be laid out according
to the requirements of the platform and language.
The example below shows an example of a C struct which requires
extra bytes of padding on many platforms. The second
element, ‘b’, is a 1-byte character followed by an 8
byte double, ‘c’. On many systems, the 8-byte value must
be stored on a 4- or 8-byte boundary. This requires the struct
to be larger than the sum of the size of its elements. </p>
<p>In the example below, <code>sizeof</code> and
<code>HOFFSET</code> are used to assure that the
members are inserted at the correct offset to match the
memory conventions of the platform. The figure below shows how
this data element would be stored in memory, assuming the
double must start on a 4-byte boundary. Notice the extra
bytes between ‘b’ and ‘c’.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
typedef struct s1_t {
int a;
char b;
double c;
} s1_t;
s1_tid = H5Tcreate (H5T_COMPOUND, sizeof(s1_t));
H5Tinsert(s1_tid, “a_name”, HOFFSET(s1_t, a), H5T_NATIVE_INT);
H5Tinsert(s1_tid, “b_name”, HOFFSET(s1_t, b), H5T_NATIVE_CHAR);
H5Tinsert(s1_tid, “c_name”, HOFFSET(s1_t, c), H5T_NATIVE_DOUBLE);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 13. A compound datatype that requires padding</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="center">
<hr color="green" size="3"/>
<img src="Images/Dtypes_fig23.JPG">
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 12. Memory layout of a compound datatype that requires
padding </b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>However, data stored on disk does not require
alignment, so unaligned versions of compound data
structures can be created to improve space efficiency
on disk. These unaligned compound datatypes can be
created by computing offsets by hand to eliminate
inter-member padding, or the members can be packed by
calling <code>H5Tpack</code> (which modifies a datatype
directly, so it is usually preceded by a call to
<code>H5Tcopy</code>). </p>
<p>The example below shows how to create a disk version of the
compound datatype from the figure above in order to store
data on disk in as compact a form as possible.
Packed compound datatypes should generally not be used to
describe memory as they may violate alignment constraints
for the architecture being used. Note also that using a
packed datatype for disk storage may involve a higher
data conversion cost.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
hid_t s2_tid = H5Tcopy (s1_tid);
H5Tpack (s2_tid);</pre> </td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 14. Create a packed compound datatype in C</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The example below shows the sequence of Fortran calls to
create a packed compound datatype. An HDF5 Fortran
compound datatype never describes a compound datatype
in memory and compound data is <em>ALWAYS</em> written
by fields as described in the next section. Therefore
packing is not needed unless the offset of each consecutive
member is not equal to the sum of the sizes of the
previous members.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
CALL h5tcopy_f(s1_id, s2_id, error)
CALL h5tpack_f(s2_id, error)</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 15. Create a packed compound datatype in Fortran</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<h4>6.4.3.2.1.2. Creating and Writing Datasets with Compound Datatypes</h4>
<p>Creating datasets with compound datatypes is similar
to creating datasets with any other HDF5 datatypes. But
writing and reading may be different since datasets that
have compound datatypes can be written or read by a field
(member) or subsets of fields (members). The compound datatype
is the only composite datatype that supports “sub-setting” by
the elements the datatype is built from.</p>
<p>The example below shows a C example of creating and writing a dataset
with a compound datatype.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
typedef struct s1_t {
int a;
float b;
double c;
} s1_t;
s1_t data[LENGTH];
/* Initialize data */
for (i = 0; i < LENGTH; i++) {
data[i].a = i;
data[i].b = i*i;
data[i].c = 1./(i+1);
...
s1_tid = H5Tcreate (H5T_COMPOUND, sizeof(s1_t));
H5Tinsert(s1_tid, “a_name”, HOFFSET(s1_t, a), H5T_NATIVE_INT);
H5Tinsert(s1_tid, “b_name”, HOFFSET(s1_t, b), H5T_NATIVE_FLOAT);
H5Tinsert(s1_tid, “c_name”, HOFFSET(s1_t, c), H5T_NATIVE_DOUBLE);
...
dataset_id = H5Dcreate(file_id, “SDScompound.h5”, s1_t, space_id,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Dwrite (dataset_id, s1_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);</pre> </td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 16. Create and write a dataset with a compound datatype in C</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<!-- NEW PAGE -->
<p>The example below shows the content of the file written on
a little-endian machine.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
HDF5 “SDScompound.h5” {
GROUP “/” {
DATASET “ArrayOfStructures” {
DATATYPE H5T_COMPOUND {
H5T_STD_I32LE “a_name”;
H5T_IEEE_F32LE “b_name”;
H5T_IEEE_F64LE “c_name”;
}
DATASPACE SIMPLE { ( 3 ) / ( 3 ) }
DATA {
(0): {
0,
0,
1
},
(1): {
1,
1,
0.5
},
(2): {
2,
4,
0.333333
}
}
}
}
}</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 17. Create and write a little-endian dataset with a compound
datatype in C</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<!-- NEW PAGE -->
<p>It is not necessary to write the whole data at once.
Datasets with compound datatypes can be written by
field or by subsets of fields. In order to do this one
has to remember to set the transfer property of the dataset
using the <code>H5Pset_preserve</code> call and to define the
memory datatype that corresponds to a field. The example below
shows how float and double fields are written to the
dataset.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
typedef struct sb_t {
float b;
double c;
} sb_t;
typedef struct sc_t {
float b;
double c;
} sc_t;
sb_t data1[LENGTH];
sc_t data2[LENGTH];
/* Initialize data */
for (i = 0; i < LENGTH; i++) {
data1.b = i*i;
data2.c = 1./(i+1);
}
...
/* Create dataset as in example 15 */
...
/* Create memory datatypes corresponding to float and
double datatype fileds */
sb_tid = H5Tcreate (H5T_COMPOUND, sizeof(sb_t));
H5Tinsert(sb_tid, “b_name”, HOFFSET(sb_t, b), H5T_NATIVE_FLOAT);
sc_tid = H5Tcreate (H5T_COMPOUND, sizeof(sc_t));
H5Tinsert(sc_tid, “c_name”, HOFFSET(sc_t, c), H5T_NATIVE_DOUBLE);
...
/* Set transfer property */
xfer_id = H5Pcreate(H5P_DATASET_XFER);
H5Pset_preserve(xfer_id, 1);
H5Dwrite (dataset_id, sb_tid, H5S_ALL, H5S_ALL, xfer_id, data1);
H5Dwrite (dataset_id, sc_tid, H5S_ALL, H5S_ALL, xfer_id, data2);</pre> </td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 18. Writing floats and doubles to a dataset</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<!-- NEW PAGE -->
<p>The figure below shows the content of the file written on a
little-endian machine. Only float and double fields are
written. The default fill value is used to initialize the
unwritten integer field.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
HDF5 “SDScompound.h5” {
GROUP “/” {
DATASET “ArrayOfStructures” {
DATATYPE H5T_COMPOUND {
H5T_STD_I32LE “a_name”;
H5T_IEEE_F32LE “b_name”;
H5T_IEEE_F64LE “c_name”;
}
DATASPACE SIMPLE { ( 3 ) / ( 3 ) }
DATA {
(0): {
0,
0,
1
},
(1): {
0,
1,
0.5
},
(2): {
0,
4,
0.333333
}
}
}
}
}</pre> </td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 19. Writing floats and doubles to a dataset on a little-endian
system</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<!-- NEW PAGE -->
<p>The example below contains a Fortran example that creates and writes
a dataset with a compound datatype. As this example illustrates,
writing and reading compound datatypes in Fortran is <em>always</em>
done by fields. The content of the written file is the same as
shown in the example above.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
! One cannot write an array of a derived datatype in Fortran.
TYPE s1_t
INTEGER a
REAL b
DOUBLE PRECISION c
END TYPE s1_t
TYPE(s1_t) d(LENGTH)
! Therefore, the following code initializes an array corresponding
! to each field in the derived datatype and writes those arrays
! to the dataset
INTEGER, DIMENSION(LENGTH) :: a
REAL, DIMENSION(LENGTH) :: b
DOUBLE PRECISION, DIMENSION(LENGTH) :: c
! Initialize data
do i = 1, LENGTH
a(i) = i-1
b(i) = (i-1) * (i-1)
c(i) = 1./i
enddo
...
! Set dataset transfer property to preserve partially initialized fields
! during write/read to/from dataset with compound datatype.
!
CALL h5pcreate_f(H5P_DATASET_XFER_F, plist_id, error)
CALL h5pset_preserve_f(plist_id, .TRUE., error)
...
!
! Create compound datatype.
!
! First calculate total size by calculating sizes of each member
!
CALL h5tget_size_f(H5T_NATIVE_INTEGER, type_sizei, error)
CALL h5tget_size_f(H5T_NATIVE_REAL, type_sizer, error)
CALL h5tget_size_f(H5T_NATIVE_DOUBLE, type_sized, error)
type_size = type_sizei + type_sizer + type_sized
CALL h5tcreate_f(H5T_COMPOUND_F, type_size, dtype_id, error)
!
! Insert memebers
!
!
! INTEGER member
!
offset = 0
CALL h5tinsert_f(dtype_id, “a_name”, offset, H5T_NATIVE_INTEGER, error)
!
! REAL member
!
offset = offset + type_sizei
CALL h5tinsert_f(dtype_id, “b_name”, offset, H5T_NATIVE_REAL, error)
!
! DOUBLE PRECISION member
!
offset = offset + type_sizer
CALL h5tinsert_f(dtype_id, “c_name”, offset, H5T_NATIVE_DOUBLE, error)
!
! Create the dataset with compound datatype.
!
CALL h5dcreate_f(file_id, dsetname, dtype_id, dspace_id, &
dset_id, error, H5P_DEFAULT_F, H5P_DEFAULT_F, H5P_DEFAULT_F)
!
...
! Create memory types. We have to create a compound datatype
! for each member we want to write.
!
!
CALL h5tcreate_f(H5T_COMPOUND_F, type_sizei, dt1_id, error)
offset = 0
CALL h5tinsert_f(dt1_id, “a_name”, offset, H5T_NATIVE_INTEGER, error)
!
CALL h5tcreate_f(H5T_COMPOUND_F, type_sizer, dt2_id, error)
offset = 0
CALL h5tinsert_f(dt2_id, “b_name”, offset, H5T_NATIVE_REAL, error)
!
CALL h5tcreate_f(H5T_COMPOUND_F, type_sized, dt3_id, error)
offset = 0
CALL h5tinsert_f(dt3_id, “c_name”, offset, H5T_NATIVE_DOUBLE, error)
!
! Write data by fields in the datatype. Fields order is not important.
!
CALL h5dwrite_f(dset_id, dt3_id, c, data_dims, error, xfer_prp = plist_id)
CALL h5dwrite_f(dset_id, dt2_id, b, data_dims, error, xfer_prp = plist_id)
CALL h5dwrite_f(dset_id, dt1_id, a, data_dims, error, xfer_prp = plist_id)</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 20. Create and write a dataset with a compound datatype in
Fortran</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<!-- NEW PAGE -->
<h4>6.4.3.2.1.3. Reading Datasets with Compound Datatypes</h4>
<p>Reading datasets with compound datatypes may be a
challenge. For general applications there is no way to
know <em>a priori</em> the corresponding C structure.
Also, C structures cannot be allocated on the fly during discovery
of the dataset’s datatype. For general C , C++, Fortran
and Java application the following steps will be required
to read and to interpret data from the dataset with
compound datatype:</p>
<dl>
<dt>
<ol>
<li>Get the identifier of the compound datatype in the file
with the <code>H5Dget_type</code> call</li>
<li>Find the number of the compound datatype members
with the <code>H5Tget_nmembers</code> call</li>
<li>Iterate through compound datatype members</li>
</ol>
<dd>
<ul>
<li>Get member class with the
<code>H5Tget_member_class</code> call</li>
<li>Get member name with the
<code>H5Tget_member_name</code> call</li>
<li>Check class type against predefined classes</li>
<ul>
<li><code>H5T_INTEGER</code></li>
<li><code>H5T_FLOAT</code></li>
<li><code>H5T_STRING</code></li>
<li><code>H5T_BITFIELD</code></li>
<li><code>H5T_OPAQUE</code></li>
<li><code>H5T_COMPOUND</code></li>
<li><code>H5T_REFERENCE</code></li>
<li><code>H5T_ENUM</code></li>
<li><code>H5T_VLEN</code></li>
<li><code>H5T_ARRAY</code></li>
</ul>
<li>If class is <code>H5T_COMPOUND</code>,
then go to step 2 and repeat all steps under
step 3. If class is not <code>H5T_COMPOUND</code>,
then a member is of an atomic class and can be
read to a corresponding buffer after discovering
all necessary information specific to each atomic
type (e.g. size of the integer or floats, super
class for enumerated and array datatype,
and it sizes, etc.)</li>
</ul>
</dd>
</dl>
<p>The examples below show how to read a dataset with a known
compound datatype.</p>
<p>The first example below shows the steps needed to read data of a
known structure. First, build a memory datatype
the same way it was built when the dataset was created, and then
second use the datatype in a <code>H5Dread</code> call.</p>
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
typedef struct s1_t {
int a;
float b;
double c;
} s1_t;
s1_t *data;
...
s1_tid = H5Tcreate(H5T_COMPOUND, sizeof(s1_t));
H5Tinsert(s1_tid, “a_name”, HOFFSET(s1_t, a), H5T_NATIVE_INT);
H5Tinsert(s1_tid, “b_name”, HOFFSET(s1_t, b), H5T_NATIVE_FLOAT);
H5Tinsert(s1_tid, “c_name”, HOFFSET(s1_t, c), H5T_NATIVE_DOUBLE);
...
dataset_id = H5Dopen(file_id, “SDScompound.h5”, H5P_DEFAULT);
...
data = (s1_t *) malloc (sizeof(s1_t)*LENGTH);
H5Dread(dataset_id, s1_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);</pre> </td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 21. Read a dataset using a memory datatype
<!-- used to be Figure 25f --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>Instead of building a memory datatype, the application could use the
<code>H5Tget_native_type</code> function. See the example below.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
typedef struct s1_t {
int a;
float b;
double c;
} s1_t;
s1_t *data;
hid_t file_s1_t, mem_s1_t;
...
dataset_id = H5Dopen(file_id, “SDScompound.h5”, H5P_DEFAULT);
/* Discover datatype in the file */
file_s1_t = H5Dget_type(dataset_id);
/* Find corresponding memory datatype */
mem_s1_t = H5Tget_native_type(file_s1_t, H5T_DIR_DEFAULT);
...
data = (s1_t *) malloc (sizeof(s1_t)*LENGTH);
H5Dread (dataset_id, mem_s1_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 22. Read a dataset using <code>H5Tget_native_type</code>
<!-- used to be Figure 25g --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<!-- NEW PAGE -->
<p>The example below shows how to read just one float member of a
compound datatype.</p>
<!-- used to be Example 25h -->
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
typedef struct s1_t {
float b;
} sf_t;
sf_t *data;
...
sf_tid = H5Tcreate(H5T_COMPOUND, sizeof(sf_t));
H5Tinsert(s1_tid, “b_name”, HOFFSET(sf_t, b), H5T_NATIVE_FLOAT);
...
dataset_id = H5Dopen(file_id, “SDScompound.h5”, H5P_DEFAULT);
...
data = (sf_t *) malloc (sizeof(sf_t)*LENGTH);
H5Dread(dataset_id, sf_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);</pre> </td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 23. Read one floating point member of a compound datatype
<!-- used to be Figure 25h --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The example below <!-- used to be Figure 25i --> shows how to read float
and
double members of a compound datatype into
a structure that has those fields in a different
order. Please notice that <code>H5Tinsert</code>
calls can be used in an order different from the
order of the structures members.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
typedef struct s1_t {
double c;
float b;
} sdf_t;
sdf_t *data;
...
sdf_tid = H5Tcreate(H5T_COMPOUND, sizeof(sdf_t));
H5Tinsert(sdf_tid, “b_name”, HOFFSET(sdf_t, b), H5T_NATIVE_FLOAT);
H5Tinsert(sdf_tid, “c_name”, HOFFSET(sdf_t, c), H5T_NATIVE_DOUBLE);
...
dataset_id = H5Dopen(file_id, “SDScompound.h5”, H5P_DEFAULT);
...
data = (sdf_t *) malloc (sizeof(sdf_t)*LENGTH);
H5Dread(dataset_id, sdf_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 24. Read float and double members of a compound datatype
<!-- used to be Figure 25i --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<!-- NEW PAGE -->
<h4>6.4.3.2.2. Array</h4>
<p>Many scientific datasets have multiple measurements for each point
in a space. There are several natural ways to represent this data,
depending on the variables and how they are used in computation.
See the table and the figure below.</p>
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="3" align="left" valign="bottom">
<b>Table 20. Representing data with multiple measurements</b></td>
</tr>
<tr><td colspan="5"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="25%"><b>Storage Strategy</b></td>
<td width="2%"> </td>
<td width="25%"><b>Stored as</b></td>
<td width="2%"> </td>
<td width="46%"><b>Remarks</b></td>
<tr><td colspan="5"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Mulitple planes</td>
<td> </td>
<td>Several datasets with identical dataspaces</td>
<td> </td>
<td>This is optimal when variables are
accessed individually, or when often uses only selected variables.</td>
</tr>
<tr><td colspan="5"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Additional dimension</td>
<td> </td>
<td>One dataset, the last “dimension”
is a vector of variables</td>
<td> </td>
<td>This can give good performance, although
selecting only a few variables may be slow. This may not reflect the
science.</td>
</tr>
<tr><td colspan="5"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Record with multiple values</td>
<td> </td>
<td>One dataset with compound datatype</td>
<td> </td>
<td>This enables the variables to be read all
together or selected. Also handles “vectors” of
heterogenous data.</td>
</tr>
<tr><td colspan="5"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Vector or Tensor value</td>
<td> </td>
<td>One dataset, each data element is a small
array of values.</td>
<td> </td>
<td>This uses the same amount of space as
the previous two, and may represent the science model better.</td>
</tr>
<tr><td colspan="5"><hr color="green" size="3" /></td></tr>
</table>
<br />
<br />
<!-- NEW PAGE -->
<table width="400" cellspacing="0" align="center">
<tr><td colspan="3"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td align="left">
<img src="Images/Dtypes_fig26_pic1of4.JPG"></td>
<td> </td>
<td align="center">
<img src="Images/Dtypes_fig26_pic2of4.JPG"></td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<img src="Images/Dtypes_fig26_pic3of4.JPG"></td>
<td> </td>
<td align="center">
<img src="Images/Dtypes_fig26_pic4of4.JPG"></td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" colspan="3" >
<b>Figure 13. Representing data with multiple measurements</b>
</td>
</tr>
<tr><td colspan="3"><hr color="green" size="3" /></td></tr>
</table>
<br />
<p>The HDF5 <code>H5T_ARRAY</code> datatype defines
the data element to be a homogeneous, multi-dimensional
array. See Figure 13d above. The elements of the array
can be any HDF5 datatype (including compound and array), and
the size of the datatype is the total size of the array.
A dataset of array datatype cannot be subdivided for I/O
within the data element: the entire array of the data element
must be transferred. If the data elements need to be accessed
separately, e.g., by plane, then the array datatype should not
be used. The table below <!-- formerly Table 22 -->
shows advantages and disadvantages of various
storage methods.</p>
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="5" align="left" valign="bottom">
<b>Table 21. Storage method advantages and disadvantages</b></td>
</tr>
<tr><td colspan="5"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="20%"><b>Method</b></td>
<td width="2%"> </td>
<td width="38%"><b>Advantages</b></td>
<td width="2%"> </td>
<td width="38%"><b>Disadvantages</b></td>
<tr><td colspan="5"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>a) Multiple Datasets</td>
<td> </td>
<td>Easy to access each plane, can select any plane(s)</td>
<td> </td>
<td>Less efficient to access a ‘column’ through the
planes</td>
</tr>
<tr><td colspan="5"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>b) N+1 Dimension</td>
<td> </td>
<td>All access patterns supported</td>
<td> </td>
<td>Must be homogeneous datatype<br /><br />
The added dimension may not make sense in the scientific
model</td>
</tr>
<tr><td colspan="5"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>c) Compound Datatype</td>
<td> </td>
<td>Can be heterogenous datatype</td>
<td> </td>
<td>Planes must be named, selection is by plane<br /><br />
Not a natural representation for a matrix</td>
</tr>
<tr><td colspan="5"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>d) Array</td>
<td> </td>
<td>A natural representation for vector or tensor data</td>
<td> </td>
<td>Cannot access elements separately (no access by plane)</td>
</tr>
<tr><td colspan="5"><hr color="green" size="3" /></td></tr>
</table>
<br />
<p>An array datatype may be multi-dimensional with 1 to
<code>H5S_MAX_RANK</code> (the maximum rank of a dataset is currently
32) dimensions. The dimensions can be any size greater than 0, but
unlimited dimensions are not supported (although the datatype can be
a variable-length datatype).</p>
<p>An array datatype is created with the <code>H5Tarray_create</code>
call, which specifies the number of dimensions, the size of each
dimension, and the base type of the array. The array datatype can
then be used in any way that any datatype object is used. The example
below <!-- formerly Figure 27 --> shows the creation of a datatype
that is a two-dimensional array of native integers, and this is then
used to create a dataset. Note that the dataset can be a dataspace
that is any number and size of dimensions. The figure below
<!-- formerly Figure 28 --> shows the layout in memory assuming that
the native integers are 4 bytes. Each data element has 6 elements,
for a total of 24 bytes.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
hid_t file, dataset;
hid_t datatype, dataspace;
hsize_t adims[] = {3, 2};
datatype = H5Tarray_create(H5T_NATIVE_INT, 2, adims, NULL);
dataset = H5Dcreate(file, datasetname, datatype, dataspace,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 25. Create a two-dimensional array datatype
<!-- formerly Figure 27 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<br />
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dtypes_fig28.JPG" width="550">
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 14. Memory layout of a two-dimensional array datatype
<!-- formerly Figure 28 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<!-- NEW PAGE -->
<h4>6.4.3.2.3. Variable-length Datatypes</h4>
<p>A variable-length (VL) datatype is a one-dimensional sequence of a
datatype which are not fixed in length from one dataset location to
another, i.e., each data element may have a different number of members.
Variable-length datatypes cannot be divided, the entire data element
must be transferred.</p>
<p>VL datatypes are useful to the scientific community in many different
ways, possibly including: </p>
<ul>
<li><em>Ragged arrays</em>: Multi-dimensional ragged arrays can be
implemented with the last (fastest changing) dimension being ragged by
using a VL datatype as the type of the element stored. </li>
<li><em>Fractal arrays</em>: A nested VL datatype can be used to implement
ragged arrays of ragged arrays, to whatever nesting depth is required
for the user. </li>
<li><em>Polygon lists</em>: A common storage requirement is to
efficiently store arrays of polygons with different numbers of
vertices. A VL datatypes can be used to efficiently and succinctly
describe an array of polygons with different numbers of vertices. </li>
<li><em>Character strings</em>: Perhaps the most common use of VL
datatypes will be to store C-like VL character strings in dataset
elements or as attributes of objects. </li>
<li><em>Indices, e.g. of objects within the file</em>: An array of
VL object references could be used as an index to all the objects
in a file which contain a particular sequence of dataset values. </li>
<li><em>Object Tracking</em>: An array of VL dataset region references
can be used as a method of tracking objects or features appearing
in a sequence of datasets. </li>
</ul>
<p>A VL datatype is created by calling <code>H5Tvlen_create</code> which
specifies the base datatype. The first example below <!-- formerly
Figure 29 --> shows an example of code that creates a VL datatype
of unsigned integers. Each data element is a one-dimensional array of
zero or more members and is stored in the <code>hvl_t</code> structure.
See the second example below. <!-- formerly Figure 30 --></p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
tid1 = H5Tvlen_create (H5T_NATIVE_UINT);
dataset=H5Dcreate(fid1, “Dataset1”, tid1, sid1, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT);</pre> </td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 26. Create a variable-length datatype of unsigned integers
<!-- formerly Figure 29 --></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>
typedef struct {
size_t len; /* Length of VL data (in base type units) */
void *p; /* Pointer to VL data */
} hvl_t;</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 27. Data element storage for members of the VL datatype
<!-- formerly Figure 30 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<!-- NEW PAGE -->
<p>The first example below <!-- formerly Figure 31 --> shows how the VL
data is written. For each of the 10 data elements,
a length and data buffer must be allocated. Below the two examples is a
figure <!-- formerly Figure 33 --> that shows how the data is
laid out in memory. </p>
<p>An analogous procedure must be used to read the data. See the second
example below.
An appropriate array of <code>vl_t</code> must be allocated,
and the data read. It is then traversed one data element at a time.
The <code>H5Dvlen_reclaim</code> call frees the data buffer for the buffer.
With each element possibly being of different sequence lengths for a
dataset with a VL datatype, the memory for the VL datatype
must be dynamically allocated. Currently there are two methods of managing the
memory for VL datatypes: the standard C malloc/free memory allocation routines
or a method of calling user-defined memory management routines to allocate or
free memory (set with <code>H5Pset_vlen_mem_manager</code>). Since the memory
allocated when reading (or writing) may be complicated to release,
the <code>H5Dvlen_reclaim</code> function
is provided to traverse a memory buffer and free the VL datatype information
without leaking memory.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
hvl_t wdata[10]; /* Information to write */
/* Allocate and initialize VL data to write */
for(i=0; i < 10; i++) {
wdata[i].p = malloc((i+1)*sizeof(unsigned int));
wdata[i].len = i+1;
for(j=0; j<(i+1); j++)
((unsigned int *)wdata[i].p)[j]=i*10+j;
}
ret=H5Dwrite(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata);</pre> </td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 28. Write VL data
<!-- formerly Figure 31 --></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>
hvl_t rdata[SPACE1_DIM1];
ret=H5Dread(dataset, tid1, H5S_ALL, H5S_ALL, xfer_pid, rdata);
for(i=0; i<SPACE1_DIM1; i++) {
printf(“%d: len %d ”,rdata[i].len);
for(j=0; j<rdata[i].len; j++) {
printf(“ value: %u\n”,((unsigned int *)rdata[i].p)[j]);
}
}
ret=H5Dvlen_reclaim(tid1, sid1, xfer_pid, rdata);</pre> </td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 29. Read VL data
<!-- formerly Figure 32 --></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="center">
<hr color="green" size="3"/>
<img src="Images/Dtypes_fig33.JPG" width="550">
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 15. Memory layout of a VL datatype
<!-- formerly Figure 33 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The user program must carefully manage these relatively complex data
structures.
The <code>H5Dvlen_reclaim</code> function performs a standard traversal,
freeing all the data. This function analyzes the datatype and dataspace
objects, and visits each VL data element, recursing through nested
types. By default, the system <code>free</code> is called for the
pointer in each <code>vl_t</code>. Obviously, this call assumes that
all of this memory was allocated with the system <code>malloc</code>.</p>
<p>The user program may specify custom memory manager routines, one for
allocating and one for freeing. These may be set with the
<code>H5Pvlen_mem_manager</code>, and must have the following prototypes: </p>
<ul>
<li><code>typedef void *(*H5MM_allocate_t)(size_t size, void *info);</code> </li>
<li><code>typedef void (*H5MM_free_t)(void *mem, void *free_info);</code> </li>
</ul>
<p>The utility function <code>H5Dget_vlen_buf_size</code> checks the
number of bytes required to store the VL data from the dataset. This
function analyzes the datatype and dataspace object to visit all the
VL data elements, to determine the number of bytes required to store
the data for the in the destination storage (memory). The
<code>size</code> value is adjusted for data conversion and alignment
in the destination.</p>
<SCRIPT language="JavaScript">
<!--
document.writeln ("
<a name="NonNumDtypes">
<div align=right>
<a href="#TOP"><font size="-1">(Top)</font></a>
</div>
</a>
");
-->
</SCRIPT>
<a name="NonNumDtypes">
<h3 class=pagebefore>6.5. Other Non-numeric Datatypes</h3>
</a>
<p>Several datatype classes define special types of objects.</p>
<h4>6.5.1. Strings</h4>
<p>Text data is represented by arrays of characters, called strings.
Many programming languages support different conventions for storing strings,
which may be fixed or variable-length, and may have different rules for
padding unused storage. HDF5 can represent strings in several ways.
See the figure below.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<table align="center" width="100%">
<tr align="left">
<td width="5%"> </td>
<td width="25%" align="left" valign="top">The Strings to store are: </td>
<td width="70%" align="left">“Four score”,<br /> “lazy programmers.”</td>
</tr>
<tr>
<td colspan="3"> </td>
</tr>
</table>
<table width="100%">
<tr align="left">
<td width="5%"> </td>
<td valign="top" align="right">
<strong>a)</strong>
</td>
<td><code>H5T_NATIVE_CHAR</code> the dataset is a one-dimensional
array with 29 elements, each element is a single character.
</td>
</tr>
</table>
<table align="center" width="100%">
<tr>
<td width="5%"> </td>
<td colspan="2">
<table border="1" width="100%">
<tr>
<td align="center">0</td>
<td align="center">1</td>
<td align="center">2</td>
<td align="center">3</td>
<td align="center">4</td>
<td align="center">...</td>
<td align="center">25</td>
<td align="center">26</td>
<td align="center">27</td>
<td align="center">28</td>
</tr>
<tr>
<td align="center">‘F’</td>
<td align="center">‘o’</td>
<td align="center">‘u’</td>
<td align="center">‘r’</td>
<td align="center">‘ ’</td>
<td align="center">...</td>
<td align="center">‘r’</td>
<td align="center">‘s’</td>
<td align="center">‘.’</td>
<td align="center">‘\0’</td>
</tr>
</table>
</td>
</tr>
<tr><td colspan="3"> </td></tr>
</table>
<table width="100%">
<tr align="left">
<td width="5%"> </td>
<td align="right" valign="top"><strong>b)</strong></td>
<td>Fixed-length string<br />
The dataset is a one-dimensional array with 2 elements,
each element is 20 characters.
</td>
</tr>
</table>
<table align="center" width="100%">
<tr>
<td width="15%"> </td>
<td colspan="2">
<table border="1" width="50%">
<tr align="center">
<td> 0 </td>
<td><pre>“Four score\0 ”</pre></td>
</tr>
<tr align="center">
<td> 1 </td>
<td><pre>“lazy programmers.\0”</pre></td>
</tr>
</table>
</td>
</tr>
<tr><td colspan="3"> </td></tr>
</table>
<table width="100%">
<tr align="left">
<td width="5%"> </td>
<td align="right" valign="top"><strong>c)</strong></td>
<td>Variable-length string<br />
The dataset is a one-dimensional array with 2
elements, each element is a variable-length string.<br />
This is the same result when stored as fixed-length
string, except that first element of the array will
need only 11 bytes for storage instead of 20.
</td>
</tr>
</table>
<table align="center" width="100%">
<tr>
<td width="15%"> </td>
<td colspan="2">
<table border="1" width="50%">
<tr align="center">
<td> 0 </td>
<td><pre>“Four score\0”</pre></td>
</tr>
<tr align="center">
<td> 1 </td>
<td><pre>“lazy programmers.\0”</pre></td>
</tr>
</table>
</td>
</tr>
<tr><td colspan="3"> </td></tr>
</table>
<table align="center" width="100%">
<tr>
<td width="15%"> </td>
<td colspan="2">
<img src="Images/Dtypes_fig34.JPG">
</td>
</table>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 16. Ways to represent strings
<!-- formerly Figure 34 --></b><hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>First, a dataset may have a dataset with datatype
<code>H5T_NATIVE_CHAR</code>, with each character of the string as an
element of the dataset. This will store an unstructured block of text
data, but gives little indication of any structure in the text. See
item a in the figure above. </p>
<p>A second alternative is to store the data using the datatype class
<code>H5T_STRING</code>,
with each element a fixed length. See item b in the figure above. In this
approach, each element might be a word or a sentence, addressed by
the dataspace. The dataset reserves space for the specified number of
characters, although some strings may be shorter. This approach is
simple and usually is fast to access, but can waste storage space if
the length of the Strings varies.</p>
<p>A third alternative is to use a variable-length datatype. See item c in
the figure above. This can be done using the standard mechanisms
described above (e.g., using <code>H5T_NATIVE_CHAR</code>
instead of <code>H5T_NATIVE_INT</code> in Example 25 above). The
program would use <code>vl_t</code> structures to write and
read the data.</p>
<p>A fourth alternative is to use a special feature of the string datatype
class to set the size of the datatype to <code>H5T_VARIABLE</code>. See
item c in the figure above. The example below <!-- formerly Figure 35 -->
shows a declaration of a datatype of type <code>H5T_C_S1</code>
which is set to <code>H5T_VARIABLE</code>. The HDF5 Library automatically
translates between this and the <code>vl_t</code> structure. (Note: the
<code>H5T_VARIABLE</code> size can only be used with string datatypes.)</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
tid1 = H5Tcopy (H5T_C_S1);
ret = H5Tset_size (tid1, H5T_VARIABLE);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 30. Set the string datatype size to <code>H5T_VARIABLE</code>
<!-- formerly Figure 35 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>Variable-length strings can be read into C strings (i.e., pointers to zero
terminated arrays of <code>char</code>). See the figure below. </p>
<table width="650" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
char *rdata[SPACE1_DIM1];
ret=H5Dread(dataset, tid1, H5S_ALL, H5S_ALL, xfer_pid, rdata);
for(i=0; i<SPACE1_DIM1; i++) {
printf(“%d: len: %d, str is: %s\n”, i, strlen(rdata[i]),rdata[i]);
}
ret=H5Dvlen_reclaim(tid1, sid1, xfer_pid, rdata);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 31. Read variable-length strings into C strings
<!-- formerly Figure 36 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<!--
3.23.2012. I commented out the "Strings in Mixed Environments" section below.
I have spent too many GMQS hours and have to stop charging GMQS for awhile. MEE.
<a name="stringsInMixedEnvironments">
<b>Strings in Mixed Environments</b></a>
<p>In the figures above, the strings are terminated with NULLs.
Suppose in another scenario that the strings were stored on disk and
were not terminated with NULLs, and suppose that the users of the data
would be using applications that expected strings to be terminated with
NULLs? What APIs might an application use to properly handle the strings?
</p>
<p>The figure below shows the strings “Four score” and
“seven years ago” stored as fixed-length dataset elements
without NULL terminators.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<table align="center" width="100%">
<tr>
<td colspan="2">
<table align="center" border="1" width="70%">
<tr>
<td width="50%" align="center">0</td>
<td width="50%" align="center">1</td>
</tr>
<tr>
<td align="center">‘Four score
’</td>
<td align="center">‘seven years ago
’</td>
</tr>
</table>
</td>
</tr>
</table>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 17???. Strings stored as fixed-length dataset elements
and not terminated with NULLs
</b><hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>
<p>??????? rewrite for this new example
The figure below shows how these strings might be stored using
a <b>fixed-length</b> datatype. This one-dimensional array uses the
<code>H5T_STRING</code> datatype. The dataset reserves space for a
specified number of characters in each string although some strings may
be shorter. In the example below, the size is set to 20. This approach
is simple and usually fast to access, but this approach can waste storage
space if the lengths of the strings vary. The single quotation marks are
used to show the 20 characters included in each dataset element.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<table align="center" width="100%">
<tr>
<td colspan="2">
<table align="center" border="1" width="70%">
<tr>
<td width="50%" align="center">0</td>
<td width="50%" align="center">1</td>
</tr>
<tr>
<td align="center">‘Four score\0
’</td>
<td align="center">‘seven years ago\0
’</td>
</tr>
</table>
</td>
</tr>
</table>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 17???. Strings stored as fixed-length dataset elements
</b><hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>Please note that a data element of size 1 might be useful in an
environment where a NULL is not needed to terminate a string. If a NULL
is needed to terminate a string, then a data element of size 1
would not be useful.</p>
<br /><br />
-->
<h4>6.5.2. Reference</h4>
<p>In HDF5, objects (i.e. groups, datasets, and committed datatypes)
are usually accessed by name. There is another way to access stored
objects - by reference. There are two reference datatypes: object
reference and region reference. Object reference objects are created
with <code>H5Rcreate</code> and other calls (cross reference). These
objects can be stored and retrieved in a dataset as elements with
reference datatype. The first example below <!-- formerly Figure 37 -->
shows an example of code that creates references to four objects,
and then writes the array of object references to a dataset. The
second example below <!-- formerly Figure 38 -->shows a dataset of datatype
reference being read and one of the reference objects being
dereferenced to obtain an object pointer.</p>
<p>In order to store references to regions of a dataset, the datatype
should be <code>H5T_REGION_OBJ</code>. Note that a data element must
be either an object reference or a region reference: these are different
types and cannot be mixed within a single array.</p>
<p>A reference datatype cannot be divided for I/O: an element is read or
written completely.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
dataset=H5Dcreate(fid1, “Dataset3”, H5T_STD_REF_OBJ, sid1,
H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* Create reference to dataset */
ret = H5Rcreate(&wbuf[0], fid1,“/Group1/Dataset1”, H5R_OBJECT, -1);
/* Create reference to dataset */
ret = H5Rcreate(&wbuf[1], fid1, “/Group1/Dataset2”, H5R_OBJECT, -1);
/* Create reference to group */
ret = H5Rcreate(&wbuf[2], fid1, “/Group1”, H5R_OBJECT, -1);
/* Create reference to committed datatype */
ret = H5Rcreate(&wbuf[3], fid1, “/Group1/Datatype1”, H5R_OBJECT, -1);
/* Write selection to disk */
ret=H5Dwrite(dataset, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 32. Create object references and write to a dataset
<!-- formerly Figure 37 --></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>
rbuf = malloc(sizeof(hobj_ref_t)*SPACE1_DIM1);
/* Read selection from disk */
ret=H5Dread(dataset, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf);
/* Open dataset object */
dset2 = H5Rdereference(dataset, H5R_OBJECT, &rbuf[0]);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 33. Read a dataset with a reference datatype
<!-- formerly Figure 38 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<!-- NEW PAGE -->
<h4>6.5.3. ENUM</h4>
<p>The enum datatype implements a set of (name, value) pairs, similar
to C/C++ enum. The values are currently limited to native integer datatypes.
Each name can be the name of only one value, and each value can have only
one name. </p>
<p>The data elements of the ENUMERATION are stored according to the datatype,
e.g., as an array of integers. The example below <!-- formerly Figure 39 -->
shows an example of how to create
an enumeration with five elements. The elements map symbolic names to
2-byte integers. See the table below.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
hid_t hdf_en_colors = H5Tcreate(H5T_ENUM, sizeof(short));
short val;
H5Tenum_insert(hdf_en_colors, “RED”, (val=0,&val));
H5Tenum_insert(hdf_en_colors, “GREEN”, (val=1,&val));
H5Tenum_insert(hdf_en_colors, “BLUE”, (val=2,&val));
H5Tenum_insert(hdf_en_colors, “WHITE”, (val=3,&val));
H5Tenum_insert(hdf_en_colors, “BLACK”, (val=4,&val));
H5Dcreate(fileid, datasetname, hdf_en_colors, spaceid, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 34. Create an enumeration with five elements
<!-- formerly Figure 39 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<br />
<table width="200" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="2" align="left" valign="bottom">
<b>Table 22. An enumeration<br />with five elements</b>
<!-- formerly Table 23 --></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="50%"><b>Name</b></td>
<td width="50%"><b>Value</b></td>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>RED</td>
<td>0</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>GREEN</td>
<td>1</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>BLUE</td>
<td>2</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>WHITE</td>
<td>3</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>BLACK</td>
<td>4</td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
</table>
<br />
<!-- NEW PAGE -->
<p>The figure below <!-- formerly Figure 40 -->shows how an array of eight
values might be stored. Conceptually,
the array is an array of symbolic names [BLACK, RED, WHITE, BLUE, ...]. See
item a in the figure below. <!-- formerly Figure 40a -->
These are stored as the values and are short integers. So, the first 2 bytes
are the value associated with “BLACK”, which is the number 4,
and so on. See item b in the figure below. <!-- formerly Figure 40b --></p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<table align="center" width="100%">
<tr>
<td align="center">a) Logical data to be written -
eight elements</td>
</tr>
<tr>
<td align="center">
<table>
<tr>
<td width="50" align="center">Index</td>
<td width="135" align="center">Name</td>
</tr>
</table>
<table border="1">
<tr>
<td width="30" align="center">0</td>
<td width="130" align="left">:BLACK</td>
</tr>
<tr>
<td width="30" align="center">1</td>
<td width="130" align="left">RED</td>
</tr>
<tr>
<td width="30" align="center">2</td>
<td width="130" align="left">WHITE</td>
</tr>
<tr>
<td width="30" align="center">3</td>
<td width="130" align="left">BLUE</td>
</tr>
<tr>
<td width="30" align="center">4</td>
<td width="130" align="left">RED</td>
</tr>
<tr>
<td width="30" align="center">5</td>
<td width="130" align="left">WHITE</td>
</tr>
<tr>
<td width="30" align="center">6</td>
<td width="130" align="left">BLUE</td>
</tr>
<tr>
<td width="30" align="center">7</td>
<td width="130" align="left">GREEN</td>
</tr>
</table>
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td align="center"><img src="Images/Dtypes_fig40.JPG"></td>
</tr>
<tr>
<td align="center">b) The storage layout. Total size of the
array is 16 bytes, 2 bytes per element.
</td>
</tr>
</table>
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 17. Storing an enum array
<!-- formerly Figure 40 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The order that members are inserted into an enumeration type is
unimportant; the important part is the associations between the symbol
names and the values. Thus, two enumeration datatypes will be considered
equal if and only if both types have the same symbol/value associations
and both have equal underlying integer datatypes. Type equality is
tested with the <code>H5Tequal</code> function.</p>
<p>If a particular architecture type is required, a little-endian or
big-endian datatype for example, use a native integer datatype as the
ENUM base datatype and use <code>H5Tconvert</code> on values as they
are read from or written to a dataset. </p>
<!-- NEW PAGE -->
<h4>6.5.4. Opaque</h4>
<p>In some cases, a user may have data objects that should be stored and
retrieved as blobs with no attempt to interpret them. For example,
an application might wish to store an array of encrypted certificates
which are 100 bytes long.</p>
<p>While an arbitrary block of data may always be stored as bytes,
characters, integers, or whatever, this might mislead programs about
the meaning of the data. The opaque datatype defines data elements which
are uninterpreted by HDF5. The opaque data may be labeled with
<code>H5Tset_tag</code> with a string that might be used by an
application. For example, the encrypted certificates might have
a tag to indicate the encryption and the certificate standard.</p>
<h4>6.5.5. Bitfield</h4>
<p>Some data is represented as bits, where the number of bits is not an
integral byte and the bits are not necessarily interpreted as a standard
type. Some examples might include readings from machine registers (e.g.,
switch positions), a cloud mask, or data structures with several small
integers that should be store in a single byte.</p>
<p>This data could be stored as integers, strings, or enumerations.
However, these storage methods would likely result in considerable wasted
space. For example, storing a cloud mask with one byte per value would
use up to eight times the space of a packed array of bits. </p>
<p>The HDF5 bitfield datatype class defines a data element that is a
contiguous sequence of bits, which are stored on disk in a packed array.
The programming model is the same as for unsigned integers: the datatype
object is created by copying a predefined datatype, and then the
precision, offset, and padding are set.</p>
<p>While the use of the bitfield datatype will reduce storage space
substantially, there will still be wasted space if the bitfield as a
whole does not match the 1-, 2-, 4-, or 8-byte unit in which it is
written. The remaining unused space can be removed by applying the
<a href="10_Datasets.html#N-Bit">N-bit filter</a> to the dataset
containing the bitfield data. </p>
<!--
<h4>5.6. Time</h4>
<p>The HDF5 time datatype defines storage layout for various date and
time standards. Currently, only Unix "time" and "timeval" structs are
supported. The H5T_UNIX_D32BE (LE) defines storage for 4 bytes
(sufficient for the time struct), H5T_UNIX_D64BE (LE) is sufficient
for timeval. The data is treated as a single opaque value.</p>
-->
<SCRIPT language="JavaScript">
<!--
document.writeln ("
<a name="Fvalues">
<div align=right>
<a href="#TOP"><font size="-1">(Top)</font></a>
</div>
</a>
");
-->
</SCRIPT>
<a name="Fvalues">
<h3 class=pagebefore>6.6. Fill Values</h3>
</a>
<p>The “fill value” for a dataset is the specification of
the default value assigned to data elements that have not yet been
written. In the case of a dataset with an atomic datatype, the fill
value is a single value of the appropriate datatype, such as
‘0’ or ‘-1.0’. In the case of a dataset with
a composite datatype, the fill value is a single data element of the
appropriate type. For example, for an array or compound datatype,
the fill value is a single data element with values for all the
component elements of the array or compound datatype.</p>
<p>The fill value is set (permanently) when the dataset is created.
The fill value is set in the dataset creation properties
<!-- editingComment
<span class="editingComment">[ [ [
(see chapter ??)
] ] ]</span>
-->
in the <code>H5Dcreate</code> call. Note that the <code>H5Dcreate</code>
call must also include the datatype of the dataset, and the value provided
for the fill value will be interpreted as a single element of this datatype.
The example below <!-- formerly Figure 41 -->shows code which creates a
dataset of integers with fill
value -1. Any unwritten data elements will be set to -1.</p>
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
hid_t plist_id;
int filler;
filler = -1;
plist_id = H5Pcreate(H5P_DATASET_CREATE);
H5Pset_fill_value(plist_id, H5T_NATIVE_INT, &filler);
/* Create the dataset with fill value ‘-1’. */
dataset_id = H5Dcreate(file_id, “/dset”, H5T_STD_I32BE,
dataspace_id, H5P_DEFAULT, plist_id, H5P_DEFAULT);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 35. Create a dataset with a fill value of -1
<!-- formerly Figure 41 --></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>
typedef struct s1_t {
int a;
char b;
double c;
} s1_t;
s1_t filler;
s1_tid = H5Tcreate (H5T_COMPOUND, sizeof(s1_t));
H5Tinsert(s1_tid, “a_name”, HOFFSET(s1_t, a), H5T_NATIVE_INT);
H5Tinsert(s1_tid, “b_name”, HOFFSET(s1_t, b), H5T_NATIVE_CHAR);
H5Tinsert(s1_tid, “c_name”, HOFFSET(s1_t, c), H5T_NATIVE_DOUBLE);
filler.a = -1;
filler.b = ‘*’;
filler.c = -2.0;
plist_id = H5Pcreate(H5P_DATASET_CREATE);
H5Pset_fill_value(plist_id, s1_tid, &filler);
/* Create the dataset with fill value (-1, ‘*’, -2.0). */
dataset = H5Dcreate(file, datasetname, s1_tid, space, H5P_DEFAULT,
plist_id, H5P_DEFAULT);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 36. Create a fill value for a compound datatype
<!-- formerly Figure 42 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The figure above <!-- formerly Figure 42 -->shows how to create a fill
value for a compound datatype. The procedure is the same as the previous
example except the filler must be a structure with the correct fields.
Each field is initialized to the desired fill value.</p>
<p>The fill value for a dataset can be retrieved by reading the dataset
creation properties of the dataset and then by reading the fill value with
<code>H5Pget_fill_value</code>. The data will be read into memory using
the storage layout specified by the datatype. This transfer will convert
data in the same way as <code>H5Dread</code>.
The figure below <!-- formerly Figure 43 --> shows how to get the fill
value from the dataset created in Example 33 above.</p>
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
hid_t plist2;
int filler;
dataset_id = H5Dopen(file_id, “/dset”, H5P_DEFAULT);
plist2 = H5Dget_create_plist(dataset_id);
H5Pget_fill_value(plist2, H5T_NATIVE_INT, &filler);
/* filler has the fill value, ‘-1’ */</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 37. Retrieve a fill value
<!-- formerly Figure 43 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>A similar procedure is followed for any datatype. The example below
<!-- formerly Figure 45 -->shows how to
read the fill value for the compound datatype created in an example above
<!-- formerly Figure 42 -->. Note that the program must pass an
element large enough to hold a fill value of the datatype indicated by the
argument to <code>H5Pget_fill_value</code>. Also, the program must
understand the datatype in order to interpret its components. This may
be difficult to determine without knowledge of the application that
created the dataset.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
char * fillbuf;
int sz;
dataset = H5Dopen( file, DATASETNAME, H5P_DEFAULT);
s1_tid = H5Dget_type(dataset);
sz = H5Tget_size(s1_tid);
fillbuf = (char *)malloc(sz);
plist_id = H5Dget_create_plist(dataset);
H5Pget_fill_value(plist_id, s1_tid, fillbuf);
printf(“filler.a: %d\n”,((s1_t *) fillbuf)->a);
printf(“filler.b: %c\n”,((s1_t *) fillbuf)->b);
printf(“filler.c: %f\n”,((s1_t *) fillbuf)->c);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 38. Read the fill value for a compound datatype
<!-- formerly Figure 44 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<SCRIPT language="JavaScript">
<!--
document.writeln ("
<a name="CCDtypes">
<div align=right>
<a href="#TOP"><font size="-1">(Top)</font></a>
</div>
</a>
");
-->
</SCRIPT>
<!-- NEW PAGE -->
<a name="CCDtypes">
<h3 class=pagebefore>6.7. Complex Combinations of Datatypes</h3>
</a>
<p>Several composite datatype classes define collections of other datatypes,
including other composite datatypes. In general, a datatype can be nested
to any depth, with any combination of datatypes.</p>
<p>For example, a compound datatype can have members that are other compound
datatypes, arrays, VL datatypes. An array can be an array of array,
an array of compound, or an array of VL. And a VL datatype can be a
variable-length array of compound, array, or VL datatypes.</p>
<p>These complicated combinations of datatypes form a logical tree,
with a single root datatype, and leaves which must be atomic datatypes
(predefined or user-defined). The figure below <!-- formerly Figure 45 -->
shows an example of a logical
tree describing a compound datatype constructed from different datatypes.</p>
<p>Recall that the datatype is a description of the layout of storage.
The complicated compound datatype is constructed from component datatypes,
each of which describe the layout of part of the storage. Any datatype can
be used as a component of a compound datatype, with the following
restrictions:</p>
<ol>
<li>No byte can be part of more than one component datatype (i.e., the
fields cannot overlap within the compound datatype)</li><br />
<li>The total size of the components must be less than or equal to the
total size of the compound datatype</li>
</ol>
<p>These restrictions are essentially the rules for C structures and similar
record types familiar from programming languages. Multiple typing, such
as a C union, is not allowed in HDF5 datatypes.</p>
<table width="500" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dtypes_fig45.JPG">
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 18. A compound datatype built with
different datatypes<!-- formerly Figure 45 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<!-- NEW PAGE -->
<h4>6.7.1. Creating a Complicated Compound Datatype</h4>
<p>To construct a complicated compound datatype, each component is
constructed, and then added to the enclosing datatype description.
The example below <!-- formerly Figure 46 --> shows
how to create a compound datatype with four members:</p>
<ul>
<li>“T1”, a compound datatype with three members</li>
<li>“T2”, a compound datatype with two members</li>
<li>“T3”, a one-dimensional array of integers</li>
<li>“T4”, a string</li>
</ul>
<p>Below the example code is a figure that shows this datatype as a logical
tree. <!-- formerly Figure 47 --> The output of the
<em>h5dump</em> utility is shown in the example below the figure.
<!-- the example was formerly called Figure 48.--></p>
<p>Each datatype is created as a separate datatype object. Figure 20 below
<!-- formerly Figure 49 --> shows
the storage layout for the four individual datatypes. Then the datatypes are
inserted into the outer datatype at an appropriate offset. Figure 21 below
<!-- formerly Figure 50 -->shows
the resulting storage layout. The combined record is 89 bytes long.</p>
<p>The Dataset is created using the combined compound datatype. The dataset
is declared to be a 4 by 3 array of compound data. Each data element is an
instance of the 89-byte compound datatype. Figure 22 below
<!-- formerly Figure 51 -->shows the layout of
the dataset, and expands one of the elements to show the relative position
of the component data elements.</p>
<p>Each data element is a compound datatype, which can be written or read
as a record, or each field may be read or written individually. The first
field (“T1”) is itself a compound datatype with three fields
(“T1.a”, “T1.b”, and “T1.c”).
“T1” can be read or written as a record, or individual
fields can be accessed. Similarly, the second filed is a compound datatype
with two fields (“T2.f1”, “T2.f2”).</p>
<p>The third field (“T3”) is an array datatype. Thus,
“T3” should be accessed as an array of 40 integers. Array
data can only be read or written as a single element, so all 40
integers must be read or written to the third field. The fourth
field (“T4”) is a single string of length 25.</p>
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
typedef struct s1_t {
int a;
char b;
double c;
} s1_t;
typedef struct s2_t {
float f1;
float f2;
} s2_t;
hid_t s1_tid, s2_tid, s3_tid, s4_tid, s5_tid;
/* Create a datatype for s1 */
s1_tid = H5Tcreate (H5T_COMPOUND, sizeof(s1_t));
H5Tinsert(s1_tid, “a_name”, HOFFSET(s1_t, a), H5T_NATIVE_INT);
H5Tinsert(s1_tid, “b_name”, HOFFSET(s1_t, b), H5T_NATIVE_CHAR);
H5Tinsert(s1_tid, “c_name”, HOFFSET(s1_t, c), H5T_NATIVE_DOUBLE);
/* Create a datatype for s2. *.
s2_tid = H5Tcreate (H5T_COMPOUND, sizeof(s2_t));
H5Tinsert(s2_tid, “f1”, HOFFSET(s2_t, f1), H5T_NATIVE_FLOAT);
H5Tinsert(s2_tid, “f2”, HOFFSET(s2_t, f2), H5T_NATIVE_FLOAT);
/* Create a datatype for an Array of integers */
s3_tid = H5Tarray_create(H5T_NATIVE_INT, RANK, dim);
/* Create a datatype for a String of 25 characters */
s4_tid = H5Tcopy(H5T_C_S1);
H5Tset_size(s4_tid, 25);
/*
* Create a compound datatype composed of one of each of these
* types.
* The total size is the sum of the size of each.
*/
sz = H5Tget_size(s1_tid) + H5Tget_size(s2_tid) + H5Tget_size(s3_tid)
+ H5Tget_size(s4_tid);
s5_tid = H5Tcreate (H5T_COMPOUND, sz);
/* insert the component types at the appropriate offsets */
H5Tinsert(s5_tid, “T1”, 0, s1_tid);
H5Tinsert(s5_tid, “T2”, sizeof(s1_t), s2_tid);
H5Tinsert(s5_tid, “T3”, sizeof(s1_t)+sizeof(s2_t), s3_tid);
H5Tinsert(s5_tid, “T4”, (sizeof(s1_t) +sizeof(s2_t)+
H5Tget_size(s3_tid)), s4_tid);
/*
* Create the dataset with this datatype.
*/
dataset = H5Dcreate(file, DATASETNAME, s5_tid, space, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT);</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 39. Create a compound datatype with four members
<!-- formerly Figure 46 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<br />
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dtypes_fig47.JPG">
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 19. Logical tree for the compound
datatype with four members<!-- formerly Figure 47 --></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>
DATATYPE H5T_COMPOUND {
H5T_COMPOUND {
H5T_STD_I32LE “a_name”;
H5T_STD_I8LE “b_name”;
H5T_IEEE_F64LE “c_name”;
} “T1”;
H5T_COMPOUND {
H5T_IEEE_F32LE “f1”;
H5T_IEEE_F32LE “f2”;
} “T2”;
H5T_ARRAY { [10] H5T_STD_I32LE } “T3”;
H5T_STRING {
STRSIZE 25;
STRPAD H5T_STR_NULLTERM;
CSET H5T_CSET_ASCII;
CTYPE H5T_C_S1;
} “T4”;
}</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 40. Output from h5dump for the compound datatype
<!-- formerly Figure 48 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<br />
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<table align="center" border="0" width="100%">
<tr>
<td valign="middle" align="left">a) Compound type ‘s1_t’, size 16 bytes.</td>
</tr>
<tr><td>
<table border="1" align="center" width="100%">
<tr>
<td valign="middle" align="center" width="25%"><code>Byte 0</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 1</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 2</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 3</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>aaaaaaaa</code></td>
<td valign="middle" align="center"><code>aaaaaaaa</code></td>
<td valign="middle" align="center"><code>aaaaaaaa</code></td>
<td valign="middle" align="center"><code>aaaaaaaa</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>Byte 4</code></td>
<td valign="middle" align="center"><code>Byte 5</code></td>
<td valign="middle" align="center"><code>Byte 6</code></td>
<td valign="middle" align="center"><code>Byte 7</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>bbbbbbbb</code></td>
<td valign="middle" align="center"><code> </code></td>
<td valign="middle" align="center"><code> </code></td>
<td valign="middle" align="center"><code> </code></td>
</tr>
</table>
<table border="1" align="center" width="100%">
<tr>
<td valign="middle" align="center" width="25%"><code>Byte 8</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 9</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 10</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 11</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>cccccccc</code></td>
<td valign="middle" align="center"><code>cccccccc</code></td>
<td valign="middle" align="center"><code>cccccccc</code></td>
<td valign="middle" align="center"><code>cccccccc</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>Byte 12</code></td>
<td valign="middle" align="center"><code>Byte 13</code></td>
<td valign="middle" align="center"><code>Byte 14</code></td>
<td valign="middle" align="center"><code>Byte 15</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>cccccccc</code></td>
<td valign="middle" align="center"><code>cccccccc</code></td>
<td valign="middle" align="center"><code>cccccccc</code></td>
<td valign="middle" align="center"><code>cccccccc</code></td>
</tr>
</table>
</td></tr>
<tr>
<td valign="middle" align="left"> <br />b) Compound type ‘s2_t’, size 8 bytes.</td>
</tr>
<tr><td>
<table border="1" align="center" width="100%">
<tr>
<td valign="middle" align="center" width="25%"><code>Byte 0</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 1</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 2</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 3</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>ffffffff</code></td>
<td valign="middle" align="center"><code>ffffffff</code></td>
<td valign="middle" align="center"><code>ffffffff</code></td>
<td valign="middle" align="center"><code>ffffffff</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>Byte 4</code></td>
<td valign="middle" align="center"><code>Byte 5</code></td>
<td valign="middle" align="center"><code>Byte 6</code></td>
<td valign="middle" align="center"><code>Byte 7</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>gggggggg</code></td>
<td valign="middle" align="center"><code>gggggggg</code></td>
<td valign="middle" align="center"><code>gggggggg</code></td>
<td valign="middle" align="center"><code>gggggggg</code></td>
</tr>
</table>
</td></tr>
<tr>
<td valign="middle" align="left"> <br />c) Array type ‘s3_tid’, 40 integers, total size 40 bytes.</td>
</tr>
<tr><td>
<table border="1" align="center" width="100%">
<tr>
<td valign="middle" align="center" width="25%"><code>Byte 0</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 1</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 2</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 3</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>00000000</code></td>
<td valign="middle" align="center"><code>00000000</code></td>
<td valign="middle" align="center"><code>00000000</code></td>
<td valign="middle" align="center"><code>00000000</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>Byte 4</code></td>
<td valign="middle" align="center"><code>Byte 5</code></td>
<td valign="middle" align="center"><code>Byte 6</code></td>
<td valign="middle" align="center"><code>Byte 7</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>00000000</code></td>
<td valign="middle" align="center"><code>00000000</code></td>
<td valign="middle" align="center"><code>00000000</code></td>
<td valign="middle" align="center"><code>00000001</code></td>
</tr>
</table>
<table align="center" width="100%">
<tr>
<td align="center" colspan="4"> ... <br /> </td>
</tr>
</table>
<table border="1" align="center" width="100%">
<tr>
<td valign="middle" align="center" width="25%"><code>Byte 36</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 37</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 38</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 39</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>00000000</code></td>
<td valign="middle" align="center"><code>00000000</code></td>
<td valign="middle" align="center"><code>00000000</code></td>
<td valign="middle" align="center"><code>00001010</code></td>
</tr>
</table>
</td></tr>
<tr>
<td valign="middle" align="left"> <br />d) String type ‘s4_tid’, size 25 bytes.</td>
</tr>
<tr><td>
<table border="1" align="center" width="100%">
<tr>
<td valign="middle" align="center" width="25%"><code>Byte 0</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 1</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 2</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 3</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>‘a’</code></td>
<td valign="middle" align="center"><code>‘b’</code></td>
<td valign="middle" align="center"><code>‘c’</code></td>
<td valign="middle" align="center"><code>‘d’</code></td>
</tr>
</table>
<table align="center" width="100%">
<tr>
<td align="center" colspan="4"> ... <br /> </td>
</tr>
</table>
<table border="1" align="center" width="100%">
<tr>
<td valign="middle" align="center" width="25%"><code>Byte 24</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 25</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 26</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 27</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>00000000</code></td>
<td valign="middle" align="center"><code> </code></td>
<td valign="middle" align="center"><code> </code></td>
<td valign="middle" align="center"><code> </code></td>
</tr>
</table>
</td></tr>
</table>
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 20. The storage layout for the
four member datatypes<!-- formerly Figure 49 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<br />
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dtypes_fig50.JPG" width="550">
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 21. The storage layout of the combined four members
<!-- formerly Figure 50 --></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="center">
<hr color="green" size="3"/></td>
</tr>
<tr align="center">
<td align="center"><img src="Images/Dtypes_fig51.JPG"
width="550"></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 22. The layout of the dataset
<!-- formerly Figure 51 --></b>
<hr color="green" size="3"/></td>
</tr>
<!-- 9.1.10, the JPG above, Dtypes_fig51.jpg, spells Element incorrectly -->
<!-- 9.1.10, the section above has text and many examples and figures.
Should the text be interspersed with the examples and figures at some
point? -->
</table>
<br />
<!-- NEW PAGE -->
<h4>6.7.2. Analyzing and Navigating a Compound Datatype</h4>
<p>A complicated compound datatype can be analyzed piece by piece to
discover the exact storage layout. In the example above, the outer
datatype is analyzed to discover that it is a compound datatype with
four members. Each member is analyzed in turn to construct a complete
map of the storage layout.</p>
<p>The example below <!-- formerly Figure 52 -->shows an example of code
that partially analyzes a nested
compound datatype. The name and overall offset and size of the component
datatype is discovered, and then its type is analyzed depending on the
datatype class. Through this method, the complete storage layout can be
discovered.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
s1_tid = H5Dget_type(dataset);
if (H5Tget_class(s1_tid) == H5T_COMPOUND) {
printf(“COMPOUND DATATYPE {\n”);
sz = H5Tget_size(s1_tid);
nmemb = H5Tget_nmembers(s1_tid);
printf(“ %d bytes\n”,sz);
printf(“ %d members\n”,nmemb);
for (i =0; i < nmemb; i++) {
s2_tid = H5Tget_member_type(s1_tid, i);
if (H5Tget_class(s2_tid) == H5T_COMPOUND) {
/* recursively analyze the nested type. */
} else if (H5Tget_class(s2_tid) == H5T_ARRAY) {
sz2 = H5Tget_size(s2_tid);
printf(“ %s: NESTED ARRAY DATATYPE offset %d size %d {\n”,
H5Tget_member_name(s1_tid, i),
H5Tget_member_offset(s1_tid, i),
sz2);
H5Tget_array_dims(s2_tid, dim);
s3_tid = H5Tget_super(s2_tid);
/* Etc., analyze the base type of the array */
} else {
/* analyze a simple type */
printf(“ %s: type code %d offset %d size %d\n”,
H5Tget_member_name(s1_tid, i),
H5Tget_class(s2_tid),
H5Tget_member_offset(s1_tid, i),
H5Tget_size(s2_tid));
}
/* and so on. */</pre></td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 41. Analyzing a compound datatype and its members
<!-- formerly Figure 52--></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<SCRIPT language="JavaScript">
<!--
document.writeln ("
<a name="LCDtypeObj">
<div align=right>
<a href="#TOP"><font size="-1">(Top)</font></a>
</div>
</a>
");
-->
</SCRIPT>
<br />
<!-- NEW PAGE -->
<a name="LCDtypeObj">
<h3 class=pagebefore>6.8. Life Cycle of the Datatype Object</h3>
</a>
<p>Application programs access HDF5 datatypes through identifiers.
Identifiers are obtained by creating a new datatype or by copying
or opening an existing datatype. The identifier can be used until
it is closed or until the library shuts down. See items a and b in
the figure below. <!-- formerly Figure 53a,b --> By default, a
datatype is <em>transient</em>, and it disappears when it is closed. </p>
<p>When a dataset or attribute is created (<code>H5Dcreate</code> or
<code>H5Acreate</code>), its datatype is stored in the HDF5
file as part of the dataset or attribute object. See item c in
the figure below. Once an object created, its datatype cannot
be changed or deleted. The datatype can be accessed by calling
<code>H5Dget_type</code>, <code>H5Aget_type</code>,
<code>H5Tget_super</code>, or <code>H5Tget_member_type</code>.
See item d in the figure below. These calls return an identifier to a
<em>transient</em> copy of the datatype of the dataset or attribute
unless the datatype is a committed datatype. </p>
<p>Note that when an object is created, the stored datatype is a copy
of the transient datatype. If two objects are created with the same
datatype, the information is stored in each object with the same
effect as if two different datatypes were created and used. </p>
<p>A transient datatype can be stored using <code>H5Tcommit</code> in the
HDF5 file as an independent, named object, called a committed datatype.
Committed datatypes were formerly known as named datatypes.
See item e in the figure below. Subsequently, when a committed datatype
is opened with <code>H5Topen</code> (item f), or is obtained with
<code>H5Tget_type</code> or similar call (item k), the return
is an identifier to a transient copy of the stored datatype. The identifier
can be used in the same way as other datatype identifiers except that
the committed datatype cannot be modified. When a committed datatype is
copied with <code>H5Tcopy</code>, the return is a new, modifiable,
transient datatype object (item f). </p>
<p>When an object is created using a committed datatype (<code>H5Dcreate</code>,
<code>H5Acreate</code>), the stored datatype is used without copying
it to the object. See item j in the figure below. In this case, if
multiple objects are created using the same committed datatype, they
all share the exact same datatype object. This saves space and makes
clear that the datatype is shared. Note that a committed datatype can
be shared by objects within the same HDF5 file, but not by objects
in other files. For more information on copying committed datatypes to
other HDF5 files, see the
“Copying Committed Datatypes with H5Ocopy” topic in
the “<a href="17_Additional.html">Additional Resources</a>”
chapter.</p>
<p>A committed datatype can be deleted from the file by calling
<code>H5Ldelete</code> which replaces <code>H5Gunlink</code>.
See item i in the figure below. If one or more objects are still using the
datatype, the committed datatype cannot be accessed with <code>H5Topen</code>,
but will not be removed from the file until it is no longer used.
<code>H5Tget_type</code> and similar calls will return a transient
copy of the datatype.</p>
<!-- NEW PAGE -->
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dtypes_fig53.JPG">
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 23. Life cycle of a datatype
<!-- formerly Figure 53 --> </b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>Transient datatypes are initially modifiable. Note that
when a datatype is copied or when it is written to the file (when an
object is created) or the datatype is used to create a composite
datatype, a copy of the current state of the datatype is used. If
the datatype is then modified, the changes have no effect on
datasets, attributes, or datatypes that have already been created.
See the figure below.</p>
<p>A transient datatype can be made <em>read-only</em>
(<code>H5Tlock</code>). Note that the datatype is still transient,
and otherwise does not change. A datatype that is <em>immutable</em>
is <em>read-only</em> but cannot be closed except when the entire
library is closed. The predefined types such as
<code>H5T_NATIVE_INT</code> are <em>immutable transient</em> types.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dtypes_fig54.JPG">
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 24. Transient datatype states: modifiable, read-only, and
immutable <!-- formerly Figure 54 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>To create two or more datasets that share a common datatype,
first commit the datatype, and then use that datatype to create the
datasets. See the example below.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
hid_t t1 = ...some transient type...;
H5Tcommit (file, “shared_type”, t1, H5P_DEFAULT, H5P_DEFAULT,
H5P_DEFAULT);
hid_t dset1 = H5Dcreate (file, “dset1”, t1, space, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT);
hid_t dset2 = H5Dcreate (file, “dset2”, t1, space, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT);
hid_t dset1 = H5Dopen (file, “dset1”, H5P_DEFAULT);
hid_t t2 = H5Dget_type (dset1);
hid_t dset3 = H5Dcreate (file, “dset3”, t2, space, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT);
hid_t dset4 = H5Dcreate (file, “dset4”, t2, space, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT);</pre> </td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 42. Create a shareable datatype
<!-- formerly Figure 55 --></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 23. Datatype APIs</b>
<!-- formerly Table 24 --></td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td width="50%"><b>Function</b></td>
<td width="50%"><b>Description</b></td>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>hid_t H5Topen (hid_t location, <br />const
char *name)</code></td>
<td>A committed datatype can be opened by
calling this function, which returns a datatype identifier. The
identifier should eventually be released by calling
<code>H5Tclose()</code> to release resources. The committed
datatype returned by this function is read-only or a negative
value is returned for failure. The location is either a file or
group identifier.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>herr_t H5Tcommit (hid_t location,
const char *name, hid_t type, H5P_DEFAULT, H5P_DEFAULT,
<br />H5P_DEFAULT)</code></td>
<td>A transient datatype (not immutable) can
be written to a file and turned into a committed datatype by calling this
function. The location is either a file or group identifier and when
combined with name refers to a new committed datatype.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td><code>htri_t H5Tcommitted
(hid_t type)</code></td>
<td>A type can be queried to determine
if it is a committed type or a transient type. If this function returns a
positive value then the type is committed. Datasets which return committed
datatypes with <code>H5Dget_type()</code> are able to share the
datatype with other datasets in the same file.</td>
</tr>
<tr><td colspan="2"><hr color="green" size="3" /></td></tr>
</table>
<br />
<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>6.9. Data Transfer: Datatype Conversion and Selection</h3>
</a>
<p>When data is transferred (write or read), the storage layout of the data
elements may be different. For example, an integer might be stored on disk
in big-endian byte order and read into memory with little-endian byte order.
In this case, each data element will be transformed by the HDF5 Library
during the data transfer.</p>
<p>The conversion of data elements is controlled by specifying the datatype
of
the source and specifying the intended datatype of the destination.
The storage format on disk is the datatype specified when the dataset
is created. The datatype of memory must be specified in the library call.</p>
<p>In order to be convertible, the datatype of the source and destination
must have the same datatype class (with the exception of enumeration
type). Thus, integers can be converted to other integers, and floats to
other floats, but integers cannot (yet) be converted to floats. For
each atomic datatype class, the possible conversions are defined. An
enumeration datatype can be converted to an integer or a
floating-point number datatype.</p>
<p>Basically, any datatype can be converted to another datatype of the same
datatype class. The HDF5 Library automatically converts all properties.
If the destination is too small to hold the source value then an overflow
or underflow exception occurs. If a handler is defined with the
<code>H5Pset_type_conv_cb</code> function,
<!-- editingComment
<span class="editingComment">[ [ [
(see Chapter??)
] ] ]</span>
-->
it will be called. Otherwise,
a default action will be performed. The table below <!-- formerly Table 25-->
summarizes the default actions.</p>
<table width="600" cellspacing="0" align="center" cellpadding="0">
<tr valign="bottom">
<td colspan="3" align="left" valign="bottom">
<b>Table 24. Default actions for datatype conversion exceptions</b>
<!-- formerly Table 25 --></td>
</tr>
<tr><td colspan="3"><hr color="green" size="3" /></td></tr>
<tr valign="top">
<td><b>Datatype Class</b></td>
<td><b>Possible Exceptions</b></td>
<td><b>Default Action</b></td>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Integer</td>
<td>Size, offset, pad</td>
<td> </td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Float</td>
<td>Size, offset, pad, ebits</td>
<td> </td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>String</td>
<td>Size</td>
<td>Truncates, zero terminate if required.</td>
</tr>
<tr><td colspan="3"><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td>Enumeration</td>
<td>No field</td>
<td>All bits set</td>
</tr>
<tr><td colspan="3"><hr color="green" size="3" /></td></tr>
</table>
<br />
<p>For example, when reading data from a dataset, the source datatype is the
datatype set when the dataset was created, and the destination datatype is
the description of the storage layout in memory. The destination datatype
must be specified in
the <code>H5Dread</code> call. The example below <!-- formerly Figure 56 -->
shows an example of reading a dataset
of 32-bit integers. The figure <!-- formerly Figure 57 -->below the example
shows the data transformation
that is performed.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
/* Stored as H5T_STD_BE32 */
/* Use the native memory order in the destination */
mem_type_id = H5Tcopy(H5T_NATIVE_INT);
status = H5Dread(dataset_id, mem_type_id, mem_space_id,
file_space_id, xfer_plist_id, buf );</pre> </td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 43. Specify the destination datatype
with <code>H5Dread</code><!-- formerly Figure 56 --></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="center">
<hr color="green" size="3"/>
<table align="center" width="100%">
<tr><td>
<table align="left">
<tr>
<td align="left">Source Datatype: <code>H5T_STD_BE32</code></td>
</tr>
</table>
</td></tr>
<tr><td>
<table align="left" border="1" width="100%">
<tr>
<td valign="middle" align="center" width="25%"><code>Byte 0</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 1</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 2</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 3</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>aaaaaaaa</code></td>
<td valign="middle" align="center"><code>bbbbbbbb</code></td>
<td valign="middle" align="center"><code>cccccccc</code></td>
<td valign="middle" align="center"><code>dddddddd</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>Byte 4</code></td>
<td valign="middle" align="center"><code>Byte 5</code></td>
<td valign="middle" align="center"><code>Byte 6</code></td>
<td valign="middle" align="center"><code>Byte 7</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>wwwwwwww</code></td>
<td valign="middle" align="center"><code>xxxxxxxx</code></td>
<td valign="middle" align="center"><code>yyyyyyyy</code></td>
<td valign="middle" align="center"><code>zzzzzzzz</code></td>
</tr>
</table>
</td></tr>
<tr>
<td>. . . .</td>
</tr>
<tr><td>
<table align="center" width="100%">
<tr>
<td width="45%"> </td>
<td width="10%" align="center"><img src="Images/Dtypes_fig57_arrow.jpg"></td>
<td width="45%" align="left">Automatically byte swapped<br /> during the <code>H5Dread</code></td>
</tr>
</table>
</td></tr>
<tr><td>
<table align="left">
<tr>
<td align="left">Destination Datatype: <code>H5T_STD_LE32</code></td>
</tr>
</table>
</td></tr>
<tr><td>
<table align="left" border="1" width="100%">
<tr>
<td valign="middle" align="center" width="25%"><code>Byte 0</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 1</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 2</code></td>
<td valign="middle" align="center" width="25%"><code>Byte 3</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>bbbbbbbb</code></td>
<td valign="middle" align="center"><code>aaaaaaaa</code></td>
<td valign="middle" align="center"><code>dddddddd</code></td>
<td valign="middle" align="center"><code>cccccccc</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>Byte 4</code></td>
<td valign="middle" align="center"><code>Byte 5</code></td>
<td valign="middle" align="center"><code>Byte 6</code></td>
<td valign="middle" align="center"><code>Byte 7</code></td>
</tr>
<tr>
<td valign="middle" align="center"><code>xxxxxxxx</code></td>
<td valign="middle" align="center"><code>wwwwwwww</code></td>
<td valign="middle" align="center"><code>zzzzzzzz</code></td>
<td valign="middle" align="center"><code>yyyyyyyy</code></td>
</tr>
</table>
</td></tr>
<tr>
<td>. . . .</td>
</tr>
<tr><td>
</table>
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 25. Layout of a datatype conversion
<!-- formerly Figure 57 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>One thing to note in the example above <!-- formerly Figure 56 -->is the
use of the predefined native datatype <code>H5T_NATIVE_INT</code>.
Recall that in this example, the data was stored as a 4-bytes
in big-endian order. The application wants to read this data into an array
of integers in memory. Depending on the system, the storage layout of memory
might be either big or little-endian, so the data may need to be transformed
on some platforms and not on others. The <code>H5T_NATIVE_INT</code> type
is set by the HDF5 Library to be the correct type to describe the storage
layout of the memory on the system. Thus, the code in the example above
<!-- Figure 56 -->will work correctly on any platform, performing a
transformation when needed.</p>
<p>There are predefined native types for most atomic datatypes, and
these can be combined in composite datatypes. In general, the predefined
native datatypes should always be used for data stored in memory.</p>
<table align="center" width="300" >
<tr >
<td style="background-color:#E6F2E6">
<hr color="green" size="3"/>
<b>Storage Properties </b><br />
<p>Predefined native datatypes describe the storage properties
of memory.</p>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>For composite datatypes, the component atomic datatypes will be converted.
For a variable-length datatype, the source and destination must have
compatible base datatypes. For a fixed-size string datatype, the length
and padding of the strings will be converted. Variable-length strings
are converted as variable-length datatypes.</p>
<p>For an array datatype, the source and destination must have the same rank
and dimensions, and the base datatype must be compatible. For example an
array datatype of 4 x 3 32-bit big-endian integers can be transferred to an
array datatype of 4 x 3 little-endian integers, but not to a 3 x 4 array.</p>
<p>For an enumeration datatype, data elements are converted by matching the
symbol names of the source and destination datatype. The figure below
<!-- formerly Figure 58 -->shows an example
of how two enumerations with the same names and different values would be
converted. The value ‘2’ in the source dataset would be converted
to ‘0x0004’ in the destination.</p>
<p>If the source data stream contains values which are not in the domain of
the conversion map then an overflow exception is raised within the library.</p>
<table width="400" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<table border="0">
<tr>
<td width="%"> 0 </td>
<td width="%"> </td>
<td width="%">RED</td>
<td width="%"><img src="Images/Dtypes_fig58_arrow.jpg"></td>
<td align="right" width="%">RED</td>
<td width="%"> </td>
<td width="%"> 0x0001</td>
</tr>
<tr>
<td width="%"> 1 </td>
<td width="%"> </td>
<td width="%">GREEN </td>
<td width="%"><img src="Images/Dtypes_fig58_arrow.jpg"></td>
<td align="right" width="%"> GREEN</td>
<td width="%"> </td>
<td width="%"> 0x0002</td>
</tr>
<tr>
<td width="%"> 2 </td>
<td width="%"> </td>
<td width="%">BLUE</td>
<td width="%"><img src="Images/Dtypes_fig58_arrow.jpg"></td>
<td align="right" width="%">BLUE</td>
<td width="%"> </td>
<td width="%"> 0x0004</td>
</tr>
<tr>
<td width="%"> 3 </td>
<td width="%"> </td>
<td width="%">WHITE</td>
<td width="%"><img src="Images/Dtypes_fig58_arrow.jpg"></td>
<td align="right" width="%">WHITE</td>
<td width="%"> </td>
<td width="%"> 0x0008</td>
</tr>
<tr>
<td width="%"> 4 </td>
<td width="%"> </td>
<td width="%">BLACK </td>
<td width="%"><img src="Images/Dtypes_fig58_arrow.jpg"></td>
<td align="right" width="%"> BLACK</td>
<td width="%"> </td>
<td width="%"> 0x0010</td>
</tr>
</table>
</td></tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 26. An enum datatype conversion
<!-- formerly Figure 58 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The library also allows conversion from enumeration to a numeric
datatype. A numeric datatype is either an integer or a floating-point
number. This conversion can simplify the application program because
the base type for an enumeration datatype is an integer datatype. The
application program can read the data from a dataset of enumeration
datatype in file into a memory buffer of numeric datatype. And it can
write enumeration data from memory into a dataset of numeric datatype
in file, too. </p>
<p>For compound datatypes, each field of the source and destination
datatype is converted according to its type. The name of the fields
must be the same in the source and the destination in order for the
data to be converted. </p>
<p>The example below <!-- formerly Figure 59 -->shows the compound
datatypes shows sample code to create a
compound datatype with the fields aligned on word boundaries (s1_tid)
and with the fields packed (s2_tid). The former is suitable as a description
of the storage layout in memory, the latter would give a more compact store
on disk. These types can be used for transferring data, with
<code>s2_tid</code> used to create the dataset, and
<code>s1_tid</code> used as the memory datatype.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
typedef struct s1_t {
int a;
char b;
double c;
} s1_t;
s1_tid = H5Tcreate (H5T_COMPOUND, sizeof(s1_t));
H5Tinsert(s1_tid, “a_name”, HOFFSET(s1_t, a), H5T_NATIVE_INT);
H5Tinsert(s1_tid, “b_name”, HOFFSET(s1_t, b), H5T_NATIVE_CHAR);
H5Tinsert(s1_tid, “c_name”, HOFFSET(s1_t, c), H5T_NATIVE_DOUBLE);
s2_tid = H5Tcopy(s1_tid);
H5Tpack(s2_tid);</pre> </td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 44. Create an aligned and packed compound datatype
<!-- formerly Figure 59 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>When the data is transferred, the fields within each data element will be
aligned according to the datatype specification. The figure below
<!-- formerly Figure 60 -->shows how one data
element would be aligned in memory and on disk. Note that the size and byte
order of the elements might also be converted during the transfer.</p>
<p>It is also possible to transfer some of the fields of compound datatypes.
Based on the example above, <!-- formerly Figure 59 --> the example below
<!-- formerly Figure 61 -->shows a compound datatype
that selects the first and third fields of the <code>s1_tid</code>.
The second datatype can be used as the memory datatype, in which case data
is read from or written to these two fields, while skipping the middle field.
The second figure below <!-- formerly Figure 62 -->shows the layout for
two data elements.</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="center">
<hr color="green" size="3"/>
<img src="Images/Dtypes_fig60.JPG" width="550">
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 27. Alignment of a compound datatype
<!-- formerly Figure 60 --></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>
typedef struct s1_t {
int a;
char b;
double c;
} s1_t;
typedef struct s2_t { /* two fields from s1_t */
int a;
double c;
} s2_t;
s1_tid = H5Tcreate (H5T_COMPOUND, sizeof(s1_t));
H5Tinsert(s1_tid, “a_name”, HOFFSET(s1_t, a), H5T_NATIVE_INT);
H5Tinsert(s1_tid, “b_name”, HOFFSET(s1_t, b), H5T_NATIVE_CHAR);
H5Tinsert(s1_tid, “c_name”, HOFFSET(s1_t, c), H5T_NATIVE_DOUBLE);
s2_tid = H5Tcreate (H5T_COMPOUND, sizeof(s2_t));
H5Tinsert(s1_tid, “a_name”, HOFFSET(s2_t, a), H5T_NATIVE_INT);
H5Tinsert(s1_tid, “c_name”, HOFFSET(s2_t, c), H5T_NATIVE_DOUBLE);
</pre> </td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 45. Transfer some fields of a compound datatype
<!-- formerly Figure 61 --></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="center">
<hr color="green" size="3"/>
<img src="Images/Dtypes_fig62.JPG" width="550">
</td>
</tr>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left" >
<b>Figure 28. Layout when an element is skipped
<!-- formerly Figure 62 --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<!-- NEW PAGE -->
<a name="TextDescriptions">
<h3 class=pagebefore>6.10. Text Descriptions of Datatypes: Conversion to
and from</h3></a>
<p>HDF5 provides a means for generating a portable and human-readable
text descripition of a datatype and
for generating a datatype from such a text description.
This capability is particularly useful
for creating complex datatypes in a single step,
for creating a text description of a datatype for debugging purposes,
and for creating a portable datatype definition that can then be used
to recreate the datatype on many platforms or in other applications.</p>
<p>These tasks are handled by two functions provided in the HDF5 high-level
library (<a href="../HL/RM_H5LT.html" target="ExtWin">H5HL</a>):</p>
<div align="left">
<table >
<tr valign="top" align="left">
<td><span class="codeText">H5LTtext_to_dtype</span> </td>
<td>Creates an HDF5 datatype in a single step.</td>
</tr><tr valign="top" align="left">
<td><span class="codeText">H5LTdtype_to_text</span></td>
<td>Translates an HDF5 datatype into a text description.</td>
</tr>
</table>
</div>
<p>Note that this functionality requires that the
HDF5 High-Level Library (H5LT) be installed.
<!-- editingComment
See
<span class="editingComment">< < Quick Start > ></span>.
-->
<p>While <span class="codeText">H5LTtext_to_dtype</span> can be used to
generate any sort of datatype, it is particularly useful for
complex datatypes. </p>
<p><span class="codeText">H5LTdtype_to_text</span> is most likely to be
used in two sorts of situations:
when a datatype must be closely examined for debugging purpose
or to create a portable text description of the datatype
that can then be used to recreate the datatype on other platforms
or in other applications.</p>
<p>These two functions work for all valid HDF5 datatypes
except time, bitfield, and reference datatypes.</p>
<p>The currently supported text format used by
<span class="codeText">H5LTtext_to_dtype</span> and
<span class="codeText">H5LTdtype_to_text</span> is the
data description language (DDL) and conforms to the
<a href="../ddl.html" target="ExtWin"><cite>HDF5 DDL</cite></a>.
The portion of the <cite>HDF5 DDL</cite> that defines HDF5 datatypes
appears below.
</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
<datatype> ::= <atomic_type> | <compound_type> | <array_type> |
<variable_length_type>
<atomic_type> ::= <integer> | <float> | <time> | <string> |
<bitfield> | <opaque> | <reference> | <enum>
<integer> ::= H5T_STD_I8BE | H5T_STD_I8LE |
H5T_STD_I16BE | H5T_STD_I16LE |
H5T_STD_I32BE | H5T_STD_I32LE |
H5T_STD_I64BE | H5T_STD_I64LE |
H5T_STD_U8BE | H5T_STD_U8LE |
H5T_STD_U16BE | H5T_STD_U16LE |
H5T_STD_U32BE | H5T_STD_U32LE |
H5T_STD_U64BE | H5T_STD_U64LE |
H5T_NATIVE_CHAR | H5T_NATIVE_UCHAR |
H5T_NATIVE_SHORT | H5T_NATIVE_USHORT |
H5T_NATIVE_INT | H5T_NATIVE_UINT |
H5T_NATIVE_LONG | H5T_NATIVE_ULONG |
H5T_NATIVE_LLONG | H5T_NATIVE_ULLONG
<float> ::= H5T_IEEE_F32BE | H5T_IEEE_F32LE |
H5T_IEEE_F64BE | H5T_IEEE_F64LE |
H5T_NATIVE_FLOAT | H5T_NATIVE_DOUBLE |
H5T_NATIVE_LDOUBLE
<time> ::= TBD
<string> ::= H5T_STRING { STRSIZE <strsize> ;
STRPAD <strpad> ;
CSET <cset> ;
CTYPE <ctype> ;}
<strsize> ::= <int_value> | H5T_VARIABLE
<strpad> ::= H5T_STR_NULLTERM | H5T_STR_NULLPAD | H5T_STR_SPACEPAD
<cset> ::= H5T_CSET_ASCII | H5T_CSET_UTF8
<ctype> ::= H5T_C_S1 | H5T_FORTRAN_S1
<bitfield> ::= TBD
<opaque> ::= H5T_OPAQUE { OPQ_SIZE <opq_size>;
OPQ_TAG <opq_tag>; }
opq_size ::= <int_value>
opq_tag ::= "<string>"
<reference> ::= Not supported
<compound_type> ::= H5T_COMPOUND { <member_type_def>+ }
<member_type_def> ::= <datatype> <field_name> <offset><font size=1.7>opt</font> ;
<field_name> ::= "<identifier>"
<offset> ::= : <int_value>
<variable_length_type> ::= H5T_VLEN { <datatype> }
<array_type> ::= H5T_ARRAY { <dim_sizes> <datatype> }
<dim_sizes> ::= [<dimsize>] | [<dimsize>] <dim_sizes>
<dimsize> ::= <int_value>
<enum> ::= H5T_ENUM { <enum_base_type>; <enum_def>+ }
<enum_base_type> ::= <integer>
// Currently enums can only hold integer type data, but they may be
//expanded in the future to hold any datatype
<enum_def> ::= <enum_symbol> <enum_val>;
<enum_symbol> ::= "<identifier>"
<enum_val> ::= <int_value>
</pre>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 46. The definition of HDF5 datatypes from the
<!-- formerly Figure 63: -->
<a href="../ddl.html" target="ExtWin"><cite>HDF5 DDL</cite></a></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The definitions of opaque and compound datatype above are
revised for HDF5 Release 1.8. In Release 1.6.5. and earlier,
they were were defined as follows:
</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
<opaque> ::= H5T_OPAQUE { <identifier> }
<compound_type> ::= H5T_COMPOUND { <member_type_def>+ }
<member_type_def> ::= <datatype> <field_name> ;
<field_name> ::= <identifier></pre>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 47.
<!-- formerly Figure 64: -->
Old definitions of the opaque and compound datatypes</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<h4><em>Examples</em></h4>
<p>The code sample below illustrates the use of
<span class="codeText">H5LTtext_to_dtype</span> to generate a
variable-length string datatype.
</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
hid_t dtype;
if((dtype = H5LTtext_to_dtype(“H5T_STRING {
STRSIZE H5T_VARIABLE;
STRPAD H5T_STR_NULLPAD;
CSET H5T_CSET_ASCII;
CTYPE H5T_C_S1;
}”, H5LT_DDL))<0)
goto out;</pre>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 48. Creating a variable-length string datatype from
a text description<!-- formerly Figure 65: --></b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<p>The code sample below illustrates the use of
<span class="codeText">H5LTtext_to_dtype</span> to generate a
complex array datatype.
</p>
<table width="600" cellspacing="0" align="center">
<tr valign="top">
<td align="left">
<hr color="green" size="3"/>
<pre>
hid_t dtype;
if((dtype = H5LTtext_to_dtype(“H5T_ARRAY { [5][7][13] H5T_ARRAY
{ [17][19] H5T_COMPOUND
{
H5T_STD_I8BE
\“arr_compound_1\”;
H5T_STD_I32BE
\“arr_compound_2\”;
}
}
}”, H5LT_DDL))<0)
goto out;</pre>
<tr><td><hr color="green" size="1" /></td></tr>
<tr valign="top">
<td align="left">
<b>Example 49. <!-- formerly Figure 66: -->
Creating a complex array datatype from a text description</b>
<hr color="green" size="3"/></td>
</tr>
</table>
<br />
<br />
<br />
<!-- NEW PAGE -->
</body>
</html>
|