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 3225 ret = (herr_t)H5Sget_simple_extent_npoints(dset_sid2); VERIFY(ret, 0, "H5Sget_simple_extent_npoints"); /* Try reading from the dataset (make certain our buffer is unmodified) */ ret = H5Dread(did, H5T_NATIVE_UINT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &uval); CHECK(ret, FAIL, "H5Dread"); VERIFY(uval, 2, "H5Dread"); /* Close the dataspace */ ret = H5Sclose(dset_sid); CHECK(ret, FAIL, "H5Sclose"); ret = H5Sclose(dset_sid2); CHECK(ret, FAIL, "H5Sclose"); /* Open the attribute for the dataset */ attr=H5Aopen_name(did,NULLATTR); CHECK(attr, FAIL, "H5Aopen_name"); /* Get the space of the dataset */ attr_sid = H5Aget_space(attr); CHECK(attr_sid, FAIL, "H5Aget_space"); /* Verify the class type of dataspace */ stype = H5Sget_simple_extent_type(attr_sid); VERIFY(stype, H5S_NULL, "H5Sget_simple_extent_type"); /* Verify there is zero element in the dataspace */ ret = (herr_t)H5Sget_simple_extent_npoints(attr_sid); VERIFY(ret, 0, "H5Sget_simple_extent_npoints"); /* Close the dataspace */ ret = H5Sclose(attr_sid); CHECK(ret, FAIL, "H5Sclose"); /* Try reading from the attribute (make certain our buffer is unmodified) */ ret = H5Aread(attr, H5T_NATIVE_INT, &val); CHECK(ret, FAIL, "H5Aread"); VERIFY(val, 1, "H5Aread"); /* Close attribute */ ret=H5Aclose(attr); CHECK(ret, FAIL, "H5Aclose"); /* Close the dataset */ ret = H5Dclose(did); CHECK(ret, FAIL, "H5Dclose"); /* Close the file */ ret = H5Fclose(fid); CHECK(ret, FAIL, "H5Fclose"); } /* end test_h5s_null() */ /**************************************************************** ** ** test_h5s_encode(): Test H5S (dataspace) encoding and decoding. ** ****************************************************************/ static void test_h5s_encode(void) { hid_t sid1, sid2, sid3; /* Dataspace ID */ hid_t decoded_sid1, decoded_sid2, decoded_sid3; int rank; /* Logical rank of dataspace */ hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; size_t sbuf_size=0, null_size=0, scalar_size=0; unsigned char *sbuf=NULL, *null_sbuf=NULL, *scalar_buf=NULL; hsize_t tdims[4]; /* Dimension array to test with */ hssize_t n; /* Number of dataspace elements */ hsize_t start[] = {0, 0, 0}; hsize_t stride[] = {2, 5, 3}; hsize_t count[] = {2, 2, 2}; hsize_t block[] = {1, 3, 1}; H5S_sel_type sel_type; H5S_class_t space_type; hssize_t nblocks; herr_t ret; /* Generic return value */ /* Output message about test being performed */ MESSAGE(5, ("Testing Dataspace Encoding and Decoding\n")); /*------------------------------------------------------------------------- * Test encoding and decoding of simple dataspace and hyperslab selection. *------------------------------------------------------------------------- */ sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL); CHECK/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 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 COPYING file, which can be found at the root of the source code * * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. * * If you do not have access to either file, you may request a copy from * * help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* * For details of the HDF libraries, see the HDF Documentation at: * http://hdfgroup.org/HDF5/doc/ * */ #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #include <jni.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include "hdf5.h" #include "h5util.h" /* size of hyperslab buffer when a dataset is bigger than H5TOOLS_MALLOCSIZE */ hsize_t H5TOOLS_BUFSIZE = (32 * 1024 * 1024); /* 32 MB */ int H5TOOLS_TEXT_BLOCK = 16; /* Number of elements on a line in a text export file */ /* * Pointer to the JNI's Virtual Machine; used for callback functions. */ JavaVM *jvm; jobject copy_callback; jobject close_callback; jobject create_callback; jobject compare_callback; jobject get_callback; jobject set_callback; jobject delete_callback; H5E_auto2_t efunc; void *edata; /********************/ /* Local Prototypes */ /********************/ static int h5str_dump_region_blocks(JNIEnv *env, h5str_t *str, hid_t region, hid_t region_obj); static int h5str_dump_region_points(JNIEnv *env, h5str_t *str, hid_t region, hid_t region_obj); static int h5str_is_zero(const void *_mem, size_t size); static hid_t h5str_get_native_type(hid_t type); static hid_t h5str_get_little_endian_type(hid_t type); static hid_t h5str_get_big_endian_type(hid_t type); static htri_t h5str_detect_vlen(hid_t tid); static htri_t h5str_detect_vlen_str(hid_t tid); static int h5tools_dump_simple_data(JNIEnv *env, FILE *stream, hid_t container, hid_t type, void *_mem, hsize_t nelmts); static int h5str_render_bin_output(FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t block_nelmts); static int render_bin_output_region_data_blocks(FILE *stream, hid_t region_id, hid_t container, int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata); static int render_bin_output_region_blocks(FILE *stream, hid_t region_space, hid_t region_id, hid_t container); static int render_bin_output_region_data_points(FILE *stream, hid_t region_space, hid_t region_id, hid_t container, int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata); static int render_bin_output_region_points(FILE *stream, hid_t region_space, hid_t region_id, hid_t container); /** frees memory held by array of strings */ void h5str_array_free (char **strs, size_t len) { size_t i; if (!strs || len <= 0) return; for (i = 0; i < len; i++) { if (strs[i]) HDfree(strs[i]); } /* for (i=0; i<n; i++)*/ HDfree(strs); } /* end h5str_array_free */ /** allocate a new str with given length */ void h5str_new (h5str_t *str, size_t len) { if (str && len > 0) { str->s = (char *)HDmalloc(len); str->max = len; str->s[0] = '\0'; } /* end if */ } /* end h5str_new */ /** free string memory */ void h5str_free (h5str_t *str) { if (str && str->max > 0) { HDfree(str->s); HDmemset(str, 0, sizeof(h5str_t)); } /* end if */ } /* end h5str_free */ /** reset the max size of the string */ /* * TODO: no error return. malloc can fail. */ void h5str_resize (h5str_t *str, size_t new_len) { char *new_str; if (!str || new_len <= 0 || str->max == new_len) return; if (NULL == (new_str = (char *) HDmalloc(new_len))) return; if (new_len > str->max) /* increase memory */ HDstrcpy(new_str, str->s); else HDstrncpy(new_str, str->s, new_len - 1); HDfree(str->s); str->s = new_str; str->max = new_len; } /* end h5str_resize */ /* appends a copy of the string pointed to by cstr to the h5str. Return Value: the char string point to str->s */ char* h5str_append (h5str_t *str, const char* cstr) { size_t len; if (!str) return NULL; else if (!cstr) return str->s; len = HDstrlen(str->s) + HDstrlen(cstr); while (len >= str->max) /* not enough to hold the new string, double the space */ { h5str_resize(str, str->max * 2); } return HDstrcat(str->s, cstr); } /* end h5str_append */ /* * Converts the given data point string into a real data point. * * Returns: * SUCCESS: Length of string token processed * FAILURE: 0 */ size_t h5str_convert (JNIEnv *env, char **in_str, hid_t container, hid_t tid, void *out_buf, size_t out_buf_offset) { unsigned char *ucptr = NULL; static char fmt_llong[8], fmt_ullong[8]; H5T_class_t tclass = H5T_NO_CLASS; const char delimiter[] = " ," H5_COMPOUND_BEGIN_INDICATOR H5_COMPOUND_END_INDICATOR \ H5_ARRAY_BEGIN_INDICATOR H5_ARRAY_END_INDICATOR \ H5_VLEN_BEGIN_INDICATOR H5_VLEN_END_INDICATOR; size_t typeSize = 0; hid_t mtid = H5I_INVALID_HID; char *this_str = NULL; char *token; char *cptr = NULL; int n; size_t retVal = 0; if (!in_str) H5_NULL_ARGUMENT_ERROR(ENVONLY, "h5str_convert: in_str is NULL"); if (!out_buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "h5str_convert: out_buf is NULL"); this_str = *in_str; cptr = &(((char *) out_buf)[out_buf_offset]); ucptr = &(((unsigned char *) out_buf)[out_buf_offset]); if (H5T_NO_CLASS == (tclass = H5Tget_class(tid))) H5_LIBRARY_ERROR(ENVONLY); if (!(typeSize = H5Tget_size(tid))) H5_LIBRARY_ERROR(ENVONLY); /* Build default formats for long long types */ if (!fmt_llong[0]) { if (HDsprintf(fmt_llong, "%%%sd", H5_PRINTF_LL_WIDTH) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_convert: HDsprintf failure"); if (HDsprintf(fmt_ullong, "%%%su", H5_PRINTF_LL_WIDTH) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_convert: HDsprintf failure"); } /* end if */ switch (tclass) { case H5T_FLOAT: { token = HDstrtok(this_str, delimiter); switch (typeSize) { case sizeof(float): { float tmp_float = 0.0; sscanf(token, "%f", &tmp_float); HDmemcpy(cptr, &tmp_float, sizeof(float)); break; } case sizeof(double): { double tmp_double = 0.0; sscanf(token, "%lf", &tmp_double); HDmemcpy(cptr, &tmp_double, sizeof(double)); break; } #if H5_SIZEOF_LONG_DOUBLE != 0 && H5_SIZEOF_LONG_DOUBLE != H5_SIZEOF_DOUBLE case sizeof(long double): { long double tmp_ldouble = 0.0; sscanf(token, "%Lf", &tmp_ldouble); HDmemcpy(cptr, &tmp_ldouble, sizeof(long double)); break; } #endif default: H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_convert: floating-point datatype size didn't match any of expected sizes"); break; } retVal = typeSize; break; } case H5T_STRING: { size_t len = HDstrlen(this_str); if (len > 0) { HDstrncpy(cptr, this_str, typeSize); cptr[typeSize - 1] = '\0'; retVal = typeSize; } else { cptr = NULL; } break; } case H5T_INTEGER: { H5T_sign_t nsign = H5T_SGN_ERROR; if (H5T_SGN_ERROR == (nsign = H5Tget_sign(tid))) H5_LIBRARY_ERROR(ENVONLY); token = HDstrtok(this_str, delimiter); switch (typeSize) { case sizeof(char): { unsigned char tmp_uchar = 0; signed char tmp_char = 0; if (H5T_SGN_NONE == nsign) { sscanf(token, "%hhu", &tmp_uchar); HDmemcpy(cptr, &tmp_uchar, sizeof(unsigned char)); } else { sscanf(token, "%hhd", &tmp_char); HDmemcpy(cptr, &tmp_char, sizeof(char)); } break; } case sizeof(short): { unsigned short tmp_ushort = 0; short tmp_short = 0; if (H5T_SGN_NONE == nsign) { sscanf(token, "%hu", &tmp_ushort); HDmemcpy(&tmp_ushort, cptr, sizeof(unsigned short)); } else { sscanf(token, "%hd", &tmp_short); HDmemcpy(&tmp_short, cptr, sizeof(short)); } break; } case sizeof(int): { unsigned int tmp_uint = 0; int tmp_int = 0; if (H5T_SGN_NONE == nsign) { sscanf(token, "%u", &tmp_uint); HDmemcpy(cptr, &tmp_uint, sizeof(unsigned int)); } else { sscanf(token, "%d", &tmp_int); HDmemcpy(cptr, &tmp_int, sizeof(int)); } break; } #if H5_SIZEOF_LONG != H5_SIZEOF_INT case sizeof(long): { unsigned long tmp_ulong = 0; long tmp_long = 0; if (H5T_SGN_NONE == nsign) { sscanf(token, "%lu", &tmp_ulong); HDmemcpy(cptr, &tmp_ulong, sizeof(unsigned long)); } else { sscanf(token, "%ld", &tmp_long); HDmemcpy(cptr, &tmp_long, sizeof(long)); } break; } #endif #if H5_SIZEOF_LONG_LONG != H5_SIZEOF_LONG case sizeof(long long): { unsigned long long tmp_ullong = 0; long long tmp_llong = 0; if (H5T_SGN_NONE == nsign) { sscanf(token, fmt_ullong, &tmp_ullong); HDmemcpy(cptr, &tmp_ullong, sizeof(unsigned long long)); } else { sscanf(token, fmt_llong, &tmp_llong); HDmemcpy(cptr, &tmp_llong, sizeof(long long)); } break; } #endif default: H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_convert: integer datatype size didn't match any of expected sizes"); break; } retVal = typeSize; break; } case H5T_COMPOUND: { unsigned i; size_t member_offset; if ((n = H5Tget_nmembers(tid)) < 0) H5_LIBRARY_ERROR(ENVONLY); /* Skip whitespace and compound indicators */ while (*this_str == ' ') this_str++; if (*this_str == '{') this_str++; while (*this_str == ' ') this_str++; for (i = 0; i < (unsigned) n; i++) { member_offset = H5Tget_member_offset(tid, i); if ((mtid = H5Tget_member_type(tid, i)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (!h5str_convert(ENVONLY, &this_str, container, mtid, out_buf, member_offset)) { CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); goto done; } /* Skip whitespace and commas */ while (*this_str == ' ') this_str++; if (*this_str == ',') this_str++; while (*this_str == ' ') this_str++; if (H5Tclose(mtid) < 0) H5_LIBRARY_ERROR(ENVONLY); mtid = H5I_INVALID_HID; } /* Skip whitespace and compound indicators */ while (*this_str == ' ') this_str++; if (*this_str == '}') this_str++; while (*this_str == ' ') this_str++; retVal = typeSize * (size_t) n; break; } /* TODO handle reference writing */ case H5T_REFERENCE: cptr = NULL; break; case H5T_ENUM: { void *value; token = HDstrtok(this_str, delimiter); switch (typeSize) { case sizeof(char): { unsigned char tmp_uchar = 0; value = &tmp_uchar; break; } case sizeof(short): { unsigned short tmp_ushort = 0; value = &tmp_ushort; break; } #if H5_SIZEOF_LONG != H5_SIZEOF_INT case sizeof(long): { unsigned long tmp_ulong = 0; value = &tmp_ulong; break; } #endif #if H5_SIZEOF_LONG_LONG != H5_SIZEOF_LONG case sizeof(long long): { unsigned long long tmp_ullong = 0; value = &tmp_ullong; break; } #endif default: { unsigned int tmp_uint = 0; value = &tmp_uint; break; } } if (H5Tenum_valueof(tid, token, value) < 0) H5_LIBRARY_ERROR(ENVONLY); HDmemcpy(ucptr, value, typeSize); retVal = typeSize; break; } case H5T_ARRAY: { hsize_t i, dims[H5S_MAX_RANK], total_elmts; size_t baseTypeSize; int rank = 0; /* Skip whitespace and array indicators */ while (*this_str == ' ') this_str++; if (*this_str == '[') this_str++; while (*this_str == ' ') this_str++; if ((mtid = H5Tget_super(tid)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (!(baseTypeSize = H5Tget_size(mtid))) H5_LIBRARY_ERROR(ENVONLY); if ((rank = H5Tget_array_ndims(tid)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (H5Tget_array_dims2(tid, dims) < 0) H5_LIBRARY_ERROR(ENVONLY); for (i = 0, total_elmts = 1; i < (hsize_t) rank; i++) total_elmts *= dims[i]; if (NULL == (cptr = (char *) HDcalloc((size_t)total_elmts, baseTypeSize))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_convert: failed to allocate array buffer"); for (i = 0; i < total_elmts; i++) { if (!(h5str_convert(ENVONLY, &this_str, container, mtid, out_buf, i * baseTypeSize))) { CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); goto done; } /* Skip whitespace and commas */ while (*this_str == ' ') this_str++; if (*this_str == ',') this_str++; while (*this_str == ' ') this_str++; } if (H5Tclose(mtid) < 0) H5_LIBRARY_ERROR(ENVONLY); mtid = H5I_INVALID_HID; /* Skip whitespace and array indicators */ while (*this_str == ' ') this_str++; if (*this_str == ']') this_str++; while (*this_str == ' ') this_str++; retVal = typeSize * total_elmts; break; } case H5T_VLEN: { size_t i, baseTypeSize; hvl_t *vl_buf = (hvl_t *) out_buf; char cur_char; if ((mtid = H5Tget_super(tid)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (!(baseTypeSize = H5Tget_size(mtid))) H5_LIBRARY_ERROR(ENVONLY); if (NULL == (vl_buf->p = HDmalloc(baseTypeSize))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_convert: failed to allocate vlen buffer"); vl_buf->len = 1; /* Skip whitespace and vlen indicators */ while (*this_str == ' ') this_str++; if (*this_str == '(') this_str++; while (*this_str == ' ') this_str++; cur_char = *this_str; for (i = 0; cur_char != ')' && cur_char != '\0'; i++) { if (i >= vl_buf->len) { char *tmp_realloc; if (NULL == (tmp_realloc = (char *) HDrealloc(vl_buf->p, vl_buf->len * 2 * baseTypeSize))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_convert: failed to reallocate vlen buffer"); vl_buf->len *= 2; vl_buf->p = tmp_realloc; } if (!(h5str_convert(ENVONLY, &this_str, container, mtid, vl_buf->p, i * baseTypeSize))) { CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); vl_buf->len = i; goto done; } /* Skip whitespace and commas */ while (*this_str == ' ') this_str++; if (*this_str == ',') this_str++; while (*this_str == ' ') this_str++; } vl_buf->len = i; if (H5Tclose(mtid) < 0) H5_LIBRARY_ERROR(ENVONLY); mtid = H5I_INVALID_HID; /* Skip whitespace and vlen indicators */ while (*this_str == ' ') this_str++; if (*this_str == ')') this_str++; while (*this_str == ' ') this_str++; retVal = typeSize; break; } case H5T_NCLASSES: case H5T_NO_CLASS: { H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_convert: invalid datatype class"); break; } case H5T_TIME: case H5T_BITFIELD: case H5T_OPAQUE: default: { /* All other types get copied raw */ HDmemcpy(ucptr, this_str, typeSize); retVal = typeSize; break; } } /* end switch */ done: if (mtid >= 0) H5Tclose(mtid); return retVal; } /* end h5str_convert */ /* * Prints the value of a data point into a string. * * Returns: * SUCCESS: Total number of characters printed * FAILURE: 0 */ size_t h5str_sprintf (JNIEnv *env, h5str_t *out_str, hid_t container, hid_t tid, void *in_buf, size_t in_buf_len, int expand_data) { unsigned char *ucptr = (unsigned char *) in_buf; static char fmt_llong[8], fmt_ullong[8]; H5T_class_t tclass = H5T_NO_CLASS; size_t typeSize = 0; hid_t mtid = H5I_INVALID_HID; char *cptr = (char *) in_buf; char *this_str = NULL; int n; size_t retVal = 0; if (!out_str) H5_NULL_ARGUMENT_ERROR(ENVONLY, "h5str_sprintf: out_str is NULL"); if (!in_buf) H5_NULL_ARGUMENT_ERROR(ENVONLY, "h5str_sprintf: in_buf is NULL"); if (H5T_NO_CLASS == (tclass = H5Tget_class(tid))) H5_LIBRARY_ERROR(ENVONLY); if (!(typeSize = H5Tget_size(tid))) H5_LIBRARY_ERROR(ENVONLY); /* Build default formats for long long types */ if (!fmt_llong[0]) { if (HDsprintf(fmt_llong, "%%%sd", H5_PRINTF_LL_WIDTH) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: sprintf failure"); if (HDsprintf(fmt_ullong, "%%%su", H5_PRINTF_LL_WIDTH) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: sprintf failure"); } /* end if */ switch (tclass) { case H5T_FLOAT: { switch (typeSize) { case sizeof(float): { float tmp_float = 0.0; HDmemcpy(&tmp_float, cptr, sizeof(float)); if (NULL == (this_str = (char *) HDmalloc(25))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); if (HDsprintf(this_str, "%g", tmp_float) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); break; } case sizeof(double): { double tmp_double = 0.0; HDmemcpy(&tmp_double, cptr, sizeof(double)); if (NULL == (this_str = (char *) HDmalloc(25))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); if (HDsprintf(this_str, "%g", tmp_double) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); break; } #if H5_SIZEOF_LONG_DOUBLE != 0 && H5_SIZEOF_LONG_DOUBLE != H5_SIZEOF_DOUBLE case sizeof(long double): { long double tmp_ldouble = 0.0; HDmemcpy(&tmp_ldouble, cptr, sizeof(long double)); if (NULL == (this_str = (char *) HDmalloc(27))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); if (HDsprintf(this_str, "%Lf", tmp_ldouble) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); break; } #endif default: H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_sprintf: floating-point datatype size didn't match any of expected sizes"); break; } break; } case H5T_STRING: { htri_t is_variable; char *tmp_str; typeSize = 0; if ((is_variable = H5Tis_variable_str(tid)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (is_variable) { if (NULL != (tmp_str = *(char **) in_buf)) typeSize = HDstrlen(tmp_str); } else { tmp_str = cptr; } /* Check for NULL pointer for string */ if (!tmp_str) { if (NULL == (this_str = (char *) HDmalloc(5))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); HDstrncpy(this_str, "NULL", 5); } else { if (typeSize > 0) { if (NULL == (this_str = (char *) HDmalloc(typeSize + 1))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); HDstrncpy(this_str, tmp_str, typeSize); this_str[typeSize] = '\0'; } } break; } case H5T_INTEGER: { H5T_sign_t nsign = H5T_SGN_ERROR; if (H5T_SGN_ERROR == (nsign = H5Tget_sign(tid))) H5_LIBRARY_ERROR(ENVONLY); switch (typeSize) { case sizeof(char): { unsigned char tmp_uchar = 0; char tmp_char = 0; if (H5T_SGN_NONE == nsign) { HDmemcpy(&tmp_uchar, cptr, sizeof(unsigned char)); if (NULL == (this_str = (char *) HDmalloc(7))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); if (HDsprintf(this_str, "%u", tmp_uchar) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); } else { HDmemcpy(&tmp_char, cptr, sizeof(char)); if (NULL == (this_str = (char *) HDmalloc(7))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); if (HDsprintf(this_str, "%hhd", tmp_char) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); } break; } case sizeof(short): { unsigned short tmp_ushort = 0; short tmp_short = 0; if (H5T_SGN_NONE == nsign) { HDmemcpy(&tmp_ushort, cptr, sizeof(unsigned short)); if (NULL == (this_str = (char *) HDmalloc(9))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); if (HDsprintf(this_str, "%u", tmp_ushort) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); } else { HDmemcpy(&tmp_short, cptr, sizeof(short)); if (NULL == (this_str = (char *) HDmalloc(9))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); if (HDsprintf(this_str, "%d", tmp_short) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); } break; } case sizeof(int): { unsigned int tmp_uint = 0; int tmp_int = 0; if (H5T_SGN_NONE == nsign) { HDmemcpy(&tmp_uint, cptr, sizeof(unsigned int)); if (NULL == (this_str = (char *) HDmalloc(14))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); if (HDsprintf(this_str, "%u", tmp_uint) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); } else { HDmemcpy(&tmp_int, cptr, sizeof(int)); if (NULL == (this_str = (char *) HDmalloc(14))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); if (HDsprintf(this_str, "%d", tmp_int) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); } break; } #if H5_SIZEOF_LONG != H5_SIZEOF_INT case sizeof(long): { unsigned long tmp_ulong = 0; long tmp_long = 0; if (H5T_SGN_NONE == nsign) { HDmemcpy(&tmp_ulong, cptr, sizeof(unsigned long)); if (NULL == (this_str = (char *) HDmalloc(23))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); if (HDsprintf(this_str, "%lu", tmp_ulong) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); } else { HDmemcpy(&tmp_long, cptr, sizeof(long)); if (NULL == (this_str = (char *) HDmalloc(23))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); if (HDsprintf(this_str, "%ld", tmp_long) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); } break; } #endif #if H5_SIZEOF_LONG_LONG != H5_SIZEOF_LONG case sizeof(long long): { unsigned long long tmp_ullong = 0; long long tmp_llong = 0; if (H5T_SGN_NONE == nsign) { HDmemcpy(&tmp_ullong, cptr, sizeof(unsigned long long)); if (NULL == (this_str = (char *) HDmalloc(25))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); if (HDsprintf(this_str, fmt_ullong, tmp_ullong) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); } else { HDmemcpy(&tmp_llong, cptr, sizeof(long long)); if (NULL == (this_str = (char *) HDmalloc(25))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); if (HDsprintf(this_str, fmt_llong, tmp_llong) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); } break; } #endif default: H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_sprintf: integer datatype size didn't match any of expected sizes"); break; } break; } case H5T_COMPOUND: { unsigned i; size_t offset; if ((n = H5Tget_nmembers(tid)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (!h5str_append(out_str, H5_COMPOUND_BEGIN_INDICATOR)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); for (i = 0; i < (unsigned) n; i++) { offset = H5Tget_member_offset(tid, i); if ((mtid = H5Tget_member_type(tid, i)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (!h5str_sprintf(ENVONLY, out_str, container, mtid, &cptr[offset], in_buf_len, expand_data)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); if ((i + 1) < (unsigned) n) if (!h5str_append(out_str, ", ")) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); if (H5Tclose(mtid) < 0) H5_LIBRARY_ERROR(ENVONLY); mtid = H5I_INVALID_HID; } if (!h5str_append(out_str, H5_COMPOUND_END_INDICATOR)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); break; } case H5T_ENUM: { char enum_name[1024]; if (H5Tenum_nameof(tid, cptr, enum_name, sizeof enum_name) >= 0) { if (!h5str_append(out_str, enum_name)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } else { size_t i; if (NULL == (this_str = (char *) HDmalloc(4 * (typeSize + 1)))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); if (1 == typeSize) { if (HDsprintf(this_str, "%#02x", ucptr[0]) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); } else { for (i = 0; i < typeSize; i++) if (HDsprintf(this_str, "%s%02x", i ? ":" : "", ucptr[i]) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); } } break; } case H5T_REFERENCE: { if (h5str_is_zero(cptr, 99)) { if (!h5str_append(out_str, "NULL")) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); break; } if (H5R_DSET_REG_REF_BUF_SIZE == typeSize) { H5S_sel_type region_type = H5S_SEL_ERROR; hid_t region_obj = H5I_INVALID_HID; hid_t region = H5I_INVALID_HID; char ref_name[1024]; /* * Dataset region reference -- * show the type and the referenced object */ /* Get name of the dataset the region reference points to using H5Rget_name */ if ((region_obj = H5Rdereference2(container, H5P_DEFAULT, H5R_DATASET_REGION, cptr)) < 0) H5_LIBRARY_ERROR(ENVONLY); if ((region = H5Rget_region(container, H5R_DATASET_REGION, cptr)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (expand_data) { if (H5S_SEL_ERROR == (region_type = H5Sget_select_type(region))) H5_LIBRARY_ERROR(ENVONLY); if (H5S_SEL_POINTS == region_type) { if (h5str_dump_region_points_data(ENVONLY, out_str, region, region_obj) < 0) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } else { if (h5str_dump_region_blocks_data(ENVONLY, out_str, region, region_obj) < 0) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } } else { if (H5Rget_name(region_obj, H5R_DATASET_REGION, cptr, (char *)ref_name, 1024) < 0) H5_LIBRARY_ERROR(ENVONLY); if (!h5str_append(out_str, ref_name)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); if (H5S_SEL_ERROR == (region_type = H5Sget_select_type(region))) H5_LIBRARY_ERROR(ENVONLY); if (H5S_SEL_POINTS == region_type) { if (!h5str_append(out_str, " REGION_TYPE POINT")) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); if (h5str_dump_region_points(ENVONLY, out_str, region, region_obj) < 0) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } else { if (!h5str_append(out_str, " REGION_TYPE BLOCK")) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); if (h5str_dump_region_blocks(ENVONLY, out_str, region, region_obj) < 0) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } } if (H5Sclose(region) < 0) H5_LIBRARY_ERROR(ENVONLY); region = H5I_INVALID_HID; if (H5Dclose(region_obj) < 0) H5_LIBRARY_ERROR(ENVONLY); region_obj = H5I_INVALID_HID; } else if (H5R_OBJ_REF_BUF_SIZE == typeSize) { H5O_info_t oi; hid_t obj = H5I_INVALID_HID; /* * Object references -- show the type and OID of the referenced * object. */ if (NULL == (this_str = (char *) HDmalloc(64))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); if ((obj = H5Rdereference2(container, H5P_DEFAULT, H5R_OBJECT, cptr)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (H5Oget_info2(obj, &oi, H5O_INFO_ALL) < 0) H5_LIBRARY_ERROR(ENVONLY); /* Print object data and close object */ if (HDsprintf(this_str, "%u-%lu", (unsigned) oi.type, oi.addr) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); if (H5Oclose(obj) < 0) H5_LIBRARY_ERROR(ENVONLY); obj = H5I_INVALID_HID; } break; } case H5T_ARRAY: { hsize_t dims[H5S_MAX_RANK], i, total_elmts; size_t baseSize; int rank = 0; if (!h5str_append(out_str, H5_ARRAY_BEGIN_INDICATOR)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); if ((mtid = H5Tget_super(tid)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (!(baseSize = H5Tget_size(mtid))) H5_LIBRARY_ERROR(ENVONLY); if ((rank = H5Tget_array_ndims(tid)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (H5Tget_array_dims2(tid, dims) < 0) H5_LIBRARY_ERROR(ENVONLY); for (i = 0, total_elmts = 1; i < (hsize_t) rank; i++) total_elmts *= dims[i]; for (i = 0; i < total_elmts; i++) { if (!h5str_sprintf(ENVONLY, out_str, container, mtid, &(cptr[i * baseSize]), in_buf_len, expand_data)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); if ((i + 1) < total_elmts) if (!h5str_append(out_str, ", ")) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } if (!h5str_append(out_str, H5_ARRAY_END_INDICATOR)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); if (H5Tclose(mtid) < 0) H5_LIBRARY_ERROR(ENVONLY); mtid = H5I_INVALID_HID; break; } case H5T_VLEN: { unsigned int i; size_t baseSize; hvl_t *vl_buf = (hvl_t *) in_buf; if ((mtid = H5Tget_super(tid)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (!(baseSize = H5Tget_size(mtid))) H5_LIBRARY_ERROR(ENVONLY); if (!h5str_append(out_str, H5_VLEN_BEGIN_INDICATOR)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); for (i = 0; i < (unsigned) vl_buf->len; i++) { if (!h5str_sprintf(ENVONLY, out_str, container, mtid, &(((char *) vl_buf->p)[i * baseSize]), vl_buf->len, expand_data)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); if ((i + 1) < (unsigned) vl_buf->len) if (!h5str_append(out_str, ", ")) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } if (!h5str_append(out_str, H5_VLEN_END_INDICATOR)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); if (H5Tclose(mtid) < 0) H5_LIBRARY_ERROR(ENVONLY); mtid = H5I_INVALID_HID; break; } case H5T_NO_CLASS: case H5T_NCLASSES: { H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_sprintf: invalid datatype class"); break; } case H5T_TIME: case H5T_BITFIELD: case H5T_OPAQUE: default: { size_t i; /* All other types get printed as hexadecimal */ if (NULL == (this_str = (char *) HDmalloc(4 * (typeSize + 1)))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: failed to allocate string buffer"); if (1 == typeSize) { if (HDsprintf(this_str, "%#02x", ucptr[0]) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); } else { for (i = 0; i < typeSize; i++) if (HDsprintf(this_str, "%s%02x", i ? ":" : "", ucptr[i]) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_sprintf: HDsprintf failure"); } break; } } if (this_str) { if (!h5str_append(out_str, this_str)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); HDfree(this_str); this_str = NULL; } /* end if */ retVal = HDstrlen(out_str->s); done: if (mtid >= 0) H5Tclose(mtid); return retVal; } /* end h5str_sprintf */ /*------------------------------------------------------------------------- * Purpose: Print the data values from a dataset referenced by region blocks. * * Description: * This is a special case subfunction to print the data in a region reference of type blocks. * * Return: * The function returns FAIL if there was an error, otherwise SUCEED *------------------------------------------------------------------------- */ static int h5str_print_region_data_blocks (JNIEnv *env, hid_t region_id, h5str_t *str, int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata) { unsigned indx; hsize_t *dims1 = NULL; hsize_t *start = NULL; hsize_t *count = NULL; hsize_t blkndx; hsize_t total_size[H5S_MAX_RANK]; hsize_t numelem; hsize_t numindex; size_t jndx; size_t type_size; hid_t mem_space = H5I_INVALID_HID; hid_t sid1 = H5I_INVALID_HID; void *region_buf = NULL; int ret_value = FAIL; if (ndims < 0) H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_print_region_data_blocks: ndims < 0"); if (nblocks < 0) H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_print_region_data_blocks: nblocks < 0"); /* Get the dataspace of the dataset */ if ((sid1 = H5Dget_space(region_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); /* Allocate space for the dimension array */ if (NULL == (dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * (size_t)ndims))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_print_region_data_blocks: failed to allocate dimension array buffer"); /* Find the dimensions of each data space from the block coordinates */ for (jndx = 0, numelem = 1; jndx < (size_t) ndims; jndx++) { dims1[jndx] = ptdata[jndx + (size_t)ndims] - ptdata[jndx] + 1; numelem = dims1[jndx] * numelem; } /* end for */ /* Create dataspace for reading buffer */ if ((mem_space = H5Screate_simple(ndims, dims1, NULL)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (!(type_size = H5Tget_size(type_id))) H5_LIBRARY_ERROR(ENVONLY); if (NULL == (region_buf = HDmalloc(type_size * (size_t)numelem))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_print_region_data_blocks: failed to allocate region buffer"); /* Select (x , x , ..., x ) x (y , y , ..., y ) hyperslab for reading memory dataset */ /* 1 2 n 1 2 n */ if (NULL == (start = (hsize_t *) HDmalloc(sizeof(hsize_t) * (size_t)ndims))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_print_region_data_blocks: failed to allocate hyperslab start buffer"); if (NULL == (count = (hsize_t *) HDmalloc(sizeof(hsize_t) * (size_t)ndims))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_print_region_data_blocks: failed to allocate hyperslab count buffer"); for (blkndx = 0; blkndx < (hsize_t) nblocks; blkndx++) { for (indx = 0; indx < (unsigned) ndims; indx++) { start[indx] = ptdata[indx + blkndx * (hsize_t)ndims * 2]; count[indx] = dims1[indx]; } /* end for */ if (H5Sselect_hyperslab(sid1, H5S_SELECT_SET, start, NULL, count, NULL) < 0) H5_LIBRARY_ERROR(ENVONLY); if (H5Dread(region_id, type_id, mem_space, sid1, H5P_DEFAULT, region_buf) < 0) H5_LIBRARY_ERROR(ENVONLY); if (H5Sget_simple_extent_dims(mem_space, total_size, NULL) < 0) H5_LIBRARY_ERROR(ENVONLY); for (numindex = 0; numindex < numelem; numindex++) { if (!h5str_sprintf(ENVONLY, str, region_id, type_id, ((char *)region_buf + numindex * type_size), 0, 1)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); if (numindex + 1 < numelem) if (!h5str_append(str, ", ")) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } /* end for (jndx = 0; jndx < numelem; jndx++, region_elmtno++, ctx.cur_elmt++) */ } /* end for (blkndx = 0; blkndx < nblocks; blkndx++) */ ret_value = SUCCEED; done: if (count) HDfree(count); if (start) HDfree(start); if (region_buf) HDfree(region_buf); if (mem_space >= 0) H5Sclose(mem_space); if (dims1) HDfree(dims1); if (sid1 >= 0) H5Sclose(sid1); return ret_value; } /* end h5str_print_region_data_blocks */ int h5str_dump_region_blocks_data (JNIEnv *env, h5str_t *str, hid_t region, hid_t region_id) { hssize_t nblocks; hsize_t alloc_size; hsize_t *ptdata = NULL; hid_t dtype = H5I_INVALID_HID; hid_t type_id = H5I_INVALID_HID; int ndims = -1; int ret_value = FAIL; /* * This function fails if the region does not have blocks. */ H5E_BEGIN_TRY { nblocks = H5Sget_select_hyper_nblocks(region); } H5E_END_TRY; if (nblocks < 0) H5_LIBRARY_ERROR(ENVONLY); if ((ndims = H5Sget_simple_extent_ndims(region)) < 0) H5_LIBRARY_ERROR(ENVONLY); /* Print block information */ alloc_size = (hsize_t)nblocks * (hsize_t)ndims * 2 * (hsize_t)sizeof(ptdata[0]); if (alloc_size == (hsize_t)((size_t) alloc_size)) { if (NULL == (ptdata = (hsize_t *) HDmalloc((size_t) alloc_size))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_blocks_data: failed to allocate region block buffer"); if (H5Sget_select_hyper_blocklist(region, (hsize_t) 0, (hsize_t) nblocks, ptdata) < 0) H5_LIBRARY_ERROR(ENVONLY); if ((dtype = H5Dget_type(region_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); if ((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (h5str_print_region_data_blocks(ENVONLY, region_id, str, ndims, type_id, nblocks, ptdata) < 0) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } /* if (alloc_size == (hsize_t)((size_t)alloc_size)) */ ret_value = SUCCEED; done: if (type_id >= 0) H5Tclose(type_id); if (dtype >= 0) H5Tclose(dtype); if (ptdata) HDfree(ptdata); return ret_value; } /* end h5str_dump_region_blocks_data */ static int h5str_dump_region_blocks (JNIEnv *env, h5str_t *str, hid_t region, hid_t region_id) { hssize_t nblocks; hsize_t alloc_size; hsize_t *ptdata = NULL; char tmp_str[256]; int ndims = -1; int ret_value = FAIL; UNUSED(region_id); /* * This function fails if the region does not have blocks. */ H5E_BEGIN_TRY { nblocks = H5Sget_select_hyper_nblocks(region); } H5E_END_TRY; if (nblocks < 0) H5_LIBRARY_ERROR(ENVONLY); if ((ndims = H5Sget_simple_extent_ndims(region)) < 0) H5_LIBRARY_ERROR(ENVONLY); /* Print block information */ alloc_size = (hsize_t)nblocks * (hsize_t)ndims * 2 * (hsize_t)sizeof(ptdata[0]); if (alloc_size == (hsize_t)((size_t) alloc_size)) { int i; if (NULL == (ptdata = (hsize_t *) HDmalloc((size_t) alloc_size))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_blocks: failed to allocate region block buffer"); if (H5Sget_select_hyper_blocklist(region, (hsize_t) 0, (hsize_t) nblocks, ptdata) < 0) H5_LIBRARY_ERROR(ENVONLY); if (!h5str_append(str, " {")) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); for (i = 0; i < nblocks; i++) { int j; if (!h5str_append(str, " ")) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); /* Start coordinates and opposite corner */ for (j = 0; j < ndims; j++) { tmp_str[0] = '\0'; if (HDsprintf(tmp_str, "%s%lu", j ? "," : "(", (unsigned long) ptdata[i * 2 * ndims + j]) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_blocks: HDsprintf failure"); if (!h5str_append(str, tmp_str)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } for (j = 0; j < ndims; j++) { tmp_str[0] = '\0'; if (HDsprintf(tmp_str, "%s%lu", j ? "," : ")-(", (unsigned long) ptdata[i * 2 * ndims + j + ndims]) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_blocks: HDsprintf failure"); if (!h5str_append(str, tmp_str)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } if (!h5str_append(str, ") ")) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); tmp_str[0] = '\0'; } if (!h5str_append(str, " }")) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } /* if (alloc_size == (hsize_t)((size_t)alloc_size)) */ ret_value = SUCCEED; done: if (ptdata) HDfree(ptdata); return ret_value; } /* end h5str_dump_region_blocks */ /*------------------------------------------------------------------------- * Purpose: Print the data values from a dataset referenced by region points. * * Description: * This is a special case subfunction to print the data in a region reference of type points. * * Return: * The function returns FAIL on error, otherwise SUCCEED *------------------------------------------------------------------------- */ static int h5str_print_region_data_points (JNIEnv *env, hid_t region_space, hid_t region_id, h5str_t *str, int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata) { hsize_t *dims1 = NULL; hsize_t total_size[H5S_MAX_RANK]; size_t jndx; size_t type_size; hid_t mem_space = H5I_INVALID_HID; void *region_buf = NULL; int ret_value = FAIL; UNUSED(ptdata); if (npoints < 0) H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_print_region_data_points: npoints < 0"); /* Allocate space for the dimension array */ if (NULL == (dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * (size_t)ndims))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_print_region_data_points: failed to allocate dimension array buffer"); dims1[0] = (hsize_t)npoints; /* Create dataspace for reading buffer */ if ((mem_space = H5Screate_simple(1, dims1, NULL)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (!(type_size = H5Tget_size(type_id))) H5_LIBRARY_ERROR(ENVONLY); if (NULL == (region_buf = HDmalloc(type_size * (size_t)npoints))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_print_region_data_points: failed to allocate region buffer"); if (H5Dread(region_id, type_id, mem_space, region_space, H5P_DEFAULT, region_buf) < 0) H5_LIBRARY_ERROR(ENVONLY); for (jndx = 0; jndx < (size_t) npoints; jndx++) { if (H5Sget_simple_extent_dims(mem_space, total_size, NULL) < 0) H5_LIBRARY_ERROR(ENVONLY); if (!h5str_sprintf(ENVONLY, str, region_id, type_id, ((char *)region_buf + jndx * type_size), 0, 1)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); if (jndx + 1 < (size_t) npoints) if (!h5str_append(str, ", ")) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } /* end for (jndx = 0; jndx < npoints; jndx++, elmtno++) */ ret_value = SUCCEED; done: if (region_buf) HDfree(region_buf); if (mem_space >= 0) H5Sclose(mem_space); if (dims1) HDfree(dims1); return ret_value; } /* end h5str_print_region_data_points */ int h5str_dump_region_points_data (JNIEnv *env, h5str_t *str, hid_t region, hid_t region_id) { hssize_t npoints; hsize_t alloc_size; hsize_t *ptdata = NULL; hid_t dtype = H5I_INVALID_HID; hid_t type_id = H5I_INVALID_HID; int ndims = -1; int ret_value = FAIL; /* * This function fails if the region does not have points. */ H5E_BEGIN_TRY { npoints = H5Sget_select_elem_npoints(region); } H5E_END_TRY; if (npoints < 0) H5_LIBRARY_ERROR(ENVONLY); if ((ndims = H5Sget_simple_extent_ndims(region)) < 0) H5_LIBRARY_ERROR(ENVONLY); /* Print point information */ if (npoints > 0) { alloc_size = (hsize_t)npoints * (hsize_t)ndims * (hsize_t)sizeof(ptdata[0]); if (alloc_size == (hsize_t)((size_t) alloc_size)) { if (NULL == (ptdata = (hsize_t *) HDmalloc((size_t) alloc_size))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_points_data: failed to allocate region point data buffer"); if (H5Sget_select_elem_pointlist(region, (hsize_t) 0, (hsize_t) npoints, ptdata) < 0) H5_LIBRARY_ERROR(ENVONLY); if ((dtype = H5Dget_type(region_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); if ((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (h5str_print_region_data_points(ENVONLY, region, region_id, str, ndims, type_id, npoints, ptdata) < 0) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } } ret_value = SUCCEED; done: if (type_id >= 0) H5Tclose(type_id); if (dtype >= 0) H5Tclose(dtype); if (ptdata) HDfree(ptdata); return ret_value; } /* end h5str_dump_region_points_data */ static int h5str_dump_region_points (JNIEnv *env, h5str_t *str, hid_t region, hid_t region_id) { hssize_t npoints; hsize_t alloc_size; hsize_t *ptdata = NULL; char tmp_str[256]; int ndims = -1; int ret_value = FAIL; UNUSED(region_id); /* * This function fails if the region does not have points. */ H5E_BEGIN_TRY { npoints = H5Sget_select_elem_npoints(region); } H5E_END_TRY; if (npoints < 0) H5_LIBRARY_ERROR(ENVONLY); if ((ndims = H5Sget_simple_extent_ndims(region)) < 0) H5_LIBRARY_ERROR(ENVONLY); /* Print point information */ if (npoints > 0) { int i; alloc_size = (hsize_t)npoints * (hsize_t)ndims * (hsize_t)sizeof(ptdata[0]); if (alloc_size == (hsize_t)((size_t) alloc_size)) { if (NULL == (ptdata = (hsize_t *) HDmalloc((size_t) alloc_size))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_points: failed to allocate region point buffer"); if (H5Sget_select_elem_pointlist(region, (hsize_t) 0, (hsize_t) npoints, ptdata) < 0) H5_LIBRARY_ERROR(ENVONLY); if (!h5str_append(str, " {")) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); for (i = 0; i < npoints; i++) { int j; if (!h5str_append(str, " ")) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); for (j = 0; j < ndims; j++) { tmp_str[0] = '\0'; if (HDsprintf(tmp_str, "%s%lu", j ? "," : "(", (unsigned long) (ptdata[i * ndims + j])) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_region_points: HDsprintf failure"); if (!h5str_append(str, tmp_str)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } /* end for (j = 0; j < ndims; j++) */ if (!h5str_append(str, ") ")) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } /* end for (i = 0; i < npoints; i++) */ if (!h5str_append(str, " }")) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } /* end if (alloc_size == (hsize_t)((size_t) alloc_size)) */ } /* end if (npoints > 0) */ ret_value = SUCCEED; done: if (ptdata) HDfree(ptdata); return ret_value; } /* end h5str_dump_region_points */ static int h5str_is_zero (const void *_mem, size_t size) { const unsigned char *mem = (const unsigned char *) _mem; while (size-- > 0) if (mem[size]) return 0; return 1; } /* end h5str_is_zero */ /*------------------------------------------------------------------------- * Function: h5str_detect_vlen * * Purpose: Recursive check for any variable length data in given type. * * Return: * 1 : type contains any variable length data * 0 : type doesn't contain any variable length data * Negative value: error occurred *------------------------------------------------------------------------- */ static htri_t h5str_detect_vlen (hid_t tid) { htri_t ret = FAIL; /* Recursively detect any vlen data values in type (compound, array ...) */ ret = H5Tdetect_class(tid, H5T_VLEN); if ((ret == 1) || (ret < 0)) goto done; /* Recursively detect any vlen string in type (compound, array ...) */ ret = h5str_detect_vlen_str(tid); if ((ret == 1) || (ret < 0)) goto done; done: return ret; } /* end h5str_detect_vlen */ /*------------------------------------------------------------------------- * Function: h5str_detect_vlen_str * * Purpose: Recursive check for variable length string of a datatype. * * Return: * TRUE : type conatains any variable length string * FALSE : type doesn't contain any variable length string * Negative value: error occur * *------------------------------------------------------------------------- */ static htri_t h5str_detect_vlen_str (hid_t tid) { H5T_class_t tclass = H5T_NO_CLASS; htri_t ret = 0; ret = H5Tis_variable_str(tid); if((ret == 1) || (ret < 0)) goto done; tclass = H5Tget_class(tid); if(tclass == H5T_ARRAY || tclass == H5T_VLEN) { hid_t btid = H5Tget_super(tid); if(btid < 0) { ret = (htri_t)btid; goto done; } /* end if */ ret = h5str_detect_vlen_str(btid); if((ret == 1) || (ret < 0)) { H5Tclose(btid); goto done; } /* end if */ } /* end if */ else if(tclass == H5T_COMPOUND) { unsigned i = 0; int n = H5Tget_nmembers(tid); if (n < 0) goto done; for(i = 0; i < (unsigned) n; i++) { hid_t mtid = H5Tget_member_type(tid, i); ret = h5str_detect_vlen_str(mtid); if((ret == 1) || (ret < 0)) { H5Tclose(mtid); goto done; } H5Tclose(mtid); } /* end for */ } /* end else */ done: return ret; } /* end h5str_detect_vlen_str */ /*------------------------------------------------------------------------- * Function: h5str_get_native_type * * Purpose: Wrapper around H5Tget_native_type() to work around * Problems with bitfields. * * Return: Success: datatype ID * Failure: FAIL *------------------------------------------------------------------------- */ static hid_t h5str_get_native_type (hid_t type) { H5T_class_t type_class; hid_t p_type = H5I_INVALID_HID; if ((type_class = H5Tget_class(type)) < 0) goto done; if (type_class == H5T_BITFIELD) p_type = H5Tcopy(type); else p_type = H5Tget_native_type(type, H5T_DIR_DEFAULT); done: return(p_type); } /* end h5str_get_native_type */ /*------------------------------------------------------------------------- * Function: h5str_get_little_endian_type * * Purpose: Get a little endian type from a file type * * Return: Success: datatype ID * Failure: FAIL *------------------------------------------------------------------------- */ static hid_t h5str_get_little_endian_type (hid_t tid) { H5T_class_t type_class; H5T_sign_t sign; size_t size; hid_t p_type = H5I_INVALID_HID; if ((type_class = H5Tget_class(tid)) < 0) goto done; if (!(size = H5Tget_size(tid))) goto done; if ((sign = H5Tget_sign(tid)) < 0) goto done; switch ( type_class ) { case H5T_INTEGER: { if ( size == 1 && sign == H5T_SGN_2 ) p_type = H5Tcopy(H5T_STD_I8LE); else if ( size == 2 && sign == H5T_SGN_2 ) p_type = H5Tcopy(H5T_STD_I16LE); else if ( size == 4 && sign == H5T_SGN_2 ) p_type = H5Tcopy(H5T_STD_I32LE); else if ( size == 8 && sign == H5T_SGN_2 ) p_type = H5Tcopy(H5T_STD_I64LE); else if ( size == 1 && sign == H5T_SGN_NONE ) p_type = H5Tcopy(H5T_STD_U8LE); else if ( size == 2 && sign == H5T_SGN_NONE ) p_type = H5Tcopy(H5T_STD_U16LE); else if ( size == 4 && sign == H5T_SGN_NONE ) p_type = H5Tcopy(H5T_STD_U32LE); else if ( size == 8 && sign == H5T_SGN_NONE ) p_type = H5Tcopy(H5T_STD_U64LE); break; } case H5T_FLOAT: { if ( size == 4 ) p_type = H5Tcopy(H5T_IEEE_F32LE); else if ( size == 8 ) p_type = H5Tcopy(H5T_IEEE_F64LE); break; } case H5T_BITFIELD: { if ( size == 1 ) p_type = H5Tcopy(H5T_STD_B8LE); else if ( size == 2 ) p_type = H5Tcopy(H5T_STD_B16LE); else if ( size == 4 ) p_type = H5Tcopy(H5T_STD_B32LE); else if ( size == 8 ) p_type = H5Tcopy(H5T_STD_B64LE); break; } case H5T_NO_CLASS: case H5T_NCLASSES: { goto done; break; } case H5T_TIME: case H5T_OPAQUE: case H5T_STRING: case H5T_COMPOUND: case H5T_REFERENCE: case H5T_ENUM: case H5T_VLEN: case H5T_ARRAY: break; default: break; } done: return(p_type); } /* end h5str_get_little_endian_type */ /*------------------------------------------------------------------------- * Function: h5str_get_big_endian_type * * Purpose: Get a big endian type from a file type * * Return: Success: datatype ID * Failure: FAIL *------------------------------------------------------------------------- */ static hid_t h5str_get_big_endian_type (hid_t tid) { H5T_class_t type_class; H5T_sign_t sign; size_t size; hid_t p_type = H5I_INVALID_HID; if ((type_class = H5Tget_class(tid)) < 0) goto done; if (!(size = H5Tget_size(tid))) goto done; if ((sign = H5Tget_sign(tid)) < 0) goto done; switch ( type_class ) { case H5T_INTEGER: { if ( size == 1 && sign == H5T_SGN_2 ) p_type = H5Tcopy(H5T_STD_I8BE); else if ( size == 2 && sign == H5T_SGN_2 ) p_type = H5Tcopy(H5T_STD_I16BE); else if ( size == 4 && sign == H5T_SGN_2 ) p_type = H5Tcopy(H5T_STD_I32BE); else if ( size == 8 && sign == H5T_SGN_2 ) p_type = H5Tcopy(H5T_STD_I64BE); else if ( size == 1 && sign == H5T_SGN_NONE ) p_type = H5Tcopy(H5T_STD_U8BE); else if ( size == 2 && sign == H5T_SGN_NONE ) p_type = H5Tcopy(H5T_STD_U16BE); else if ( size == 4 && sign == H5T_SGN_NONE ) p_type = H5Tcopy(H5T_STD_U32BE); else if ( size == 8 && sign == H5T_SGN_NONE ) p_type = H5Tcopy(H5T_STD_U64BE); break; } case H5T_FLOAT: { if ( size == 4 ) p_type = H5Tcopy(H5T_IEEE_F32BE); else if ( size == 8 ) p_type = H5Tcopy(H5T_IEEE_F64BE); break; } case H5T_BITFIELD: { if ( size == 1 ) p_type = H5Tcopy(H5T_STD_B8BE); else if ( size == 2 ) p_type = H5Tcopy(H5T_STD_B16BE); else if ( size == 4 ) p_type = H5Tcopy(H5T_STD_B32BE); else if ( size == 8 ) p_type = H5Tcopy(H5T_STD_B64BE); break; } case H5T_NO_CLASS: case H5T_NCLASSES: { goto done; break; } case H5T_TIME: case H5T_OPAQUE: case H5T_STRING: case H5T_COMPOUND: case H5T_REFERENCE: case H5T_ENUM: case H5T_VLEN: case H5T_ARRAY: break; default: break; } done: return(p_type); } /* end h5str_get_big_endian_type */ /*------------------------------------------------------------------------- * Function: render_bin_output * * Purpose: Write one element of memory buffer to a binary file stream * * Return: Success: SUCCEED * Failure: FAIL *------------------------------------------------------------------------- */ static int h5str_render_bin_output (FILE *stream, hid_t container, hid_t tid, void *_mem, hsize_t block_nelmts) { unsigned char *mem = (unsigned char*)_mem; H5T_class_t type_class; hsize_t block_index; size_t size; /* datum size */ int ret_value = 0; if (!(size = H5Tget_size(tid))) { ret_value = FAIL; goto done; } if ((type_class = H5Tget_class(tid)) < 0) { ret_value = FAIL; goto done; } switch (type_class) { case H5T_INTEGER: case H5T_FLOAT: case H5T_ENUM: { block_index = block_nelmts * size; while (block_index > 0) { size_t bytes_in = 0; /* # of bytes to write */ size_t bytes_wrote = 0; /* # of bytes written */ if (block_index > sizeof(size_t)) bytes_in = sizeof(size_t); else bytes_in = (size_t)block_index; bytes_wrote = fwrite(mem, 1, bytes_in, stream); if (bytes_wrote != bytes_in || (0 == bytes_wrote && ferror(stream))) { ret_value = FAIL; break; } block_index -= (hsize_t)bytes_wrote; mem = mem + bytes_wrote; } break; } case H5T_STRING: { unsigned char tempuchar; unsigned int i; H5T_str_t pad; char *s; if ((pad = H5Tget_strpad(tid)) < 0) { ret_value = FAIL; goto done; } for (block_index = 0; block_index < block_nelmts; block_index++) { mem = ((unsigned char *)_mem) + block_index * size; if (H5Tis_variable_str(tid)) { s = *(char**) mem; if (s != NULL) size = HDstrlen(s); } else { s = (char *) mem; } for (i = 0; i < size && (s[i] || pad != H5T_STR_NULLTERM); i++) { HDmemcpy(&tempuchar, &s[i], sizeof(unsigned char)); if (1 != fwrite(&tempuchar, sizeof(unsigned char), 1, stream)) { ret_value = FAIL; break; } } /* i */ if (ret_value < 0) break; } /* for (block_index = 0; block_index < block_nelmts; block_index++) */ break; } case H5T_COMPOUND: { unsigned j; size_t offset; hid_t memb = H5I_INVALID_HID; int nmembs; if ((nmembs = H5Tget_nmembers(tid)) < 0) { ret_value = FAIL; goto done; } for (block_index = 0; block_index < block_nelmts; block_index++) { mem = ((unsigned char*)_mem) + block_index * size; for (j = 0; j < (unsigned) nmembs; j++) { offset = H5Tget_member_offset(tid, j); memb = H5Tget_member_type(tid, j); if (h5str_render_bin_output(stream, container, memb, mem + offset, 1) < 0) { H5Tclose(memb); ret_value = FAIL; break; } H5Tclose(memb); } if (ret_value < 0) break; } break; } case H5T_ARRAY: { hsize_t dims[H5S_MAX_RANK], temp_nelmts, nelmts; hid_t memb; int k, ndims; /* Get the array's base datatype for each element */ if ((memb = H5Tget_super(tid)) < 0) { ret_value = FAIL; goto done; } if ((ndims = H5Tget_array_ndims(tid)) < 0) { ret_value = FAIL; goto done; } if (H5Tget_array_dims2(tid, dims) < 0) { ret_value = FAIL; goto done; } /* Calculate the number of array elements */ for (k = 0, nelmts = 1; k < ndims; k++) { temp_nelmts = nelmts; temp_nelmts *= dims[k]; nelmts = (size_t) temp_nelmts; } for (block_index = 0; block_index < block_nelmts; block_index++) { mem = ((unsigned char*)_mem) + block_index * size; /* dump the array element */ if (h5str_render_bin_output(stream, container, memb, mem, nelmts) < 0) { ret_value = FAIL; break; } } H5Tclose(memb); break; } case H5T_VLEN: { hsize_t nelmts; hid_t memb; /* Get the VL sequences's base datatype for each element */ if ((memb = H5Tget_super(tid)) < 0) { ret_value = FAIL; goto done; } for (block_index = 0; block_index < block_nelmts; block_index++) { mem = ((unsigned char*)_mem) + block_index * size; /* Get the number of sequence elements */ nelmts = ((hvl_t *) mem)->len; /* dump the array element */ if (h5str_render_bin_output(stream, container, memb, ((char *) (((hvl_t *) mem)->p)), nelmts) < 0) { ret_value = FAIL; break; } } H5Tclose(memb); break; } case H5T_REFERENCE: { if (H5Tequal(tid, H5T_STD_REF_DSETREG)) { H5S_sel_type region_type; hid_t region_id, region_space; /* Region data */ for (block_index = 0; block_index < block_nelmts; block_index++) { mem = ((unsigned char*)_mem) + block_index * size; if ((region_id = H5Rdereference2(container, H5P_DEFAULT, H5R_DATASET_REGION, mem)) < 0) continue; if ((region_space = H5Rget_region(container, H5R_DATASET_REGION, mem)) < 0) { H5Dclose(region_id); continue; } if ((region_type = H5Sget_select_type(region_space)) < 0) { H5Sclose(region_space); H5Dclose(region_id); continue; } if (region_type == H5S_SEL_POINTS) ret_value = render_bin_output_region_points(stream, region_space, region_id, container); else ret_value = render_bin_output_region_blocks(stream, region_space, region_id, container); H5Sclose(region_space); H5Dclose(region_id); if (ret_value < 0) break; } } else if (H5Tequal(tid, H5T_STD_REF_OBJ)) { ; } break; } case H5T_NO_CLASS: case H5T_NCLASSES: { ret_value = FAIL; goto done; break; } case H5T_TIME: case H5T_BITFIELD: case H5T_OPAQUE: default: for (block_index = 0; block_index < block_nelmts; block_index++) { mem = ((unsigned char*)_mem) + block_index * size; if (size != fwrite(mem, sizeof(char), size, stream)) { ret_value = FAIL; break; } } break; } done: return ret_value; } /* end h5str_render_bin_output */ /*------------------------------------------------------------------------- * Purpose: Print the data values from a dataset referenced by region blocks. * * Description: * This is a special case subfunction to print the data in a region reference of type blocks. * * Return: * The function returns FAIL if there was an error, otherwise SUCEED * *------------------------------------------------------------------------- */ static int render_bin_output_region_data_blocks (FILE *stream, hid_t region_id, hid_t container, int ndims, hid_t type_id, hssize_t nblocks, hsize_t *ptdata) { hsize_t *dims1 = NULL; hsize_t *start = NULL; hsize_t *count = NULL; hsize_t numelem; hsize_t total_size[H5S_MAX_RANK]; size_t type_size; hid_t sid1 = H5I_INVALID_HID; hid_t mem_space = H5I_INVALID_HID; void *region_buf = NULL; int blkndx; int jndx; int ret_value = SUCCEED; /* Get the dataspace of the dataset */ if ((sid1 = H5Dget_space(region_id)) < 0) { ret_value = FAIL; goto done; } /* Allocate space for the dimension array */ if (NULL == (dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * (size_t)ndims))) { ret_value = FAIL; goto done; } /* Find the dimensions of each data space from the block coordinates */ for (jndx = 0, numelem = 1; jndx < ndims; jndx++) { dims1[jndx] = ptdata[jndx + ndims] - ptdata[jndx] + 1; numelem = dims1[jndx] * numelem; } /* Create dataspace for reading buffer */ if ((mem_space = H5Screate_simple(ndims, dims1, NULL)) < 0) { ret_value = FAIL; goto done; } if (!(type_size = H5Tget_size(type_id))) { ret_value = FAIL; goto done; } if (NULL == (region_buf = HDmalloc(type_size * (size_t)numelem))) { ret_value = FAIL; goto done; } /* Select (x , x , ..., x ) x (y , y , ..., y ) hyperslab for reading memory dataset */ /* 1 2 n 1 2 n */ if (NULL == (start = (hsize_t *) HDmalloc(sizeof(hsize_t) * (size_t)ndims))) { ret_value = FAIL; goto done; } if (NULL == (count = (hsize_t *) HDmalloc(sizeof(hsize_t) * (size_t)ndims))) { ret_value = FAIL; goto done; } for (blkndx = 0; blkndx < nblocks; blkndx++) { for (jndx = 0; jndx < ndims; jndx++) { start[jndx] = ptdata[jndx + blkndx * ndims * 2]; count[jndx] = dims1[jndx]; } if (H5Sselect_hyperslab(sid1, H5S_SELECT_SET, start, NULL, count, NULL) < 0) { ret_value = FAIL; goto done; } if (H5Dread(region_id, type_id, mem_space, sid1, H5P_DEFAULT, region_buf) < 0) { ret_value = FAIL; goto done; } if (H5Sget_simple_extent_dims(mem_space, total_size, NULL) < 0) { ret_value = FAIL; goto done; } if (h5str_render_bin_output(stream, container, type_id, (char *)region_buf, numelem) < 0) { ret_value = FAIL; goto done; } /* Render the region data element end */ } /* end for (blkndx = 0; blkndx < nblocks; blkndx++) */ done: if (count) HDfree(count); if (start) HDfree(start); if (region_buf) HDfree(region_buf); if (mem_space >= 0) H5Sclose(mem_space); if (dims1) HDfree(dims1); if (sid1 >= 0) H5Sclose(sid1); return ret_value; } /* end render_bin_output_region_data_blocks */ /*------------------------------------------------------------------------- * Purpose: Print some values from a dataset referenced by region blocks. * * Description: * This is a special case subfunction to dump a region reference using blocks. * * Return: * The function returns False if ERROR, otherwise True * *------------------------------------------------------------------------- */ static int render_bin_output_region_blocks (FILE *stream, hid_t region_space, hid_t region_id, hid_t container) { hssize_t nblocks; hsize_t alloc_size; hsize_t *ptdata = NULL; hid_t dtype = H5I_INVALID_HID; hid_t type_id = H5I_INVALID_HID; int ndims; int ret_value = SUCCEED; if ((nblocks = H5Sget_select_hyper_nblocks(region_space)) < 0) { ret_value = FAIL; goto done; } if (nblocks > 0) { /* Print block information */ if ((ndims = H5Sget_simple_extent_ndims(region_space)) < 0) { ret_value = FAIL; goto done; } alloc_size = (hsize_t)nblocks * (hsize_t)ndims * 2 * (hsize_t)sizeof(ptdata[0]); if (NULL == (ptdata = (hsize_t *) HDmalloc((size_t)alloc_size))) { ret_value = FAIL; goto done; } if (H5Sget_select_hyper_blocklist(region_space, (hsize_t)0, (hsize_t)nblocks, ptdata) < 0) { ret_value = FAIL; goto done; } if ((dtype = H5Dget_type(region_id)) < 0) { ret_value = FAIL; goto done; } if ((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) < 0) { ret_value = FAIL; goto done; } if (render_bin_output_region_data_blocks(stream, region_id, container, ndims, type_id, nblocks, ptdata) < 0) { ret_value = FAIL; goto done; } } done: if (type_id >= 0) H5Tclose(type_id); if (dtype >= 0) H5Tclose(dtype); if (ptdata) HDfree(ptdata); return ret_value; } /* end render_bin_output_region_blocks */ /*------------------------------------------------------------------------- * Purpose: Print the data values from a dataset referenced by region points. * * Description: * This is a special case subfunction to print the data in a region reference of type points. * * Return: * The function returns FAIL on error, otherwise SUCCEED * *------------------------------------------------------------------------- */ static int render_bin_output_region_data_points (FILE *stream, hid_t region_space, hid_t region_id, hid_t container, int ndims, hid_t type_id, hssize_t npoints, hsize_t *ptdata) { hsize_t *dims1 = NULL; size_t type_size; hid_t mem_space = H5I_INVALID_HID; void *region_buf = NULL; int ret_value = SUCCEED; UNUSED(ptdata); if (!(type_size = H5Tget_size(type_id))) { ret_value = FAIL; goto done; } if (NULL == (region_buf = HDmalloc(type_size * (size_t)npoints))) { ret_value = FAIL; goto done; } /* Allocate space for the dimension array */ if (NULL == (dims1 = (hsize_t *) HDmalloc(sizeof(hsize_t) * (size_t)ndims))) { ret_value = FAIL; goto done; } dims1[0] = (hsize_t)npoints; if ((mem_space = H5Screate_simple(1, dims1, NULL)) < 0) { ret_value = FAIL; goto done; } if (H5Dread(region_id, type_id, mem_space, region_space, H5P_DEFAULT, region_buf) < 0) { ret_value = FAIL; goto done; } if (H5Sget_simple_extent_dims(region_space, dims1, NULL) < 0) { ret_value = FAIL; goto done; } if (h5str_render_bin_output(stream, container, type_id, (char *)region_buf, (hsize_t)npoints) < 0) { ret_value = FAIL; goto done; } done: if (dims1) HDfree(dims1); if (mem_space >= 0) H5Sclose(mem_space); if (region_buf) HDfree(region_buf); return ret_value; } /* end render_bin_output_region_data_points */ /*------------------------------------------------------------------------- * Purpose: Print some values from a dataset referenced by region points. * * Description: * This is a special case subfunction to dump a region reference using points. * * Return: * The function returns False if the last dimension has been reached, otherwise True * *------------------------------------------------------------------------- */ static int render_bin_output_region_points (FILE *stream, hid_t region_space, hid_t region_id, hid_t container) { hssize_t npoints; hsize_t alloc_size; hsize_t *ptdata = NULL; hid_t dtype = H5I_INVALID_HID; hid_t type_id = H5I_INVALID_HID; int ndims; int ret_value = SUCCEED; if ((npoints = H5Sget_select_elem_npoints(region_space)) < 0) { ret_value = FAIL; goto done; } if (npoints > 0) { /* Allocate space for the dimension array */ if ((ndims = H5Sget_simple_extent_ndims(region_space)) < 0) { ret_value = FAIL; goto done; } alloc_size = (hsize_t)npoints * (hsize_t)ndims * (hsize_t)sizeof(ptdata[0]); if (NULL == (ptdata = (hsize_t *) HDmalloc((size_t)alloc_size))) { ret_value = FAIL; goto done; } if (H5Sget_select_elem_pointlist(region_space, (hsize_t)0, (hsize_t)npoints, ptdata) < 0) { ret_value = FAIL; goto done; } if ((dtype = H5Dget_type(region_id)) < 0) { ret_value = FAIL; goto done; } if ((type_id = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) < 0) { ret_value = FAIL; goto done; } if (render_bin_output_region_data_points(stream, region_space, region_id, container, ndims, type_id, npoints, ptdata) < 0) { ret_value = FAIL; goto done; } } done: if (type_id >= 0) H5Tclose(type_id); if (dtype >= 0) H5Tclose(dtype); if (ptdata) HDfree(ptdata); return ret_value; } /* end render_bin_output_region_points */ int h5str_dump_simple_dset (JNIEnv *env, FILE *stream, hid_t dset, int binary_order) { hsize_t elmtno; /* counter */ hsize_t zero[8]; /* vector of zeros */ hsize_t total_size[H5S_MAX_RANK]; /* total size of dataset*/ size_t i; /* counter */ hid_t f_space = H5I_INVALID_HID; /* file data space */ int ndims; int carry; /* counter carry value */ /* Print info */ hsize_t p_nelmts; /* total selected elmts */ size_t p_type_nbytes; /* size of memory type */ /* Stripmine info */ unsigned char *sm_buf = NULL; /* buffer for raw data */ hsize_t sm_size[H5S_MAX_RANK]; /* stripmine size */ hsize_t sm_nbytes; /* bytes per stripmine */ hsize_t sm_nelmts; /* elements per stripmine */ hid_t sm_space = H5I_INVALID_HID; /* stripmine data space */ /* Hyperslab info */ hsize_t hs_offset[H5S_MAX_RANK]; /* starting offset */ hsize_t hs_size[H5S_MAX_RANK]; /* size this pass */ hsize_t hs_nelmts; /* elements in request */ /* VL data special information */ unsigned int vl_data = 0; /* contains VL datatypes */ hid_t p_type = H5I_INVALID_HID; hid_t f_type = H5I_INVALID_HID; int ret_value = FAIL; if (dset < 0) H5_BAD_ARGUMENT_ERROR(ENVONLY, "h5str_dump_simple_dset: dset ID < 0"); if ((f_type = H5Dget_type(dset)) < 0) H5_LIBRARY_ERROR(ENVONLY); switch (binary_order) { case 1: { if ((p_type = h5str_get_native_type(f_type)) < 0) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); break; } case 2: { if ((p_type = h5str_get_little_endian_type(f_type)) < 0) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); break; } case 3: { if ((p_type = h5str_get_big_endian_type(f_type)) < 0) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); break; } default: { if ((p_type = H5Tcopy(f_type)) < 0) H5_LIBRARY_ERROR(ENVONLY); break; } } if ((f_space = H5Dget_space(dset)) < 0) H5_LIBRARY_ERROR(ENVONLY); if ((ndims = H5Sget_simple_extent_ndims(f_space)) < 0) H5_LIBRARY_ERROR(ENVONLY); if ((size_t)ndims <= (sizeof(sm_size) / sizeof(sm_size[0]))) { if (H5Sget_simple_extent_dims(f_space, total_size, NULL) < 0) H5_LIBRARY_ERROR(ENVONLY); /* Calculate the number of elements we're going to print */ p_nelmts = 1; if (ndims > 0) { for (i = 0; i < (size_t) ndims; i++) p_nelmts *= total_size[i]; } /* end if */ if (p_nelmts > 0) { /* Check if we have VL data in the dataset's datatype */ if (h5str_detect_vlen(p_type) != 0) vl_data = 1; /* * Determine the strip mine size and allocate a buffer. The strip mine is * a hyperslab whose size is manageable. */ if (!(sm_nbytes = p_type_nbytes = H5Tget_size(p_type))) H5_LIBRARY_ERROR(ENVONLY); if (ndims > 0) { for (i = (size_t)ndims; i > 0; --i) { hsize_t size = H5TOOLS_BUFSIZE / sm_nbytes; if ( size == 0 ) /* datum size > H5TOOLS_BUFSIZE */ size = 1; sm_size[i - 1] = (((total_size[i - 1]) < (size)) ? (total_size[i - 1]) : (size)); sm_nbytes *= sm_size[i - 1]; } } if (sm_nbytes > 0) { if (NULL == (sm_buf = (unsigned char *) HDmalloc((size_t)sm_nbytes))) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_simple_dset: failed to allocate sm_buf"); sm_nelmts = sm_nbytes / p_type_nbytes; if ((sm_space = H5Screate_simple(1, &sm_nelmts, NULL)) < 0) H5_LIBRARY_ERROR(ENVONLY); /* The stripmine loop */ HDmemset(hs_offset, 0, sizeof hs_offset); HDmemset(zero, 0, sizeof zero); for (elmtno = 0; elmtno < p_nelmts; elmtno += hs_nelmts) { /* Calculate the hyperslab size */ if (ndims > 0) { for (i = 0, hs_nelmts = 1; i < (size_t) ndims; i++) { hs_size[i] = (((total_size[i] - hs_offset[i]) < (sm_size[i])) ? (total_size[i] - hs_offset[i]) : (sm_size[i])); hs_nelmts *= hs_size[i]; } if (H5Sselect_hyperslab(f_space, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL) < 0) H5_LIBRARY_ERROR(ENVONLY); if (H5Sselect_hyperslab(sm_space, H5S_SELECT_SET, zero, NULL, &hs_nelmts, NULL) < 0) H5_LIBRARY_ERROR(ENVONLY); } else { if (H5Sselect_all(f_space) < 0) H5_LIBRARY_ERROR(ENVONLY); if (H5Sselect_all(sm_space) < 0) H5_LIBRARY_ERROR(ENVONLY); hs_nelmts = 1; } /* Read the data */ if (H5Dread(dset, p_type, sm_space, f_space, H5P_DEFAULT, sm_buf) < 0) H5_LIBRARY_ERROR(ENVONLY); if (binary_order == 99) { if (h5tools_dump_simple_data(ENVONLY, stream, dset, p_type, sm_buf, hs_nelmts) < 0) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } else { if (h5str_render_bin_output(stream, dset, p_type, sm_buf, hs_nelmts) < 0) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); } /* Reclaim any VL memory, if necessary */ if (vl_data) { if (H5Dvlen_reclaim(p_type, sm_space, H5P_DEFAULT, sm_buf) < 0) H5_LIBRARY_ERROR(ENVONLY); } /* Calculate the next hyperslab offset */ for (i = (size_t)ndims, carry = 1; i > 0 && carry; --i) { hs_offset[i - 1] += hs_size[i - 1]; if (hs_offset[i - 1] == total_size[i - 1]) hs_offset[i - 1] = 0; else carry = 0; } } } } } ret_value = SUCCEED; done: if (sm_space >= 0) H5Sclose(sm_space); if (sm_buf) HDfree(sm_buf); if (f_space >= 0) H5Sclose(f_space); if (p_type >= 0) H5Tclose(p_type); if (f_type >= 0) H5Tclose(f_type); return ret_value; } /* end h5str_dump_simple_dset */ htri_t H5Tdetect_variable_str(hid_t tid) { htri_t ret_val = 0; if (H5Tget_class(tid) == H5T_COMPOUND) { unsigned i; unsigned nm = (unsigned)H5Tget_nmembers(tid); for(i = 0; i < nm; i++) { htri_t status = 0; hid_t mtid = 0; if((mtid = H5Tget_member_type(tid, i)) < 0) return FAIL; /* exit immediately on error */ if((status = H5Tdetect_variable_str(mtid)) < 0) return status; /* exit immediately on error */ ret_val |= status; H5Tclose (mtid); } /* end for */ } /* end if */ else ret_val = H5Tis_variable_str(tid); return ret_val; } /* end H5Tdetect_variable_str */ static int h5tools_dump_simple_data (JNIEnv *env, FILE *stream, hid_t container, hid_t type, void *_mem, hsize_t nelmts) { unsigned char *mem = (unsigned char *)_mem; h5str_t buffer; /* string into which to render */ hsize_t i; /* element counter */ size_t size; /* datum size */ int line_count; int ret_value = 0; if (!(size = H5Tget_size(type))) H5_LIBRARY_ERROR(ENVONLY); for (i = 0, line_count = 0; i < nelmts; i++, line_count++) { size_t bytes_in = 0; /* # of bytes to write */ void *memref = mem + i * size; /* Render the data element*/ h5str_new(&buffer, 32 * size); if (!buffer.s) H5_JNI_FATAL_ERROR(ENVONLY, "h5tools_dump_simple_data: failed to allocate buffer"); if (!(bytes_in = h5str_sprintf(ENVONLY, &buffer, container, type, memref, 0, 1))) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); if (i > 0) { if (HDfprintf(stream, ", ") < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5tools_dump_simple_data: HDfprintf failure"); if (line_count >= H5TOOLS_TEXT_BLOCK) { line_count = 0; if (HDfprintf(stream, "\n") < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5tools_dump_simple_data: HDfprintf failure"); } } if (HDfprintf(stream, "%s", buffer.s) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5tools_dump_simple_data: HDfprintf failure"); h5str_free(&buffer); } /* end for (i = 0; i < nelmts... */ if (HDfprintf(stream, "\n") < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5tools_dump_simple_data: HDfprintf failure"); done: if (buffer.s) h5str_free(&buffer); return ret_value; } /* end h5tools_dump_simple_data */ /* * Utility Java APIs * Functions designed to workaround issues with the Java-C interface */ /* * Class: hdf_hdf5lib_H5 * Method: H5AreadComplex * Signature: (JJ[Ljava/lang/String;)I */ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5AreadComplex (JNIEnv *env, jclass clss, jlong attr_id, jlong mem_type_id, jobjectArray buf) { h5str_t h5str; jstring jstr; size_t size; size_t i; hid_t p_type = H5I_INVALID_HID; jsize n; char *readBuf = NULL; herr_t status = FAIL; UNUSED(clss); HDmemset(&h5str, 0, sizeof(h5str_t)); if ((p_type = H5Tget_native_type(mem_type_id, H5T_DIR_DEFAULT)) < 0) H5_LIBRARY_ERROR(ENVONLY); size = (((H5Tget_size(mem_type_id))>(H5Tget_size(p_type))) ? (H5Tget_size(mem_type_id)) : (H5Tget_size(p_type))); if ((n = ENVPTR->GetArrayLength(ENVONLY, buf)) <= 0) { CHECK_JNI_EXCEPTION(ENVONLY, JNI_TRUE); H5_BAD_ARGUMENT_ERROR(ENVONLY, "H5AreadComplex: read buffer length <= 0"); } if (NULL == (readBuf = (char *) HDmalloc((size_t)n * size))) H5_JNI_FATAL_ERROR(ENVONLY, "H5AreadComplex: failed to allocate read buffer"); if ((status = H5Aread(attr_id, mem_type_id, readBuf)) < 0) H5_LIBRARY_ERROR(ENVONLY); h5str_new(&h5str, 4 * size); if (!h5str.s) H5_JNI_FATAL_ERROR(ENVONLY, "H5AreadComplex: failed to allocate string buffer"); for (i = 0; i < (size_t) n; i++) { h5str.s[0] = '\0'; if (!h5str_sprintf(ENVONLY, &h5str, attr_id, mem_type_id, readBuf + (i * size), 0, 0)) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); if (NULL == (jstr = ENVPTR->NewStringUTF(ENVONLY, h5str.s))) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); ENVPTR->SetObjectArrayElement(ENVONLY, buf, (jsize) i, jstr); CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); ENVPTR->DeleteLocalRef(ENVONLY, jstr); } /* end for */ done: if (h5str.s) h5str_free(&h5str); if (readBuf) HDfree(readBuf); if (p_type >= 0) H5Tclose(p_type); return status; } /* * Copies the content of one attribute to another attribute * Class: hdf_hdf5lib_H5 * Method: H5Acopy * Signature: (JJ)I */ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Acopy (JNIEnv *env, jclass clss, jlong src_id, jlong dst_id) { hssize_t npoints; hsize_t total_size = 0; size_t type_size; jbyte *buf = NULL; hid_t tid = H5I_INVALID_HID; hid_t sid = H5I_INVALID_HID; herr_t retVal = FAIL; UNUSED(clss); if ((sid = H5Aget_space((hid_t)src_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); if ((tid = H5Aget_type((hid_t)src_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); if ((npoints = H5Sget_simple_extent_npoints(sid)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (!(type_size = H5Tget_size(tid))) H5_LIBRARY_ERROR(ENVONLY); total_size = (hsize_t)npoints * (hsize_t)type_size; if (NULL == (buf = (jbyte *) HDmalloc((size_t)total_size * sizeof(jbyte)))) H5_JNI_FATAL_ERROR(ENVONLY, "H5Acopy: failed to allocate buffer"); if ((retVal = H5Aread((hid_t)src_id, tid, buf)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (H5Tclose(tid) < 0) H5_LIBRARY_ERROR(ENVONLY); tid = H5I_INVALID_HID; if ((tid = H5Aget_type((hid_t)dst_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); if ((retVal = H5Awrite((hid_t)dst_id, tid, buf)) < 0) H5_LIBRARY_ERROR(ENVONLY); done: if (buf) HDfree(buf); if (tid >= 0) H5Tclose(tid); if (sid >= 0) H5Sclose(sid); return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Acopy */ /* * Copies the content of one dataset to another dataset * Class: hdf_hdf5lib_H5 * Method: H5Dcopy * Signature: (JJ)I */ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Dcopy (JNIEnv *env, jclass clss, jlong src_id, jlong dst_id) { hssize_t npoints; hsize_t total_size = 0, total_allocated_size; size_t type_size; jbyte *buf = NULL; hid_t tid = H5I_INVALID_HID; hid_t sid = H5I_INVALID_HID; herr_t retVal = FAIL; UNUSED(clss); if (!(total_allocated_size = H5Dget_storage_size((hid_t)src_id))) return 0; // nothing to write if ((sid = H5Dget_space((hid_t)src_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); if ((tid = H5Dget_type((hid_t)src_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); if ((npoints = H5Sget_simple_extent_npoints(sid)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (!(type_size = H5Tget_size(tid))) H5_LIBRARY_ERROR(ENVONLY); total_size = (hsize_t)npoints * (hsize_t)type_size; if (NULL == (buf = (jbyte *) HDmalloc((size_t)total_size * sizeof(jbyte)))) H5_JNI_FATAL_ERROR(ENVONLY, "H5Dcopy: failed to allocate buffer"); if ((retVal = H5Dread((hid_t)src_id, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf)) < 0) H5_LIBRARY_ERROR(ENVONLY); if (H5Tclose(tid) < 0) H5_LIBRARY_ERROR(ENVONLY); tid = H5I_INVALID_HID; if ((tid = H5Dget_type((hid_t)dst_id)) < 0) H5_LIBRARY_ERROR(ENVONLY); if ((retVal = H5Dwrite((hid_t)dst_id, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf)) < 0) H5_LIBRARY_ERROR(ENVONLY); done: if (buf) HDfree(buf); if (tid >= 0) H5Tclose(tid); if (sid >= 0) H5Sclose(sid); return (jint)retVal; } /* end Java_hdf_hdf5lib_H5_H5Dcopy */ /* ///////////////////////////////////////////////////////////////////////////////// // // // Add these methods so that we don't need to call H5Gget_objtype_by_idx // in a loop to get information for all the objects in a group, which takes // a lot of time to finish if the number of objects is more than 10,000 // ///////////////////////////////////////////////////////////////////////////////// */ #ifdef __cplusplus herr_t obj_info_all(hid_t g_id, const char *name, const H5L_info_t *linfo, void *op_data); herr_t obj_info_max(hid_t g_id, const char *name, const H5L_info_t *linfo, void *op_data); int H5Gget_obj_info_max(hid_t, char **, int *, int *, unsigned long *, long); int H5Gget_obj_info_full( hid_t loc_id, char **objname, int *otype, int *ltype, unsigned long *fno, unsigned long *objno, int indexType, int indexOrder); #else static herr_t obj_info_all(hid_t g_id, const char *name, const H5L_info_t *linfo, void *op_data); static herr_t obj_info_max(hid_t g_id, const char *name, const H5L_info_t *linfo, void *op_data); static int H5Gget_obj_info_max(hid_t, char **, int *, int *, unsigned long *, long); static int H5Gget_obj_info_full( hid_t loc_id, char **objname, int *otype, int *ltype, unsigned long *fno, unsigned long *objno, int indexType, int indexOrder); #endif typedef struct info_all { char **objname; int *otype; int *ltype; unsigned long *objno; unsigned long *fno; unsigned long idxnum; int count; } info_all_t; /* * Class: hdf_hdf5lib_H5 * Method: H5Gget_obj_info_full * Signature: (JLjava/lang/String;[Ljava/lang/String;[I[I[J[JIII)I */ /* * NOTE: This is a dangerous call! The caller can supply any value they'd like * for 'n' and if it exceeds the number of links in the group, we will most likely * end up overwriting memory heap-tracking info. */ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Gget_1obj_1info_1full (JNIEnv *env, jclass clss, jlong loc_id, jstring group_name, jobjectArray objName, jintArray oType, jintArray lType, jlongArray fNo, jlongArray oRef, jint n, jint indx_type, jint indx_order) { unsigned long *refs = NULL; unsigned long *fnos = NULL; const char *gName = NULL; char **oName = NULL; jboolean isCopy; jstring str; jint *otarr = NULL; jint *ltarr = NULL; jlong *refP = NULL; jlong *fnoP = NULL; hid_t gid = (hid_t)loc_id; int i; int indexType = indx_type; int indexOrder = indx_order; herr_t ret_val = FAIL; UNUSED(clss); if (NULL == oType) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Gget_obj_info_full: oType is NULL"); if (NULL == lType) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Gget_obj_info_full: lType is NULL"); if (NULL == oRef) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Gget_obj_info_full: oRef is NULL"); if (NULL == fNo) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Gget_obj_info_full: fNo is NULL"); PIN_INT_ARRAY(ENVONLY, oType, otarr, &isCopy, "H5Gget_obj_info_full: oType not pinned"); PIN_INT_ARRAY(ENVONLY, lType, ltarr, &isCopy, "H5Gget_obj_info_full: lType not pinned"); PIN_LONG_ARRAY(ENVONLY, oRef, refP, &isCopy, "H5Gget_obj_info_full: oRef not pinned"); PIN_LONG_ARRAY(ENVONLY, fNo, fnoP, &isCopy, "H5Gget_obj_info_full: fNo not pinned"); if (NULL == (oName = (char **) HDcalloc((size_t)n, sizeof(*oName)))) H5_JNI_FATAL_ERROR(ENVONLY, "H5Gget_obj_info_full: failed to allocate buffer for object name"); if (NULL == (refs = (unsigned long *) HDcalloc((size_t)n, sizeof(unsigned long)))) H5_JNI_FATAL_ERROR(ENVONLY, "H5Gget_obj_info_full: failed to allocate buffer for ref. info"); if (NULL == (fnos = (unsigned long *) HDcalloc((size_t)n, sizeof(unsigned long)))) H5_JNI_FATAL_ERROR(ENVONLY, "H5Gget_obj_info_full: failed to allocate buffer for file number info"); if (group_name) { PIN_JAVA_STRING(ENVONLY, group_name, gName, &isCopy, "H5Gget_obj_info_full: group_name not pinned"); if ((gid = H5Gopen2((hid_t)loc_id, gName, H5P_DEFAULT)) < 0) H5_LIBRARY_ERROR(ENVONLY); } if ((ret_val = H5Gget_obj_info_full(gid, oName, (int *)otarr, (int *)ltarr, fnos, refs, indexType, indexOrder)) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "H5Gget_obj_info_full: retrieval of object info failed"); for (i = 0; i < n; i++) { refP[i] = (jlong)refs[i]; fnoP[i] = (jlong)fnos[i]; if (oName[i]) { if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, oName[i]))) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); ENVPTR->SetObjectArrayElement(ENVONLY, objName, i, (jobject)str); CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); ENVPTR->DeleteLocalRef(ENVONLY, str); } /* end if */ } done: if (gName) { H5Gclose(gid); UNPIN_JAVA_STRING(ENVONLY, group_name, gName); } if (fnos) HDfree(fnos); if (refs) HDfree(refs); if (oName) h5str_array_free(oName, (size_t)n); if (fnoP) UNPIN_LONG_ARRAY(ENVONLY, fNo, fnoP, (ret_val < 0) ? JNI_ABORT : 0); if (refP) UNPIN_LONG_ARRAY(ENVONLY, oRef, refP, (ret_val < 0) ? JNI_ABORT : 0); if (ltarr) UNPIN_INT_ARRAY(ENVONLY, lType, ltarr, (ret_val < 0) ? JNI_ABORT : 0); if (otarr) UNPIN_INT_ARRAY(ENVONLY, oType, otarr, (ret_val < 0) ? JNI_ABORT : 0); return ret_val; } /* end Java_hdf_hdf5lib_H5_H5Gget_1obj_1info_1full */ /* * Class: hdf_hdf5lib_H5 * Method: H5Gget_obj_info_max * Signature: (J[Ljava/lang/String;[I[I[JJI)I */ /* * NOTE: This is a dangerous call! The caller can supply any value they'd like * for 'n' and if it exceeds the number of links reachable from the group, we * will most likely end up overwriting memory heap-tracking info. */ JNIEXPORT jint JNICALL Java_hdf_hdf5lib_H5_H5Gget_1obj_1info_1max (JNIEnv *env, jclass clss, jlong loc_id, jobjectArray objName, jintArray oType, jintArray lType, jlongArray oRef, jlong maxnum, jint n) { unsigned long *refs = NULL; jboolean isCopy; jstring str; jlong *refP = NULL; char **oName = NULL; jint *otarr = NULL; jint *ltarr = NULL; int i; herr_t ret_val = FAIL; UNUSED(clss); if (NULL == oType) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Gget_obj_info_max: oType is NULL"); if (NULL == lType) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Gget_obj_info_max: lType is NULL"); if (NULL == oRef) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5Gget_obj_info_max: oRef is NULL"); PIN_INT_ARRAY(ENVONLY, oType, otarr, &isCopy, "H5Gget_obj_info_max: oType not pinned"); PIN_INT_ARRAY(ENVONLY, lType, ltarr, &isCopy, "H5Gget_obj_info_max: lType not pinned"); PIN_LONG_ARRAY(ENVONLY, oRef, refP, &isCopy, "H5Gget_obj_info_max: oRef not pinned"); if (NULL == (oName = (char **) HDcalloc((size_t)n, sizeof(*oName)))) H5_JNI_FATAL_ERROR(ENVONLY, "H5Gget_obj_info_max: failed to allocate buffer for object name"); if (NULL == (refs = (unsigned long *) HDcalloc((size_t)n, sizeof(unsigned long)))) H5_JNI_FATAL_ERROR(ENVONLY, "H5Gget_obj_info_max: failed to allocate buffer for ref. info"); if ((ret_val = H5Gget_obj_info_max((hid_t)loc_id, oName, (int *)otarr, (int *)ltarr, refs, maxnum)) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "H5Gget_obj_info_max: retrieval of object info failed"); for (i = 0; i < n; i++) { refP[i] = (jlong) refs[i]; if (oName[i]) { if (NULL == (str = ENVPTR->NewStringUTF(ENVONLY, oName[i]))) CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); ENVPTR->SetObjectArrayElement(ENVONLY, objName, i, (jobject)str); CHECK_JNI_EXCEPTION(ENVONLY, JNI_FALSE); ENVPTR->DeleteLocalRef(ENVONLY, str); } } /* end for */ done: if (refs) HDfree(refs); if (oName) h5str_array_free(oName, (size_t)n); if (refP) UNPIN_LONG_ARRAY(ENVONLY, oRef, refP, (ret_val < 0) ? JNI_ABORT : 0); if (ltarr) UNPIN_INT_ARRAY(ENVONLY, lType, ltarr, (ret_val < 0) ? JNI_ABORT : 0); if (otarr) UNPIN_INT_ARRAY(ENVONLY, oType, otarr, (ret_val < 0) ? JNI_ABORT : 0); return ret_val; } /* end Java_hdf_hdf5lib_H5_H5Gget_1obj_1info_1max */ int H5Gget_obj_info_full (hid_t loc_id, char **objname, int *otype, int *ltype, unsigned long *fno, unsigned long *objno, int indexType, int indexOrder) { info_all_t info; info.objname = objname; info.otype = otype; info.ltype = ltype; info.idxnum = 0; info.fno = fno; info.objno = objno; info.count = 0; if (H5Literate(loc_id, (H5_index_t)indexType, (H5_iter_order_t)indexOrder, NULL, obj_info_all, (void *)&info) < 0) { /* * Reset info stats; most importantly, reset the count. */ info.objname = objname; info.otype = otype; info.ltype = ltype; info.idxnum = 0; info.fno = fno; info.objno = objno; info.count = 0; /* Iteration failed, try normal alphabetical order */ if (H5Literate(loc_id, H5_INDEX_NAME, H5_ITER_INC, NULL, obj_info_all, (void *)&info) < 0) return -1; } return info.count; } /* end H5Gget_obj_info_full */ int H5Gget_obj_info_max (hid_t loc_id, char **objname, int *otype, int *ltype, unsigned long *objno, long maxnum) { info_all_t info; info.objname = objname; info.otype = otype; info.ltype = ltype; info.idxnum = (unsigned long)maxnum; info.objno = objno; info.count = 0; if (H5Lvisit(loc_id, H5_INDEX_NAME, H5_ITER_NATIVE, obj_info_max, (void *)&info) < 0) return -1; return info.count; } /* end H5Gget_obj_info_max */ herr_t obj_info_all (hid_t loc_id, const char *name, const H5L_info_t *info, void *op_data) { info_all_t *datainfo = (info_all_t *)op_data; H5O_info_t object_info; htri_t object_exists; size_t str_len; datainfo->otype[datainfo->count] = -1; datainfo->ltype[datainfo->count] = -1; datainfo->objno[datainfo->count] = (unsigned long)-1; str_len = HDstrlen(name); if (NULL == (datainfo->objname[datainfo->count] = (char *) HDmalloc(str_len + 1))) goto done; HDstrncpy(datainfo->objname[datainfo->count], name, str_len); (datainfo->objname[datainfo->count])[str_len] = '\0'; if ((object_exists = H5Oexists_by_name(loc_id, name, H5P_DEFAULT)) < 0) goto done; if (object_exists) { if (H5Oget_info_by_name2(loc_id, name, &object_info, H5O_INFO_ALL, H5P_DEFAULT) < 0) goto done; datainfo->otype[datainfo->count] = object_info.type; datainfo->ltype[datainfo->count] = info->type; datainfo->fno[datainfo->count] = object_info.fileno; datainfo->objno[datainfo->count] = (unsigned long)object_info.addr; } /* if (info->type == H5L_TYPE_HARD) datainfo->objno[datainfo->count] = (unsigned long)info->u.address; else datainfo->objno[datainfo->count] = info->u.val_size; */ done: datainfo->count++; return SUCCEED; } /* end obj_info_all */ herr_t obj_info_max (hid_t loc_id, const char *name, const H5L_info_t *info, void *op_data) { info_all_t *datainfo = (info_all_t *)op_data; H5O_info_t object_info; size_t str_len; datainfo->otype[datainfo->count] = -1; datainfo->ltype[datainfo->count] = -1; datainfo->objname[datainfo->count] = NULL; datainfo->objno[datainfo->count] = (unsigned long)-1; /* This will be freed by h5str_array_free(oName, n) */ str_len = HDstrlen(name); if (NULL == (datainfo->objname[datainfo->count] = (char *) HDmalloc(str_len + 1))) goto done; HDstrncpy(datainfo->objname[datainfo->count], name, str_len); (datainfo->objname[datainfo->count])[str_len] = '\0'; if (H5Oget_info2(loc_id, &object_info, H5O_INFO_ALL) < 0) goto done; datainfo->otype[datainfo->count] = object_info.type; datainfo->ltype[datainfo->count] = info->type; if (info->type == H5L_TYPE_HARD) datainfo->objno[datainfo->count] = (unsigned long)info->u.address; else datainfo->objno[datainfo->count] = info->u.val_size; done: datainfo->count++; if (datainfo->count >= (int)datainfo->idxnum) return 1; else return SUCCEED; } /* end obj_info_max */ /* * Class: hdf_hdf5lib_H5 * Method: H5export_dataset * Signature: (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V */ JNIEXPORT void JNICALL Java_hdf_hdf5lib_H5_H5export_1dataset (JNIEnv *env, jclass cls, jstring file_export_name, jstring file_name, jstring object_path, jint binary_order) { const char *file_export = NULL; const char *object_name = NULL; const char *fileName = NULL; jboolean isCopy; herr_t ret_val = FAIL; hid_t file_id = H5I_INVALID_HID; hid_t dataset_id = H5I_INVALID_HID; FILE *stream; UNUSED(cls); if (NULL == file_export_name) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5export_dataset: file_export_name is NULL"); if (NULL == file_name) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5export_dataset: file_name is NULL"); if (NULL == object_path) H5_NULL_ARGUMENT_ERROR(ENVONLY, "H5export_dataset: object_path is NULL"); PIN_JAVA_STRING(ENVONLY, file_name, fileName, NULL, "H5export_dataset: file name not pinned"); if ((file_id = H5Fopen(fileName, (unsigned)H5F_ACC_RDWR, (hid_t)H5P_DEFAULT)) < 0) H5_LIBRARY_ERROR(ENVONLY); PIN_JAVA_STRING(ENVONLY, object_path, object_name, &isCopy, "H5export_dataset: object_path not pinned"); if ((dataset_id = H5Dopen2(file_id, object_name, H5P_DEFAULT)) < 0) H5_LIBRARY_ERROR(ENVONLY); PIN_JAVA_STRING(ENVONLY, file_export_name, file_export, NULL, "H5export_dataset: file_export name not pinned"); if (NULL == (stream = HDfopen(file_export, "w+"))) H5_JNI_FATAL_ERROR(ENVONLY, "HDfopen failed"); if ((ret_val = h5str_dump_simple_dset(ENVONLY, stream, dataset_id, binary_order)) < 0) H5_JNI_FATAL_ERROR(ENVONLY, "h5str_dump_simple_dset failed"); if (stream) { HDfclose(stream); stream = NULL; } done: if (stream) HDfclose(stream); if (file_export) UNPIN_JAVA_STRING(ENVONLY, file_export_name, file_export); if (object_name) UNPIN_JAVA_STRING(ENVONLY, object_path, object_name); if (fileName) UNPIN_JAVA_STRING(ENVONLY, file_name, fileName); if (dataset_id >= 0) H5Dclose(dataset_id); if (file_id >= 0) H5Fclose(file_id); } /* end Java_hdf_hdf5lib_H5_H5export_1dataset */ #ifdef __cplusplus } #endif |