source: TI03-DataExtractor/trunk/pydxs/CDMSOutputHandler.py @ 794

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/trunk/pydxs/CDMSOutputHandler.py@794
Revision 794, 1.3 KB checked in by astephen, 13 years ago (diff)

Unstable but latest version with multi-variable support and split hooks
for CDML and CSML.

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"""
6CDMSOutputHandler.py
7====================
8
9Output handler when writing files to NetCDF via CDMS.
10
11"""
12
13# Import required modules
14import cdms
15
16# Import package modules including global variables
17from DXErrors import *
18
19
20class CDMSOutputHandler:
21
22    def __init__(self, outputFileName):
23        """
24        Opens the output NetCDF file using CDMS.
25        """
26        self.outputFile=cdms.open(outputFileName, "w")
27       
28       
29    def writeVariable(self, variable):
30        """
31        Writes the variable object 'variable' to the output file.
32        """
33        self.outputFile.write(variable)
34       
35       
36    def writeGlobalAttributes(self, attDict):
37        """
38        Writes global attributes to the output file.
39        """     
40        for att in attDict:
41            self.outputFile.__setattr__(att, attDict[att])
42           
43
44    def writeVariableAndGlobalAttributes(self, variable, attDict):
45        """
46        Writes a variable and a set of global attributes to
47        the output file.
48        """
49        self.writeVariable(variable)
50        self.writeGlobalAttributes(attDict)
51
52   
53    def closeFile(self):
54        """
55        Closes the output file.
56        """
57        self.outputFile.close()
Note: See TracBrowser for help on using the repository browser.