source: nappy/trunk/nappy/nappy_api.py @ 3488

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/trunk/nappy/nappy_api.py@3488
Revision 3488, 1.5 KB checked in by astephen, 12 years ago (diff)

Added some thoughts about what you might put in the API.

Line 
1"""
2nappy_api.py
3============
4
5Top-level API module that allows user to access most of the useful stuff in
6nappy. Just imports all the good stuff so accessible from here.
7
8What do we want in the API?
9 - some thoughts....
10
11
12openNAFile - read and/or write
13convertNCToNA
14convertNAToNC
15convertNCToCSV
16convertNAToCSV
17
18compareNAFiles
19convertCDMSObjectsToNA
20convertCDMSObjectsToCSV
21convertNADictToNC
22
23some things from utils...
24
25getMappings
26getVersion
27getFFI
28chooseFFI
29
30
31
32"""
33
34# Import standard library modules
35
36
37# Import local modules
38from nappy.utils.common_utils import *
39
40def openNAFile(filename, mode="r", na_dict=None, delimiter="    ", float_format="%8.3f"):
41    """
42    Function wrapper around the NASA Ames File classes. Any NASA Ames
43    file can be opened through this function and the appropriate read or
44    write NASA Ames File class instance is returned.
45    """
46    if mode == "r":
47        ffi = readFFI(filename)
48        return apply(getNAFileClass(ffi), (filename, mode))
49
50    elif mode == "w":
51        if na_dict.has_key('FFI') and type(na_dict['FFI']) == type(3):
52            ffi = na_dict['FFI']
53        else:
54            ffi = chooseFFI(na_dict)
55            na_dict['FFI'] = ffi
56            print "\nFormat identified as:", ffi   
57        return apply(getNAFileClass(ffi), (filename,), {"mode":mode, "na_dict":na_dict}) #, "delimiter":delimiter, "float_format":float_format})
58    else:
59        raise Exception("File mode not recognised '" + mode + "'.")
Note: See TracBrowser for help on using the repository browser.