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

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

Tidied up _fixHeaderLength in na_file.py.
Changed write interface so self.write(na_dict, delimiter, float_format)
is a separate call to creating the instance.
Fixed unit tests to cope with this.

BUT: broke nappy_api.openNAFile(<file>, "w") with these changes.
Hence need to think about changes being made to openNAFile() so that it
can predict (or not) the FFI.

Only 1001 unit test (worked on by CK) is broken at present.

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
8"""
9
10# Import standard library modules
11
12
13# Import local modules
14from nappy.utils.common_utils import *
15
16def openNAFile(filename, mode="r", na_dict=None, delimiter="    ", float_format="%8.3f"):
17    """
18    Function wrapper around the NASA Ames File classes. Any NASA Ames
19    file can be opened through this function and the appropriate read or
20    write NASA Ames File class instance is returned.
21    """
22    if mode == "r":
23        ffi = readFFI(filename)
24        return apply(getNAFileClass(ffi), (filename, mode))
25
26    elif mode == "w":
27        if na_dict.has_key('FFI') and type(na_dict['FFI']) == type(3):
28            ffi = na_dict['FFI']
29        else:
30            ffi = chooseFFI(na_dict)
31            na_dict['FFI'] = ffi
32            print "\nFormat identified as:", ffi   
33        return apply(getNAFileClass(ffi), (filename,), {"mode":mode, "na_dict":na_dict}) #, "delimiter":delimiter, "float_format":float_format})
34    else:
35        raise Exception("File mode not recognised '" + mode + "'.")
Note: See TracBrowser for help on using the repository browser.