adopted that it does compile with Microsoft Visual Studio 2008 Express Edition (see spirit_fcn_test.mak which is an input file for nmake.exe)

This commit is contained in:
suter_a 2010-08-16 07:31:10 +00:00
parent 5fba77fe72
commit 3be37b2599
7 changed files with 101 additions and 60 deletions

View File

@ -36,6 +36,10 @@ using namespace std;
#include <boost/algorithm/string/trim.hpp> // for stripping leading whitespace in std::string
#include <boost/math/special_functions/acosh.hpp>
#include <boost/math/special_functions/asinh.hpp>
#include <boost/math/special_functions/atanh.hpp>
#include "PFunction.h"
//--------------------------------------------------------------------------
@ -164,7 +168,7 @@ bool PFunction::CheckParameterAndMapInTree(iter_t const& i)
assert(i->children.size() == 0);
string str(i->value.begin(), i->value.end());
boost::algorithm::trim(str);
cout << endl << "parameterID: value = '" << str << "'" << endl;
cout << endl << "parameterID: value = '" << str << "'" << endl;
bool minus_sign_present = false;
if (str[0] == '-')
@ -283,7 +287,7 @@ void PFunction::FillFuncEvalTree(iter_t const& i, PFuncTreeNode &node)
status = sscanf(str.c_str(), "%lf", &dvalue); // convert string to double
node.fID = PFunctionGrammar::realID; // keep the ID
node.fDvalue = dvalue; // keep the value
// cout << endl << ">> realID: value = " << dvalue;
cout << endl << ">> realID: value = " << dvalue;
} else if (i->value.id() == PFunctionGrammar::constPiID) { // handle constant pi
node.fID = PFunctionGrammar::constPiID; // keep the ID
node.fDvalue = 3.14159265358979323846; // keep the value
@ -300,7 +304,7 @@ void PFunction::FillFuncEvalTree(iter_t const& i, PFuncTreeNode &node)
}
node.fID = PFunctionGrammar::parameterID; // keep the ID
node.fIvalue = ivalue; // keep the value
cout << endl << ">> parameterID: value = " << ivalue;
cout << endl << ">> parameterID: value = " << ivalue;
} else if (i->value.id() == PFunctionGrammar::mapID) { // handle map number
str = string(i->value.begin(), i->value.end()); // get string
status = sscanf(str.c_str(), "MAP%d", &ivalue); // convert string to map number
@ -463,13 +467,13 @@ double PFunction::EvalNode(PFuncTreeNode &node)
} else if (node.fFunctionTag == FUN_ATAN) {
return atan(EvalNode(node.children[0]));
} else if (node.fFunctionTag == FUN_ACOSH) {
return acosh(EvalNode(node.children[0]));
return boost::math::acosh(EvalNode(node.children[0]));
} else if (node.fFunctionTag == FUN_ASINH) {
return asinh(EvalNode(node.children[0]));
return boost::math::asinh(EvalNode(node.children[0]));
} else if (node.fFunctionTag == FUN_ATANH) {
return atanh(EvalNode(node.children[0]));
return boost::math::atanh(EvalNode(node.children[0]));
} else if (node.fFunctionTag == FUN_LOG) {
return log(EvalNode(node.children[0]))/log(10);
return log(EvalNode(node.children[0]))/log(10.0);
} else if (node.fFunctionTag == FUN_LN) {
return log(EvalNode(node.children[0]));
} else if (node.fFunctionTag == FUN_EXP) {

View File

@ -32,9 +32,10 @@
#include <string>
#include <cassert>
#include <qfile.h>
#include <qtextstream.h>
#include <qstring.h>
#include <fstream>
using namespace std;
#include <boost/algorithm/string.hpp>
#include "PFunctionHandler.h"
@ -46,13 +47,12 @@
*
* \param fln
*/
PFunctionHandler::PFunctionHandler(char *fln, bool debug) : fDebug(debug)
PFunctionHandler::PFunctionHandler(char *fln, bool debug) : fDebug(debug), fFileName(fln)
{
fValid = true;
fFileName = QString(fln);
cout << endl << "in PFunctionHandler(char *fln)";
cout << endl << "fFileName = " << fFileName.latin1();
cout << endl << "fFileName = " << fFileName;
fValid = ReadFile();
if (fValid)
@ -67,12 +67,12 @@ PFunctionHandler::PFunctionHandler(char *fln, bool debug) : fDebug(debug)
*
* \param lines
*/
PFunctionHandler::PFunctionHandler(vector<QString> lines)
PFunctionHandler::PFunctionHandler(vector<string> lines)
{
fValid = true;
fFileName = "";
cout << endl << "in PFunctionHandler(vector<QString> lines)";
cout << endl << "in PFunctionHandler(vector<string> lines)";
if (lines.size() == 0) {
fValid = false;
@ -86,26 +86,31 @@ PFunctionHandler::PFunctionHandler(vector<QString> lines)
double dval[10];
bool inFcnBlock = false;
for (unsigned int i=0; i<lines.size(); i++) {
if (lines[i].startsWith("#")) // comment hence ignore
if (lines[i].find("#") == 0) // comment hence ignore
continue;
lines[i] = lines[i].upper();
if (lines[i].startsWith("PAR")) {
boost::to_upper(lines[i]);
if (lines[i].find("PAR") == 0) {
cout << endl << "this is a parameter line ...";
status = sscanf(lines[i].latin1(), "PAR %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
status = sscanf(lines[i].c_str(), "PAR %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
&dval[0], &dval[1], &dval[2], &dval[3], &dval[4],
&dval[5], &dval[6], &dval[7], &dval[8], &dval[9]);
cout << endl << "status=" << status;
if (status < 0) {
done = true;
fValid = false;
cout << endl << "invalid PAR line, sorry ...";
} else { // fill map
} else { // fill par
cout << endl << "PAR line, status = " << status;
for (int i=0; i<status; i++)
fParam.push_back(dval[i]);
cout << endl << "fParam.size()=" << fParam.size() << endl;
for (unsigned int i=0; i<fParam.size(); i++)
cout << endl << "Par" << i+1 << " = " << fParam[i];
cout << endl;
}
} else if (lines[i].startsWith("MAP")) {
} else if (lines[i].find("MAP") == 0) {
cout << endl << "this is a map line ...";
status = sscanf(lines[i].latin1(), "MAP %d %d %d %d %d %d %d %d %d %d",
status = sscanf(lines[i].c_str(), "MAP %d %d %d %d %d %d %d %d %d %d",
&val[0], &val[1], &val[2], &val[3], &val[4],
&val[5], &val[6], &val[7], &val[8], &val[9]);
if (status < 0) {
@ -117,10 +122,10 @@ PFunctionHandler::PFunctionHandler(vector<QString> lines)
for (int i=0; i<status; i++)
fMap.push_back(val[i]);
}
} else if (lines[i].startsWith("FUNCTIONS")) {
} else if (lines[i].find("FUNCTIONS") == 0) {
cout << endl << "the functions block start ...";
inFcnBlock = true;
} else if (lines[i].startsWith("END")) {
} else if (lines[i].find("END") == 0) {
cout << endl << "end tag found; rest will be ignored";
done = true;
} else if (inFcnBlock) {
@ -144,7 +149,7 @@ PFunctionHandler::PFunctionHandler(vector<QString> lines)
if (fValid) {
cout << endl << "Functions: ";
for (unsigned int i=0; i<fLines.size(); i++)
cout << endl << fLines[i].latin1();
cout << endl << fLines[i];
}
}
@ -180,9 +185,9 @@ bool PFunctionHandler::DoParse()
PFunctionGrammar function;
for (unsigned int i=0; i<fLines.size(); i++) {
cout << endl << "fLines[" << i << "] = '" << fLines[i].latin1() << "'";
cout << endl << "fLines[" << i << "] = '" << fLines[i] << "'";
tree_parse_info<> info = ast_parse(fLines[i].latin1(), function, space_p);
tree_parse_info<> info = ast_parse(fLines[i].c_str(), function, space_p);
if (info.full) {
cout << endl << "parse successfull ..." << endl;
@ -277,41 +282,38 @@ bool PFunctionHandler::ReadFile()
{
cout << endl << "in ~PFunctionHandler::ReadFile()";
if (fFileName.isEmpty()) {
if (fFileName.length() == 0) {
cout << endl << "PFunctionHandler::ReadFile(): **ERROR**";
cout << endl << " no file name given :-(. Will quit";
return false;
}
QFile f(fFileName);
if (!f.exists()) {
ifstream f;
f.open(fFileName.c_str(), ifstream::in);
if (!f.is_open()) {
cout << endl << "PFunctionHandler::ReadFile(): **ERROR**";
cout << endl << " File '" << fFileName.latin1() << "' does not exist.";
cout << endl << " File '" << fFileName.c_str() << "' couldn't being opened.";
return false;
}
if (!f.open(IO_ReadOnly)) {
cout << endl << "PFunctionHandler::ReadFile(): **ERROR**";
cout << endl << " File '" << fFileName.latin1() << "' couldn't being opened.";
return false;
}
QTextStream stream(&f);
QString line;
string line;
char c_line[128];
bool done = false;
bool success = true;
int status;
int val[10];
double dval[10];
bool inFcnBlock = false;
while ( !stream.atEnd() && !done) {
line = stream.readLine(); // line of text excluding '\n'
if (line.startsWith("#")) // comment hence ignore
while ( !f.eof() && !done) {
f.getline(c_line, 128); // line of text excluding '\n'
line = c_line;
if (line.find("#") == 0) // comment hence ignore
continue;
line = line.upper();
if (line.startsWith("PAR")) {
boost::to_upper(line);
if (line.find("PAR") == 0) {
cout << endl << "this is a parameter line ...";
status = sscanf(line.latin1(), "PAR %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
status = sscanf(line.c_str(), "PAR %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
&dval[0], &dval[1], &dval[2], &dval[3], &dval[4],
&dval[5], &dval[6], &dval[7], &dval[8], &dval[9]);
if (status < 0) {
@ -322,10 +324,13 @@ bool PFunctionHandler::ReadFile()
cout << endl << "PAR line, status = " << status;
for (int i=0; i<status; i++)
fParam.push_back(dval[i]);
for (unsigned int i=0; i<fParam.size(); i++)
cout << endl << "Par" << i+1 << " = " << fParam[i];
cout << endl;
}
} else if (line.startsWith("MAP")) {
} else if (line.find("MAP") == 0) {
cout << endl << "this is a map line ...";
status = sscanf(line.latin1(), "MAP %d %d %d %d %d %d %d %d %d %d",
status = sscanf(line.c_str(), "MAP %d %d %d %d %d %d %d %d %d %d",
&val[0], &val[1], &val[2], &val[3], &val[4],
&val[5], &val[6], &val[7], &val[8], &val[9]);
if (status < 0) {
@ -337,10 +342,10 @@ bool PFunctionHandler::ReadFile()
for (int i=0; i<status; i++)
fMap.push_back(val[i]);
}
} else if (line.startsWith("FUNCTIONS")) {
} else if (line.find("FUNCTIONS") == 0) {
cout << endl << "the functions block start ...";
inFcnBlock = true;
} else if (line.startsWith("END")) {
} else if (line.find("END") == 0) {
cout << endl << "end tag found; rest will be ignored";
done = true;
} else if (inFcnBlock) {
@ -365,7 +370,7 @@ bool PFunctionHandler::ReadFile()
if (success) {
cout << endl << "Functions: ";
for (unsigned int i=0; i<fLines.size(); i++)
cout << endl << fLines[i].latin1();
cout << endl << fLines[i];
}
return success;

View File

@ -34,10 +34,9 @@
#include <iostream>
#include <vector>
#include <string>
using namespace std;
#include <qstring.h>
#include "PFunctionGrammar.h"
#include "PFunction.h"
@ -45,7 +44,7 @@ class PFunctionHandler
{
public:
PFunctionHandler(char *fln, bool debug);
PFunctionHandler(vector<QString> lines);
PFunctionHandler(vector<string> lines);
virtual ~PFunctionHandler();
virtual bool IsValid() { return fValid; }
@ -58,11 +57,11 @@ class PFunctionHandler
bool fDebug;
bool fValid;
QString fFileName;
string fFileName;
vector<double> fParam;
vector<int> fMap;
vector<QString> fLines;
vector<string> fLines;
vector<PFunction> fFuncs;

View File

@ -17,13 +17,14 @@
PAR 1.0 2.1 3.5 -0.87 0.87
MAP 2 1 4 5
FUNCTIONS
fun0 = cos(par1)
#fun0 = sin(par3/(par1+map2))
#fun0 = 1.2+pi
#fun1 = gamma_mu
#fun2 = -par1*(sin(par2)*cos(par3)+((map1)))
#fun1 = cos(par1)
#fun0 = par1 + map3 * cos(cos(par2 - map1))
fun8 = -par1*log(sin(par1)) + exp(-1.0*map2)
#fun8 = -par1*log(sin(par1)) + exp(-1.0*map2)
#fun1 = par1 + map1 * (0.01355+par1*(2.1 - (-2.3 / 3.4)))
#fun2 = par1 * par2 - map3
#fun3 = -3.2 + (par2-par1)/(map2+map3)

View File

@ -1,8 +1,7 @@
#include <iostream>
#include <string>
using namespace std;
#include <qstring.h>
#include "PFunctionHandler.h"
//-----------------------------------------------------
@ -17,7 +16,7 @@ void syntax()
}
//-----------------------------------------------------
void handle_input(vector<QString> &lines)
void handle_input(vector<string> &lines)
{
cout << endl << "will handle input ...";
cout << endl << "you should provide a PAR, a MAP, and a FUNCTION block";
@ -80,7 +79,7 @@ int main(int argc, char *argv[])
if (inputFile) {
fcnHandler = new PFunctionHandler(argv[2], debug);
} else {
vector<QString> lines;
vector<string> lines;
handle_input(lines);
cout << endl << "lines.size() = " << lines.size();
fcnHandler = new PFunctionHandler(lines);

View File

@ -0,0 +1,33 @@
#-------------------------------------------------
# spirit_fcn_test.mak
#-------------------------------------------------
# Paths
STD_INC = "C:\Program Files\Microsoft Visual Studio 9.0\VC\include"
BOOST_INC = "D:\boost_1_43_0\boost_1_43_0"
LIB_PATH_1 = "C:\Program Files\Microsoft Visual Studio 9.0\VC\lib"
LIB_PATH_2 = "C:\Program Files\Microsoft SDKs\Windows\v6.0a\Lib"
LIB_PATH_3 = "D:\boost_1_43_0\boost_1_43_0\bin.v2\libs"
# Compiler etc
CC = cl
LINK32 = link
# Options
CXXFLAGS = /c /W3 /O2 /nologo /EHsc /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /I$(STD_INC) /I$(BOOST_INC)
LINK32_FLAGS = /nologo /subsystem:console /incremental:no /machine:I386
fln = spirit_fcn_test
OBJ = $(fln).obj PFunction.obj PFunctionHandler.obj
$(fln): $(OBJ)
$(LINK32) $(LINK32_FLAGS) /LIBPATH:$(LIB_PATH_1) /LIBPATH:$(LIB_PATH_2) /LIBPATH:$(LIB_PATH_3) $(OBJ) /out:$(fln).exe
.cpp.obj:
$(CC) $(CXXFLAGS) $<
clean:
@del /f *.obj