source: TI03-DataExtractor/branches/csml_hooks/CSMLOutputHandler.py @ 799

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/branches/csml_hooks/CSMLOutputHandler.py@799
Revision 799, 1.3 KB checked in by astephen, 14 years ago (diff)

Set up stub classes for CSML to interact with.

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