diff --git a/trick_source/trick_swig/swig_convert_units.cpp b/trick_source/trick_swig/swig_convert_units.cpp index 096c22fc..f8637603 100644 --- a/trick_source/trick_swig/swig_convert_units.cpp +++ b/trick_source/trick_swig/swig_convert_units.cpp @@ -34,3 +34,47 @@ int convert_united_value( std::string & to_units , std::string & from_units , do return 0 ; } +int scale_united_value( std::string & to_units , std::string & from_units , long long * val ) { + + if ( from_units.compare("--") ) { + try { + Units_t * from = new_units(from_units.c_str()) ; + Units_t * to = new_units(to_units.c_str()) ; + UnitsConvFn_t conv_fn; + if (conv_fn_u(from, to, &conv_fn) != CONV_OK) { + throw Unit::CONVERSION_ERROR(); + } + *val = (long long)(conv_fn.C[1] * (*val)) ; + free(from) ; + free(to) ; + } + catch (Unit::CONVERSION_ERROR & ce_err ) { + PyErr_SetString(PyExc_AttributeError,"Units conversion Error"); + return -1 ; + } + } + return 0 ; +} + +int scale_united_value( std::string & to_units , std::string & from_units , double * val ) { + + if ( from_units.compare("--") ) { + try { + Units_t * from = new_units(from_units.c_str()) ; + Units_t * to = new_units(to_units.c_str()) ; + UnitsConvFn_t conv_fn; + if (conv_fn_u(from, to, &conv_fn) != CONV_OK) { + throw Unit::CONVERSION_ERROR(); + } + *val = conv_fn.C[1] * (*val) ; + free(from) ; + free(to) ; + } + catch (Unit::CONVERSION_ERROR & ce_err ) { + PyErr_SetString(PyExc_AttributeError,"Units conversion Error"); + return -1 ; + } + } + return 0 ; +} + diff --git a/trick_source/trick_swig/swig_convert_units.hh b/trick_source/trick_swig/swig_convert_units.hh index ab3cdc86..2ba10947 100644 --- a/trick_source/trick_swig/swig_convert_units.hh +++ b/trick_source/trick_swig/swig_convert_units.hh @@ -6,4 +6,6 @@ int convert_united_value( std::string & to_units , std::string & from_units , long long * val ) ; int convert_united_value( std::string & to_units , std::string & from_units , double * val ) ; +int scale_united_value( std::string & to_units , std::string & from_units , long long * val ) ; +int scale_united_value( std::string & to_units , std::string & from_units , double * val ) ; #endif diff --git a/trick_source/trick_swig/swig_double.cpp b/trick_source/trick_swig/swig_double.cpp index 5b034370..f831b084 100644 --- a/trick_source/trick_swig/swig_double.cpp +++ b/trick_source/trick_swig/swig_double.cpp @@ -46,7 +46,7 @@ PyObject * swig_double::__add__( PyObject * obj1 ) { swig_int * temp_m = reinterpret_cast< swig_int * >(argp2) ; new_value = (double)temp_m->value ; - conv_ret = convert_united_value( units , temp_m->units , &new_value ) ; + conv_ret = scale_united_value( units , temp_m->units , &new_value ) ; if ( conv_ret == 0 ) { result->value = value + new_value ; } else { @@ -55,7 +55,7 @@ PyObject * swig_double::__add__( PyObject * obj1 ) { } else if (SWIG_IsOK(SWIG_ConvertPtr(obj1, &argp2,SWIG_TypeQuery("swig_double *"), 0 ))) { swig_double * temp_m = reinterpret_cast< swig_double * >(argp2) ; new_value = temp_m->value ; - conv_ret = convert_united_value( units , temp_m->units , &new_value ) ; + conv_ret = scale_united_value( units , temp_m->units , &new_value ) ; if ( conv_ret == 0 ) { result->value = value + new_value ; } else { @@ -86,7 +86,7 @@ PyObject * swig_double::__sub__( PyObject * obj1 ) { swig_int * temp_m = reinterpret_cast< swig_int * >(argp2) ; new_value = (double)temp_m->value ; - conv_ret = convert_united_value( units , temp_m->units , &new_value ) ; + conv_ret = scale_united_value( units , temp_m->units , &new_value ) ; if ( conv_ret == 0 ) { result->value = value - new_value ; } else { @@ -95,7 +95,7 @@ PyObject * swig_double::__sub__( PyObject * obj1 ) { } else if (SWIG_IsOK(SWIG_ConvertPtr(obj1, &argp2,SWIG_TypeQuery("swig_double *"), 0 ))) { swig_double * temp_m = reinterpret_cast< swig_double * >(argp2) ; new_value = temp_m->value ; - conv_ret = convert_united_value( units , temp_m->units , &new_value ) ; + conv_ret = scale_united_value( units , temp_m->units , &new_value ) ; if ( conv_ret == 0 ) { result->value = value - new_value ; } else { @@ -450,7 +450,7 @@ PyObject * swig_double::__iadd__( PyObject * obj1 ) { } else if (SWIG_IsOK(SWIG_ConvertPtr(obj1, &argp2,SWIG_TypeQuery("swig_int *"), 0 ))) { swig_int * temp_m = reinterpret_cast< swig_int * >(argp2) ; new_val = (double)temp_m->value ; - conv_ret = convert_united_value( units , temp_m->units , &new_val ) ; + conv_ret = scale_united_value( units , temp_m->units , &new_val ) ; if ( conv_ret == 0 ) { value += new_val ; } else { @@ -459,7 +459,7 @@ PyObject * swig_double::__iadd__( PyObject * obj1 ) { } else if (SWIG_IsOK(SWIG_ConvertPtr(obj1, &argp2,SWIG_TypeQuery("swig_double *"), 0 ))) { swig_double * temp_m = reinterpret_cast< swig_double * >(argp2) ; new_val = temp_m->value ; - conv_ret = convert_united_value( units , temp_m->units , &new_val ) ; + conv_ret = scale_united_value( units , temp_m->units , &new_val ) ; if ( conv_ret == 0 ) { value += new_val ; } else { @@ -485,7 +485,7 @@ PyObject * swig_double::__isub__( PyObject * obj1 ) { } else if (SWIG_IsOK(SWIG_ConvertPtr(obj1, &argp2,SWIG_TypeQuery("swig_int *"), 0 ))) { swig_int * temp_m = reinterpret_cast< swig_int * >(argp2) ; new_val = temp_m->value ; - conv_ret = convert_united_value( units , temp_m->units , &new_val ) ; + conv_ret = scale_united_value( units , temp_m->units , &new_val ) ; if ( conv_ret == 0 ) { value -= new_val ; } else { @@ -494,7 +494,7 @@ PyObject * swig_double::__isub__( PyObject * obj1 ) { } else if (SWIG_IsOK(SWIG_ConvertPtr(obj1, &argp2,SWIG_TypeQuery("swig_double *"), 0 ))) { swig_double * temp_m = reinterpret_cast< swig_double * >(argp2) ; new_val = temp_m->value ; - conv_ret = convert_united_value( units , temp_m->units , &new_val ) ; + conv_ret = scale_united_value( units , temp_m->units , &new_val ) ; if ( conv_ret == 0 ) { value -= new_val ; } else { diff --git a/trick_source/trick_swig/swig_int.cpp b/trick_source/trick_swig/swig_int.cpp index 09e7d8ed..251f1f26 100644 --- a/trick_source/trick_swig/swig_int.cpp +++ b/trick_source/trick_swig/swig_int.cpp @@ -43,7 +43,7 @@ PyObject * swig_int::__add__( PyObject * obj1 ) { long long new_val ; swig_int * temp_m = reinterpret_cast< swig_int * >(argp2) ; new_val = temp_m->value ; - conv_ret = convert_united_value( units , temp_m->units , &new_val ) ; + conv_ret = scale_united_value( units , temp_m->units , &new_val ) ; if ( conv_ret == 0 ) { result->value = value + new_val ; } else { @@ -53,7 +53,7 @@ PyObject * swig_int::__add__( PyObject * obj1 ) { double new_val ; swig_double * temp_m = reinterpret_cast< swig_double * >(argp2) ; new_val = temp_m->value ; - conv_ret = convert_united_value( units , temp_m->units , &new_val ) ; + conv_ret = scale_united_value( units , temp_m->units , &new_val ) ; if ( conv_ret == 0 ) { result->value = (long long)(round(value + new_val)) ; } else { @@ -83,7 +83,7 @@ PyObject * swig_int::__sub__( PyObject * obj1 ) { long long new_val ; swig_int * temp_m = reinterpret_cast< swig_int * >(argp2) ; new_val = temp_m->value ; - conv_ret = convert_united_value( units , temp_m->units , &new_val ) ; + conv_ret = scale_united_value( units , temp_m->units , &new_val ) ; if ( conv_ret == 0 ) { result->value = value - new_val ; } else { @@ -93,7 +93,7 @@ PyObject * swig_int::__sub__( PyObject * obj1 ) { double new_val ; swig_double * temp_m = reinterpret_cast< swig_double * >(argp2) ; new_val = temp_m->value ; - conv_ret = convert_united_value( units , temp_m->units , &new_val ) ; + conv_ret = scale_united_value( units , temp_m->units , &new_val ) ; if ( conv_ret == 0 ) { result->value = (long long)(round(value - new_val)) ; } else { @@ -626,7 +626,7 @@ PyObject * swig_int::__iadd__( PyObject * obj1 ) { long long new_val ; swig_int * temp_m = reinterpret_cast< swig_int * >(argp2) ; new_val = temp_m->value ; - conv_ret = convert_united_value( units , temp_m->units , &new_val ) ; + conv_ret = scale_united_value( units , temp_m->units , &new_val ) ; if ( conv_ret == 0 ) { value += new_val ; } else { @@ -636,7 +636,7 @@ PyObject * swig_int::__iadd__( PyObject * obj1 ) { double new_val ; swig_double * temp_m = reinterpret_cast< swig_double * >(argp2) ; new_val = temp_m->value ; - conv_ret = convert_united_value( units , temp_m->units , &new_val ) ; + conv_ret = scale_united_value( units , temp_m->units , &new_val ) ; if ( conv_ret == 0 ) { value = (long long)round(value + new_val) ; } else { @@ -663,7 +663,7 @@ PyObject * swig_int::__isub__( PyObject * obj1 ) { long long new_val ; swig_int * temp_m = reinterpret_cast< swig_int * >(argp2) ; new_val = temp_m->value ; - conv_ret = convert_united_value( units , temp_m->units , &new_val ) ; + conv_ret = scale_united_value( units , temp_m->units , &new_val ) ; if ( conv_ret == 0 ) { value -= new_val ; } else { @@ -673,7 +673,7 @@ PyObject * swig_int::__isub__( PyObject * obj1 ) { double new_val ; swig_double * temp_m = reinterpret_cast< swig_double * >(argp2) ; new_val = temp_m->value ; - conv_ret = convert_united_value( units , temp_m->units , &new_val ) ; + conv_ret = scale_united_value( units , temp_m->units , &new_val ) ; if ( conv_ret == 0 ) { value = (long long)round(value - new_val) ; } else {