source: nappy/trunk/naFile1001.py @ 343

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/trunk/naFile1001.py@347
Revision 343, 2.3 KB checked in by astephen, 15 years ago (diff)

Latest version with new files in test directory.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1"""
2naFile1001.py
3=============
4
5Container module for NAFile1001 class.
6
7"""
8
9# Imports from python standard library
10
11# Imports from local package
12from textParser import *
13import naFile
14
15class NAFile1001(naFile.NAFile):
16    """
17    Class to read, write and interact with NASA Ames files conforming to the
18    File Format Index (FFI) 1001.
19    """
20
21    def readHeader(self):
22        """
23        Reads FFI-specifc header section.
24        """
25        self._readCommonHeader()
26        self.DX=readItemsFromLine(self.file.readline(), self.NIV, float)
27        self.XNAME=readItemsFromLines(self._readLines(self.NIV), self.NIV, str)
28        self._readVariablesHeaderSection()
29        self._readComments()
30
31    def writeHeader(self):
32        """
33        Writes FFI-specifc header section.
34        """       
35        self._writeCommonHeader()
36        self.file.write(("%s "*self.NIV+"\n") % tuple(self.DX))
37        self.file.write("%s\n"*self.NIV % tuple(self.XNAME))
38        self._writeVariablesHeaderSection()
39        self._writeComments()
40
41    def _setupArrays(self):
42        """
43        Sets up FFI-specific arrays to fill with data (lists of lists).
44        """
45        self.X=[]
46        self.V=[]
47        # Set up the variables list
48        for n in range(self.NV):
49            self.V.append([])
50
51    def _readData1(self, datalines, ivar_count):
52        """
53        Reads first line/section of current block of data.
54        """
55        (x_and_v, rtlines)=readItemsFromUnknownLines(datalines, 1+self.NV, float)
56        (x, v)=(x_and_v[0], x_and_v[1:])
57        self.X.append(x)
58        count=0
59        # Set up mth list in self.V
60        for n in range(self.NV):
61            self.V[n].append(v[count])
62            count=count+1
63        return rtlines   
64
65    def _readData2(self, datalines, ivar_count):
66        """
67        Reads second line/section (if used) of current block of data.
68        """
69        return datalines 
70
71    def writeData(self):
72        """
73        Writes the data section of the file.
74        This method can be called directly by the user.
75        """
76        for i in range(len(self.X)):
77            var_string=""
78            for n in range(self.NV):
79                var_string=var_string+("%s    " % self.V[n][i])
80            self.file.write("%s    %s\n" % (self.X[i], var_string))
Note: See TracBrowser for help on using the repository browser.