source: nappy/trunk/naFile1001.py @ 366

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/nappy/trunk/naFile1001.py@366
Revision 366, 2.6 KB checked in by astephen, 14 years ago (diff)

Latest version - for compatibility with web service. Includes multiple file
output on conversion from NetCDF.

  • 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"""
6naFile1001.py
7=============
8
9Container module for NAFile1001 class.
10
11"""
12
13# Imports from python standard library
14
15# Imports from local package
16from textParser import *
17import naFile
18
19class NAFile1001(naFile.NAFile):
20    """
21    Class to read, write and interact with NASA Ames files conforming to the
22    File Format Index (FFI) 1001.
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.XNAME=readItemsFromLines(self._readLines(self.NIV), self.NIV, str)
32        self._readVariablesHeaderSection()
33        self._readComments()
34
35    def writeHeader(self):
36        """
37        Writes FFI-specifc header section.
38        """       
39        self._writeCommonHeader()
40        self.header.write(("%s "*self.NIV+"\n") % tuple(self.DX))
41        self.header.write("%s\n"*self.NIV % tuple(self.XNAME))
42        self._writeVariablesHeaderSection()
43        self._writeComments()
44        lines=self._fixHeaderLength(self.header)
45        self.file.writelines(lines)
46
47    def _setupArrays(self):
48        """
49        Sets up FFI-specific arrays to fill with data (lists of lists).
50        """
51        self.X=[]
52        self.V=[]
53        # Set up the variables list
54        for n in range(self.NV):
55            self.V.append([])
56
57    def _readData1(self, datalines, ivar_count):
58        """
59        Reads first line/section of current block of data.
60        """
61        (x_and_v, rtlines)=readItemsFromUnknownLines(datalines, 1+self.NV, float)
62        (x, v)=(x_and_v[0], x_and_v[1:])
63        self.X.append(x)
64        count=0
65        # Set up mth list in self.V
66        for n in range(self.NV):
67            self.V[n].append(v[count])
68            count=count+1
69        return rtlines   
70
71    def _readData2(self, datalines, ivar_count):
72        """
73        Reads second line/section (if used) of current block of data.
74        """
75        return datalines 
76
77    def writeData(self):
78        """
79        Writes the data section of the file.
80        This method can be called directly by the user.
81        """
82        for i in range(len(self.X)):
83            var_string=""
84            for n in range(self.NV):
85                var_string=var_string+("%s    " % self.V[n][i])
86            self.file.write("%s    %s\n" % (self.X[i], var_string))
Note: See TracBrowser for help on using the repository browser.