source: nappy/trunk/naFile2160.py @ 343

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/trunk/naFile2160.py@347
Revision 343, 2.2 KB checked in by astephen, 16 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"""
2naFile2160.py
3=============
4
5Container module for NAFile2160 class.
6
7"""
8
9# Imports from python standard library
10
11# Imports from local package
12from textParser import *
13import naFile2110
14
15class NAFile2160(naFile2110.NAFile2110):
16    """
17    Class to read, write and interact with NASA Ames files conforming to the
18    File Format Index (FFI) 2160.
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(), 1, float)
28        self.LENX=readItemFromLine(self.file.readline(), float)
29        self.XNAME=readItemsFromLines(self._readLines(self.NIV), self.NIV, str)
30        self.XNAME.reverse()  # Reverse because C-type array is least-changing first         
31        self._readVariablesHeaderSection()
32        self._readCharAuxVariablesHeaderSection()
33        self._readComments()
34
35    def _setupArrays(self):
36        """
37        Sets up FFI-specific arrays to fill with data (lists of lists).
38        """
39        self.V=[]
40        self.A=[]
41        self.X=[]
42        self.NX=[]
43       
44        for n in range(self.NV):
45            self.V.append([])
46        for i in range(self.NAUXV):
47            self.A.append([])
48
49    def _readData1(self, datalines, ivar_count):
50        """
51        Reads first line/section of current block of data.
52        """     
53        # Start with independent and Auxilliary vars
54        # Get character string independent variable
55        (x1, datalines)=readItemsFromUnknownLines(datalines, 1, str)
56        self.X.append([])
57        self.X[ivar_count].append(x1)
58        # Set up list to take second changing independent variable
59        self.X[ivar_count].append([]) 
60        # Get NX and Non-character AUX vars
61        (aux, datalines)=readItemsFromUnknownLines(datalines, (self.NAUXV-self.NAUXC), float)
62        self.NX.append(int(aux[0]))
63        for a in range(self.NAUXV-self.NAUXC):
64            self.A.append(aux[a])
65        # Get character AUX vars
66        (auxc)=readItemsFromLines(datalines[:self.NAUXC], self.NAUXC, str)
67        rtlines=datalines[self.NAUXC:]
68        for a in range(self.NAUXC):
69            self.A.append(auxc[a])
70        return rtlines
71   
Note: See TracBrowser for help on using the repository browser.