source: nappy/trunk/naFile2110.py @ 349

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

Inserted license information.

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