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 this->decompose.set(false); 00025 00026 if( types::TypeInfoRepository::Instance()->type("short") == 0 ) 00027 { 00028 types::TypeInfoRepository::Instance()->addType(new types::TemplateTypeInfo<short, true>("short")); 00029 } 00030 } 00031 00032 bool NetcdfReporting::startHook() 00033 { 00034 int retval; 00035 00040 retval = nc_create(repfile.get().c_str(), NC_CLOBBER, &ncid); 00041 if ( retval ) { 00042 log(Error) << "Could not create "+repfile.get()+" for reporting."<<endlog(); 00043 return false; 00044 } 00045 00050 retval = nc_def_dim(ncid, "time", NC_UNLIMITED, &dimsid); 00051 if ( retval ) { 00052 log(Error) << "Could not create time dimension "+repfile.get() <<endlog(); 00053 return false; 00054 } 00055 00059 retval = nc_enddef( ncid ); 00060 if ( retval ) { 00061 log(Error) << "Could not leave define mode in "+repfile.get() <<endlog(); 00062 return false; 00063 } 00064 00065 fheader = new RTT::NetcdfHeaderMarshaller( ncid , dimsid); 00066 fbody = new RTT::NetcdfMarshaller( ncid ); 00067 00068 this->addMarshaller( fheader, fbody ); 00069 00070 return ReportingComponent::startHook(); 00071 } 00072 00073 void NetcdfReporting::stopHook() 00074 { 00075 int retval; 00076 00077 ReportingComponent::stopHook(); 00078 00079 this->removeMarshallers(); 00080 00084 if ( ncid ) 00085 retval = nc_close (ncid); 00086 if ( retval ) 00087 log(Error) << "Could not close file "+repfile.get()+" for reporting."<<endlog(); 00088 } 00089 00090 }