- Index
- » Developer
- » OpenModelica development
- » Generation of XML file via...
Generation of XML file via openModelica API with a specific shape.
Generation of XML file via openModelica API with a specific shape.
Hi every one,
First, thank you for the attention and help you'll give to this post.
I wrote an openModelica API named "createXML" which creates from a modelica model
a specific XML file which contains all definitions of variables.
The start point of my development was the "dumpXMLDAE" API function for
openModelica version 1.9.1_Beta1.
This openModelica API "createXML" works and generates a XML file
such as:
<?xml version="1.0" encoding="UTF-8"?>
<model>
<name> modelName <\name>
<variables dimension="52">
<elements>
<terminal>
<name> output_tetaInterne.value <\name>
<kind> continuous <\kind>
<id> 1 <\id>
<type> Real <\type>
<direction> output <\direction>
<fixed> false <\fixed>
<connector> Potential <\connector>
<className>
<element>
modelName
</element>
<element>
OutPin
</element>
<element>
Real
</element>
</className>
</terminal>
.....
<terminal>
<name> teta <\name>
<kind> continuous <\kind>
<id> 42 <\id>
<type> Real <\type>
<direction> none <\direction>
<fixed> false <\fixed>
<connector> Non_Connector <\connector>
<className>
<element>
DYNModelM1S
</element>
<element>
Real
</element>
</className>
<attributesValues>
<initialValue string="teta0">
</initialValue>
</attributesValues>
</terminal>
...
This openModelica API "createXML" works from "FrontEnd DAE" only on the first DAE lower
(dlow = BackendDAECreate.lower(dae,cache,env,BackendDAE.EXTRA_INFO(cname_str)); )
without any optimization.
Yet, the shape of my resulting XML file is not sufficient.
I must change its form for the variables which the name (DAE.ComponentRef) is equal to a designation
like that "name1.name2".
like the previous variable 'output_tetaInterne.value"
and so I must replace these lines :
<terminal>
<name> output_tetaInterne.value <\name>
by these ones :
<struct>
<name> output_tetaInterne </name>
<subnodes>
<terminal>
<name> value </name>
....
</terminal>
</subnodes>
</struct>
I thought to split the DAE.ComponentRef of each Variable before to call a programm such as the "dumpVariable" one
but I do not manage to find how to realize it.
Perhaps, somebody can help me and tell me the correct method
Thanks
Re: Generation of XML file via openModelica API with a specific shape.
I replace the previous problem by this one less difficult :
//-------------------------------------
protected function sortCrefs
input list<BackendDAE.Var> inVars;
input list<String> inStrCR;
output list<String> outStrConnectorCref;
algorithm
outStrConnectorCref := matchcontinue (inVars,inStrCR)
local
BackendDAE.Var v1;
list<BackendDAE.Var> tail1;
DAE.ComponentRef cr1;
String selectCR;
case ({},_) then inStrCR;
case (v1 :: tail1,_)
equation
cr1 = BackendVariable.varCref(v1);
selectCR = Util.if_(BackendVariable.isVarConnector(v1),ComponentReference.printComponentRefStr(cr1),"");
then sortCrefs(tail1,listAppend(inStrCR,{selectCR}));
end matchcontinue;
end sortCrefs;
Re: Generation of XML file via openModelica API with a specific shape.
Why do you use listAppend(inStrCR,{selectCR})? This is a very slow operation; selectCR :: inStrCR is much faster.
- sjoelund.se
- 1700 Posts
Re: Generation of XML file via openModelica API with a specific shape.
Thanks
I am a beginner concerning development in MetaModelica Language.
Nowly, I try to calculate from a list of Component Ref or String
defined such as :
list = { a.b, b.d, c.f, c.d, c.h, g.h }
a integer list equal to outList = { 1, 1, 3, 0, 0, 1 }
because there is three terms with the same prefix c.
But for me, it is a little difficult!!!
//-------------------------------------
inList = split(list,1)
public function countStrCref "Specific count about StrCref."
input list<list<String>> inList;
input Integer indx;
output list<Integer> outList;
algorithm
outList := matchcontinue (inList,indx)
local
list<Integer> nbCrefList;
Integer index1;
list<String> firstLst,secondLst;
String strFirst,strSecond;
case({},_) then {}
case(_,_)
equation
indx1 = indx+1;
firstLst = listGet(inList,indx);
strFirst = listGet(firstLst,1);
secondLst = listGet(inList,indx1);
strSecond = listGet(secondLst,2);
//ilen1 = stringLength(strFirst);
//ilen2 = stringLength(strSecond);
//isLength = intEq(ilen1,ilen2);
nbSameCref = Util.if_(stringEq(strFirst,strSecond),nbSameCref+1,nbSameCref);
nbCrefList = List.insert(nbCrefList,indx,nbSameCref)
then
nbCrefList;
end matchcontinue;
end countStrCref;
- Index
- » Developer
- » OpenModelica development
- » Generation of XML file via...