NetcdfReporting.cpp
Go to the documentation of this file.
00001 #include "NetcdfReporting.hpp"
00002 #include <rtt/RTT.hpp>
00003 #include <rtt/Logger.hpp>
00004 #include <rtt/types/Types.hpp>
00005 #include <rtt/types/TemplateTypeInfo.hpp>
00006 #include "NetcdfMarshaller.hpp"
00007 #include "NetcdfHeaderMarshaller.hpp"
00008 
00009 #include "ocl/Component.hpp"
00010 ORO_CREATE_COMPONENT(OCL::NetcdfReporting)
00011 
00012 #include <netcdf.h>
00013 
00014 namespace OCL
00015 {
00016     using namespace RTT;
00017     using namespace std;
00018 
00019     NetcdfReporting::NetcdfReporting(const std::string& fr_name)
00020         : ReportingComponent( fr_name ),
00021           repfile("ReportFile","Location on disc to store the reports.", "reports.nc")
00022     {
00023         this->properties()->addProperty( repfile );
00024 
00025         if(types::TypeInfoRepository::Instance()->getTypeInfo<short>() == 0 )
00026         {
00027                 types::TypeInfoRepository::Instance()->addType(new types::TemplateTypeInfo<short, true>("short"));
00028         }
00029     }
00030 
00031     bool NetcdfReporting::startHook()
00032     {
00033       int retval;
00034 
00039       retval = nc_create(repfile.get().c_str(), NC_CLOBBER | NC_SHARE, &ncid);
00040       if ( retval ) {
00041        log(Error) << "Could not create "+repfile.get()+" for reporting."<<endlog();
00042        return false;
00043       }
00044 
00049       retval = nc_def_dim(ncid, "time", NC_UNLIMITED, &dimsid);
00050       if ( retval ) {
00051        log(Error) << "Could not create time dimension "+repfile.get() <<endlog();
00052        return false;
00053       }
00054 
00058       retval = nc_enddef( ncid );
00059       if ( retval ) {
00060        log(Error) << "Could not leave define mode in "+repfile.get() <<endlog();
00061        return false;
00062       }
00063 
00064       fheader = new RTT::NetcdfHeaderMarshaller( ncid , dimsid);
00065       fbody = new RTT::NetcdfMarshaller( ncid );
00066                 
00067       this->addMarshaller( fheader, fbody );
00068 
00069       return ReportingComponent::startHook();
00070     }
00071 
00072   void NetcdfReporting::stopHook()
00073   {
00074     int retval;
00075 
00076     ReportingComponent::stopHook();
00077 
00078     this->removeMarshallers();
00079 
00083     if ( ncid )
00084       retval = nc_close (ncid);
00085     if ( retval )
00086       log(Error) << "Could not close file "+repfile.get()+" for reporting."<<endlog();
00087   }
00088 
00089 }


ocl
Author(s): OCL Development Team
autogenerated on Sat Jun 8 2019 18:48:54