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
|
;+
; NAME:
; NCDF_FILE
;
; PURPOSE:
;
; The pupose of this NCDF_File object is three-fold. (1) Allow the user to easily
; determine what information is inside a netCDF file and allow easy access
; to such information. (2) Allow the user to easily create a netCDF file from
; scratch. (3) Allow the user to easily copy information from one netCDF
; file to another.
;
; AUTHOR:
;
; FANNING SOFTWARE CONSULTING
; David Fanning, Ph.D.
; 1645 Sheely Drive
; Fort Collins, CO 80526 USA
; Phone: 970-221-0438
; E-mail: david@idlcoyote.com
; Coyote's Guide to IDL Programming: http://www.idlcoyote.com
;
; CATEGORY:
; File I/O
;
; CALLING SEQUENCE:
;
; IDL> nCDFObject = Obj_New('NCDF_FILE', filename)
;
; ARGUMENTS:
;
; filename: The name of a netCDF file to read, write to, or browse.
;
; KEYWORD PARAMETERS:
;
; ALERT: Set this keyword if you wish to have alert from the object's error logger.
; Input. Default is 1.
;
; BROWSE: If this keyword is set, the Browse Window is invoked as soon
; as the object is initiated. Input. Default is 0.
;
; CLOBBER: Set this keyword if you are opening a netCDF file that already exists and
; you want to overwrite the existing file. Input. Default is 0.
;
; CREATE: Set this keyword if you wish to create a new netCDF file to write
; into. Input. Default is 0, which means the file will be opened as
; "read-only".
;
; DELETE_ON_DESTROY: Set this keyword if you wish to delete the error log file when
; the ErrorLogger object is destroyed. This will only happen if the ErrorLogger
; object is not in an error state. Input. Default is 1.
;
; MODIFY: Set this keyword if you wish to modify (write to) a file you are opening.
; If not set, the file will be opened as "read-only".
;
;
; METHODS:
;
; The following methods are available. Each is documented in front of the method.
;
; ncdfObject -> Browse
; ncdfObject -> CopyVarAttrTo, varName, attrName, destObj
; ncdfObject -> CopyVarDataTo, varName, destObj, COUNT=count, OFFSET=offset, STRIDE=stride
; ncdfObject -> CopyVarDefTo, varName, destObj
; ncdfObject -> CopyGlobalAttrTo, attrName, destObj
; ncdfObject -> CopyDimTo, dimName, destObj
; dimNames = ncdfObject -> GetDimNames(COUNT=dimCount)
; dimValue = ncdfObject -> GetDimValue(dimName)
; fileID = ncdfObject -> GetFileID()
; globalAttrNames = ncdfObject -> GetGlobalAttrNames(COUNT=attrCount)
; attrValue = ncdfObject -> GetGlobalAttrValue(attrName, DATATYPE=datatype)
; ncdfObject -> GetProperty, ....
; property = ncdfObject -> GetProperty(thisProperty)
; varAttrNames = ncdfObject -> GetVarAttrNames(varName, COUNT=attrCount)
; varAttrValue = ncdfObject -> GetVarAttrValue(varName, varAttrName, COUNT=attrCount)
; varNames = ncdfObject -> GetVarNames(COUNT=varCount)
; varData = ncdfObject -> GetVarData(varName, COUNT=count, OFFSET=offset, STRIDE=stride)
; answer = ncdfObject -> HasGlobalAttr(attrName, OBJECT=object)
; answer = ncdfObject -> HasDim(dimName, OBJECT=object)
; answer = ncdfObject -> HasVar(varName, OBJECT=object)
; answer = ncdfObject -> HasVarAttr(varName, attrName, OBJECT=object)
; ncdfObject -> PrintFileInfo
; ncdfObject -> ParseFile
; ncdfObject -> SetMode, DEFINE=define, DATA=data
; ncdfObject -> WriteVarData, varName, data, COUNT=count, OFFSET=offset, STRIDE=stride
; ncdfObject -> WriteVarDef, varName, dimNames, DATATYPE=datatype, VAROBJ=varObj
; ncdfObject -> WriteDim, dimName, dimSize, UNLIMITED=unlimited
; ncdfObject -> WriteGlobalAttr, attrName, attrValue, DATATYPE=datatype
; ncdfObject -> WriteVarAttr, attrName, attrValue, varObj, DATATYPE=datatype
;
; NOTES:
;
; Note that all variable, attribute, and dimension names in a netCDF file are CASE SENSITIIVE!!
; Thus, it is a good idea to use the methods provided in this object to obtain and examine
; information in the file, as these names are handled in a case sensitive manner.
;
; Whenever you are creating a new netCDF file, you should try to create the file in
; the following way.
; 1. Create your global attributes.
; 2. Create the dimensions you will be using to describe the variables.
; 3. Define the variables. To do this correctly, dimensions MUST be defined.
; 4. Define variable attributes.
; 5. Load your variables with data.
;
; Note that the data type of the _FillValue variable attribute MUST match the
; data type of the variable data. Otherwise, you will have MANY problems! This
; is a common source of error.
;
; Note that in almost all cases where you see the names "varName", "dimName", or
; "attrName" used as input variables, you can substitute the proper object
; reference in place of the actual name. In other words, you could get the value
; of a variable attribute by doing something like this:
;
; check = ncdfObject -> HasAttr('history', OBJECT=attrObj)
; IF check THEN attrValue = ncdfObject -> GetGlobalAttrValue(attrObj)
;
; as opposed to this:
;
; IF check THEN attrValue = ncdfObject -> GetGlobalAttrValue('history')
; EXAMPLE:
;
; IDL> filename = 'example.nc'
; IDL> ncdfObj = Obj_New('NCDF_FILE', filename)
; IDL> ncdfObj -> Browse
; IDL> Obj_Destroy, ncdfObj
;
; MODIFICATION HISTORY:
; Written by: David W. Fanning, 3 Feb 2010, using (stealing, really) plenty of ideas
; from Mark Hadfield's Motley Library. Mark's mghncfile object is terrific, but it
; had a number of limitations for my particular application, which I have attemped
; to correct in my version of the software. But I wouldn't have even attempted this
; had Mark not blazed the trail and Matt Savoie not insisted that I look at Mark's
; wonderful library.
; Changes in the way dimensions with a zero length are handled. 11 Feb 2010, DWF.
; Added GetVarInfo method. 20 March 2010. DWF.
; Added MISSINGINIDCES and FILLVALUE output keywords to GetVarData method. 20 March 2010. DWF.
; Added output keywords SCALE_FACTOR, ADD_OFFSET, and DATATYPE to GetVarData method
; so that these values can be obtained with the data. 29 Apr 2010. DWF.
; I changed "missingValue" to "fillValue" some time ago, but I missed one in
; the GetVarData method. Fixed. 7 June 2010. DWF.
; Used the undefine procedure OBJ_DELETE, rather than OBJ_DESTROY. Sheesh! 18 June 2010. DWF.
; Added NETCDF4_FORMAT keyword. 13 Feb 2012. DWF.
; Added a bunch of new IDL 8.0 and 8.1 keyword to the WriteVarDef method to allow
; access to these keywords in NCDF_VarDef. Also modified the NETCDF4_FORMAT keyword
; to apply only in IDL versions 8.0 and higher. 21 Feb 2012. DWF.
; Small typo fixed in setting CHAR datatype for IDL 8.1 and higher. 22 May 2013. DWF.
; Typo (CONTINUOUS->CONTIGUOUS) fixed in WriteDefVar method. 30 July 2013. DWF.
; Modified CopyVarDefTo method to allow new NCDF4 keywords. 30 July 2013. DWF.
; Added DelGlobalAttr method to allow deletion of global attributes. 11 Jan 2014. DWF.
; Found typo in UBYTE variable code, which I fixed. 12 Fef 2016. DWF.
;
;-
;******************************************************************************************;
; Copyright (c)2010, by Fanning Software Consulting, Inc. ;
; All rights reserved. ;
; ;
; Redistribution and use in source and binary forms, with or without ;
; modification, are permitted provided that the following conditions are met: ;
; ;
; * Redistributions of source code must retain the above copyright ;
; notice, this list of conditions and the following disclaimer. ;
; * Redistributions in binary form must reproduce the above copyright ;
; notice, this list of conditions and the following disclaimer in the ;
; documentation and/or other materials provided with the distribution. ;
; * Neither the name of Fanning Software Consulting, Inc. nor the names of its ;
; contributors may be used to endorse or promote products derived from this ;
; software without specific prior written permission. ;
; ;
; THIS SOFTWARE IS PROVIDED BY FANNING SOFTWARE CONSULTING, INC. ''AS IS'' AND ANY ;
; EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES ;
; OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT ;
; SHALL FANNING SOFTWARE CONSULTING, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, ;
; INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED ;
; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; ;
; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ;
; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ;
; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;
; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;
;******************************************************************************************;
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::Browse
;
; Purpose:
;
; Allows the user to browse the netCDF file interactively. Variables, attributes,
; and dimensions can be saved to the main IDL level or command line where they can
; be manipulated further.
;
; Method Syntax:
;
; obj -> Browse
;
; Auguments:
;
; None.
;
; Keywords:
;
; TITLE: A text string that will be the title of the browser window. (Optional)
; XOFFSET: The X offset of the top-left corner of the browser. (Optional)
; YOFFSET: The Y offset of the top-left corner of the browser. (Optional)
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::Browse, TITLE=title, XOFFSET=xoffset, YOFFSET=yoffset
NCDF_Browser, self.filename, $
/NO_NEW_FILE, $
TITLE=title, $
XOFFSET=xoffset, $
YOFFSET=yoffset
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::Close_File
;
; Purpose:
;
; Closes the netCDF file, if open.
;
; Method Syntax:
;
; obj -> Browse
;
; Auguments:
;
; None.
;
; Keywords:
;
; None.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::Close_File
IF self.fileID GT 0 THEN NCDF_Close, self.fileID
self.fileID = -1
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::CreateVarObj
;
; Purpose:
;
; Creates a NCDF_Variable object and adds it the the variable container.
;
; Method Syntax:
;
; obj -> CreateVarObj, varName
;
; Auguments:
;
; varName: The case sensitive name of the variable.
;
; Keywords:
;
; None.
;
; Notes: An internal method.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::CreateVarObj, varName
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN
ENDIF
varObj = Obj_New('NCDF_Variable', varName, self)
self.vars -> Add, varObj
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::CreateAttrObj
;
; Purpose:
;
; Creates a NCDF_Attribute object and adds it the the attribute container.
;
; Method Syntax:
;
; obj -> CreateAttrObj, attrName
;
; Auguments:
;
; attrName: The case sensitive name of the attribute.
;
; Keywords:
;
; None.
;
; Notes: An internal method.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::CreateAttrObj, attrName
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN
ENDIF
attrObj = Obj_New('NCDF_Attribute', attrName, self)
self.attrs -> Add, attrObj
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::CreateDimObj
;
; Purpose:
;
; Creates a NCDF_Dimension object and adds it the the dimension container.
;
; Method Syntax:
;
; obj -> CreateDimObj, dimensionName
;
; Auguments:
;
; dimensionName: The case sensitive name of the dimension.
;
; Keywords:
;
; None.
;
; Notes: An internal method.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::CreateDimObj, dimensionName
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN
ENDIF
dimObj = Obj_New('NCDF_Dimension', dimensionName, self)
self.dims -> Add, dimObj
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::CopyVarAttrTo
;
; Purpose:
;
; Copies a variable attribute from this object to another NCDF_FILE object.
;
; Method Syntax:
;
; obj -> CopyVarAttrTo, varName, attrName, destObj
;
; Auguments:
;
; varName: The case sensitive name of the variable you wish to copy.
; attrName: The case sensitive name of the variable attribute you wish to copy.
; destObj: The object reference of a NCDF_FILE object you wish to copy
; the variable attribute to.
;
; Keywords:
;
; None.
;
; Notes: The variable will have had to have been previously defined for the file.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::CopyVarAttrTo, varName, attrName, destObj
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN
ENDIF
IF N_Elements(varName) EQ 0 THEN $
Message, 'A variable name or object reference is required.'
IF N_Elements(attrName) EQ 0 THEN $
Message, 'An attribute name or object reference is required.'
; Make sure the file has been parsed.
IF ~self.fileHasBeenParsed THEN self -> ParseFile
; Were you passed the name of a variable or a variable object?
CASE Size(varName, /TNAME) OF
'STRING': BEGIN
varObj = self.vars -> FindByName(varName, COUNT=varCount, /CASE_SENSITIVE)
IF varCount EQ 0 THEN $
Message, 'Cannot find a variable object with name ' + varName + '.'
IF ~Obj_Valid(varObj) THEN $
Message, 'Invalid object with name "' + varName + '" has been found.'
END
'OBJREF': BEGIN
varObj = varName
END
ELSE: Message, 'Input variable name or object is the wrong data type.'
ENDCASE
; Get and return the variable's attribute value.
attrValue = varObj -> GetAttrValue(attrName, DATATYPE=attrDataType)
; Write the variable attribute in the destination object.
destObj -> WriteVarAttr, varName, attrName, attrValue, DATATYPE=attrDataType
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::CopyVariableTo
;
; Purpose:
;
; The NCDF_File object has methods to do low-level manipulation of netCDF files, but
; this method is a high-level method to copy a variable from one file to another.
; This method will find all of the variable parts it needs in the file (dimensions,
; variable definition, variable attributes, and even variable data) and will copy
; everything it finds (if needed!) into the destination file. This eliminates a lot
; of the druge work that goes into understanding exactly how everything works.
;
; Method Syntax:
;
; obj -> CopyVariableTo, varName, destObj
;
; Auguments:
;
; varName: The case sensitive name of the variable you wish to copy
; the variable definition from.
; destObj: The object reference of a NCDF_FILE object you wish to copy the
; variable definition to.
;
; Keywords:
;
; NODATA: If this keyword is set, the variable's data is not copied to the file.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::CopyVariableTo, varName, destObj
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN
ENDIF
IF N_Elements(varName) EQ 0 THEN $
Message, 'A variable name or object reference is required.'
IF N_Elements(destObj) EQ 0 THEN $
Message, 'A destination NCDF_FILE object is required.'
IF ~Obj_Valid(destObj) THEN $
Message, 'The destination NCDF_FILE object is not valid.'
IF ~destObj -> GetProperty('Writable') THEN $
Message, 'The destination NCDF_FILE object is not writeable.'
; Make sure the file has been parsed.
IF ~self.fileHasBeenParsed THEN self -> ParseFile
; Were you passed the name of a variable or a variable object?
CASE Size(varName, /TNAME) OF
'STRING': BEGIN
varObj = self.vars -> FindByName(varName, COUNT=strCount, /CASE_SENSITIVE)
IF strCount EQ 0 THEN Message, 'Cannot find a variable object with name ' + varName + '.'
IF ~Obj_Valid(varObj) THEN Message, 'Invalid object with name "' + varName + '" has been found.'
END
'OBJREF': BEGIN
varObj = varName
END
ELSE: Message, 'Input variable name or object is the wrong data type.'
ENDCASE
; Start with this variable's dimensions. Have these been defined
; for the variable in the destination object? If not, define them.
dimNames = VarObj -> GetDimNames(COUNT=dimCount)
FOR j=0,dimCount-1 DO BEGIN
thisName = dimNames[j]
IF ~destObj->HasDim(thisName) THEN self -> CopyDimTo, thisName, destObj
ENDFOR
; Has this variable been defined in the destination object. ? If not, do it.
IF ~destObj->HasVar(varName) THEN self -> CopyVarDefTo, varName, destObj
; Does the variable have attributes? Copy these, too.
varAttrNames = varObj -> GetAttrNames(COUNT=attrCount)
FOR j=0,attrCount-1 DO BEGIN
thisAttrName = varAttrNames[j]
IF ~destObj->HasVarAttr(varName, thisAttrName) THEN $
self -> CopyVarAttrTo, varName, thisAttrName, destObj
ENDFOR
; Finally, copy the variable's data to the destination object.
IF ~Keyword_Set(nodata) THEN self -> CopyVarDataTo, varName, destObj
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::CopyVarDataTo
;
; Purpose:
;
; Copies variable data from this object to another NCDF_FILE object.
;
; Method Syntax:
;
; obj -> CopyVarDataTo, varName, destObj, COUNT=count, OFFSET=offset, STRIDE=stride
;
; Auguments:
;
; varName: The case sensitive name of the variable you wish to copy the data from.
; destObj: The object reference of a NCDF_FILE object you wish to copy the data to.
;
; Keywords:
;
; COUNT: An optional vector containing the counts to be used in reading the
; variable. Count is a 1-based vector with an element for each dimension.
; The default matches the size of the variable so that all data is
; written out.
; OFFSET: An optional vector containing the starting position for the read.
; The default start position is [0, 0, ...].
; STRIDE: An optional vector containing the strides, or sampling intervals,
; between accessed values of the netCDF variable. The default stride
; vector is that for a contiguous read, [1, 1, ...].
;
; Notes: The variable will have had to have been previously defined for the file.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::CopyVarDataTo, varName, destObj, COUNT=count, OFFSET=offset, STRIDE=stride
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN
ENDIF
IF N_Elements(varName) EQ 0 THEN $
Message, 'A variable name or object reference is required.'
IF N_Elements(destObj) EQ 0 THEN $
Message, 'A destination NCDF_FILE object is required.'
IF ~Obj_Valid(destObj) THEN $
Message, 'The destination NCDF_FILE object is not valid.'
IF ~destObj -> GetProperty('Writable') THEN $
Message, 'The destination NCDF_FILE object is not writeable.'
; Make sure the file has been parsed.
IF ~self.fileHasBeenParsed THEN self -> ParseFile
; Were you passed the name of a variable or a variable object?
CASE Size(varName, /TNAME) OF
'STRING': BEGIN
varObj = self.vars -> FindByName(varName, COUNT=strCount, /CASE_SENSITIVE)
IF strCount EQ 0 THEN Message, 'Cannot find a variable object with name ' + varName + '.'
IF ~Obj_Valid(varObj) THEN Message, 'Invalid object with name "' + varName + '" has been found.'
END
'OBJREF': BEGIN
varObj = varName
END
ELSE: Message, 'Input variable name or object is the wrong data type.'
ENDCASE
; Gather information.
data = varObj ->GetValue(COUNT=count, OFFSET=offset, STRIDE=stride)
; Copy the information to the destination object.
destObj -> WriteVarData, varName, data, COUNT=count, OFFSET=offset, STRIDE=stride
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::CopyVarDefTo
;
; Purpose:
;
; Copies a variable definition from this object to another NCDF_FILE object.
; Note that dimension IDs are required to define a variable. This method assumes
; that whatever dimensions are defined for the variable you are copying are already
; defined in the file object you are copying this variable to.
;
; Method Syntax:
;
; obj -> CopyVarDefTo, varName, destObj
;
; Auguments:
;
; varName: The case sensitive name of the variable you wish to copy
; the variable definition from.
; destObj: The object reference of a NCDF_FILE object you wish to copy the
; variable definition to.
;
; Keywords:
;
; CHUNK_DIMENSIONS: Set this keyword equal to a vector containing the chunk dimensions for the variable.
; A new NetCDF variable is chunked by default, using a default chunk value that is
; the full dimension size for limited dimensions, and 1 for unlimited dimensions.
; CHUNK_DIMENSIONS must have the same number of elements as the number of dimensions
; specified by Dim. If the CONTIGUOUS keyword is set, the value of the
; CHUNK_DIMENSIONS keyword is ignored. Available only in IDL 8.0 and higher.
; GZIP: Set this keyword to an integer between zero and nine to specify the level
; of GZIP compression applied to the variable. Lower compression values result
; in faster but less efficient compression. This keyword is ignored if the
; CHUNK_DIMENSIONS keyword is not set. This keyword is ignored if the CONTIGUOUS
; keyword is set. If the GZIP keyword is set, the CONTIGUOUS keyword is ignored.
; You can only use GZIP compression with NCDF 4 files. Available only in
; IDL 8.0 and higher.
; SHUFFLE: Set this keyword to apply the shuffle filter to the variable. If the GZIP
; keyword is not set, this keyword is ignored. The shuffle filter de-interlaces blocks
; of data by reordering individual bytes. Byte shuffling can sometimes
; increase compression density because bytes in the same block positions
; often have similar values, and grouping similar values together often
; leads to more efficient compression. Available only in IDL 8.0 and higher.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::CopyVarDefTo, varName, destObj, $
CHUNK_DIMENSIONS=chunk_dimensions, $
GZIP=gzip, $
SHUFFLE=shuffle
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN
ENDIF
IF N_Elements(varName) EQ 0 THEN $
Message, 'A variable name or object reference is required.'
IF N_Elements(destObj) EQ 0 THEN $
Message, 'A destination NCDF_FILE object is required.'
IF ~Obj_Valid(destObj) THEN $
Message, 'The destination NCDF_FILE object is not valid.'
IF ~destObj -> GetProperty('Writable') THEN $
Message, 'The destination NCDF_FILE object is not writeable.'
; Make sure the file has been parsed.
IF ~self.fileHasBeenParsed THEN self -> ParseFile
; Were you passed the name of a variable or a variable object?
CASE Size(varName, /TNAME) OF
'STRING': BEGIN
varObj = self.vars -> FindByName(varName, COUNT=varCount, /CASE_SENSITIVE)
IF varCount EQ 0 THEN $
Message, 'Cannot find a variable object with name ' + varName + '.'
IF ~Obj_Valid(varObj) THEN $
Message, 'Invalid object with name "' + varName + '" has been found.'
END
'OBJREF': BEGIN
varObj = varName
END
ELSE: Message, 'Input variable name or object is the wrong data type.'
ENDCASE
; Gather information.
dimNames = varObj -> GetDimNames(COUNT=dimCount)
datatype = varObj -> GetProperty('DATATYPE')
; See if you can match the names of the dimensions with the dimensions
; that are current defined for the destination object.
IF dimCount GT 0 THEN BEGIN
destDimContainer = destObj -> GetProperty('DIMS')
dimIDs = LonArr(dimCount)
FOR j=0,dimCount-1 DO BEGIN
thisObj = destDimContainer -> FindByName(dimNames[j], COUNT=found)
IF found EQ 0 THEN Message, 'Cannot find a dimension named "' + $
dimNames[j] + '" in the destination object.'
dimIDs[j] = thisObj -> GetID()
ENDFOR
ENDIF
; Copy the information to the destination object.
IF dimCount EQ 0 THEN BEGIN
destObj -> WriteVarDef, varName, DATATYPE=datatype, $
CHUNK_DIMENSIONS=chunk_dimensions, $
GZIP=gzip, $
SHUFFLE=shuffle
ENDIF ELSE BEGIN
destObj -> WriteVarDef, varName, dimIDs, DATATYPE=datatype, $
CHUNK_DIMENSIONS=chunk_dimensions, $
GZIP=gzip, $
SHUFFLE=shuffle
ENDELSE
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::CopyGlobalAttrTo
;
; Purpose:
;
; Copies a global attribute from this object to another NCDF_FILE object.
;
; Method Syntax:
;
; obj -> CopyGlobalAttrTo, attrName, destObj
;
; Auguments:
;
; attrName: The case sensitive name of the global attribute you wish to copy
; to the destination object.
; destObj: The object reference of a NCDF_FILE object you wish to copy the
; variable definition to.
;
; Keywords:
;
; None.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::CopyGlobalAttrTo, attrName, destObj
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN
ENDIF
IF N_Elements(attrName) EQ 0 THEN $
Message, 'A global attrubute name or object reference is required.'
IF N_Elements(destObj) EQ 0 THEN $
Message, 'A destination NCDF_FILE object is required.'
IF ~Obj_Valid(destObj) THEN $
Message, 'The destination NCDF_FILE object is not valid.'
IF ~destObj -> GetProperty('Writable') THEN $
Message, 'The destination NCDF_FILE object is not writeable.'
; Make sure the file has been parsed.
IF ~self.fileHasBeenParsed THEN self -> ParseFile
; Were you passed the name of an attribute or an attribute object?
CASE Size(attrName, /TNAME) OF
'STRING': BEGIN
attrObj = self.attrs -> FindByName(attrName, COUNT=attrCount, /CASE_SENSITIVE)
IF attrCount EQ 0 THEN Message, 'Cannot find a dimension object with name ' + attrName + '.'
IF ~Obj_Valid(attrObj) THEN Message, 'Invalid object with name "' + attrName + '" has been found.'
END
'OBJREF': BEGIN
attrObj = attrName
END
ELSE: Message, 'Input global attribute name or object is the wrong data type.'
ENDCASE
; Gather information.
attrValue = attrObj -> GetValue()
dataType = attrObj -> GetProperty('DATATYPE')
; Copy the information to the destination object.
destObj -> WriteGlobalAttr, attrName, attrValue, DATATYPE=datatype
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::CopyDimTo
;
; Purpose:
;
; Copies a dimension from this object to another NCDF_FILE object.
;
; Method Syntax:
;
; obj -> CopyDimTo, dimName, destObj
;
; Auguments:
;
; dimName: The case sensitive name of the dimension you wish to copy to the
; destination object.
; destObj: The object reference of a NCDF_FILE object you wish to copy the
; dimension to.
;
; Keywords:
;
; None.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::CopyDimTo, dimName, destObj
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN
ENDIF
IF N_Elements(dimName) EQ 0 THEN $
Message, 'A dimension name or object reference is required.'
IF N_Elements(destObj) EQ 0 THEN $
Message, 'A destination NCDF_FILE object is required.'
IF ~Obj_Valid(destObj) THEN $
Message, 'The destination NCDF_FILE object is not valid.'
IF ~destObj -> GetProperty('Writable') THEN $
Message, 'The destination NCDF_FILE object is not writeable.'
; Make sure the file has been parsed.
IF ~self.fileHasBeenParsed THEN self -> ParseFile
; Were you passed the name of a dimension or an dimenison object?
CASE Size(dimName, /TNAME) OF
'STRING': BEGIN
dimObj = self.dims -> FindByName(dimName, COUNT=dimCount, /CASE_SENSITIVE)
IF dimCount EQ 0 THEN $
Message, 'Cannot find a dimension object with name ' + dimName + '.'
IF ~Obj_Valid(dimObj) THEN $
Message, 'Invalid object with name "' + dimName + '" has been found.'
END
'OBJREF': BEGIN
dimObj = dimName
END
ELSE: Message, 'Input dimension name or object is the wrong data type.'
ENDCASE
; Gather information.
dimSize = dimObj -> GetValue()
unlimited = dimObj -> GetProperty('UNLIMITED')
; Copy the information to the destination object.
destObj -> WriteDim, dimName, dimSize, UNLIMITED=unlimited
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::DelGlobalAttr
;
; Purpose:
;
; Deletes a global attribute from this netCDF file.
;
; Method Syntax:
;
; obj -> DelGlobalAttr, attrName
;
; Auguments:
;
; attrName: The case sensitive name of the global attribute you wish to delete.
;
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::DelGlobalAttr, attrName
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN
ENDIF
; The file has to be writable to delete a global attribute.
IF ~self.writable THEN $
Message, 'Cannot delete a global attribute from a READ-ONLY file.'
; Check parameters.
IF N_Elements(attrName) EQ 0 THEN Message, 'The attribute name is required.'
; Make sure the attribute is available. Another possible behavior
; would be to do nothing and return instead of throwing an error
check = self -> HasGlobalAttr(attrName, OBJECT=attrObj)
IF ~check THEN Message, 'The attribute name is not present in the file or is spelled incorrectly: ' + attrName
; Put the file into define mode
self -> SetMode, /DEFINE
; Delete the attribute from the file.
NCDF_ATTDEL, self.fileID, attrName, /GLOBAL
; We should also remove the attribute object from the container
self.attrs -> Remove, attrObj
Undefine, attrObj
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::GetDimNames
;
; Purpose:
;
; Returns the names of all the dimensions in the file.
;
; Method Syntax:
;
; dimNames = obj -> GetDimNames(COUNT=dimCount)
;
; Auguments:
;
; None.
;
; Keywords:
;
; COUNT: An output keyword that reports the number of dimension names found.
;
; Return Value:
;
; dimNames: A string array containing the names of the dimensions in the file.
;
;------------------------------------------------------------------------------------------;
FUNCTION NCDF_File::GetDimNames, COUNT=dimCount
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN, ""
ENDIF
; Make sure the file has been parsed.
IF ~self.fileHasBeenParsed THEN self -> ParseFile
; Count the number of dimension objects.
dimCount = self.dims -> Count()
; If there are no dimensions, return null string.
IF dimCount EQ 0 THEN RETURN, ""
dimNames = StrArr(dimCount)
FOR j=0,dimCount-1 DO BEGIN
thisObj = self.dims -> Get(POSITION=j)
dimNames[j] = thisObj -> GetName()
ENDFOR
; Return a scalar if necessary.
IF N_Elements(dimNames) EQ 1 THEN dimNames = dimNames[0]
RETURN, dimNames
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::GetDimValue
;
; Purpose:
;
; Returns the value (the size) of a dimension.
;
; Method Syntax:
;
; dimValue = obj -> GetDimValue(dimName)
;
; Auguments:
;
; dimName: The case sensitive name of the dimension you want the value (size) of.
;
; Keywords:
;
; None.
;
; Return Value:
;
; dimValue: An integer that gives the size of the dimension.
;
;------------------------------------------------------------------------------------------;
FUNCTION NCDF_File::GetDimValue, dimName
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN, ""
ENDIF
IF N_Elements(dimName) EQ 0 THEN $
Message, 'A dimension name or object reference is required.'
; Make sure the file has been parsed.
IF ~self.fileHasBeenParsed THEN self -> ParseFile
; Were you passed the name of a dimension or dimension object?
CASE Size(dimName, /TNAME) OF
'STRING': BEGIN
dimObj = self.dims -> FindByName(dimName, COUNT=dimCount, /CASE_SENSITIVE)
IF dimCount EQ 0 THEN $
Message, 'Cannot find a dimension object with name ' + dimName + '.'
IF ~Obj_Valid(dimObj) THEN $
Message, 'Invalid object with name "' + dimName + '" has been found.'
END
'OBJREF': BEGIN
dimObj = dimName
END
ELSE: Message, 'Input dimension name or object is the wrong data type.'
ENDCASE
; Get the data.
dimData = dimObj -> GetValue()
RETURN, dimData
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::GetFileID
;
; Purpose:
;
; Returns the netCDF file identifier.
;
; Method Syntax:
;
; fileID = obj -> GetFileID()
;
; Auguments:
;
; None.
;
; Keywords:
;
; None.
;
; Return Value:
;
; fileID: The netCDF file identifier that is required to interact with the file. ;
;
;------------------------------------------------------------------------------------------;
FUNCTION NCDF_File::GetFileID
RETURN, self.fileID
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::GetGlobalAttrNames
;
; Purpose:
;
; Returns the names of all the global attributes in the file.
;
; Method Syntax:
;
; attrNames = obj -> GetGlobalAttrNames(COUNT=attrCount)
;
; Auguments:
;
; None.
;
; Keywords:
;
; COUNT: An output keyword that reports the number of dimension names found.
;
; Return Value:
;
; attrNames: A string array containing the names of the global attributes in the file.
;
;------------------------------------------------------------------------------------------;
FUNCTION NCDF_File::GetGlobalAttrNames, COUNT=attrCount
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN, ""
ENDIF
; Make sure the file has been parsed.
IF ~self.fileHasBeenParsed THEN self -> ParseFile
; Count the number of global attribute objects.
attrCount = self.attrs -> Count()
; If there are no global attributes, return null string.
IF attrCount EQ 0 THEN RETURN, ""
attrNames = StrArr(attrCount)
FOR j=0,attrCount-1 DO BEGIN
thisObj = self.attrs -> Get(POSITION=j)
attrNames[j] = thisObj -> GetName()
ENDFOR
; Return a scalar if necessary.
IF N_Elements(attrNames) EQ 1 THEN attrNames = attrNames[0]
RETURN, attrNames
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::GetGlobalAttrValue
;
; Purpose:
;
; Returns the value of a global attributes in the file.
;
; Method Syntax:
;
; attrValue = obj -> GetGlobalAttrValue(attrName, DATATYPE=datatype)
;
; Auguments:
;
; attrName: The case sensitive name of a global attribute.
;
; Keywords:
;
; DATATYPE: An output keyword that contains the data type of the global attribute.
;
; Return Value:
;
; attrValue: The value of the global attribute.
;
;------------------------------------------------------------------------------------------;
FUNCTION NCDF_File::GetGlobalAttrValue, attrName, DATATYPE=datatype
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN, ""
ENDIF
IF N_Elements(attrName) EQ 0 THEN $
Message, 'A global attribute name or object reference is required.'
; Make sure the file has been parsed.
IF ~self.fileHasBeenParsed THEN self -> ParseFile
; Were you passed the name of an attribute or an attribute object?
CASE Size(attrName, /TNAME) OF
'STRING': BEGIN
attrObj = self.attrs -> FindByName(attrName, COUNT=attrCount, /CASE_SENSITIVE)
IF attrCount EQ 0 THEN $
Message, 'Cannot find an attribute object with name ' + attrName + '.'
IF ~Obj_Valid(attrObj) THEN $
Message, 'Invalid object with name "' + attrName + '" has been found.'
END
'OBJREF': BEGIN
attrObj = attrName
END
ELSE: Message, 'Input attribute name or object is the wrong data type.'
ENDCASE
; Get the data.
attrData = attrObj -> GetValue(DATATYPE=datatype)
RETURN, attrData
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::GetProperty
;
; Purpose:
;
; Returns various properties of the object via output keyword parameters.
;
; Method Syntax:
;
; obj -> GetProperty, ....
;
; Auguments:
;
; None.
;
; Keywords:
;
; ALL: If set, return all properties of the object in a structure variable.
; ATTRNAMES: This output variable returns all the global attribute names.
; DEFINE: This output variable returns a 1 if the file is in DEFINE mode.
; DIMNAMES: This output variable returns all the dimension names.
; ERRORLOGGER: This output variable returns the errorlogger object.
; FILEID: This output variable returns the netCDF file identifier.
; FILENAME: This output variable returns the name of the netCDF file.
; FILEHASBEENPARSED: This output variable returns a 1 if the file has been parsed.
; N_ATTRS: This output variable returns the number of global attributes in
; the file.
; N_DIMS: This output variable returns the number of dimensions in the file.
; N_VARS: This output variable returns the number of variables in the file.
; UNLIMITED: This output variable returns a vector of 0s and 1s, one element
; for each dimension, indicating if the dimension is unlimited or not.
; VARNAMES: This output variable returns the names of variables in the file.
; WRITEABLE: This output variable returns a 1 if the file is writable.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::GetProperty, $
ALL=all, $
ATTRNAMES=attrnames, $
DEFINE=define, $
DIMNAMES=dim_names, $
DIMENSIONS=dimensions, $
ERRORLOGGER=errorLogger, $
FILEID=fileID, $
FILENAME=filename, $
FILEHASBEENPARSED=fileHasBeenParsed, $
N_DIMS=n_dims, $
N_VARS=n_vars, $
N_ATTRS=n_attrs, $
UNLIMITED=unlimited, $
VARNAMES=varnames, $
WRITABLE=writable
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN
ENDIF
; Make sure the file has been parsed.
IF ~self.fileHasBeenParsed THEN self -> ParseFile
; Easily returned information.
errorLogger = self.errorLogger
filename = self.filename
fileID = self.fileID
fileHasBeenParsed = self.fileHasBeenParsed
define = self.define
writable = self.writable
; What's in the file?
info = NCDF_Inquire(self.fileID)
n_dims = info.ndims
n_vars = info.nvars
n_attrs = info.ngatts
; Get the attribute names, if needed.
IF Arg_Present(attrnames) || Arg_Present(all) THEN BEGIN
IF n_attrs EQ 0 THEN BEGIN
attrnames = ""
ENDIF ELSE BEGIN
attrnames = StrArr(n_attrs)
FOR j=0,n_attrs-1 DO BEGIN
thisAttr = self.attrs -> Get(POSITION=j)
attrnames[j] = thisAttr -> GetProperty('NAME')
ENDFOR
ENDELSE
ENDIF
; Get the dimension names, and dimension IDs, if needed.
IF Arg_Present(dimNames) || Arg_Present(dimensions) || Arg_Present(all) THEN BEGIN
IF n_dims EQ 0 THEN BEGIN
dimNames = ""
dimensions = 0
unlimited = 0
ENDIF ELSE BEGIN
dimNames = StrArr(n_dims)
dimensions = LonArr(n_dims)
unlimited = BytArr(n_dims)
FOR j=0, n_dims-1 DO BEGIN
dimsObj = self.dims -> Get(POSITION=j)
dimNames[j] = dimsObj -> GetProperty('NAME')
dimensions[j] = dimsObj -> GetProperty('SIZE')
unlimited[j] = dimsObj -> GetProperty('UNLIMITED')
ENDFOR
ENDELSE
ENDIF
; Get the variable names, if needed.
IF Arg_Present(varNames) || Arg_Present(all) THEN BEGIN
IF n_vars EQ 0 THEN BEGIN
varNames = ""
ENDIF ELSE BEGIN
varNames = StrArr(n_vars)
FOR j=0,n_vars-1 DO BEGIN
thisVar = self.vars -> Get(POSITION=j)
varNames[j] = thisVar -> GetProperty('NAME')
ENDFOR
ENDELSE
ENDIF
IF Arg_Present(all) THEN BEGIN
all = { ATTRNAMES:attrnames, $
DEFINE:define, $
DIMNAMES:dim_names, $
DIMENSIONS:dimensions, $
ERRORLOGGER:errorLogger, $
FILEID:fileID, $
FILENAME:filename, $
FILEHASBEENPARSED:fileHasBeenParsed, $
N_DIMS:n_dims, $
N_VARS:n_vars, $
N_ATTRS:n_attrs, $
UNLIMITED:unlimited, $
VARNAMES:varnames, $
WRITABLE:writable }
ENDIF
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::GetProperty
;
; Purpose:
;
; Returns various properties of the object one at a time. This is a shorthand and
; generic way to get the value of an object's "properties", which are defined as
; the IDL variables in the object's class structure.
;
; Method Syntax:
;
; propertyValue = obj -> GetProperty(thisProperty)
;
; Auguments:
;
; thisProperty: A string variable that is equivalent to a field in the object's
; class structure. See the *__DEFINE procedure for which properties
; can be returned. The property is case insensitive.
;
; Keywords:
;
; None.
;
; Return Value:
;
; propertyValue: The value of a particular object property. Note that pointer
; properties will return the variable the pointer points to.
;
;------------------------------------------------------------------------------------------;
FUNCTION NCDF_File::GetProperty, thisProperty
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN, 0
ENDIF
; Get the self structure as a structure, rather than as an object.
Call_Procedure, StrLowCase(Obj_Class(self)) + '__define', classStruct
; Find the property in this class structure.
index = Where(StrPos(Tag_Names(classStruct), StrUpCase(thisProperty)) EQ 0, count)
index = index[0]
; What happened?
CASE count OF
0: Message, 'Property ' + StrUpCase(thisProperty) + ' could not be found.'
1: propertyValue = self.(index)
ELSE: Message, 'Ambiguous property. Use more characters to specify it.'
ENDCASE
; If this is a pointer, you want the thing pointed to.
IF Size(propertyValue, /TNAME) EQ 'POINTER' THEN propertyValue = *propertyValue
RETURN, propertyValue
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::GetVarAttrNames
;
; Purpose:
;
; Returns the names of variable attributes in the file.
;
; Method Syntax:
;
; attrNames = obj -> GetVarAttrNames(varName, COUNT=varAttrCount)
;
; Auguments:
;
; varName: The case sensitive name of the variable you want the attributes of.
;
; Keywords:
;
; COUNT: The number of variable attributes found.
;
; Return Value:
;
; attrNames: A string array containing the names of the variable attributes.
;
;------------------------------------------------------------------------------------------;
FUNCTION NCDF_File::GetVarAttrNames, varName, COUNT=varAttrCount
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN, ""
ENDIF
IF N_Elements(varName) EQ 0 THEN $
Message, 'A variable name or object reference is required.'
; Make sure the file has been parsed.
IF ~self.fileHasBeenParsed THEN self -> ParseFile
; Were you passed the name of a variable or a variable object?
CASE Size(varName, /TNAME) OF
'STRING': BEGIN
varObj = self.vars -> FindByName(varName, COUNT=varCount, /CASE_SENSITIVE)
IF varCount EQ 0 THEN $
Message, 'Cannot find a variable object with name ' + varName + '.'
IF ~Obj_Valid(varObj) THEN $
Message, 'Invalid object with name "' + varName + '" has been found.'
END
'OBJREF': BEGIN
varObj = varName
END
ELSE: Message, 'Input variable name or object is the wrong data type.'
ENDCASE
; Get the variable attribute names.
attrNames = varObj -> GetAttrNames(COUNT=varAttrCount)
RETURN, attrNames
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::GetVarAttrValue
;
; Purpose:
;
; Returns the value of a variable attribute in the file.
;
; Method Syntax:
;
; attrValue = obj -> GetVarAttrValue(varName, attrName, DATATYPE=datatype)
;
; Auguments:
;
; varName: The case sensitive name of a variable whose attribute you want
; to obtain.
; attrName: The case sensitive name of a global attribute.
;
; Keywords:
;
; DATATYPE: An output keyword that contains the data type of the attribute.
;
; Return Value:
;
; attrValue: The value of the variable attribute.
;
;------------------------------------------------------------------------------------------;
FUNCTION NCDF_File::GetVarAttrValue, varName, attrName, DATATYPE=datatype
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN, ""
ENDIF
IF N_Elements(varName) EQ 0 THEN $
Message, 'A variable name or object reference is required.'
IF N_Elements(attrName) EQ 0 THEN $
Message, 'An attribute name or object reference is required.'
; Make sure the file has been parsed.
IF ~self.fileHasBeenParsed THEN self -> ParseFile
; Were you passed the name of a variable or a variable object?
CASE Size(varName, /TNAME) OF
'STRING': BEGIN
varObj = self.vars -> FindByName(varName, COUNT=varCount, /CASE_SENSITIVE)
IF varCount EQ 0 THEN $
Message, 'Cannot find a variable object with name ' + varName + '.'
IF ~Obj_Valid(varObj) THEN $
Message, 'Invalid object with name "' + varName + '" has been found.'
END
'OBJREF': BEGIN
varObj = varName
END
ELSE: Message, 'Input variable name or object is the wrong data type.'
ENDCASE
; Get and return the variable's attribute value.
attrValue = varObj -> GetAttrValue(attrName, DATATYPE=datatype)
RETURN, attrValue
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::GetVarNames
;
; Purpose:
;
; Returns the names of the variables in the file.
;
; Method Syntax:
;
; varNames = obj -> GetVarNames(COUNT=varCount)
;
; Auguments:
;
; None.
;
; Keywords:
;
; COUNT: The number of variables found.
;
; Return Value:
;
; varNames: A string array containing the names of the variables in the file.
;
;------------------------------------------------------------------------------------------;
FUNCTION NCDF_File::GetVarNames, COUNT=varCount
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN, ""
ENDIF
; Make sure the file has been parsed.
IF ~self.fileHasBeenParsed THEN self -> ParseFile
; Count the number of global attribute objects.
varCount = self.vars -> Count()
; If there are no global attributes, return null string.
IF varCount EQ 0 THEN RETURN, ""
varNames = StrArr(varCount)
FOR j=0,varCount-1 DO BEGIN
thisObj = self.vars -> Get(POSITION=j)
varNames[j] = thisObj -> GetName()
ENDFOR
; Return a scalar if necessary.
IF varCount EQ 1 THEN varNames = varNames[0]
RETURN, varNames
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::GetVarData
;
; Purpose:
;
; Returns the variable data from the file.
;
; Method Syntax:
;
; data = obj -> GetVarData(varName, COUNT=count, OFFSET=offset, STRIDE=stride)
;
; Auguments:
;
; varName: The case sensitive name of a variable whose data you want to obtain.
;
; Input Keywords:
;
; COUNT: An optional vector containing the counts to be used in reading the
; variable. Count is a 1-based vector with an element for each dimension.
; The default matches the size of the variable so that all data is
; written out.
; OFFSET: An optional vector containing the starting position for the read.
; The default start position is [0, 0, ...].
; STRIDE: An optional vector containing the strides, or sampling intervals,
; between accessed values of the netCDF variable. The default stride
; vector is that for a contiguous read, [1, 1, ...].
;
; Output Keywords:
;
; ADD_OFFSET: The add_offset value for the variable, if there is one.
;
; DATATYPE: The data type of the variable, before the scale and offset are applied.
; The same as what comes back from datatype = Size(rawVariable, /TNAME).
;
; FILLVALUE: The value that is being used for the "missing" value in this variable.
;
; MISSINGINDICES: A vector containing the missing indices in the returned data. Missing
; data is identified by either the depreciated "missing_value" attribute
; or the approved "_FillValue" attribute.
;
; SCALE_FACTOR: The scale factor for the variable, if there is one.
;
; Return Value:
;
; data: The data obtained from the variable. If there is an ADD_OFFSET and
; SCALE_FACTOR attribute for this variable, the returned data is scaled
; and offset before returning. The "missing" or "fill value" is not
; changed by scaling and offsetting.
;
;------------------------------------------------------------------------------------------;
FUNCTION NCDF_File::GetVarData, varName, $
ADD_OFFSET=add_offset, $
COUNT=count, $
DATATYPE=datatype, $
FILLVALUE=fillValue, $
OFFSET=offset, $
SCALE_FACTOR=scale_factor, $
STRIDE=stride, $
MISSINGINDICES=missingIndices
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN, ""
ENDIF
IF N_Elements(varName) EQ 0 THEN $
Message, 'A variable name or variable object reference is required.'
; Make sure the file has been parsed.
IF ~self.fileHasBeenParsed THEN self -> ParseFile
; Were you passed the name of a variable or a variable object?
CASE Size(varName, /TNAME) OF
'STRING': BEGIN
varObj = self.vars -> FindByName(varName, COUNT=varCount, /CASE_SENSITIVE)
IF varCount EQ 0 THEN $
Message, 'Cannot find a variable object with name ' + varName + '.'
IF ~Obj_Valid(varObj) THEN $
Message, 'Invalid object with name "' + varName + '" has been found.'
END
'OBJREF': BEGIN
varObj = varName
END
ELSE: Message, 'Input variable name or object is the wrong data type.'
ENDCASE
; Get the data.
varData = varObj -> GetValue( $
ADD_OFFSET=add_offset, $
COUNT=count, $
DATATYPE=datatype, $
FILLVALUE=fillvalue, $
OFFSET=offset, $
MISSINGINDICES=missingindices, $
SCALE_FACTOR=scale_factor, $
STRIDE=stride)
RETURN, varData
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::GetVarInfo
;
; Purpose:
;
; Returns information about a specified variable from the file.
;
; Method Syntax:
;
; info = obj -> GetVarInfo(varName)
;
; Auguments:
;
; varName: The case sensitive name of a variable whose information you want to obtain.
;
; Keywords:
;
; None.
;
; Return Value:
;
; info: A structure contains the following fields.
;
; info = { dims: varObj -> GetDimSizes(), $
; dimNames: varObj -> GetDimNames(), $
; attrNames: varObj -> GetAttrNames(), $
; dataType: varObj -> GetProperty('datatype'), $
; nattrs: varObj -> GetProperty('nattrs'), $
; ndims: varObj -> GetProperty('ndims') }
;
; In addition, the structure will contain the fields "scale_factor," "add_offset,"
; and "_FillValue" if these attributes are available for the variable.
;
;------------------------------------------------------------------------------------------;
FUNCTION NCDF_File::GetVarInfo, varName
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN, ""
ENDIF
IF N_Elements(varName) EQ 0 THEN $
Message, 'A variable name or variable object reference is required.'
; Make sure the file has been parsed.
IF ~self.fileHasBeenParsed THEN self -> ParseFile
; Were you passed the name of a variable or a variable object?
CASE Size(varName, /TNAME) OF
'STRING': BEGIN
varObj = self.vars -> FindByName(varName, COUNT=varCount, /CASE_SENSITIVE)
IF varCount EQ 0 THEN $
Message, 'Cannot find a variable object with name ' + varName + '.'
IF ~Obj_Valid(varObj) THEN $
Message, 'Invalid object with name "' + varName + '" has been found.'
END
'OBJREF': BEGIN
varObj = varName
END
ELSE: Message, 'Input variable name or object is the wrong data type.'
ENDCASE
; Get the information you need.
hasVar = self -> HasVar(varName, OBJECT=varObj)
IF ~hasVar THEN Message, 'Cannot find a variable with the name ' + varName + '.'
RETURN, varObj -> GetInfo()
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::HasGlobalAttr
;
; Purpose:
;
; Indicates, by returning a 1, that this particular global attribute is found in the
; file. If not found, this function returns a 0.
;
; Method Syntax:
;
; isFound = obj -> HasGlobalAttr(attrName, OBJECT=object)
;
; Auguments:
;
; attrName: The case sensitive name of a global attribute.
;
; Keywords:
;
; OBJECT: If the attribute exists, this keyword returns the global attribute's
; object reference. Such a reference can be used in place of the
; global attribute's name in most methods.
;
; Return Value:
;
; isFound: If an attribute with this name is found, this variable is set to
; 1. It is set to 0 otherwise.
;
;------------------------------------------------------------------------------------------;
FUNCTION NCDF_File::HasGlobalAttr, attrName, OBJECT=object
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN, ""
ENDIF
; Can you find a global attribute object with this name?
object = self.attrs -> FindByName(attrName, COUNT=count)
IF count GT 0 THEN RETURN, 1 ELSE RETURN, 0
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::HasDim
;
; Purpose:
;
; Indicates, by returning a 1, that this particular dimension is found in the
; file. If not found, this function returns a 0.
;
; Method Syntax:
;
; isFound = obj -> HasDim(dimName, OBJECT=object)
;
; Auguments:
;
; dimName: The case sensitive name of a dimension.
;
; Keywords:
;
; OBJECT: If the dimension exists, this keyword returns the dimension's
; object reference. Such a reference can be used in place of the
; dimension's name in most methods.
;
; Return Value:
;
; isFound: If a dimension with this name is found, this variable is set to
; 1. It is set to 0 otherwise.
;
;------------------------------------------------------------------------------------------;
FUNCTION NCDF_File::HasDim, dimName, OBJECT=object
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN, ""
ENDIF
; Can you find a dimension object with this name?
object = self.dims -> FindByName(dimName, COUNT=count)
IF count GT 0 THEN RETURN, 1 ELSE RETURN, 0
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::HasVar
;
; Purpose:
;
; Indicates, by returning a 1, that this particular variable is found in the
; file. If not found, this function returns a 0.
;
; Method Syntax:
;
; isFound = obj -> HasVar(varName, OBJECT=object)
;
; Auguments:
;
; varName: The case sensitive name of a variable.
;
; Keywords:
;
; OBJECT: If the variable exists, this keyword returns the variable's
; object reference. Such a reference can be used in place of the
; variable's name in most methods.
;
; Return Value:
;
; isFound: If a variable with this name is found, this variable is set to
; 1. It is set to 0 otherwise.
;
;------------------------------------------------------------------------------------------;
FUNCTION NCDF_File::HasVar, varName, OBJECT=object
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN, ""
ENDIF
; Can you find a variable object with this name?
object = self.vars -> FindByName(varName, COUNT=count)
IF count GT 0 THEN RETURN, 1 ELSE RETURN, 0
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::HasVarAttr
;
; Purpose:
;
; Indicates, by returning a 1, that this particular variable attribute is found in the ;
; file. If not found, this function returns a 0.
;
; Method Syntax:
;
; isFound = obj -> HasVarAttr(varName, attrName, OBJECT=object)
;
; Auguments:
;
; varName: The case sensitive name of a variable whose attribute we want to find.
; attrName: The case sensitive name of a variable attribute.
;
; Keywords:
;
; OBJECT: If the variable exists, this keyword returns the variable attribute's
; object reference. Such a reference can be used in place of the
; variable attribute's name in most methods.
;
; Return Value:
;
; isFound: If a variable attribute with this name is found, this variable
; is set to 1. It is set to 0 otherwise.
;
;------------------------------------------------------------------------------------------;
FUNCTION NCDF_File::HasVarAttr, varName, varAttrName, OBJECT=object
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN, ""
ENDIF
; Can you find a variable object with this name?
varObj = self.vars -> FindByName(varName, COUNT=count)
IF count EQ 0 THEN Message, 'Cannot find a variable with name "' + varName + '".'
; Can you find a variable attribute with this name.
hasAttr = varObj[0] -> HasAttr(varAttrName, OBJECT=object)
RETURN, hasAttr
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::PrintFileInfo
;
; Purpose:
;
; Prints file information out to the IDL console window or, optionally, to a file.
;
; Method Syntax:
;
; obj -> PrintFileInfo, outputFile
;
; Auguments:
;
; outputFile: An optional filename. If present, the output is written to this
; file instead of to the console.
;
; Keywords:
;
; None.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::PrintFileInfo, outputFile
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
IF lun NE -1 THEN Free_Lun, lun
RETURN
ENDIF
; Make sure the file has been parsed.
IF ~self.fileHasBeenParsed THEN self -> ParseFile
; Are we writing to a file or to standard output?
IF N_Elements(outputFile) NE 0 THEN BEGIN
OpenW, lun, outputFile, /GET_LUN
ENDIF ELSE lun = -1
; Gather information.
numGAttrs = self.attrs -> Count()
numDims = self.dims -> Count()
numVars = self.vars -> Count()
PrintF, lun, 'File Information: ', self.filename
PrintF, lun, 'Number of Global Attributes: ', StrTrim(numGAttrs,2)
PrintF, lun, 'Number of Dimensions: ', StrTrim(numDims,2)
PrintF, lun, 'Number of Variables: ', StrTrim(numVars,2)
PrintF, lun, ''
PrintF, lun, 'Global Attributes: '
FOR j=0,numGAttrs-1 DO BEGIN
attrObj = self.attrs -> Get(POSITION=j)
name = attrObj -> GetProperty('NAME')
PrintF, lun, ' ', name
ENDFOR
PrintF, lun, ''
PrintF, lun, 'Dimensions: '
FOR j=0,numDims-1 DO BEGIN
dimsObj = self.dims -> Get(POSITION=j)
name = dimsObj -> GetProperty('NAME')
size = dimsObj -> GetProperty('SIZE')
unlimited = dimsObj -> GetProperty('UNLIMITED')
IF unlimited EQ 1 THEN unlimited = ' (unlimited)' ELSE unlimited = ""
PrintF, lun, ' ', name, ': ', StrTrim(size,2), unlimited
ENDFOR
PrintF, lun, ''
PrintF, lun, 'Variables: '
FOR j=0,numVars-1 DO BEGIN
varObj = self.vars -> Get(POSITION=j)
name = varObj -> GetProperty('NAME')
attrs = varObj -> GetProperty('ATTRS')
PrintF, lun, ' ', name
nattrs = attrs -> Count()
FOR k=0,nattrs-1 DO BEGIN
attrObj = attrs -> Get(POSITION=k)
attrname = attrObj -> GetProperty('NAME')
PrintF, lun, ' ', attrname
ENDFOR
ENDFOR
PrintF, lun, ''
; Clean up.
IF lun NE -1 THEN Free_Lun, lun
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::ParseFile
;
; Purpose:
;
; Parses the file and creates the appropriate file objects for all subsequent
; object operations.
;
; Method Syntax:
;
; obj -> ParseFile
;
; Auguments:
;
; None.
;
; Keywords:
;
; None.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::ParseFile
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN
ENDIF
; Only need to parse this file once.
IF self.fileHasBeenParsed THEN RETURN
; Purge all containers and destroy all objects in the container.
theseObjects = self.attrs -> Get(/ALL, COUNT=objCount)
self.attrs -> Remove, /ALL
FOR j=0,objCount-1 DO Obj_Destroy, theseObjects[j]
theseObjects = self.dims -> Get(/ALL, COUNT=objCount)
self.dims -> Remove, /ALL
FOR j=0,objCount-1 DO Obj_Destroy, theseObjects[j]
theseObjects = self.vars -> Get(/ALL, COUNT=objCount)
self.vars -> Remove, /ALL
FOR j=0,objCount-1 DO Obj_Destroy, theseObjects[j]
; Gather information about the file.
info = NCDF_Inquire(self.fileID)
; Parse the global variables.
num_attr = info.ngatts
IF num_attr GT 0 THEN BEGIN
FOR j=0,num_attr-1 DO BEGIN
attribute_name = NCDF_AttName(self.fileID, j, /GLOBAL)
NCDF_AttGet, self.fileID, attribute_name, theAttribute, /GLOBAL
self -> CreateAttrObj, attribute_name
ENDFOR
ENDIF
; Parse the dimensions.
num_dims = info.ndims
IF num_dims GT 0 THEN BEGIN
FOR j=0,num_dims-1 DO BEGIN
NCDF_DIMINQ, self.fileID, j, dimension_name, dimension_size
self -> CreateDimObj, dimension_name
ENDFOR
ENDIF
; Parse the variables.
num_vars = info.nvars
IF num_vars GT 0 THEN BEGIN
FOR j=0,num_vars-1 DO BEGIN
varinfo = NCDF_VarInq(self.fileID, j)
self -> CreateVarObj, varinfo.name
ENDFOR
ENDIF
self.fileHasBeenParsed = 1
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::SetMode
;
; Purpose:
;
; Sets the file mode to DEFINE or DATA, as needed. Only one of the two keywords
; should be used.
;
; Method Syntax:
;
; obj -> SetMode, DATA=data , DEFINE=define
;
; Auguments:
;
; None.
;
; Keywords:
;
; DATA: If this keyword is set, the file is put into DATA mode.
; DEFINE: If this keyword is set, the file is put into DEFINE mode.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::SetMode, DATA=data, DEFINE=define
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
CATCH, theError
IF theError NE 0 THEN BEGIN
CATCH, /CANCEL
self.errorLogger -> AddError
RETURN
ENDIF
; Can't have both keywords set.
IF Keyword_Set(define) && Keyword_Set(data) THEN BEGIN
Message, 'You cannot set both DEFINE and DATA keywords.'
ENDIF
; If nothing is set, put us into DEFINE mode.
IF ~Keyword_Set(define) && ~Keyword_Set(data) THEN define = 1
; Set define mode.
IF Keyword_Set(define) THEN BEGIN
data = 0
IF self.define NE 1 THEN BEGIN
NCDF_Control, self.fileID, /REDEF
self.define = 1
ENDIF
ENDIF
; Set data mode.
IF Keyword_Set(data) THEN BEGIN
IF self.define NE 0 THEN BEGIN
NCDF_Control, self.fileID, /ENDEF
self.define = 0
ENDIF
ENDIF
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::Sync
;
; Purpose:
;
; Writes data in memory to the disk.
;
; Method Syntax:
;
; obj -> Sync
;
; Auguments:
;
; None.
;
; Keywords:
;
; None.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::Sync
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
CATCH, theError
IF theError NE 0 THEN BEGIN
CATCH, /CANCEL
self.errorLogger -> AddError
RETURN
ENDIF
; The file has to be writable to sync the file.
IF ~self.writable THEN Message, 'Cannot sync a READ-ONLY file.'
; The file has to be in DATA mode.
self -> SetMode, /DATA
; Sync the file.
NCDF_Control, self.fileID, /SYNC
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::WriteVarData
;
; Purpose:
;
; Writes variable data into this netCDF file. It assumes the variable has previously
; been defined for this file.
;
; Method Syntax:
;
; obj -> WriteVarData, varName, data, COUNT=count, OFFSET=offset, STRIDE=stride
;
; Auguments:
;
; varName: The case sensitive name of the variable you wish to write data to.
; data: The data to be written into this variable.
;
; Keywords:
;
; COUNT: An optional vector containing the counts to be used in reading the
; variable. Count is a 1-based vector with an element for each dimension.
; The default matches the size of the variable so that all data is
; written out.
; OFFSET: An optional vector containing the starting position for the read.
; The default start position is [0, 0, ...].
; STRIDE: An optional vector containing the strides, or sampling intervals,
; between accessed values of the netCDF variable. The default stride
; vector is that for a contiguous read, [1, 1, ...].
;
; Notes: The variable will have had to have been previously defined for the file.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::WriteVarData, varName, data, COUNT=count, OFFSET=offset, STRIDE=stride
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN
ENDIF
; The file has to be writable to add a variable definition.
IF ~self.writable THEN Message, 'Cannot add a variable definition to a READ-ONLY file.'
; Check parameters.
IF N_Elements(varName) EQ 0 THEN $
Message, 'A variable name or variable object reference is required.'
IF N_Elements(data) EQ 0 THEN $
Message, 'Data is required to write the variable into the file.'
; Were you passed the name of a variable or a variable object?
CASE Size(varName, /TNAME) OF
'STRING': BEGIN
varObj = self.vars -> FindByName(varName, COUNT=varCount, /CASE_SENSITIVE)
IF varCount EQ 0 THEN $
Message, 'Cannot find a variable object with name ' + varName + '.'
IF ~Obj_Valid(varObj) THEN $
Message, 'Invalid object with name ' + varName + ' has been found.'
END
'OBJREF': BEGIN
varObj = varName
END
ELSE: Message, 'Input variable name or object is the wrong data type.'
ENDCASE
; Get the variable ID.
varName = varObj -> GetName()
; Put the file into data mode.
self -> SetMode, /DATA
; Write the data to the file.
NCDF_VarPut, self.fileID, varName, data, COUNT=count, OFFSET=offset, STRIDE=stride
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::WriteVarDef
;
; Purpose:
;
; Writes the variable definition into this netCDF file.
;
; Method Syntax:
;
; obj -> WriteVarDef, varName, dimNames, DATATYPE=datatype, OBJECT=object
;
; Auguments:
;
; varName: The case sensitive name of the variable you wish to define.
; dimNames: The names of dimensions that have been previously defined in the
; file and that are associated with this variable. A string array.
; If dimNames is missing, then the variable is assumed to be a scalar.
;
; Keywords:
;
; CHUNK_DIMENSIONS: Set this keyword equal to a vector containing the chunk dimensions for the variable.
; A new NetCDF variable is chunked by default, using a default chunk value that is
; the full dimension size for limited dimensions, and 1 for unlimited dimensions.
; CHUNK_DIMENSIONS must have the same number of elements as the number of dimensions
; specified by Dim. If the CONTIGUOUS keyword is set, the value of the
; CHUNK_DIMENSIONS keyword is ignored. Available only in IDL 8.0 and higher.
; CONTIGUOUS: Set this keyword to store a NetCDF variable as a single array in a file.
; Contiguous storage works well for smaller variables such as coordinate variables.
; Contiguous storage works only for fixed-sized datasets (those without any unlimited
; dimensions). You can’t use compression or other filters with contiguous data.
; If the CONTIGUOUS keyword is set, the value of the CHUNK_DIMENSIONS keyword is ignored.
; The CONTIGUOUS keyword is ignored if the GZIP keyword is set. Available only in
; IDL 8.0 and higher.
; DATATYPE: The netCDF data type of the variable. This is REQUIRED. The appropriate
; netCDF data types are: "BYTE", "CHAR", "SHORT", "LONG" "FLOAT", or
; "DOUBLE". In IDL 8.1, the data types "STRING", "UBYTE", UINT64",
; "ULONG" and "USHORT" were added.
; GZIP: Set this keyword to an integer between zero and nine to specify the level
; of GZIP compression applied to the variable. Lower compression values result
; in faster but less efficient compression. This keyword is ignored if the
; CHUNK_DIMENSIONS keyword is not set. This keyword is ignored if the CONTIGUOUS
; keyword is set. If the GZIP keyword is set, the CONTIGUOUS keyword is ignored.
; You can only use GZIP compression with NCDF 4 files. Available only in
; IDL 8.0 and higher.
;
; OBJECT: If a variable is successfully defined, this keyword will return the
; object reference to that variable.
; SHUFFLE: Set this keyword to apply the shuffle filter to the variable. If the GZIP
; keyword is not set, this keyword is ignored. The shuffle filter de-interlaces blocks
; of data by reordering individual bytes. Byte shuffling can sometimes
; increase compression density because bytes in the same block positions
; often have similar values, and grouping similar values together often
; leads to more efficient compression. Available only in IDL 8.0 and higher.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::WriteVarDef, varName, dimNames, $
CHUNK_DIMENSIONS=chunk_dimensions, $
CONTIGUOUS=contiguous, $
DATATYPE=datatype, $
GZIP=gzip, $
OBJECT=object, $
SHUFFLE=shuffle
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN
ENDIF
; The file has to be writable to add a variable definition.
IF ~self.writable THEN $
Message, 'Cannot add a variable definition to a READ-ONLY file.'
; Check parameters.
IF N_Elements(varName) EQ 0 THEN $
Message, 'Variable name is required for variable definition.'
IF N_Elements(datatype) EQ 0 THEN Message, 'Variable data type is required.'
; Check the data type to see that it conforms to netCDF protocol.
CASE StrUpCase(datatype) OF
'BYTE': tbyte = 1
'CHAR': tchar = 1
'DOUBLE': tdouble = 1
'FLOAT': tfloat = 1
'LONG': tlong = 1
'SHORT': tshort = 1
'INT': tshort = 1
'STRING': tchar = 1
'UBYTE': tubyte = 1
'ULONG': tulong = 1
'UINT64': tuint64 = 1
'UINT': tuint = 1
'USHORT': tushort = 1
ELSE: Message, 'Unknown DATATYPE for netCDF files: ' + datatype
ENDCASE
; If the dimension names are present, use them to get the dimension IDs, which are
; needed to define the variable.
ndims = N_Elements(dimNames)
IF ndims NE 0 THEN BEGIN
dimIDs = LonArr(ndims)
IF Size(dimNames, /TNAME) EQ 'STRING' THEN BEGIN
FOR j=0,ndims-1 DO BEGIN
dimObj = self.dims -> FindByName(dimNames[j], COUNT=dimCount, /CASE_SENSITIVE)
CASE dimCount OF
0: Message, 'Cannot find dimension object with the name: ' + dimNames[j]
1: BEGIN
dimIDs[j] = dimObj -> GetID()
END
2: Message, 'Found more than one dimension with the name: ' + dimNames[j]
ENDCASE
ENDFOR
ENDIF ELSE BEGIN
dimIDs = dimNames
ENDELSE
ENDIF
; Put the file into define mode.
self -> SetMode, /DEFINE
; Define the variable.
IF N_Elements(dimIDs) EQ 0 THEN BEGIN
release = Float(!Version.Release)
CASE 1 OF
(release LT 8.0) && (!Version.Release NE '7.1.1'): BEGIN
varID = NCDF_VarDef(self.fileID, varName, $
BYTE=tbyte, $
CHAR=tchar, $
DOUBLE=tdouble, $
FLOAT=tfloat, $
LONG=tlong, $
SHORT=tshort)
END
(!Version.Release EQ '7.1.1') || ((release GE 7.2) && (release LT 8.1)): BEGIN
varID = NCDF_VarDef(self.fileID, varName, $
BYTE=tbyte, $
CHAR=tchar, $
CHUNK_DIMENSIONS=chunk_dimensions, $
CONTIGUOUS=contiguous, $
DOUBLE=tdouble, $
FLOAT=tfloat, $
GZIP=gzip, $
LONG=tlong, $
SHORT=tshort, $
SHUFFLE=shuffle)
END
release GE 8.1: BEGIN
varID = NCDF_VarDef(self.fileID, varName, $
BYTE=tbyte, $
CHAR=tchar, $
CHUNK_DIMENSIONS=chunk_dimensions, $
CONTIGUOUS=contiguous, $
DOUBLE=tdouble, $
FLOAT=tfloat, $
GZIP=gzip, $
LONG=tlong, $
SHORT=tshort, $
SHUFFLE=shuffle, $
STRING=tstring, $
UBYTE=tubyte, $
UINT64=tuint64, $
ULONG=tulong, $
USHORT=tushort)
END
ENDCASE
ENDIF ELSE BEGIN
release = Float(!Version.Release)
CASE 1 OF
(release LT 8.0) && (!Version.Release NE '7.1.1'): BEGIN
varID = NCDF_VarDef(self.fileID, varName, dimIDs, $
BYTE=tbyte, $
CHAR=tchar, $
DOUBLE=tdouble, $
FLOAT=tfloat, $
LONG=tlong, $
SHORT=tshort)
END
(!Version.Release EQ '7.1.1') || ((release GE 7.2) && (release LT 8.1)): BEGIN
varID = NCDF_VarDef(self.fileID, varName, dimIDs, $
BYTE=tbyte, $
CHAR=tchar, $
CHUNK_DIMENSIONS=chunk_dimensions, $
CONTIGUOUS=contiguous, $
DOUBLE=tdouble, $
FLOAT=tfloat, $
GZIP=gzip, $
LONG=tlong, $
SHORT=tshort, $
SHUFFLE=shuffle)
END
release GE 8.1: BEGIN
varID = NCDF_VarDef(self.fileID, varName, dimIDs, $
BYTE=tbyte, $
CHAR=tchar, $
CHUNK_DIMENSIONS=chunk_dimensions, $
CONTIGUOUS=contiguous, $
DOUBLE=tdouble, $
FLOAT=tfloat, $
GZIP=gzip, $
LONG=tlong, $
SHORT=tshort, $
SHUFFLE=shuffle, $
STRING=tstring, $
UBYTE=tubyte, $
UINT64=tuint64, $
ULONG=tulong, $
USHORT=tushort)
END
ENDCASE
ENDELSE
; Create a variable object and add it to the variable list.
self -> CreateVarObj, varName
; Need to return the variable object?
IF Arg_Present(object) THEN BEGIN
object = self.vars -> FindByName(varName, COUNT=varCount, /CASE_SENSITIVE)
IF varCount EQ 0 THEN $
Message, 'Cannot find an object with name ' + varName + $
' in the object container.'
ENDIF
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::WriteDim
;
; Purpose:
;
; Writes the variable definition into this netCDF file.
;
; Method Syntax:
;
; obj -> WriteDim, dimName, dimSize, UNLIMITED=unlimited, OBJECT=object
;
; Auguments:
;
; dimName: The case sensitive name of the dimension you wish to define.
; dimSize: The size of the dimension. Required, unless UNLIMITED is set.
;
; Keywords:
;
; UNLIMITED: Set this keyword if you wish this to be an unlimited dimension.
; In general, only one unlimited dimension is allowed per netCDF file.
; OBJECT: If a dimension is successfully defined, this keyword will return the
; dimension object reference to that dimension.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::WriteDim, dimName, dimSize, UNLIMITED=unlimited, OBJECT=object
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN
ENDIF
; The file has to be writable to add a dimension.
IF ~self.writable THEN Message, 'Cannot add a dimension to a READ-ONLY file.'
; Check parameters.
IF N_Elements(dimName) EQ 0 THEN $
Message, 'The name of the dimension is required.'
IF ~Keyword_Set(unlimited) THEN BEGIN
IF N_Elements(dimSize) EQ 0 THEN $
Message, 'The size of the dimension is required.'
ENDIF
; Put the file into define mode
self -> SetMode, /DEFINE
; Add the dimension to the file.
IF Keyword_Set(unlimited) THEN BEGIN
void = NCDF_DimDef(self.fileID, dimName, /UNLIMITED)
ENDIF ELSE BEGIN
void = NCDF_DimDef(self.fileID, dimName, dimSize)
ENDELSE
; Create a dimension object and add it to the dimension container.
self -> CreateDimObj, dimName
; Need to return the dimension object?
IF Arg_Present(object) THEN BEGIN
object = self.dims -> FindByName(dimName, COUNT=dimCount, /CASE_SENSITIVE)
IF dimCount EQ 0 THEN $
Message, 'Cannot find an object with name ' + dimName + $
' in the object container.'
ENDIF
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::WriteGlobalAttr
;
; Purpose:
;
; Writes a global attribute into this netCDF file.
;
; Method Syntax:
;
; obj -> WriteGlobalAttr, attrName, attrValue, DATATYPE=datatype, OBJECT=object
;
; Auguments:
;
; attrName: The case sensitive name of the global attribute you wish to write.
; attrValue: The value of the attribute. Required.
;
; Keywords:
;
; DATATYPE: The netCDF data type of the variable. This is REQUIRED. The appropriate
; netCDF data types are: "BYTE", "CHAR", "SHORT", "LONG" "FLOAT", or
; "DOUBLE".
; OBJECT: If a dimension is successfully defined, this keyword will return the
; dimension object reference to that dimension.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::WriteGlobalAttr, attrName, attrValue, DATATYPE=datatype, OBJECT=object
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN
ENDIF
; The file has to be writable to add a global attribute.
IF ~self.writable THEN $
Message, 'Cannot add a global attribute to a READ-ONLY file.'
; Check parameters.
IF N_Elements(attrName) EQ 0 THEN Message, 'The attribute name is required.'
IF N_Elements(attrValue) EQ 0 THEN Message, 'The attribute value is required.'
IF N_Elements(datatype) EQ 0 THEN datatype = NCDF_CastDataType(attrValue)
; Make sure the attribute name doesn't have spaces.
parts = StrSplit(attrName, /EXTRACT)
IF N_Elements(parts) GT 1 THEN $
Message, 'Global attribute names cannot have spaces in them.'
; Set the appropriate netCDF data type keyword.
CASE StrUpCase(datatype) OF
'BYTE': tbyte = 1
'CHAR': tchar = 1
'DOUBLE': tdouble = 1
'FLOAT': tfloat = 1
'LONG': tlong = 1
'SHORT': tshort = 1
'INT': tshort = 1
'STRING': tchar = 1
'ULONG': tlong = 1
'UINT': tlong = 1
ELSE: Message, 'Unknown DATATYPE for netCDF files: ' + datatype
ENDCASE
; Put the file into define mode
self -> SetMode, /DEFINE
; Add the attribute to the file.
NCDF_AttPut, self.fileID, attrName, attrValue, $
/GLOBAL, $
BYTE=tbyte, $
CHAR=tchar, $
DOUBLE=tdouble, $
FLOAT=tfloat, $
LENGTH=length, $
LONG=tlong, $
SHORT=tshort
; Create an attribute object and add it to the attribute container.
self -> CreateAttrObj, attrName
; Need to return the dimension object?
IF Arg_Present(object) THEN BEGIN
object = self.attrs -> FindByName(attrName, COUNT=attrCount, /CASE_SENSITIVE)
IF attrCount EQ 0 THEN $
Message, 'Cannot find an object with name ' + attrName + $
' in the object container.'
ENDIF
END
;------------------------------------------------------------------------------------------;
;
; NAME:
; NCDF_File::WriteVarAttr
;
; Purpose:
;
; Writes a variable attribute into this netCDF file.
;
; Method Syntax:
;
; obj -> WriteVarAttr, varName, attrName, attrValue, DATATYPE=datatype
;
; Auguments:
;
; varName: The case sensitive variable name for which the attribute is being
; defined.
; attrName: The case sensitive name of the global attribute you wish to write.
; attrValue: The value of the attribute. Required.
;
; Keywords:
;
; DATATYPE: The netCDF data type of the variable. The appropriate netCDF data types
; are: "BYTE", "CHAR", "SHORT", "LONG" "FLOAT", or "DOUBLE".
; OBJECT: If a dimension is successfully defined, this keyword will return the
; dimension object reference to that dimension.
;
;------------------------------------------------------------------------------------------;
PRO NCDF_File::WriteVarAttr, varName, attrName, attrValue, DATATYPE=datatype
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling.
Catch, theError
IF theError NE 0 THEN BEGIN
Catch, /CANCEL
self.errorLogger -> AddError
RETURN
ENDIF
; The file has to be writable to add a variable attribute.
IF ~self.writable THEN Message, 'Cannot add a variable attribute to a READ-ONLY file.'
; Check parameters.
IF N_Elements(attrName) EQ 0 THEN Message, 'The attribute name is required.'
IF N_Elements(attrValue) EQ 0 THEN Message, 'The attribute value is required.'
IF N_Elements(varName) EQ 0 THEN Message, 'A variable name or object is required.'
IF N_Elements(datatype) EQ 0 THEN datatype = NCDF_CastDataType(attrValue)
; Make sure the attribute name doesn't have spaces.
parts = StrSplit(attrName, /EXTRACT)
IF N_Elements(parts) GT 1 THEN $
Message, 'Variable attribute names cannot have spaces in them.'
; Were you passed the name of a variable or a variable object?
CASE Size(varName, /TNAME) OF
'STRING': BEGIN
varObj = self.vars -> FindByName(varName, COUNT=varCount, /CASE_SENSITIVE)
IF varCount EQ 0 THEN $
Message, 'Cannot find a variable object with name ' + varName + '.'
IF ~Obj_Valid(varObj) THEN $
Message, 'Invalid object with name "' + varName + '" has been found.'
END
'OBJREF': BEGIN
varObj = varName
END
ELSE: Message, 'Input variable name or object is the wrong data type.'
ENDCASE
; Is this a valid variable object?
IF ~Obj_Valid(varObj) THEN Message, 'Invalid variable object. Cannot add attribute.'
; Put the file into define mode
self -> SetMode, /DEFINE
; Add the attribute to the variable.
varObj -> AddAttr, attrName, attrValue, DATATYPE=datatype
END
;
;--------------------------------------------------------------------------------------------------
; NAME:
; NCDF_FILE::CLEANUP
;
; PURPOSE:
;
; The cleanup method for the NCDF_FILE object.
;
; ARGUMENTS:
;
; None.
;
; KEYWORD PARAMETERS:
;
; None.
;
;----------------------------------------------------------------------------------------------
PRO NCDF_File::CLEANUP
IF self.fileID GT 0 THEN NCDF_Close, self.fileID
self.errorLogger -> CloseFile
Obj_Destroy, self.errorLogger
Obj_Destroy, self.vars
Obj_Destroy, self.attrs
Obj_Destroy, self.dims
END
;--------------------------------------------------------------------------------------------------
; NAME:
; NCDF_FILE::INIT
;
; PURPOSE:
;
; The initialization method for the NCDF_FILE object.
;
; ARGUMENTS:
;
; filename: The name of a netCDF file to open.
;
; KEYWORD PARAMETERS:
;
; ALERT: Set this keyword if you wish to have alert from the object's error logger.
; Input. Default is 1.
;
; BROWSE: If this keyword is set, the Browse Window is invoked as soon
; as the object is initiated. Input. Default is 0.
;
; CLOBBER: Set this keyword if you are opening a netCDF file that already exists and
; you want to overwrite the existing file. Input. Default is 0.
;
; CREATE: Set this keyword if you wish to create a new netCDF file to write
; into. Input. Default is 0, which means the file will be opened as
; "read-only".
;
; DELETE_ON_DESTROY: Set this keyword if you wish to delete the error log file when
; the ErrorLogger object is destroyed. This will only happen if the ErrorLogger
; object is not in an error state. Input. Default is 1.
;
; ERRORLOGGERNAME: The name of the ErrorLogger filename that captures errors from this
; program. Optional. If not provided a default name will be provided, based
; on the current local system time.
;
; MODIFY: Set this keyword if you wish to modify (write to) a file you are opening.
; If not set, the file will be opened as "read-only".
;
; NETCDF4_FORMAT: Set this keyowrd to create a new NetCDF 4 file. In NetCDF 4 files, data
; is created and accessed with the HDF5 library. NetCDF 4 files are valid HDF5 files,
; and may be read with HDF5 routines. Note that if a NetCDF 4 file is modified using
; the HDF5 routines, rather than with the NetCDF 4 routines, the file is no longer a
; valid NetCDF 4 file, and may no longer be readable with the NetCDF routines.
; You need IDL 8.0 to use this keyword.
;
; NOCLUTTER: Set the keyword to set the ErrorLogger NOCLUTTER keyword.
;
; TIMESTAMP: Set this keyword is you want the ErrorLogger filename to have a time stamp
; appended to it.
;
;----------------------------------------------------------------------------------------------
FUNCTION NCDF_FILE::INIT, filename, $
ALERT=alert, $
BROWSE=browse, $
CLOBBER=clobber, $
CREATE=create, $
DELETE_ON_DESTROY=delete_on_destroy, $
ERRORLOGGERNAME=errorLoggerName, $
MODIFY=modify, $
NETCDF4_FORMAT=netcdf4_format, $
NOCLUTTER=noclutter, $
TIMESTAMP=timestamp
; Compiler options.
Compile_Opt DEFINT32
Compile_Opt STRICTARR
Compile_Opt STRICTARRSUBS
Compile_Opt LOGICAL_PREDICATE
; Error handling. Return 0 if can't finish.
CATCH, theError
IF theError NE 0 THEN BEGIN
CATCH, /CANCEL
self.errorLogger -> AddError
Obj_Destroy, self.errorLogger
IF self.fileID GT 0 THEN NCDF_Close, self.fileID
RETURN, 0
ENDIF
; Create the error logger.
self.errorLogger = Obj_New('ErrorLogger', errorLoggerName, ALERT=1, $
DELETE_ON_DESTROY=1, TIMESTAMP=Keyword_Set(timestamp), NOCLUTTER=noclutter)
; Check keywords.
IF N_Elements(filename) EQ 0 THEN BEGIN
filters = ['*.nc', '*.ncdf*']
filename = Dialog_Pickfile(FILTER=filters, TITLE='Select netCDF File...')
IF filename EQ "" THEN RETURN, 0
ENDIF
; Make sure you have an absolute filename.
root_name = File_Basename(filename)
IF root_name EQ filename THEN BEGIN
CD, CURRENT=thisDir
absFilename = FilePath(ROOT_DIR=thisDir, filename)
filename = absFilename
ENDIF
; Set default values, if keywords are not already set.
SetDefaultValue, alert, 1, /Boolean
SetDefaultValue, create, 0, /Boolean
SetDefaultValue, clobber, 0, /Boolean
SetDefaultValue, modify, 0, /Boolean
SetDefaultValue, delete_on_destroy, 1, /Boolean
SetDefaultValue, noclutter, 0, /Boolean
SetDefaultValue, netcdf4_format, 0, /Boolean
self.errorLogger -> SetProperty, ALERT=alert, DELETE_ON_DESTROY=delete_on_destroy, NOCLUTTER=noclutter
; If you are not going to create the file, you are going to open it.
; If you want to modify the file, it is going to be writable.
mode = create ? 'CREATE' : 'OPEN'
self.writable = (mode EQ 'OPEN' && modify) || mode EQ 'CREATE'
; Are you creating the file? Make sure it doesn't already exist. If it does,
; you will have to clobber it.
IF mode EQ 'CREATE' THEN BEGIN
IF File_Test(filename) THEN BEGIN
CASE clobber OF
1: File_Delete, filename, /ALLOW_NONEXISTENT
0: Message, "The specified netCDF file already exists and cannot " + $
"be overwritten unless CLOBBER is set."
ENDCASE
ENDIF
ENDIF
; If the user wants to open the file, make sure it is possible.
IF mode EQ 'OPEN' THEN BEGIN
IF ~File_Test(filename, /READ) THEN $
Message, "The specified netCDF file cannot be opened for reading: " + filename
IF modify THEN BEGIN
IF ~File_Test(filename, /WRITE) THEN $
Message, "The specified netCDF file cannot be opened for writing: " + filename
ENDIF
ENDIF
; Store the filename.
self.filename = filename
; Open or create the file.
CASE mode OF
'OPEN': BEGIN
self.fileID = NCDF_Open(self.filename, WRITE=self.writable)
self.define = 0
END
'CREATE': BEGIN
IF (!Version.Release EQ '7.1.1') || (Float(!Version.Release) GE 7.2) THEN BEGIN
self.fileID = NCDF_Create(self.filename, CLOBBER=clobber, NETCDF4_FORMAT=netcdf4_format)
ENDIF ELSE BEGIN
self.fileID = NCDF_Create(self.filename, CLOBBER=clobber)
ENDELSE
self.define = 1
END
ENDCASE
; Initialize object containers for contents.
self.vars = Obj_New('NCDF_Container')
self.attrs = Obj_New('NCDF_Container')
self.dims = Obj_New('NCDF_Container')
; Did the user want to browse this file?
IF Keyword_Set(browse) THEN self -> Browse
; If this file has been opened for reading or modifying, then parse it.
IF ~self.writable THEN self -> Parsefile
IF Keyword_Set(modify) THEN self -> Parsefile
RETURN, 1
END ; --------------------------------------------------------------------------------------------
PRO NCDF_File__DEFINE, class
class = { NCDF_FILE, $
filename: "", $ ; The name of the netCDF file.
fileID: 0L, $ ; The netCDF file ID.
errorlogger: Obj_New(), $ ; The error logger object.
vars: Obj_New(), $ ; An object container containing variable objects.
attrs: Obj_New(), $ ; An object container containing global attribute objects.
dims: Obj_New(), $ ; An object container containing dimension objects.
writable: 0B, $ ; A flag that indicates the file is writable.
fileHasBeenParsed: 0B, $ ; A flag that is 1 when the file has been parsed.
file_extension: "", $ ; A file extension that is used with Dialog_Pickfile()
define: 0B $ ; A flag that indicates the file is in define mode.
}
END ; --------------------------------------------------------------------------------------------
|