source: nappy/trunk/nappy/na_file/na_file_1001.py @ 3440

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/trunk/nappy/na_file/na_file_1001.py@3440
Revision 3440, 2.7 KB checked in by ckilburn, 12 years ago (diff)

delimiter work

Line 
1;#   Copyright (C) 2004 CCLRC & NERC( Natural Environment Research Council ).
2#   This software may be distributed under the terms of the
3#   Q Public License, version 1.0 or later. http://ndg.nerc.ac.uk/public_docs/QPublic_license.txt
4
5"""
6naFile1001.py
7=============
8
9Container module for NAFile1001 class.
10
11"""
12
13# Imports from python standard library
14
15# Imports from local package
16import nappy.utils.text_parser
17import nappy.na_file.na_file
18
19class NAFile1001(nappy.na_file.na_file.NAFile):
20    """
21    Class to read, write and interact with NASA Ames files conforming to the
22    File Format Index (FFI) 1001.
23    """
24
25    def readHeader(self):
26        """
27        Reads FFI-specific header section.
28        """
29        self._readCommonHeader()
30        self.DX = nappy.utils.text_parser.readItemsFromLine(self.file.readline(), self.NIV, float)
31        self.XNAME = nappy.utils.text_parser.readItemsFromLines(self._readLines(self.NIV), self.NIV, str)
32        self._readVariablesHeaderSection()
33        self._readComments()
34
35    def writeHeader(self):
36        """
37        Writes FFI-specific header section.
38        """       
39        self._writeCommonHeader()
40        self.header.write(("%s" * self.NIV + "\n") % tuple(self.DX))
41        self.header.write("%s\n" * self.NIV % tuple(self.XNAME))
42        self._writeVariablesHeaderSection()
43        self._writeComments()
44        self._fixHeaderLength()
45        self.file.write(self.header.read())
46
47    def _setupArrays(self):
48        """
49        Sets up FFI-specific arrays to fill with data (lists of lists).
50        """
51        self.X = []
52        self.V = []
53        # Set up the variables list
54        for n in range(self.NV):
55            self.V.append([])
56
57    def _readData1(self, datalines, ivar_count):
58        """
59        Reads first line/section of current block of data.
60        """
61        (x_and_v, rtlines) = nappy.utils.text_parser.readItemsFromUnknownLines(datalines, 1 + self.NV, float)
62        (x, v) = (x_and_v[0], x_and_v[1:])
63        self.X.append(x)
64        count = 0
65        # Set up mth list in self.V
66        for n in range(self.NV):
67            self.V[n].append(v[count])
68            count = count + 1
69        return rtlines   
70
71    def _readData2(self, datalines, ivar_count):
72        """
73        Reads second line/section (if used) of current block of data.
74        """
75        return datalines 
76
77    def writeData(self):
78        """
79        Writes the data section of the file.
80        This method can be called directly by the user.
81        """
82        for m in range(len(self.X)):
83            var_string = "%s" % self.X[m]
84
85            for n in range(self.NV):
86                var_string = var_string + ("%s%s" % (self.delimiter, self.V[n][m]))
87
88            self.file.write("%s\n" % var_string)
Note: See TracBrowser for help on using the repository browser.