Lengthy example of creating SBML models presented in the SBML specification.
#include <stdio.h>
const char* ProgramName = "createExampleModels";
const char* ProgramVersion = "1.0.0";
const unsigned int Level = 2;
const unsigned int Version = 4;
int
main (int argc, char *argv[])
{
int SBMLok = 0;
sbmlDoc = createExampleEnzymaticReaction();
SBMLok = validateExampleSBML(sbmlDoc);
if (SBMLok == 1) writeExampleSBML(sbmlDoc, "enzymaticreaction.xml");
if (SBMLok == 0) return 1;
sbmlDoc = createExampleInvolvingUnits();
SBMLok = validateExampleSBML(sbmlDoc);
if (SBMLok == 1) writeExampleSBML(sbmlDoc, "units.xml");
if (SBMLok == 0) return 1;
sbmlDoc = createExampleInvolvingFunctionDefinitions();
SBMLok = validateExampleSBML(sbmlDoc);
if (SBMLok == 1) writeExampleSBML(sbmlDoc, "functiondef.xml");
if (SBMLok == 0) return 1;
return 0;
}
{
const unsigned int level = Level;
const unsigned int version = Version;
const char* compName = "cytosol";
char* mathXMLString;
mathXMLString = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
" <apply>"
" <times/>"
" <ci> cytosol </ci>"
" <ci> kcat </ci>"
" <ci> ES </ci>"
" </apply>"
"</math>";
return sbmlDoc;
}
{
const unsigned int level = Level;
const unsigned int version = Version;
char* notesString, * mathXMLString ;
ASTNode_t* astMath, * astDivide, * astTimes, * astPlus ;
const char* compName = "cell";
notesString = "<xhtml:p> ((vm * s1)/(km + s1)) * cell </xhtml:p>";
mathXMLString = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
" <apply>"
" <times/>"
" <apply>"
" <divide/>"
" <apply>"
" <times/>"
" <ci> vm </ci>"
" <ci> s2 </ci>"
" </apply>"
" <apply>"
" <plus/>"
" <ci> km </ci>"
" <ci> s2 </ci>"
" </apply>"
" </apply>"
" <ci> cell </ci>"
" </apply>"
"</math>";
notesString = "<xhtml:p> ((vm * x1)/(km + x1)) * cell </xhtml:p>";
mathXMLString = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
" <apply>"
" <times/>"
" <apply>"
" <divide/>"
" <apply>"
" <times/>"
" <ci> vm </ci>"
" <ci> x1 </ci>"
" </apply>"
" <apply>"
" <plus/>"
" <ci> km </ci>"
" <ci> x1 </ci>"
" </apply>"
" </apply>"
" <ci> cell </ci>"
" </apply>"
"</math>";
return sbmlDoc;
}
{
const unsigned int level = Level;
const unsigned int version = Version;
char* mathXMLString;
const char* compName = "compartmentOne";
mathXMLString = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
" <lambda>"
" <bvar>"
" <ci> x </ci>"
" </bvar>"
" <apply>"
" <times/>"
" <ci> x </ci>"
" <cn> 2 </cn>"
" </apply>"
" </lambda>"
"</math>";
mathXMLString = "<math xmlns=\"http://www.w3.org/1998/Math/MathML\">"
" <apply>"
" <divide/>"
" <apply>"
" <times/>"
" <apply>"
" <ci> f </ci>"
" <ci> S1 </ci>"
" </apply>"
" <ci> compartmentOne </ci>"
" </apply>"
" <ci> t </ci>"
" </apply>"
"</math>";
return sbmlDoc;
}
{
int noProblems = 1;
unsigned int numCheckFailures = 0;
unsigned int numConsistencyErrors = 0;
unsigned int numConsistencyWarnings = 0;
unsigned int numValidationErrors = 0;
unsigned int numValidationWarnings = 0;
if (!sbmlDoc)
{
fprintf(stderr, "validateExampleSBML: given a null SBML Document\n");
return 0;
}
if ( numCheckFailures > 0 )
{
unsigned int i;
noProblems = 0;
for (i = 0; i < numCheckFailures; i++)
{
{
++numConsistencyErrors;
}
else
{
++numConsistencyWarnings;
}
}
}
if (numConsistencyErrors > 0)
{
printf("Further validation aborted.\n");
}
else
{
if ( numCheckFailures > 0 )
{
unsigned int i;
noProblems = 0;
for (i = 0; i < numCheckFailures; i++)
{
{
++numValidationErrors;
}
else
{
++numValidationWarnings;
}
}
}
}
if (noProblems)
return 1;
else
{
if (numConsistencyErrors > 0)
{
printf("ERROR: encountered %d consistency error%s in model '%s'.\n",
numConsistencyErrors,
(numConsistencyErrors == 1 ? "" : "s"),
}
if (numConsistencyWarnings > 0)
{
printf( "Notice: encountered %d consistency warning%s in model '%s'.\n",
numConsistencyWarnings,
(numConsistencyWarnings == 1 ? "" : "s"),
);
}
if (numValidationErrors > 0)
{
printf("ERROR: encountered %d validation error%s in model '%s'.\n",
numValidationErrors,
(numValidationErrors == 1 ? "" : "s"),
}
if (numValidationWarnings > 0)
{
printf( "Notice: encountered %d validation warning%s in model '%s'.\n",
numValidationWarnings,
(numValidationWarnings == 1 ? "" : "s"),
);
}
return (numConsistencyErrors == 0 && numValidationErrors == 0);
}
}
{
if (result)
{
printf("Wrote file \"%s\"\n", filename);
return 1;
}
else
{
fprintf(stderr, "Failed to write \"%s\"\n", filename );
return 0;
}
}