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

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

Merged with titania version.

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 *
18from common import *
19
20
21class CDMSOutputHandler:
22
23    def __init__(self, outputFileName):
24        """
25        Opens the output NetCDF file using CDMS.
26        """
27        self.outputFileName=outputFileName
28        self.outputFile=cdms.open(outputFileName, "w")
29       
30       
31    def writeVariable(self, variable):
32        """
33        Writes the variable object 'variable' to the output file.
34        """
35        self.outputFile.write(variable)
36       
37       
38    def writeGlobalAttributes(self, attDict):
39        """
40        Writes global attributes to the output file.
41        """     
42        for att in attDict:
43            self.outputFile.__setattr__(att, attDict[att])
44        self.outputFile.Conventions="CF-1.0"
45           
46
47    def writeVariableAndGlobalAttributes(self, variable, attDict):
48        """
49        Writes a variable and a set of global attributes to
50        the output file.
51        """
52        self.writeVariable(variable)
53        self.writeGlobalAttributes(attDict)
54
55   
56    def closeFile(self):
57        """
58        Closes the output file.
59        """
60        self.outputFile.close()
61        fixFilePermissions(self.outputFileName)
Note: See TracBrowser for help on using the repository browser.