NetcdfReporting.cpp
Go to the documentation of this file.
1 #include "NetcdfReporting.hpp"
2 #include <rtt/RTT.hpp>
3 #include <rtt/Logger.hpp>
4 #include <rtt/types/Types.hpp>
6 #include "NetcdfMarshaller.hpp"
8 
9 #include "ocl/Component.hpp"
11 
12 #include <netcdf.h>
13 
14 namespace OCL
15 {
16  using namespace RTT;
17  using namespace std;
18 
19  NetcdfReporting::NetcdfReporting(const std::string& fr_name)
20  : ReportingComponent( fr_name ),
21  repfile("ReportFile","Location on disc to store the reports.", "reports.nc")
22  {
23  this->properties()->addProperty( repfile );
24 
25  if(types::TypeInfoRepository::Instance()->getTypeInfo<short>() == 0 )
26  {
27  types::TypeInfoRepository::Instance()->addType(new types::TemplateTypeInfo<short, true>("short"));
28  }
29  }
30 
32  {
33  int retval;
34 
39  retval = nc_create(repfile.get().c_str(), NC_CLOBBER | NC_SHARE, &ncid);
40  if ( retval ) {
41  log(Error) << "Could not create "+repfile.get()+" for reporting."<<endlog();
42  return false;
43  }
44 
49  retval = nc_def_dim(ncid, "time", NC_UNLIMITED, &dimsid);
50  if ( retval ) {
51  log(Error) << "Could not create time dimension "+repfile.get() <<endlog();
52  return false;
53  }
54 
58  retval = nc_enddef( ncid );
59  if ( retval ) {
60  log(Error) << "Could not leave define mode in "+repfile.get() <<endlog();
61  return false;
62  }
63 
66 
67  this->addMarshaller( fheader, fbody );
68 
70  }
71 
73  {
74  int retval;
75 
77 
78  this->removeMarshallers();
79 
83  if ( ncid )
84  retval = nc_close (ncid);
85  if ( retval )
86  log(Error) << "Could not close file "+repfile.get()+" for reporting."<<endlog();
87  }
88 
89 }
DataSourceType get() const
RTT::marsh::MarshallInterface * fheader
bool addMarshaller(RTT::marsh::MarshallInterface *headerM, RTT::marsh::MarshallInterface *bodyM)
NetcdfReporting(const std::string &fr_name)
RTT::marsh::MarshallInterface * fbody
RTT::Property< std::string > repfile
Property< T > & addProperty(const std::string &name, T &attr)
Error
A Component for periodically reporting Component Port contents to a human readable text format...
PropertyBag * properties()
ORO_CREATE_COMPONENT(OCL::logging::Log4cxxAppender)


ocl
Author(s): OCL Development Team
autogenerated on Wed Jun 26 2019 19:26:27