mirror of
https://github.com/nasa/trick.git
synced 2024-12-18 20:57:55 +00:00
Use udunits package for units conversions
Converted data products to use udunits. refs #231
This commit is contained in:
parent
1454236a81
commit
d72aa59fdd
11
include/trick/map_trick_units_to_udunits.hh
Normal file
11
include/trick/map_trick_units_to_udunits.hh
Normal file
@ -0,0 +1,11 @@
|
||||
// List prototypes to convert old units strings to udunits
|
||||
|
||||
#ifndef MAP_TRICK_UNITS_TO_UDUNITS_HH
|
||||
#define MAP_TRICK_UNITS_TO_UDUNITS_HH
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string map_trick_units_to_udunits( std::string orig_units ) ;
|
||||
|
||||
#endif
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "Utilities.hh"
|
||||
|
||||
// Provides units check capability.
|
||||
std::string map_trick_units_to_udunits( std::string orig_units ) ;
|
||||
#include "trick/map_trick_units_to_udunits.hh"
|
||||
|
||||
extern llvm::cl::opt< bool > units_truth_is_scary ;
|
||||
|
||||
|
@ -58,7 +58,7 @@ $(ICG): $(OBJECTS) $(UDUNITS_OBJS)
|
||||
$(CXX) -o $@ $(OBJECTS) $(UNITS_CONV_OBJ) $(UDUNITS_OBJS) $(LLVMLDFLAGS) $(CLANGLIBS)
|
||||
|
||||
# Only FieldDescription.cpp includes the units conversion header.
|
||||
$(OBJ_DIR)/FieldDescription.o : CXXFLAGS += $(UNITS_CONV_INCLUDE)
|
||||
$(OBJ_DIR)/FieldDescription.o : CXXFLAGS += -I$(TRICK_HOME)/include
|
||||
$(OBJ_DIR)/HeaderSearchDirs.o : CXXFLAGS += -DLLVM_HOME=\"${LLVM_HOME}\"
|
||||
$(OBJ_DIR)/main.o : CXXFLAGS += $(UNITS_CONV_INCLUDE)
|
||||
|
||||
|
@ -7,7 +7,7 @@ CPP = c++
|
||||
|
||||
DPX_DIR = ../..
|
||||
|
||||
CFLAGS = -g -Wall
|
||||
CFLAGS = -g -Wall $(UDUNITS_INCLUDES)
|
||||
|
||||
INCDIRS = -I${DPX_DIR} -I../../.. -I${TRICK_HOME}/include -I/usr/include/libxml2 -I$(MOTIF_HOME)/include -I$(TRICK_HOME)/trick_source/data_products/fermi-ware
|
||||
|
||||
@ -35,7 +35,7 @@ DPX_LIBS = -L${DPX_DIR}/lib_${TRICK_HOST_CPU} -lDPC -lDPM
|
||||
FERMI_WARE_LIB = $(TRICK_HOME)/trick_source/data_products/fermi-ware/object_${TRICK_HOST_CPU}/libfermi.a
|
||||
|
||||
#HDF5_LIB is assigned in Makefile.common
|
||||
ALL_LIBS = $(DPX_LIBS) $(FERMI_WARE_LIB) ${DP_LIBS} ${TRICK_UNIT_LIBS} $(LIBXML) ${HDF5_LIB} -ldl $(FERMI_WARE_DIR)
|
||||
ALL_LIBS = $(DPX_LIBS) $(FERMI_WARE_LIB) ${DP_LIBS} ${TRICK_UNIT_LIBS} $(LIBXML) ${HDF5_LIB} -ldl $(FERMI_WARE_DIR) -ludunits2
|
||||
|
||||
#############################################################################
|
||||
## MODEL TARGETS ##
|
||||
|
@ -58,7 +58,7 @@ GPViewCurveNode::GPViewCurveNode( Widget Toplevel,
|
||||
curve_x_label = Curve->getXAttribute("label");
|
||||
} else {
|
||||
std::string curve_x_var_name = (dpc_curve->getXVarName()) ? dpc_curve->getXVarName() : "" ;
|
||||
std::string curve_x_units = (dpc_curve->getXAttribute("units")) ? dpc_curve->getXAttribute("units") : "--";
|
||||
std::string curve_x_units = (dpc_curve->getXAttribute("units")) ? dpc_curve->getXAttribute("units") : "1";
|
||||
curve_x_label = curve_x_var_name + "(" + curve_x_units + ")";
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ GPViewCurveNode::GPViewCurveNode( Widget Toplevel,
|
||||
if (Curve->getYAttribute("label")) {
|
||||
curve_y_label = Curve->getYAttribute("label");
|
||||
} else {
|
||||
std::string curve_y_units = (dpc_curve->getYAttribute("units")) ? dpc_curve->getYAttribute("units") : "--";
|
||||
std::string curve_y_units = (dpc_curve->getYAttribute("units")) ? dpc_curve->getYAttribute("units") : "1";
|
||||
curve_y_label = curve_y_var_name + "(" + curve_y_units + ")";
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ DPX_DIR = ../..
|
||||
|
||||
INCDIRS = -I${DPX_DIR} -I../../.. -I${TRICK_HOME}/include -I/usr/include/libxml2 $(MOTIF_INCDIR)
|
||||
|
||||
CFLAGS = -g -Wall
|
||||
CFLAGS = -g -Wall $(UDUNITS_INCLUDES)
|
||||
|
||||
OBJDIR = object_${TRICK_HOST_CPU}
|
||||
LIBDIR = ${DPX_DIR}/lib_${TRICK_HOST_CPU}
|
||||
@ -40,7 +40,7 @@ DP_LIBS = -L../../../lib_${TRICK_HOST_CPU} -llog -lvar -leqparse -L${TRI
|
||||
MODEL_LIBS = -L${DPX_DIR}/lib_${TRICK_HOST_CPU} -lDPM
|
||||
CONTROLLER_LIBS = -L${DPX_DIR}/lib_${TRICK_HOST_CPU} -lDPC
|
||||
|
||||
ALL_LIBS = $(CONTROLLER_LIBS) $(MODEL_LIBS) ${DP_LIBS} ${TRICK_UNIT_LIBS} ${HDF5_LIB} -ldl
|
||||
ALL_LIBS = $(CONTROLLER_LIBS) $(MODEL_LIBS) ${DP_LIBS} ${TRICK_UNIT_LIBS} ${HDF5_LIB} -ldl -ludunits2
|
||||
|
||||
#############################################################################
|
||||
## MODEL TARGETS ##
|
||||
|
@ -1,43 +1,41 @@
|
||||
|
||||
#include <udunits2.h>
|
||||
#include "DPC/DPC_UnitConvDataStream.hh"
|
||||
|
||||
extern ut_system * u_system ;
|
||||
|
||||
// CONSTRUCTOR
|
||||
DPC_UnitConvDataStream::DPC_UnitConvDataStream(DataStream* ds, const char *ToUnits, const char *FromUnitsHint ) {
|
||||
Unit *to_unit = NULL;
|
||||
Unit *from_unit = NULL;
|
||||
std::string from_unit_string;
|
||||
|
||||
|
||||
ut_unit * to = NULL ;
|
||||
ut_unit * from = NULL ;
|
||||
|
||||
const char * recorded_units = ds->getUnit().c_str();
|
||||
|
||||
source_ds = ds;
|
||||
|
||||
if ((ToUnits != NULL) && (strcmp(ToUnits,"") != 0) && (strcmp(ToUnits,"--") != 0)) {
|
||||
try {
|
||||
to_unit = new Unit(ToUnits);
|
||||
} catch (Unit::CONVERSION_ERROR) {
|
||||
delete to_unit;
|
||||
to_unit = NULL;
|
||||
std::cerr << "ERROR: Invalid units: \"" << ToUnits << "\"." << std::endl;
|
||||
}
|
||||
if (ToUnits != NULL) {
|
||||
to = ut_parse(u_system, ToUnits, UT_ASCII) ;
|
||||
to_units = ToUnits ;
|
||||
}
|
||||
|
||||
// If the user has specified a units conversion and those units are valid ...
|
||||
if ( to_unit != NULL ) {
|
||||
if ( to != NULL ) {
|
||||
// If the recorded data file doesn't contain the units in which the data is recorded ...
|
||||
if ((recorded_units == NULL) || (strcmp(recorded_units,"") == 0)) {
|
||||
// If the user didn't give us a hint as to what the units are (using var@from_units) ...
|
||||
if ((FromUnitsHint == NULL) || (strcmp(FromUnitsHint,"") == 0)) {
|
||||
cf = new UCFn("--", "--", 1.0, 0.0);
|
||||
// set the from units to the same as the to units.
|
||||
cf = cv_get_trivial() ;
|
||||
std::cerr << "ERROR: Unable to to perform units conversion"
|
||||
<< " because the recorded data doesn't indicate it's"
|
||||
<< " units and no @from_units hint is provided."
|
||||
<< std::endl;
|
||||
std::cerr.flush();
|
||||
} else { // the user did give us a hint.
|
||||
try {
|
||||
from_unit = new Unit(FromUnitsHint);
|
||||
} catch (Unit::CONVERSION_ERROR) {
|
||||
delete from_unit;
|
||||
from_unit = NULL;
|
||||
from = ut_parse(u_system, FromUnitsHint, UT_ASCII) ;
|
||||
if ( ! from ) {
|
||||
std::cerr << "ERROR: Unable to to perform units conversion"
|
||||
<< " because the recorded data doesn't indicate it's"
|
||||
<< " units and although a @from_units hint is provided ("
|
||||
@ -48,11 +46,8 @@ DPC_UnitConvDataStream::DPC_UnitConvDataStream(DataStream* ds, const char *ToUni
|
||||
}
|
||||
} else { // the recorded data file does "know" the units in which the data was recorded,
|
||||
// so those will be the units that we convert from.
|
||||
try {
|
||||
from_unit = new Unit(recorded_units);
|
||||
} catch (Unit::CONVERSION_ERROR) {
|
||||
delete from_unit;
|
||||
from_unit = NULL;
|
||||
from = ut_parse(u_system, recorded_units, UT_ASCII) ;
|
||||
if ( !from ) {
|
||||
std::cerr << "ERROR: Unable to to perform units conversion because the"
|
||||
<< " units in the data recording file appear to be corrupt."
|
||||
<< std::endl;
|
||||
@ -61,39 +56,37 @@ DPC_UnitConvDataStream::DPC_UnitConvDataStream(DataStream* ds, const char *ToUni
|
||||
}
|
||||
|
||||
// If we know what units the data was recorded in ...
|
||||
if ( from_unit != NULL ) {
|
||||
|
||||
// Then we should be able to convert to the units requested by the user.
|
||||
try {
|
||||
cf = from_unit->Conversion_to(to_unit);
|
||||
|
||||
} catch (Unit::CONVERSION_ERROR) {
|
||||
cf = new UCFn(from_unit_string.c_str(),from_unit_string.c_str(), 1.0, 0.0);
|
||||
std::cerr << "ERROR: Unable to convert from \"" << from_unit << "\" to \""
|
||||
<< to_unit << "\" because they are incompatible." << std::endl;
|
||||
if ( from != NULL ) {
|
||||
cf = ut_get_converter(from,to) ;
|
||||
if ( cf == NULL ) {
|
||||
std::cerr << "ERROR: Unable to convert from \"" << FromUnitsHint << "\" to \""
|
||||
<< to_units << "\" because they are incompatible." << std::endl;
|
||||
std::cerr.flush();
|
||||
cf = cv_get_trivial() ;
|
||||
}
|
||||
} else {
|
||||
std::cerr << "ERROR: Unable to perform units conversion becuase the units"
|
||||
<< " that the data is recorded in is unknown." << std::endl;
|
||||
cf = new UCFn("--", "--", 1.0, 0.0);
|
||||
cf = cv_get_trivial() ;
|
||||
}
|
||||
} else { // The user has not specified a units conversion or the units were not valid.
|
||||
// If the recorded data file doesn't contain the units in which the data is recorded ...
|
||||
if ((recorded_units == NULL) || (strcmp(recorded_units,"") == 0)) {
|
||||
// If the user didn't give us a hint as to what the units are (using var@from_units) ...
|
||||
if ((FromUnitsHint == NULL) || (strcmp(FromUnitsHint,"") == 0)) {
|
||||
cf = new UCFn("--", "--", 1.0, 0.0);
|
||||
cf = cv_get_trivial() ;
|
||||
} else { // the user did give us a hint.
|
||||
cf = new UCFn(FromUnitsHint, FromUnitsHint, 1.0, 0.0);
|
||||
to_units = FromUnitsHint ;
|
||||
cf = cv_get_trivial() ;
|
||||
}
|
||||
} else { // the recorded data file does "know" the units in which the data was recorded,
|
||||
cf = new UCFn(recorded_units, recorded_units, 1.0, 0.0);
|
||||
to_units = recorded_units ;
|
||||
cf = cv_get_trivial() ;
|
||||
}
|
||||
}
|
||||
|
||||
if (to_unit) delete to_unit;
|
||||
if (from_unit) delete from_unit;
|
||||
if (to) ut_free(to) ;
|
||||
if (from) ut_free(from) ;
|
||||
|
||||
this->begin();
|
||||
}
|
||||
@ -101,7 +94,7 @@ DPC_UnitConvDataStream::DPC_UnitConvDataStream(DataStream* ds, const char *ToUni
|
||||
// DESTRUCTOR
|
||||
DPC_UnitConvDataStream::~DPC_UnitConvDataStream() {
|
||||
|
||||
delete cf;
|
||||
cv_free(cf);
|
||||
delete source_ds;
|
||||
}
|
||||
|
||||
@ -111,7 +104,7 @@ int DPC_UnitConvDataStream::get(double* timestamp, double* paramValue) {
|
||||
|
||||
if ( source_ds->get(&time, &value) ) {
|
||||
*timestamp = time;
|
||||
*paramValue = cf->eval(value);
|
||||
*paramValue = cv_convert_double(cf, value) ;;
|
||||
return (1);
|
||||
} else {
|
||||
return (0);
|
||||
@ -124,7 +117,7 @@ int DPC_UnitConvDataStream::peek(double* timestamp, double* paramValue) {
|
||||
|
||||
if (! source_ds->peek(&time, &value) ) {
|
||||
*timestamp = time;
|
||||
*paramValue = cf->eval(value);
|
||||
*paramValue = cv_convert_double(cf, value) ;;
|
||||
return (0);
|
||||
} else {
|
||||
return (-1);
|
||||
@ -138,8 +131,7 @@ std::string DPC_UnitConvDataStream::getFileName() {
|
||||
|
||||
// MEMBER FUNCTION
|
||||
std::string DPC_UnitConvDataStream::getUnit() {
|
||||
std::string unitstr(cf->t_name);
|
||||
return( unitstr);
|
||||
return to_units ;
|
||||
}
|
||||
|
||||
// MEMBER FUNCTION
|
||||
|
@ -3,6 +3,7 @@
|
||||
#define DPC_UNITCONVDATASTREAM_HH
|
||||
|
||||
#include <string>
|
||||
#include <udunits2.h>
|
||||
#include "trick/Unit.hh"
|
||||
#include "../../Log/DataStream.hh"
|
||||
|
||||
@ -89,7 +90,9 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
UCFn* cf;
|
||||
cv_converter * cf ;
|
||||
std::string to_units ;
|
||||
|
||||
DataStream *source_ds;
|
||||
|
||||
};
|
||||
|
@ -3,6 +3,7 @@
|
||||
#define DPC_COLUMN_INFO_HH
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include <udunits2.h>
|
||||
#include "trick/Unit.hh"
|
||||
|
||||
class DPC_column_info {
|
||||
@ -10,7 +11,7 @@ public:
|
||||
DPC_column_info( DPM_var * Var,
|
||||
const char * Units_s,
|
||||
int DS_ix,
|
||||
UCFn * Conversion_fn) {
|
||||
cv_converter * Conversion_fn) {
|
||||
var = Var;
|
||||
units = strdup(Units_s);
|
||||
ds_ix = DS_ix;
|
||||
@ -20,7 +21,7 @@ public:
|
||||
DPM_var *var;
|
||||
const char *units;
|
||||
int ds_ix ;
|
||||
UCFn *time_conversion;
|
||||
cv_converter *time_conversion;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -123,7 +123,7 @@ DPC_delta_curve::DPC_delta_curve( DPM_curve* Curve_spec,
|
||||
delta_y_var = new DPM_var( s.c_str());
|
||||
y_var = delta_y_var;
|
||||
|
||||
time_conversion = new UCFn( "s", "s", 1.0, 0.0);
|
||||
time_conversion = cv_get_trivial() ;
|
||||
x_actual_units = strdup("s");
|
||||
|
||||
// Make sure we know what units we're actually getting from DataStream #1.
|
||||
@ -179,7 +179,7 @@ DPC_delta_curve::~DPC_delta_curve() {
|
||||
if ( run_dir1 ) { free( run_dir1); }
|
||||
if ( run_dir2 ) { free( run_dir2); }
|
||||
if ( data_src_label ) { free( data_src_label); }
|
||||
if ( time_conversion ) { delete time_conversion; }
|
||||
if ( time_conversion ) { cv_free(time_conversion); }
|
||||
}
|
||||
|
||||
// MEMBER FUNCTION
|
||||
@ -217,7 +217,7 @@ int DPC_delta_curve::getXY(double *X_value, double *Y_value) {
|
||||
}
|
||||
}
|
||||
if (!eos) {
|
||||
*X_value = time_conversion->eval( t1);
|
||||
*X_value = cv_convert_double(time_conversion,t1);
|
||||
*Y_value = v1 - v2;
|
||||
return(1);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "DPM/DPM_run.hh"
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <udunits2.h>
|
||||
|
||||
/**
|
||||
* This class provides all of the data necessary to represent a curve of a plot.
|
||||
@ -68,6 +69,6 @@ private:
|
||||
char * run_dir1;
|
||||
char * run_dir2;
|
||||
char * data_src_label;
|
||||
UCFn* time_conversion;
|
||||
cv_converter* time_conversion;
|
||||
};
|
||||
#endif
|
||||
|
@ -1,8 +1,12 @@
|
||||
|
||||
#include <udunits2.h>
|
||||
|
||||
#include "DPC/DPC_std_curve.hh"
|
||||
#include "math.h"
|
||||
#include "trick/Unit.hh"
|
||||
|
||||
extern ut_system * u_system ;
|
||||
|
||||
// CONSTRUCTOR
|
||||
DPC_std_curve::DPC_std_curve(
|
||||
DPM_curve* Curve_spec,
|
||||
@ -49,62 +53,53 @@ DPC_std_curve::DPC_std_curve(
|
||||
// Because the X-axis is time, we handle it's unit conversion
|
||||
// here. Note that for the Y-axis or where the X-axis is not time,
|
||||
// unit conversion handled by the corresponding
|
||||
// DPC_UnitConvDataStream.
|
||||
|
||||
// DPC_UnitConvDataStream.
|
||||
|
||||
// If the user has specified a conversion to units other than seconds,
|
||||
// then generate a units conversion from seconds to those units.
|
||||
if ((x_var_units != NULL) && (strcmp( x_var_units,"s" ) != 0)) {
|
||||
|
||||
Unit *to_unit;
|
||||
Unit *from_unit;
|
||||
|
||||
// Create the "to_unit" object.
|
||||
try {
|
||||
to_unit = new Unit(x_var_units);
|
||||
} catch (Unit::CONVERSION_ERROR) {
|
||||
delete to_unit;
|
||||
to_unit = NULL;
|
||||
|
||||
ut_unit *to;
|
||||
ut_unit *from;
|
||||
|
||||
to = ut_parse(u_system, x_var_units, UT_ASCII) ;
|
||||
if ( ! to ) {
|
||||
std::cerr << "ERROR: For the curve <X,Y> = <" << x_var_name << ", "
|
||||
<< y_var_name << ">, " << "the units (\""<< x_var_units
|
||||
<< "\") specified for " << x_var_name << " are invalid."
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
// Create the "from_unit" object.
|
||||
// Create the "from" object.
|
||||
// Note that in the case of time, from_units must be seconds.
|
||||
from_unit = new Unit("s");
|
||||
from = ut_parse(u_system, "s", UT_ASCII) ;
|
||||
|
||||
// If both the to_unit and from_unit objects are created
|
||||
// If both the to and from objects are created
|
||||
// successfully then attempt to create the conversion.
|
||||
if (to_unit && from_unit) {
|
||||
|
||||
try {
|
||||
time_conversion = from_unit->Conversion_to(to_unit);
|
||||
x_actual_units = strdup( x_var_units);
|
||||
} catch (Unit::CONVERSION_ERROR) {
|
||||
|
||||
if (to && from) {
|
||||
x_actual_units = strdup( x_var_units);
|
||||
time_conversion = ut_get_converter(from,to) ;
|
||||
if ( time_conversion == NULL ) {
|
||||
std::cerr << "ERROR: For the curve <X,Y> = <" << x_var_name << ", "
|
||||
<< y_var_name << ">, " << "seconds (\"s\") cannot be converted to (\""<< x_var_units
|
||||
<< "\"), which have been specified for " << x_var_name << "."
|
||||
<< std::endl;
|
||||
|
||||
time_conversion = new UCFn( "s","s", 1.0, 0.0);
|
||||
time_conversion = cv_get_trivial() ;
|
||||
x_actual_units = strdup("s");
|
||||
}
|
||||
|
||||
ut_free(to) ;
|
||||
ut_free(from) ;
|
||||
} else {
|
||||
time_conversion = new UCFn( "s", "s", 1.0, 0.0);
|
||||
time_conversion = cv_get_trivial() ;
|
||||
x_actual_units = strdup("s");
|
||||
}
|
||||
|
||||
} else {
|
||||
time_conversion = new UCFn( "s", "s", 1.0, 0.0);
|
||||
time_conversion = cv_get_trivial() ;
|
||||
x_actual_units = strdup("s");
|
||||
}
|
||||
}
|
||||
|
||||
// Create the one DataStream [A(t)] that we need for this curve.
|
||||
|
||||
|
||||
ds[0] = ds_supplier->getDataStream( y_var_name,
|
||||
y_var_units,
|
||||
y_var_from_units,
|
||||
@ -216,7 +211,7 @@ DPC_std_curve::~DPC_std_curve() {
|
||||
data_src_label = NULL;
|
||||
}
|
||||
if ( time_conversion ) {
|
||||
delete time_conversion;
|
||||
cv_free(time_conversion);
|
||||
time_conversion = NULL;
|
||||
}
|
||||
}
|
||||
@ -260,7 +255,7 @@ int DPC_std_curve::getXY(double *X_value, double *Y_value) {
|
||||
} else {
|
||||
eos = !ds[0]->get( &t1, &v1);
|
||||
if (!eos) {
|
||||
*X_value = time_conversion->eval( t1);
|
||||
*X_value = cv_convert_double(time_conversion,t1);
|
||||
*Y_value = v1;
|
||||
return(1);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#ifndef DPC_STD_CURVE_HH
|
||||
#define DPC_STD_CURVE_HH
|
||||
|
||||
#include <udunits2.h>
|
||||
#include "DPM/DPM_run.hh"
|
||||
#include "DPM/DPM_curve.hh"
|
||||
#include "DPC/DPC_curve.hh"
|
||||
@ -64,6 +65,6 @@ private:
|
||||
char * x_actual_units;
|
||||
char * y_actual_units;
|
||||
char * data_src_label;
|
||||
UCFn* time_conversion;
|
||||
cv_converter * time_conversion;
|
||||
};
|
||||
#endif
|
||||
|
@ -1,8 +1,10 @@
|
||||
|
||||
#include <udunits2.h>
|
||||
#include "DPC/DPC_table.hh"
|
||||
#include "DPM/DPM_var.hh"
|
||||
#include "DPM/DPM_column.hh"
|
||||
|
||||
extern ut_system * u_system ;
|
||||
|
||||
static const char *default_time_units = "s";
|
||||
|
||||
@ -66,42 +68,42 @@ DPC_table::DPC_table( DPC_datastream_supplier *DS_Supplier,
|
||||
const char * column_var_units = column_var->AttributeValue("units");
|
||||
const char * column_var_from_units = column_var->AttributeValue("from_units");
|
||||
|
||||
UCFn *time_conversion = NULL;
|
||||
int dsix = -1;
|
||||
cv_converter *time_conversion = NULL;
|
||||
int dsix = -1;
|
||||
|
||||
if ( strcmp( column_var_name, run->getTimeName() ) == 0 ) {
|
||||
if ((column_var_units != NULL) && (strcmp( column_var_units, default_time_units) != 0)) {
|
||||
// Convert seconds to whatever the user requested.
|
||||
Unit *to_unit;
|
||||
Unit *from_unit;
|
||||
ut_unit *to;
|
||||
ut_unit *from;
|
||||
|
||||
try {
|
||||
to_unit = new Unit(column_var_units);
|
||||
} catch (Unit::CONVERSION_ERROR) {
|
||||
to_unit = NULL;
|
||||
to = ut_parse(u_system, column_var_units, UT_ASCII) ;
|
||||
if ( ! to ) {
|
||||
std::cerr << "ERROR: Unable to convert values to invalid units: \""
|
||||
<< column_var_units << "\"." << std::endl;
|
||||
}
|
||||
from_unit = new Unit(default_time_units);
|
||||
from = ut_parse(u_system, default_time_units, UT_ASCII) ;
|
||||
|
||||
if (to_unit && from_unit) {
|
||||
try {
|
||||
time_conversion = from_unit->Conversion_to(to_unit);
|
||||
actual_units = column_var_units;
|
||||
} catch (Unit::CONVERSION_ERROR) {
|
||||
std::cerr << "ERROR: Unable to convert from \"" << from_unit << "\" to \""
|
||||
<< to_unit << "\" because they are incompatible." << std::endl;
|
||||
time_conversion = new UCFn( default_time_units, default_time_units, 1.0, 0.0);
|
||||
if (to && from) {
|
||||
actual_units = column_var_units;
|
||||
time_conversion = ut_get_converter(from,to) ;
|
||||
if ( time_conversion == NULL ) {
|
||||
std::cerr << "ERROR: Unable to convert from \"" << default_time_units << "\" to \""
|
||||
<< column_var_units << "\" because they are incompatible." << std::endl;
|
||||
time_conversion = cv_get_trivial() ;
|
||||
actual_units = default_time_units;
|
||||
}
|
||||
ut_free(to) ;
|
||||
ut_free(from) ;
|
||||
} else {
|
||||
time_conversion = new UCFn( default_time_units, default_time_units, 1.0, 0.0);
|
||||
time_conversion = cv_get_trivial() ;
|
||||
actual_units = default_time_units;
|
||||
}
|
||||
} else {
|
||||
time_conversion = new UCFn( default_time_units, default_time_units, 1.0, 0.0);
|
||||
time_conversion = cv_get_trivial() ;
|
||||
actual_units = default_time_units;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
ds = DS_Supplier->getDataStream( column_var_name,
|
||||
@ -287,7 +289,7 @@ int DPC_table::getRow(double *time, double *row_values) {
|
||||
const char *column_var_name;
|
||||
column_var_name = column_info_list[col_ix]->var->getName();
|
||||
if ( strcmp( column_var_name, run->getTimeName()) == 0) {
|
||||
row_values[col_ix] = column_info_list[col_ix]->time_conversion->eval( *time);
|
||||
row_values[col_ix] = cv_convert_double(column_info_list[col_ix]->time_conversion, *time);
|
||||
} else {
|
||||
row_values[col_ix] = synchronized_values[ column_info_list[col_ix]->ds_ix ];
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ DPX_DIR = ..
|
||||
|
||||
INCLUDE_DIRS = -I${DPX_DIR} -I../.. -I${TRICK_HOME}/include -I/usr/include/libxml2
|
||||
|
||||
CFLAGS = -g -Wall
|
||||
CFLAGS = -g -Wall $(UDUNITS_INCLUDES)
|
||||
|
||||
OBJDIR = object_${TRICK_HOST_CPU}
|
||||
LIBDIR = ${DPX_DIR}/lib_${TRICK_HOST_CPU}
|
||||
@ -58,12 +58,3 @@ clean:
|
||||
spotless: clean
|
||||
${RM} ${LIBDIR}/${LIBNAME}
|
||||
|
||||
|
||||
# Dependencies
|
||||
|
||||
#######################################################################
|
||||
# To update dependencies:
|
||||
# - Save changes (if any)
|
||||
# - run "make depend"
|
||||
#######################################################################
|
||||
# DO NOT DELETE
|
||||
|
@ -1,11 +1,13 @@
|
||||
|
||||
#include <udunits2.h>
|
||||
#include <string.h>
|
||||
#include "DPM_axis.hh"
|
||||
#include "trick/Unit.hh"
|
||||
|
||||
extern ut_system * u_system ;
|
||||
|
||||
int DPM_axis::Initialize(xmlNode *base_node) {
|
||||
|
||||
xmlNode *current_node;
|
||||
Unit* validation_unit;
|
||||
|
||||
label = NULL;
|
||||
unitspec = NULL;
|
||||
@ -39,13 +41,12 @@ int DPM_axis::Initialize(xmlNode *base_node) {
|
||||
// 1. If units are supplied, they must be valid.
|
||||
|
||||
if (unitspec != NULL) {
|
||||
try {
|
||||
validation_unit = new Unit(unitspec);
|
||||
} catch (Unit::CONVERSION_ERROR) {
|
||||
ut_unit * validation_unit = ut_parse(u_system, unitspec, UT_ASCII) ;
|
||||
if( validation_unit == NULL ) {
|
||||
std::cerr << "ERROR: <axis> specifies invalid units: \"" << unitspec << "\"." << std::endl;
|
||||
return -1;
|
||||
}
|
||||
delete validation_unit;
|
||||
ut_free(validation_unit) ;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1,11 +1,13 @@
|
||||
|
||||
#include <udunits2.h>
|
||||
#include <string.h>
|
||||
#include "DPM_column.hh"
|
||||
#include "trick/Unit.hh"
|
||||
|
||||
extern ut_system * u_system ;
|
||||
|
||||
int DPM_column::Initialize(xmlNode *base_node) {
|
||||
|
||||
xmlNode *current_node;
|
||||
Unit* validation_unit;
|
||||
|
||||
label = NULL;
|
||||
unitspec = NULL;
|
||||
@ -43,13 +45,12 @@ int DPM_column::Initialize(xmlNode *base_node) {
|
||||
// 1. If units are supplied, they must be valid.
|
||||
|
||||
if (unitspec != NULL) {
|
||||
try {
|
||||
validation_unit = new Unit(unitspec);
|
||||
} catch (Unit::CONVERSION_ERROR) {
|
||||
ut_unit * validation_unit = ut_parse(u_system, unitspec, UT_ASCII) ;
|
||||
if( validation_unit == NULL ) {
|
||||
std::cerr << "ERROR: <column> specifies invalid units: \"" << unitspec << "\"." << std::endl;
|
||||
return -1;
|
||||
}
|
||||
delete validation_unit;
|
||||
ut_free(validation_unit) ;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -1,6 +1,9 @@
|
||||
|
||||
#include <udunits2.h>
|
||||
#include <string.h>
|
||||
#include "DPM_measurement.hh"
|
||||
#include "trick/Unit.hh"
|
||||
|
||||
extern ut_system * u_system ;
|
||||
|
||||
// MEMEBR FUNCTION
|
||||
int DPM_measurement::Initialize( xmlNode *base_node) {
|
||||
@ -52,15 +55,12 @@ int DPM_measurement::Initialize( xmlNode *base_node) {
|
||||
std::cerr << "ERROR: <measurement> specification is missing a <units> specification." << std::endl;
|
||||
return -1;
|
||||
} else {
|
||||
// Validate the units.
|
||||
Unit* validation_unit;
|
||||
try {
|
||||
validation_unit = new Unit(unitspec);
|
||||
} catch (Unit::CONVERSION_ERROR) {
|
||||
ut_unit * validation_unit = ut_parse(u_system, unitspec, UT_ASCII) ;
|
||||
if( validation_unit == NULL ) {
|
||||
std::cerr << "ERROR: <measurement> specification contains an invalid <units> specification: \"" << unitspec << "\"." << std::endl;
|
||||
return -1;
|
||||
}
|
||||
delete validation_unit;
|
||||
ut_free(validation_unit) ;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ DPX_DIR = ..
|
||||
|
||||
INCLUDE_DIRS = -I${DPX_DIR} -I../.. -I${TRICK_HOME}/include -I/usr/include/libxml2
|
||||
|
||||
CFLAGS = -g -Wall
|
||||
CFLAGS = -g -Wall $(UDUNITS_INCLUDES)
|
||||
|
||||
OBJDIR = object_${TRICK_HOST_CPU}
|
||||
LIBDIR = ${DPX_DIR}/lib_${TRICK_HOST_CPU}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <strings.h>
|
||||
#include <math.h>
|
||||
#include "Csv.hh"
|
||||
#include "trick/map_trick_units_to_udunits.hh"
|
||||
|
||||
Csv::Csv(char * file_name , char * param_name ) {
|
||||
|
||||
@ -18,7 +19,7 @@ Csv::Csv(char * file_name , char * param_name ) {
|
||||
printf("ERROR: Couldn't open \"%s\"\n" , file_name ) ;
|
||||
exit(-1) ;
|
||||
}
|
||||
|
||||
|
||||
line_ = new char[20480] ;
|
||||
header = new char[20480] ;
|
||||
fgets( header , 20480 , fp_ );
|
||||
@ -32,17 +33,17 @@ Csv::Csv(char * file_name , char * param_name ) {
|
||||
if ( strncmp(next_field , param_name, len) ) {
|
||||
field_num_++ ;
|
||||
while ((next_field = strtok( NULL , "," ))) {
|
||||
char *space_loc = strchr(next_field, ' ');
|
||||
int actual_name_len = space_loc - next_field;
|
||||
// need to make sure if the length of the parameter and the length
|
||||
// of the parameter found in the next_field are actually the same,
|
||||
// since strncmp(a.b.c_more, a.b.c, 5) results a.b.c_more equals a.b.c.
|
||||
char *space_loc = strchr(next_field, ' ');
|
||||
int actual_name_len = space_loc - next_field;
|
||||
// need to make sure if the length of the parameter and the length
|
||||
// of the parameter found in the next_field are actually the same,
|
||||
// since strncmp(a.b.c_more, a.b.c, 5) results a.b.c_more equals a.b.c.
|
||||
if ( strncmp(next_field , param_name, len) || actual_name_len != len) {
|
||||
field_num_++ ;
|
||||
}
|
||||
else {
|
||||
/* found the parameter, get the units if there are any */
|
||||
char * start_unit , * end_unit ;
|
||||
/* found the parameter, get the units if there are any */
|
||||
char * start_unit , * end_unit ;
|
||||
if ((start_unit = index( next_field , '{' ))) {
|
||||
end_unit = index( next_field , '}' ) ;
|
||||
end_unit[0] = '\0' ;
|
||||
@ -50,7 +51,7 @@ Csv::Csv(char * file_name , char * param_name ) {
|
||||
unitTimeStr_ = start_unit + 1 ;
|
||||
}
|
||||
else {
|
||||
unitStr_ = start_unit + 1 ;
|
||||
unitStr_ = map_trick_units_to_udunits(start_unit + 1) ;
|
||||
}
|
||||
}
|
||||
break ;
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <math.h>
|
||||
|
||||
DataStream::DataStream() {
|
||||
unitStr_ = "--" ;
|
||||
unitStr_ = "1" ;
|
||||
unitTimeStr_ = "s" ;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "ExternalProgram.hh"
|
||||
|
||||
@ -10,7 +12,7 @@ ExternalProgram::ExternalProgram( const char* sharedLibName,
|
||||
int ii ;
|
||||
|
||||
char next_record_str[] = "extGetNextRecord" ;
|
||||
unitStr_ = "--" ;
|
||||
unitStr_ = "1" ;
|
||||
unitTimeStr_ = "s" ;
|
||||
|
||||
// Open up external plugin program
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "trick_byte_order.h"
|
||||
#include "trick_byteswap.h"
|
||||
#include "trick/units_conv.h"
|
||||
#include "trick/map_trick_units_to_udunits.hh"
|
||||
|
||||
TrickBinary::TrickBinary(char * file_name , char * param_name ) {
|
||||
|
||||
@ -153,7 +154,7 @@ TrickBinary::TrickBinary(char * file_name , char * param_name ) {
|
||||
}
|
||||
|
||||
if ( ! strcmp( name_ptr , param_name )) {
|
||||
unitStr_ = units_ptr ;
|
||||
unitStr_ = map_trick_units_to_udunits(units_ptr) ;
|
||||
record_offset_ = record_size_ ;
|
||||
type_ = type ;
|
||||
size_ = size ;
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <strings.h>
|
||||
#include <math.h>
|
||||
#include "TrickHDF5.hh"
|
||||
#include "trick/map_trick_units_to_udunits.hh"
|
||||
|
||||
TrickHDF5::TrickHDF5(char *file_name , char *parameter_name , char *time_name) {
|
||||
|
||||
@ -53,7 +54,7 @@ TrickHDF5::TrickHDF5(char *file_name , char *parameter_name , char *time_name) {
|
||||
H5PTget_next(parameter_units, 1, units_buf);
|
||||
// the specified parameter_name is found, set the units
|
||||
if (strcmp(parameter_name, name_buf) == 0) {
|
||||
unitStr_ = units_buf;
|
||||
unitStr_ = map_trick_units_to_udunits(units_buf) ;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <udunits2.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "trick_byteswap.h"
|
||||
@ -12,6 +13,8 @@
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
extern ut_system * u_system ;
|
||||
|
||||
/**
|
||||
* LogData constructor
|
||||
*/
|
||||
@ -902,7 +905,7 @@ int LogData::getParamIdx(const char *param)
|
||||
}
|
||||
|
||||
/** Get the unit associated with the parameter as specified in Log header */
|
||||
Unit *LogData::getUnit(char *param)
|
||||
std::string LogData::getUnit(char *param)
|
||||
{
|
||||
|
||||
int ii;
|
||||
@ -982,32 +985,49 @@ int LogData::setMin(int paramIdx, double min)
|
||||
* file to unit given as argument. If the unit passed is
|
||||
* NULL, the scale factor will be set to 1.0.
|
||||
*/
|
||||
int LogData::setUnit(int paramIdx, Unit * u)
|
||||
int LogData::setUnit(int paramIdx, std::string to_units)
|
||||
{
|
||||
|
||||
UCFn *cf;
|
||||
|
||||
if (paramIdx > nVals_ || paramIdx < 0) {
|
||||
fprintf(stderr, "ERROR: setUnit received paramIdx %d "
|
||||
"out of bounds.\n", paramIdx);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// If no unit passed, set scale factor to 1.0 (default)
|
||||
if (u == 0) {
|
||||
if (to_units.empty()) {
|
||||
unitVal_[paramIdx] = 1.0;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
try {
|
||||
cf = vars[varVal_[paramIdx]]->getUnit()->Conversion_to(u);
|
||||
unitVal_[paramIdx] = cf->C[1];
|
||||
biasVal_[paramIdx] = cf->C[0];
|
||||
delete cf;
|
||||
} catch (Unit::CONVERSION_ERROR) {
|
||||
fprintf(stderr, "ERROR: Bad unit conversion given to setUnit.\n");
|
||||
exit(-1);
|
||||
std::string from_units = vars[varVal_[paramIdx]]->getUnit() ;
|
||||
ut_unit * from = ut_parse(u_system, from_units.c_str(), UT_ASCII) ;
|
||||
if ( !from ) {
|
||||
unitVal_[paramIdx] = 1.0;
|
||||
std::cout << "could not covert from units " << from_units << std::endl ;
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
ut_unit * to = ut_parse(u_system, to_units.c_str(), UT_ASCII) ;
|
||||
if ( !to ) {
|
||||
unitVal_[paramIdx] = 1.0;
|
||||
std::cout << "could not covert to units " << to_units << std::endl ;
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
cv_converter * converter = ut_get_converter(from,to) ;
|
||||
if ( converter ) {
|
||||
biasVal_[paramIdx] = cv_convert_double(converter, 0.0 ) ;
|
||||
unitVal_[paramIdx] = cv_convert_double(converter, 1.0 ) - biasVal_[paramIdx] ;
|
||||
cv_free(converter) ;
|
||||
} else {
|
||||
std::cout << "Units conversion error from " << from_units << " to " << to_units << std::endl ;
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
ut_free(from) ;
|
||||
ut_free(to) ;
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
@ -1238,7 +1258,7 @@ int LogGroup::setMin(int logIdx, int paramIdx, double min)
|
||||
/** Set unit for parameter
|
||||
* @see LogData::setUnit()
|
||||
*/
|
||||
int LogGroup::setUnit(int logIdx, int paramIdx, Unit * u)
|
||||
int LogGroup::setUnit(int logIdx, int paramIdx, std::string u)
|
||||
{
|
||||
|
||||
log[logIdx]->setUnit(paramIdx, u);
|
||||
@ -1249,7 +1269,7 @@ int LogGroup::setUnit(int logIdx, int paramIdx, Unit * u)
|
||||
/** Set unit for parameter
|
||||
* @see LogData::setUnit()
|
||||
*/
|
||||
int LogGroup::setUnit(const char *paramName, Unit * u)
|
||||
int LogGroup::setUnit(const char *paramName, std::string u)
|
||||
{
|
||||
|
||||
int xIdx, xLogIdx;
|
||||
|
@ -55,7 +55,7 @@ class LogData {
|
||||
int getParamIdx(const char *param);
|
||||
Var::enumType getType(int vIdx);
|
||||
int getSize(int vIdx); // TODO: getValByteSize
|
||||
Unit *getUnit(char *param); // Get unit for associated param
|
||||
std::string getUnit(char *param); // Get unit for associated param
|
||||
char *getBinaryFileName();
|
||||
|
||||
int setBinaryFileName(char *fileName);
|
||||
@ -63,7 +63,7 @@ class LogData {
|
||||
int setBias(int paramIdx, double bias);
|
||||
int setMax(int paramIdx, double max);
|
||||
int setMin(int paramIdx, double min);
|
||||
int setUnit(int paramIdx, Unit * u);
|
||||
int setUnit(int paramIdx, std::string u);
|
||||
|
||||
// Get value of a parameter at a given time stamp
|
||||
int getValueAtTime( int timeIdx, double time,
|
||||
@ -209,8 +209,8 @@ class LogGroup {
|
||||
|
||||
int setScaleFactor(int logIdx, int paramIdx, double factor);
|
||||
int setBias(int logIdx, int paramIdx, double bias);
|
||||
int setUnit(int logIdx, int paramIdx, Unit * u);
|
||||
int setUnit(const char *paramName, Unit * u);
|
||||
int setUnit(int logIdx, int paramIdx, std::string u);
|
||||
int setUnit(const char *paramName, std::string u);
|
||||
int setMax(int logIdx, int paramIdx, double max);
|
||||
int setMin(int logIdx, int paramIdx, double min);
|
||||
|
||||
@ -329,7 +329,7 @@ class LogMultiGroup {
|
||||
// Set factors for scaling, biasing...
|
||||
int setScaleFactor(const char* paramName, double factor);
|
||||
int setBias(const char* paramName, double bias);
|
||||
int setUnit(const char* paramName, Unit * u);
|
||||
int setUnit(const char* paramName, std::string u);
|
||||
int setMax(const char* paramName, double max);
|
||||
int setMin(const char* paramName, double min);
|
||||
|
||||
|
@ -15,7 +15,7 @@ OBJ_DIR = object_${TRICK_HOST_CPU}
|
||||
LIBDIR = ../lib_${TRICK_HOST_CPU}
|
||||
LIBNAME = liblog.a
|
||||
INCLUDE_DIRS = -I.. -I${TRICK_HOME}/include
|
||||
DP_CFLAGS = -g ${INCLUDE_DIRS} -fPIC
|
||||
DP_CFLAGS = -g ${INCLUDE_DIRS} -fPIC $(UDUNITS_INCLUDES)
|
||||
CPP_OBJECTS = $(OBJ_DIR)/log.o \
|
||||
$(OBJ_DIR)/multiLog.o \
|
||||
$(OBJ_DIR)/trick_byteswap.o \
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "log.h"
|
||||
|
||||
// For DBL_MIN, DBL_MAX defs
|
||||
|
@ -14,6 +14,9 @@
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#include "trick/units_conv.h"
|
||||
#include "trick/map_trick_units_to_udunits.hh"
|
||||
|
||||
/* A private function for parsing log header files.
|
||||
* This is responsible for initialize the Log classes as well
|
||||
*/
|
||||
@ -142,7 +145,7 @@ int LogGroup::parseLogHeaders()
|
||||
}
|
||||
|
||||
// Initialize Unit class
|
||||
currVar->setUnit(str3);
|
||||
currVar->setUnit(map_trick_units_to_udunits(str3));
|
||||
|
||||
// Set Var Name
|
||||
currVar->setVarName(str4) ;
|
||||
|
@ -39,8 +39,6 @@ Var::Var() {
|
||||
minRange_ = -DBL_MAX ;
|
||||
maxRange_ = DBL_MAX ;
|
||||
varType_ = NONE ;
|
||||
unit_ = new Unit() ;
|
||||
timeUnit_ = new Unit() ;
|
||||
byteSize_ = 0 ;
|
||||
isProgramOutput = 0 ;
|
||||
|
||||
@ -48,9 +46,6 @@ Var::Var() {
|
||||
|
||||
/** Var Destructor */
|
||||
Var::~Var() {
|
||||
|
||||
delete unit_ ;
|
||||
delete timeUnit_ ;
|
||||
}
|
||||
|
||||
/** Copy constructor */
|
||||
@ -121,23 +116,22 @@ double Var::getMaxRange() {
|
||||
}
|
||||
|
||||
/** Get variable's unit
|
||||
* @see Unit
|
||||
*/
|
||||
Unit* Var::getUnit() {
|
||||
std::string Var::getUnit() {
|
||||
return ( unit_ ) ;
|
||||
}
|
||||
|
||||
Unit* Var::setUnit(const char * unit_name) {
|
||||
unit_->setUnitName(unit_name) ;
|
||||
std::string Var::setUnit(std::string unit_name) {
|
||||
unit_ = unit_name ;
|
||||
return ( unit_ ) ;
|
||||
}
|
||||
|
||||
Unit* Var::getTimeUnit() {
|
||||
std::string Var::getTimeUnit() {
|
||||
return ( timeUnit_ ) ;
|
||||
}
|
||||
|
||||
Unit* Var::setTimeUnit(const char * unit_name) {
|
||||
timeUnit_->setUnitName(unit_name) ;
|
||||
std::string Var::setTimeUnit(std::string unit_name) {
|
||||
timeUnit_ = unit_name ;
|
||||
return ( timeUnit_ ) ;
|
||||
}
|
||||
|
||||
@ -836,8 +830,8 @@ const Var& Var::operator= ( Var& right )
|
||||
this->setScaleFactor( right.getScaleFactor() ) ;
|
||||
this->setBias( right.getBias() ) ;
|
||||
this->setLabel( right.getLabel() ) ;
|
||||
this->setUnit( right.getUnit()->getUnitName() ) ;
|
||||
this->setTimeUnit( right.getTimeUnit()->getUnitName() ) ;
|
||||
this->setUnit( right.getUnit()) ;
|
||||
this->setTimeUnit( right.getTimeUnit()) ;
|
||||
this->isProgramOutput = right.isProgramOutput ;
|
||||
|
||||
return *this ; // Allows concatenated assignments
|
||||
|
@ -14,8 +14,6 @@
|
||||
#include <string>
|
||||
using namespace std ;
|
||||
|
||||
#include "trick/Unit.hh"
|
||||
|
||||
/*
|
||||
* Variable Class
|
||||
*/
|
||||
@ -67,11 +65,11 @@ class Var {
|
||||
double getBias();
|
||||
void setBias(double);
|
||||
|
||||
Unit* getUnit();
|
||||
Unit* setUnit(const char *);
|
||||
std::string getUnit();
|
||||
std::string setUnit(std::string);
|
||||
|
||||
Unit* getTimeUnit();
|
||||
Unit* setTimeUnit(const char *);
|
||||
std::string getTimeUnit();
|
||||
std::string setTimeUnit(std::string);
|
||||
|
||||
// Compare var names (not counting dims)
|
||||
int compareNames( const char* name );
|
||||
@ -100,8 +98,8 @@ class Var {
|
||||
double bias_; // Value Offset (addition)
|
||||
|
||||
/** @see Unit() */
|
||||
Unit* unit_ ;
|
||||
Unit* timeUnit_ ;
|
||||
std::string unit_ ;
|
||||
std::string timeUnit_ ;
|
||||
|
||||
|
||||
|
||||
|
19
trick_source/data_products/units/init_units_system.cpp
Normal file
19
trick_source/data_products/units/init_units_system.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <udunits2.h>
|
||||
|
||||
ut_system * init_unit_system() {
|
||||
ut_system * u_system ;
|
||||
/* Initialize the udunits-2 library */
|
||||
ut_set_error_message_handler(ut_ignore) ;
|
||||
if( (u_system = ut_read_xml( NULL )) == NULL ) {
|
||||
std::cerr << "Error initializing udunits-2 unit system" << std::endl ;
|
||||
return NULL ;
|
||||
}
|
||||
ut_set_error_message_handler(ut_write_to_stderr) ;
|
||||
return u_system ;
|
||||
}
|
||||
|
||||
// Global units system pointer
|
||||
ut_system * u_system = init_unit_system() ;
|
||||
|
@ -16,11 +16,13 @@ OBJ_DIR = object_${TRICK_HOST_CPU}
|
||||
LIBDIR = ../lib_${TRICK_HOST_CPU}
|
||||
LIBNAME = libtrick_units.a
|
||||
INCLUDE_DIRS = -I${TRICK_HOME}/include
|
||||
DP_CFLAGS = -g ${INCLUDE_DIRS} -fPIC
|
||||
DP_CFLAGS = -g ${INCLUDE_DIRS} -fPIC $(UDUNITS_INCLUDES)
|
||||
|
||||
CPP_OBJECTS = $(OBJ_DIR)/UCFn.o \
|
||||
$(OBJ_DIR)/Unit.o
|
||||
C_OBJECTS = $(OBJ_DIR)/units_conv.o
|
||||
CPP_OBJECTS = \
|
||||
$(OBJ_DIR)/init_units_system.o \
|
||||
$(OBJ_DIR)/map_trick_units_to_udunits.o
|
||||
|
||||
C_OBJECTS = $(OBJ_DIR)/units_conv.o
|
||||
|
||||
ifeq ($(TRICK_DP_FORCE_32BIT), 1)
|
||||
DP_CFLAGS += -m32
|
||||
@ -40,11 +42,8 @@ $(LIBDIR):
|
||||
|
||||
OBJECTS: $(CPP_OBJECTS)
|
||||
|
||||
$(LIBDIR)/$(LIBNAME): $(CPP_OBJECTS) $(C_OBJECTS) $(LIB_DIR)
|
||||
ar crs $(LIBDIR)/$(LIBNAME) $?
|
||||
|
||||
depend:
|
||||
@ echo "No depend rule for this directory"
|
||||
$(LIBDIR)/$(LIBNAME): $(CPP_OBJECTS) $(C_OBJECTS) $(LIBDIR)
|
||||
ar crs $(LIBDIR)/$(LIBNAME) $(CPP_OBJECTS) $(C_OBJECTS)
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ_DIR)
|
||||
@ -52,18 +51,9 @@ clean:
|
||||
|
||||
real_clean: clean
|
||||
|
||||
$(CPP_OBJECTS) : $(OBJ_DIR)/%.o : src/%.cpp | $(OBJ_DIR)
|
||||
$(CPP_OBJECTS) : $(OBJ_DIR)/%.o : %.cpp | $(OBJ_DIR)
|
||||
$(CC) $(DP_CFLAGS) -c $< -o $@
|
||||
|
||||
$(C_OBJECTS) : $(OBJ_DIR)/%.o : src/%.c | $(OBJ_DIR)
|
||||
$(C_OBJECTS) : $(OBJ_DIR)/%.o : %.c | $(OBJ_DIR)
|
||||
$(CC) $(DP_CFLAGS) -c $< -o $@
|
||||
|
||||
|
||||
#----------------------------
|
||||
# Dependencies
|
||||
|
||||
#######################################################################
|
||||
# To update dependencies:
|
||||
# - Save changes (if any)
|
||||
# - run "make depend"
|
||||
#######################################################################
|
||||
|
1
trick_source/data_products/units/map_trick_units_to_udunits.cpp
Symbolic link
1
trick_source/data_products/units/map_trick_units_to_udunits.cpp
Symbolic link
@ -0,0 +1 @@
|
||||
../../sim_services/UdUnits/map_trick_units_to_udunits.cpp
|
@ -1 +0,0 @@
|
||||
../../trick_utils/units/src
|
1
trick_source/data_products/units/units_conv.c
Symbolic link
1
trick_source/data_products/units/units_conv.c
Symbolic link
@ -0,0 +1 @@
|
||||
../../trick_utils/units/src/units_conv.c
|
@ -8,8 +8,7 @@
|
||||
#include <frameobject.h>
|
||||
#include <udunits2.h>
|
||||
#include "trick/swig/swig_double.hh"
|
||||
|
||||
std::string map_trick_units_to_udunits( std::string orig_units ) ;
|
||||
#include "trick/map_trick_units_to_udunits.hh"
|
||||
|
||||
%}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user