~ubuntu-branches/ubuntu/hoary/scilab/hoary

« back to all changes in this revision

Viewing changes to macros/scicos/scicos_flat.sci

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2005-01-09 22:58:21 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109225821-473xr8vhgugxxx5j
Tags: 3.0-12
changed configure.in to build scilab's own malloc.o, closes: #255869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
6
  
 
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 
 
13
  end
 
14
  //-------------- suppress blocks with an unconnected regular port -------------- 
 
15
  scs_m=delete_unconnected(scs_m);
 
16
  
 
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 --------------
 
22
  nb=0;
 
23
  links_table=[]; // 
 
24
  corinv=list();
 
25
  cor=list();for k=1:n, cor(k)=0;end
 
26
 
 
27
  ok=%t;
 
28
  Links=[] //to memorize links position in the data structure
 
29
  
 
30
  //-------------- Analyse blocks --------------
 
31
 
 
32
  for k=1:n //loop on all objects
 
33
    o=scs_m.objs(k);
 
34
    x=getfield(1,o);
 
35
    cor(k)=0
 
36
    if x(1)=='Block' then
 
37
      if or(o.gui==blocks_to_remove) then
 
38
        cur_fictitious=cur_fictitious+1;
 
39
        cor(k)=cur_fictitious
 
40
      elseif o.gui=='SUM_f'|o.gui=='SOM_f' then
 
41
        nb=nb+1;
 
42
        corinv(nb)=k;
 
43
        cor(k)=nb
 
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
 
48
        if ksup==0 then 
 
49
          scs_m=scs_m_s
 
50
          hilite_path([path,k],'Port blocks must be only used in a Super Block',%f)
 
51
          ok=%f;return
 
52
        end
 
53
        connected=get_connected(scs_m,k)
 
54
        if connected==[] then
 
55
          scs_m=scs_m_s
 
56
          hilite_path([path,k],'This Super Block Input port is unconnected',%t)
 
57
          ok=%f;return
 
58
        end
 
59
        if or(o.gui==['IN_f','INIMPL_f']) then
 
60
          pind=Pind(1)
 
61
        elseif or(o.gui==['OUT_f','OUTIMPL_f']) then
 
62
          pind=Pind(2)
 
63
        elseif or(o.gui==['CLKIN_f','CLKINV_f']) then
 
64
          pind=Pind(3)
 
65
        elseif or(o.gui==['CLKOUT_f','CLKOUTV_f']) then
 
66
          pind=Pind(4)
 
67
        end 
 
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)
 
71
        end
 
72
        if scs_m.objs(connected).to(1)==k then
 
73
          scs_m.objs(connected).to(1)=-(pind+o.model.ipar)
 
74
        end
 
75
 
 
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
 
80
        //ficitious blocks
 
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)
 
87
          for kk=ki
 
88
            kc=ip(kk)
 
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
 
92
            end
 
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
 
96
            end
 
97
          end
 
98
          cur_fictitious=cur_fictitious+size(ip,'*')
 
99
        end
 
100
 
 
101
 
 
102
        //Analyze the superblock contents
 
103
 
 
104
        [cors,corinvs,lt,cur_fictitious,ok]=scicos_flat(o.model.rpar,cur_fictitious)
 
105
        if ~ok then return,end
 
106
        nbs=size(corinvs) 
 
107
        
 
108
        //catenate superbloc data with current data
 
109
 
 
110
        f=find(lt(:,1)>0&lt(:,1)<=nbs);if f<>[] then lt(f,1)=lt(f,1)+nb,end
 
111
        links_table=[links_table;lt]
 
112
        
 
113
        for kk=1:nbs, corinv(nb+kk)=[k,corinvs(kk)];end
 
114
        cors=shiftcors(cors,nb)
 
115
        cor(k)=cors
 
116
 
 
117
        nb=nb+nbs
 
118
        Pind=Pinds
 
119
        path($)=[]
 
120
      else//standard blocks
 
121
        nb=nb+1
 
122
        corinv(nb)=k
 
123
        //[model,ok]=build_block(o.model)
 
124
        cor(k)=nb
 
125
      end
 
126
    elseif x(1)=='Deleted'|x(1)=='Text' then
 
127
        //this objects are ignored
 
128
    else //links
 
129
      Links=[Links k] // memorize their position for use during links analysis
 
130
    end
 
131
  end //end of loop on objects
 
132
  
 
133
  if ksup==0&nb==0 then
 
134
    message('Empty diagram')
 
135
    ok=%f
 
136
    return
 
137
  end
 
138
 
 
139
  //-------------- Analyse  links -------------- 
 
140
  for k=Links
 
141
    o=scs_m.objs(k);
 
142
    f=0
 
143
    if o.from(1)<0|o.from(1)>MaxBlock then //Link coming from a superblock input port
 
144
    else
 
145
      o.from(1)=cor(o.from(1));
 
146
    end
 
147
    if o.to(1)<0 |o.to(1)>MaxBlock then //Link going to a superblock output port
 
148
    else
 
149
      o.to(1)=cor(o.to(1)),
 
150
    end
 
151
 
 
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
 
155
                   o.from(1:3)    o.ct(2) 
 
156
                   o.to(1:3)      o.ct(2) ]
 
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
 
161
    end
 
162
  end
 
163
endfunction