47 #include <sbml/util/util.h>
64 bool startsWith(
const std::string& str,
const std::string& sub)
66 if (str.length() < sub.length())
return false;
68 if (sub.empty())
return true;
70 for (
size_t i = 0; i < sub.length(); ++i)
71 if (str[i] != sub[i])
return false;
94 stream <<
"\"" << prefix << key <<
"\", ";
108 size_t i, j, num_params, count;
114 for (i = 0; i < reacs_size; ++i)
120 for (j = 0; j < num_params; ++j)
136 std::ostringstream p_names; p_names <<
"const char* p_names[] = {";
137 std::ostringstream x_names; x_names <<
"const char* x_names[] = {";
138 std::ostringstream y_names; y_names <<
"const char* y_names[] = {";
139 std::ostringstream xc_names; xc_names <<
"const char* xc_names[] = {";
140 std::ostringstream pc_names; pc_names <<
"const char* pc_names[] = {";
141 std::ostringstream yc_names; yc_names <<
"const char* yc_names[] = {";
142 std::ostringstream dx_names; dx_names <<
"const char* dx_names[] = {";
143 std::ostringstream ct_names; ct_names <<
"const char* ct_names[] = {";
147 std::map< std::string, std::string >::const_iterator it =
NameMap.begin();
148 std::map< std::string, std::string > reverse_map;
152 const std::string& abbrev = it->second;
153 const std::string& key = it->first;
157 reverse_map[abbrev] = key;
162 reverse_map[abbrev] = key;
167 reverse_map[abbrev] = key;
172 reverse_map[abbrev] = key;
177 reverse_map[abbrev] = key;
190 reverse_map[abbrev] = key;
205 reverse_map[abbrev] = key;
220 reverse_map[abbrev] = key;
229 for (
size_t i = 0; i < numP; ++i)
231 std::stringstream str; str <<
"p[" << i <<
"]";
235 for (
size_t i = 0; i < numX; ++i)
237 std::stringstream str; str <<
"x[" << i <<
"]";
241 for (
size_t i = 0; i < numY; ++i)
243 std::stringstream str; str <<
"y[" << i <<
"]";
247 for (
size_t i = 0; i < numDX; ++i)
249 std::stringstream str; str <<
"dx[" << i <<
"]";
253 for (
size_t i = 0; i < numCT; ++i)
255 std::stringstream str; str <<
"ct[" << i <<
"]";
259 for (
size_t i = 0; i < numXC; ++i)
261 std::stringstream str; str <<
"x_c[" << i <<
"]";
262 xc_names <<
"\"" << reverse_map[str.str()] <<
"\", ";
265 for (
size_t i = 0; i < numPC; ++i)
267 std::stringstream str; str <<
"p_c[" << i <<
"]";
268 pc_names <<
"\"" << reverse_map[str.str()] <<
"\", ";
271 for (
size_t i = 0; i < numYC; ++i)
273 std::stringstream str; str <<
"y_c[" << i <<
"]";
274 yc_names <<
"\"" << reverse_map[str.str()] <<
"\", ";
277 os <<
"#ifdef SIZE_DEFINITIONS" << std::endl;
278 os <<
"#define N_METABS " << metab_size << std::endl;
279 os <<
"#define N_ODE_METABS " << ode_size << std::endl;
280 os <<
"#define N_INDEP_METABS " << indep_size << std::endl;
281 os <<
"#define N_COMPARTMENTS " << comps_size << std::endl;
282 os <<
"#define N_GLOBAL_PARAMS " << modvals_size << std::endl;
283 os <<
"#define N_KIN_PARAMS " << count << std::endl;
284 os <<
"#define N_REACTIONS " << reacs_size << std::endl << std::endl;
286 os <<
"#define N_ARRAY_SIZE_P " << numP <<
"\t// number of parameters" << std::endl;
287 os <<
"#define N_ARRAY_SIZE_X " << numX <<
"\t// number of initials" << std::endl;
288 os <<
"#define N_ARRAY_SIZE_Y " << numY <<
"\t// number of assigned elements" << std::endl;
289 os <<
"#define N_ARRAY_SIZE_XC " << numXC <<
"\t// number of x concentration" << std::endl;
290 os <<
"#define N_ARRAY_SIZE_PC " << numPC <<
"\t// number of p concentration" << std::endl;
291 os <<
"#define N_ARRAY_SIZE_YC " << numYC <<
"\t// number of y concentration" << std::endl;
292 os <<
"#define N_ARRAY_SIZE_DX " << numDX <<
"\t// number of ODEs " << std::endl;
293 os <<
"#define N_ARRAY_SIZE_CT " << numCT <<
"\t// number of conserved totals" << std::endl << std::endl;
295 os <<
"#endif // SIZE_DEFINITIONS" << std::endl;
298 os <<
"#ifdef TIME" << std::endl;
299 os <<
"#define T <set here a user name for the time variable> " << std::endl;
300 os <<
"#endif // TIME" << std::endl;
303 os <<
"#ifdef NAME_ARRAYS" << std::endl;
304 os << p_names.str() <<
" \"\" };" << std::endl;
305 os << x_names.str() <<
" \"\" };" << std::endl;
306 os << y_names.str() <<
" \"\" };" << std::endl;
307 os << xc_names.str() <<
" \"\" };" << std::endl;
308 os << pc_names.str() <<
" \"\" };" << std::endl;
309 os << yc_names.str() <<
" \"\" };" << std::endl;
310 os << dx_names.str() <<
" \"\" };" << std::endl;
311 os << ct_names.str() <<
" \"\" };" << std::endl;
312 os <<
"#endif // NAME_ARRAYS" << std::endl;
325 std::ostringstream name;
330 name <<
"p[" << n[0] <<
"]";
338 name <<
"x[" << n[1] <<
"]";
343 name <<
"y[" << n[2] <<
"]";
350 name <<
"x[" << n[1] <<
"]";
355 name <<
"y[" << n[2] <<
"]";
369 std::ostringstream name;
374 name <<
"p_c[" << n[0] <<
"]";
382 name <<
"x_c[" << n[1] <<
"]";
387 name <<
"y_c[" << n[2] <<
"]";
394 name <<
"x_c[" << n[1] <<
"]";
399 name <<
"y_c[" << n[2] <<
"]";
421 std::ostringstream tmpName;
423 size_t realName_size = realName.size();
428 if (!std::isalpha(ch, C))
432 if (std::isdigit(ch, C)) tmpName << ch;
436 for (i = 1; i < realName_size; i++)
440 if (std::isalpha(ch, C))
442 if (std::isspace(realName[i - 1], C) && std::islower(ch, C))
443 tmpName << (char) toupper(ch);
448 if (std::isdigit(ch, C)) tmpName << ch;
450 if (std::ispunct(ch, C))
487 std::ostringstream newname, tmp;
489 size_t name_size = name.size();
492 for (i = 0; i < name_size; i++)
496 if (std::isalpha(ch, C) && std::islower(ch, C))
497 tmp << (char) toupper(ch);
512 newname << name <<
"_" <<
Frequancy[tmp.str()];
520 return "d" + objName;
526 size_t n[3] = {0, 0, 0};
527 size_t n_c[3] = {0, 0, 0};
536 size_t metabs_size = metabs.
size();
538 for (i = 0; i < metabs_size; i++)
540 CMetab * metab = metabs[i];
553 std::ostringstream smKey;
554 smKey <<
"sm_" << metab->
getKey();
556 NameMap[smKey.str()] = smname;
560 std::ostringstream odeKey;
561 odeKey <<
"ode_" << metab->
getKey();
571 for (i = 0; i < comps_size; i++)
583 std::ostringstream odeKey;
584 odeKey <<
"ode_" << comp->
getKey();
593 for (i = 0; i < modvals_size; i++)
601 std::ostringstream odeKey;
602 odeKey <<
"ode_" << modval->
getKey();
611 std::set<std::string> tmpset;
613 for (i = 0; i < reacs_size; ++i)
617 params_size = reacs[i]->getParameters().
size();
619 for (j = 0; j < params_size; ++j)
621 if (!reacs[i]->isLocalParameter(reacs[i]->getParameters().getParameter(j)->getObjectName()))
624 std::ostringstream name;
626 name <<
"p[" << n[0] <<
"]";
629 NameMap[reacs[i]->getParameters().getParameter(j)->
getKey()] = name.str();
632 const CFunction* func = reacs[i]->getFunction();
640 if (tmpset.find(name) == tmpset.end())
657 while (treeIt != NULL)
681 which << name <<
" = " << expression <<
";"
682 <<
'\t' <<
"//" << comments << std::endl;
692 std::ostringstream smKey;
693 smKey <<
"sm_" << metab->
getKey();
777 if (util_isNaN(number))
780 if (util_isInf(number))
783 std::stringstream str; str << number;
829 metab =
dynamic_cast< const CMetab *
>(tmp);
833 std::ostringstream smKey;
834 smKey <<
"sm_" << metab->
getKey();
892 size_t size = reacs.
size();
897 for (i = 0; i < size; ++i)
928 std::map< std::string, std::string > parameterNameMap;
929 std::set<std::string> parameterNameSet;
931 std::map< CFunctionParameter::Role, std::string > constName;
932 std::map< CFunctionParameter::Role, size_t > tmpIndex;
942 for (j = 0; j < varbs_size; ++j)
946 std::ostringstream tmpName;
949 tmpName << constName[role] << tmpIndex[role];
958 while (newIt != NULL)
979 if (isExported.find(name) == isExported.end())
985 if (mappedName.empty())
991 functions <<
"double " << mappedName <<
"(";
992 headers <<
"double " << mappedName <<
"(";
994 for (j = 0; j < varbs_size; ++j)
998 if (j != varbs_size - 1)
functions <<
", ";
1002 if (j != varbs_size - 1)
headers <<
", ";
1006 functions <<
'\t' <<
"//" << name << std::endl;
1009 headers <<
"); " << std::endl;
1011 isExported.insert(name);
1020 std::ostringstream equation;
1025 size_t k, params_size = params.
size();
1030 for (k = 0; k < params_size; ++k)
1042 name = NameMap[obj->
getKey()];
1053 name = NameMap[modval->
getKey()];
1059 name = NameMap[param->
getKey()];
1067 name = NameMap[comp->
getKey()];
1077 std::string message =
"Could not export C code, since one of the arguments could not be resolved. Please consider filing a bug with the COPASI tracker: http://www.copasi.org/tracker";
1083 if (k != params_size - 1)
1096 size_t substrs_size = substrs.
size(), prods_size = prods.
size();
1123 for (k = 0; k < substrs_size; ++k)
1125 substr = substrs[k];
1132 for (m = 1; m < mult; ++m)
1157 for (k = 0; k < prods_size; ++k)
1166 for (m = 1; m < mult; ++m)
1174 return equation.str();
1179 std::ostringstream odeKey;
1180 odeKey <<
"ode_" << mentity->
getKey();
1192 return "#ifdef INITIAL";
1195 return "#ifdef FIXED";
1198 return "#ifdef ASSIGNMENT";
1201 return "#ifdef FUNCTIONS_HEADERS";
1204 return "#ifdef FUNCTIONS";
1207 return "#ifdef ODEs";
1228 return "#endif /* INITIAL */\n";
1231 return "#endif /* FIXED */\n";
1234 return "#endif /* ASSIGNMENT */\n";
1237 return "#endif /* FUNCTIONS_HEADERS */\n";
1240 return "#endif /* FUNCTIONS */\n";
1243 return "#endif /* ODEs */\n";
Header file of class CExpression.
bool startsWith(const std::string &str, const std::string &sub)
virtual bool exportSingleModVal(const CModelValue *modval, std::string &expression, std::string &comments)
std::set< std::string > NameSet
virtual bool exportSingleModelEntity(const CModelEntity *tmp, std::string &expression, std::string &comments)
virtual std::string translateTimeVariableName()
std::ostringstream headers
virtual std::string translateObjectName(const std::string &realName)
virtual bool exportSingleFunction(const CFunction *func, std::set< std::string > &isExported)
virtual bool exportSingleMetabolite(const CMetab *metab, std::string &expression, std::string &comments)
const std::string & getObjectName() const
const CCopasiVectorN< CModelValue > & getModelValues() const
virtual std::string KineticFunction2ODEmember(const CReaction *reac)
virtual size_t size() const
CCopasiObject * get(const std::string &key)
virtual std::string exportTitleString(const size_t tmp)
const CMetab * getMetabolite() const
bool isLocalParameter(const size_t &index) const
const CEvaluationTree::Type & getType() const
virtual bool exportSingleODE(const CModelEntity *mentity, std::string &equation, std::string &comments)
virtual bool exportSingleObject(std::ostringstream &which, const std::string &name, const std::string &expression, const std::string &comments)
virtual void setReservedNames()
size_t getNumODEMetabs() const
std::ostringstream initial
std::string buildCCodeString() const
const std::string & getKey() const
std::map< std::string, size_t > Frequancy
void printNameForKey(std::ostringstream &stream, CKeyFactory *kf, const std::string &key, const std::string prefix="")
virtual std::string exportClosingString(const size_t tmp)
virtual const std::string & getKey() const
const CCopasiVector< CChemEqElement > & getProducts() const
static Type type(const Type &type)
const CFunction * getFunction() const
virtual std::string exportNumber(double number)
const CFunctionParameters & getFunctionParameters() const
virtual bool exportSingleCompartment(const CCompartment *comp, std::string &expression, std::string &comments)
std::ostringstream functions
const TriLogic & isReversible() const
virtual const std::string & getKey() const
virtual bool exportSingleParameter(const CCopasiParameter *param, std::string &expression, std::string &comments)
virtual const std::string & getKey() const
const C_FLOAT64 & getMultiplicity() const
virtual std::string getSingleLineComment()
void setExportNameOfFunction(const CEvaluationNode *pNode, std::set< std::string > &tmpset)
std::string testName(const std::string &name)
const CCopasiVector< CChemEqElement > & getSubstrates() const
std::string setODEName(const std::string &objName)
static CFunctionDB * getFunctionList()
size_t getNumIndependentReactionMetabs() const
void modifyTreeForMassAction(CFunction *tmpfunc)
CCopasiVectorNS< CCompartment > & getCompartments()
static CKeyFactory * getKeyFactory()
std::map< std::string, std::string > NameMap
const CCopasiParameterGroup & getParameters() const
virtual bool exportKineticFunctionGroup(const CModel *copasiModel)
std::ostringstream assignment
The class for handling a chemical kinetic function.
CCopasiVectorNS< CReaction > & getReactions()
void findFunctionsCalls(const CEvaluationNode *pNode)
virtual bool exportKineticFunction(CReaction *reac)
std::string setExportName(const CModelEntity::Status &status, size_t n[], size_t dependent)
const CModelEntity::Status & getStatus() const
const CCopasiVector< CMetab > & getMetabolitesX() const
const std::vector< std::vector< std::string > > & getParameterMappings() const
virtual bool preprocess(const CModel *copasiModel)
virtual bool exportTitleData(const CModel *copasiModel, std::ostream &os)
CFunction * findFunction(const std::string &functionName)
const CChemEq & getChemEq() const
CEvaluationNode * getRoot()
std::string setConcentrationName(const CModelEntity::Status &status, size_t n[], size_t dependent)
bool exportSingleFunction(const CFunction *func)
CFunctionParameters & getVariables()
virtual std::string getDisplayExpressionString(CExpression *tmp)