19 #include "epicsStdlib.h"
20 #include "epicsString.h"
22 #include "epicsMutex.h"
24 #include "dbStaticLib.h"
25 #include "dbFldTypes.h"
27 #include "dbAccessDefs.h"
28 #include <epicsTypes.h>
29 #include <epicsTime.h>
30 #include <epicsThread.h>
31 #include <epicsString.h>
32 #include <epicsTimer.h>
33 #include <epicsMutex.h>
42 #include <boost/scoped_array.hpp>
45 #include <registryFunction.h>
47 #include <epicsExport.h>
54 static void iocdcalc(
const char* resultvar,
const char* expression,
int options,
int precision)
56 if (resultvar == NULL || expression == NULL)
58 errlogPrintf(
"iocdcalc: ERROR: NULL args");
61 bool verbose = (options & 0x1);
62 char* expr_expand = macEnvExpand(expression);
63 if (expr_expand == NULL)
65 errlogPrintf(
"iocdcalc: ERROR: NULL expanded expression arg");
70 printf(
"iocdcalc: expanded expression=\"%s\"\n", expr_expand);
73 static const int CALC_NARGS = 12;
74 std::vector<double> parg(CALC_NARGS);
75 for(
int i=0; i<CALC_NARGS; ++i)
81 boost::scoped_array<char> ppostfix(
new char[INFIX_TO_POSTFIX_SIZE(strlen(expr_expand)) + 100]);
82 if ( postfix(expr_expand, ppostfix.get(), &calc_error) != 0 )
84 errlogPrintf(
"iocdcalc: ERROR: postfix: %s\n", calcErrorStr(calc_error));
87 if ( calcPerform(&(parg[0]), &result, ppostfix.get()) != 0 )
89 errlogPrintf(
"iocdcalc: ERROR: calcPerform: %s\n",
"");
93 double dsmall = 1.0E-20;
94 std::ostringstream format_str;
99 format_str <<
"." << precision;
102 if ( sprintf(result_str, format_str.str().c_str(), result) < 0 )
104 errlogPrintf(
"iocdcalc: ERROR: sprintf: %s\n", format_str.str().c_str());
108 epicsEnvSet(resultvar, result_str);
127 iocdcalc(args[0].sval, args[1].sval, args[2].ival, args[3].ival);
static void iocdcalc(const char *resultvar, const char *expression, int options, int precision)
static void iocdcalcRegister(void)
static const iocshFuncDef dcalcInitFuncDef
static const iocshArg *const dcalcInitArgs[]
static const iocshArg dcalcInitArg3
static const iocshArg dcalcInitArg2
static const iocshArg dcalcInitArg0
static void dcalcInitCallFunc(const iocshArgBuf *args)
epicsExportRegistrar(dbLoadRecordsFuncsRegister)
static const iocshArg dcalcInitArg1