1
function [cor,corinv,links_table,cur_fictitious,ok]=scicos_flat(scs_m,ksup)
2
//This function takes a hierarchical Scicos diagram and computes the
3
//"flat" equivalent, removing "non computational" blocs like splits.
4
//S. Steer, R. Nikoukhah 2003. Copyright INRIA
5
if argn(2)<=1 then ksup=0;end //used for recursion
7
if ksup==0 then // main scheme
8
MaxBlock=countblocks(scs_m);
9
//last created fictitious block (clock split,clock sum,super_blocks, superbloc))
10
cur_fictitious=MaxBlock
11
path=[]; // for delete_unconnected
12
scs_m_s=scs_m ;// for delete_unconnected
14
//-------------- suppress blocks with an unconnected regular port --------------
15
scs_m=delete_unconnected(scs_m);
17
//list of blocks with are not retained in the final block list
18
blocks_to_remove=['CLKSPLIT_f' 'SPLIT_f' 'IMPSPLIT_f' 'CLKSOM_f' 'CLKSOMV_f' 'NRMSOM_f']
19
port_blocks=['IN_f','INIMPL_f','OUT_f','OUTIMPL_f','CLKIN_f','CLKINV_f','CLKOUT_f','CLKOUTV_f']
20
n=lstsize(scs_m.objs) //number of "objects" in the data structure
21
//-------------- initialize outputs --------------
25
cor=list();for k=1:n, cor(k)=0;end
28
Links=[] //to memorize links position in the data structure
30
//-------------- Analyse blocks --------------
32
for k=1:n //loop on all objects
37
if or(o.gui==blocks_to_remove) then
38
cur_fictitious=cur_fictitious+1;
40
elseif o.gui=='SUM_f'|o.gui=='SOM_f' then
44
//scs_m=adjust_sum(scs_m,k)
45
elseif or(o.gui==port_blocks) then
46
//here we suppose to be inside a superblock
47
//may be we can handle this blocks just as blocks_to_remove
50
hilite_path([path,k],'Port blocks must be only used in a Super Block',%f)
53
connected=get_connected(scs_m,k)
56
hilite_path([path,k],'This Super Block Input port is unconnected',%t)
59
if or(o.gui==['IN_f','INIMPL_f']) then
61
elseif or(o.gui==['OUT_f','OUTIMPL_f']) then
63
elseif or(o.gui==['CLKIN_f','CLKINV_f']) then
65
elseif or(o.gui==['CLKOUT_f','CLKOUTV_f']) then
68
//connect the link to the fictitious bloc replacing the superblock
69
if scs_m.objs(connected).from(1)==k then
70
scs_m.objs(connected).from(1)=-(pind+o.model.ipar)
72
if scs_m.objs(connected).to(1)==k then
73
scs_m.objs(connected).to(1)=-(pind+o.model.ipar)
76
elseif o.model.sim=='super'|o.model.sim=='csuper' then
77
path=[path k] //superbloc path in the hierarchy
78
//replace superbloc by a set of fictitious blocks (one per port)
79
//and reconnect links connected to the superblock to these
81
Pinds=[];if exists('Pind') then Pinds=Pind,end
82
Pind=[] //base of ports numbering
83
//mprintf("entering superblock at level '+string(size(path,'*'))+"\r\n")
84
for port_type=['pin','pout','pein','peout']
85
Pind=[Pind cur_fictitious]
86
ip=scs_m.objs(k).graphics(port_type);ki=find(ip>0)
89
if scs_m.objs(kc).to(1)==k then // a link going to the superblock
90
scs_m.objs(kc).to(1)=-(cur_fictitious+scs_m.objs(kc).to(2));
91
scs_m.objs(kc).to(2)=1
93
if scs_m.objs(kc).from(1)==k then // a link coming from the superblock
94
scs_m.objs(kc).from(1)=-(cur_fictitious+scs_m.objs(kc).from(2));
95
scs_m.objs(kc).from(2)=1
98
cur_fictitious=cur_fictitious+size(ip,'*')
102
//Analyze the superblock contents
104
[cors,corinvs,lt,cur_fictitious,ok]=scicos_flat(o.model.rpar,cur_fictitious)
105
if ~ok then return,end
108
//catenate superbloc data with current data
110
f=find(lt(:,1)>0<(:,1)<=nbs);if f<>[] then lt(f,1)=lt(f,1)+nb,end
111
links_table=[links_table;lt]
113
for kk=1:nbs, corinv(nb+kk)=[k,corinvs(kk)];end
114
cors=shiftcors(cors,nb)
120
else//standard blocks
123
//[model,ok]=build_block(o.model)
126
elseif x(1)=='Deleted'|x(1)=='Text' then
127
//this objects are ignored
129
Links=[Links k] // memorize their position for use during links analysis
131
end //end of loop on objects
133
if ksup==0&nb==0 then
134
message('Empty diagram')
139
//-------------- Analyse links --------------
143
if o.from(1)<0|o.from(1)>MaxBlock then //Link coming from a superblock input port
145
o.from(1)=cor(o.from(1));
147
if o.to(1)<0 |o.to(1)>MaxBlock then //Link going to a superblock output port
149
o.to(1)=cor(o.to(1)),
152
if o.ct(2)==2 //implicit links
153
//if abs(o.from(1))==125|abs(o.to(1))==125 then pause,end
154
links_table=[links_table
157
else //regular or event links
158
links_table=[links_table
159
o.from(1:2) -1 o.ct(2) //outputs are tagged with -1
160
o.to(1:2) 1 o.ct(2) ] //inputs are tagged with 1