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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/trunk/pydxs/NASAAmesOutputHandler.py@794
Revision 794, 1.4 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"""
6NASAAmesOutputHandler.py
7====================
8
9Output handler when writing files to NASA Ames via CDMS and NAppy.
10
11"""
12
13# Import required modules
14import cdms
15import nappy
16
17# Import package modules including global variables
18from DXErrors import *
19
20
21class NASAAmesOutputHandler:
22
23    def __init__(self, outputFileName):
24        """
25        Opens the output NetCDF file using CDMS.
26        """
27        self.outputFileName=outputFileName
28       
29       
30    def writeVariable(self, variable):
31        """
32        Writes the variable object 'variable' to the output file.
33        """
34        builtNADict=nappy.CdmsToNABuilder([variable])
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            setattr(self.outputFile, att, attDict[att])
44
45
46    def writeVariableAndGlobalAttributes(self, variable, attDict):
47        """
48        Writes a variable and global attributes to output file.
49        """
50        builtNADict=nappy.CdmsToNABuilder([variable], attDict).naDict
51        self.outputFile=nappy.openNAFile(self.outputFileName, 'w', builtNADict)             
52       
53       
54    def closeFile(self):
55        """
56        Closes the output file.
57        """
58        self.outputFile.close()
Note: See TracBrowser for help on using the repository browser.