source: nappy/trunk/naFile2310.py @ 361

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

bug fixes, write classes and other new classes as required.

  • 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"""
6naFile2310.py
7=============
8
9Container module for NAFile2310 class.
10
11"""
12
13# Imports from python standard library
14
15# Imports from local package
16from textParser import *
17import naFile2110
18
19class NAFile2310(naFile2110.NAFile2110):
20    """
21    Class to read, write and interact with NASA Ames files conforming to the
22    File Format Index (FFI) 2310.
23    """
24
25    def readHeader(self):
26        """
27        Reads FFI-specifc header section.
28        """       
29        self._normalizedX="no"
30        self._readCommonHeader()
31        self.DX=readItemsFromLine(self.file.readline(), 1, float)
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 writeHeader(self):
39        """
40        Writes FFI-specifc header section.
41        """
42        self._writeCommonHeader()
43        #self.DX.reverse()
44        self.file.write(("%s\n") % self.DX[0])
45        self.XNAME.reverse()
46        self.file.write("%s\n"*self.NIV % tuple(self.XNAME))
47        self._writeVariablesHeaderSection()
48        self._writeAuxVariablesHeaderSection()
49        self._writeComments()
50
51    def _readData1(self, datalines, ivar_count):
52        """
53        Reads first line/section of current block of data.
54        """       
55        # Start with independent and Auxilliary vars
56        (x_and_a, rtlines)=readItemsFromUnknownLines(datalines, self.NAUXV+1, float)
57        (x, aux)=(x_and_a[0], x_and_a[1:])
58        count=0
59        for a in range(self.NAUXV):
60            self.A[a].append(aux[count])
61            count=count+1
62        self.X.append([])
63        self.X[ivar_count].append(x)
64        # Set up list to take second changing independent variable
65        self.X[ivar_count].append([aux[1]])
66        self.NX.append(int(aux[0]))
67        self.DX.append(int(aux[2]))
68        return rtlines
69   
70    def _readData2(self, datalines, ivar_count):
71        """
72        Reads second line/section (if used) of current block of data.
73        """
74        # Now get the dependent variables
75        (v, rtlines)=readItemsFromUnknownLines(datalines, self.NV*self.NX[ivar_count], float)
76        count=0
77        for n in range(self.NV):
78            self.V[n].append([])
79            for i in range(self.NX[ivar_count]):
80                self.V[n][ivar_count].append(v[count])
81                count=count+1
82        return rtlines
83
84    def writeData(self):
85        """
86        Writes the data section of the file.
87        This method can be called directly by the user.
88        """
89        # Set up unbounded IV loop
90       # self.NX.reverse()
91        for m in range(len(self.X)):
92             # Write Independent variable mark and auxiliary variables
93             var_string="%s    " % self.X[m][0]
94             for a in range(self.NAUXV):
95                 var_string=var_string+("%s    " % self.A[a][m])
96             self.file.write("%s\n" % var_string.rstrip())
97             # Write second independant variable and dependant variables
98             var_string=""
99             for p in range(self.NX[m]):
100                #var_string="%s    " % self.X[m][1][p]
101                for n in range(self.NV):
102                        var_string=var_string+("%s    " %self.V[n][m][p])
103             self.file.write("%s    \n" %var_string)
Note: See TracBrowser for help on using the repository browser.