1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright 1993, University Corporation for Atmospheric Research *
* See netcdf/COPYRIGHT file for copying and redistribution conditions. *
* *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF. The full HDF copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at *
* http://hdfgroup.org/products/hdf4/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* $Id: cdf.c 6032 2014-01-17 18:13:52Z acheng $ */
#include "local_nc.h"
#include "alloc.h"
#ifdef HDF
#include "hfile.h"
extern intn hdf_xdr_cdf
PROTO((XDR *xdrs, NC**handlep));
/* A couple of local prototypes to HDF section*/
intn hdf_cdf_clobber(NC *handle);
intn hdf_close(NC *handle);
static intn
hdf_num_attrs(NC *handle,/* IN: handle to SDS */
int32 vg /* IN: ref of top Vgroup */);
#endif /* HDF */
static bool_t NC_xdr_cdf(XDR *xdrs, NC **handlep);
static int NC_free_xcdf(NC *);
/* hmm we write the NDG out always for now */
#define WRITE_NDG 1
/* Debugging: define for each function you want debugging printfs */
/* #define HDF_READ_VARS
#define HDF_READ_ATTRS
#define HDF_NUM_ATTRS
#define HDF_XDR_CDF
#define HDF_VG_CLOBBER
#define HDF_CDF_CLOBBER
#define HDF_CLOSE */
/*
* Free the resources that xdr_cdf allocates
*
* NOTE: Modified to return SUCCEED / FAIL and to catch errors
* -GV 9/16/97
*/
static int
NC_free_xcdf(handle)
NC *handle ;
{
int ret_value = SUCCEED;
if(handle != NULL)
{
if (NC_free_array(handle->dims) == FAIL)
{
ret_value = FAIL;
goto done;
}
if (NC_free_array(handle->attrs) == FAIL)
{
ret_value = FAIL;
goto done;
}
if (NC_free_array(handle->vars) ==FAIL)
{
ret_value = FAIL;
goto done;
}
}
done:
if (ret_value == FAIL)
{ /* Failure cleanup */
}
/* Normal cleanup */
return ret_value;
}
/*
* NOTE: Modified to return SUCCEED / FAIL and to catch errors
* -GV 9/16/97
*/
int
NC_free_cdf(handle)
NC *handle ;
{
int ret_value = SUCCEED;
if(handle != NULL)
{
if (NC_free_xcdf(handle) == FAIL)
{
ret_value = FAIL;
goto done;
}
/* destroy xdr struct */
xdr_destroy(handle->xdrs);
Free(handle->xdrs);
#ifdef HDF
if(handle->file_type == HDF_FILE)
{
if (Vend(handle->hdf_file) == FAIL)
{
ret_value = FAIL;
goto done;
}
if (Hclose(handle->hdf_file) == FAIL)
{
ret_value = FAIL;
goto done;
}
}
#endif /* HDF */
Free(handle);
}
done:
if (ret_value == FAIL)
{ /* Failure cleanup */
}
/* Normal cleanup */
return ret_value;
}
#ifdef HDF
/******************************************************************************/
/*
From NASA CDF Source
*/
#define V2_MAGIC_NUMBER 0x0000FFFF /* Written twice at the beginning of file */
#define V2_MAGIC_OFFSET 0
/* -------------------------------- HDiscdf -------------------------------- */
/*
Return TRUE/FALSE depending on if the given file is a NASA CDF file
*/
intn
HDiscdf(filename)
const char * filename;
{
static const char *FUNC = "HDiscdf";
hdf_file_t fp;
uint8 b[4];
uint8 * bb = NULL;
int32 magic_num;
intn ret_value = TRUE;
fp = (hdf_file_t)HI_OPEN(filename, DFACC_READ);
if (OPENERR(fp))
{
ret_value = FALSE;
goto done;
}
else
{
if(HI_SEEK(fp, V2_MAGIC_OFFSET) == FAIL)
{
HERROR(DFE_SEEKERROR);
ret_value = FALSE;
goto done;
}
if(HI_READ(fp, b, 4) == FAIL)
{
HERROR(DFE_READERROR);
ret_value = FALSE;
goto done;
}
bb = &b[0];
INT32DECODE(bb, magic_num);
if(magic_num == V2_MAGIC_NUMBER)
ret_value = TRUE;
else
ret_value = FALSE;
HI_CLOSE(fp);
}
done:
if (ret_value == FALSE)
{ /* FALSE cleanup ?*/
}
/* Normal cleanup */
return ret_value;
}
/*
Model after HDiscdf
*/
/* -------------------------------- HDisnetcdf -------------------------------- */
/*
Return TRUE if the given file is a netCDF file, FALSE otherwise.
*/
intn
HDisnetcdf(filename)
const char * filename;
{
static const char *FUNC = "HDisnetcdf";
hdf_file_t fp;
uint8 b[4];
uint8 * bb = NULL;
int32 magic_num;
intn ret_value = TRUE;
fp = (hdf_file_t)HI_OPEN(filename, DFACC_READ);
if (OPENERR(fp))
{
ret_value = FALSE;
goto done;
}
else
{
if(HI_READ(fp, b, 4) == FAIL)
{
HERROR(DFE_READERROR);
HI_CLOSE(fp);
ret_value = FALSE;
goto done;
}
bb = &b[0];
INT32DECODE(bb, magic_num);
if(magic_num == NCMAGIC)
ret_value = TRUE;
else
ret_value = FALSE;
HI_CLOSE(fp);
}
done:
if (ret_value == FALSE)
{ /* FALSE cleanup? */
}
/* Normal cleanup */
return ret_value;
}
/******************************************************************************/
#endif /* HDF */
/*
* NOTE: Cleaned up to catch errors - GV 9/19/97
*/
NC *
NC_new_cdf(name, mode)
const char *name ;
int mode ;
{
#ifdef HDF
int32 hdf_mode = DFACC_RDWR; /* default */
#endif
NC *cdf = NULL;
static const char *FUNC = "NC_new_cdf";
NC *ret_value = NULL;
/* allocate an NC struct */
cdf = (NC *)HDcalloc(1,sizeof(NC)) ;
if( cdf == NULL )
{
nc_serror("NC_new_cdf") ;
ret_value = NULL;
goto done;
}
cdf->flags = mode ;
cdf->xdrs = (XDR *)HDmalloc(sizeof(XDR)) ;
if( cdf->xdrs == NULL)
{
nc_serror("NC_new_cdf: xdrs") ;
ret_value = NULL;
goto done;
} /* else */
#ifdef HDF
/*
* See what type of file we are looking at.
* If we are creating a new file it will be an HDF file
*/
if(mode & NC_CREAT)
{
cdf->file_type = HDF_FILE;
}
else
{
if(Hishdf(name))
cdf->file_type = HDF_FILE;
else if(HDiscdf(name))
cdf->file_type = CDF_FILE;
else if(HDisnetcdf(name))
cdf->file_type = netCDF_FILE;
else
{
ret_value = NULL;
goto done;
}
#ifdef DEBUG
if(cdf->file_type == CDF_FILE)
printf("Yow! found a CDF file\n");
#endif
}
/*
* Set up the XDR functions that some of the netCDF old code uses
*/
switch(cdf->file_type)
{
case HDF_FILE:
hdf_xdrfile_create(cdf->xdrs, mode); /* return type is 'void' */
break;
case netCDF_FILE:
if( NCxdrfile_create( cdf->xdrs, name, mode ) < 0)
{
ret_value = NULL;
goto done;
}
break;
case CDF_FILE:
/* CDF_xdrfile_create(); */
/* try this, I bet it will be sufficient */
hdf_xdrfile_create(cdf->xdrs, mode);
break;
}
#else /* !HDF */
if( NCxdrfile_create( cdf->xdrs, name, mode ) < 0)
{
ret_value = NULL;
goto done;
}
#endif /* !HDF */
cdf->dims = NULL ;
cdf->attrs = NULL ;
cdf->vars = NULL ;
cdf->begin_rec = 0 ;
cdf->recsize = 0 ;
cdf->numrecs = 0 ;
cdf->redefid = -1 ;
#ifdef HDF
/*
* determine the HDF access mode
*/
switch(mode)
{
case NC_CLOBBER :
hdf_mode = DFACC_CLOBBER; break;
case NC_NOCLOBBER :
/* will handle below */
break;
case NC_WRITE :
hdf_mode = DFACC_RDWR; break;
case NC_NOWRITE :
hdf_mode = DFACC_RDONLY; break;
default:
hdf_mode = DFACC_RDWR;
}
/*
* Do file type specific setup
*/
switch(cdf->file_type)
{
case HDF_FILE: /* HDF stuff */
/* see if the file exists */
if(mode == NC_NOCLOBBER)
{
if((int) Hishdf(name))
{ /* Need to free allocated structures.
This will happen on failure cleanup. */
xdr_destroy(cdf->xdrs) ; /* destroy xdr struct first */
ret_value = NULL;
goto done;
}
hdf_mode = DFACC_RDWR;
}
/* open the file */
cdf->hdf_file = (int32) Hopen(name, hdf_mode, 200);
if(cdf->hdf_file == FAIL)
{
ret_value = NULL;
goto done;
}
/* start Vxx access */
if (Vstart(cdf->hdf_file) == FAIL)
{
ret_value = NULL;
goto done;
}
cdf->hdf_mode = hdf_mode;
cdf->vgid = 0; /* invalid ref */
/* copy filename only up to its length instead of FILENAME_MAX as
used to be */
HDstrncpy(cdf->path, name, strlen(name)+1);
break;
case netCDF_FILE:
/* Nothing */
break;
case CDF_FILE:
#ifdef DEBUG
fprintf(stderr, "About to do CDF file set up\n");
#endif
cdf->cdf_fp = (hdf_file_t) HI_OPEN(name, hdf_mode);
if (OPENERR(cdf->cdf_fp))
HRETURN_ERROR(DFE_DENIED,NULL);
break;
}
#endif /* HDF */
/*
* Read in the contents
*/
if(cdf->xdrs->x_op == XDR_DECODE) /* Not NC_CREAT */
{
if(!xdr_cdf(cdf->xdrs, &cdf) )
{ /* free cdf struct. This cleanup is different than
NC_free_xcdf(). */
NC_free_cdf(cdf); /* free memory, close structues,files etc*/
cdf = NULL;
ret_value = NULL ;
goto done;
}
if(NC_computeshapes(cdf) == -1)
{
ret_value = NULL;
goto done;
}
}
ret_value = cdf ;
done:
if (ret_value == NULL)
{ /* Failure cleanup */
if (cdf != NULL)
{ /* handles case other than one for NC_free_cdf().
These routines only free up allocted memory. */
NC_free_xcdf(cdf); /* no point in catching error here */
if (cdf->xdrs != NULL)
Free(cdf->xdrs);
Free(cdf) ;
}
}
/* Normal cleanup */
return ret_value;
}
/*
* Duplicate a description structure.
* Can only be called for 'old' extant on disk, eg, old in DATA mode.
*
* NOTE: Cleaned up to catch errors - GV 9/19/97
*/
NC *
NC_dup_cdf(name, mode, old)
const char *name ;
int mode ;
NC *old ;
{
NC *cdf = NULL;
NC *ret_value = NULL;
cdf = (NC *)HDmalloc(sizeof(NC)) ;
if( cdf == NULL )
{
nc_serror("NC_dup_cdf") ;
ret_value = NULL;
goto done;
}
cdf->flags = old->flags | NC_INDEF ;
cdf->xdrs = (XDR *)HDmalloc(sizeof(XDR)) ;
if( cdf->xdrs == NULL)
{
nc_serror("NC_dup_cdf: xdrs") ;
ret_value = NULL;
goto done;
}
cdf->dims = NULL ;
cdf->attrs = NULL ;
cdf->vars = NULL ;
cdf->begin_rec = 0 ;
cdf->recsize = 0 ;
cdf->numrecs = 0 ;
#ifdef HDF
cdf->file_type = old->file_type;
#endif
if(NCxdrfile_create( cdf->xdrs, name, mode) < 0)
{
ret_value = NULL ;
goto done;
}
old->xdrs->x_op = XDR_DECODE ;
if(!xdr_cdf(old->xdrs, &cdf) )
{
ret_value = NULL;
goto done;
}
if( NC_computeshapes(cdf) == -1)
{
ret_value = NULL;
goto done;
}
ret_value = cdf;
done:
if (ret_value == NULL)
{ /* Failure cleanup */
if (cdf != NULL)
{ /* free up allocated structures */
if (cdf->xdrs != NULL)
Free(cdf->xdrs);
NC_free_xcdf(cdf); /* don't catch error here */
Free(cdf);
}
}
/* Normal cleanup */
return ret_value;
}
int ncinquire(cdfid, ndimsp, nvarsp, nattrsp, xtendimp)
int cdfid ;
int *ndimsp ;
int *nvarsp ;
int *nattrsp ;
int *xtendimp ;
{
NC *handle ;
cdf_routine_name = "ncinquire" ;
handle = NC_check_id(cdfid) ;
if(handle == NULL)
return(-1) ;
if(nvarsp != NULL)
*nvarsp = (handle->vars != NULL) ? handle->vars->count : 0 ;
if(nattrsp != NULL)
*nattrsp = (handle->attrs != NULL) ? handle->attrs->count : 0 ;
if(handle->dims != NULL)
{
NC_dim **dp ;
unsigned ii ;
if(ndimsp != NULL)
*ndimsp = handle->dims->count ;
if(xtendimp != NULL) {
*xtendimp = -1 ;
dp = (NC_dim**)handle->dims->values ;
for(ii = 0 ; ii < handle->dims->count ; ii++, dp++)
{
if((*dp)->size == NC_UNLIMITED)
{
*xtendimp = ii ;
}
}
}
} else {
if(ndimsp != NULL)
*ndimsp = 0 ;
if(xtendimp != NULL)
*xtendimp = -1 ;
}
return(cdfid) ;
}
/*
* NOTE: modfied how errors were caught and reported - GV 9/19/97
*/
bool_t
xdr_cdf(xdrs, handlep)
XDR *xdrs;
NC **handlep;
{
bool_t ret_value = TRUE;
#ifdef HDF
switch((*handlep)->file_type)
{
case HDF_FILE:
if (hdf_xdr_cdf(xdrs, handlep) == FAIL)
ret_value = FALSE;
break;
case netCDF_FILE:
ret_value = NC_xdr_cdf(xdrs, handlep);
break;
case CDF_FILE:
ret_value = nssdc_xdr_cdf(xdrs, handlep);
break;
default:
ret_value = FALSE;
break;
}
#else /* !HDF */
ret_value = NC_xdr_cdf(xdrs, handlep);
#endif /* !HDF */
return ret_value;
}
static bool_t
NC_xdr_cdf(xdrs, handlep)
XDR *xdrs;
NC **handlep;
{
u_long magic;
if( xdrs->x_op == XDR_FREE)
{
NC_free_xcdf(*handlep) ;
return(TRUE) ;
}
if( xdr_getpos(xdrs) != 0)
{
if( !xdr_setpos(xdrs, 0) )
{
nc_serror("Can't set position to begin") ;
return(FALSE) ;
}
}
/* magic number */
if( !xdr_u_long(xdrs, &magic) )
{
if( xdrs->x_op == XDR_DECODE)
{
NCadvise(NC_ENOTNC,
"Not a netcdf file (Can't read magic number)") ;
}
else
{
/* write error */
nc_serror("xdr_cdf: xdr_u_long") ;
}
return(FALSE) ;
}
if( xdrs->x_op == XDR_DECODE && magic != NCMAGIC )
{
if(magic == NCLINKMAGIC)
{
NCadvise(NC_NOERR, "link file not handled yet") ;
return(FALSE) ;
} /* else */
NCadvise(NC_ENOTNC, "Not a netcdf file") ;
return(FALSE) ;
}
if( !xdr_numrecs(xdrs, *handlep))
{
NCadvise(NC_EXDR, "xdr_numrecs") ;
return(FALSE) ;
}
if( !xdr_NC_array(xdrs, &((*handlep)->dims)))
{
NCadvise(NC_EXDR, "xdr_cdf:dims") ;
return(FALSE) ;
}
if( !xdr_NC_array(xdrs, &((*handlep)->attrs)))
{
NCadvise(NC_EXDR, "xdr_cdf:attrs") ;
return(FALSE) ;
}
if( !xdr_NC_array(xdrs, &((*handlep)->vars)))
{
NCadvise(NC_EXDR, "xdr_cdf:vars") ;
return(FALSE) ;
}
return(TRUE) ;
}
#ifdef HDF
/*****************************************************************************
*
* NCSA HDF / netCDF Project
* May, 1993
*
* NCSA HDF / netCDF source code and documentation are in the public domain.
* Specifically, we give to the public domain all rights for future
* licensing of the source code, all resale rights, and all publishing rights.
*
* We ask, but do not require, that the following message be included in all
* derived works:
*
* Portions developed at the National Center for Supercomputing Applications at
* the University of Illinois at Urbana-Champaign. Funding for this project
* has come primarily from the National Science Foundation.
*
* THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
* SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
* WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
*
******************************************************************************
*
* Please report all bugs / comments to hdfhelp@ncsa.uiuc.edu
*
*****************************************************************************/
/* ----------------------------------------------------------------
** Map an NC_<type> to an HDF type
*/
int
hdf_map_type(type)
nc_type type;
{
switch(type)
{
case NC_UNSPECIFIED : /* be like netCDF */
case NC_CHAR :
return DFNT_CHAR;
case NC_BYTE :
return DFNT_INT8;
case NC_SHORT :
return DFNT_INT16;
case NC_LONG :
return DFNT_INT32;
case NC_FLOAT :
return DFNT_FLOAT32;
case NC_DOUBLE :
return DFNT_FLOAT64;
default:
return DFNT_NONE;
}
} /* hdf_map_type */
/* ----------------------------------------------------------------
** UnMap a data type. I.e. go from an HDF type to an NC_<type>
** The HDF type may be in DFNT_NATIVE mode, so only look at the
** bottom bits
*/
nc_type
hdf_unmap_type(type)
int type;
{
switch(type & 0xff)
{
case DFNT_CHAR :
case DFNT_UCHAR :
return NC_CHAR;
case DFNT_INT8 :
case DFNT_UINT8 :
return NC_BYTE;
case DFNT_INT16 :
case DFNT_UINT16 :
return NC_SHORT;
case DFNT_INT32 :
case DFNT_UINT32 :
return NC_LONG;
case DFNT_FLOAT32 :
return NC_FLOAT;
case DFNT_FLOAT64 :
return NC_DOUBLE;
default:
return (nc_type)FAIL; /* need a better legal nc_type value */
}
} /* hdf_unmap_type */
/* -----------------------------------------------------------------
** Given a dimension id number return its hdf_ref number (Vgroup id)
*/
int
hdf_get_ref(handle, i)
NC *handle;
int i;
{
NC_array *tmp = NULL;
NC_dim **d = NULL;
Void *dims = NULL;
tmp = handle->dims;
dims = handle->dims->values;
dims += i * tmp->szof;
d = (NC_dim **) dims;
return (*d)->vgid; /* return ref of vgroup */
} /* get_hdf_ref */
/* ----------------------------------------------------------------
** Given a dimension pointer return the ref of a Vdata which was
** newly created to represent the values the dimension takes on
** If there is a variable with the same name as our dimension then
** the values the variable takes on are the values for the
** 'steps' in the dimension.
** Otherwise, the dimension takes on the values 0..(size -1)
**
** NOTE: This may cause conflicts cuz we may get called before
** the variable's values are set???
**
** NOTE2: Someone should update the comments here. They no longer
** seem valid -GV 9/19/97
*/
int
hdf_create_dim_vdata(xdrs, handle, dim)
XDR *xdrs;
NC *handle;
NC_dim *dim;
{
#ifdef LATER
CONSTR(FUNC,"hdf_create_dim_vdata");
#endif /* LATER */
int found = FALSE;
int ref;
int32 val;
long dsize;
int ret_value = FAIL;
#if DEBUG
fprintf(stderr, "hdf_create_dim_vdata I've been called\n");
fprintf(stderr, "handle->hdf_file = %d\n", handle->hdf_file);
#endif
#if 0
/* look for variable with the given name */
if(handle->vars)
{
dp = (NC_var **) handle->vars->values;
for(ii = 0; ii < handle->vars->count; ii++, dp++)
if(HDstrcmp(dim->name->values, (*dp)->name->values) == 0)
{
/* found it */
found = TRUE;
break;
}
}
#endif
if(found)
{
/* load in the variable's values */
#if DEBUG
fprintf(stderr, "Found real values for dimension %s\n", dim->name->values);
#endif
}
else
{
dsize = 1;
val = (dim->size != NC_UNLIMITED) ? dim->size : (int32)handle->numrecs;
ref = VHstoredata(handle->hdf_file, "Values", (const uint8 *)&val, dsize,
DFNT_INT32, dim->name->values, DIM_VALS01);
if(ref == FAIL)
{
#ifdef DEBUG
fprintf(stderr, "FAILed creating Vdata %s\n", dim->name->values);
#endif
ret_value = FAIL;
goto done;
}
}
#if DEBUG
fprintf(stderr, "Returning vdata pointer %d\n", ref);
#endif
ret_value = ref;
done:
if (ret_value == FAIL)
{ /* Failure cleanup */
}
/* Normal cleanup */
return ret_value;
} /* hdf_create_dim_vdata */
/* ----------------------------------------------------------------
** Given a dimension pointer return the ref of an older version
** dim Vdata which was newly created to represent the values
** the dimension takes on, for backward compatibility.
**
** For DIM_VALS, the values the variable takes on are the values
** for the 'steps' in the dimension.
**
*/
int
hdf_create_compat_dim_vdata(XDR *xdrs,
NC *handle,
NC_dim *dim,
int32 dimval_ver)
{
static const char *FUNC = "hdf_create_compat_dim_vdata";
int i;
int ref;
long dsize;
int32 *val = NULL;
int ret_value = FAIL;
#ifdef DEBUG
fprintf(stderr, "hdf_create_compat_dim_vdata I've been called\n");
fprintf(stderr, "handle->hdf_file = %d\n", handle->hdf_file);
fprintf(stderr, "dim_ver = %d\n", dim_ver);
#endif
if (dimval_ver != DIMVAL_VERSION00)
{
ret_value = FAIL;
goto done;
}
dsize = (dim->size == NC_UNLIMITED)? 1 : dim->size;
if (dsize < 0)
{
ret_value = FAIL;
goto done;
}
/* create a fake one */
#ifdef DEBUG
fprintf(stderr, "Creating fake dim ::::%s::: (%d)\n",
dim->name->values, dsize);
#endif
/* allocate space */
val = (int32 *) HDmalloc(dsize * sizeof(int32));
if(!val)
{
HERROR(DFE_NOSPACE);
ret_value = FAIL;
goto done;
}
/* Shouldn't a check for netCDF file be here before using handle->numrecs?
If the file is an HDF file, vp->numrecs should be used, right?
-BMR (2013-6/24) */
if (dim->size == NC_UNLIMITED)
{
*val = handle->numrecs;
}
else
{
for(i = 0; i < dsize; i++) val[i] = i;
}
ref = VHstoredata(handle->hdf_file, "Values", (const uint8 *)val,
dsize, DFNT_INT32, dim->name->values, DIM_VALS);
if(ref == FAIL)
{
#ifdef DEBUG
fprintf(stderr, "FAILed creating Vdata %s\n", dim->name->values);
#endif
ret_value = FAIL;
goto done;
}
#ifdef DEBUG
fprintf(stderr, "Returning vdata pointer %d\n", ref);
#endif
ret_value = ref;
done:
if (ret_value == FAIL)
{ /* Failure cleanup */
}
/* Normal cleanup */
if (val != NULL)
HDfree(val);
return ret_value;
} /* hdf_create_compat_dim_vdata */
/* ----------------------------------------------------------------
** Write out a vdata representing an attribute
*/
int
hdf_write_attr(xdrs, handle, attr)
XDR *xdrs;
NC *handle;
NC_attr **attr;
{
char *name = NULL;
Void *values = NULL;
int size;
int type;
int order;
int ret_value = SUCCEED;
name = (*attr)->name->values;
values = (*attr)->data->values;
size = (*attr)->data->count;
type = (*attr)->HDFtype;
#if DEBUG
fprintf(stderr, "hdf_write_attr I've been called\n");
fprintf(stderr, "The attribute is called %s\n", name);
fprintf(stderr, "Type = %d (%d) size %d\n", type, (*attr)->HDFtype, size);
fprintf(stderr, "Value: ");
switch(type)
{
case DFNT_CHAR :fprintf(stderr, " (char) %s\n", (char *) values); break;
case DFNT_UINT8 :fprintf(stderr, " (uint8) %d\n", (char *) values); break;
case DFNT_INT8 :fprintf(stderr, " (int8) %d\n", (char *) values); break;
case DFNT_UINT16 :fprintf(stderr, " (uint16) %d\n", (int *) values); break;
case DFNT_INT16 :fprintf(stderr, " (int16) %d\n", (int *) values); break;
case DFNT_UINT32 :fprintf(stderr, " (uint32) %d\n", (int *) values); break;
case DFNT_INT32 :fprintf(stderr, " (int32) %d\n", (int *) values); break;
case DFNT_FLOAT32 :fprintf(stderr, " (float32) %f\n", (float *) values); break;
case DFNT_FLOAT64 :fprintf(stderr, " (float64) %f\n", (double *) values); break;
default:fprintf(stderr, "???\n");
}
#endif
if(type == DFNT_CHAR)
{
order = size;
size = 1;
}
else
{
order = 1;
}
ret_value = VHstoredatam(handle->hdf_file, ATTR_FIELD_NAME,
(unsigned char *) values, size,
type, name, _HDF_ATTRIBUTE, order);
#if DEBUG
fprintf(stderr, "hdf_write_attr returning %d\n", ret_value);
#endif
#ifdef LATER
done:
if (ret_value == FAIL)
{ /* Failure cleanup */
}
/* Normal cleanup */
#endif /* LATER */
return ret_value;
} /* hdf_write_attr */
/* ----------------------------------------------------------------
** Write out a group representing a dimension
*/
int32
hdf_write_dim(XDR *xdrs, NC *handle, NC_dim **dim, int32 cnt)
{
int32 tags[100];
int32 refs[100];
int32 count;
const char *class = NULL;
char name[H4_MAX_NC_NAME] = "";
int32 ret_value = SUCCEED;
#if DEBUG
fprintf(stderr, "hdf_write_dim I've been called\n");
fprintf(stderr, "The name is -- %s -- \n", (*dim)->name->values);
#endif
/*
* Look up to see if there is a variable of the same name
* giving values
*/
count = 0;
tags[count] = DFTAG_VH;
refs[count] = hdf_create_dim_vdata(xdrs, handle, (*dim));
if(refs[count] == FAIL)
{
ret_value = FAIL;
goto done;
}
count++;
/* do we need to create compatible dimension? */
if ((*dim)->dim00_compat)
{
tags[count] = DFTAG_VH;
refs[count] = hdf_create_compat_dim_vdata(xdrs, handle, (*dim), DIMVAL_VERSION00);
if(refs[count] == FAIL)
{
ret_value = FAIL;
goto done;
}
count++;
}
/* check if UNLIMITED dimension */
if((*dim)->size == NC_UNLIMITED)
class = _HDF_UDIMENSION;
else
class = _HDF_DIMENSION;
if(HDstrncmp((*dim)->name->values, "fakeDim", 7) == 0)
sprintf(name, "fakeDim%d", (int)cnt);
else
HDstrcpy(name, (*dim)->name->values);
/* write out the dimension group? */
(*dim)->vgid = VHmakegroup(handle->hdf_file, tags, refs, count,
name, class);
ret_value = (*dim)->vgid; /* ref of vgroup of dimension */
done:
if (ret_value == FAIL)
{ /* Failure cleanup */
}
/* Normal cleanup */
return ret_value;
} /* hdf_write_dim */
/* ----------------------------------------------------------------
** Write out a group representing a variable
** If successfull, return the id of the created Vgroup else
** return NULL
*/
int32
hdf_write_var(xdrs, handle, var)
XDR *xdrs;
NC *handle;
NC_var **var;
{
NC_array * attrs = NULL;
NC_iarray * assoc = NULL;
uint8 ntstring[4];
uint16 ref;
int8 outNT;
uint8 tbuf[2+((H4_MAX_VAR_DIMS+1)*8)]; /* temporary buffer */
int32 tags[H4_MAX_NC_ATTRS + H4_MAX_VAR_DIMS + 2];
int32 refs[H4_MAX_NC_ATTRS + H4_MAX_VAR_DIMS + 10];
uint16 nt_ref, rank;
int32 GroupID, val, vs_id;
uint8 *bufp = NULL;
#ifdef LATER
CONSTR(FUNC,"hdf_write_var");
#endif /* LATER */
int32 ret_value = SUCCEED;
register unsigned i, count;
register Void *attribute = NULL;
count = 0;
assoc = (*var)-> assoc;
attrs = (*var)-> attrs;
#if DEBUG
fprintf(stderr, "hdf_write_var I've been called\n");
fprintf(stderr, "handle->hdf_file = %d\n", handle->hdf_file);
fprintf(stderr, "The name is -- %s -- \n", (*var)->name->values);
if(assoc && assoc->count)
{
fprintf(stderr, "value of assoc %d\n", assoc);
fprintf(stderr, " assoc->count %d\n", assoc->count);
fprintf(stderr, " asc[0] %d asc[1] %d\n", assoc->values[0], assoc->values[1]);
}
#endif
/*
* Get the dimension information
*/
for(i = 0; i < assoc->count; i++)
{
tags[count] = DIM_TAG;
refs[count] = hdf_get_ref(handle, assoc->values[i]);
count++;
}
/*
* Add info for the attributes
*/
if(attrs)
{
attribute = attrs->values;
for(i = 0; i < attrs->count; i++)
{
tags[count] = ATTR_TAG;
refs[count] = hdf_write_attr(xdrs, handle, (NC_attr **)attribute);
if (refs[count] == FAIL)
{
ret_value = FAIL;
goto done;
}
attribute += attrs->szof;
count++;
}
}
/*
* Add info about the type of this variable
*/
if ((*var)->var_type == IS_SDSVAR || (*var)->var_type == IS_CRDVAR)
{
char fields[FIELDNAMELENMAX];
char vsclass[H4_MAX_NC_NAME];
if ((*var)->var_type == IS_SDSVAR)
{
strncpy(fields, "SDS variable", 13);
strncpy(vsclass, _HDF_SDSVAR, 7);
}
else if ((*var)->var_type == IS_CRDVAR)
{
strncpy(fields, "Coordinate variable", 20);
strncpy(vsclass, _HDF_CRDVAR, 9);
}
if ((vs_id = VSattach(handle->hdf_file, -1, "w")) == FAIL)
{
ret_value = FAIL;
goto done;
}
if(VSsetclass(vs_id, vsclass)==FAIL)
{
ret_value = FAIL;
goto done;
}
if ( VSfdefine(vs_id, fields, DFNT_FLOAT32, 1) == FAIL)
{
ret_value = FAIL;
goto done;
}
if ( VSsetfields(vs_id, fields) == FAIL)
{
ret_value = FAIL;
goto done;
}
ref = VSQueryref(vs_id);
if(VSdetach(vs_id)==FAIL)
{
ret_value = FAIL;
goto done;
}
tags[count] = DFTAG_VH;
refs[count] = ref;
count++;
}
/*
* If we already have data written out include that too
* (this might happen after a redef() cuz we will leave
* the data sitting on the disk but clear out all the
* meta-data)
*/
if((*var)->data_ref)
{
tags[count] = (int32) DFTAG_SD;
refs[count] = (*var)->data_ref;
#if DEBUG
fprintf(stderr, " ---- Carrying forward data with ref %d ---- \n", (*var)->data_ref);
#endif
count++;
}
/*
* Write out a number type tag so that we can recover this
* variable's type later on
*
* by default numbers are converted to IEEE otherwise we need to save the
* machine type in the NT object
*/
/* somone unwrap this statement....*/
outNT = ((*var)->HDFtype & DFNT_NATIVE)?
DFKgetPNSC((*var)->HDFtype, DF_MT) : ((*var)->HDFtype & DFNT_LITEND)?
DFNTF_PC : DFNTF_IEEE;
#ifdef NOT_YET
ref = Htagnewref(handle->hdf_file,DFTAG_NT);
#else /* NOT_YET */
ref = Hnewref(handle->hdf_file);
#endif /* NOT_YET */
ntstring[0] = DFNT_VERSION; /* version */
ntstring[1] = (uint8)((*var)->HDFtype & 0xff); /* type */
ntstring[2] = (uint8)((*var)->HDFsize * 8); /* width (in bits) */
ntstring[3] = outNT; /* class: IEEE or machine class */
if(Hputelement(handle->hdf_file, DFTAG_NT, ref, ntstring, (int32) 4) == FAIL)
{
ret_value = FAIL;
goto done;
}
tags[count] = DFTAG_NT;
refs[count] = ref;
nt_ref = (uint16) ref;
count++;
#ifdef WRITE_NDG
/* prepare to start writing ndg */
if ((GroupID = DFdisetup(10)) < 0)
{
ret_value = FAIL;
goto done;
}
/* write SD record */
if((*var)->data_ref)
{
if (DFdiput(GroupID, DFTAG_SD, (uint16) (*var)->data_ref) == FAIL)
{
ret_value = FAIL;
goto done;
}
}
/* write NT tag/ref */
if (DFdiput(GroupID, DFTAG_NT, (uint16) ref) == FAIL)
{
ret_value = FAIL;
goto done;
}
/* put rank & dimensions in buffer */
bufp = tbuf;
rank = assoc->count;
UINT16ENCODE(bufp, rank);
for(i = 0; i < (int)rank; i++)
{
val = (int32) (*var)->shape[i];
/* need to fake the size of the record dimension */
if(val == NC_UNLIMITED)
{
if(handle->file_type == HDF_FILE)
val = (*var)->numrecs;
else
val = handle->numrecs;
}
INT32ENCODE(bufp, val);
}
/* "<=" used to put 1 data NT + rank scale NTs in buffer */
for (i = 0; i <= (int)rank; i++)
{ /* scale NTs written even if no scale!*/
UINT16ENCODE(bufp, DFTAG_NT);
UINT16ENCODE(bufp, nt_ref);
}
/* write out SDD record */
if(Hputelement(handle->hdf_file, DFTAG_SDD, ref, tbuf, (int32) (bufp-tbuf)) == FAIL)
{
ret_value = FAIL;
goto done;
}
/* write dimension record tag/ref */
if (DFdiput(GroupID, DFTAG_SDD,(uint16) ref) == FAIL)
{
ret_value = FAIL;
goto done;
}
tags[count] = DFTAG_SDD;
refs[count] = ref;
count++;
/* Add a bogus tag so we know this NDG is really a variable */
if (DFdiput(GroupID, BOGUS_TAG,(uint16) ref) == FAIL)
{
ret_value = FAIL;
goto done;
}
/* write out NDG */
if (DFdiwrite(handle->hdf_file, GroupID, DFTAG_NDG, (*var)->ndg_ref) < 0)
{
ret_value = FAIL;
goto done;
}
tags[count] = DFTAG_NDG;
refs[count] = (*var)->ndg_ref;
count++;
#endif /* WRITE_NDG */
/* write the vgroup for the coordinate variable */
(*var)->vgid = VHmakegroup(handle->hdf_file, tags, refs, count,
(*var)->name->values, _HDF_VARIABLE);
#ifdef DEBUG
if((*var)->vgid == FAIL)
{
fprintf(stderr, "Failed to write variable %s\n", (*var)->name->values);
fprintf(stderr, "count = %d\n", count);
for(i = 0; i < count; i++)
fprintf(stderr, "i = %d tag = %d ref = %d\n", i, tags[i], refs[i]);
HEprint(stdout, 0);
}
#endif
ret_value = (*var)->vgid; /* ref of vgroup of variable */
done:
if (ret_value == FAIL)
{ /* Failure cleanup */
}
/* Normal cleanup */
return ret_value;
} /* hdf_write_var */
/* ----------------------------------------------------------------
** Write out a cdf structure
*/
intn
hdf_write_xdr_cdf(xdrs, handlep)
XDR *xdrs;
NC **handlep;
{
int32 count;
int status, done;
unsigned sz, i, j;
int32 *tags = NULL;
int32 *refs = NULL;
NC_dim **dims = NULL;
NC_dim **dims1 = NULL;
NC_array *tmp = NULL;
long *dim_size_array = NULL;
long *tsizeptr = NULL;
long tsize;
uint32 *dim_hash_array = NULL;
uint32 *thashptr = NULL;
uint32 thash;
Void *vars = NULL;
Void *attrs = NULL;
intn ret_value = SUCCEED;
#if DEBUG
fprintf(stderr, "hdf_write_xdr_cdf i've been called op = %d \n", xdrs->x_op);
#endif
/* Convert old scales into coordinate var values before writing
out any header info */
status = hdf_conv_scales(handlep);
if (status == FAIL)
{
ret_value = FAIL;
goto done;
}
/* count size of tag / ref arrays */
sz = 0;
if((*handlep)->dims)
sz += (*handlep)->dims->count;
if((*handlep)->vars)
sz += (*handlep)->vars->count;
if((*handlep)->attrs)
sz += (*handlep)->attrs->count;
#if DEBUG
fprintf(stderr, "sz = %d\n", sz);
#endif
/* allocate tag / ref arrays */
tags = (int32 *) HDmalloc(sz * sizeof(int32) + 1);
refs = (int32 *) HDmalloc(sz * sizeof(int32) + 1);
if(NULL == tags || NULL == refs)
{
#ifdef DEBUG
fprintf(stderr, "Out of memory line %d file %s\n", __LINE__, __FILE__);
#endif
ret_value = FAIL;
goto done;
}
/*
** write out dimension arrays
*/
count = 0;
if((*handlep)->dims)
{
tmp = (*handlep)->dims;
dims = (NC_dim **) (*handlep)->dims->values;
tsizeptr = dim_size_array =(long *)HDmalloc(sizeof(long)*(size_t)tmp->count);
thashptr = dim_hash_array =(uint32 *)HDmalloc(sizeof(uint32)*(size_t)tmp->count);
if(NULL == dim_size_array || NULL == dim_hash_array)
{
#ifdef DEBUG
fprintf(stderr, "Out of memory line %d file %s\n", __LINE__, __FILE__);
#endif
ret_value = FAIL;
goto done;
}
for(i = 0; i < tmp->count; i++,dims++)
{
*tsizeptr++=(*dims)->size;
*thashptr++=(*dims)->name->hash;
} /* end for */
dims = (NC_dim **) (*handlep)->dims->values;
for(i = 0; i < tmp->count; i++)
{
/* this is really ugly and should be handled another way */
/* make sure we don't duplicate dimensions */
done = FALSE;
dims1 = (NC_dim **) (*handlep)->dims->values;
tsize = dim_size_array[i];
thash = dim_hash_array[i];
tsizeptr = dim_size_array;
thashptr = dim_hash_array;
for(j = 0; j < i; j++)
{
/* this order on the test is faster -QAK */
if( thash == *thashptr
&& tsize == *tsizeptr
&& NC_compare_string((*dims)->name,(*dims1)->name) == 0 )
{
done = TRUE;
break;
}
tsizeptr++;
thashptr++;
dims1++;
}
if(!done)
{
tags[count] = (int32) DIM_TAG;
refs[count] = (int32) hdf_write_dim(xdrs, (*handlep), dims, count);
if(refs[count] == FAIL)
{
ret_value = FAIL;
goto done;
}
count++;
}
dims++;
}
} /* end if handle->dims */
/*
** write out variable info
*/
if((*handlep)->vars)
{
tmp = (*handlep)->vars;
vars = (*handlep)->vars->values;
for(i = 0; i < tmp->count; i++)
{
tags[count] = (int32) VAR_TAG;
refs[count] = (int32) hdf_write_var(xdrs, (*handlep), (NC_var **)vars);
if(refs[count] == FAIL)
{
ret_value = FAIL;
goto done;
}
vars += tmp->szof;
count++;
}
}
/*
* write global attribute information
*/
if((*handlep)->attrs)
{
tmp = (*handlep)->attrs;
attrs = (*handlep)->attrs->values;
for(i = 0; i < tmp->count; i++)
{
tags[count] = (int32) ATTR_TAG;
refs[count] = (int32) hdf_write_attr(xdrs, (*handlep), (NC_attr **)attrs);
if(refs[count] == FAIL)
{
ret_value = FAIL;
goto done;
}
attrs += tmp->szof;
count++;
}
}
#if DEBUG
fprintf(stderr, "About to write top level VG with %d elements\n", count);
{
int i;
for(i = 0; i < count; i++)
fprintf(stderr, "%d :=> %d %d\n", i, tags[i], refs[i]);
}
#endif
/* write out final VGroup thang */
/* set the top level CDF VGroup pointer */
(*handlep)->vgid = VHmakegroup((*handlep)->hdf_file, tags, refs, count,
(*handlep)->path, _HDF_CDF);
ret_value = (*handlep)->vgid; /* ref of final vgroup */
#ifdef DEBUG
fprintf(stderr, "======= Have finished writing top level VGroup #%d\n", ret_value);
#endif
done:
if (ret_value == FAIL)
{ /* Failure cleanup */
}
/* Normal cleanup */
if (dim_size_array != NULL)
HDfree(dim_size_array);
if (dim_hash_array != NULL)
HDfree(dim_hash_array);
if (tags != NULL)
HDfree(tags);
if (refs != NULL)
HDfree(refs);
return ret_value;
} /* hdf_write_xdr_cdf */
/* --------------------------------------------------------------
** hdf_conv_scales converts old scale values into coord var values.
** Searchs through var list for DFTAG_SDS, reads in the scale data,
** change the ref to ndg_ref and the tag to DATA_TAG, writes the
** data out.
*/
intn
hdf_conv_scales(handlep)
NC **handlep;
{
int status, scaleref, scaletag, scalelen;
unsigned i;
NC_var **vars = NULL;
NC_array *tmp = NULL;
uint8 *scalebuf = NULL;
uint8 *datap = NULL;
intn ret_value = SUCCEED;
#ifdef LATER
CONSTR(FUNC, "hdf_conv_scales");
#endif /* LATER */
if ((*handlep)->vars)
{
tmp = (*handlep)->vars;
vars = (NC_var **)tmp->values;
for (i = 0; i < tmp->count; i++)
{
if ( ((*vars)->data_tag == DFTAG_SDS)
&& ((*vars)->data_ref != (*vars)->ndg_ref))
{
/* read in scale values */
scaleref = (*vars)->data_ref;
scaletag = (*vars)->data_tag;
scalelen = Hlength((*handlep)->hdf_file, scaletag, scaleref);
if (scalelen == FAIL)
{
ret_value = FAIL;
goto done;
}
if ((*vars)->data_offset == -1)
{ /* this dim has no scale values */
(*vars)->data_ref = 0;
(*vars)->data_tag = DATA_TAG;
}
else
{ /* has scale values */
scalebuf = (uint8 *)HDmalloc((uint32)scalelen);
if (scalebuf == NULL)
{
ret_value = FAIL;
goto done;
}
status = Hgetelement((*handlep)->hdf_file, scaletag,
scaleref, scalebuf);
if (status == FAIL)
{
ret_value = FAIL;
goto done;
}
(*vars)->data_tag = DATA_TAG;
(*vars)->data_ref = (*vars)->ndg_ref; /* Try to stick
with the current way. If this ref conflicts with
existing SDS, call Hnewref to get a new one. 3/25/97 */
datap = scalebuf + (*vars)->data_offset;
status = Hputelement((*handlep)->hdf_file, DATA_TAG,
(*vars)->data_ref, datap, (*vars)->len);
if (status == FAIL)
{
(*vars)->data_tag = scaletag;
(*vars)->data_ref = scaleref;
ret_value = FAIL;
goto done;
}
} /* has scale values */
} /* DFTAG_SDS */
vars ++;
}
}
done:
if (ret_value == FAIL)
{ /* Failure cleanup */
}
/* Normal cleanup */
if (scalebuf != NULL)
HDfree(scalebuf);
return ret_value;
}
/* ----------------------------------------------------------------
** Read in the dimensions out of a cdf structure
** Return FAIL if something goes wrong
*/
intn
hdf_read_dims(XDR *xdrs, NC *handle, int32 vg)
{
char vgname[H4_MAX_NC_NAME] = "";
char vsclass[H4_MAX_NC_CLASS] = "";
char vgclass[H4_MAX_NC_CLASS] = "";
int id, count, i, found;
int sub_id;
int32 dim_size;
NC_dim **dimension = NULL;
int32 dim, entries;
int32 vs;
intn ret_value = SUCCEED;
found = FALSE;
count = 0;
id = -1;
#if DEBUG
fprintf(stderr, "hdf_read_dims I've been called, handle->hdf_file = %d\n", handle->hdf_file);
#endif
/*
* Allocate enough space in case everything is a dimension
*/
count = 0;
dimension = (NC_dim **) HDmalloc(sizeof(NC_dim *) * Vntagrefs(vg) + 1);
if(NULL == dimension)
{
/* replace it with NCadvice or HERROR?? */
#ifdef DEBUG
fprintf(stderr, "Out of memory line %d file %s\n", __LINE__, __FILE__);
#endif
ret_value = FAIL;
goto done;
}
/*
* Look through for a Vgroup of class _HDF_DIMENSION
*/
while((id = Vgetnext(vg, id)) != FAIL)
{
if(Visvg(vg, id))
{
dim = Vattach(handle->hdf_file, id, "r");
if(dim == FAIL)
continue; /* why do we continue? does this failure here
not matter? -GV */
if (Vgetclass(dim, vgclass) == FAIL)
{
ret_value = FAIL;
goto done;
}
if(!HDstrcmp(vgclass, _HDF_DIMENSION)
|| !HDstrcmp(vgclass, _HDF_UDIMENSION))
{
int is_dimval, is_dimval01;
/* init both flags to FALSE */
is_dimval = FALSE;
is_dimval01 = FALSE;
if (Vinquire(dim, &entries, vgname) == FAIL)
{
ret_value = FAIL;
goto done;
}
/*
* look through for a Vdata of class DIM_VALS01 and/or DIM_VALS
* to get size
*/
sub_id = -1;
while(((sub_id = Vgetnext(dim, sub_id)) != FAIL) )
{
if(Visvs(dim, sub_id))
{
vs = VSattach(handle->hdf_file, sub_id, "r");
if(vs == FAIL)
{
ret_value = FAIL;
goto done;
}
if (VSgetclass(vs, vsclass) == FAIL)
{
ret_value = FAIL;
goto done;
}
if(!HDstrcmp(vsclass, DIM_VALS))
{
is_dimval = TRUE;
if (HDstrcmp(vgclass, _HDF_UDIMENSION)) /* not unlimited di
m */
{
if (VSQuerycount(vs, &dim_size) == FAIL)
{
ret_value = FAIL;
goto done;
}
}
}
if ((!HDstrcmp(vsclass, DIM_VALS01))
|| (!HDstrcmp(vgclass, _HDF_UDIMENSION)))
{ /* DIM_VALS && _HDF_UDIMENSION */
int32 val; /* needs a temp var since handle->numrecs */
/* may not be an int32 */
/*
The call to VSsetfields fails for the files created with the library
version 3.3r1. This call is not necessary since handle vs is
obtained by specifying class name.
Elena Pourmal 2/17/99
if (VSsetfields(vs, "Values") == FAIL)
{
ret_value = FAIL;
goto done;
}
*/
if (VSseek(vs, 0) == FAIL)
{
ret_value = FAIL;
goto done;
}
/*
* This is highly dangerous since there might be multiple
* unlimited dimensions
*/
if(VSread(vs, (uint8 *) &val, 1, FULL_INTERLACE) != 1)
{
ret_value = FAIL;
goto done;
}
if (!HDstrcmp(vgclass, _HDF_UDIMENSION))
{
dim_size = NC_UNLIMITED;
handle->numrecs = val;
}
else
dim_size = val;
} /* */
if (!HDstrcmp(vsclass, DIM_VALS01)) /* dimval01 */
is_dimval01 = TRUE;
if (VSdetach(vs) == FAIL)
{
ret_value = FAIL;
goto done;
}
/* Is it the second dim vs of a compatible dim? */
found = FALSE;
for (i = count-1; ((i >= 0) && (!found)); i--)
{
if (!HDstrcmp(vgname, dimension[i]->name->values) &&
(dim_size == dimension[i]->size)) {
/* vgname is the dim name. vgname may be diff from vsname */
if (is_dimval01 == TRUE && is_dimval == TRUE)
dimension[i]->dim00_compat = 1;
found = TRUE; /* the second vs */
}
} /* for */
if (!found)
{
dimension[count] = NC_new_dim(vgname, dim_size);
if(NULL == dimension[count])
{
#ifdef DEBUG
/* replace it with NCadvice or HERROR?? */
fprintf(stderr, "Can't create new dimension #%d\n", count);
#endif
ret_value = FAIL;
goto done;
} /* dimension[count] */
#if DEBUG
fprintf(stderr, "Dimension <%s> has size %d\n", vgname, dim_size);
#endif
if (!HDstrcmp(vsclass, DIM_VALS01)) /* dimvals01 only */
dimension[count]->dim00_compat = 0;
/* record vgroup id here so we can use later */
/* Note: this is only for later file -BMR */
dimension[count]->vgid = id;
count++;
} /* found */
} /* is vs */
} /* while in dimension vg */
} /* is vg */
if (Vdetach(dim) == FAIL)
{
ret_value = FAIL;
goto done;
}
} /* while */
}
if(count)
{
handle->dims = NC_new_array(NC_DIMENSION, count, (Void *) dimension);
if (handle->dims == NULL)
{
ret_value = FAIL;
goto done;
}
}
else
handle->dims = NULL;
#if DEBUG
fprintf(stderr, "Created dimension array %d \n", handle->dims);
#endif
done:
if (ret_value == FAIL)
{ /* Failure cleanup */
if (handle->dims != NULL)
{
NC_free_array(handle->dims);
handle->dims = NULL;
}
}
/* Normal cleanup */
if (dimension != NULL)
HDfree(dimension);
return ret_value;
} /* hdf_read_dims */
/******************************************************************************
NAME
hdf_num_attrs
DESCRIPTION
Determine number of attributes in vgroup i.e. of the SDS
RETURNS
returns number of attributes in vgroup if successful and FAIL
otherwise.
*******************************************************************************/
static intn
hdf_num_attrs(NC *handle,/* IN: handle to SDS */
int32 vg /* IN: ref of top Vgroup */)
{
int count = 0;
int t, n;
int32 vs, tag;
int32 id = -1;
char class[H4_MAX_NC_CLASS] = "";
intn ret_value = FAIL;
#ifdef HDF_NUM_ATTRS
fprintf(stderr, "hdf_num_attrs: I've been called, handle->hdf_file = %d\n", handle->hdf_file);
#endif
n = Vntagrefs(vg);
if (n == FAIL)
{
#ifdef HDF_NUM_ATTRS
fprintf(stderr,"hdf_read_attrs: Vntagrefs failed \n");
#endif
ret_value = FAIL;
goto done;
}
#ifdef HDF_NUM_ATTRS
fprintf(stderr,"hdf_num_attrs: Vntagrefs returned =%d \n",n);
#endif
/*
* look through for a Vdata of class _HDF_ATTRIBUTE
*/
for (t = 0; t < n; t++)
{
if (Vgettagref(vg, t, &tag, &id) == FAIL)
{
ret_value = FAIL;
goto done;
}
if(tag == DFTAG_VH)
{
vs = VSattach(handle->hdf_file, id, "r");
if(vs == FAIL)
{
ret_value = FAIL;
goto done;
}
if (VSgetclass(vs, class) == FAIL)
{
ret_value = FAIL;
goto done;
}
if(!HDstrcmp(class, _HDF_ATTRIBUTE))
count++;
if (VSdetach(vs) == FAIL)
{
ret_value = FAIL;
goto done;
}
}
}
#ifdef HDF_NUM_ATTRS
fprintf(stderr, "hdf_num_attrs: number of attributes is %d \n", count);
#endif
ret_value = count;
done:
if (ret_value == FAIL)
{ /* Failure cleanup */
}
/* Normal cleanup */
return ret_value;
} /* hdf_num_attrs */
/* ----------------------------------------------------------------
** Read in all attributes of the current vg
** Return NULL if something goes wrong
** Return a pointer to the array of attributes if all goes well
*/
NC_array *
hdf_read_attrs(XDR *xdrs, NC *handle, int32 vg)
{
int count, t, n;
int32 vs, tag, id, vsize, attr_size, nt;
nc_type type;
char vsname[H4_MAX_NC_NAME] = "";
char fields[100] = "" ;
char class[H4_MAX_NC_CLASS] = "";
char *values = NULL;
NC_attr **attributes = NULL;
NC_array *Array = NULL;
NC_array *ret_value = NULL;
count = 0;
id = -1;
#if DEBUG
fprintf(stderr, "hdf_read_attrs I've been called, handle->hdf_file = %d\n", handle->hdf_file);
#endif
n = Vntagrefs(vg);
if (n == FAIL)
{
#ifdef HDF_READ_ATTRS
fprintf(stderr,"hdf_read_attrs: Vntagrefs failed \n");
#endif
ret_value = NULL;
goto done;
}
#ifdef HDF_READ_ATTRS
fprintf(stderr,"hdf_read_attrs: Vntagrefs returned =%d \n",n);
#endif
/*
* Allocate enough space in case everything is an attribute
*/
count = 0;
attributes = (NC_attr **) HDmalloc(sizeof(NC_attr *) * n + 1);
if(NULL == attributes)
{
/* replace it with NCAdvice or HERROR? */
#ifdef HDF_READ_ATTRS
fprintf(stderr, "Out of memory line %d file %s\n", __LINE__, __FILE__);
#endif
ret_value = NULL;
goto done;
}
/*
* look through for a Vdata of class _HDF_ATTRIBUTE
*/
for (t = 0; t < n; t++)
{
if (Vgettagref(vg, t, &tag, &id) == FAIL)
{
ret_value = NULL;
goto done;
}
if(tag == DFTAG_VH)
{
vs = VSattach(handle->hdf_file, id, "r");
if(vs == FAIL)
{
ret_value = NULL;
goto done;
}
if (VSgetclass(vs, class) == FAIL)
{
ret_value = NULL;
goto done;
}
if(!HDstrcmp(class, _HDF_ATTRIBUTE))
{
if (VSinquire(vs, &attr_size, NULL, fields, &vsize, vsname) == FAIL)
{
ret_value = NULL;
goto done;
}
if ((nt = VFfieldtype(vs, 0)) == FAIL)
{
ret_value = NULL;
goto done;
}
if ((type = hdf_unmap_type(nt)) == FAIL)
{
ret_value = NULL;
goto done;
}
values = (char *) HDmalloc(vsize * attr_size + 1);
if (NULL == values)
{
ret_value = NULL;
goto done;
}
if (VSsetfields(vs, fields) == FAIL)
{
ret_value = NULL;
goto done;
}
if (VSread(vs, (uint8 *) values, attr_size, FULL_INTERLACE) == FAIL)
{
ret_value = NULL;
goto done;
}
if(type == NC_CHAR)
{
if ((attr_size = VFfieldorder(vs, 0)) == FAIL)
{
ret_value = NULL;
goto done;
}
((char *) values)[attr_size] = '\0';
}
attributes[count] =
(NC_attr *) NC_new_attr(vsname, type, attr_size, values);
if(NULL == attributes[count])
{
/* replace it with NCadvice or HERROR? */
#ifdef HDF_READ_ATTRS
fprintf(stderr, "hdf_read_attrs: Can't create new attribute #%d\n", count);
#endif
ret_value = NULL;
goto done;
}
attributes[count]->HDFtype = nt;
#ifdef HDF_READ_ATTRS
fprintf(stderr, "hdf_read_attrs: Attribute <%s> has type %d and size %d\n",
vsname, type, attr_size);
#endif
/* free values and reset to NULL */
HDfree(values);
values = NULL;
count++;
} /* end if attribute ? */
if (VSdetach(vs) == FAIL)
{
ret_value = NULL;
goto done;
}
} /* end if DFTAG_VH */
} /* end for */
/* create array of attributes */
if(count)
Array = NC_new_array(NC_ATTRIBUTE, count, (Void *) attributes);
#ifdef HDF_READ_ATTRS
fprintf(stderr, "hdf_read_attrs: Created attribute array %d \n", Array);
#endif
ret_value = Array; /* return array of attributes */
done:
if (ret_value == NULL)
{ /* Failure cleanup */
if (Array != NULL)
NC_free_array(Array);
}
/* Normal cleanup */
if (values != NULL)
HDfree(values);
if (attributes != NULL)
HDfree(attributes);
return ret_value;
} /* hdf_read_attrs */
/* ----------------------------------------------------------------
** Read in the variables out of a cdf structure
** Return FAIL if something goes wrong
**
** Important: We must already assume that handle->dims is set
** so that we can do a call to NC_var_shape() so that we can
** set the numrecs fields of variables (so we can fill record
** variables intelligently)
*/
intn
hdf_read_vars(XDR *xdrs,
NC *handle,
int32 vg)
{
char vgname[H4_MAX_NC_NAME] = "";
char subname[H4_MAX_NC_NAME] = "";
char class[H4_MAX_NC_CLASS] = "";
NC_var **variables = NULL;
NC_var *vp = NULL;
int ndims, *dims = NULL;
uint8 ntstring[4];
int data_ref, is_rec_var, vg_size, count;
int32 data_count;
int32 HDFtype = FAIL;
int32 tag;
int32 id;
int32 n;
int32 sub_id;
int32 entries;
int32 ndg_ref = 0;
int32 rag_ref = 0;
intn nattrs;
hdf_vartype_t var_type = UNKNOWN;
register int t, i;
register nc_type type;
register int32 var, sub;
intn ret_value = SUCCEED;
#ifdef LATER
CONSTR(FUNC,"hdf_read_vars");
#endif /* LATER */
count = 0;
id = -1;
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars: I've been called, handle->hdf_file = %d\n", handle->hdf_file);
#endif
/*
* Allocate enough space in case everything is a variable
*/
count = 0;
variables = (NC_var **) HDmalloc(sizeof(NC_var *) * Vntagrefs(vg) + 1);
if(NULL == variables)
{
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars:Out of memory line %d file %s\n", __LINE__, __FILE__);
#endif
ret_value = FAIL;
goto done;
}
/*
* Allocate enough space in case lots of dimensions
*/
dims = (int *) HDmalloc(sizeof(int) * Vntagrefs(vg) + 1);
if(NULL == dims)
{
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars:Out of memory line %d file %s\n", __LINE__, __FILE__);
#endif
ret_value = FAIL;
goto done;
}
/*
* Look through for a Vgroup of class _HDF_VARIABLE
*/
if ((vg_size = Vntagrefs(vg)) == FAIL)
{
ret_value = FAIL;
goto done;
}
for(i = 0; i < vg_size; i++)
{
if (Vgettagref(vg, i, &tag, &id) == FAIL)
{
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars:Vgettagref failed\n");
#endif
ret_value = FAIL;
goto done;
}
if(tag == DFTAG_VG)
{
var = Vattach(handle->hdf_file, id, "r");
if(var == FAIL)
continue; /* isn't this bad? -GV */
if (Vgetclass(var, class) == FAIL)
{
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars:Vgetclass failed\n");
#endif
ret_value = FAIL;
goto done;
}
/* Process as below if this VGroup represents a Variable or
a Coordinate Variable */
if(!HDstrcmp(class, _HDF_VARIABLE))
{
/*
* We have found a VGroup representing a Variable or a
* a Coordinate Variable
*/
ndims = 0;
type = NC_UNSPECIFIED;
data_ref = 0;
data_count = 0;
rag_ref = 0;
is_rec_var = FALSE;
if (Vinquire(var, &n, vgname) == FAIL)
{
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars:Vinquire failed\n");
#endif
ret_value = FAIL;
goto done;
}
/*
* Loop through contents looking for dimensions
*/
for (t = 0; t < n; t++)
{
char dimclass[H4_MAX_NC_CLASS] = "";
char vsclass[H4_MAX_NC_CLASS] = "";
if (Vgettagref(var, t, &tag, &sub_id) == FAIL)
{
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars:Vgettagref failed\n");
#endif
ret_value = FAIL;
goto done;
}
switch(tag)
{
case DFTAG_VG : /* ------ V G R O U P ---------- */
sub = Vattach(handle->hdf_file, sub_id, "r");
if (FAIL == sub)
{
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars:Vattach failed\n");
#endif
ret_value = FAIL;
goto done;
}
if (FAIL == Vgetclass(sub, dimclass))
{
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars:Vgetclass failed\n");
#endif
ret_value = FAIL;
goto done;
}
if(!HDstrcmp(dimclass, _HDF_DIMENSION)
|| !HDstrcmp(dimclass, _HDF_UDIMENSION))
{
if(!HDstrcmp(dimclass, _HDF_UDIMENSION))
is_rec_var = TRUE;
if (FAIL == Vinquire(sub, &entries, subname))
{
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars:Vinquire failed\n");
#endif
ret_value = FAIL;
goto done;
}
dims[ndims] = (int) NC_dimid( handle, subname);
if (-1 == dims[ndims]) /* should change to FAIL */
{
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars:NC_dimid failed\n");
#endif
ret_value = FAIL;
goto done;
}
ndims++;
}
if (FAIL == Vdetach(sub))
{
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars:Vdetach failed\n");
#endif
ret_value = FAIL;
goto done;
}
break;
case DFTAG_VH : /* ----- V D A T A ----- */
sub = VSattach(handle->hdf_file, sub_id, "r");
if (FAIL == sub)
{
ret_value = FAIL;
goto done;
}
if (FAIL == VSgetclass(sub, vsclass))
{
ret_value = FAIL;
goto done;
}
if(!HDstrcmp(vsclass, _HDF_SDSVAR))
var_type = IS_SDSVAR;
else if(!HDstrcmp(vsclass, _HDF_CRDVAR))
var_type = IS_CRDVAR;
else
var_type = UNKNOWN;
if (FAIL == VSdetach(sub))
{
ret_value = FAIL;
goto done;
}
break;
case DFTAG_NDG : /* ----- NDG Tag for HDF 3.2 ----- */
ndg_ref = sub_id;
break;
case DFTAG_SD : /* ------- Data Storage ------ */
data_ref = sub_id;
/* Note: apparently Hlength will fail in certain cases, but
but this okay since I believe this is because
the data does not exist yet in the file?
So we can't catch this error -GV*/
data_count = Hlength(handle->hdf_file, DATA_TAG, sub_id);
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars:Hlength returned %d\n",data_count);
#endif
break;
case DFTAG_SDRAG : /* ----- Ragged Array index ----- */
rag_ref = sub_id;
#ifdef HDF_READ_VARS
printf("hdf_read_vars:Lookout! Found a ragged array element\n");
#endif
break;
case DFTAG_NT : /* ------- Number type ------- */
if(Hgetelement(handle->hdf_file, tag, sub_id, ntstring) == FAIL)
{
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars:Hgetlement failed\n");
#endif
ret_value = FAIL;
goto done;
}
HDFtype = ntstring[1];
if ((type = hdf_unmap_type(HDFtype)) == FAIL)
{
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars:hdf_unmap_teyp failed\n");
#endif
ret_value = FAIL;
goto done;
}
/*
* Check if data was stored in native format
* And make sure the numbertype version numbers are the same
*/
if((ntstring[0] != DFNT_VERSION)
|| ((ntstring[3] != DFNTF_NONE)
&& (ntstring[3] != DFNTF_IEEE)))
{
/* check if in native mode for a different type of machine or external data file is LITEND */
if (ntstring[3] == DFNTF_PC)
HDFtype |= DFNT_LITEND;
else
{
if(ntstring[3] != (uint8)DFKgetPNSC(HDFtype, DF_MT))
{
/*
* OK, we have a problem here --- is in native mode
* for a different machine. PUNT
*/
goto bad_number_type; /* GOTO */
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars: BAD number type \n");
#endif
}
else
{
/*
* Is in native mode but its OK --- same machine type
*/
HDFtype |= DFNT_NATIVE;
}
}
}
break;
default:
/* Do nothing */
break;
}
}
variables[count] = NC_new_var(vgname, type, ndims, dims);
/* BMR: put back hdf type that was set wrong by
NC_new_var; please refer to the cvs history of
bug #172 for reason on this statement - 4/17/2001
*/
variables[count]->HDFtype = HDFtype;
vp = variables[count];
if(NULL == vp)
{
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars:Can't read new variable %s\n", vgname);
#endif
ret_value = FAIL;
goto done;
}
#ifdef HDF_READ_VARS
fprintf(stderr,"hdf_read_vars:Created a variable called %s (id %d) \n", vgname, id);
#endif
/* Read in the attributes if any */
if ((nattrs = hdf_num_attrs(handle, var)) > 0)
vp->attrs = hdf_read_attrs(xdrs, handle, var);
else
vp->attrs = NULL;
#ifdef HDF_READ_VARS
fprintf(stderr,"hdf_read_vars:read in %d attributes \n",nattrs );
#endif
/* set up for easy access later */
vp->vgid = id;
vp->data_ref = data_ref;
vp->data_tag = DATA_TAG;
vp->HDFtype = HDFtype;
vp->ndg_ref = (uint16) ndg_ref;
vp->cdf = handle; /* for NC_var_shape */
vp->var_type = var_type;
/* need to process the ragged array info here */
/* QUESTION: Load the whole rag_fill list in now??????? */
if(rag_ref)
{
vp->is_ragged = TRUE;
}
if(vp->data_ref)
{
/*
* We have already seen data for this variable so now
* we need to worry about its numrecs field
*/
if(is_rec_var)
{
/*
* Call NC_var_shape() so we can figure out how many
* records have been written. This is horribly
* inefficient, but the separation-of-powers gets
* really mucked up if we wait till later...
*/
if(NC_var_shape(vp, handle->dims) == -1)
{
#ifdef HDF_READ_VARS
fprintf(stderr,"hdf_read_vars:NC_var_shape failed \n" );
#endif
ret_value = FAIL;
goto done;
}
/*
* Now figure out how many recs have been written
* For a while there was a -1 at the end of this
* equation. I don't remember why its there
* (4-Nov-93)
*/
vp->numrecs = data_count / vp->dsizes[0];
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars:I have set numrecs to %d\n", vp->numrecs);
#endif
/*
* Deallocate the shape info as it will be recomputed
* at a higher level later
*/
if(vp->shape != NULL)
HDfree(vp->shape);
if(vp->dsizes != NULL)
HDfree(vp->dsizes);
/* Reset these two pointers to NULL after
freeing. BMR 4/11/01 */
vp->shape = NULL;
vp->dsizes = NULL;
}
else
{
/* Not a rec var, don't worry about it */
vp->numrecs = 1;
}
} /* end vp->data_ref */
count++;
} /* end if vgroup class is variable */
bad_number_type: /* ? */
if (FAIL == Vdetach(var))
{
ret_value = FAIL;
goto done;
}
} /* end if DTAG_VG */
} /* end for vg_size */
/* create array of variables */
if(count)
{
handle->vars = NC_new_array(NC_VARIABLE, count, (Void *) variables);
if (NULL == handle->vars)
{
ret_value = FAIL;
goto done;
}
}
else
handle->vars = NULL;
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars: Created variable array %d \n", handle->vars);
#endif
done:
if (ret_value == FAIL)
{ /* Failure cleanup */
#ifdef HDF_READ_VARS
fprintf(stderr, "hdf_read_vars: failed to created variable array \n");
#endif
if (handle->vars != NULL)
NC_free_array(handle->vars);
}
/* Normal cleanup */
if (variables != NULL)
HDfree(variables);
if (dims != NULL)
HDfree(dims);
return ret_value;
} /* hdf_read_vars */
/* ----------------------------------------------------------------
** Read in a cdf structure
*/
intn
hdf_read_xdr_cdf(xdrs, handlep)
XDR *xdrs;
NC **handlep;
{
#if DEBUG
char vgname[H4_MAX_NC_NAME];
int32 entries;
#endif
register int32 cdf_vg = FAIL;
register int vgid = 0;
int status;
#ifdef OLD_WAY
register int found;
char class[H4_MAX_NC_CLASS];
#endif /* OLD_WAY */
CONSTR(FUNC,"hdf_read_xdr_cdf");
intn ret_value = SUCCEED;
#if DEBUG
fprintf(stderr, "hdf_read_xdr_cdf i've been called %d\n", (*handlep)->hdf_file);
#endif
#ifdef OLD_WAY
/* find first thing of type _HDF_CDF */
vgid = -1;
found = FALSE;
while(!found
&& ((vgid = Vgetid((*handlep)->hdf_file, vgid)) != FAIL))
{
cdf_vg = Vattach((*handlep)->hdf_file, vgid, "r");
if(cdf_vg == FAIL)
{
HERROR(DFE_CANTATTACH);
ret_value = FAIL;
goto done;
}
if (Vgetclass(cdf_vg, class) == FAIL)
{
ret_value = FAIl;
goto done;
}
if(!HDstrcmp(class, _HDF_CDF))
found = TRUE;
else
{
if (Vdetach(cdf_vg) == FAIL)
{
ret_value = FAIL;
goto done;
}
}
}
if(!found)
{
ret_value = FAIL;
goto done;
}
#else /* new way */
if((vgid = Vfindclass((*handlep)->hdf_file,_HDF_CDF))!=FAIL)
{
cdf_vg = Vattach((*handlep)->hdf_file, vgid, "r");
if(cdf_vg == FAIL)
{
HERROR(DFE_CANTATTACH);
ret_value = FAIL;
goto done;
}
} /* end if */
else
{
ret_value = FAIL;
goto done;
}
#endif /* new way */
(*handlep)->vgid = vgid; /* ref of vgroup */
#if DEBUG
Vinquire(cdf_vg, &entries, vgname);
fprintf(stderr, "Found _HDF_CDF : %s (%d entries)\n", vgname, entries);
#endif
/* read in dimensions */
status = hdf_read_dims(xdrs, (*handlep), cdf_vg);
if(status == FAIL)
{
ret_value = FAIL;
goto done;
}
/* read in variables */
status = hdf_read_vars(xdrs, (*handlep), cdf_vg);
if(status == FAIL)
{
ret_value = FAIL;
goto done;
}
/* read in attributes */
if(hdf_num_attrs((*handlep), cdf_vg) > 0 )
(*handlep)->attrs = hdf_read_attrs(xdrs, (*handlep), cdf_vg);
else
(*handlep)->attrs = NULL;
/* deatch from cdf vgroup */
if (FAIL == Vdetach(cdf_vg))
{
ret_value = FAIL;
goto done;
}
done:
if (ret_value == FAIL)
{ /* Failure cleanup */
if (cdf_vg != FAIL)
Vdetach(cdf_vg);
}
/* Normal cleanup */
return ret_value;
} /* hdf_read_xdr_cdf */
/* -------------------------------------------------------------------
** Read or write a CDF structure
**
** If we are reading, first try to read the information out of netCDF
** object stored explicitly in HDF files as netCDF objects. If
** that fails try to read SDSs out of the HDF file and interpret
** them as netCDF information.
*/
intn
hdf_xdr_cdf(xdrs, handlep)
XDR *xdrs;
NC **handlep;
{
CONSTR(FUNC,"hdf_xdr_cdf"); /* for HERROR */
intn status;
intn ret_value = SUCCEED;
#ifdef HDF_XDR_CDF
fprintf(stderr, "hdf_xdr_cdf: i've been called op = %d \n", xdrs->x_op);
#endif
switch(xdrs->x_op)
{
case XDR_ENCODE :
if((*handlep)->vgid)
{
if (FAIL == hdf_cdf_clobber((*handlep)))
{
ret_value = FAIL;
goto done;
}
}
status = hdf_write_xdr_cdf(xdrs, handlep);
if (FAIL == status)
{
#ifdef HDF_XDR_CDF
fprintf(stderr, "hdf_xdr_cdf: hdf_write_xdr_cdf failed \n");
#endif
ret_value = FAIL;
goto done;
}
break;
case XDR_DECODE :
if(FAIL == (status = hdf_read_xdr_cdf(xdrs, handlep)))
{
#ifdef HDF_XDR_CDF
fprintf(stderr, "hdf_xdr_cdf: hdf_read_xdr_cdf failed \n");
fprintf(stderr," going to hdf_read_sds \n");
#endif
status = hdf_read_sds_cdf(xdrs, handlep);
if(FAIL == status)
{
#ifdef HDF_XDR_CDF
fprintf(stderr, "hdf_xdr_cdf: hdf_read_sds failed \n");
#endif
HERROR(DFE_BADNDG);
ret_value = FAIL;
goto done;
}
} /* end if */
break;
case XDR_FREE :
if (FAIL == NC_free_cdf((*handlep)))
ret_value = FAIL;
else
ret_value = SUCCEED;
break;
default:
ret_value = FAIL;
}
done:
if (ret_value == FAIL)
{ /* Failure cleanup */
}
/* Normal cleanup */
return ret_value;
} /* hdf_xdr_cdf */
/* ---------------------- hdf_vg_clobber --------------- */
/*
Delete a VGroup that is on the disk. Basically, we will want to
just trash everything inside of it, making sure that any VDatas
with class == DATA are saved
*/
intn
hdf_vg_clobber(handle, id)
NC *handle;
int id;
{
int t, n;
int32 vg, tag, ref;
int32 status;
intn ret_value = SUCCEED;
#ifdef HDF_VG_CLOBBER
fprintf(stderr, "hdf_vg_clobber: has been called for vgroup ref=%d\n",id);
#endif
/* loop through and Clobber all top level VGroups */
/* attach to top level vgroup with read access */
vg = Vattach(handle->hdf_file, id, "r");
if(FAIL == vg)
{
#ifdef HDF_VG_CLOBBER
fprintf(stderr,"hdf_vg_clobber: Vattach failed for vgroup ref =%d\n",id);
HEprint(stderr,0);
#endif
ret_value = FAIL;
goto done;
}
/* get number of members in vgroup */
n = Vntagrefs(vg);
if (FAIL == n)
{
#ifdef HDF_VG_CLOBBER
fprintf(stderr,"hdf_vg_clobber: Vntagrefs failed \n");
#endif
ret_value = FAIL;
goto done;
}
/* Loop though and kill stuff */
for (t = 0; t < n; t++)
{ /* get tag/ref of elment in vgroup */
if (FAIL == Vgettagref(vg, t, &tag, &ref))
{
#ifdef HDF_VG_CLOBBER
fprintf(stderr,"hdf_vg_clobber: Vgettagref failed \n");
#endif
ret_value = FAIL;
goto done;
}
#ifdef HDF_VG_CLOBBER
fprintf(stderr, "hdf_vg_clobber: Looking at <%d, %d> in vgroup\n", tag, ref);
#endif
/* switch on the type of element: vgroup, vdata, data,
everyting else */
switch(tag)
{
case DFTAG_VG : /* recursive call */
#ifdef HDF_VG_CLOBBER
fprintf(stderr,"hdf_vg_clobber: found a vgroup ref %d in vgroup %d\n",ref,id);
#endif
/* check if vgroup exists in file before trying to delete
it's members */
if (vexistvg(handle->hdf_file, ref) != FAIL)
{
if (FAIL == hdf_vg_clobber(handle, ref))
{
#ifdef HDF_VG_CLOBBER
fprintf(stderr,"hdf_vg_clobber: hdf_vg_clobber failed member whose vgroup ref=%d\n",ref);
#endif
ret_value = FAIL;
goto done;
}
}
break;
case DFTAG_VH :
/* check if vdata exists in file before trying to delete it */
if (vexistvs(handle->hdf_file, ref) != FAIL)
{
status = VSdelete(handle->hdf_file, (int32) ref);
if (FAIL == status)
{
#ifdef HDF_VG_CLOBBER
fprintf(stderr,"hdf_vg_clobber: VSdelete failed for vdata ref=%d\n",ref);
#endif
ret_value = FAIL;
goto done;
}
}
#ifdef HDF_VG_CLOBBER
fprintf(stderr,"hdf_vg_clobber: VSdelete deleted vdata ref=%d\n",ref);
#endif
break;
case DFTAG_SD :
/*
* Don't delete actual numeric data
* I guess this means we save it? -GV
*/
break;
default: /* delete other objects given tag/ref in file */
if (FAIL == Hdeldd(handle->hdf_file, (uint16) tag, (uint16) ref))
{
#ifdef HDF_VG_CLOBBER
fprintf(stderr,"hdf_vg_clobber: Hdeldd failed \n");
#endif
ret_value = FAIL;
goto done;
}
#ifdef HDF_VG_CLOBBER
fprintf(stderr,"hdf_vg_clobber: Hdeldd deleted tag/ref=%d/%d\n",tag,ref);
#endif
break;
}
}
ret_value = Vdetach(vg);
#ifdef HDF_VG_CLOBBER
fprintf(stderr, "hdf_vg_clobber: Vdetach, ret_value=%d \n",ret_value);
#endif
done:
if (ret_value == FAIL)
{ /* Failure cleanup */
#ifdef HDF_VG_CLOBBER
fprintf(stderr, "hdf_vg_clobber: failed \n");
#endif
}
/* Normal cleanup */
return ret_value;
} /* hdf_vg_clobber */
/* --------------------------- hdf_cdf_clobber ---------------------------- */
/*
Delete a netCDF structure that has been already written to disk
*/
intn
hdf_cdf_clobber(handle)
NC *handle;
{
int32 vg, tag, ref;
int n, t, status;
intn ret_value = SUCCEED;
if(!handle->vgid)
{ /* okay right? */
ret_value = SUCCEED; /* hmm...since ref of vgroup is zero? */
goto done;
}
/* Close open VData pointers */
if (FAIL == hdf_close(handle))
{
#ifdef HDF_CDF_CLOBBER
fprintf(stderr,"hdf_cdf_clobber: hdf_close failed \n");
#endif
ret_value = FAIL;
goto done;
}
#ifdef HDF_CDF_CLOBBER
fprintf(stderr,"hdf_cdf_clobber: closed all open vdata handles \n");
#endif
/* loop through and Clobber all top level VGroups */
vg = Vattach(handle->hdf_file, handle->vgid, "r");
if(vg == FAIL)
{
#ifdef HDF_CDF_CLOBBER
fprintf(stderr,"hdf_cdf_clobber: Vattach failed for vgroup ref=%d\n",
handle->vgid);
#endif
ret_value = FAIL;
goto done;
}
/* get number of members of Vgroup */
n = Vntagrefs(vg);
if (FAIL == n)
{
#ifdef HDF_CDF_CLOBBER
fprintf(stderr,"hdf_cdf_clobber: Vntagrefs failed \n");
#endif
ret_value = FAIL;
goto done;
}
/* Loop though and just kill everyone */
for (t = 0; t < n; t++)
{
if (FAIL == Vgettagref(vg, t, &tag, &ref))
{
#ifdef HDF_CDF_CLOBBER
fprintf(stderr,"hdf_cdf_clobber: Vgettagref failed for vgroup %d\n",
handle->vgid);
#endif
ret_value = FAIL;
goto done;
}
/* if this member is a vgroup destroy everything in it */
if(tag == DFTAG_VG)
{
#ifdef HDF_CDF_CLOBBER
fprintf(stderr,"hdf_cdf_clobber: member of vgroup is a vgroup,");
fprintf(stderr,"deleteing everything in vgroup %d \n",ref);
#endif
/* check if vgroup exists in file */
if (vexistvg(handle->hdf_file, ref) != FAIL)
{
hdf_vg_clobber(handle, ref);
}
}
switch(tag)
{
case DFTAG_VG:
status = Vdelete(handle->hdf_file, (int32) ref);
if (FAIL == status)
{
#ifdef HDF_CDF_CLOBBER
fprintf(stderr,"hdf_cdf_clobber: Vdelete failed for vgroup %d\n",
ref);
#endif
ret_value = FAIL;
goto done;
}
#ifdef HDF_CDF_CLOBBER
fprintf(stderr,"hdf_cdf_clobber: Vdelete deleted vgroup %d\n",
ref);
#endif
break;
case DFTAG_VH:
status = VSdelete(handle->hdf_file, (int32) ref);
if (FAIL == status)
{
#ifdef HDF_CDF_CLOBBER
fprintf(stderr,"hdf_cdf_clobber: VSdelete failed for vdata %d\n",
ref);
#endif
ret_value = FAIL;
goto done;
}
#ifdef HDF_CDF_CLOBBER
fprintf(stderr,"hdf_cdf_clobber: VSdelete deleted vdata %d\n",
ref);
#endif
break;
default:
status = Hdeldd(handle->hdf_file, (uint16) tag, (uint16) ref);
if (FAIL == status)
{
#ifdef HDF_CDF_CLOBBER
fprintf(stderr,"hdf_cdf_clobber: Hdeldd failed for tag/ref %d/%d\n",
tag,ref);
#endif
ret_value = FAIL;
goto done;
}
#ifdef HDF_CDF_CLOBBER
fprintf(stderr,"hdf_cdf_clobber: Hdeldd deleted tag/ref %d/%d\n",
tag,ref);
#endif
break;
} /* end switch tag */
}/* end for every member in vgroup */
if (FAIL == Vdetach(vg))
{
#ifdef HDF_CDF_CLOBBER
fprintf(stderr,"hdf_cdf_clobber: Vdetach failed for vgroup %d\n",
handle->vgid);
#endif
ret_value = FAIL;
goto done;
}
status = Vdelete(handle->hdf_file, (int32) handle->vgid);
if (FAIL == status)
{
#ifdef HDF_CDF_CLOBBER
fprintf(stderr,"hdf_cdf_clobber: Vdelete failed for vgroup %d\n",
handle->vgid);
#endif
ret_value = FAIL;
goto done;
}
#ifdef HDF_CDF_CLOBBER
fprintf(stderr,"hdf_cdf_clobber:Clobbering VGroup %d\n\n", handle->vgid);
#endif
handle->vgid = 0; /* reset ref of SDS vgroup to invalid ref */
done:
if(ret_value == FAIL)
{ /* Error condition cleanup */
#ifdef HDF_CDF_CLOBBER
fprintf(stderr,"hdf_cdf_clobber: Failed to Clobber VGroup %d\n\n", handle->vgid);
#endif
} /* end if */
/* Normal function cleanup */
return ret_value;
} /* hdf_cdf_clobber */
/* -------------------------- hdf_close --------------------- */
/*
We're about to close the file, do last minute HDF cleanup
Also dump the number of records currently instatiated into the
unlimited dimensions.
BUG: All unlimited dimensions will have the same size
BMR: handle->numrecs is used to write out the dim value for all unlimited
dimensions without checking for netCDF file as in other places where
vp->numrecs is used for HDF file and handle->numrecs is used for netCDF
file. I believe this is what the "BUG:" comment above means. 6/24/2013
*/
intn
hdf_close(handle)
NC *handle;
{
NC_array *tmp = NULL;
NC_var **vp = NULL;
Void *vars = NULL;
register int i;
int id, sub_id;
int32 vg, dim;
int32 vs;
char class[H4_MAX_NC_CLASS] = "";
intn ret_value = SUCCEED;
#ifdef LATER
CONSTR(FUNC,"hdf_close");
#endif /* LATER */
#ifdef HDF_CLOSE
fprintf(stderr,"hdf_close: I've been called\n");
#endif
/* loop through and detach from variable data VDatas */
if(handle->vars)
{
tmp = handle->vars;
vars = handle->vars->values;
for(i = 0; i < tmp->count; i++)
{
vp = (NC_var **) vars;
if((*vp)->aid != FAIL)
{
if (FAIL == Hendaccess((*vp)->aid))
{
#ifdef HDF_CLOSE
fprintf(stderr,"hdf_close: Hendaccess failed for vdata aid %d\n",
(*vp)->aid);
#endif
ret_value = FAIL;
goto done;
}
}
(*vp)->aid = FAIL; /* reset access id */
vars += tmp->szof;
} /* end for each variable */
}
/* loop through top level looking for unlimited dimensions.
we write them out? -GV */
if(handle->flags & NC_NDIRTY)
{
id = -1;
vg = Vattach(handle->hdf_file, handle->vgid, "r");
if (FAIL == vg)
{
#ifdef HDF_CLOSE
fprintf(stderr,"hdf_close: Vattach failed for vgroup ref %d\n",
handle->vgid);
#endif
ret_value = FAIL;
goto done;
}
/* go through vgroup hierachy */
while((id = Vgetnext(vg, id)) != FAIL)
{
if(Visvg(vg, id))
{
dim = Vattach(handle->hdf_file, id, "r");
if (FAIL == dim)
{
#ifdef HDF_CLOSE
fprintf(stderr,"hdf_close: Vattach failed for vgroup ref %d\n",
id);
#endif
ret_value = FAIL;
goto done;
}
if (FAIL == Vgetclass(dim, class))
{
#ifdef HDF_CLOSE
fprintf(stderr,"hdf_close: Vgetclass failed for vgroup ref %d\n",
id);
#endif
ret_value = FAIL;
goto done;
}
/* look for proper vgroup */
if(!HDstrcmp(class, _HDF_UDIMENSION))
{
sub_id = -1;
/* look for vdata in vgroup */
while((sub_id = Vgetnext(dim, sub_id)) != FAIL)
{
if(Visvs(dim, sub_id))
{ /* yes, attach to vdata */
vs = VSattach(handle->hdf_file, sub_id, "w");
if(vs == FAIL)
{
#ifdef HDF_CLOSE
fprintf(stderr,"hdf_close: VSattach failed for vdata ref %d\n",
sub_id);
#endif
ret_value = FAIL;
goto done;
/* HEprint(stdout, 0); */
}
/* get class of vdata */
if (FAIL == VSgetclass(vs, class))
{
#ifdef HDF_CLOSE
fprintf(stderr,"hdf_close: VSgetclass failed for vdata ref %d\n",
sub_id);
#endif
ret_value = FAIL;
goto done;
}
/* are these dimension vdatas? */
if(!HDstrcmp(class, DIM_VALS)
|| !HDstrcmp(class, DIM_VALS01))
{ /* yes */
int32 val = handle->numrecs;
if (FAIL == VSsetfields(vs, "Values"))
{
#ifdef HDF_CLOSE
fprintf(stderr,"hdf_close: VSsetfields failed for vdata ref %d\n",
sub_id);
#endif
ret_value = FAIL;
goto done;
}
if (FAIL == VSseek(vs, 0))
{
#ifdef HDF_CLOSE
fprintf(stderr,"hdf_close: VSseek failed for vdata ref %d\n",
sub_id);
#endif
ret_value = FAIL;
goto done;
}
/* write out dimension vdatas? */
if(VSwrite(vs, (uint8 *)&val, 1, FULL_INTERLACE) != 1)
{
#ifdef HDF_CLOSE
fprintf(stderr,"hdf_close: VSwrite failed for vdata ref %d\n",
sub_id);
#endif
ret_value = FAIL;
goto done;
}
}
/* detach from vdata */
if (FAIL == VSdetach(vs))
{
#ifdef HDF_CLOSE
fprintf(stderr,"hdf_close: VSdetach failed for vdata ref %d\n",
sub_id);
#endif
ret_value = FAIL;
goto done;
}
} /* end if vdata */
} /* end while looking for vdata in vgroup */
} /* end if UNLIMTED dimension vgroup */
if (FAIL == Vdetach(dim))
{
fprintf(stderr,"hdf_close: Vdetach failed for vgroup ref %d\n",
id);
ret_value = FAIL;
goto done;
}
}/* end if vgroup */
} /* end if looking through toplevel vgroup hierachy */
if (FAIL == Vdetach(vg))
{
#ifdef HDF_CLOSE
fprintf(stderr,"hdf_close: Vdetach failed for vgroup ref %d\n",
handle->vgid);
#endif
ret_value = FAIL;
goto done;
}
} /* end if we need to flush out unlimited dimensions? */
done:
if(ret_value == FAIL)
{ /* Error condition cleanup */
} /* end if */
/* Normal function cleanup */
return ret_value;
} /* hdf_close */
/*******************************************************************************/
#endif /* HDF */
/*
* How much space will the xdr'd NC description take.
*
*/
int NC_xlen_cdf(cdf)
NC *cdf ;
{
int len = 8 ;
if(cdf == NULL)
return(0) ;
len += NC_xlen_array(cdf->dims) ;
len += NC_xlen_array(cdf->attrs) ;
len += NC_xlen_array(cdf->vars) ;
return(len) ;
}
#define RECPOS 4L /* seek index of numrecs value */
bool_t
xdr_numrecs(xdrs, handle)
XDR *xdrs;
NC *handle;
{
#ifdef HDF
if(handle->file_type == HDF_FILE)
return TRUE; /* hmm...why? */
#endif
if( (handle->flags & NC_NOFILL)
&& xdrs->x_op == XDR_ENCODE
&& handle->begin_rec > 0)
{
/*
* we need to write something just beyond the last
* record so we can successfully read back the
* entire last record.
*/
if( !xdr_setpos(xdrs, handle->begin_rec
+ handle->numrecs * handle->recsize) )
{
nc_serror("Can't set position to EOF") ;
return(FALSE) ;
}
#ifdef RDEBUG
fprintf(stderr,"\txdr_numrecs %ld = %d + %ld * %d\n",
xdr_getpos(xdrs),
handle->begin_rec, handle->numrecs, handle->recsize) ;
#endif /* RDEBUG */
if( !xdr_u_long(xdrs, &(handle->numrecs)) )
return(FALSE) ;
}
if( !xdr_setpos(xdrs, RECPOS) )
{
nc_serror("Can't set position to RECPOS") ;
return(FALSE) ;
}
return( xdr_u_long(xdrs, &(handle->numrecs)) ) ;
}
static bool_t
xdr_4bytes(xdrs, cp)
XDR *xdrs ;
char *cp ; /* at least 4 valid bytes */
{
return xdr_opaque(xdrs, cp, 4) ;
}
static bool_t
xdr_2shorts(xdrs, sp)
XDR *xdrs ;
short *sp ; /* at least 2 valid shorts */
{
return xdr_shorts(xdrs, sp, 2) ;
}
bool_t
xdr_NC_fill(xdrs, vp)
XDR *xdrs ;
NC_var *vp ;
{
char fillp[2*sizeof(double)] ;
bool_t stat ;
bool_t (*xdr_NC_fnct)() ;
u_long alen = vp->len ;
NC_attr **attr = NULL ;
/*
* set up fill value
*/
/* start with the default */
NC_arrayfill((Void *)fillp, (size_t)2*sizeof(double),
vp->type) ;
/*
* if there is a valid user defined value, use it instead
*/
attr = NC_findattr(&vp->attrs, _FillValue) ;
if( attr != NULL )
{
if( (*attr)->data->type != vp->type || (*attr)->data->count != 1 )
NCadvise(NC_EBADTYPE, "var %s: _FillValue type mismatch",
vp->name->values) ;
else
{
int len = NC_typelen(vp->type) ;
char *cp = fillp ;
while(cp < &fillp[sizeof(fillp) -1])
{
NC_copy_arrayvals(cp, (*attr)->data) ;
cp += len ;
}
}
}
switch(vp->type){
case NC_BYTE :
case NC_CHAR :
alen /= 4 ;
xdr_NC_fnct = xdr_4bytes ;
break ;
case NC_SHORT :
alen /= 4 ;
xdr_NC_fnct = xdr_2shorts ;
break ;
case NC_LONG :
alen /= 4 ;
#if defined __alpha || (_MIPS_SZLONG == 64) || defined __ia64 || (defined __sun && defined _LP64) || defined AIX5L64 || defined __x86_64__ || defined __powerpc64__
xdr_NC_fnct = xdr_int ;
#else
xdr_NC_fnct = xdr_long ;
#endif
break ;
case NC_FLOAT :
alen /= 4 ;
xdr_NC_fnct = xdr_float ;
break ;
case NC_DOUBLE :
alen /= 8 ;
xdr_NC_fnct = xdr_double ;
break ;
default :
NCadvise(NC_EBADTYPE, "bad type %d", vp->type) ;
return(FALSE) ;
}
/* write out fill values */
for(stat = TRUE ; stat && (alen > 0) ; alen--)
{
stat = (*xdr_NC_fnct)(xdrs,fillp) ;
}
if(!stat)
{
NCadvise(NC_EXDR, "xdr_NC_fill") ;
return(FALSE) ;
}
return(TRUE) ;
}
|