From d2e81257c27503970a4f052ac70021c05f238090 Mon Sep 17 00:00:00 2001 From: Scott Fennell Date: Tue, 30 Oct 2018 10:40:46 -0500 Subject: [PATCH] #687 do not warn or convert unit -- --- .../VariableServerThread_commands.cpp | 76 ++++++++++--------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/trick_source/sim_services/VariableServer/VariableServerThread_commands.cpp b/trick_source/sim_services/VariableServer/VariableServerThread_commands.cpp index cb182d86..17ca85ab 100644 --- a/trick_source/sim_services/VariableServer/VariableServerThread_commands.cpp +++ b/trick_source/sim_services/VariableServer/VariableServerThread_commands.cpp @@ -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) ; }