Merge pull request #689 from nasa/unitless-no-convert

#687 do not warn or convert unit --
This commit is contained in:
Scott Fennell 2018-10-30 10:59:40 -05:00 committed by GitHub
commit b23fda4e2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -124,51 +124,53 @@ int Trick::VariableServerThread::var_units(std::string var_name, std::string uni
oss << "Variable Server: " << message << std::endl; oss << "Variable Server: " << message << std::endl;
message_publish(type, oss.str().c_str()); 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) ; auto publishError = [&](const std::string& units) {
if ( units_name.compare(new_units) ) { std::ostringstream oss;
std::ostringstream oss; oss << "units error for [" << var_name << "] [" << units << "]";
oss << "[" << var_name << "] old-style units converted from [" publish(MSG_ERROR, oss.str());
<< units_name << "] to [" << new_units << "]"; };
publish(MSG_WARNING, oss.str());
}
auto publishError = [&](const std::string& units) { ut_unit * from = ut_parse(Trick::UdUnits::get_u_system(), variable->ref->attr->units, UT_ASCII) ;
std::ostringstream oss; if ( !from ) {
oss << "units error for [" << var_name << "] [" << units << "]"; publishError(variable->ref->attr->units);
publish(MSG_ERROR, oss.str()); ut_free(from) ;
}; return -1 ;
}
ut_unit * from = ut_parse(Trick::UdUnits::get_u_system(), variable->ref->attr->units, UT_ASCII) ; ut_unit * to = ut_parse(Trick::UdUnits::get_u_system(), new_units.c_str(), UT_ASCII) ;
if ( !from ) { if ( !to ) {
publishError(variable->ref->attr->units); publishError(new_units);
ut_free(from) ; ut_free(from) ;
return -1 ; ut_free(to) ;
} return -1 ;
}
ut_unit * to = ut_parse(Trick::UdUnits::get_u_system(), new_units.c_str(), UT_ASCII) ; cv_converter * conversion_factor = ut_get_converter(from, to) ;
if ( !to ) {
publishError(new_units);
ut_free(from) ; ut_free(from) ;
ut_free(to) ; 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) ; cv_free(variable->conversion_factor);
ut_free(from) ; variable->conversion_factor = conversion_factor ;
ut_free(to) ; free(variable->ref->units);
if ( !conversion_factor ) { variable->ref->units = strdup(new_units.c_str());
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());
} }
return(0) ; return(0) ;
} }