2008-01-11 14:42:14 +01:00
|
|
|
/*
|
2009-01-22 16:05:38 +01:00
|
|
|
* Copyright (C) 2003-2009 Dynare Team
|
2008-01-11 14:42:14 +01:00
|
|
|
*
|
|
|
|
* This file is part of Dynare.
|
|
|
|
*
|
|
|
|
* Dynare is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Dynare is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2008-06-28 13:20:45 +02:00
|
|
|
#include <cstdlib>
|
2006-11-05 00:31:17 +01:00
|
|
|
#include <iostream>
|
2007-05-08 21:16:35 +02:00
|
|
|
|
2006-11-05 00:31:17 +01:00
|
|
|
#include "NumericalConstants.hh"
|
2006-11-23 20:10:41 +01:00
|
|
|
|
2007-05-08 21:16:35 +02:00
|
|
|
int
|
|
|
|
NumericalConstants::AddConstant(const string &iConst)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2007-05-08 21:16:35 +02:00
|
|
|
map<string, int>::iterator iter = numConstantsIndex.find(iConst);
|
2007-06-04 00:35:30 +02:00
|
|
|
//cout << "iConst=" << iConst << "\n" ;
|
2006-11-23 20:10:41 +01:00
|
|
|
if (iter != numConstantsIndex.end())
|
|
|
|
return iter->second;
|
|
|
|
|
2007-05-08 21:16:35 +02:00
|
|
|
if (atof(iConst.c_str()) < 0)
|
|
|
|
{
|
|
|
|
cerr << "Can't handle a negative constant..!" << endl;
|
2008-10-29 16:33:16 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2007-05-08 21:16:35 +02:00
|
|
|
}
|
|
|
|
|
2006-11-23 20:10:41 +01:00
|
|
|
int id = (int) mNumericalConstants.size();
|
2006-11-05 00:31:17 +01:00
|
|
|
mNumericalConstants.push_back(iConst);
|
2006-11-23 20:10:41 +01:00
|
|
|
numConstantsIndex[iConst] = id;
|
|
|
|
return id;
|
2006-11-05 00:31:17 +01:00
|
|
|
}
|
|
|
|
|
2007-05-08 21:16:35 +02:00
|
|
|
string
|
|
|
|
NumericalConstants::get(int ID) const
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2007-05-08 21:16:35 +02:00
|
|
|
if (ID < (int) mNumericalConstants.size())
|
|
|
|
return mNumericalConstants[ID];
|
2006-11-05 00:31:17 +01:00
|
|
|
else
|
|
|
|
{
|
2007-05-08 21:16:35 +02:00
|
|
|
cerr << "Unknown constant" << endl;
|
2008-10-29 16:33:16 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2006-11-05 00:31:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-08 21:16:35 +02:00
|
|
|
double
|
|
|
|
NumericalConstants::getDouble(int iID) const
|
|
|
|
{
|
|
|
|
return(atof(get(iID).c_str()));
|
|
|
|
}
|