source: nappy/trunk/naFile2110.py @ 343

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/trunk/naFile2110.py@343
Revision 343, 2.6 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"""
2naFile2110.py
3=============
4
5Container module for NAFile2110 class.
6
7"""
8
9# Imports from python standard library
10
11# Imports from local package
12from textParser import *
13import naFile2010
14
15class NAFile2110(naFile2010.NAFile2010):
16    """
17    Class to read, write and interact with NASA Ames files conforming to the
18    File Format Index (FFI) 2110.
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.DX.reverse()  # Reverse because C-type array is least-changing first       
28        self.XNAME=readItemsFromLines(self._readLines(self.NIV), self.NIV, str)
29        self.XNAME.reverse()  # Reverse because C-type array is least-changing first       
30        self._readVariablesHeaderSection()
31        self._readAuxVariablesHeaderSection()
32        self._readComments()
33
34    def _setupArrays(self):
35        """
36        Sets up FFI-specific arrays to fill with data (lists of lists).
37        """
38        self.V=[]
39        self.A=[]
40        self.X=[]  # Needs to be a list of sublists each containing [x0n, [x1n, x1n+1, x1n+2....]]
41        self.NX=[]
42 
43        for n in range(self.NV):
44            self.V.append([])
45        for i in range(self.NAUXV):
46            self.A.append([])
47
48    def _readData1(self, datalines, ivar_count): 
49        """
50        Reads first line/section of current block of data.
51        """   
52        # Start with independent and Auxilliary vars
53        (x_and_a, rtlines)=readItemsFromUnknownLines(datalines, self.NAUXV+1, float)
54        (x, aux)=(x_and_a[0], x_and_a[1:])
55        for a in range(self.NAUXV):
56            self.A.append(aux[a])
57        self.X.append([])
58        self.X[ivar_count].append(x)
59        # Set up list to take second changing independent variable
60        self.X[ivar_count].append([]) 
61        self.NX.append(int(aux[0]))
62        return rtlines
63   
64    def _readData2(self, datalines, ivar_count):
65        """
66        Reads second line/section (if used) of current block of data.
67        """       
68        # Now get the dependent variables
69        for n in range(self.NV):
70            self.V[n].append([])
71        for c in range(self.NX[ivar_count]):
72            (x_and_v, datalines)=readItemsFromUnknownLines(datalines, self.NV+1, float)
73            (x, v)=(x_and_v[0], x_and_v[1:])
74            self.X[ivar_count][1].append(x)
75            count=0
76            for n in range(self.NV):
77                self.V[n][ivar_count].append(v[count])
78                count=count+1
79        rtlines=datalines
80        return rtlines
Note: See TracBrowser for help on using the repository browser.