Download libsbml[5pt] Developer`s Manual

Transcript
to set the level to 2, the model structure at that moment is translated internally so that such
things as object names are converted to id’s (which do not exist in Level 1).
The C program listed in Figure 8 is provided in the libsbml distribution in the examples
subdirectory. This command-line program takes two arguments: the name of an input file and
the name of an output file. It then translates the SBML in the input file into SBML Level 2 and
writes it out to the named output file. It may be surprising to see how short this program is.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <string.h>
#include "sbml/SBMLTypes.h"
int
main (int argc, char *argv[])
{
MathMLDocument_t *doc;
ASTNode_t
*ast;
char
*result;
MathMLDocument_t *new_doc;
ASTNode_t
*new_mathml;
char
*new_s;
const char* expected = "1 + f(x)";
const char* s = "<?xml version=’1.0’ encoding=’UTF-8’?>"
"<math xmlns=’http://www.w3.org/1998/Math/MathML’>"
" <apply> <plus/> <cn> 1 </cn>"
"
<apply> <ci> f </ci> <ci> x </ci> </apply>"
" </apply>"
"</math>";
doc
= readMathMLFromString(s);
ast
= MathMLDocument_getMath(doc);
result = SBML_formulaToString(ast);
if ( strcmp(result, expected) == 0 )
{
printf("Got expected result\n");
}
else
{
printf("Mismatch after readMathMLFromString()\n");
}
new_mathml = SBML_parseFormula(result);
new_doc
= MathMLDocument_create();
MathMLDocument_setMath(new_doc, new_mathml);
new_s
= writeMathMLToString(new_doc);
printf("Result of writing AST:\n");
printf(new_s);
return 0;
}
Figure 7: Short program to translate MathML into a formula string and back.
31