mirror of
https://github.com/nasa/trick.git
synced 2024-12-18 20:57:55 +00:00
#687 do not warn or convert unit --
This commit is contained in:
parent
2a059719ba
commit
d2e81257c2
@ -124,51 +124,53 @@ int Trick::VariableServerThread::var_units(std::string var_name, std::string uni
|
||||
oss << "Variable Server: " << message << std::endl;
|
||||
message_publish(type, oss.str().c_str());
|
||||
};
|
||||
/* if unitless ('--') then do not convert to udunits*/
|
||||
if(units_name.compare("--")){
|
||||
std::string new_units = map_trick_units_to_udunits(units_name) ;
|
||||
if ( units_name.compare(new_units) ) {
|
||||
std::ostringstream oss;
|
||||
oss << "[" << var_name << "] old-style units converted from ["
|
||||
<< units_name << "] to [" << new_units << "]";
|
||||
publish(MSG_WARNING, oss.str());
|
||||
}
|
||||
|
||||
std::string new_units = map_trick_units_to_udunits(units_name) ;
|
||||
if ( units_name.compare(new_units) ) {
|
||||
std::ostringstream oss;
|
||||
oss << "[" << var_name << "] old-style units converted from ["
|
||||
<< units_name << "] to [" << new_units << "]";
|
||||
publish(MSG_WARNING, oss.str());
|
||||
}
|
||||
auto publishError = [&](const std::string& units) {
|
||||
std::ostringstream oss;
|
||||
oss << "units error for [" << var_name << "] [" << units << "]";
|
||||
publish(MSG_ERROR, oss.str());
|
||||
};
|
||||
|
||||
auto publishError = [&](const std::string& units) {
|
||||
std::ostringstream oss;
|
||||
oss << "units error for [" << var_name << "] [" << units << "]";
|
||||
publish(MSG_ERROR, oss.str());
|
||||
};
|
||||
ut_unit * from = ut_parse(Trick::UdUnits::get_u_system(), variable->ref->attr->units, UT_ASCII) ;
|
||||
if ( !from ) {
|
||||
publishError(variable->ref->attr->units);
|
||||
ut_free(from) ;
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
ut_unit * from = ut_parse(Trick::UdUnits::get_u_system(), variable->ref->attr->units, UT_ASCII) ;
|
||||
if ( !from ) {
|
||||
publishError(variable->ref->attr->units);
|
||||
ut_free(from) ;
|
||||
return -1 ;
|
||||
}
|
||||
ut_unit * to = ut_parse(Trick::UdUnits::get_u_system(), new_units.c_str(), UT_ASCII) ;
|
||||
if ( !to ) {
|
||||
publishError(new_units);
|
||||
ut_free(from) ;
|
||||
ut_free(to) ;
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
ut_unit * to = ut_parse(Trick::UdUnits::get_u_system(), new_units.c_str(), UT_ASCII) ;
|
||||
if ( !to ) {
|
||||
publishError(new_units);
|
||||
cv_converter * conversion_factor = ut_get_converter(from, to) ;
|
||||
ut_free(from) ;
|
||||
ut_free(to) ;
|
||||
return -1 ;
|
||||
}
|
||||
if ( !conversion_factor ) {
|
||||
std::ostringstream oss;
|
||||
oss << "[" << var_name << "] cannot convert units from [" << variable->ref->attr->units
|
||||
<< "] to [" << new_units << "]";
|
||||
publish(MSG_ERROR, oss.str());
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
cv_converter * conversion_factor = ut_get_converter(from, to) ;
|
||||
ut_free(from) ;
|
||||
ut_free(to) ;
|
||||
if ( !conversion_factor ) {
|
||||
std::ostringstream oss;
|
||||
oss << "[" << var_name << "] cannot convert units from [" << variable->ref->attr->units
|
||||
<< "] to [" << new_units << "]";
|
||||
publish(MSG_ERROR, oss.str());
|
||||
return -1 ;
|
||||
cv_free(variable->conversion_factor);
|
||||
variable->conversion_factor = conversion_factor ;
|
||||
free(variable->ref->units);
|
||||
variable->ref->units = strdup(new_units.c_str());
|
||||
}
|
||||
|
||||
cv_free(variable->conversion_factor);
|
||||
variable->conversion_factor = conversion_factor ;
|
||||
free(variable->ref->units);
|
||||
variable->ref->units = strdup(new_units.c_str());
|
||||
}
|
||||
return(0) ;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user