trick/trick_source/sim_services/MonteCarlo/MonteVarCalculated.cpp
Alex Lin 19025d77ad Standardize directory names
Reorganized.  Created a new top level include directory that will hold all of Trick's header files. Moved all of the Trick headers to this directory.  Created a libexec directory that holds all of the executables that users don't need to execute directly.  Changed all of the executables remaining in bin to start with "trick-".  In the sim_services directories changed all source files to find the Trick headers in their new location.  Since all of the include files are gone in sim_services, removed the src directories as well, moving all of the source files up a level.  Moved the makefiles, docs, man, and other architecture independent files into a top level share directory.  Renamed lib_${TRICK_HOST_CPU} to lib64 or lib depending on the platform we're currently on.

refs #63
2015-06-09 08:44:42 -05:00

69 lines
2.5 KiB
C++

#include <iostream>
#include "trick/MonteVarCalculated.hh"
#include "trick/memorymanager_c_intf.h"
#include "trick/message_proto.h"
#include "trick/message_type.h"
Trick::MonteVarCalculated::MonteVarCalculated(std::string in_name, std::string in_unit) {
this->name = in_name;
this->unit = in_unit;
ref2 = ref_attributes((char *)name.c_str());
if (ref2 == NULL) {
message_publish(MSG_ERROR, "Monte : MonteVarCalculated could not find parameter %s.\n", name.c_str()) ;
}
}
std::string Trick::MonteVarCalculated::get_next_value() {
char buffer[128];
if (ref2 != NULL) {
switch (ref2->attr->type) {
case TRICK_CHARACTER:
case TRICK_UNSIGNED_CHARACTER:
sprintf(buffer, "%d", *(char *)ref2->address);
value = buffer;
break;
case TRICK_SHORT:
case TRICK_UNSIGNED_SHORT:
sprintf(buffer, "%d", *(short *)ref2->address);
value = buffer;
break;
case TRICK_INTEGER:
case TRICK_UNSIGNED_INTEGER:
case TRICK_LONG:
case TRICK_UNSIGNED_LONG:
sprintf(buffer, "%ld", *(long *)ref2->address);
value = buffer;
break;
case TRICK_LONG_LONG:
case TRICK_UNSIGNED_LONG_LONG:
sprintf(buffer, "%lld", *(long long *)ref2->address);
value = buffer;
break;
case TRICK_FLOAT:
sprintf(buffer, "%.10g", *(float *)ref2->address);
value = buffer;
sprintf(buffer, "trick.unhex_float(0x%lx)", *(long *)ref2->address);
break;
case TRICK_DOUBLE:
sprintf(buffer, "%.10g", *(double *)ref2->address);
value = buffer;
sprintf(buffer, "struct.unpack(\"!d\", binascii.unhexlify(\"%016llx\"))[0]",
*(long long *)ref2->address);
break;
default:
sprintf(buffer, "#Unsupported value type %d", ref2->attr->type) ;
break ;
}
if (unit.empty()) {
return name + std::string(" = ") + std::string(buffer) + std::string(" # ") + std::string(value);
} else {
return name + std::string(" = trick.attach_units(\"") + unit + std::string("\", ") + std::string(buffer) +
std::string(") # ") + std::string(value);
}
}
return NULL;
}