1 | """ |
---|
2 | naFile1010.py |
---|
3 | ============= |
---|
4 | |
---|
5 | Container module for NAFile1010 class. |
---|
6 | |
---|
7 | """ |
---|
8 | #$Log$ |
---|
9 | #Revision 1.2 2004/11/03 16:23:41 selatham |
---|
10 | #updated by selatham for bug fixes and new write methods |
---|
11 | # |
---|
12 | # Imports from python standard library |
---|
13 | |
---|
14 | # Imports from local package |
---|
15 | import naFile1001 |
---|
16 | from textParser import * |
---|
17 | |
---|
18 | class NAFile1010(naFile1001.NAFile1001): |
---|
19 | """ |
---|
20 | Class to read, write and interact with NASA Ames files conforming to the |
---|
21 | File Format Index (FFI) 1010. |
---|
22 | """ |
---|
23 | #$Log$ |
---|
24 | #Revision 1.2 2004/11/03 16:23:41 selatham |
---|
25 | #updated by selatham for bug fixes and new write methods |
---|
26 | # |
---|
27 | # |
---|
28 | |
---|
29 | def readHeader(self): |
---|
30 | """ |
---|
31 | Reads FFI-specifc header section. |
---|
32 | """ |
---|
33 | self._readCommonHeader() |
---|
34 | self.DX=readItemsFromLine(self.file.readline(), self.NIV, float) |
---|
35 | self.XNAME=readItemsFromLines(self._readLines(self.NIV), self.NIV, str) |
---|
36 | self._readVariablesHeaderSection() |
---|
37 | self._readAuxVariablesHeaderSection() |
---|
38 | self._readComments() |
---|
39 | |
---|
40 | def writeHeader(self): |
---|
41 | """ |
---|
42 | Writes FFI-specifc header section. |
---|
43 | """ |
---|
44 | self._writeCommonHeader() |
---|
45 | self.file.write(("%s "*self.NIV+"\n") % tuple(self.DX)) |
---|
46 | self.file.write("%s\n"*self.NIV % tuple(self.XNAME)) |
---|
47 | self._writeVariablesHeaderSection() |
---|
48 | self._writeAuxVariablesHeaderSection() |
---|
49 | self._writeComments() |
---|
50 | |
---|
51 | def _setupArrays(self): |
---|
52 | """ |
---|
53 | Sets up FFI-specific arrays to fill with data (lists of lists). |
---|
54 | """ |
---|
55 | self.X=[] |
---|
56 | self.V=[] |
---|
57 | self.A=[] |
---|
58 | for n in range(self.NV): |
---|
59 | self.V.append([]) |
---|
60 | for a in range(self.NAUXV): |
---|
61 | self.A.append([]) |
---|
62 | |
---|
63 | def _readData1(self, datalines, ivar_count): |
---|
64 | """ |
---|
65 | Reads first line/section of current block of data. |
---|
66 | """ |
---|
67 | # Start with independent and Auxilliary vars |
---|
68 | #print "NAUXV = %s" %self.NAUXV testing |
---|
69 | (x2_and_a, rtlines)=readItemsFromUnknownLines(datalines, 1+self.NAUXV, float) |
---|
70 | #print "First line of block = %s" %x2_and_a testing |
---|
71 | (x, aux)=(x2_and_a[0], x2_and_a[1:]) |
---|
72 | self.X.append(x) |
---|
73 | count=0 |
---|
74 | for a in range(self.NAUXV): |
---|
75 | self.A[a].append(aux[count]) |
---|
76 | count=count+1 |
---|
77 | return rtlines |
---|
78 | |
---|
79 | def _readData2(self, datalines, ivar_count): |
---|
80 | """ |
---|
81 | Reads second line/section (if used) of current block of data. |
---|
82 | """ |
---|
83 | # Now get the dependent variables |
---|
84 | (v, rtlines)=readItemsFromUnknownLines(datalines, self.NV, float) |
---|
85 | # Set up mth list in self.V removed by selatham |
---|
86 | #self.V.append([]) removed by selatham |
---|
87 | count=0 |
---|
88 | for n in range(self.NV): |
---|
89 | #self.V[n].append([]) removed by selatham |
---|
90 | #self.V[ivar_count].append(v[count]) removed by selatham |
---|
91 | self.V[n].append(v[count]) |
---|
92 | count=count+1 |
---|
93 | return rtlines |
---|
94 | |
---|
95 | def writeData(self): |
---|
96 | """ |
---|
97 | Writes the data section of the file. |
---|
98 | This method can be called directly by the user. |
---|
99 | """ |
---|
100 | for m in range(len(self.X)): |
---|
101 | # Write Independent variable mark and auxiliary variables |
---|
102 | var_string="%s " % self.X[m] |
---|
103 | for a in range(self.NAUXV): |
---|
104 | var_string=var_string+("%s " % self.A[a][m]) |
---|
105 | self.file.write("%s\n" % var_string.rstrip()) |
---|
106 | # Write dependant variables |
---|
107 | var_string="" |
---|
108 | for n in range(self.NV): |
---|
109 | var_string=var_string+("%s " %self.V[n][m]) |
---|
110 | self.file.write("%s \n" %var_string) |
---|