source: nappy/trunk/naFile1020.py @ 345

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/trunk/naFile1020.py@345
Revision 345, 2.6 KB checked in by selatham, 15 years ago (diff)

updated by selatham for bug fixes and new write methods

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1"""
2naFile1020.py
3=============
4
5Container module for NAFile1020 class.
6
7"""
8
9# Imports from python standard library
10
11# Imports from local package
12from textParser import *
13import naFile1010
14
15class NAFile1020(naFile1010.NAFile1010):
16    """
17    Class to read, write and interact with NASA Ames files conforming to the
18    File Format Index (FFI) 1020.
19    """
20
21    def readHeader(self):
22        """
23        Reads FFI-specifc header section.
24        """   
25        self._normalizedX="no"
26        self._readCommonHeader()
27        self.DX=readItemsFromLine(self.file.readline(), self.NIV, float)
28        if self.DX==0:
29            raise "DX found to be zero (0). Not allowed for FFI 1020."
30
31        self.NVPM=readItemFromLine(self.file.readline(), int)
32        self.XNAME=readItemsFromLines(self._readLines(self.NIV), self.NIV, str)
33        self._readVariablesHeaderSection()
34        self._readAuxVariablesHeaderSection()
35        self._readComments()
36 
37    def _readData2(self, datalines, ivar_count):
38        """
39        Reads second line/section (if used) of current block of data.
40        """
41        # Now get the dependent variables
42        (v, rtlines)=readItemsFromUnknownLines(datalines, self.NV*self.NVPM, float)
43        count=0
44        #print "chunk of ind vars",v            testing
45        #print rtlines                          testing
46        for n in range(self.NV):
47            self.V[n].append([])
48            for i in range(self.NVPM):   # Number of steps where independent variable is implied
49                self.V[n][ivar_count].append(v[count])
50                count=count+1
51        return rtlines
52
53    def _normalizeIndVars(self):
54        """
55        Normalizes the values in the unbounded independent variable for FFIs
56        that store an abbreviated version of this axis.
57        """
58        newX=[]
59        for x in self.X[0]:
60            for i in range(self.NVPM):
61                newX.append(x+(i*self.DX))
62        self.X[0]=newX
63        self._normalizedX="yes"
64
65    def writeData(self):
66        """
67        Writes the data section of the file.
68        This method can be called directly by the user.
69        """
70        for m in range(len(self.X)):
71            # Write Independent variable mark and auxiliary variables
72            var_string="%s    " % self.X[m]
73            for a in range(self.NAUXV):
74                var_string=var_string+("%s    " % self.A[a][m])
75            self.file.write("%s\n" % var_string.rstrip())
76            # Write dependant variablesf.
77            var_string=""
78            for n in range(self.NV):
79                 var_string=var_string+("%s    " %self.V[n][m])
80            self.file.write("%s    \n" %var_string)
Note: See TracBrowser for help on using the repository browser.