Scicos: indent c_pass1 and related modelica files 24/11224/1
Clément DAVID [Fri, 5 Apr 2013 10:23:19 +0000 (12:23 +0200)]
Change-Id: I9fed0f4d5147f5fd18dc1c3e9ce74cf82d0f0fa2

scilab/modules/scicos/macros/scicos_scicos/build_modelica_block.sci
scilab/modules/scicos/macros/scicos_scicos/c_pass1.sci
scilab/modules/scicos/macros/scicos_scicos/create_modelica.sci

index d8dc336..372861b 100644 (file)
 //
 
 function [model,ok]=build_modelica_block(blklstm,corinvm,cmmat,NiM,NoM,scs_m,path)
-// given the blocks definitions in blklstm and connections in cmmat this
-// function first create  the associated modelicablock  and writes its code
-// in the file named 'imppart_'+name+'.mo' in the directory given by path
-// Then modelica compiler is called to produce the C code of scicos block
-// associated to this modelica block. filbally the C code is compiled and
-// dynamically linked with Scilab.
-// The correspondind model data structure is returned.
+    // given the blocks definitions in blklstm and connections in cmmat this
+    // function first create  the associated modelicablock  and writes its code
+    // in the file named 'imppart_'+name+'.mo' in the directory given by path
+    // Then modelica compiler is called to produce the C code of scicos block
+    // associated to this modelica block. filbally the C code is compiled and
+    // dynamically linked with Scilab.
+    // The correspondind model data structure is returned.
 
 
-//## get the name of the generated main modelica file
-name=stripblanks(scs_m.props.title(1))+'_im'; 
+    //## get the name of the generated main modelica file
+    name=stripblanks(scs_m.props.title(1))+"_im";
 
-//## generation of the txt for the main modelica file
-//## plus return ipar/rpar for the model of THE modelica block
-[txt,rpar,ipar]=create_modelica(blklstm,corinvm,cmmat,name,scs_m);
+    //## generation of the txt for the main modelica file
+    //## plus return ipar/rpar for the model of THE modelica block
+    [txt,rpar,ipar]=create_modelica(blklstm,corinvm,cmmat,name,scs_m);
 
-//## write txt in the file path+name+'.mo'
-path=pathconvert(stripblanks(path),%t,%t)
-mputl(txt,path+name+'.mo');
-mprintf('%s\n',['--------------------------------------------\';
-               msprintf(_(' Main Modelica : %s'),path+name+'.mo')
-               ''])
+    //## write txt in the file path+name+'.mo'
+    path=pathconvert(stripblanks(path),%t,%t)
+    mputl(txt,path+name+".mo");
+    mprintf("%s\n",["--------------------------------------------\";
+    msprintf(_(" Main Modelica : %s"),path+name+".mo")
+    ""])
 
-//## search for 
+    //## search for
 
-Mblocks = [];
-for i=1:lstsize(blklstm)
-  if type(blklstm(i).sim)==15 then
-    if blklstm(i).sim(2)==30004 then
-      o = scs_m(scs_full_path(corinvm(i)))
-      Mblocks=[Mblocks;
-              o.graphics.exprs.nameF]
+    Mblocks = [];
+    for i=1:lstsize(blklstm)
+        if type(blklstm(i).sim)==15 then
+            if blklstm(i).sim(2)==30004 then
+                o = scs_m(scs_full_path(corinvm(i)))
+                Mblocks=[Mblocks;
+                o.graphics.exprs.nameF]
+            end
+        end
     end
-  end
-end
 
-//generating XML and Flat_Model
-//## compile modelica files
-[ok,name,nipar,nrpar,nopar,nz,nx,nx_der,nx_ns,nin,nout,nm,ng,dep_u]=compile_modelica(path+name+'.mo',Mblocks);
+    //generating XML and Flat_Model
+    //## compile modelica files
+    [ok,name,nipar,nrpar,nopar,nz,nx,nx_der,nx_ns,nin,nout,nm,ng,dep_u]=compile_modelica(path+name+".mo",Mblocks);
 
-if ~ok then return,end
+    if ~ok then return,end
 
-//nx is the state dimension
-//ng is the number of surfaces
-//name1 of the model+flat
+    //nx is the state dimension
+    //ng is the number of surfaces
+    //name1 of the model+flat
 
-//build model data structure of the block equivalent to the implicit part
-model=scicos_model(sim=list(name,10004),.. 
-                   in=ones(nin,1),out=ones(nout,1),..
-                   state=zeros(nx*2,1),..
-                   dstate=zeros(nz,1),..
-                   rpar=rpar,..
-                   ipar=ipar,..
-                   dep_ut=[dep_u %t],nzcross=ng,nmode=nm)
+    //build model data structure of the block equivalent to the implicit part
+    model=scicos_model(sim=list(name,10004),..
+    in=ones(nin,1),out=ones(nout,1),..
+    state=zeros(nx*2,1),..
+    dstate=zeros(nz,1),..
+    rpar=rpar,..
+    ipar=ipar,..
+    dep_ut=[dep_u %t],nzcross=ng,nmode=nm)
 endfunction
index b683a19..70aada4 100644 (file)
 //
 
 function  [blklst,cmat,ccmat,cor,corinv,ok,scs_m,flgcdgen,freof]=c_pass1(scs_m,flgcdgen)
-//derived from c_pass1 for implicit diagrams
-//%Purpose
-// Determine one level blocks and connections matrix
-//%Parameters
-// scs_m  :   scicos data structure
-// ksup   :
-// blklst : a list containing the "model" information structure for each block
-//
-// cmat   : nx6 matrix. Each row contains, in order, the block
-//             number and the port number and the port type of an outgoing scicopath,
-//             and the block number and the port number and the port type of the target
-//             ingoing scicopath. for regular links
-//
-// ccmat  : nx4 matrix.  Each row contains, in order, the block
-//             number and the port number  of an outgoing scicopath,
-//             and the block number and the port number  of the target
-//             ingoing scicopath for clock connections
-
-// cor    : is a list with same recursive structure as scs_m each leaf 
-//          contains the index of associated block in blklst 
-// corinv : corinv(nb) is the path of nb ith block defined in blklst 
-//          in the scs_m structure
-//!
-// Serge Steer 2003, Copyright INRIA
-// flgcdgen: is a flag containing the numbre of event input of the diagram 
-//           it is used only in the Codegeneration case.
-// freof   : it is a vector containing the frequency and the offset of the major clock.
-//           it is used only in the Codegeneration case.
-// Fady Nassif 2007. INRIA.
-//c_pass1;
-
-if argn(2)<=1 then flgcdgen=-1, end
-freof=[];
-MaxBlock=countblocks(scs_m);
-blklst=[];cmat=[],ccmat=[],cor=[],corinv=[]
-[cor,corinvt,links_table,cur_fictitious,sco_mat,ok]=scicos_flat(scs_m);
-if ~ok then
-  disp(mprintf("%s: flat failed", "c_pass1"));
-  return;
-end
-[links_table,sco_mat,ok]=global_case(links_table,sco_mat)
-if ~ok then
-  disp(mprintf("%s: global case failed", "c_pass1"));
-  return;
-end
-index1=find((sco_mat(:,2)=='-1')& (sco_mat(:,5)<>'10'))
-if index1<>[] then
-  for i=index1
-    [path]=findinlist(cor,-evstr(sco_mat(i,1)))
-    full_path=path(1)
-    if flgcdgen<>-1 then full_path=[numk full_path];scs_m=all_scs_m;end
-    hilite_path(full_path,"Error in compilation, There is a FROM ''"+(sco_mat(i,3))+ "'' without a GOTO",%t)
-    ok=%f;
-    disp(mprintf("%s: invalid connection matrix", "c_pass1"));
-    return;
-  end
-end
-
-nb=size(corinvt);
-reg=1:nb
-//form the block lists
-
-blklst=list();kr=0 ; //regular  block list 
-blklstm=list();km=0; //modelica block list
-
-//if ind(i)>0  ith block is a regular  block and stored in blklst(ind(i))
-//if ind(i)<0  ith block is a modelica block and stored in blklstm(-ind(i))
-
-ind=[];
-
-for kb=1:nb
-  o=scs_m(scs_full_path(corinvt(kb)));
-  if is_modelica_block(o) then
-    km=km+1;blklstm(km)=o.model;
-    ind(kb)=-km;
-    [modelx,ok]=build_block(o); // compile modelica block type 30004
+    //derived from c_pass1 for implicit diagrams
+    //%Purpose
+    // Determine one level blocks and connections matrix
+    //%Parameters
+    // scs_m  :   scicos data structure
+    // ksup   :
+    // blklst : a list containing the "model" information structure for each block
+    //
+    // cmat   : nx6 matrix. Each row contains, in order, the block
+    //             number and the port number and the port type of an outgoing scicopath,
+    //             and the block number and the port number and the port type of the target
+    //             ingoing scicopath. for regular links
+    //
+    // ccmat  : nx4 matrix.  Each row contains, in order, the block
+    //             number and the port number  of an outgoing scicopath,
+    //             and the block number and the port number  of the target
+    //             ingoing scicopath for clock connections
+
+    // cor    : is a list with same recursive structure as scs_m each leaf
+    //          contains the index of associated block in blklst
+    // corinv : corinv(nb) is the path of nb ith block defined in blklst
+    //          in the scs_m structure
+    //!
+    // Serge Steer 2003, Copyright INRIA
+    // flgcdgen: is a flag containing the numbre of event input of the diagram
+    //           it is used only in the Codegeneration case.
+    // freof   : it is a vector containing the frequency and the offset of the major clock.
+    //           it is used only in the Codegeneration case.
+    // Fady Nassif 2007. INRIA.
+    //c_pass1;
+
+    if argn(2)<=1 then flgcdgen=-1, end
+    freof=[];
+    MaxBlock=countblocks(scs_m);
+    blklst=[];cmat=[],ccmat=[],cor=[],corinv=[]
+    [cor,corinvt,links_table,cur_fictitious,sco_mat,ok]=scicos_flat(scs_m);
     if ~ok then
-      disp(mprintf("%s: unable to build modelica block", "c_pass1"));
-      return
+        disp(mprintf("%s: flat failed", "c_pass1"));
+        return;
     end
-  else
-    [model,ok]=build_block(o);
+    [links_table,sco_mat,ok]=global_case(links_table,sco_mat)
     if ~ok then
-      disp(mprintf("%s: unable to build block", "c_pass1"));
-      return,
+        disp(mprintf("%s: global case failed", "c_pass1"));
+        return;
     end
+    index1=find((sco_mat(:,2)=="-1")& (sco_mat(:,5)<>"10"))
+    if index1<>[] then
+        for i=index1
+            [path]=findinlist(cor,-evstr(sco_mat(i,1)))
+            full_path=path(1)
+            if flgcdgen<>-1 then full_path=[numk full_path];scs_m=all_scs_m;end
+            hilite_path(full_path,"Error in compilation, There is a FROM ''"+(sco_mat(i,3))+ "'' without a GOTO",%t)
+            ok=%f;
+            disp(mprintf("%s: invalid connection matrix", "c_pass1"));
+            return;
+        end
+    end
+
+    nb=size(corinvt);
+    reg=1:nb
+    //form the block lists
+
+    blklst=list();kr=0 ; //regular  block list
+    blklstm=list();km=0; //modelica block list
+
+    //if ind(i)>0  ith block is a regular  block and stored in blklst(ind(i))
+    //if ind(i)<0  ith block is a modelica block and stored in blklstm(-ind(i))
+
+    ind=[];
+
+    for kb=1:nb
+        o=scs_m(scs_full_path(corinvt(kb)));
+        if is_modelica_block(o) then
+            km=km+1;blklstm(km)=o.model;
+            ind(kb)=-km;
+            [modelx,ok]=build_block(o); // compile modelica block type 30004
+            if ~ok then
+                disp(mprintf("%s: unable to build modelica block", "c_pass1"));
+                return
+            end
+        else
+            [model,ok]=build_block(o);
+            if ~ok then
+                disp(mprintf("%s: unable to build block", "c_pass1"));
+                return,
+            end
+
+            if or(model.sim(1)==["plusblk"]) then
+                [model,links_table]=adjust_sum(model,links_table,kb);
+            end
+
+            kr=kr+1;blklst(kr)=model;
+            ind(kb)=kr;
+        end
 
-    if or(model.sim(1)==['plusblk']) then
-      [model,links_table]=adjust_sum(model,links_table,kb);
     end
 
-    kr=kr+1;blklst(kr)=model;
-    ind(kb)=kr;
-  end
-
-end
-
-if (find(sco_mat(:,5)==string(4))<>[]) then
-  if flgcdgen ==-1 then
-    [links_table,blklst,corinvt,ind,ok]=sample_clk(sco_mat,links_table,blklst,corinvt,scs_m,ind,flgcdgen)
-  else 
-    [links_table,blklst,corinvt,ind,ok,scs_m,flgcdgen,freof]=sample_clk(sco_mat,links_table,blklst,corinvt,scs_m,ind,flgcdgen)
-  end
-  if ~ok then
-    disp(mprintf("%s: unable to sample the whole diagram", "c_pass1"));
-    return,
-  end
-end
-nb=size(corinvt)
-nl=size(links_table,1)/2
-
-// Check if size match !
-if(size(links_table(:,1:3), "r") == size(matrix([1;1]*(1:nl),-1,1), "r") ..
-& size(matrix([1;1]*(1:nl),-1,1), "r") == size(links_table(:,4), "r"))
-  links_table=[links_table(:,1:3) matrix([1;1]*(1:nl),-1,1) ..
-  links_table(:,4) ];
-else
-  disp(mprintf("%s: invalid links table size", "c_pass1"));
-  return
-end
-imp=find(ind<0)
-
-reg(imp)=[]
-
-if imp==[] then //no modelica block exists
-  cmat=matfromT(links_table(find(links_table(:,5)==1),:),nb); //data flow links
-  ccmat=cmatfromT(links_table(find(links_table(:,5)==-1),:),nb); //event links
-  corinv=corinvt
-else // mixed diagram
-  nm=size(imp,'*') //number of modelica blocks
-  nr=nb-nm //number of regular blocks
-  cmmat=mmatfromT(links_table(find(links_table(:,5)==2),:),nb); //modelica links
-  cmat=matfromT(links_table(find(links_table(:,5)==1),:),nb); //data flow links
-  ccmat=cmatfromT(links_table(find(links_table(:,5)==-1),:),nb);//event links
-  //build connections between modelica world and regular one. These
-  //links should be data flow links
-  // links from modelica world to regular world
-  fromM=find(dsearch(cmat(:,1),imp,'d')>0);NoM=size(fromM,'*');
-
-  if NoM>0 then
-    //add modelica Output ports in Modelica world
-    mo=modelica();mo.model='OutPutPort';mo.outputs='vo';mo.inputs='vi';
-    for k=1:NoM,blklstm($+1)=scicos_model(equations=mo);end
-    //add modelica connections to these Output ports, set negative
-    //value to port numbers to avoid conflits with other blocks
-    cmmat=[cmmat;
-           cmat(fromM,1:2) zeros(NoM,1) -(nm+(1:NoM)'),ones(NoM,1),ones(NoM,1)];
-
-    nm=nm+NoM;
-
-    //add regular connection with regular block replacing the modelica world
-
-    cmat(fromM,1:2)=[-(nr+1)*ones(NoM,1),(1:NoM)'];
-  end
-
-  // links from regular world to modelica world 
-  toM=find(dsearch(cmat(:,3),imp,'d')>0);NiM=size(toM,'*');
-  if NiM>0 then
-    //add modelica Input ports in Modelica world
-    mo=modelica();mo.model='InPutPort';mo.outputs='vo';mo.inputs='vi';
-    for k=1:NiM,blklstm($+1)=scicos_model(equations=mo);end
-    //add modelica connections to these Input ports  set negative
-    //value to port numbers to avoid conflits with other blocks
-    cmmat=[cmmat;
-           -(nm+(1:NiM)'), ones(NiM,1),zeros(NiM,1), cmat(toM,3:4), ones(NiM,1) ];
-
-    nm=nm+NiM;
-    //add regular connection with regular block replacing the modelica world
-    cmat(toM,3:4)=[-(nr+1)*ones(NiM,1),(1:NiM)'];
-  end
-
-  // modelica blocks with events ports are not allowed yet
-  if size(ccmat,1)>0 then
-    if or(dsearch(ccmat(:,[1 3]),imp,'d')>0) then
-      messagebox('An implicit block has an event port',"modal","error");
-      disp(mprintf("%s: implicit block with event port", "c_pass1"));
-      ok=%f;return
+    if (find(sco_mat(:,5)==string(4))<>[]) then
+        if flgcdgen ==-1 then
+            [links_table,blklst,corinvt,ind,ok]=sample_clk(sco_mat,links_table,blklst,corinvt,scs_m,ind,flgcdgen)
+        else
+            [links_table,blklst,corinvt,ind,ok,scs_m,flgcdgen,freof]=sample_clk(sco_mat,links_table,blklst,corinvt,scs_m,ind,flgcdgen)
+        end
+        if ~ok then
+            disp(mprintf("%s: unable to sample the whole diagram", "c_pass1"));
+            return,
+        end
     end
-  end
+    nb=size(corinvt)
+    nl=size(links_table,1)/2
+
+    // Check if size match !
+    if(size(links_table(:,1:3), "r") == size(matrix([1;1]*(1:nl),-1,1), "r") ..
+        & size(matrix([1;1]*(1:nl),-1,1), "r") == size(links_table(:,4), "r"))
+        links_table=[links_table(:,1:3) matrix([1;1]*(1:nl),-1,1) ..
+        links_table(:,4) ];
+    else
+        disp(mprintf("%s: invalid links table size", "c_pass1"));
+        return
+    end
+    imp=find(ind<0)
 
-  //renumber blocks according to their types   
+    reg(imp)=[]
 
-  corinv=list();corinvm=list();
+    if imp==[] then //no modelica block exists
+        cmat=matfromT(links_table(find(links_table(:,5)==1),:),nb); //data flow links
+        ccmat=cmatfromT(links_table(find(links_table(:,5)==-1),:),nb); //event links
+        corinv=corinvt
+    else // mixed diagram
+        nm=size(imp,"*") //number of modelica blocks
+        nr=nb-nm //number of regular blocks
+        cmmat=mmatfromT(links_table(find(links_table(:,5)==2),:),nb); //modelica links
+        cmat=matfromT(links_table(find(links_table(:,5)==1),:),nb); //data flow links
+        ccmat=cmatfromT(links_table(find(links_table(:,5)==-1),:),nb);//event links
+        //build connections between modelica world and regular one. These
+        //links should be data flow links
+        // links from modelica world to regular world
+        fromM=find(dsearch(cmat(:,1),imp,"d")>0);NoM=size(fromM,"*");
 
-  for kb=1:nb
+        if NoM>0 then
+            //add modelica Output ports in Modelica world
+            mo=modelica();mo.model="OutPutPort";mo.outputs="vo";mo.inputs="vi";
+            for k=1:NoM,blklstm($+1)=scicos_model(equations=mo);end
+            //add modelica connections to these Output ports, set negative
+            //value to port numbers to avoid conflits with other blocks
+            cmmat=[cmmat;
+            cmat(fromM,1:2) zeros(NoM,1) -(nm+(1:NoM)'),ones(NoM,1),ones(NoM,1)];
 
-    if ind(kb)<0 then // modelica block
+            nm=nm+NoM;
 
-      km=-ind(kb);
+            //add regular connection with regular block replacing the modelica world
 
-      //replace by negative value to avoid conflicts
+            cmat(fromM,1:2)=[-(nr+1)*ones(NoM,1),(1:NoM)'];
+        end
 
-      cmmat(find(cmmat(:,1)==kb),1)=-km ;
+        // links from regular world to modelica world
+        toM=find(dsearch(cmat(:,3),imp,"d")>0);NiM=size(toM,"*");
+        if NiM>0 then
+            //add modelica Input ports in Modelica world
+            mo=modelica();mo.model="InPutPort";mo.outputs="vo";mo.inputs="vi";
+            for k=1:NiM,blklstm($+1)=scicos_model(equations=mo);end
+            //add modelica connections to these Input ports  set negative
+            //value to port numbers to avoid conflits with other blocks
+            cmmat=[cmmat;
+            -(nm+(1:NiM)'), ones(NiM,1),zeros(NiM,1), cmat(toM,3:4), ones(NiM,1) ];
 
-      cmmat(find(cmmat(:,4)==kb),4)=-km;
+            nm=nm+NiM;
+            //add regular connection with regular block replacing the modelica world
+            cmat(toM,3:4)=[-(nr+1)*ones(NiM,1),(1:NiM)'];
+        end
 
-      corinvm(km)=corinvt(kb);
+        // modelica blocks with events ports are not allowed yet
+        if size(ccmat,1)>0 then
+            if or(dsearch(ccmat(:,[1 3]),imp,"d")>0) then
+                messagebox("An implicit block has an event port","modal","error");
+                disp(mprintf("%s: implicit block with event port", "c_pass1"));
+                ok=%f;return
+            end
+        end
 
-    else
+        //renumber blocks according to their types
 
-      kr=ind(kb);
+        corinv=list();corinvm=list();
 
-      cmat (find(cmat (:,1)==kb),1)=-kr;
+        for kb=1:nb
 
-      cmat (find(cmat (:,3)==kb),3)=-kr;
+            if ind(kb)<0 then // modelica block
 
-      ccmat(find(ccmat(:,1)==kb),1)=-kr;
+                km=-ind(kb);
 
-      ccmat(find(ccmat(:,3)==kb),3)=-kr;
+                //replace by negative value to avoid conflicts
 
-      corinv(kr)=corinvt(kb);
+                cmmat(find(cmmat(:,1)==kb),1)=-km ;
 
-    end
+                cmmat(find(cmmat(:,4)==kb),4)=-km;
 
-  end
+                corinvm(km)=corinvt(kb);
 
-  //renumbering done, replace negative value by positive ones
+            else
 
+                kr=ind(kb);
 
+                cmat (find(cmat (:,1)==kb),1)=-kr;
 
-  cmat(:,[1 3])=abs(cmat(:,[1 3])) ;
+                cmat (find(cmat (:,3)==kb),3)=-kr;
 
-  ccmat(:,[1 3])=abs(ccmat(:,[1 3])) ;
+                ccmat(find(ccmat(:,1)==kb),1)=-kr;
 
-  cmmat=abs(cmmat) ;
+                ccmat(find(ccmat(:,3)==kb),3)=-kr;
 
-  //create regular block associated to all modelica blocks
+                corinv(kr)=corinvt(kb);
 
-  [model,ok]=build_modelica_block(blklstm,corinvm,cmmat,NiM,NoM,scs_m,TMPDIR+'/');
+            end
 
-  if ~ok then
-    disp(mprintf("%s: build the modelica meta-block failed", "c_pass1"));
-    return
-  end
+        end
 
-  blklst(nr+1)=model;
+        //renumbering done, replace negative value by positive ones
 
-  //make compiled modelica block refer to the set of corresponding
 
-  //modelica blocks
 
-  corinv(nr+1)=corinvm //it may be useful to adapt function making use
+        cmat(:,[1 3])=abs(cmat(:,[1 3])) ;
 
-  //of corinv
+        ccmat(:,[1 3])=abs(ccmat(:,[1 3])) ;
 
-  //adjust the numbering of regular block in sco_mat
+        cmmat=abs(cmmat) ;
 
-  //if modelica's blocks exist
+        //create regular block associated to all modelica blocks
 
-  //Fady 08/11/2007
+        [model,ok]=build_modelica_block(blklstm,corinvm,cmmat,NiM,NoM,scs_m,TMPDIR+"/");
 
-  for i=1:size(sco_mat,1)
+        if ~ok then
+            disp(mprintf("%s: build the modelica meta-block failed", "c_pass1"));
+            return
+        end
 
-    if eval(sco_mat(i,1))<MaxBlock then
+        blklst(nr+1)=model;
 
-      sco_mat(i,1)=string(ind(eval(sco_mat(i,1))))
+        //make compiled modelica block refer to the set of corresponding
 
-    end
+        //modelica blocks
+
+        corinv(nr+1)=corinvm //it may be useful to adapt function making use
+
+        //of corinv
+
+        //adjust the numbering of regular block in sco_mat
+
+        //if modelica's blocks exist
 
-  end
+        //Fady 08/11/2007
 
-  sco_mat=[sco_mat;[string(size(blklst)) '-1' 'scicostimeclk0' '1' '10']]
+        for i=1:size(sco_mat,1)
 
-end
+            if eval(sco_mat(i,1))<MaxBlock then
 
-cor=update_cor(cor,reg)
+                sco_mat(i,1)=string(ind(eval(sco_mat(i,1))))
 
+            end
 
+        end
 
-// Taking care of the clk 0; 
+        sco_mat=[sco_mat;[string(size(blklst)) "-1" "scicostimeclk0" "1" "10"]]
 
-//*** this part has been taken from c_pass2 modified and placed here it must be tested ***
+    end
+
+    cor=update_cor(cor,reg)
 
-//Fady 08/11/2007
 
-nbl=size(blklst)
 
-fff=ones(nbl,1)==1
+    // Taking care of the clk 0;
 
-clkptr=zeros(nbl+1,1);clkptr(1)=1; typ_l=fff;
+    //*** this part has been taken from c_pass2 modified and placed here it must be tested ***
 
-for i=1:nbl
+    //Fady 08/11/2007
 
-  ll=blklst(i);
+    nbl=size(blklst)
 
-  clkptr(i+1)=clkptr(i)+size(ll.evtout,'*');
+    fff=ones(nbl,1)==1
 
-  //tblock(i)=ll.dep_ut($);
+    clkptr=zeros(nbl+1,1);clkptr(1)=1; typ_l=fff;
 
-  typ_l(i)=ll.blocktype=='l';
+    for i=1:nbl
 
-end
+        ll=blklst(i);
 
-all_out=[]
+        clkptr(i+1)=clkptr(i)+size(ll.evtout,"*");
 
-for k=1:size(clkptr,1)-1
+        //tblock(i)=ll.dep_ut($);
 
-  if ~typ_l(k) then
+        typ_l(i)=ll.blocktype=="l";
+
+    end
 
-    kk=[1:(clkptr(k+1)-clkptr(k))]'
+    all_out=[]
 
-    all_out=[all_out;[k*ones(kk),kk]]
+    for k=1:size(clkptr,1)-1
 
-  end
+        if ~typ_l(k) then
 
-end
+            kk=[1:(clkptr(k+1)-clkptr(k))]'
+
+            all_out=[all_out;[k*ones(kk),kk]]
+
+        end
 
-all_out=[all_out;[0,0]]
-//add time event if needed
-tblock=find((sco_mat(:,2)=='-1')&(sco_mat(:,5)=='10'))
-ind=sco_mat(tblock,1);
-if ind<>[] then
-  ind=eval(ind(:))
-  //ind=find(tblock)
-  //ind=ind(:)
-  for k=ind'
-    ccmat=[ccmat;[all_out,ones(all_out)*[k,0;0,0]]]
-  end
-  for Ii=1:length(blklst)
-    if type(blklst(Ii).sim(1))==10 then
-      if part(blklst(Ii).sim(1),1:7)=='capteur' then
-        ccmat=[ccmat;[0 0 Ii 0]]
-      end
     end
-  end
-end
-//*** 
+
+    all_out=[all_out;[0,0]]
+    //add time event if needed
+    tblock=find((sco_mat(:,2)=="-1")&(sco_mat(:,5)=="10"))
+    ind=sco_mat(tblock,1);
+    if ind<>[] then
+        ind=eval(ind(:))
+        //ind=find(tblock)
+        //ind=ind(:)
+        for k=ind'
+            ccmat=[ccmat;[all_out,ones(all_out)*[k,0;0,0]]]
+        end
+        for Ii=1:length(blklst)
+            if type(blklst(Ii).sim(1))==10 then
+                if part(blklst(Ii).sim(1),1:7)=="capteur" then
+                    ccmat=[ccmat;[0 0 Ii 0]]
+                end
+            end
+        end
+    end
+    //***
 endfunction
 //**-----------------------------------------------------------------------------------------------------------------
 
 function [model,links_table]=adjust_sum(model,links_table,k)
-//sum blocks have variable number of input ports, adapt the associated
-//model data structure and input connection to take into account the
-//actual number of connected ports
-// Serge Steer 2003, Copyright INRIA
-  in=find(links_table(:,1)==k&links_table(:,3)==1)
-  nin=size(in,'*')
-  model.in=-ones(nin,1)
-  links_table(in,2)=(1:nin)'
+    //sum blocks have variable number of input ports, adapt the associated
+    //model data structure and input connection to take into account the
+    //actual number of connected ports
+    // Serge Steer 2003, Copyright INRIA
+    in=find(links_table(:,1)==k&links_table(:,3)==1)
+    nin=size(in,"*")
+    model.in=-ones(nin,1)
+    links_table(in,2)=(1:nin)'
 endfunction
 
 
 function mat=mmatfromT(Ts,nb)
-//S. Steer, R. Nikoukhah 2003. Copyright INRIA
-  Ts(:,1)=abs(Ts(:,1));
-  K=unique(Ts(find(Ts(:,1)>nb),1)); // identificator of blocks to be removed
-  //remove superblocks port and split connections 
-  Ts=remove_fictitious(Ts,K)
-  
-  // from connection matrix
-  Imat=[];
-  for u=matrix(unique(Ts(:,4)),1,-1)
-    kue=matrix(find(Ts(:,4)==u),-1,1); //identical links
-    Imat=[Imat;[kue(2:$)  kue(1).*ones(kue(2:$))]];
-  end
-  mat=[Ts(Imat(:,1),1:3)  Ts(Imat(:,2),1:3)]
+    //S. Steer, R. Nikoukhah 2003. Copyright INRIA
+    Ts(:,1)=abs(Ts(:,1));
+    K=unique(Ts(find(Ts(:,1)>nb),1)); // identificator of blocks to be removed
+    //remove superblocks port and split connections
+    Ts=remove_fictitious(Ts,K)
+
+    // from connection matrix
+    Imat=[];
+    for u=matrix(unique(Ts(:,4)),1,-1)
+        kue=matrix(find(Ts(:,4)==u),-1,1); //identical links
+        Imat=[Imat;[kue(2:$)  kue(1).*ones(kue(2:$))]];
+    end
+    mat=[Ts(Imat(:,1),1:3)  Ts(Imat(:,2),1:3)]
 endfunction
 
 
 function mat=matfromT(Ts,nb)
-//S. Steer, R. Nikoukhah 2003. Copyright INRIA
-
-  Ts(:,1)=abs(Ts(:,1))
-  K=unique(Ts(find(Ts(:,1)>nb),1)); // identificator of blocks to be removed
-  //remove superblocks port and split connections 
-  Ts=remove_fictitious(Ts,K)
-
-  // from connection matrix
-  Imat=[];
-  for u=matrix(unique(Ts(:,4)),1,-1)
-    kue=matrix(find(Ts(:,4)==u&Ts(:,3)==-1),-1,1); //look for outputs
-    jue=matrix(find(Ts(:,4)==u&Ts(:,3)==1),-1,1); //look for inputs
-    Imat=[Imat;[ones(jue).*.kue jue.*.ones(kue)]];
-  end
-  mat=[Ts(Imat(:,1),1:2)  Ts(Imat(:,2),1:2)]
+    //S. Steer, R. Nikoukhah 2003. Copyright INRIA
+
+    Ts(:,1)=abs(Ts(:,1))
+    K=unique(Ts(find(Ts(:,1)>nb),1)); // identificator of blocks to be removed
+    //remove superblocks port and split connections
+    Ts=remove_fictitious(Ts,K)
+
+    // from connection matrix
+    Imat=[];
+    for u=matrix(unique(Ts(:,4)),1,-1)
+        kue=matrix(find(Ts(:,4)==u&Ts(:,3)==-1),-1,1); //look for outputs
+        jue=matrix(find(Ts(:,4)==u&Ts(:,3)==1),-1,1); //look for inputs
+        Imat=[Imat;[ones(jue).*.kue jue.*.ones(kue)]];
+    end
+    mat=[Ts(Imat(:,1),1:2)  Ts(Imat(:,2),1:2)]
 endfunction
 
 function mat=cmatfromT(Ts,nb)
-//S. Steer, R. Nikoukhah 2003. Copyright INRIA
-//this function has been modified to support 
-// CLKGOTO et CLKFROM
-// Fady NASSIF: 11/07/2007
-  k=find(Ts(:,1)<0) //superblock ports links and CLKGOTO/CLKFROM
-  K=unique(Ts(k,1));
-  Ts=remove_fictitious(Ts,K)
-  
-  if Ts==[] then mat=[],return,end
-//  if size(Ts,1)<>int(size(Ts,1)/2)*2 then disp('PB'),pause,end
-  [s,k]=gsort(Ts(:,[4,3]),'lr','i');Ts=Ts(k,:)
-  // modified to support the CLKGOTO/CLKFROM
-  //mat=[Ts(1:2:$,1:2) Ts(2:2:$,1:2)]
-//----------------------------------
-
-  J=find(Ts(:,3)==1); //find the destination block of the link
-  v=find([Ts(:,3);-1]==-1) // find the source block of the link
-  // many destination blocks can be connected to one source block
-  // so we have to find the number of destination blocks for each source block
-  // v(2:$)-v(1:$-1)-1
-  // then create the vector I that must be compatible with the vector J.
-  I=duplicate(v(1:$-1),v(2:$)-v(1:$-1)-1); 
-  mat=[Ts(I,1:2),Ts(J,1:2)]
-
-//----------------------------------
-  K=unique(Ts(Ts(:,1)>nb))
-  Imat=[];
-  for u=matrix(K,1,-1)
-    jue=matrix(find(mat(:,1)==u),-1,1); //look for outputs
-    kue=matrix(find(mat(:,3)==u),-1,1); //look for inputs
-    Imat=[ones(jue).*.kue jue.*.ones(kue)];
-    mat1=[mat(Imat(:,1),1:2), mat(Imat(:,2),3:4)];
-    mat([jue;kue],:)=[];
-    mat=[mat;mat1];
-  end
-  
+    //S. Steer, R. Nikoukhah 2003. Copyright INRIA
+    //this function has been modified to support
+    // CLKGOTO et CLKFROM
+    // Fady NASSIF: 11/07/2007
+    k=find(Ts(:,1)<0) //superblock ports links and CLKGOTO/CLKFROM
+    K=unique(Ts(k,1));
+    Ts=remove_fictitious(Ts,K)
+
+    if Ts==[] then mat=[],return,end
+    //  if size(Ts,1)<>int(size(Ts,1)/2)*2 then disp('PB'),pause,end
+    [s,k]=gsort(Ts(:,[4,3]),"lr","i");Ts=Ts(k,:)
+    // modified to support the CLKGOTO/CLKFROM
+    //mat=[Ts(1:2:$,1:2) Ts(2:2:$,1:2)]
+    //----------------------------------
+
+    J=find(Ts(:,3)==1); //find the destination block of the link
+    v=find([Ts(:,3);-1]==-1) // find the source block of the link
+    // many destination blocks can be connected to one source block
+    // so we have to find the number of destination blocks for each source block
+    // v(2:$)-v(1:$-1)-1
+    // then create the vector I that must be compatible with the vector J.
+    I=duplicate(v(1:$-1),v(2:$)-v(1:$-1)-1);
+    mat=[Ts(I,1:2),Ts(J,1:2)]
+
+    //----------------------------------
+    K=unique(Ts(Ts(:,1)>nb))
+    Imat=[];
+    for u=matrix(K,1,-1)
+        jue=matrix(find(mat(:,1)==u),-1,1); //look for outputs
+        kue=matrix(find(mat(:,3)==u),-1,1); //look for inputs
+        Imat=[ones(jue).*.kue jue.*.ones(kue)];
+        mat1=[mat(Imat(:,1),1:2), mat(Imat(:,2),3:4)];
+        mat([jue;kue],:)=[];
+        mat=[mat;mat1];
+    end
+
 endfunction
 
 function Ts=remove_fictitious(Ts,K)
-//removes fictitious blocks connected links are replaced by a single one
-//S. Steer, R. Nikoukhah 2003. Copyright INRIA
-  count=min(Ts(:,4))
-  for i=1:size(K,'*')
-    ki=K(i);
-    v1=find(Ts(:,1)==ki);
-    if v1<>[] then
-      v=unique(Ts(v1,4));
-      Ts(v1,:)=[];
-      if size(v)==1 then
-       ind=find(Ts(:,4)==v);
-      else
-       ind = find(dsearch(Ts(:,4),gsort(v,'g','i'),'d')<>0);
-      end
-      if size(ind,'*')>1 then
-       count=count-1;
-       Ts(ind,4)=count
-      else
-       Ts(ind,:)=[]
-      end
+    //removes fictitious blocks connected links are replaced by a single one
+    //S. Steer, R. Nikoukhah 2003. Copyright INRIA
+    count=min(Ts(:,4))
+    for i=1:size(K,"*")
+        ki=K(i);
+        v1=find(Ts(:,1)==ki);
+        if v1<>[] then
+            v=unique(Ts(v1,4));
+            Ts(v1,:)=[];
+            if size(v)==1 then
+                ind=find(Ts(:,4)==v);
+            else
+                ind = find(dsearch(Ts(:,4),gsort(v,"g","i"),"d")<>0);
+            end
+            if size(ind,"*")>1 then
+                count=count-1;
+                Ts(ind,4)=count
+            else
+                Ts(ind,:)=[]
+            end
+        end
     end
-  end
 endfunction
 
 function cor=update_cor(cor,reg)
-  n=size(cor)
-  for k=1:n
-    if type(cor(k))==15 then
-      cor(k)=update_cor(cor(k),reg)
-    else
-      p=find(cor(k)==reg)
-      if p<>[] then 
-       cor(k)=p
-      elseif cor(k)<0 then  // GOTO FROM cases
-       cor(k)=0
-      elseif cor(k)<>0 then
-       cor(k)=size(reg,'*')+1
-      end
+    n=size(cor)
+    for k=1:n
+        if type(cor(k))==15 then
+            cor(k)=update_cor(cor(k),reg)
+        else
+            p=find(cor(k)==reg)
+            if p<>[] then
+                cor(k)=p
+            elseif cor(k)<0 then  // GOTO FROM cases
+                cor(k)=0
+            elseif cor(k)<>0 then
+                cor(k)=size(reg,"*")+1
+            end
+        end
     end
-  end
 endfunction
index 6472e45..f6c4c91 100644 (file)
 
 function [txt,rpar,ipar] = create_modelica(blklst,corinvm,cmat,name,scs_m)
 
-  if exists('%Modelica_Init')==0 then
-    // Modelica_Init becomes true only in "Modelicainitialize_.sci"
-    %Modelica_Init=%f;
-  end
-  if exists('%Modelica_ParEmb')==0 then
-    %Modelica_ParEmb=%t;
-  end
-
-  Parembed=%Modelica_ParEmb & ~%Modelica_Init;
-
-  txt=[];tab=ascii(9)
-  rpar=[];//will contain all parameters associated with the all modelica blocs
-  ipar=[];//will contain the "adress" of each block in rpar
-  models=[]//will contain the model declaration part
-  eqns=[]//will contain the modelica equations part
-  Pin=[]
-  Bnumbers=[]
-  Bnam=[]
-  Bnames=[]
-  nb=size(blklst)
-  Params=[];
-  for k=1:nb
-    ipar(k)=0
-    o=blklst(k);
-    //#########
-    //## Params
-    //#########
-    mo=o.equations;
-    np=size(mo.parameters(1),'*');
-    P=[];
-    //** mo.parameters have size=2
-    //** it only contains parameters
-    if np<>0 then
-      if lstsize(mo.parameters)==2 then
-        mo.parameters(3)=zeros(1,np)
-      end
+    if exists("%Modelica_Init")==0 then
+        // Modelica_Init becomes true only in "Modelicainitialize_.sci"
+        %Modelica_Init=%f;
     end
-
-    for j=1:np
-      //## loop on number of param value
-      //## can be both scalar or array
-      Parj=mo.parameters(1)(j)
-      Parjv=mo.parameters(2)(j)
-      Parj_in=Parj+'_'+string(k)+string(j)
-
-      if type(Parjv)==1 then // if Real/Complex        Integers are used with "fixed=true"
-       rpar=[rpar;matrix(Parjv,-1,1)]
-       ipar(k)=ipar(k)+size(Parjv,'*')
-      end
-      //======================================================
-      Params=[Params;construct_Pars(Parj_in,Parjv,Parembed)]
-      if mo.parameters(3)(j)==0 then
-       P=[P;Parj+'='+Parj_in]
-      elseif mo.parameters(3)(j)==1 then
-       //eParjv=construct_redeclar(Parjv)
-       P=[P;Parj+'(start='+Parj_in+')'];
-      elseif mo.parameters(3)(j)==2 then
-       //eParjv=construct_redeclar(Parjv)
-       P=[P;Parj+'(start='+Parj_in+',fixed=true)'];
-      end
-      //======================================================
+    if exists("%Modelica_ParEmb")==0 then
+        %Modelica_ParEmb=%t;
     end
 
-    //#########
-    //## models
-    //#########
-    Bnumbers=[Bnumbers k];
-
-    //## update list of names of modelica blocks
-    // Modelica compiler complains about ID containing dots
-    // So remove them Modelica.package.subpackage => Modelica_DOT_package_DOT_subpackage
-    Bnam = [Bnam, get_model_name(strsubst(mo.model, ".", "_DOT_"),Bnam)];
-    Bnames = [Bnames, Bnam($)]
-
-    if P==[] then
-      models=[models;
-              '  '+mo.model+' '+tab+Bnames($)];
-    else
-      models=[models;
-              '  '+mo.model+' '+tab+Bnames($)+'('+strcat(P,', ')+')'];
+    Parembed=%Modelica_ParEmb & ~%Modelica_Init;
+
+    txt=[];tab=ascii(9)
+    rpar=[];//will contain all parameters associated with the all modelica blocs
+    ipar=[];//will contain the "adress" of each block in rpar
+    models=[]//will contain the model declaration part
+    eqns=[]//will contain the modelica equations part
+    Pin=[]
+    Bnumbers=[]
+    Bnam=[]
+    Bnames=[]
+    nb=size(blklst)
+    Params=[];
+    for k=1:nb
+        ipar(k)=0
+        o=blklst(k);
+        //#########
+        //## Params
+        //#########
+        mo=o.equations;
+        np=size(mo.parameters(1),"*");
+        P=[];
+        //** mo.parameters have size=2
+        //** it only contains parameters
+        if np<>0 then
+            if lstsize(mo.parameters)==2 then
+                mo.parameters(3)=zeros(1,np)
+            end
+        end
+
+        for j=1:np
+            //## loop on number of param value
+            //## can be both scalar or array
+            Parj=mo.parameters(1)(j)
+            Parjv=mo.parameters(2)(j)
+            Parj_in=Parj+"_"+string(k)+string(j)
+
+            if type(Parjv)==1 then // if Real/Complex  Integers are used with "fixed=true"
+                rpar=[rpar;matrix(Parjv,-1,1)]
+                ipar(k)=ipar(k)+size(Parjv,"*")
+            end
+            //======================================================
+            Params=[Params;construct_Pars(Parj_in,Parjv,Parembed)]
+            if mo.parameters(3)(j)==0 then
+                P=[P;Parj+"="+Parj_in]
+            elseif mo.parameters(3)(j)==1 then
+                //eParjv=construct_redeclar(Parjv)
+                P=[P;Parj+"(start="+Parj_in+")"];
+            elseif mo.parameters(3)(j)==2 then
+                //eParjv=construct_redeclar(Parjv)
+                P=[P;Parj+"(start="+Parj_in+",fixed=true)"];
+            end
+            //======================================================
+        end
+
+        //#########
+        //## models
+        //#########
+        Bnumbers=[Bnumbers k];
+
+        //## update list of names of modelica blocks
+        // Modelica compiler complains about ID containing dots
+        // So remove them Modelica.package.subpackage => Modelica_DOT_package_DOT_subpackage
+        Bnam = [Bnam, get_model_name(strsubst(mo.model, ".", "_DOT_"),Bnam)];
+        Bnames = [Bnames, Bnam($)]
+
+        if P==[] then
+            models=[models;
+            "  "+mo.model+" "+tab+Bnames($)];
+        else
+            models=[models;
+            "  "+mo.model+" "+tab+Bnames($)+"("+strcat(P,", ")+")"];
+        end
+
+        //## Add gr_i identification in comments of models
+        if mo.model<>"OutPutPort" & mo.model<>"InPutPort" then
+            //## retrieve the object in the scs_m structure
+            o_scsm = scs_m(scs_full_path(corinvm(k)));
+            //## get the structure graphics
+            o_gr  = o_scsm.graphics;
+            //## get the identification field
+            id = stripblanks(o_gr.id)
+
+            if id<>"" then
+                models($)=models($)+" """+id+""";"
+            else
+                models($)=models($)+";"
+            end
+        else
+            models($)=models($)+";"
+        end
+
+        //rajouter les ports
     end
-
-    //## Add gr_i identification in comments of models
-    if mo.model<>'OutPutPort' & mo.model<>'InPutPort' then
-      //## retrieve the object in the scs_m structure
-      o_scsm = scs_m(scs_full_path(corinvm(k)));
-      //## get the structure graphics
-      o_gr  = o_scsm.graphics;
-      //## get the identification field
-      id = stripblanks(o_gr.id)
-
-      if id<>'' then
-        models($)=models($)+' ""'+id+'"";'
-      else
-        models($)=models($)+';'
-      end
-    else
-      models($)=models($)+';'
-    end
-
-    //rajouter les ports
-  end
-  ipar=cumsum([1;ipar(:)])
-
-  //links
-  for k=1:size(cmat,1)
-    from=cmat(k,1:3)
-    to=cmat(k,4:6)
-    if from(1)==0 then //input port
-      nb=nb+1
-      Bnumbers=[Bnumbers nb];
-      Bnames=[Bnames,'B'+string(nb)];
-      models=[models;'  InPutPort'+' '+tab+'B'+string(nb)+';'];
-      n1='B'+string(nb)
-    elseif from(3)==1 then
-      p1=blklst(from(1)).equations.inputs(from(2))
-      n1=Bnames(find(Bnumbers==from(1)))
-    else
-      p1=blklst(from(1)).equations.outputs(from(2))
-      n1=Bnames(find(Bnumbers==from(1)))
+    ipar=cumsum([1;ipar(:)])
+
+    //links
+    for k=1:size(cmat,1)
+        from=cmat(k,1:3)
+        to=cmat(k,4:6)
+        if from(1)==0 then //input port
+            nb=nb+1
+            Bnumbers=[Bnumbers nb];
+            Bnames=[Bnames,"B"+string(nb)];
+            models=[models;"  InPutPort"+" "+tab+"B"+string(nb)+";"];
+            n1="B"+string(nb)
+        elseif from(3)==1 then
+            p1=blklst(from(1)).equations.inputs(from(2))
+            n1=Bnames(find(Bnumbers==from(1)))
+        else
+            p1=blklst(from(1)).equations.outputs(from(2))
+            n1=Bnames(find(Bnumbers==from(1)))
+        end
+
+        if to(1)==0 then //output port
+            nb=nb+1
+            Bnumbers=[Bnumbers nb];
+            Bnames=[Bnames,"B"+string(nb)];
+            models=[models;"  OutPutPort"+" "+tab+"B"+string(nb)+";"];
+            n1="B"+string(nb)
+        elseif to(3)==1 then
+            p2=blklst(to(1)).equations.inputs(to(2))
+            n2=Bnames(find(Bnumbers==to(1)))
+        else
+            if size(blklst(to(1)).equations.outputs,"*")<to(2) then pause,end
+            p2=blklst(to(1)).equations.outputs(to(2))
+            n2=Bnames(find(Bnumbers==to(1)))
+        end
+
+        if or(blklst(from(1)).equations.model==["InPutPort","OutPutPort"]) ...
+            | or(blklst(to(1)).equations.model==["InPutPort","OutPutPort"]) ...
+            then
+            eqns=[eqns
+            "  "+n1+"."+p1+" = "+n2+"."+p2+";"]
+        else
+            eqns=[eqns
+            "  connect ("+n1+"."+p1+","+n2+"."+p2+");"]
+        end
     end
 
-    if to(1)==0 then //output port
-      nb=nb+1
-      Bnumbers=[Bnumbers nb];
-      Bnames=[Bnames,'B'+string(nb)];
-      models=[models;'  OutPutPort'+' '+tab+'B'+string(nb)+';'];
-      n1='B'+string(nb)
-    elseif to(3)==1 then
-      p2=blklst(to(1)).equations.inputs(to(2))
-      n2=Bnames(find(Bnumbers==to(1)))
-    else
-      if size(blklst(to(1)).equations.outputs,'*')<to(2) then pause,end
-      p2=blklst(to(1)).equations.outputs(to(2))
-      n2=Bnames(find(Bnumbers==to(1)))
-    end
-
-    if or(blklst(from(1)).equations.model==['InPutPort','OutPutPort']) ...
-         | or(blklst(to(1)).equations.model==['InPutPort','OutPutPort']) ...
-    then
-      eqns=[eqns
-            '  '+n1+'.'+p1+' = '+n2+'.'+p2+';']
-    else
-      eqns=[eqns
-            '  connect ('+n1+'.'+p1+','+n2+'.'+p2+');']
-    end
-  end
-
-  txt=[txt;
-       'model '+name
-       Params
-       models
-       'equation'
-       eqns
-       'end '+name+';']
+    txt=[txt;
+    "model "+name
+    Params
+    models
+    "equation"
+    eqns
+    "end "+name+";"]
 endfunction
 
 function r=validvar_modelica(s)
- r=validvar(s);
-
- if r then
-   bad_char=['%' '#' '$']
-   for j=1:size(bad_char,2)
-     if strindex(s,bad_char(j)) then
-       r=%f
-       return
-     end
-   end
- end
+    r=validvar(s);
+
+    if r then
+        bad_char=["%" "#" "$"]
+        for j=1:size(bad_char,2)
+            if strindex(s,bad_char(j)) then
+                r=%f
+                return
+            end
+        end
+    end
 endfunction
 
 
 
 function r=write_nD_format(x)
-  sx=size(x)
-
-  if size(sx,'*')==2 then // Matrix/Vector
-      [nD1,nD2]=size(x)
-      if nD1==1 then // rows vector
-        r='{'+strcat(string(x),',')+'}'
-        r=strsubst(r,'D','e');
-        return r;
-      elseif nD2==1   then // column vector
-       N=nD1;
-       cmd=')'
-      else  //matrix
-       N=sx(1);
-       cmd=',:)'
-      end
-   else // hypermatrix
-     // typeof(x)==hypermat
-     //  xd=x.entries
-     //  sdims=x.dims(2:$)
-     //  N=x.dims(1)
-     //  cmd=':)'
-     //  n=size(sx,'c')
-     //  for i=1:n-2;cmd=':,'+cmd;end;
-     //  cmd=','+cmd;
-  end
-  r=[];
-  for i=1:N
-      cmdx='write_nD_format(x('+string(i)+cmd+')';
-      execstr("r(i)="+cmdx,'errcatch')
-  end
-  r='{'+strcat(r,',')+'}';
+    sx=size(x)
+
+    if size(sx,"*")==2 then // Matrix/Vector
+        [nD1,nD2]=size(x)
+        if nD1==1 then // rows vector
+            r="{"+strcat(string(x),",")+"}"
+            r=strsubst(r,"D","e");
+            return r;
+        elseif nD2==1   then // column vector
+            N=nD1;
+            cmd=")"
+        else  //matrix
+            N=sx(1);
+            cmd=",:)"
+        end
+    else // hypermatrix
+        // typeof(x)==hypermat
+        //  xd=x.entries
+        //  sdims=x.dims(2:$)
+        //  N=x.dims(1)
+        //  cmd=':)'
+        //  n=size(sx,'c')
+        //  for i=1:n-2;cmd=':,'+cmd;end;
+        //  cmd=','+cmd;
+    end
+    r=[];
+    for i=1:N
+        cmdx="write_nD_format(x("+string(i)+cmd+")";
+        execstr("r(i)="+cmdx,"errcatch")
+    end
+    r="{"+strcat(r,",")+"}";
 endfunction
 
 // a 2x3 matrix {{xx,xx,xx},{xx,xx,xx}}
@@ -247,86 +247,86 @@ endfunction
 
 function     Pari=construct_Pars(Pari,opari,Parembed)
 
-  if Pari==[] then
-    return ' '
-  end
-   // Pars='  parameter Real '+Pars+'(fixed=false);'
-   [atemp]=format();
-   format(20);// writing in long format
-
-   //erpar=string(rpar); will put 1e-16 to zero in a vector containing
-   //big numbers
-
-   C=opari;
-   [a1,b1]=size(C);
-   npi=a1*b1;
-   if typeof(C)== 'hypermat' then
-     messagebox(_('Hyper Matrix is not supported'),'error','modal')
-     return
-   end
-
-   if (type(C)==1) then
-     if isreal(C) then
-       par_type='Real'
-     else
-       par_type='Complex'
-     end
-     FIXED='false'
-   elseif (typeof(C)=="int32") | (typeof(C)=="int16") |...
-        (typeof(C)=="int8") |(typeof(C)=="uint32") |...
-        (typeof(C)=="uint16") | (typeof(C)=="uint8") then
-     par_type='Integer'
-     FIXED='true'
-   else
-     par_type='UnKnown_Type'
-     FIXED='???'
-     messagebox(_("Type not recognized"),'error','modal');ok=%f;
-   end
-
-   if ~Parembed then
-     FIXED='true'
-   end
-
-   if (npi==1) then,
-     eopari=strsubst(string(C),'D','e');
-     fixings='(fixed='+FIXED+') '
-   else
-     eopari=write_nD_format(C)
-     fixings='(each fixed='+FIXED+') ';
-     [d1,d2]=size(C);
-      if (d1==1) then
-       Pari=Pari+'['+string(d2)+']'; //[d2]
-      else
-       Pari=Pari+'['+string(d1)+','+string(d2)+']'; //[d1,d2]
-      end
-   end
-  Pari='  parameter '+par_type+' '+Pari+ fixings+'='+eopari+ "  """+Pari+""""+';'
-  format(atemp(2))// restituing the format
+    if Pari==[] then
+        return " "
+    end
+    // Pars='  parameter Real '+Pars+'(fixed=false);'
+    [atemp]=format();
+    format(20);// writing in long format
+
+    //erpar=string(rpar); will put 1e-16 to zero in a vector containing
+    //big numbers
+
+    C=opari;
+    [a1,b1]=size(C);
+    npi=a1*b1;
+    if typeof(C)== "hypermat" then
+        messagebox(_("Hyper Matrix is not supported"),"error","modal")
+        return
+    end
+
+    if (type(C)==1) then
+        if isreal(C) then
+            par_type="Real"
+        else
+            par_type="Complex"
+        end
+        FIXED="false"
+    elseif (typeof(C)=="int32") | (typeof(C)=="int16") |...
+        (typeof(C)=="int8") |(typeof(C)=="uint32") |...
+        (typeof(C)=="uint16") | (typeof(C)=="uint8") then
+        par_type="Integer"
+        FIXED="true"
+    else
+        par_type="UnKnown_Type"
+        FIXED="???"
+        messagebox(_("Type not recognized"),"error","modal");ok=%f;
+    end
+
+    if ~Parembed then
+        FIXED="true"
+    end
+
+    if (npi==1) then,
+        eopari=strsubst(string(C),"D","e");
+        fixings="(fixed="+FIXED+") "
+    else
+        eopari=write_nD_format(C)
+        fixings="(each fixed="+FIXED+") ";
+        [d1,d2]=size(C);
+        if (d1==1) then
+            Pari=Pari+"["+string(d2)+"]"; //[d2]
+        else
+            Pari=Pari+"["+string(d1)+","+string(d2)+"]"; //[d1,d2]
+        end
+    end
+    Pari="  parameter "+par_type+" "+Pari+ fixings+"="+eopari+ "  """+Pari+""""+";"
+    format(atemp(2))// restituing the format
 
 endfunction
 
 function eopari = construct_redeclar(opari)
 
-   [atemp]=format();
-   format(20);// writing in long format
-   C=opari;
-   npi=size(C,'*');
-
-   if typeof(C)== 'hypermat' then
-     messagebox(_('Hyper Matrix is not supported'),'error','modal')
-     return
-   end
-   if  ~isreal(C) then
-     messagebox(_('Complex Matrix is not supported'),'error','modal')
-     return
-   end
-
-   if (npi==1) then,
-     eopari=strsubst(string(C),'D','e');
-   else
-     eopari=write_nD_format(C)
-   end
-
-  format(atemp(2))// restituing the format
+    [atemp]=format();
+    format(20);// writing in long format
+    C=opari;
+    npi=size(C,"*");
+
+    if typeof(C)== "hypermat" then
+        messagebox(_("Hyper Matrix is not supported"),"error","modal")
+        return
+    end
+    if  ~isreal(C) then
+        messagebox(_("Complex Matrix is not supported"),"error","modal")
+        return
+    end
+
+    if (npi==1) then,
+        eopari=strsubst(string(C),"D","e");
+    else
+        eopari=write_nD_format(C)
+    end
+
+    format(atemp(2))// restituing the format
 
 endfunction