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
|
use Config;
our $VERSION = '0.73';
pp_setversion(qq{'$VERSION'});
# Necessary includes for .xs file
pp_addhdr(<<'EOH');
#include <hdf5.h>
#define PDLchar pdl
#define PDLuchar pdl
#define PDLshort pdl
#define PDLint pdl
#define PDLlong pdl
#define PDLfloat pdl
#define PDLdouble pdl
#define uchar unsigned char
EOH
pp_bless ("PDL::IO::HDF5");
pp_addpm(<<'EOPM');
=head1 NAME
PDL::IO::HDF5 - PDL Interface to the HDF5 Data Format.
=head1 DESCRIPTION
This package provides an object-oriented interface for L<PDL>s to
the HDF5 data-format. Information on the HDF5 Format can be found
at the HDF Group's web site at http://www.hdfgroup.org .
=head2 LIMITATIONS
Currently this interface only provides a subset of the total HDF5 library's
capability.
=over 1
=item *
Only HDF5 Simple datatypes are supported. No HDF5 Compound datatypes are supported since PDL doesn't
support them.
=item *
Only HDF5 Simple dataspaces are supported.
=back
=head1 SYNOPSIS
use PDL::IO::HDF5;
# Files #######
my $newfile = new PDL::IO::HDF5("newfile.hdf"); # create new hdf5 or open existing file.
my $attrValue = $existingFile->attrGet('AttrName'); # Get attribute value for file
$existingFile->attSet('AttrName' => 'AttrValue'); # Set attribute value(s) for file
# Groups ######
my $group = $newfile->group("/mygroup"); # create a new or open existing group
my @groups = $existingFile->groups; # get a list of all the groups at the root '/'
# level.
my @groups = $group->groups; # get a list of all the groups at the "mygroup"
# level.
my $group2 = $group->group('newgroup'); # Create/open a new group in existing group "mygroup"
$group->unlink('datasetName'); # Delete a dataset from a group
$group->reference($dataset,'refName',\@start,\@count); # Create a scalar reference to a subregion of a
# dataset, with specified start index and count.
my $attrValue = $group->attrGet('AttrName'); # Get attribute value for a group
$group->attrSet('AttrName' => 'AttrValue'); # Set attribute value(s) for a group
$group->attrDel('AttrName1', 'AttrName2'); # Delete attribute(s) for a group
@attrs = $group->attrs; # Get List of attributes for a group
# Data Sets ########
my $dataset = $group->dataset( 'datasetName'); # create a new or open existing dataset
# in an existing group
my $dataset = $newfile->dataset( 'datasetName'); # create a new or open existing dataset
# in the root group of a file
my $dataset2 = $newfile->dataset( 'datasetName'); # create a new or open existing dataset
# in the root group.
my @datasets = $existingFile->datasets; # get a list of all datasets in the root '/' group
my @datasets = $group->datasets; # get a list of all datasets in a group
@dims = $dataset->dims; # get a list of dimensions for the dataset
$pdl = $dataset->get(); # Get the array data in the dataset
$pdl = $dataset->get($start,$length,$stride); # Get a slice or hyperslab of the array data in the dataset
$dataset->set($pdl, unlimited => 1); # Set the array data in the dataset
my $attrValue = $dataset->attrGet('AttrName'); # Get attribute value for a dataset
$dataset->attSet('AttrName' => 'AttrValue'); # Set attribute value(s) for a dataset
=head1 MEMBER DATA
=over 1
=item ID
ID number given to the file by the HDF5 library
=item filename
Name of the file.
=item accessMode
Access Mode?? ( read /write etc????)
=item attrIndex
Quick lookup index of group names to attribute values. Autogenerated as-needed by the
L<allAttrValues>, L<allAttrNames>, L<getGroupByAttr> methods. Any attribute writes or group
creations will delete this data member, because it will no longer be valid.
The index is of this form:
{
groupName1 => { attr1 => value, attr2 => value }.
groupName2 => { attr1 => value, attr3 => value }.
.
.
.
}
For the purposes of indexing groups by their attributes, the attributes are
applied hierarchically. i.e. any attributes of the higher level groups are assumed to be
apply for the lower level groups.
=item groupIndex
Quick lookup index of attribute names/values group names. This index is used by the
L<getGroupByAttr> method to quickly find any group(s) that have attribute that match a
desired set.
The index is of this form:
{ "attr1\0attt2" => { "value1\0value2' => [ group1, group2, ...],
"value3\0value3' => [ groupA ],
.
.
.
},
"att1" => { "value1' => [ group1, group2, ...],
"value3' => [ groupA ]
.
.
.
},
.
.
.
}
The first level of the index maps the attribute name combinations that have
indexes built to their index. The second level maps the corresponding attribute values
with the group(s) where these attributes take on these values.
groupName1 => { attr1 => value, attr2 => value }.
groupName2 => { attr1 => value, attr3 => value }.
.
.
.
}
For the purposes of indexing groups by their attributes, the attributes are
applied hierarchically. i.e. any attributes of the higher level groups are assumed to be
apply for the lower level groups.
=back
=head1 METHODS
=head2 new
=for ref
PDL::IO::HDF5 constructor - creates PDL::IO::HDF5 object for reading or
writing data.
B<Usage:>
=for usage
$a = new PDL::IO::HDF5( $filename );
Arguments:
1) The name of the file.
If this file exists and you want to write to it,
prepend the name with the '>' character: ">name.nc"
Returns undef on failure.
B<Example:>
=for example
$hdf5obj = new PDL::IO::HDF5( "file.hdf" );
=cut
sub new {
my $type = shift;
my $file = shift;
my $self = {};
my $rc;
my $write;
if (substr($file, 0, 1) eq '>') { # open for writing
$file = substr ($file, 1); # chop off >
$write = 1;
}
my $fileID; # HDF file id
if (-e $file) { # Existing File
if ($write) {
$fileID = H5Fopen($file, H5F_ACC_RDWR(), H5P_DEFAULT());
if( $fileID < 0){
carp("Can't Open Existing HDF file '$file' for writing\n");
return undef;
}
$self->{accessMode} = 'w';
} else { # Open read-only
$fileID = H5Fopen($file, H5F_ACC_RDONLY(), H5P_DEFAULT());
if( $fileID < 0){
carp("Can't Open Existing HDF file '$file' for reading\n");
return undef;
}
$self->{accessMode} = 'r';
}
}
else{ # File doesn't exist, create it:
$fileID = H5Fcreate($file, H5F_ACC_TRUNC(), H5P_DEFAULT(), H5P_DEFAULT());
if( $fileID < 0){
carp("Can't Open New HDF file '$file' for writing\n");
return undef;
}
$self->{accessMode} = 'w';
}
# Record file name, ID
$self->{filename} = $file;
$self->{ID} = $fileID;
$self->{attrIndex} = undef; # Initialize attrIndex
$self->{groupIndex} = undef; # Initialize groupIndex
bless $self, $type;
}
=head2 filename
=for ref
Get the filename for the HDF5 file
B<Usage:>
=for usage
my $filename = $HDFfile->filename;
=cut
sub filename {
my $self = shift;
return $self->{filename};
}
=head2 group
=for ref
Open or create a group in the root "/" group (i.e. top level)
of the HDF5 file.
B<Usage:>
=for usage
$HDFfile->group("groupName");
Returns undef on failure, 1 on success.
=cut
sub group {
my $self = shift;
my $name = $_[0]; # get the group name
my $parentID = $self->{ID};
my $parentName = '';
my $group = new PDL::IO::HDF5::Group( 'name'=> $name, parent => $self,
fileObj => $self );
}
=head2 groups
=for ref
Get a list of groups in the root "/" group (i.e. top level)
of the HDF5 file.
B<Usage:>
=for usage
@groups = $HDFfile->groups;
=cut
sub groups {
my $self = shift;
my @groups = $self->group("/")->groups;
return @groups;
}
=head2 unlink
=for ref
Unlink an object from the root "/" group (i.e. top level)
of the HDF5 file.
B<Usage:>
=for usage
$HDFfile->unlink($name);
=cut
sub unlink {
my $self = shift;
my $name = $_[0];
$self->group("/")->unlink($name);
return 1;
}
=head2 dataset
=for ref
Open or create a dataset in the root "/" group (i.e. top level)
of the HDF5 file.
B<Usage:>
=for usage
$HDFfile->dataset("groupName");
Returns undef on failure, 1 on success.
Note: This is a convienence method that is equivalent to:
$HDFfile->group("/")->dataset("groupName");
=cut
sub dataset {
my $self = shift;
my $name = $_[0]; # get the dataset name
return $self->group("/")->dataset($name);
}
=head2 datasets
=for ref
Get a list of all dataset names in the root "/" group.
B<Usage:>
=for usage
@datasets = $HDF5file->datasets;
Note: This is a convienence method that is equivalent to:
$HDFfile->group("/")->datasets;
=cut
sub datasets{
my $self = shift;
my $name = $_[0]; # get the dataset name
return $self->group("/")->datasets;
}
=head2 attrSet
=for ref
Set the value of an attribute(s) in the root '/' group of the file.
Currently attribute types supported are null-terminated strings and
any PDL type.
B<Usage:>
=for usage
$HDFfile->attrSet( 'attr1' => 'attr1Value',
'attr2' => 'attr2 value',
'attr3' => $pdl,
.
.
.
);
Returns undef on failure, 1 on success.
Note: This is a convienence method that is equivalent to:
$HDFfile->group("/")->attrSet( 'attr1' => 'attr1Value',
'attr2' => 'attr2 value',
'attr3' => $pdl,
.
.
.
);
=cut
sub attrSet {
my $self = shift;
my %attrs = @_; # get atribute hash
return $self->group("/")->attrSet(%attrs);
}
=head2 attrGet
=for ref
Get the value of an attribute(s) in the root '/' group of the file.
Currently the attribute types supported are null-terminated strings
and PDLs.
B<Usage:>
=for usage
@attrValues = $HDFfile->attrGet( 'attr1', 'attr2' );
=cut
sub attrGet {
my $self = shift;
my @attrs = @_; # get atribute hash
return $self->group("/")->attrGet(@attrs);
}
=head2 attrDel
=for ref
Delete attribute(s) in the root "/" group of the file.
B<Usage:>
=for usage
$HDFfile->attrDel( 'attr1',
'attr2',
.
.
.
);
Returns undef on failure, 1 on success.
Note: This is a convienence method that is equivalent to:
$HDFfile->group("/")->attrDel( 'attr1',
'attr2',
.
.
.
);
=cut
sub attrDel {
my $self = shift;
my @attrs = @_; # get atribute names
return $self->group("/")->attrDel(@attrs);
}
=head2 attrs
=for ref
Get a list of all attribute names in the root "/" group of the file.
B<Usage:>
=for usage
@attrs = $HDFfile->attrs;
Note: This is a convienence method that is equivalent to:
$HDFfile->group("/")->attrs
=cut
sub attrs {
my $self = shift;
return $self->group("/")->attrs;
}
=head2 reference
=for ref
Create a reference to part of a dataset in the root "/" group of the file.
B<Usage:>
=for usage
$HDFfile->reference;
Note: This is a convienence method that is equivalent to:
$HDFfile->group("/")->reference($referenceName,$datasetObj,@regionStart,@regionCount);
Create a reference named $referenceName within the root group "/" to a subroutine of
the dataset $datasetObj. The region to be referenced is defined by the @regionStart
and @regionCount arrays.
=cut
sub reference {
my $self = shift;
my $datasetObj = shift;
my $referenceName = shift;
my @regionStart = shift;
my @regionCount = shift;
return $self->group("/")->reference($datasetObj,$referenceName,\@regionStart,\@regionCount);
}
=head2 _buildAttrIndex
=for ref
Internal Method to build the attribute index hash
for the object
B<Usage:>
=for usage
$hdf5obj->_buildAttrIndex;
Output:
Updated attrIndex data member
=cut
sub _buildAttrIndex{
my ($self) = @_;
# Take care of any attributes in the current group
my @attrs = $self->attrs;
my @attrValues = $self->attrGet(@attrs);
my $index = $self->{attrIndex} = {};
my %indexElement; # element of the index for this group
@indexElement{@attrs} = @attrValues;
$index->{'/'} = \%indexElement;
my $topLevelAttrs = { %indexElement };
# Now Do any subgroups:
my @subGroups = $self->groups;
my $subGroup;
foreach $subGroup(@subGroups){
$self->group($subGroup)->_buildAttrIndex($index,$topLevelAttrs);
}
}
=head2 clearAttrIndex
=for ref
Method to clear the attribute index hash
for the object. This is a mostly internal method that is
called whenever some part of the HDF5 file has changed and the
L<attrIndex> index is no longer valid.
B<Usage:>
=for usage
$hdf5obj->clearAttrIndex;
=cut
sub clearAttrIndex{
my $self = shift;
$self->{attrIndex} = undef;
}
=head2 _buildGroupIndex
=for ref
Internal Method to build the groupIndex hash
for the object
B<Usage:>
=for usage
$hdf5obj->_buildGroupIndex(@attrs);
where:
@attrs List of attribute names to build
a group index on.
Output:
Updated groupIndex data member
=cut
sub _buildGroupIndex{
my ($self,@attrs) = @_;
@attrs = sort @attrs; # Sort the attributes so the order won't matter
# Generate attrIndex if not there yet
defined( $self->{attrIndex}) || $self->_buildAttrIndex;
my $attrIndex = $self->{attrIndex};
my $groupIndexElement = {}; # Element of the group index that we will build
my $group;
my $attrIndexElement; # Attr index for the current group
my @attrValues; # attr values corresponding to @attrs for the current group
my $key; # group index key
# Go Thru All Groups
foreach $group(sort keys %$attrIndex){
$attrIndexElement = $attrIndex->{$group};
@attrValues = map defined($_) ? $_ : '_undef_', @$attrIndexElement{@attrs}; # Groups with undefined attr will get a '_undef_' string for the value
# Use multi-dimensional array emulation for the hash
# key here because it should be quicker.
if( defined( $groupIndexElement->{$key = join($;,@attrValues)}) ) { # if already defined, add to the list
push @{$groupIndexElement->{$key}}, $group;
}
else{ # not already defined create new element
$groupIndexElement->{$key} = [ $group ];
}
}
# initialize group index if it doesn't exist.
unless( defined $self->{groupIndex} ){ $self->{groupIndex} = {} };
# Use multi-dimensional array emulation for the hash
# key here because it should be quicker.
$self->{groupIndex}{join($;,@attrs)} = $groupIndexElement;
}
=head2 clearGroupIndex
=for ref
Method to clear the group index hash
for the object. This is a mostly internal method that is
called whenever some part of the HDF5 file has changed and the
L<groupIndex> index is no longer valid.
B<Usage:>
=for usage
$hdf5obj->clearGroupIndex;
=cut
sub clearGroupIndex{
my $self = shift;
$self->{groupIndex} = undef;
}
=head2 getGroupsByAttr
=for ref
Get the group names which attributes match a given set of values. This method
enables database-like queries to be made. I.e. you can get answers to
questions like 'Which groups have attr1 = value1, and attr3 = value2?'.
B<Usage:>
=for usage
@groupNames = $hdf5Obj->getGroupsByAttr( 'attr1' => 'value1',
'attr2' => 'value2' );
=cut
sub getGroupsByAttr{
my $self = shift;
my %attrHash = @_;
my @keys = sort keys %attrHash;
# Use multi-dimensional array emulation for the hash
# key here because it should be quicker.
my $compositeKey = join($;, @keys);
# Generate groupIndex if not there yet
defined( $self->{groupIndex}{$compositeKey} ) || $self->_buildGroupIndex(@keys);
$groupIndex = $self->{groupIndex}{$compositeKey};
my @values = @attrHash{@keys};
my $compositeValues = join($;, @values);
if( defined($groupIndex->{$compositeValues} )){
return @{$groupIndex->{$compositeValues}};
}
else{
return ();
}
}
=head2 allAttrValues
=for ref
Returns information about group attributes defined in the HDF5 datafile.
B<Usage:>
=for usage
# Single Attr Usage. Returns an array of all
# values of attribute 'attrName' in the file.
$hdf5obj->allAttrValues('attrName');
# Multiple Attr Usage. Returns an 2D array of all
# values of attributes 'attr1', 'attr2' in the file.
# Higher-Level
$hdf5obj->allAttrValues('attr1', 'attr2');
=cut
sub allAttrValues{
my $self = shift;
my @attrs = @_;
# Generate attrIndex if not there yet
defined( $self->{attrIndex}) || $self->_buildAttrIndex;
my $attrIndex = $self->{attrIndex};
if( @attrs == 1) { # Single Argument Processing
my $attr = $attrs[0];
my $group;
my @values;
my $grpAttrHash; # attr hash for a particular group
# Go thru each group and look for instances of $attr
foreach $group( keys %$attrIndex){
$grpAttrHash = $attrIndex->{$group};
if( defined($grpAttrHash->{$attr})){
push @values, $grpAttrHash->{$attr};
}
}
return @values;
}
else{ # Multiple argument processing
my $group;
my @values;
my $grpAttrHash; # attr hash for a particular group
my $attr; # individual attr name
my $allAttrSeen; # flag = 0 if we have not seen all of the
# desired attributes in the current group
my $value; # Current value of the @values array that we
# will return
# Go thru each group and look for instances of $attr
foreach $group( keys %$attrIndex){
$grpAttrHash = $attrIndex->{$group};
# Go thru each attribute
$allAttrSeen = 1; # assume we will se all atributes, set to zero if we don't
$value = [];
foreach $attr(@attrs){
if( defined($grpAttrHash->{$attr})){
push @$value, $grpAttrHash->{$attr};
}
else{
$allAttrSeen = 0;
}
}
push @values, $value if $allAttrSeen; #add to values array if we got anything
}
return @values;
}
}
=head2 allAttrNames
=for ref
Returns a sorted list of all the group attribute names that are defined
in the file.
B<Usage:>
=for usage
my @attrNames = $hdf5obj->allAttrNames;
=cut
sub allAttrNames{
my $self = shift;
# Generate attrIndex if not there yet
defined( $self->{attrIndex}) || $self->_buildAttrIndex;
my $attrIndex = $self->{attrIndex};
my $group;
my %names;
my $grpAttrHash; # attr hash for a particular group
my @currentNames;
# Go thru each group and look for instances of $attr
foreach $group( keys %$attrIndex){
$grpAttrHash = $attrIndex->{$group};
@currentNames = keys %$grpAttrHash;
@names{@currentNames} = @currentNames;
}
return sort keys %names;
}
=head2 IDget
=for ref
Returns the HDF5 library ID for this object
B<Usage:>
=for usage
my $ID = $hdf5obj->IDget;
=cut
sub IDget{
my $self = shift;
return $self->{ID};
}
=head2 nameGet
=for ref
Returns the HDF5 Group Name for this object. (Always '/', i.e. the
root group for this top-level object)
B<Usage:>
=for usage
my $name = $hdf5obj->nameGet;
=cut
sub nameGet{
my $self = shift;
return '/';
}
=head2 DESTROY
=for ref
PDL::IO::HDF5 Desctructor - Closes the HDF5 file
B<Usage:>
=for usage
No Usage. Automatically called
=cut
sub DESTROY {
my $self = shift;
if( H5Fclose($self->{ID}) < 0){
warn("Error closing HDF5 file ".$self->{filename}."\n");
}
}
#
# Utility function (Not a Method!!!)
# to pack a perl list into a binary structure
# to be interpereted as a C array of long longs. This code is build
# during the make process to do the Right Thing for big and little
# endian machines
sub packList{
my @list = @_;
if(ref($_[0])){
croak(__PACKAGE__."::packList is not a method!\n");
}
EOPM
# Packing of long int array structure differs depending on
# if the current machine is little or big endian. This logic
# probably won't work for 'weird' byte order machine, but for most
# others (intel, vax, sun, etc) it should be OK.
#
if( $Config{'byteorder'} =~ /^1/){ # little endian
pp_addpm("\t".'@list = map (( $_,0 ), @list); # Intersperse zeros to make 64 bit hsize_t');
}
else{ # Big Endian Machine
pp_addpm("\t".'@list = map (( 0,$_ ), @list); # Intersperse zeros to make 64 bit hsize_t');
}
pp_addpm(<<'EOPM');
my $list = pack ("L*", @list);
return $list;
}
EOPM
pp_addpm(<<'EOPM');
#
# Utility function (Not a Method!!!)
# to unpack a perl list from a binary structure
# that is a C array of long longs. This code is build
# during the make process to do the Right Thing for big and little
# endian machines
sub unpackList{
if(ref($_[0])){
croak(__PACKAGE__."::unpackList is not a method!\n");
}
my ($binaryStruct) = (@_); # input binary structure
my $listLength = length($binaryStruct) / 8; # list returned will be the
# number of bytes in the input struct/8, since
# the output numbers are 64bit.
EOPM
# UnPacking of long int array structure differs depending on
# if the current machine is little or big endian. This logic
# probably won't work for 'weird' byte order machine, but for most
# others (intel, vax, sun, etc) it should be OK.
#
if( $Config{'byteorder'} =~ /^1/){ # little endian
pp_addpm("\t".'my $unpackString = "Lxxxx" x $listLength; # 4 xxxx used to toss upper 32 bits');
}
else{ # Big Endian Machine
pp_addpm("\t".'my $unpackString = "xxxxL" x $listLength; # 4 xxxx used to toss upper 32 bits');
}
pp_addpm(<<'EOPM');
my @list = unpack( $unpackString, $binaryStruct );
return @list;
}
=head1 AUTHORS
John Cerney, j-cerney1@raytheon.com
Andrew Benson, abenson@obs.carnegiescience.edu
=cut
EOPM
# Read in a modified hdf.h file. Define
# a low-level perl interface to hdf from these definitions.
sub create_low_level {
# This file must be modified to only include
# hdf5 3 function definitions.
# Also, all C function declarations must be on one line.
my $defn = shift;
my @lines = split (/\n/, $defn);
foreach (@lines) {
next if (/^\#/); # Skip commented out lines
next if (/^\s*$/); # Skip blank lines
my ($return_type, $func_name, $parms) = /^(\w+\**)\s+(\w+)\s*\((.*?)\)\;/;
my @parms = split (/,/, $parms);
my @vars = ();
my @types = ();
my %output = ();
foreach $parm (@parms) {
my ($varname) = ($parm =~ /(\w+)$/);
$parm =~ s/$varname$//; # parm now contains the full C type
$output{$varname} = 1 if (($parm =~ /\*/) && ($parm !~ /const/));
$parm =~ s/const //; # get rid of 'const' in C type
$parm =~ s/^\s+//;
$parm =~ s/\s+$//; # pare off the variable type from 'parm'
push (@vars, $varname);
push (@types, $parm);
}
my $xsout = '';
$xsout .= "$return_type\n";
$xsout .= "$func_name (" . join (", ", @vars) . ")\n";
for (my $i=0;$i<@vars;$i++) {
$xsout .= "\t$types[$i]\t$vars[$i]\n";
}
$xsout .= "CODE:\n";
$xsout .= "\tRETVAL = $func_name (";
for (my $i=0;$i<@vars;$i++) {
if ($types[$i] =~ /PDL/) {
($type = $types[$i]) =~ s/PDL//; # Get rid of PDL type when writine xs CODE section
$xsout .= "($type)$vars[$i]"."->data,";
} else {
$xsout .= "$vars[$i],";
}
}
chop ($xsout) if( $xsout =~ /\,$/s); # remove last comma, if present
$xsout .= ");\n";
$xsout .= "OUTPUT:\n";
$xsout .= "\tRETVAL\n";
foreach $var (sort keys %output) {
$xsout .= "\t$var\n";
}
$xsout .= "\n\n";
pp_addxs ('', $xsout);
}
}
#-------------------------------------------------------------------------
# Create low level interface from edited hdr5 header file.
#-------------------------------------------------------------------------
create_low_level (<<'EODEF');
# HDF5 Functions we create an interface to using the perl XS code
#
# Note: H5Gget_objinfo arg statbuf has been changed from a H5G_stat_t type to
# a const void type to avoid compilation errors. This function only used
# to determine if a group exists, so the statbuf variable is not used as
# I/O variable as stated in the HDF5 docs.
hid_t H5Fcreate (const char *name, unsigned flags, hid_t create_id, hid_t access_id);
hid_t H5Fopen (const char *name, unsigned flags, hid_t access_id);
herr_t H5Fclose (hid_t file_id);
#
# Dataspace functions
hid_t H5Screate_simple (int rank, const hsize_t * dims, const hsize_t * maxdims);
herr_t H5Sclose(hid_t space_id);
int H5Sget_simple_extent_ndims(hid_t space_id);
int H5Sget_simple_extent_dims(hid_t space_id, hsize_t *dims, hsize_t *maxdims);
herr_t H5Sselect_hyperslab(hid_t space_id, int op, const hsize_t *start, const hsize_t *stride, const hsize_t *count, const hsize_t *block);
herr_t H5Sget_select_bounds(hid_t space_id, hsize_t *start, hsize_t *end);
hid_t H5Pcreate(hid_t cls_id);
herr_t H5Pset_chunk(hid_t plist, int ndims, const hsize_t *dim);
herr_t H5Pclose(hid_t plist);
#
#
# Dataset Functions
hid_t H5Dcreate (hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, hid_t create_plist_id);
hid_t H5Dopen (hid_t loc_id, const char *name);
herr_t H5Dwrite (hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t xfer_plist_id, const char * buf);
herr_t H5Dextend(hid_t dataset_id, const hsize_t *size);
# H5Dread buf type changed from void * to I8 * so that is can be catergorized separately in the
# typemap as a T_PVI traslation
herr_t H5Dread (hid_t dataset_id, hid_t mem_type_id, hid_t mem_space_id, hid_t file_space_id, hid_t xfer_plist_id, I8 * buf);
hid_t H5Dclose (hid_t dataset_id);
hid_t H5Dget_type(hid_t dataset_id);
hid_t H5Dget_space(hid_t dataset_id);
# H5Dvlen_reclaim buf type changed from void * to I8 * so that is can be catergorized separately in the
# typemap as a T_PVI traslation
herr_t H5Dvlen_reclaim(hid_t type_id, hid_t space_id, hid_t plist_id, I8 *buf);
hid_t H5Gcreate(hid_t loc_id, const char *name, size_t size_hint);
hid_t H5Gopen(hid_t loc_id, const char *name);
herr_t H5Gclose(hid_t group_id);
herr_t H5Gget_objinfo(hid_t loc_id, const char *name, hbool_t follow_link, const void *statbuf);
herr_t H5errorOn();
herr_t H5errorOff();
#
# Attribute Functions
hid_t H5Aopen_name(hid_t loc_id, const char *name);
hid_t H5Acreate(hid_t loc_id, const char *name, hid_t type_id, hid_t space_id, hid_t create_plist);
# Note: attrib write only supports char buffer right now
herr_t H5Awrite (hid_t attr_id, hid_t mem_type_id, I8 * buf);
herr_t H5Adelete(hid_t loc_id, const char * name);
herr_t H5Aclose(hid_t attr_id);
int H5Aget_num_attrs(hid_t loc_id);
hid_t H5Aopen_idx(hid_t loc_id, unsigned int idx);
ssize_t H5Aget_name(hid_t attr_id, size_t buf_size, char *buf);
htri_t H5Sis_simple(hid_t space_id);
hid_t H5Aget_space(hid_t attr_id);
hid_t H5Aget_type(hid_t attr_id);
# The Attrib read only supports char buffer right now
herr_t H5Aread(hid_t attr_id, hid_t mem_type_id, I8 *buf);
# Type Functions:
herr_t H5Tset_size(hid_t type_id, size_t size);
herr_t H5Tclose(hid_t type_id);
hid_t H5Tcopy(hid_t type_id);
size_t H5Tget_size(hid_t type_id);
#hid_t H5Tget_super(hid_t type);
htri_t H5Tequal(hid_t type_id1, hid_t type_id2);
H5T_class_t H5Tget_class(hid_t type_id);
htri_t H5Tis_variable_str(hid_t type_id);
# Reference Functions:
H5G_obj_t H5Rget_obj_type(hid_t id, H5R_type_t ref_type, I8 *ref);
hid_t H5Rget_region(hid_t dataset, H5R_type_t ref_type, I8 *ref);
hid_t H5Rdereference(hid_t dataset, H5R_type_t ref_type, I8 *ref);
herr_t H5Rcreate(I8 *ref, hid_t loc_id, const char *name, H5R_type_t ref_type, hid_t space_id);
# Link functions:
herr_t H5Ldelete(hid_t loc_id, const char *name, hid_t lapl_id);
EODEF
# Add Optional HDF Constants to export list.
pp_add_exported('', <<'EOPM');
H5F_ACC_DEBUG
H5F_ACC_EXCL
H5F_ACC_RDONLY
H5F_ACC_RDWR
H5F_ACC_TRUNC
H5P_DEFAULT
H5P_DATASET_CREATE
H5S_ALL
H5S_UNLIMITED
H5T_ALPHA_B16
H5T_ALPHA_B32
H5T_ALPHA_B64
H5T_ALPHA_B8
H5T_ALPHA_F32
H5T_ALPHA_F64
H5T_ALPHA_I16
H5T_ALPHA_I32
H5T_ALPHA_I64
H5T_ALPHA_I8
H5T_ALPHA_U16
H5T_ALPHA_U32
H5T_ALPHA_U64
H5T_ALPHA_U8
H5T_C_S1
H5T_FORTRAN_S1
H5T_IEEE_F32BE
H5T_IEEE_F32LE
H5T_IEEE_F64BE
H5T_IEEE_F64LE
H5T_INTEL_B16
H5T_INTEL_B32
H5T_INTEL_B64
H5T_INTEL_B8
H5T_INTEL_F32
H5T_INTEL_F64
H5T_INTEL_I16
H5T_INTEL_I32
H5T_INTEL_I64
H5T_INTEL_I8
H5T_INTEL_U16
H5T_INTEL_U32
H5T_INTEL_U64
H5T_INTEL_U8
H5T_MIPS_B16
H5T_MIPS_B32
H5T_MIPS_B64
H5T_MIPS_B8
H5T_MIPS_F32
H5T_MIPS_F64
H5T_MIPS_I16
H5T_MIPS_I32
H5T_MIPS_I64
H5T_MIPS_I8
H5T_MIPS_U16
H5T_MIPS_U32
H5T_MIPS_U64
H5T_MIPS_U8
H5T_NATIVE_B16
H5T_NATIVE_B32
H5T_NATIVE_B64
H5T_NATIVE_B8
H5T_NATIVE_CHAR
H5T_NATIVE_DOUBLE
H5T_NATIVE_FLOAT
H5T_NATIVE_HBOOL
H5T_NATIVE_HERR
H5T_NATIVE_HSIZE
H5T_NATIVE_HSSIZE
H5T_NATIVE_INT
H5T_NATIVE_INT16
H5T_NATIVE_INT32
H5T_NATIVE_INT64
H5T_NATIVE_INT8
H5T_NATIVE_INT_FAST16
H5T_NATIVE_INT_FAST32
H5T_NATIVE_INT_FAST64
H5T_NATIVE_INT_FAST8
H5T_NATIVE_INT_LEAST16
H5T_NATIVE_INT_LEAST32
H5T_NATIVE_INT_LEAST64
H5T_NATIVE_INT_LEAST8
H5T_NATIVE_LDOUBLE
H5T_NATIVE_LLONG
H5T_NATIVE_LONG
H5T_NATIVE_OPAQUE
H5T_NATIVE_SCHAR
H5T_NATIVE_SHORT
H5T_NATIVE_UCHAR
H5T_NATIVE_UINT
H5T_NATIVE_UINT16
H5T_NATIVE_UINT32
H5T_NATIVE_UINT64
H5T_NATIVE_UINT8
H5T_NATIVE_UINT_FAST16
H5T_NATIVE_UINT_FAST32
H5T_NATIVE_UINT_FAST64
H5T_NATIVE_UINT_FAST8
H5T_NATIVE_UINT_LEAST16
H5T_NATIVE_UINT_LEAST32
H5T_NATIVE_UINT_LEAST64
H5T_NATIVE_UINT_LEAST8
H5T_NATIVE_ULLONG
H5T_NATIVE_ULONG
H5T_NATIVE_USHORT
H5T_STD_B16BE
H5T_STD_B16LE
H5T_STD_B32BE
H5T_STD_B32LE
H5T_STD_B64BE
H5T_STD_B64LE
H5T_STD_B8BE
H5T_STD_B8LE
H5T_STD_I16BE
H5T_STD_I16LE
H5T_STD_I32BE
H5T_STD_I32LE
H5T_STD_I64BE
H5T_STD_I64LE
H5T_STD_I8BE
H5T_STD_I8LE
H5T_STD_REF_DSETREG
H5T_STD_REF_OBJ
H5T_STD_U16BE
H5T_STD_U16LE
H5T_STD_U32BE
H5T_STD_U32LE
H5T_STD_U64BE
H5T_STD_U64LE
H5T_STD_U8BE
H5T_STD_U8LE
H5T_STRING
H5T_UNIX_D32BE
H5T_UNIX_D32LE
H5T_UNIX_D64BE
H5T_UNIX_D64LE
H5T_REFERENCE
H5R_DATASET_REGION
EOPM
###############################################################
# XS Code that implements self-contained turn-on/off for
# the h5 library error reporting. We can turn error reporting
# selectively on and off to keep the library from complaining
# when we are doing things like checking to see if a particular
# group name exists.
pp_addhdr(<<'EOXS');
/* ###############################################################
#
# H5 Library error reporting turn-on/off functions
#
#
*/
herr_t
H5errorOff()
{
return H5Eset_auto(NULL, NULL );
}
herr_t
H5errorOn()
{
return H5Eset_auto((herr_t(*)(void*))H5Eprint, stderr );
}
/* ###############################################################
#
# Operator Interation Functions (Supplied to and called by 'H5Giterate')
# used to get the number of datasets in a group,
# and the names of the dataset in the group.
#
#
*/
/*
* Operator function to get number of datasets
*/
herr_t incIfDset(hid_t loc_id, const char *name, void *opdata)
{
H5G_stat_t statbuf;
unsigned int * dsetCount;
dsetCount = (unsigned int *) opdata;
/*
* Get type of the object and increment *dsetCount
* if it is a dataset
* The name of the object is passed to this function by
* the Library. Some magic :-)
*/
H5Gget_objinfo(loc_id, name, FALSE, &statbuf);
if( statbuf.type == H5G_DATASET){
(*dsetCount)++;
}
return 0;
}
/*
* Operator function to fill up char array of dataset names
*
* opdata is a pointer to an Array of strings (i.e. 2D char array)
*/
herr_t getName_if_Dset(hid_t loc_id, const char *name, void *opdata)
{
H5G_stat_t statbuf;
char ** datasetName;
char *** tempptr;
tempptr = (char ***) opdata;
datasetName = *tempptr;
/*
* Get type of the object.
* If it is a dataset, get allocate space for it at *datasetName
* Increment *tempptr so we will be looking at the next name space when
* this function is called again.
*
* Note: The calling function must take care of freeing memory allocateed
*
*/
H5Gget_objinfo(loc_id, name, FALSE, &statbuf);
if( statbuf.type == H5G_DATASET){
*datasetName = (char *) malloc( (strlen(name)+1) * sizeof(char));
if( *datasetName == NULL){
printf("PDL::IO::HDF5; Out of Memory in getName_if_Dset\n");
exit(1);
}
strcpy(*datasetName,name);
(*tempptr)++;
}
return 0;
}
/*
* Operator function to get number of groups in a particular location
*/
herr_t incIfGroup(hid_t loc_id, const char *name, void *opdata)
{
H5G_stat_t statbuf;
unsigned int * groupCount;
groupCount = (unsigned int *) opdata;
/*
* Get type of the object and increment *groupCount
* if it is a group
* The name of the object is passed to this function by
* the Library. Some magic :-)
*/
H5Gget_objinfo(loc_id, name, FALSE, &statbuf);
if( statbuf.type == H5G_GROUP){
(*groupCount)++;
}
return 0;
}
/*
* Operator function to fill up char array of group names
*
* opdata is a pointer to an Array of strings (i.e. 2D char array)
*/
herr_t getName_if_Group(hid_t loc_id, const char *name, void *opdata)
{
H5G_stat_t statbuf;
char ** groupName;
char *** tempptr;
tempptr = (char ***) opdata;
groupName = *tempptr;
/*
* Get type of the object.
* If it is a group, get allocate space for it at *groupName
* Increment *tempptr so we will be looking at the next name space when
* this function is called again.
*
* Note: The calling function must take care of freeing memory allocateed
*
*/
H5Gget_objinfo(loc_id, name, FALSE, &statbuf);
if( statbuf.type == H5G_GROUP){
*groupName = (char *) malloc( (strlen(name)+1) * sizeof(char));
if( *groupName == NULL){
printf("PDL::IO::HDF5; Out of Memory in getName_if_Group\n");
exit(1);
}
strcpy(*groupName,name);
(*tempptr)++;
}
return 0;
}
EOXS
###############################################################
# XS Code that implements the HDF constants
# Using the AUTOLOAD routine, any calls to hdf5 constants, like
# H5F_ACC_RDONLY will call the 'constant' routine here and return
# the value of the #defined'ed H5F_ACC_RDONLY
pp_addhdr(<<'EOXS');
/* ###############################################################
#
# Functions to handle interfacing HDF5 constants with perl
#
# This originally generated using h2xs and manually editing
#
*/
static int
not_here(s)
char *s;
{
croak("%s not implemented on this architecture", s);
return -1;
}
hid_t
constant(name, arg)
char *name;
int arg;
{
errno = 0;
switch (*name) {
case 'A':
break;
case 'B':
break;
case 'C':
break;
case 'D':
break;
case 'E':
break;
case 'F':
break;
case 'G':
break;
case 'H':
if (strEQ(name, "H5F_ACC_DEBUG"))
#ifdef H5F_ACC_DEBUG
return H5F_ACC_DEBUG;
#else
goto not_there;
#endif
if (strEQ(name, "H5F_ACC_EXCL"))
#ifdef H5F_ACC_EXCL
return H5F_ACC_EXCL;
#else
goto not_there;
#endif
if (strEQ(name, "H5F_ACC_RDONLY"))
#ifdef H5F_ACC_RDONLY
return H5F_ACC_RDONLY;
#else
goto not_there;
#endif
if (strEQ(name, "H5F_ACC_RDWR"))
#ifdef H5F_ACC_RDWR
return H5F_ACC_RDWR;
#else
goto not_there;
#endif
if (strEQ(name, "H5F_ACC_TRUNC"))
#ifdef H5F_ACC_TRUNC
return H5F_ACC_TRUNC;
#else
goto not_there;
#endif
if (strEQ(name, "H5P_DEFAULT"))
#ifdef H5P_DEFAULT
return H5P_DEFAULT;
#else
goto not_there;
#endif
if (strEQ(name, "H5P_DATASET_CREATE"))
#ifdef H5P_DATASET_CREATE
return H5P_DATASET_CREATE;
#else
goto not_there;
#endif
if (strEQ(name, "H5S_ALL"))
#ifdef H5S_ALL
return H5S_ALL;
#else
goto not_there;
#endif
if (strEQ(name, "H5S_UNLIMITED"))
#ifdef H5S_UNLIMITED
return H5S_UNLIMITED;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_ALPHA_B16"))
#ifdef H5T_ALPHA_B16
return H5T_ALPHA_B16;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_ALPHA_B32"))
#ifdef H5T_ALPHA_B32
return H5T_ALPHA_B32;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_ALPHA_B64"))
#ifdef H5T_ALPHA_B64
return H5T_ALPHA_B64;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_ALPHA_B8"))
#ifdef H5T_ALPHA_B8
return H5T_ALPHA_B8;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_ALPHA_F32"))
#ifdef H5T_ALPHA_F32
return H5T_ALPHA_F32;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_ALPHA_F64"))
#ifdef H5T_ALPHA_F64
return H5T_ALPHA_F64;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_ALPHA_I16"))
#ifdef H5T_ALPHA_I16
return H5T_ALPHA_I16;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_ALPHA_I32"))
#ifdef H5T_ALPHA_I32
return H5T_ALPHA_I32;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_ALPHA_I64"))
#ifdef H5T_ALPHA_I64
return H5T_ALPHA_I64;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_ALPHA_I8"))
#ifdef H5T_ALPHA_I8
return H5T_ALPHA_I8;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_ALPHA_U16"))
#ifdef H5T_ALPHA_U16
return H5T_ALPHA_U16;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_ALPHA_U32"))
#ifdef H5T_ALPHA_U32
return H5T_ALPHA_U32;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_ALPHA_U64"))
#ifdef H5T_ALPHA_U64
return H5T_ALPHA_U64;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_ALPHA_U8"))
#ifdef H5T_ALPHA_U8
return H5T_ALPHA_U8;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_C_S1"))
#ifdef H5T_C_S1
return H5T_C_S1;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_FORTRAN_S1"))
#ifdef H5T_FORTRAN_S1
return H5T_FORTRAN_S1;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_IEEE_F32BE"))
#ifdef H5T_IEEE_F32BE
return H5T_IEEE_F32BE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_IEEE_F32LE"))
#ifdef H5T_IEEE_F32LE
return H5T_IEEE_F32LE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_IEEE_F64BE"))
#ifdef H5T_IEEE_F64BE
return H5T_IEEE_F64BE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_IEEE_F64LE"))
#ifdef H5T_IEEE_F64LE
return H5T_IEEE_F64LE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_INTEL_B16"))
#ifdef H5T_INTEL_B16
return H5T_INTEL_B16;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_INTEL_B32"))
#ifdef H5T_INTEL_B32
return H5T_INTEL_B32;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_INTEL_B64"))
#ifdef H5T_INTEL_B64
return H5T_INTEL_B64;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_INTEL_B8"))
#ifdef H5T_INTEL_B8
return H5T_INTEL_B8;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_INTEL_F32"))
#ifdef H5T_INTEL_F32
return H5T_INTEL_F32;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_INTEL_F64"))
#ifdef H5T_INTEL_F64
return H5T_INTEL_F64;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_INTEL_I16"))
#ifdef H5T_INTEL_I16
return H5T_INTEL_I16;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_INTEL_I32"))
#ifdef H5T_INTEL_I32
return H5T_INTEL_I32;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_INTEL_I64"))
#ifdef H5T_INTEL_I64
return H5T_INTEL_I64;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_INTEL_I8"))
#ifdef H5T_INTEL_I8
return H5T_INTEL_I8;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_INTEL_U16"))
#ifdef H5T_INTEL_U16
return H5T_INTEL_U16;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_INTEL_U32"))
#ifdef H5T_INTEL_U32
return H5T_INTEL_U32;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_INTEL_U64"))
#ifdef H5T_INTEL_U64
return H5T_INTEL_U64;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_INTEL_U8"))
#ifdef H5T_INTEL_U8
return H5T_INTEL_U8;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_MIPS_B16"))
#ifdef H5T_MIPS_B16
return H5T_MIPS_B16;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_MIPS_B32"))
#ifdef H5T_MIPS_B32
return H5T_MIPS_B32;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_MIPS_B64"))
#ifdef H5T_MIPS_B64
return H5T_MIPS_B64;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_MIPS_B8"))
#ifdef H5T_MIPS_B8
return H5T_MIPS_B8;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_MIPS_F32"))
#ifdef H5T_MIPS_F32
return H5T_MIPS_F32;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_MIPS_F64"))
#ifdef H5T_MIPS_F64
return H5T_MIPS_F64;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_MIPS_I16"))
#ifdef H5T_MIPS_I16
return H5T_MIPS_I16;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_MIPS_I32"))
#ifdef H5T_MIPS_I32
return H5T_MIPS_I32;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_MIPS_I64"))
#ifdef H5T_MIPS_I64
return H5T_MIPS_I64;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_MIPS_I8"))
#ifdef H5T_MIPS_I8
return H5T_MIPS_I8;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_MIPS_U16"))
#ifdef H5T_MIPS_U16
return H5T_MIPS_U16;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_MIPS_U32"))
#ifdef H5T_MIPS_U32
return H5T_MIPS_U32;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_MIPS_U64"))
#ifdef H5T_MIPS_U64
return H5T_MIPS_U64;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_MIPS_U8"))
#ifdef H5T_MIPS_U8
return H5T_MIPS_U8;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_B16"))
#ifdef H5T_NATIVE_B16
return H5T_NATIVE_B16;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_B32"))
#ifdef H5T_NATIVE_B32
return H5T_NATIVE_B32;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_B64"))
#ifdef H5T_NATIVE_B64
return H5T_NATIVE_B64;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_B8"))
#ifdef H5T_NATIVE_B8
return H5T_NATIVE_B8;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_CHAR"))
#ifdef H5T_NATIVE_CHAR
return H5T_NATIVE_CHAR;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_DOUBLE"))
#ifdef H5T_NATIVE_DOUBLE
return H5T_NATIVE_DOUBLE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_FLOAT"))
#ifdef H5T_NATIVE_FLOAT
return H5T_NATIVE_FLOAT;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_HBOOL"))
#ifdef H5T_NATIVE_HBOOL
return H5T_NATIVE_HBOOL;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_HERR"))
#ifdef H5T_NATIVE_HERR
return H5T_NATIVE_HERR;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_HSIZE"))
#ifdef H5T_NATIVE_HSIZE
return H5T_NATIVE_HSIZE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_HSSIZE"))
#ifdef H5T_NATIVE_HSSIZE
return H5T_NATIVE_HSSIZE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_INT"))
#ifdef H5T_NATIVE_INT
return H5T_NATIVE_INT;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_INT16"))
#ifdef H5T_NATIVE_INT16
return H5T_NATIVE_INT16;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_INT32"))
#ifdef H5T_NATIVE_INT32
return H5T_NATIVE_INT32;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_INT64"))
#ifdef H5T_NATIVE_INT64
return H5T_NATIVE_INT64;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_INT8"))
#ifdef H5T_NATIVE_INT8
return H5T_NATIVE_INT8;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_INT_FAST16"))
#ifdef H5T_NATIVE_INT_FAST16
return H5T_NATIVE_INT_FAST16;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_INT_FAST32"))
#ifdef H5T_NATIVE_INT_FAST32
return H5T_NATIVE_INT_FAST32;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_INT_FAST64"))
#ifdef H5T_NATIVE_INT_FAST64
return H5T_NATIVE_INT_FAST64;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_INT_FAST8"))
#ifdef H5T_NATIVE_INT_FAST8
return H5T_NATIVE_INT_FAST8;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_INT_LEAST16"))
#ifdef H5T_NATIVE_INT_LEAST16
return H5T_NATIVE_INT_LEAST16;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_INT_LEAST32"))
#ifdef H5T_NATIVE_INT_LEAST32
return H5T_NATIVE_INT_LEAST32;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_INT_LEAST64"))
#ifdef H5T_NATIVE_INT_LEAST64
return H5T_NATIVE_INT_LEAST64;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_INT_LEAST8"))
#ifdef H5T_NATIVE_INT_LEAST8
return H5T_NATIVE_INT_LEAST8;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_LDOUBLE"))
#ifdef H5T_NATIVE_LDOUBLE
return H5T_NATIVE_LDOUBLE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_LLONG"))
#ifdef H5T_NATIVE_LLONG
return H5T_NATIVE_LLONG;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_LONG"))
#ifdef H5T_NATIVE_LONG
return H5T_NATIVE_LONG;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_OPAQUE"))
#ifdef H5T_NATIVE_OPAQUE
return H5T_NATIVE_OPAQUE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_SCHAR"))
#ifdef H5T_NATIVE_SCHAR
return H5T_NATIVE_SCHAR;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_SHORT"))
#ifdef H5T_NATIVE_SHORT
return H5T_NATIVE_SHORT;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_UCHAR"))
#ifdef H5T_NATIVE_UCHAR
return H5T_NATIVE_UCHAR;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_UINT"))
#ifdef H5T_NATIVE_UINT
return H5T_NATIVE_UINT;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_UINT16"))
#ifdef H5T_NATIVE_UINT16
return H5T_NATIVE_UINT16;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_UINT32"))
#ifdef H5T_NATIVE_UINT32
return H5T_NATIVE_UINT32;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_UINT64"))
#ifdef H5T_NATIVE_UINT64
return H5T_NATIVE_UINT64;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_UINT8"))
#ifdef H5T_NATIVE_UINT8
return H5T_NATIVE_UINT8;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_UINT_FAST16"))
#ifdef H5T_NATIVE_UINT_FAST16
return H5T_NATIVE_UINT_FAST16;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_UINT_FAST32"))
#ifdef H5T_NATIVE_UINT_FAST32
return H5T_NATIVE_UINT_FAST32;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_UINT_FAST64"))
#ifdef H5T_NATIVE_UINT_FAST64
return H5T_NATIVE_UINT_FAST64;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_UINT_FAST8"))
#ifdef H5T_NATIVE_UINT_FAST8
return H5T_NATIVE_UINT_FAST8;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_UINT_LEAST16"))
#ifdef H5T_NATIVE_UINT_LEAST16
return H5T_NATIVE_UINT_LEAST16;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_UINT_LEAST32"))
#ifdef H5T_NATIVE_UINT_LEAST32
return H5T_NATIVE_UINT_LEAST32;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_UINT_LEAST64"))
#ifdef H5T_NATIVE_UINT_LEAST64
return H5T_NATIVE_UINT_LEAST64;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_UINT_LEAST8"))
#ifdef H5T_NATIVE_UINT_LEAST8
return H5T_NATIVE_UINT_LEAST8;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_ULLONG"))
#ifdef H5T_NATIVE_ULLONG
return H5T_NATIVE_ULLONG;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_ULONG"))
#ifdef H5T_NATIVE_ULONG
return H5T_NATIVE_ULONG;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_NATIVE_USHORT"))
#ifdef H5T_NATIVE_USHORT
return H5T_NATIVE_USHORT;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STRING"))
return H5T_STRING; /* This was manually enter to get the enumerated type */
if (strEQ(name, "H5T_STD_B16BE"))
#ifdef H5T_STD_B16BE
return H5T_STD_B16BE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_B16LE"))
#ifdef H5T_STD_B16LE
return H5T_STD_B16LE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_B32BE"))
#ifdef H5T_STD_B32BE
return H5T_STD_B32BE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_B32LE"))
#ifdef H5T_STD_B32LE
return H5T_STD_B32LE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_B64BE"))
#ifdef H5T_STD_B64BE
return H5T_STD_B64BE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_B64LE"))
#ifdef H5T_STD_B64LE
return H5T_STD_B64LE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_B8BE"))
#ifdef H5T_STD_B8BE
return H5T_STD_B8BE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_B8LE"))
#ifdef H5T_STD_B8LE
return H5T_STD_B8LE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_I16BE"))
#ifdef H5T_STD_I16BE
return H5T_STD_I16BE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_I16LE"))
#ifdef H5T_STD_I16LE
return H5T_STD_I16LE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_I32BE"))
#ifdef H5T_STD_I32BE
return H5T_STD_I32BE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_I32LE"))
#ifdef H5T_STD_I32LE
return H5T_STD_I32LE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_I64BE"))
#ifdef H5T_STD_I64BE
return H5T_STD_I64BE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_I64LE"))
#ifdef H5T_STD_I64LE
return H5T_STD_I64LE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_I8BE"))
#ifdef H5T_STD_I8BE
return H5T_STD_I8BE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_I8LE"))
#ifdef H5T_STD_I8LE
return H5T_STD_I8LE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_REF_DSETREG"))
#ifdef H5T_STD_REF_DSETREG
return H5T_STD_REF_DSETREG;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_REF_OBJ"))
#ifdef H5T_STD_REF_OBJ
return H5T_STD_REF_OBJ;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_U16BE"))
#ifdef H5T_STD_U16BE
return H5T_STD_U16BE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_U16LE"))
#ifdef H5T_STD_U16LE
return H5T_STD_U16LE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_U32BE"))
#ifdef H5T_STD_U32BE
return H5T_STD_U32BE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_U32LE"))
#ifdef H5T_STD_U32LE
return H5T_STD_U32LE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_U64BE"))
#ifdef H5T_STD_U64BE
return H5T_STD_U64BE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_U64LE"))
#ifdef H5T_STD_U64LE
return H5T_STD_U64LE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_U8BE"))
#ifdef H5T_STD_U8BE
return H5T_STD_U8BE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_STD_U8LE"))
#ifdef H5T_STD_U8LE
return H5T_STD_U8LE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_UNIX_D32BE"))
#ifdef H5T_UNIX_D32BE
return H5T_UNIX_D32BE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_UNIX_D32LE"))
#ifdef H5T_UNIX_D32LE
return H5T_UNIX_D32LE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_UNIX_D64BE"))
#ifdef H5T_UNIX_D64BE
return H5T_UNIX_D64BE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_UNIX_D64LE"))
#ifdef H5T_UNIX_D64LE
return H5T_UNIX_D64LE;
#else
goto not_there;
#endif
if (strEQ(name, "H5T_REFERENCE"))
return H5T_REFERENCE; /* This was manually enter to get the enumerated type */
if (strEQ(name, "H5R_DATASET_REGION"))
return H5R_DATASET_REGION; /* This was manually enter to get the enumerated type */
break;
case 'I':
break;
case 'J':
break;
case 'K':
break;
case 'L':
break;
case 'M':
break;
case 'N':
break;
case 'O':
break;
case 'P':
break;
case 'Q':
break;
case 'R':
break;
case 'S':
break;
case 'T':
break;
case 'U':
break;
case 'V':
break;
case 'W':
break;
case 'X':
break;
case 'Y':
break;
case 'Z':
break;
}
errno = EINVAL;
return 0;
not_there:
errno = ENOENT;
return 0;
}
/* ############################################################# */
EOXS
pp_addxs('',<<'EOXS');
hid_t
constant(name,arg)
char * name
int arg
EOXS
############### Add Autoload Routine for the hdf5 constants ##########
pp_addpm( {At => Top}, <<'EOPM');
use PDL::Lite;
use PDL::Char;
# Require needed here becuase dataset uses some of the XS
# calls that are defined in PDL::IO::HDF5 (like PDL::IO::HDF5::H5T_NATIVE_CHAR() )
# Doing a 'use' would make use of the calls before they are defined.
#
require PDL::IO::HDF5::Group;
require PDL::IO::HDF5::Dataset;
use Carp;
sub AUTOLOAD {
# This AUTOLOAD is used to 'autoload' constants from the constant()
# XS function. If a constant is not found then control is passed
# to the AUTOLOAD in AutoLoader.
my $constname;
($constname = $AUTOLOAD) =~ s/.*:://;
croak "& not defined" if $constname eq 'constant';
my $val = constant($constname, @_ ? $_[0] : 0);
if ($! != 0) {
if ($! =~ /Invalid/) {
$AutoLoader::AUTOLOAD = $AUTOLOAD;
goto &AutoLoader::AUTOLOAD;
}
else {
croak "Your vendor has not defined hdf5 macro $constname";
}
}
*$AUTOLOAD = sub { $val };
goto &$AUTOLOAD;
}
EOPM
# Code that implements the dataset count and dataset name functions
pp_addxs('',<<'EOXS');
# Code to get the number of datasets in a group
int
H5GgetDatasetCount( groupID, groupName )
hid_t groupID
char * groupName
CODE:
int dsetCount = 0;
H5Giterate(groupID, groupName, NULL, incIfDset, &dsetCount);
RETVAL = dsetCount;
OUTPUT:
RETVAL
# Code to get the names of the datasets in a group
void
H5GgetDatasetNames( groupID, groupName )
hid_t groupID
char * groupName
PREINIT:
int dsetCount = 0;
char ** datasetNames; /* Array of dataset names */
char ** datasetPtr; /* temp pointer to datasetNames */
int i; /* Index variable */
PPCODE:
/* Get the number of datasets */
H5Giterate(groupID, groupName, NULL, incIfDset, &dsetCount);
if( dsetCount > 0){ /* Datasets found */
/* Allocate Space for array of strings */
datasetNames = (char **) malloc( dsetCount * sizeof(char *));
if( datasetNames == NULL){
printf("PDL::IO::HDF5; out of Memory in H5GgetDatasetNames\n");
exit(1);
}
datasetPtr = datasetNames;
H5Giterate(groupID, groupName, NULL, getName_if_Dset, &datasetPtr);
EXTEND(SP, dsetCount); /* Make room for results on the return stack */
for( i = 0; i< dsetCount; i++){ /* Push Names onto return stack */
/* printf("Name found = '%s'\n",datasetNames[i]); */
PUSHs(sv_2mortal(newSVpv(datasetNames[i],0)));
free(datasetNames[i]); /* Release Memory */
}
free(datasetNames);
}
# Code to get the number of groups in a group/file
int
H5GgetGroupCount( groupID, groupName )
hid_t groupID
char * groupName
CODE:
int groupCount = 0;
H5Giterate(groupID, groupName, NULL, incIfGroup, &groupCount);
RETVAL = groupCount;
OUTPUT:
RETVAL
# Code to get the names of the groups in a group/file
void
H5GgetGroupNames( groupID, groupName )
hid_t groupID
char * groupName
PREINIT:
int groupCount = 0;
char ** groupNames; /* Array of group names */
char ** groupPtr; /* temp pointer to groupnames */
int i; /* Index variable */
PPCODE:
/* Get the number of datasets */
H5Giterate(groupID, groupName, NULL, incIfGroup, &groupCount);
if( groupCount > 0){ /* Groups found */
/* Allocate Space for array of strings */
groupNames = (char **) malloc( groupCount * sizeof(char *));
if( groupNames == NULL){
printf("PDL::IO::HDF5; out of Memory in H5GgetGroupNames\n");
exit(1);
}
groupPtr = groupNames;
H5Giterate(groupID, groupName, NULL, getName_if_Group, &groupPtr);
EXTEND(SP, groupCount); /* Make room for results on the return stack */
for( i = 0; i< groupCount; i++){ /* Push Names onto return stack */
/* printf("Name found = '%s'\n",datasetNames[i]); */
PUSHs(sv_2mortal(newSVpv(groupNames[i],0)));
free(groupNames[i]); /* Release Memory */
}
free(groupNames);
}
# Code to get the maximum length of strings in a ragged character array
int
findMaxVarLenSize( buf, numelem )
I8 * buf
int numelem
CODE:
int i;
int maxStrSize;
int len;
char** rdata;
/* Convert input generic pointer to character array */
rdata = (char **) buf;
/* Find max string length */
maxStrSize = 0;
for(i=0; i<numelem; i++) {
if( rdata[i] ){ /* Ignore null entries */
/* printf("String %d = '%s'\n", i, rdata[i]); */
len = strlen(rdata[i]);
if( len > maxStrSize ) maxStrSize = len;
}
} /* end for */
RETVAL = maxStrSize;
OUTPUT:
RETVAL
# Function to copy the variable length strings from an input buffer varlenbuff to a supplied
# fixed-length string buffer fixedbuf.
# Number of elements (numelem) and maximum length of any variable length string (maxVarlensize)
# must be supplied.
# Output is the number of elements converted
int
copyVarLenToFixed( varlenbuff, fixedbuf, numelem, maxVarlensize )
I8 * varlenbuff
I8 * fixedbuf
int numelem
int maxVarlensize
CODE:
int fixlenbufferInc; /* size of strings, including the null byte */
int i;
char** rdata;
char* tempPtr;
fixlenbufferInc = maxVarlensize + 1; /* size of strings, including the null byte */
/* Convert input generic pointer to character array */
rdata = (char **) varlenbuff;
tempPtr = (char*) fixedbuf;
/* Copy variable length strings to fixed length strings */
for(i=0; i<numelem; i++, tempPtr += fixlenbufferInc ) {
if( rdata[i] ){ /* Only copy non-null strings */
strncpy(tempPtr, rdata[i], fixlenbufferInc);
}
else{ /* Null Strings: Copy as zero length */
strncpy(tempPtr, "", fixlenbufferInc);
}
}
RETVAL = numelem;
OUTPUT:
RETVAL
# Code size of a pointer for the current platform
# This should return 4 on 32bit machines and 8 on 64bit machines
int
bufPtrSize()
CODE:
RETVAL = sizeof(void *);
OUTPUT:
RETVAL
# Sub to add the H5T_VARIABLE constant
# This is added manually here, rather than regenerate the constant function above
hid_t
H5T_VARIABLE()
CODE:
RETVAL = H5T_VARIABLE;
OUTPUT:
RETVAL
EOXS
# Don't import anything from core but barf
# (Don't wan't to pollute our namespace)
pp_core_importList(' qw/ barf/');
# set to not export anything. (This is a OO package, it doesn't need to export any methods.)
pp_export_nothing;
pp_done();
|