1 #ifndef PI_PROPERTIES_NETCDFTABLESERIALIZER     2 #define PI_PROPERTIES_NETCDFTABLESERIALIZER     4 #include <rtt/Property.hpp>     5 #include <rtt/base/PropertyIntrospection.hpp>     6 #include <boost/lexical_cast.hpp>    21         : 
public marsh::MarshallInterface
    34           ncid ( ncid ) {index=0;}
    38         virtual void serialize(base::PropertyBase* v) 
    40          Property<PropertyBag>* bag = 
dynamic_cast< Property<PropertyBag>* 
>( v );
    42            this->serialize( *bag );
    44            Property<char>* Pc = 
dynamic_cast< Property<char>* 
>( v );
    50            Property<short>* Ps = 
dynamic_cast< Property<short>* 
>( v );
    56            Property<int>* Pi = 
dynamic_cast< Property<int>* 
>( v );
    62            Property<float>* Pf = 
dynamic_cast< Property<float>* 
>( v );
    68            Property<double>* Pd = 
dynamic_cast< Property<double>* 
>( v );
    74            Property<std::vector<double> >* Pv = 
dynamic_cast< Property<std::vector<double> 
>* >( v );
    83         virtual void serialize(
const PropertyBag &v) 
    86             PropertyBag::const_iterator i = v.getProperties().begin();
    87             i != v.getProperties().end();
    90               this->serialize( *i );
    94         virtual void serialize(
const Property<PropertyBag> &v) 
    96           std::string oldpref = prefix;
   100             prefix = v.getName();
   102             prefix += 
"." + v.getName();
   104           serialize(v.rvalue());
   107           nameless_counter = 0;
   117           signed char value = v->rvalue();
   118           std::string sname = composeName(v->getName());
   123           retval = nc_inq_varid(ncid, sname.c_str(), &varid);
   125             log(Error) << 
"Could not get variable id of " << sname << 
", error " << retval <<endlog();
   130           retval = nc_put_var1_schar(ncid, varid, &index, &value);
   132             log(Error) << 
"Could not write variable " << sname << 
", error " << retval <<endlog();
   143           short value = v->rvalue();
   144           std::string sname = composeName(v->getName());
   149           retval = nc_inq_varid(ncid, sname.c_str(), &varid);
   151             log(Error) << 
"Could not get variable id of " << sname << 
", error " << retval <<endlog();
   156           retval = nc_put_var1_short(ncid, varid, &index, &value);
   158             log(Error) << 
"Could not write variable " << sname << 
", error " << retval <<endlog();
   168           int value = v->rvalue();
   169           std::string sname = composeName(v->getName());
   174           retval = nc_inq_varid(ncid, sname.c_str(), &varid);
   176             log(Error) << 
"Could not get variable id of " << sname << 
", error " << retval <<endlog();
   181           retval = nc_put_var1_int(ncid, varid, &index, &value);
   183             log(Error) << 
"Could not write variable " << sname << 
", error " << retval <<endlog();
   193           float value = v->rvalue();
   194           std::string sname = composeName(v->getName());
   199           retval = nc_inq_varid(ncid, sname.c_str(), &varid);
   201             log(Error) << 
"Could not get variable id of " << sname << 
", error " << retval <<endlog();
   206           retval = nc_put_var1_float(ncid, varid, &index, &value);
   208             log(Error) << 
"Could not write variable " << sname << 
", error " << retval <<endlog();
   219           double value = v->rvalue();
   220           std::string sname = composeName(v->getName());
   225           retval = nc_inq_varid(ncid, sname.c_str(), &varid);
   227             log(Error) << 
"Could not get variable id of " << sname << 
", error " << retval <<endlog();
   232           retval = nc_put_var1_double(ncid, varid, &index, &value);
   234             log(Error) << 
"Could not write variable " << sname << 
", error " << retval <<endlog();
   240         void store(Property<std::vector<double> > *v)
   244           const char *name = v->getName().c_str();
   245           size_t start[2], count[2];
   250           start[0] = index; start[1] = 0;
   254           count[0] = 1; count[1] = v->rvalue().size();
   256           retval = nc_inq_varid(ncid, name, &varid);
   258             log(Error) << 
"Could not get variable id of " << name << 
", error " << retval <<endlog();
   260           retval = nc_put_vara_double(ncid, varid, start, count, &(v->rvalue().front()));
   262             log(Error) << 
"Could not write variable " << name << 
", error " << retval <<endlog();
   266         std::string composeName(std::string propertyName)
   268           std::string last_name;
   270           if( propertyName.empty() ) {
   272             last_name = boost::lexical_cast<std::string>( nameless_counter );
   275             nameless_counter = 0;
   276             last_name = propertyName;
   278           if ( prefix.empty() )
   281             return prefix + 
"." + last_name;
 void store(Property< float > *v)
Write float data to corresponding variable name. 
 
A marsh::MarshallInterface for writing data logs into the variables of a netcdf file. 
 
void store(Property< int > *v)
Write int data to corresponding variable name. 
 
void store(Property< short > *v)
Write short data to corresponding variable name. 
 
void store(Property< std::vector< double > > *v)
Write double array data into corresponding variable name. 
 
virtual void flush()
Increase unlimited time dimension. 
 
void store(Property< char > *v)
Write char data to corresponding variable name. 
 
NetcdfMarshaller(int ncid)
Create a new NetcdfMarshaller. 
 
void store(Property< double > *v)
Write double data to corresponding variable name.