LRAUV  revA
NetCdfWriter.h
Go to the documentation of this file.
1 
9 #ifndef NETCDFWRITER_H_
10 #define NETCDFWRITER_H_
11 
12 #include "utils/NetCdf.h"
13 
14 #include "io/FileOutStream.h"
15 #include "utils/Timestamp.h"
16 
17 class DataValue;
18 class ElementURI;
19 class FileOutStream;
20 class Unit;
21 
24 
32 class NetCdfWriter : public NetCdf
33 {
34 public:
35 
37 
38 
40  static NetCdfWriter* NewNetCdfWriter( const char* fileName, bool version4, const char* trajectoryName = "LRAUVTrajectory" );
41 
43  virtual ~NetCdfWriter();
44 
46  bool isOk() const
47  {
48  return ok_;
49  }
50 
51  const NetCdfAtt* addGlobalAtt( const Str& name, const Str& value );
52 
53  const NetCdfAtt* addGlobalAtt( const Str& name, const unsigned char value );
54 
55  const NetCdfAtt* addGlobalAtt( const Str& name, const short value );
56 
57  const NetCdfAtt* addGlobalAtt( const Str& name, const int value );
58 
59  const NetCdfAtt* addGlobalAtt( const Str& name, const float value );
60 
61  const NetCdfAtt* addGlobalAtt( const Str& name, const double value );
62 
63  const NetCdfDim* addDim( const Str& name, const unsigned int dimSize );
64 
65  NetCdfVar* addVar( const Str& name, const NetCdfType netCdfType, const NetCdfDim* dimTime = NULL, const NetCdfDim* dimM = NULL, const NetCdfDim* dimN = NULL, const NetCdfDim* dimO = NULL );
66 
67  NetCdfVar* addStaticVar( const Str& name, const NetCdfType netCdfType, const NetCdfDim* dim = NULL );
68 
69  const NetCdfAtt* addVarAtt( NetCdfVar* netCdfVar, const Str& name, const Str& value );
70 
71  const NetCdfAtt* addVarAtt( NetCdfVar* netCdfVar, const Str& name, unsigned char value );
72 
73  const NetCdfAtt* addVarAtt( NetCdfVar* netCdfVar, const Str& name, const int value );
74 
75  const NetCdfAtt* addVarAtt( NetCdfVar* netCdfVar, const Str& name, const float value );
76 
77  const NetCdfAtt* addVarAtt( NetCdfVar* netCdfVar, const Str& name, const double value );
78 
79  void setAttValue( const NetCdfAtt* netCdfAtt, const Str& value );
80 
81  void setAttValue( const NetCdfAtt* netCdfAtt, const unsigned char value );
82 
83  void setAttValue( const NetCdfAtt* netCdfAtt, const int value );
84 
85  void setAttValue( const NetCdfAtt* netCdfAtt, const float value );
86 
87  void setAttValue( const NetCdfAtt* netCdfAtt, const double value );
88 
89  NetCdfGroup* addGroup( const Str& name );
90 
91  NetCdfGroup* findGroup( const Str& name );
92 
95  bool initialize( );
96 
98  bool writeRecord( Timestamp& timestamp );
99 
101  bool writeVarRecord( NetCdfVar* netCdfVar, const ElementURI* uri = NULL );
102 
105  bool finalize( );
106 
107 protected:
108 
110  NetCdfWriter( const char* filename, bool version4, const char* trajectoryName );
111 
113  NetCdfWriter( const char* name, int parentNcId );
114 
115  const NetCdfAtt* addAtt( NetCdfAtts& atts, int varId, const Str& name, const Str& value );
116 
117  const NetCdfAtt* addAtt( NetCdfAtts& atts, int varId, const Str& name, const unsigned char value );
118 
119  const NetCdfAtt* addAtt( NetCdfAtts& atts, int varId, const Str& name, const short value );
120 
121  const NetCdfAtt* addAtt( NetCdfAtts& atts, int varId, const Str& name, const int value );
122 
123  const NetCdfAtt* addAtt( NetCdfAtts& atts, int varId, const Str& name, const float value );
124 
125  const NetCdfAtt* addAtt( NetCdfAtts& atts, int varId, const Str& name, const double value );
126 
128  int putValue( NetCdfVar* netCdfVar, size_t index[], double value );
129 
130  bool ok_;
132  unsigned int numRecs_;
135  const char* trajectoryName_;
136  bool version4_;
137  const NetCdfDim* trajectoryLenDim_;
139  const NetCdfDim* timeDim_;
141  unsigned long long currentLocation_;
142  NetCdfGroups groups_; /* group map */
143 
144 private:
145  // Note that the copy constructor below is private and not given a body.
146  // Any attempt to call it will return a compiler error.
147  NetCdfWriter( const NetCdfWriter& old ); // disallow copy constructor
148 
149 };
150 
151 #endif /*NETCDFWRITER_H_*/
bool isOk() const
Indicates intialization success.
Definition: NetCdfWriter.h:46
NetCdfGroups groups_
Definition: NetCdfWriter.h:142
const NetCdfAtt * addAtt(NetCdfAtts &atts, int varId, const Str &name, const Str &value)
Definition: NetCdfWriter.cpp:574
NetCdfVar * addVar(const Str &name, const NetCdfType netCdfType, const NetCdfDim *dimTime=NULL, const NetCdfDim *dimM=NULL, const NetCdfDim *dimN=NULL, const NetCdfDim *dimO=NULL)
Definition: NetCdfWriter.cpp:96
const char * trajectoryName_
Definition: NetCdfWriter.h:135
const NetCdfDim * trajectoryLenDim_
Definition: NetCdfWriter.h:137
NetCdfVar * addStaticVar(const Str &name, const NetCdfType netCdfType, const NetCdfDim *dim=NULL)
Definition: NetCdfWriter.cpp:155
const NetCdfAtt * addVarAtt(NetCdfVar *netCdfVar, const Str &name, const Str &value)
Definition: NetCdfWriter.cpp:188
NetCdfWriter(const char *filename, bool version4, const char *trajectoryName)
Protected Constructor.
Definition: NetCdfWriter.cpp:504
bool initialized_
Definition: NetCdfWriter.h:133
bool finalized_
Definition: NetCdfWriter.h:134
NetCdfGroup * addGroup(const Str &name)
Definition: NetCdfWriter.cpp:250
Wraps a c FILE* handle with an OutStream class.
Definition: FileOutStream.h:26
FastMap< const Str, NetCdfGroup * > NetCdfGroups
Definition: NetCdfWriter.h:36
A DataValue is an abstract base class for a data value and associated engineering units of the value...
Definition: DataValue.h:35
int putValue(NetCdfVar *netCdfVar, size_t index[], double value)
Used by writeVarRecord to put a value in the variable.
Definition: NetCdfWriter.cpp:447
bool finalize()
Set the number of records in the file header Returns true if no error.
Definition: NetCdfWriter.cpp:481
A very compact, very simple netCDF writer with a minimal feature set.
Definition: NetCdfWriter.h:32
NetCdfType
Definition: NetCdf.h:44
NetCdfGroup * findGroup(const Str &name)
Definition: NetCdfWriter.cpp:261
virtual ~NetCdfWriter()
Destructor.
Definition: NetCdfWriter.cpp:33
Replacement for standard template class string.
Definition: Str.h:12
static NetCdfWriter * NewNetCdfWriter(const char *fileName, bool version4, const char *trajectoryName="LRAUVTrajectory")
Returns an newNetCdfWriter of a NetCdfWriter for a file.
Definition: NetCdfWriter.cpp:20
unsigned long long currentLocation_
Definition: NetCdfWriter.h:141
Contains the NetCdf class declaration.
bool version4_
Definition: NetCdfWriter.h:136
const NetCdfDim * timeDim_
Definition: NetCdfWriter.h:139
FastMap< const Str, NetCdfAtt * > NetCdfAtts
Definition: NetCdf.h:82
bool writeVarRecord(NetCdfVar *netCdfVar, const ElementURI *uri=NULL)
Just write the specified variable.
Definition: NetCdfWriter.cpp:358
void setAttValue(const NetCdfAtt *netCdfAtt, const Str &value)
Definition: NetCdfWriter.cpp:213
Abstract base class for NetCcfReader and NetCdfWriter.
Definition: NetCdf.h:40
NetCdfWriter NetCdfGroup
Definition: NetCdfWriter.h:22
bool ok_
Definition: NetCdfWriter.h:130
Str filename_
Definition: NetCdfWriter.h:131
Code unit that represents a unique name for a DataElement.
Definition: ElementURI.h:27
Contains the Timestamp and Timespan class declarations.
const NetCdfDim * addDim(const Str &name, const unsigned int dimSize)
Definition: NetCdfWriter.cpp:69
bool writeRecord(Timestamp &timestamp)
Write all the variables.
Definition: NetCdfWriter.cpp:298
const NetCdfAtt * addGlobalAtt(const Str &name, const Str &value)
Definition: NetCdfWriter.cpp:39
unsigned int numRecs_
Definition: NetCdfWriter.h:132
Code that represents an engineering unit.
Definition: Unit.h:24
Definition: NetCdf.h:84
Contains the FileOutStream class declaration.
Represents absolute times.
Definition: Timestamp.h:31
NetCdfVar * trajectoryVar_
Definition: NetCdfWriter.h:138
NetCdfVar * timeVar_
Definition: NetCdfWriter.h:140
bool initialize()
Opens a NetCdfWriter for a file Returns true if no error.
Definition: NetCdfWriter.cpp:266