Xcos MVC: remove the "Deleted" adapter
[scilab.git] / scilab / modules / scicos / macros / scicos_scicos / do_version.sci
1 //  Scicos
2 //
3 //  Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
4 //  Copyright (C) DIGITEO - 2010 - Jérôme PICARD
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 //
20 // See the file ../license.txt
21 //
22
23 function scs_m=do_version(scs_m,version)
24
25     // available versions of Scicos
26     availableVersions = [ ..
27     "scicos2.2"; ..
28     "scicos2.3"; ..
29     "scicos2.3.1"; ..
30     "scicos2.4"; ..
31     "scicos2.5.1"; ..
32     "scicos2.7"; ..
33     "scicos2.7.1"; ..
34     "scicos2.7.2"; ..
35     "scicos2.7.3"; ..
36     "scicos4"; ..
37     "scicos4.0.1"; ..
38     "scicos4.0.2"; ..
39     "scicos4.2"; ..
40     "scicos4.0.1"; ..
41     "scicos4.0.2"; ..
42     "scicos4.2"; ..
43     "scicos4.3"; ..
44     "scicos4.4"];
45
46     if ~or(version==availableVersions) then
47         error("No version update defined to "+version+" version")
48     end
49
50     if version=="scicos2.2" then scs_m=do_version22(scs_m);version="scicos2.3";end
51     if version=="scicos2.3" then scs_m=do_version23(scs_m);version="scicos2.3.1";end
52     if version=="scicos2.3.1" then scs_m=do_version231(scs_m); version="scicos2.4";end
53     if version=="scicos2.4" then scs_m=do_version251(scs_m),version="scicos2.5.1";end
54     if version=="scicos2.5.1" then
55         ncl=lines()
56         lines(0)
57         disp("This is an old scicos diagram. I have to translate.")
58         scs_m=do_versionxx(scs_m);scs_m=do_version27(scs_m);version="scicos2.7";
59         disp("I am now going to clean your diagram. Block numbers may change.")
60         scs_m=do_purge(scs_m);
61         disp("Save the diagram (under a different name just in case)")
62         lines(ncl(2))
63     end
64     if version=="scicos2.7" then
65         disp("This is an old scicos diagram. I have to translate. Be patient.")
66         scs_m=do_version271(scs_m),
67         version="scicos2.7.1";
68     end
69     if version=="scicos2.7.1" then scs_m=do_version272(scs_m),version="scicos2.7.2";end
70     if version=="scicos2.7.2" then scs_m=do_version273(scs_m),version="scicos2.7.3";end
71     if version=="scicos2.7.3" | version=="scicos4" |...
72         version=="scicos4.0.1" | version=="scicos4.0.2" then
73         version="scicos4.2";
74         //*** do certification ***//
75         scs_m=update_scs_m(scs_m,version);
76         //*** update scope ***//
77         scs_m=do_version42(scs_m);
78         //*********************************//
79     end
80     if version=="scicos4.2" then
81         ncl=lines(); lines(0);
82         version="scicos4.3";
83         //*** do certification ***//
84         scs_m=update_scs_m(scs_m,version);
85         scs_m=do_version43(scs_m);
86         lines(ncl(2))
87     end
88
89     if or(version==["scicos4.3";"scicos4.4"]) then
90         ncl=lines(); lines(0);
91         version="scicos4.3";
92         scs_m=update_scs_m(scs_m,version);
93         scs_m=do_version43(scs_m);
94         scs_m.version = version;
95         lines(ncl(2))
96     end
97 endfunction
98
99 function scs_m_new=do_version43(scs_m)
100     //disp('do_version43');
101     scs_m_new=scs_m;
102
103     //@@ adjust ID.fonts
104     scs_m_new.props.options.ID(1)=[scs_m.props.options.ID(1)(1),scs_m.props.options.ID(1)(2),2,1];
105     scs_m_new.props.options.ID(2)=[scs_m.props.options.ID(2)(1),scs_m.props.options.ID(2)(2),10,1];
106
107     n=size(scs_m.objs);
108     for j=1:n //loop on objects
109         o=scs_m.objs(j);
110         if typeof(o)=="Block" then
111             omod=o.model;
112
113             // Clear the doc fields if it contains a function pointer
114             if type(o.doc) == 15 & size(o.doc) > 1 & (type(o.doc(1)) == 11 | type(o.doc(1)) == 13) then
115                 scs_m_new.objs(j).doc = list();
116             end
117
118             //@@ sbloc
119             if omod.sim=="super"|omod.sim=="csuper"|omod.sim(1)=="asuper" then
120                 rpar=do_version43(omod.rpar)
121                 scs_m_new.objs(j).model.rpar=rpar
122             end
123
124             //@@ Change gr_i of MUX if needed
125             if o.gui=="MUX" then
126                 gr_i=["txt=''Mux'';"
127                 "style=5;"
128                 "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
129                 "if ~exists(''%zoom'') then %zoom=1, end;"
130                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
131                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
132                 "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
133                 "e=gce();"
134                 "e.font_style=style;"]
135                 id=o.graphics.id
136                 if id=="Mux" then id="",end
137                 scs_m_new.objs(j).graphics.id=id
138                 if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
139                     if scs_m_new.objs(j).graphics.gr_i(1) == " " then
140                         scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
141                     end
142                 else
143                     if scs_m_new.objs(j).graphics.gr_i == " " then
144                         scs_m_new.objs(j).graphics.gr_i=gr_i
145                     end
146                 end
147
148                 //@@ Change gr_i of DEMUX if needed
149             elseif o.gui=="DEMUX" then
150                 gr_i=["txt=''Demux'';"
151                 "style=5;"
152                 "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
153                 "if ~exists(''%zoom'') then %zoom=1, end;"
154                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
155                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
156                 "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
157                 "e=gce();"
158                 "e.font_style=style;"]
159                 id=o.graphics.id
160                 if id=="Demux" then id="",end
161                 scs_m_new.objs(j).graphics.id=id
162                 if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
163                     if scs_m_new.objs(j).graphics.gr_i(1) == "" then
164                         scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
165                     end
166                 else
167                     if scs_m_new.objs(j).graphics.gr_i == "" then
168                         scs_m_new.objs(j).graphics.gr_i=gr_i
169                     end
170                 end
171
172                 //@@ Change gr_i of FROMWSB
173             elseif o.gui=="FROMWSB" then
174                 gr_i=["xstringb(orig(1),orig(2),''From workspace'',sz(1),sz(2),''fill'')"
175                 "txt=varnam;"
176                 "style=5;"
177                 "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
178                 "if ~exists(''%zoom'') then %zoom=1, end;"
179                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
180                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
181                 "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
182                 "e=gce();"
183                 "e.font_style=style;"]
184                 id=""
185                 scs_m_new.objs(j).graphics.id=id
186                 if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
187                     scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
188                 else
189                     scs_m_new.objs(j).graphics.gr_i=gr_i
190                 end
191
192                 //@@ Change gr_i of TOWS_c
193             elseif o.gui=="TOWS_c" then
194                 gr_i=["xstringb(orig(1),orig(2),''To workspace'',sz(1),sz(2),''fill'')"
195                 "txt=varnam;"
196                 "style=5;"
197                 "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
198                 "if ~exists(''%zoom'') then %zoom=1, end;"
199                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
200                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
201                 "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
202                 "e=gce();"
203                 "e.font_style=style;"]
204                 id=""
205                 scs_m_new.objs(j).graphics.id=id
206                 if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
207                     scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
208                 else
209                     scs_m_new.objs(j).graphics.gr_i=gr_i
210                 end
211
212                 //@@ Change gr_i of INTEGRAL_m if needed
213             elseif o.gui=="INTEGRAL_m" | o.gui=="INTEGRAL" then
214                 gr_i=["thick=xget(''thickness'')"
215                 "pat=xget(''pattern'')"
216                 "fnt=xget(''font'')"
217                 "xpoly(orig(1)+[0.7;0.62;0.549;0.44;0.364;0.291]*sz(1),orig(2)+[0.947;0.947;0.884;0.321;0.255;0.255]*sz(2),"'lines"')"
218                 "txt=''1/s'';"
219                 "style=5;"
220                 "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
221                 "if ~exists(''%zoom'') then %zoom=1, end;"
222                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
223                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
224                 "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
225                 "e=gce();"
226                 "e.font_style=style;"
227                 "xset(''thickness'',thick)"
228                 "xset(''pattern'',pat)"
229                 "xset(''font'',fnt(1),fnt(2))"]
230                 old_gri=["thick=xget(''thickness'')"
231                 "pat=xget(''pattern'')"
232                 "fnt=xget(''font'')"
233                 "xpoly(orig(1)+[0.7;0.62;0.549;0.44;0.364;0.291]*sz(1),orig(2)+[0.947;0.947;0.884;0.321;0.255;0.255]*sz(2),"'lines"')"
234                 "xset(''thickness'',thick)"
235                 "xset(''pattern'',pat)"
236                 "xset(''font'',fnt(1),fnt(2))"
237                 ]
238                 id=o.graphics.id
239                 if id=="1/s" then id="",end
240                 scs_m_new.objs(j).graphics.id=id
241                 if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
242                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
243                         scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
244                     end
245                 else
246                     if scs_m_new.objs(j).graphics.gr_i == old_gri then
247                         scs_m_new.objs(j).graphics.gr_i=gr_i
248                     end
249                 end
250
251                 //@@ Change gr_i of PRODUCT if needed
252             elseif o.gui=="PRODUCT" then
253                 gr_i=["[x,y,typ]=standard_inputs(o) ";
254                 "dd=sz(1)/8,de=0,"
255                 "if ~arg1.graphics.flip then dd=6*sz(1)/8,de=-sz(1)/8,end"
256                 "for k=1:size(x,''*'')";
257                 "if size(sgn,1)>1 then"
258                 "  if sgn(k)>0 then";
259                 "    xstring(orig(1)+dd,y(k)-4,''*'')";
260                 "  else";
261                 "    xstring(orig(1)+dd,y(k)-4,''/'')";
262                 "  end";
263                 "end";
264                 "end";
265                 "xx=sz(1)*[.8 .8 .4  .4]+orig(1)+de";
266                 "yy=sz(2)*[.2 .8 .8  .2]+orig(2)";
267                 "xpoly(xx,yy,''lines'')"
268                 "txt=''Product'';"
269                 "style=5;"
270                 "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
271                 "if ~exists(''%zoom'') then %zoom=1, end;"
272                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
273                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
274                 "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
275                 "e=gce();"
276                 "e.font_style=style;"]
277                 old_gri=["[x,y,typ]=standard_inputs(o) ";
278                 "dd=sz(1)/8,de=0,"
279                 "if ~arg1.graphics.flip then dd=6*sz(1)/8,de=-sz(1)/8,end"
280                 "for k=1:size(x,''*'')";
281                 "if size(sgn,1)>1 then"
282                 "  if sgn(k)>0 then";
283                 "    xstring(orig(1)+dd,y(k)-4,''*'')";
284                 "  else";
285                 "    xstring(orig(1)+dd,y(k)-4,''/'')";
286                 "  end";
287                 "end";
288                 "end";
289                 "xx=sz(1)*[.8 .8 .4  .4]+orig(1)+de";
290                 "yy=sz(2)*[.2 .8 .8  .2]+orig(2)";
291                 "xpoly(xx,yy,''lines'')"]
292                 id=o.graphics.id
293                 if id=="1/s" then id="",end
294                 scs_m_new.objs(j).graphics.id=id
295                 if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
296                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
297                         scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
298                     end
299                 else
300                     if scs_m_new.objs(j).graphics.gr_i == old_gri then
301                         scs_m_new.objs(j).graphics.gr_i=gr_i
302                     end
303                 end
304
305                 //@@ Change gr_i of DERIV if needed
306             elseif o.gui=="DERIV" then
307                 gr_i=["xstringb(orig(1),orig(2),'' du/dt   '',sz(1),sz(2),''fill'');"
308                 "txt=''s'';"
309                 "style=5;"
310                 "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
311                 "if ~exists(''%zoom'') then %zoom=1, end;"
312                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
313                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
314                 "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
315                 "e=gce();"
316                 "e.font_style=style;"]
317                 old_gri=["xstringb(orig(1),orig(2),''  du/dt  '',sz(1),sz(2),''fill'');"]
318                 id=o.graphics.id
319                 if id=="s" then id="",end
320                 scs_m_new.objs(j).graphics.id=id
321                 if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
322                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
323                         scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
324                     end
325                 else
326                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
327                         scs_m_new.objs(j).graphics.gr_i=gr_i
328                     end
329                 end
330
331                 //@@ Change gr_i of JKFLIPFLOP if needed
332             elseif o.gui=="JKFLIPFLOP" then
333                 gr_i=["[x,y,typ]=standard_inputs(o) ";
334                 "dd=sz(1)/8,de=5.5*sz(1)/8";
335                 "txt=''J'';"
336                 "if ~exists(''%zoom'') then %zoom=1, end;"
337                 "rectstr=stringbox(txt,orig(1)+dd,y(1)-4,0,1,1);"
338                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
339                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
340                 "xstringb(orig(1)+dd,y(1)-4,txt,w,h,''fill'')";
341                 "txt=''clk'';"
342                 "rectstr=stringbox(txt,orig(1)+dd,y(2)-4,0,1,1);"
343                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
344                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
345                 "xstringb(orig(1)+dd,y(2)-4,txt,w,h,''fill'')";
346                 "txt=''K'';"
347                 "rectstr=stringbox(txt,orig(1)+dd,y(3)-4,0,1,1);"
348                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
349                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
350                 "xstringb(orig(1)+dd,y(3)-4,txt,w,h,''fill'')";
351                 "[x,y,typ]=standard_outputs(o) ";
352                 "txt=''Q'';"
353                 "rectstr=stringbox(txt,orig(1)+de,y(1)-4,0,1,1);"
354                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
355                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
356                 "xstringb(orig(1)+de,y(1)-4,txt,w,h,''fill'')";
357                 "txt=''!Q'';"
358                 "rectstr=stringbox(txt,orig(1)+4.5*dd,y(2)-4,0,1,1);"
359                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
360                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
361                 "xstringb(orig(1)+4.5*dd,y(2)-4,txt,w,h,''fill'')";
362                 "txt=''JK FLIP-FLOP'';"
363                 "style=5;"
364                 "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
365                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
366                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
367                 "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
368                 "e=gce();"
369                 "e.font_style=style;"]
370                 old_gri=["[x,y,typ]=standard_inputs(o) ";
371                 "dd=sz(1)/8,de=6*sz(1)/8";
372                 "xstring(orig(1)+dd,y(1)-4,''J'')";
373                 "xstring(orig(1)+dd,y(2)-4,''clk'')";
374                 "xstring(orig(1)+dd,y(3)-4,''K'')";
375                 "[x,y,typ]=standard_outputs(o) ";
376                 "xstring(orig(1)+de,y(1)-4,''Q'')";
377                 "xstring(orig(1)+5*dd,y(2)-4,''!Q'')"]
378                 id=o.graphics.id
379                 if id=="JK FLIP-FLOP" then id="",end
380                 scs_m_new.objs(j).graphics.id=id
381                 if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
382                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
383                         scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
384                     end
385                 else
386                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
387                         scs_m_new.objs(j).graphics.gr_i=gr_i
388                     end
389                 end
390
391                 //@@ Change gr_i of SRFLIPFLOP if needed
392             elseif o.gui=="SRFLIPFLOP" then
393                 gr_i=["[x,y,typ]=standard_inputs(o) ";
394                 "dd=sz(1)/8,de=5.5*sz(1)/8";
395                 "txt=''S'';"
396                 "if ~exists(''%zoom'') then %zoom=1, end;"
397                 "rectstr=stringbox(txt,orig(1)+dd,y(1)-4,0,1,1);"
398                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
399                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
400                 "xstringb(orig(1)+dd,y(1)-4,txt,w,h,''fill'')";
401                 "txt=''R'';"
402                 "rectstr=stringbox(txt,orig(1)+dd,y(2)-4,0,1,1);"
403                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
404                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
405                 "xstringb(orig(1)+dd,y(2)-4,txt,w,h,''fill'')";
406                 "[x,y,typ]=standard_outputs(o) ";
407                 "txt=''Q'';"
408                 "rectstr=stringbox(txt,orig(1)+de,y(1)-4,0,1,1);"
409                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
410                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
411                 "xstringb(orig(1)+de,y(1)-4,txt,w,h,''fill'')";
412                 "txt=''!Q'';"
413                 "rectstr=stringbox(txt,orig(1)+4.5*dd,y(2)-4,0,1,1);"
414                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
415                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
416                 "xstringb(orig(1)+4.5*dd,y(2)-4,txt,w,h,''fill'')";
417                 "txt=''SR FLIP-FLOP'';"
418                 "style=5;"
419                 "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
420                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
421                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
422                 "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
423                 "e=gce();"
424                 "e.font_style=style;"]
425                 old_gri=["[x,y,typ]=standard_inputs(o) ";
426                 "dd=sz(1)/8,de=6*sz(1)/8";
427                 "xstring(orig(1)+dd,y(1)-4,''S'')";
428                 "xstring(orig(1)+dd,y(2)-4,''R'')";
429                 "[x,y,typ]=standard_outputs(o) ";
430                 "xstring(orig(1)+de,y(1)-4,''Q'')";
431                 "xstring(orig(1)+5*dd,y(2)-4,''!Q'')"]
432                 id=o.graphics.id
433                 if id=="SR FLIP-FLOP" then id="",end
434                 scs_m_new.objs(j).graphics.id=id
435                 if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
436                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
437                         scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
438                     end
439                 else
440                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
441                         scs_m_new.objs(j).graphics.gr_i=gr_i
442                     end
443                 end
444
445                 //@@ Change gr_i of DLATCH if needed
446             elseif o.gui=="DLATCH" then
447                 gr_i=["[x,y,typ]=standard_inputs(o) ";
448                 "dd=sz(1)/8,de=5.5*sz(1)/8";
449                 "txt=''D'';"
450                 "if ~exists(''%zoom'') then %zoom=1, end;"
451                 "rectstr=stringbox(txt,orig(1)+dd,y(1)-4,0,1,1);"
452                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
453                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
454                 "xstringb(orig(1)+dd,y(1)-4,txt,w,h,''fill'')";
455                 "txt=''C'';"
456                 "rectstr=stringbox(txt,orig(1)+dd,y(2)-4,0,1,1);"
457                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
458                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
459                 "xstringb(orig(1)+dd,y(2)-4,txt,w,h,''fill'')";
460                 "txt=''Q'';"
461                 "rectstr=stringbox(txt,orig(1)+de,y(1)-4,0,1,1);"
462                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
463                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
464                 "xstringb(orig(1)+de,y(1)-4,txt,w,h,''fill'')";
465                 "txt=''!Q'';"
466                 "rectstr=stringbox(txt,orig(1)+4.5*dd,y(2)-4,0,1,1);"
467                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
468                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
469                 "xstringb(orig(1)+4.5*dd,y(2)-4,txt,w,h,''fill'')";
470                 "txt=''DLATCH'';"
471                 "style=5;"
472                 "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
473                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
474                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
475                 "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
476                 "e=gce();"
477                 "e.font_style=style;"]
478                 old_gri=["[x,y,typ]=standard_inputs(o) ";
479                 "dd=sz(1)/8,de=6*sz(1)/8";
480                 "xstring(orig(1)+dd,y(1)-4,''D'')";
481                 "xstring(orig(1)+dd,y(2)-4,''C'')";
482                 "xstring(orig(1)+de,y(1)-4,''Q'')";
483                 "xstring(orig(1)+5*dd,y(2)-4,''!Q'')"]
484                 id=o.graphics.id
485                 if id=="DLATCH" then id="",end
486                 scs_m_new.objs(j).graphics.id=id
487                 if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
488                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
489                         scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
490                     end
491                 else
492                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
493                         scs_m_new.objs(j).graphics.gr_i=gr_i
494                     end
495                 end
496
497                 //@@ Change gr_i of DFLIPFLOP if needed
498             elseif o.gui=="DFLIPFLOP" then
499                 gr_i=["[x,y,typ]=standard_inputs(o) ";
500                 "dd=sz(1)/8,de=5.5*sz(1)/8";
501                 "txt=''D'';"
502                 "if ~exists(''%zoom'') then %zoom=1, end;"
503                 "rectstr=stringbox(txt,orig(1)+dd,y(1)-4,0,1,1);"
504                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
505                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
506                 "xstringb(orig(1)+dd,y(1)-4,txt,w,h,''fill'')";
507                 "txt=''clk'';"
508                 "rectstr=stringbox(txt,orig(1)+dd,y(2)-4,0,1,1);"
509                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
510                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
511                 "xstringb(orig(1)+dd,y(2)-4,txt,w,h,''fill'')";
512                 "txt=''en'';"
513                 "rectstr=stringbox(txt,orig(1)+dd,y(3)-4,0,1,1);"
514                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
515                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
516                 "xstringb(orig(1)+dd,y(3)-4,txt,w,h,''fill'')";
517                 "[x,y,typ]=standard_outputs(o) ";
518                 "txt=''Q'';"
519                 "rectstr=stringbox(txt,orig(1)+de,y(1)-4,0,1,1);"
520                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
521                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
522                 "xstringb(orig(1)+de,y(1)-4,txt,w,h,''fill'')";
523                 "txt=''!Q'';"
524                 "rectstr=stringbox(txt,orig(1)+4.5*dd,y(2)-4,0,1,1);"
525                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
526                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
527                 "xstringb(orig(1)+4.5*dd,y(2)-4,txt,w,h,''fill'')";
528                 "txt=''D FLIP-FLOP'';"
529                 "style=5;"
530                 "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
531                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
532                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
533                 "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
534                 "e=gce();"
535                 "e.font_style=style;"]
536                 old_gri=["[x,y,typ]=standard_inputs(o) ";
537                 "dd=sz(1)/8,de=6*sz(1)/8";
538                 "xstring(orig(1)+dd,y(1)-4,''D'')";
539                 "xstring(orig(1)+dd,y(2)-4,''clk'')";
540                 "xstring(orig(1)+dd,y(3)-4,''en'')";
541                 "[x,y,typ]=standard_outputs(o) ";
542                 "xstring(orig(1)+de,y(1)-4,''Q'')";
543                 "xstring(orig(1)+5*dd,y(2)-4,''!Q'')"]
544                 id=o.graphics.id
545                 if id=="D FLIP-FLOP" then id="",end
546                 scs_m_new.objs(j).graphics.id=id
547                 if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
548                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
549                         scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
550                     end
551                 else
552                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
553                         scs_m_new.objs(j).graphics.gr_i=gr_i
554                     end
555                 end
556
557                 //@@ Change gr_i of CLKGotoTagVisibility if needed
558             elseif o.gui=="CLKGotoTagVisibility" then
559                 gr_i=["xstringb(orig(1),orig(2),[''{''+arg1.graphics.exprs(1)+''}''],sz(1),sz(2),''fill'');";
560                 "wd=xget(''wdim'').*[1.016,1.12];";
561                 "thick=xget(''thickness'');xset(''thickness'',2);";
562                 "p=wd(2)/wd(1);p=1;";
563                 "xarcs([orig(1)+0.05*sz(1);";
564                 "orig(2)+0.95*sz(2);";
565                 "0.9*sz(1)*p;";
566                 "0.9*sz(2);";
567                 "0;";
568                 "360*64],scs_color(5));";
569                 "txt=[''Goto Tag'';''Visibility'' ];"
570                 "style=5;"
571                 "gh_axes = gca();"
572                 "axes_font_style = gh_axes.font_style ;"
573                 "axes_font_size  = gh_axes.font_size  ;"
574                 "gh_axes.font_style = 5;"
575                 "gh_axes.font_size  = 1;"
576                 "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
577                 "if ~exists(''%zoom'') then %zoom=1, end;"
578                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
579                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
580                 "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-5,txt,w,h,''fill'');"
581                 "gh_axes.font_style = axes_font_style ;"
582                 "gh_axes.font_size  = axes_font_size  ;"
583                 "xset(''thickness'',thick)"]
584                 old_gri=["xstringb(orig(1),orig(2),[''{''+arg1.graphics.exprs(1)+''}''],sz(1),sz(2),''fill'');";
585                 "wd=xget(''wdim'').*[1.016,1.12];";
586                 "thick=xget(''thickness'');xset(''thickness'',2);";
587                 "p=wd(2)/wd(1);p=1;";
588                 "xarcs([orig(1)+0.05*sz(1);";
589                 "orig(2)+0.95*sz(2);";
590                 "0.9*sz(1)*p;";
591                 "0.9*sz(2);";
592                 "0;";
593                 "360*64],scs_color(5));";
594                 "xset(''thickness'',thick)"]
595                 id=o.graphics.id
596                 if id==["Goto Tag";"Visibility"] then id="",end
597                 scs_m_new.objs(j).graphics.id=id
598                 if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
599                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
600                         scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
601                     end
602                 else
603                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
604                         scs_m_new.objs(j).graphics.gr_i=gr_i
605                     end
606                 end
607
608                 //@@ Change gr_i of GotoTagVisibilityMO if needed
609             elseif o.gui=="GotoTagVisibilityMO" then
610                 gr_i=["xstringb(orig(1),orig(2),[''{''+arg1.graphics.exprs(1)+''}''],sz(1),sz(2),''fill'');";
611                 "wd=xget(''wdim'').*[1.016,1.12];";
612                 "thick=xget(''thickness'');xset(''thickness'',2);";
613                 "p=wd(2)/wd(1);p=1;";
614                 "xarcs([orig(1)+0.05*sz(1);";
615                 "orig(2)+0.95*sz(2);";
616                 "0.9*sz(1)*p;";
617                 "0.9*sz(2);";
618                 "0;";
619                 "360*64],scs_color(3));";
620                 "txt=[''Goto Tag'';''Visibility'' ];"
621                 "style=5;"
622                 "gh_axes = gca();"
623                 "axes_font_style = gh_axes.font_style ;"
624                 "axes_font_size  = gh_axes.font_size  ;"
625                 "gh_axes.font_style = 5;"
626                 "gh_axes.font_size  = 1;"
627                 "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
628                 "if ~exists(''%zoom'') then %zoom=1, end;"
629                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
630                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
631                 "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-5,txt,w,h,''fill'');"
632                 "gh_axes.font_style = axes_font_style ;"
633                 "gh_axes.font_size  = axes_font_size  ;"
634                 "xset(''thickness'',thick)"]
635                 old_gri=["xstringb(orig(1),orig(2),[''{''+arg1.graphics.exprs(1)+''}''],sz(1),sz(2),''fill'');";
636                 "wd=xget(''wdim'').*[1.016,1.12];";
637                 "thick=xget(''thickness'');xset(''thickness'',2);";
638                 "p=wd(2)/wd(1);p=1;";
639                 "xarcs([orig(1)+0.05*sz(1);";
640                 "orig(2)+0.95*sz(2);";
641                 "0.9*sz(1)*p;";
642                 "0.9*sz(2);";
643                 "0;";
644                 "360*64],scs_color(3));";
645                 "xset(''thickness'',thick)"]
646                 id=o.graphics.id
647                 if id==["Goto Tag";"Visibility"] then id="",end
648                 scs_m_new.objs(j).graphics.id=id
649                 if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
650                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
651                         scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
652                     end
653                 else
654                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
655                         scs_m_new.objs(j).graphics.gr_i=gr_i
656                     end
657                 end
658
659                 //@@ Change gr_i of GotoTagVisibility if needed
660             elseif o.gui=="GotoTagVisibility" then
661                 gr_i=["xstringb(orig(1),orig(2),[''{''+arg1.graphics.exprs(1)+''}''],sz(1),sz(2),''fill'');"
662                 "txt=[''Goto Tag'';''Visibility'' ];"
663                 "style=5;"
664                 "gh_axes = gca();"
665                 "axes_font_style = gh_axes.font_style ;"
666                 "axes_font_size  = gh_axes.font_size  ;"
667                 "gh_axes.font_style = 5;"
668                 "gh_axes.font_size  = 1;"
669                 "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
670                 "if ~exists(''%zoom'') then %zoom=1, end;"
671                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
672                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
673                 "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-5,txt,w,h,''fill'');"
674                 "gh_axes.font_style = axes_font_style ;"
675                 "gh_axes.font_size  = axes_font_size  ;"]
676                 old_gri=["xstringb(orig(1),orig(2),[''{''+arg1.graphics.exprs(1)+''}''],sz(1),sz(2),''fill'');"]
677                 id=o.graphics.id
678                 if id==["Goto Tag";"Visibility"] then id="",end
679                 scs_m_new.objs(j).graphics.id=id
680                 if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
681                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
682                         scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
683                     end
684                 else
685                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
686                         scs_m_new.objs(j).graphics.gr_i=gr_i
687                     end
688                 end
689
690                 //@@ Change gr_i of Inductor if needed
691             elseif o.gui=="Inductor" then
692                 gr_i=["tt=linspace(0.04,0.96,100)'';"
693                 "xpoly(tt*sz(1)+orig(1),+orig(2)+abs(sin(18*(tt-0.04)))*sz(2),""lines"");";
694                 "xx=orig(1)+[0 0.04 0.04 0.04 0]*sz(1);";
695                 "yy=orig(2)+[1/2 1/2 0  1/2 1/2]*sz(2);";
696                 "xpoly(xx,yy) ";
697                 "xx=orig(1)+[0.96 0.96 1   0.96 0.96 ]*sz(1);";
698                 "yy=orig(2)+[abs(sin(18*0.92))   1/2   1/2 1/2 abs(sin(18*0.92))]*sz(2);";
699                 "xpoly(xx,yy) ";
700                 "txt=''L= ''+L;"
701                 "style=2;"
702                 "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
703                 "if ~exists(''%zoom'') then %zoom=1, end;"
704                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
705                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
706                 "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
707                 "e=gce();"]
708                 old_gri=["tt=linspace(0.04,0.96,100)'';"
709                 "xpoly(tt*sz(1)+orig(1),+orig(2)+abs(sin(18*(tt-0.04)))*sz(2),""lines"");";
710                 "xx=orig(1)+[0 0.04 0.04 0.04 0]*sz(1);";
711                 "yy=orig(2)+[1/2 1/2 0  1/2 1/2]*sz(2);";
712                 "xpoly(xx,yy) ";
713                 "xx=orig(1)+[0.96 0.96 1   0.96 0.96 ]*sz(1);";
714                 "yy=orig(2)+[abs(sin(18*0.92))   1/2   1/2 1/2 abs(sin(18*0.92))]*sz(2);";
715                 "xpoly(xx,yy) ";
716                 "rect=xstringl(0,0,''L=''+L)"
717                 "xstring(orig(1)+(sz(1)-rect(3))/2,orig(2)-rect(4)*1.2,''L=''+L)"]
718                 if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
719                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
720                         scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
721                     end
722                 else
723                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
724                         scs_m_new.objs(j).graphics.gr_i=gr_i
725                     end
726                 end
727
728                 //@@ Change gr_i of Capacitor if needed
729             elseif o.gui=="Capacitor" then
730                 gr_i=["xset(''thickness'',2)"
731                 "xx=orig(1)+[0 1/3 1/3 1/3 ]*sz(1);";
732                 "yy=orig(2)+[1/2 1/2 1 0]*sz(2);";
733                 "xpoly(xx,yy);"
734                 "xsegs(orig(1)+ sz(1)*2/3*[1 1 1 3/2],orig(2)+(sz(2)*1/2)*[2 0 1 1],0);";
735                 "if orient then"
736                 "  xrects([orig(1)+sz(1)*1/2;orig(2)+sz(2);sz(1)*1/6;sz(2)],scs_color(33));"
737                 "  xstring(orig(1)+sz(1)*1/12,orig(2)+sz(2)*3/4,''+'');";
738                 "  xstring(orig(1)+sz(1)*7/8,orig(2)+sz(2)*3/4,''-'');";
739                 "else"
740                 "  xrects([orig(1)+sz(1)*1/3;orig(2)+sz(2);sz(1)*1/6;sz(2)],scs_color(33));"
741                 "  xstring(orig(1)+sz(1)*1/12,orig(2)+sz(2)*3/4,''-'');";
742                 "  xstring(orig(1)+sz(1)*7/8,orig(2)+sz(2)*3/4,''+'');";
743                 "end"
744                 "txt=''C= ''+C;"
745                 "style=2;"
746                 "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
747                 "if ~exists(''%zoom'') then %zoom=1, end;"
748                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
749                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
750                 "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
751                 "e=gce();"
752                 "e.font_style=style;"]
753                 old_gri=["xset(''thickness'',2)"
754                 "xx=orig(1)+[0 1/3 1/3 1/3 ]*sz(1);";
755                 "yy=orig(2)+[1/2 1/2 1 0]*sz(2);";
756                 "xpoly(xx,yy);"
757                 "xsegs(orig(1)+ sz(1)*2/3*[1 1 1 3/2],orig(2)+(sz(2)*1/2)*[2 0 1 1],0);";
758                 "if orient then"
759                 "  xrects([orig(1)+sz(1)*1/2;orig(2)+sz(2);sz(1)*1/6;sz(2)],scs_color(33));"
760                 "  xstring(orig(1)+sz(1)*1/12,orig(2)+sz(2)*3/4,''+'');";
761                 "  xstring(orig(1)+sz(1)*7/8,orig(2)+sz(2)*3/4,''-'');";
762                 "else"
763                 "  xrects([orig(1)+sz(1)*1/3;orig(2)+sz(2);sz(1)*1/6;sz(2)],scs_color(33));"
764                 "  xstring(orig(1)+sz(1)*1/12,orig(2)+sz(2)*3/4,''-'');";
765                 "  xstring(orig(1)+sz(1)*7/8,orig(2)+sz(2)*3/4,''+'');";
766                 "end"
767                 "rect=xstringl(0,0,''C=''+C)"
768                 "xstring(orig(1)+(sz(1)-rect(3))/2,orig(2)-rect(4)*1.2,''C= ''+C);"]
769                 if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
770                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
771                         scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
772                     end
773                 else
774                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
775                         scs_m_new.objs(j).graphics.gr_i=gr_i
776                     end
777                 end
778
779                 //@@ Change gr_i of Resistor if needed
780             elseif o.gui=="Resistor" then
781                 gr_i=["xx=[0,1,1,7,7,8,7,7,1,1]/8;";
782                 "yy=[1,1,0,0,1,1,1,2,2,1]/2;";
783                 "xpoly(orig(1)+xx*sz(1),orig(2)+yy*sz(2)); "
784                 "txt=''R= ''+R;"
785                 "style=2;"
786                 "rectstr=stringbox(txt,orig(1),orig(2),0,style,1);"
787                 "if ~exists(''%zoom'') then %zoom=1, end;"
788                 "w=(rectstr(1,3)-rectstr(1,2))*%zoom;"
789                 "h=(rectstr(2,2)-rectstr(2,4))*%zoom;"
790                 "xstringb(orig(1)+sz(1)/2-w/2,orig(2)-h-4,txt,w,h,''fill'');"
791                 "e=gce();"]
792                 old_gri=["xx=[0,1,1,7,7,8,7,7,1,1]/8;";
793                 "yy=[1,1,0,0,1,1,1,2,2,1]/2;";
794                 "xpoly(orig(1)+xx*sz(1),orig(2)+yy*sz(2)); "
795                 "rect=xstringl(0,0,''R=''+R)"
796                 "xstring(orig(1)+(sz(1)-rect(3))/2,orig(2)-rect(4)*1.2,''R=''+R);"]
797                 if (type(scs_m_new.objs(j).graphics.gr_i)==15) then
798                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
799                         scs_m_new.objs(j).graphics.gr_i=list(gr_i,scs_m_new.objs(j).graphics.gr_i(2))
800                     end
801                 else
802                     if scs_m_new.objs(j).graphics.gr_i(1) == old_gri then
803                         scs_m_new.objs(j).graphics.gr_i=gr_i
804                     end
805                 end
806
807             end
808         end
809     end
810 endfunction
811
812
813 //*** update scope ***//
814 function scs_m_new=do_version42(scs_m)
815     scs_m_new=scs_m
816     n=size(scs_m.objs);
817     for j=1:n //loop on objects
818         o=scs_m.objs(j);
819         if typeof(o)=="Block" then
820             omod=o.model;
821             //SUPER BLOCK
822             if omod.sim=="super"|omod.sim=="csuper" then
823                 rpar=do_version42(omod.rpar)
824                 scs_m_new.objs(j).model.rpar=rpar
825                 //name of gui and sim list change
826             elseif o.gui=="SCOPE_f" then
827                 scs_m_new.objs(j).gui="CSCOPE"
828                 scs_m_new.objs(j).model.dstate=[]
829                 //Alan's patch 01/10/07 : remove the last parameter
830                 // (inheritance not used in cscope)
831                 ipar = scs_m_new.objs(j).model.ipar(:);
832                 scs_m_new.objs(j).model.ipar = ipar(1:$-1);
833                 scs_m_new.objs(j).model.sim=list("cscope", 4)
834                 in = scs_m_new.objs(j).model.in(:);
835                 a = size(in,1);
836                 in2 = ones(a,1);
837                 scs_m_new.objs(j).model.in2 = in2;
838                 scs_m_new.objs(j).model.intyp = in2;
839                 //Alan's patch 04/10/07 : update exprs
840                 exprs = scs_m.objs(j).graphics.exprs;
841                 if size(exprs)<9 then exprs(9)="0",end // compatibility
842                 if size(exprs)<10 then exprs(10)=emptystr(),end // compatibility
843                 scs_m_new.objs(j).graphics.exprs=exprs;
844             elseif o.gui=="CSCOPE" then
845                 //Alan's patch 04/10/07 : update exprs
846                 exprs = scs_m.objs(j).graphics.exprs;
847                 if size(exprs)<10 then exprs(10)=emptystr(),end // compatibility
848                 scs_m_new.objs(j).graphics.exprs=exprs;
849             elseif o.gui=="BOUNCEXY" then
850                 in = scs_m_new.objs(j).model.in(:);
851                 a = size(in,1);
852                 in2 = ones(a,1);
853                 scs_m_new.objs(j).model.in2 = in2;
854                 scs_m_new.objs(j).model.intyp = in2;
855             elseif o.gui=="MSCOPE_f" then
856                 //Alan's patch 04/10/07 : update exprs
857                 exprs = scs_m.objs(j).graphics.exprs;
858                 if size(exprs)<10 then exprs(10)="0",end // compatibility
859                 if size(exprs)<11 then exprs(11)=emptystr(),end // compatibility
860                 scs_m_new.objs(j).graphics.exprs=exprs;
861                 scs_m_new.objs(j).gui="CMSCOPE"
862                 scs_m_new.objs(j).model.dstate=[]
863                 scs_m_new.objs(j).model.sim=list("cmscope", 4)
864                 in = scs_m_new.objs(j).model.in(:);
865                 a = size(in,1);
866                 B=stripblanks(scs_m.objs(j).graphics.exprs(8));
867                 B(1:a)=B;
868                 B = strcat(B', " ");
869                 scs_m_new.objs(j).graphics.exprs(8) = B;
870                 rpar=scs_m_new.objs(j).model.rpar(:);
871                 N=scs_m_new.objs(j).model.ipar(2);
872                 period = [];
873                 for i=1:N
874                     period(i)=rpar(2);
875                 end
876                 scs_m_new.objs(j).model.rpar = [rpar(1);period(:);rpar(3:size(rpar,1))]
877                 in2 = ones(a,1);
878                 scs_m_new.objs(j).model.in2 = in2;
879                 scs_m_new.objs(j).model.intyp = in2;
880             elseif o.gui=="ANIMXY_f" then
881                 scs_m_new.objs(j).gui="CANIMXY"
882                 scs_m_new.objs(j).model.dstate=[]
883                 scs_m_new.objs(j).model.sim=list("canimxy", 4)
884                 in = scs_m_new.objs(j).model.in(:);
885                 a = size(in,1);
886                 in2 = ones(a,1);
887                 scs_m_new.objs(j).model.in2 = in2;
888                 scs_m_new.objs(j).model.intyp = in2;
889                 scs_m_new.objs(j).graphics.exprs = [string(1);scs_m_new.objs(j).graphics.exprs(:)]
890                 scs_m_new.objs(j).model.ipar = [scs_m_new.objs(j).model.ipar(:);1]
891                 //Alan's patch 04/10/07 : update exprs
892                 exprs = scs_m_new.objs(j).graphics.exprs(:)
893                 if size(exprs,"*")==8 then exprs=[1;exprs(1:3);"[]";"[]";exprs(4:8)],end
894                 scs_m_new.objs(j).graphics.exprs=exprs;
895             elseif o.gui=="EVENTSCOPE_f" then
896                 scs_m_new.objs(j).gui="CEVENTSCOPE"
897                 scs_m_new.objs(j).model.dstate=[]
898                 scs_m_new.objs(j).model.sim=list("cevscpe", 4)
899                 in = scs_m_new.objs(j).model.in(:);
900                 a = size(in,1);
901                 in2 = ones(a,1);
902                 scs_m_new.objs(j).model.in2 = in2;
903                 scs_m_new.objs(j).model.intyp = in2;
904             elseif o.gui=="FSCOPE_f" then
905                 scs_m_new.objs(j).gui="CFSCOPE"
906                 scs_m_new.objs(j).model.dstate=[]
907                 scs_m_new.objs(j).model.sim=list("cfscope", 4)
908                 in = scs_m_new.objs(j).model.in(:);
909                 a = size(in,1);
910                 in2 = ones(a,1);
911                 scs_m_new.objs(j).model.in2 = in2;
912                 scs_m_new.objs(j).model.intyp = in2;
913                 //Alan's patch 04/10/07 : update exprs
914                 exprs = scs_m.objs(j).graphics.exprs;
915                 if size(exprs)<9 then exprs(9)="0",end // compatibility
916                 scs_m_new.objs(j).graphics.exprs=exprs;
917             elseif o.gui=="SCOPXY_f" then
918                 scs_m_new.objs(j).gui="CSCOPXY"
919                 scs_m_new.objs(j).model.dstate=[]
920                 scs_m_new.objs(j).model.sim=list("cscopxy", 4)
921                 in = scs_m_new.objs(j).model.in(:);
922                 a = size(in,1);
923                 in2 = ones(a,1);
924                 scs_m_new.objs(j).model.in2 = in2;
925                 scs_m_new.objs(j).model.intyp = in2;
926                 scs_m_new.objs(j).graphics.exprs = [string(1);scs_m_new.objs(j).graphics.exprs(:)]
927                 scs_m_new.objs(j).model.ipar = [scs_m_new.objs(j).model.ipar(:);1]
928             elseif o.gui=="CMSCOPE" then
929                 //Alan's patch 04/10/07 : update exprs
930                 exprs = scs_m.objs(j).graphics.exprs;
931                 if size(exprs)<11 then exprs(11)=emptystr(),end // compatibility
932                 scs_m_new.objs(j).graphics.exprs=exprs;
933                 scs_m_new.objs(j).model.dstate=[]
934                 in = scs_m_new.objs(j).model.in(:);
935                 a = size(in,1);
936                 B=stripblanks(scs_m.objs(j).graphics.exprs(8));
937                 B(1:a)=B;
938                 B = strcat(B', " ");
939                 scs_m_new.objs(j).graphics.exprs(8)=B;
940                 rpar=scs_m_new.objs(j).model.rpar(:);
941                 N=scs_m_new.objs(j).model.ipar(2);
942                 period = [];
943                 for i=1:N
944                     period(i)=rpar(2);
945                 end
946                 scs_m_new.objs(j).model.rpar = [rpar(1);period(:);rpar(3:size(rpar,1))]
947                 in2 = ones(a,1);
948                 scs_m_new.objs(j).model.in2 = in2;
949                 scs_m_new.objs(j).model.intyp = in2;
950             elseif o.gui=="IN_f" then
951                 scs_m_new.objs(j).model.out    = -1;
952                 scs_m_new.objs(j).model.out2   = -2;
953                 scs_m_new.objs(j).model.outtyp = -1;
954             elseif o.gui=="OUT_f" then
955                 scs_m_new.objs(j).model.in    = -1;
956                 scs_m_new.objs(j).model.in2   = -2;
957                 scs_m_new.objs(j).model.intyp = -1;
958             elseif o.gui=="INIMPL_f" then
959                 scs_m_new.objs(j).model.out    = -1;
960                 scs_m_new.objs(j).model.out2   = 1;
961                 scs_m_new.objs(j).model.outtyp = -1;
962             elseif o.gui=="OUTIMPL_f" then
963                 scs_m_new.objs(j).model.in    = -1;
964                 scs_m_new.objs(j).model.in2   = 1;
965                 scs_m_new.objs(j).model.intyp = -1;
966             end
967         end
968     end
969 endfunction
970
971 function scs_m_new=do_version273(scs_m)
972     scs_m_new=scs_m;
973     n=size(scs_m.objs);
974     for i=1:n //loop on objects
975         o=scs_m.objs(i);
976         if typeof(o)=="Block" then
977             omod=o.model;
978             T=getfield(1,omod)
979             if T($)<>"equations" then
980                 T($+1)="equations"
981                 scicos_setfield(1,T,omod)
982                 scicos_setfield($+1,list(),omod)
983             end
984             if omod.sim=="super"|omod.sim=="csuper" then
985                 rpar=do_version273(omod.rpar)
986                 scicos_setfield($+1,getfield($,omod),omod)
987                 scicos_setfield($-1,0,omod)
988                 omod.rpar=rpar
989             elseif omod.sim(1)=="ifthel" then // |omod.sim(1)=='eselect' then
990                 scicos_setfield($+1,getfield($,omod),omod)
991                 scicos_setfield($-1,1,omod)
992                 scicos_setfield($-2,1,omod)
993             else
994                 scicos_setfield($+1,getfield($,omod),omod)
995                 scicos_setfield($-1,0,omod)
996             end
997             xx=getfield(1,omod);
998             yy=xx($);
999             xx($)="nmode"
1000             xx($+1)=yy;
1001             scicos_setfield(1,xx,omod)
1002             o.model= omod
1003             scs_m_new.objs(i)=o
1004         elseif typeof(o)=="Link" then
1005             if size(o.from,"*")==2 then o.from(3)=0;end
1006             if size(o.to,"*")==2 then o.to(3)=1;end
1007             scs_m_new.objs(i)=o
1008         end
1009     end
1010 endfunction
1011
1012
1013 function scs_m_new=do_version272(scs_m)
1014
1015     scs_m_new=scs_m
1016     for i=1:lstsize(scs_m.objs)
1017
1018         if typeof(scs_m.objs(i))=="Block" then
1019             grphic=scs_m.objs(i).graphics
1020             chmps=size(getfield(1,grphic))
1021             if or(getfield(1,grphic)=="in_implicit")&..
1022                 size(grphic.in_implicit,"*")==size(grphic.pin,"*") then
1023                 in_implicit=grphic.in_implicit
1024             else
1025                 I="E";
1026                 in_implicit=I(ones(grphic.pin(:)));
1027             end
1028
1029             if or(getfield(1,grphic)=="out_implicit")&..
1030                 size(grphic.out_implicit,"*")==size(grphic.pout,"*") then
1031                 out_implicit=grphic.out_implicit
1032             else
1033                 I="E";
1034                 out_implicit=I(ones(grphic.pout(:)));
1035             end
1036
1037             scs_m_new.objs(i).graphics=scicos_new(["graphics","orig","sz","flip","exprs","pin",..
1038             "pout","pein","peout","gr_i","id","in_implicit","out_implicit"],..
1039             grphic.orig,grphic.sz,grphic.flip,grphic.exprs,grphic.pin,..
1040             grphic.pout,grphic.pein,grphic.peout,grphic.gr_i,grphic.id,..
1041             in_implicit,out_implicit)
1042
1043             if or(scs_m_new.objs(i).model.sim==["super","csuper"]) then
1044                 rpar=do_version272(scs_m_new.objs(i).model.rpar)
1045                 scs_m_new.objs(i).model.rpar=rpar
1046             end
1047         end
1048     end
1049 endfunction
1050
1051 function scs_m_new=do_version271(scs_m)
1052     scs_m_new=scs_m;
1053     n=size(scs_m.objs);
1054     for i=1:n //loop on objects
1055         o=scs_m.objs(i);
1056         if typeof(o)=="Block" then
1057             omod=o.model;
1058             if omod.sim=="super"|omod.sim=="csuper" then
1059                 rpar=do_version271(omod.rpar)
1060                 scicos_setfield($+1,0,omod)
1061                 omod.rpar=rpar
1062             elseif omod.sim=="zcross" then
1063                 scicos_setfield($+1,omod.in,omod)
1064                 omod.sim=list(omod.sim,1)
1065             elseif omod.sim=="lusat" then
1066                 scicos_setfield($+1,2*omod.in,omod)
1067                 omod.sim=list(omod.sim,1)
1068             else
1069                 scicos_setfield($+1,0,omod)
1070             end
1071             scicos_setfield(1,[getfield(1,omod),"nzcross"],omod)
1072             o.model= omod
1073             scs_m_new.objs(i)=o
1074         end
1075     end
1076 endfunction
1077
1078 function scs_m=do_version251(scs_m)
1079     nx=size(scs_m)
1080     obsolete=%f
1081     for k=2:nx
1082         o=scs_m(k)
1083         if o(1)=="Block" then
1084             model=o(3)
1085             if model(1)=="super"|model(1)=="csuper" then
1086                 model(8)=do_version251(model(8))
1087                 o(3)=model
1088                 scs_m(k)=o
1089             elseif o(5)=="SOM_f" then
1090                 if and(model(8)==1) then
1091                     model(8)=[]
1092                     model(1)=list("plusblk",2)
1093                     scs_m(k)(3)=model
1094                     scs_m(k)(5)="SUM_f"
1095                 else
1096                     scs_m(k)(3)(1)=list("sum",2)
1097                     obsolete=%t
1098                 end
1099             elseif o(5)=="AFFICH_f" then
1100                 scs_m(k)(3)(7)=[0;-1;0;0;1;1]
1101                 scs_m(k)(2)(9)=["xset(''font'',ipar(1),ipar(2))";
1102                 "str='' ''+part(''0'',ones(1,ipar(5)-ipar(6)-2))+''.''+part(''0'',ones(1,ipar(6)))"
1103                 "rr=xstringl(orig(1),orig(2),str)"
1104                 "xstring(orig(1)+max(0,(sz(1)-rr(3))/2),orig(2)+max(0,(sz(2)-rr(4))/2),str)"]
1105             elseif o(5)=="c_block" then
1106                 model(1)(2)=model(1)(2)-int(model(1)(2)/1000)*1000+2000
1107                 scs_m(k)(3)=model
1108                 tt=scs_m(k)(2)(4)(2)
1109                 ii=grep(tt,"machine.h")
1110                 if size(ii,"*")==1 then
1111                     tt(ii)="#include <machine.h>",
1112                     scs_m(k)(2)(4)(2)=tt
1113                 end
1114             end
1115         elseif o(1)=="Link" then
1116             if size(o(2),"*")==1 then
1117                 o(2)=o(2)*[1;1];o(3)=o(3)*[1;1];
1118                 scs_m(k)=o
1119             end
1120         end
1121     end
1122     if obsolete then
1123         messagebox(["Diagram contains obsolete signed blocks sum"
1124         "They are drawn in brown, they work as before but,"
1125         "please replace them with the new block sum"],"modal")
1126     end
1127
1128 endfunction
1129 function scs_m=do_version231(scs_m)
1130     //2.3.1 to 2.4 version
1131     if size(scs_m(1))<5 then scs_m(1)(5)=" ",end  //compatibility
1132     if type(scs_m(1)(5))<>10 then scs_m(1)(5)=" ",end //compatibility
1133     if size(scs_m(1))<6 then //compatibility
1134         wpar=scs_m(1)
1135         wpar(6)=list()
1136         wpar(7)=list(%t,[0.8 0.8 0.8])
1137         wpar(8)=[]
1138         wpar(9)=[]
1139         wpar(10)=[]
1140         scs_m(1)=wpar
1141     end
1142
1143     if size(scs_m(1)(1),"*") <4 then scs_m(1)(1)=[scs_m(1)(1),0,0],end //compatibility
1144
1145
1146     scs_m(1)(1)(2)=max(scs_m(1)(1)(2),450)
1147     if size(scs_m(1))<6 then
1148         options=default_options()
1149         doc=list() //documentation structure
1150         wpar=scs_m(1)
1151         wpar(6)=list()
1152         wpar(7)=options
1153         wpar(8)=[]
1154         wpar(9)=[]
1155         wpar(10)=doc
1156         scs_m(1)=wpar
1157     end
1158     wsiz=scs_m(1)(1)
1159     if size(wsiz,"*")<6 then //compatibility
1160         if size(wsiz,"*")<4 then wsiz(3)=0;wsiz(4)=0;end
1161         wsiz(5)=wsiz(1);wsiz(6)=wsiz(2);
1162         scs_m(1)(1)=wsiz;
1163     end
1164     if type(scs_m(1)(7))==15 then //options
1165         old_opt=scs_m(1)(7)
1166         options=default_options()
1167         options("3D")(1)=old_opt(1)
1168         options("Cmap")=old_opt(2)
1169         scs_m(1)(7)=options
1170     end
1171
1172     nx=size(scs_m)
1173     for k=2:nx
1174         o=scs_m(k)
1175         if o(1)=="Block" then
1176             model=o(3)
1177             if model(1)=="super"|model(1)=="csuper" then
1178                 model(8)=do_version231(model(8))
1179                 o(3)=model
1180                 scs_m(k)=o
1181             elseif model(1)(1)=="ifthel" then
1182                 model(1)=list("ifthel",-1)
1183                 scs_m(k)(3)=model
1184             elseif model(1)(1)=="eselect" then
1185                 model(1)=list("eselect",-1)
1186                 scs_m(k)(3)=model
1187             end
1188         end
1189     end
1190
1191
1192 endfunction
1193 function x_new=do_version23(scs_m)
1194     //2.3 to 2.3.1
1195     x_new=list()
1196     x_new(1)=scs_m(1)
1197     nx=size(scs_m)
1198     for k=2:nx
1199         o=scs_m(k)
1200         if o(1)=="Link" then
1201         elseif o(1)=="Block" then
1202             model=o(3)
1203             if model(1)=="super"|model(1)=="csuper" then
1204                 model(8)=do_version23(model(8))
1205                 o(3)=model
1206                 o=block2_version(o)
1207                 scs_m(k)=o
1208             else
1209                 o=block2_version(o)
1210             end
1211         end
1212         x_new(k)=o;
1213     end
1214
1215
1216 endfunction
1217 function o=block2_version(o)
1218     if o(3)(6)<>[] then o(3)(12)(2)=%t;end
1219
1220 endfunction
1221
1222
1223 function o=block_version(o)
1224     [graphics,model]=o(2:3)
1225     for k=2:5, model(k)=ones(model(k),1),end
1226     blocktype=o(5)
1227     ok=%t
1228     label=" "
1229     gr_i=" "
1230     select blocktype
1231     case "ABSBLK_f" then
1232         model(2)=-1
1233         model(3)=-1
1234         label=" "
1235         gr_i="xstringb(orig(1),orig(2),''abs'',sz(1),sz(2),''fill'')"
1236     case "ANIMXY_f" then
1237         [rpar,ipar]=model([8:9])
1238         model(9)=[model(9);0;[-1;-1];[-1;-1]]
1239         win=ipar(1);N=ipar(3);clrs=ipar(4);siz=ipar(5)
1240         xmin=rpar(1);xmax=rpar(2);ymin=rpar(3);ymax=rpar(4)
1241         label=[string(clrs);
1242         string(siz);
1243         string(win);
1244         "[]";
1245         "[]";
1246         string(xmin);
1247         string(xmax);
1248         string(ymin);
1249         string(ymax);
1250         string(N)]
1251         gr_i=["thick=xget(''thickness'');xset(''thickness'',2);";
1252         "t=(0:0.3:2*%pi)'';";
1253         "xx=orig(1)+(1/5+(cos(2.2*t)+1)*3/10)*sz(1);";
1254         "yy=orig(2)+(1/4.3+(sin(t)+1)*3/10)*sz(2);";
1255         "xpoly(xx,yy,''lines'');"
1256         "xset(''thickness'',thick);"]
1257     case "BOUND_f" then
1258         rpar=model(8);in=model(2);nin=sum(in)
1259         if nin<>1 then
1260             write(%io(2),["Pb with BOUND_f block";
1261             "previously block has more than one input port";
1262             "It is better to change it with the new block version";
1263             "preceded by a multiplexer"])
1264         end
1265         thresh=rpar(1:nin),v=rpar(nin+1:2*nin)
1266         label=[strcat(sci2exp(thresh));
1267         strcat(sci2exp(v))]
1268         gr_i=["thick=xget(''thickness'');xset(''thickness'',2);";
1269         "xx=orig(1)+[1/5;1/2;1/2;1-1/5]*sz(1);";
1270         "yy=orig(2)+[1/2;1/2;1-1/5;1-1/5]*sz(2);";
1271         "xpoly(xx,yy,''lines'');";
1272         "xset(''thickness'',1);";
1273         "xpoly(orig(1)+[1/9;1/5]*sz(1),orig(2)+[1/2;1/2]*sz(2),''lines'');";
1274         "xpoly(orig(1)+[1/2;1-1/9]*sz(1),orig(2)+[1/2;1/2]*sz(2),''lines'');";
1275         "xpoly(orig(1)+[1/2;1/2]*sz(1),orig(2)+[1/9;1/2]*sz(2),''lines'');";
1276         "xpoly(orig(1)+[1/2;1/2]*sz(1),orig(2)+[1-1/5;1-1/9]*sz(2),''lines'');";
1277         "xset(''thickness'',thick);"]
1278     case "CLINDUMMY_f" then
1279         label=[]
1280         gr_i=["xstringb(orig(1),orig(2),[''DUMMY'';''CLSS''],sz(1),sz(2),''fill'');"]
1281     case "CLKIN_f" then
1282         prt=model(9);
1283         label=string(prt)
1284         gr_i=[]
1285     case "CLKOUT_f" then
1286         prt=model(9);
1287         label=string(prt)
1288         gr_i=[]
1289     case "CLKSPLIT_f" then
1290         label=[]
1291         gr_i=[]
1292     case "CLKSOM_f" then
1293         label=[]
1294         gr_i=[]
1295     case "CLOCK_f" then
1296         orig=o(2)(1)
1297         sz=o(2)(2)
1298         oo=o(3)(8)
1299         dt=0.1
1300         for ko=2:size(oo)
1301             if oo(ko)(3)(1)=="evtdly" then
1302                 dt=oo(ko)(3)(8)
1303                 break
1304             end
1305         end
1306         o = list("Block",..
1307         list([0,0],[2,2],%t,[],[],[],[],0,..
1308         list(..
1309         ["wd=xget(''wdim'').*[1.016,1.12];";
1310         "thick=xget(''thickness'');xset(''thickness'',2);";
1311         "p=wd(2)/wd(1);p=1;";
1312         "rx=sz(1)*p/2;ry=sz(2)/2;";
1313         "xarcs([orig(1)+0.05*sz(1);";
1314         "orig(2)+0.95*sz(2);";
1315         "   0.9*sz(1)*p;";
1316         "   0.9*sz(2);";
1317         "   0;";
1318         "   360*64],scs_color(5));";
1319         "xset(''thickness'',1);";
1320         "xx=[orig(1)+rx    orig(1)+rx;";
1321         "    orig(1)+rx    orig(1)+rx+0.6*rx*cos(%pi/6)];";
1322         "yy=[orig(2)+ry    orig(2)+ry ;";
1323         "  orig(2)+1.8*ry  orig(2)+ry+0.6*ry*sin(%pi/6)];";
1324         "xsegs(xx,yy,scs_color(10));";
1325         "xset(''thickness'',thick);"],[])),..
1326         list("csuper",[],[],[],1,[]," ",..
1327         list(list([600,400,0,0],"foo",[],[]),..
1328         list("Block",list([399,162],[20,20],%t,"1",[],[],6,[],[]),..
1329         list("output",[],[],1,[],[],[],[],1,"d",[],[%f,%f]," ",list())," ","CLKOUT_f"),..
1330         list("Block",list([320,232],[40,40],%t,["0.1";"0.1"],[],[],7,4,..
1331         ["dt=model(8);";
1332         "txt=[''Delay'';string(dt)];";
1333         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]),..
1334         list("evtdly",[],[],1,1,[],[],0.1,[],"d",0.1,[%f,%f]," ",list())," ","EVTDLY_f"),..
1335         list("Link",[340;340;380.71066],[226.28571;172;172],"drawlink"," ",[0,0],[5,-1],[3,1],..
1336         [5,1]),..
1337         list("Block",list([380.71066;172],[1,1],%t," ",[],[],4,[6;7]),..
1338         list("lsplit",[],[],1,[1;1],[],[],[],[],"d",[-1,-1],[%t,%f]," ",list())," ","CLKSPLIT_f"),..
1339         list("Link",[380.71066;399],[172;172],"drawlink"," ",[0,0],[5,-1],[5,1],[2,1]),..
1340         list("Link",[380.71066;380.71066;340;340],[172;301.9943;301.9943;277.71429],"drawlink"," ",..
1341         [0,0],[5,-1],[5,2],[3,1])),[],"h",[],[%f,%f])," ","CLOCK_f")
1342
1343         o(2)(1)=orig
1344         o(2)(2)=sz
1345         xx=o(3)(8)(3)
1346         xx(2)(4)=string([dt;dt])
1347         xx(3)(11)=dt
1348         xx(3)(8)=dt
1349         o(3)(8)(3)=xx
1350         model=o(3)
1351     else
1352         ok=%f
1353     end
1354
1355     if ok then
1356         graphics(4)=label
1357         graphics(9)=gr_i
1358         o(2)=graphics
1359         model(13)=" ";model(14)=list()
1360         o(3)=model
1361         o=replace_firing(o)
1362         return
1363     end
1364
1365     ok=%t
1366     select blocktype
1367     case "CLR_f" then
1368         ipar=model(9);model(9)=[]
1369         ns=size(model(6),"*");nin=1;nout=1;
1370         rpar=model(8);
1371         A=matrix(rpar(1:ns*ns),ns,ns);
1372         B=matrix(rpar(ns*ns+1:ns*(ns+nin)),ns,nin);
1373         C=matrix(rpar(ns*(ns+nin)+1:ns*(ns+nin+nout)),nout,ns);
1374         D=rpar(ns*(ns+nin+nout)+1);
1375         H=ss2tf(syslin("c",A,B,C,D));
1376         H=clean(H);
1377         if type(H)==16 then
1378             num=H(2);den=H(3)
1379         else
1380             num=H,den=1
1381         end
1382         label=[sci2exp(num);sci2exp(den)]
1383         gr_i=["xstringb(orig(1),orig(2),[''Num(s)'';''-----'';''Den(s)''],sz(1),sz(2),''fill'');"]
1384     case "CLSS_f" then
1385         in=model(2);out=model(3)
1386         nin=sum(in)
1387         nout=sum(out)
1388         x0=model(6),
1389         rpar=model(8)
1390         ns=prod(size(x0))
1391         A=matrix(rpar(1:ns*ns),ns,ns)
1392         B=matrix(rpar(ns*ns+1:ns*(ns+nin)),ns,nin)
1393         C=matrix(rpar(ns*(ns+nin)+1:ns*(ns+nin+nout)),nout,ns)
1394         D=matrix(rpar(ns*(ns+nin+nout)+1:ns*(ns+nin+nout)+(nin*nout)),nout,nin)
1395         label=[  strcat(sci2exp(A));
1396         strcat(sci2exp(B));
1397         strcat(sci2exp(C));
1398         strcat(sci2exp(D));
1399         strcat(sci2exp(x0))]
1400         gr_i=["txt=[''xd=Ax+Bu'';''y=Cx+Du''];";
1401         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
1402         model(2)=nin;model(3)=nout
1403     case "CONST_f" then
1404         C=model(8);model(3)=sum(model(3))
1405         label=[strcat(sci2exp(C))]
1406         gr_i=["model=arg1(3);C=model(8);";
1407         "dx=sz(1)/5;dy=sz(2)/10;";
1408         "w=sz(1)-2*dx;h=sz(2)-2*dy;";
1409         "xstringb(orig(1)+dx,orig(2)+dy,string(C),w,h,''fill'');"]
1410     case "COSBLK_f" then
1411         in=model(2);nin=sum(in)
1412         if nin<>1 then
1413             write(%io(2),["Pb with COSBLK_f block";
1414             "previously block has more than one input port";
1415             "It is better to change it with the new block version";
1416             "preceded by a multiplexer and followed by a demultiplxer"])
1417         end
1418         label=" "
1419         gr_i=["xstringb(orig(1),orig(2),[''cos''],sz(1),sz(2),''fill'');"]
1420     case "CURV_f" then
1421         label=[]
1422         gr_i=["model=arg1(3);rpar=model(8);ipar=model(9);n=ipar(1);";
1423         "thick=xget(''thickness'');xset(''thickness'',2);";
1424         "xx=rpar(1:n);yy=rpar(n+1:2*n);";
1425         "rect=rpar(2*n+1:2*n+4);";
1426         "mxx=rect(3)-rect(1);";
1427         "mxy=rect(4)-rect(2);";
1428         "xx=orig(1)+sz(1)*(1/10+(4/5)*((xx-rect(1))/mxx));";
1429         "yy=orig(2)+sz(2)*(1/10+(4/5)*((yy-rect(2))/mxy));";
1430         "xpoly(xx,yy,''lines'');";
1431         "xset(''thickness'',thick);"]
1432     case "DELAY_f" then
1433         orig=o(2)(1)
1434         sz=o(2)(2)
1435         oo=o(3)(8)
1436         dt=[];z0=[]
1437         for ko=2:size(oo)
1438             if oo(ko)(3)(1)=="evtdly" then
1439                 dt=oo(ko)(3)(8)
1440             elseif oo(ko)(3)(1)=="register" then
1441                 z0=oo(ko)(3)(7)
1442             end
1443         end
1444         if dt==[]|z0==[] then
1445             write(%io(2), "Pb with DELAY_f block dt or z0 not found")
1446             pause
1447         end
1448         o=DELAY_f("define")
1449         o(2)(1)=orig
1450         o(2)(2)=sz
1451         o(3)(8)(4)(2)(4)=sci2exp(z0)
1452         o(3)(8)(5)(2)(4)=sci2exp(dt)
1453         o(3)(8)(5)(3)(8)=dt
1454         o(3)(8)(5)(3)(11)=0
1455         o(3)(8)(4)(3)(7)=z0(:)
1456         model=o(3)
1457         label=[]
1458         gr_i=["b1=xstringl(0,0,''e'');";
1459         "b2=xstringl(0,0,''-Ts'');";
1460         "h=-b1(2)+max(0,sz(2)-0.5*b1(4)+b2(4))/2;";
1461         "w=max(0,sz(1)-b1(3)-b1(4))/2;";
1462         "xstring(orig(1)+w,orig(2)+h,''e'');";
1463         "xstring(orig(1)+w+b1(3)/2,orig(2)+h+b1(4)*0.5,''-Ts'');"]
1464     case "DLRADAPT_f" then
1465         [dstate,rpar,ipar]=model(7:9)
1466         m=ipar(1);
1467         n=ipar(2)
1468         npt=ipar(3)
1469         p=rpar(1:npt)
1470
1471         rn=matrix(rpar(npt+1:npt+m*npt)+%i*rpar(npt+m*npt+1:npt+2*m*npt),npt,m)
1472         rd=matrix(rpar(npt+2*m*npt+1:npt+(2*m+n)*npt)+..
1473         %i*rpar(npt+(2*m+n)*npt+1:npt+2*(m+n)*npt),npt,n)
1474         g=rpar(npt+2*(m+n)*npt+1:npt+2*(m+n)*npt+npt)
1475         last_u=dstate(1:m);last_y=dstate(m+1:m+n)
1476         label=[sci2exp(p);
1477         sci2exp(rn);
1478         sci2exp(rd);
1479         sci2exp(g);
1480         sci2exp(last_u);
1481         sci2exp(last_y)]
1482         gr_i=["txt=[''N(z,p)'';''-----'';''D(z,p)''];";
1483         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
1484     case "DLR_f" then
1485         model(9)=[];model(10)="d"
1486         ns=size(model(7),"*");nin=1;nout=1;
1487         rpar=model(8);
1488         A=matrix(rpar(1:ns*ns),ns,ns);
1489         B=matrix(rpar(ns*ns+1:ns*(ns+nin)),ns,nin);
1490         C=matrix(rpar(ns*(ns+nin)+1:ns*(ns+nin+nout)),nout,ns);
1491         D=rpar(ns*(ns+nin+nout)+1);
1492         H=ss2tf(syslin("d",A,B,C,D));
1493         H=clean(H);
1494         if type(H)==16 then
1495             num=H(2);den=H(3)
1496         else
1497             num=H,den=1
1498         end
1499         label=[sci2exp(num);sci2exp(den)]
1500         gr_i=["txt=[''Num(z)'';''-----'';''Den(z)''];";
1501         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
1502     case "DLSS_f" then
1503         in=model(2);out=model(3)
1504         nin=sum(in)
1505         nout=sum(out)
1506         x0=model(6),rpar=model(8)
1507         ns=prod(size(x0))
1508         A=matrix(rpar(1:ns*ns),ns,ns)
1509         B=matrix(rpar(ns*ns+1:ns*(ns+nin)),ns,nin)
1510         C=matrix(rpar(ns*(ns+nin)+1:ns*(ns+nin+nout)),nout,ns)
1511         D=matrix(rpar(ns*(ns+nin+nout)+1:ns*(ns+nin+nout)+(nin*nout)),nout,nin)
1512
1513         label=[  strcat(sci2exp(A));
1514         strcat(sci2exp(B));
1515         strcat(sci2exp(C));
1516         strcat(sci2exp(D));
1517         strcat(sci2exp(x0))]
1518         gr_i=["txt=[''x+=Ax+Bu'';''y=Cx+Du''];";
1519         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
1520     case "EVENTSCOPE_f" then
1521         [nclock,rpar,ipar]=model([4 8 9])
1522         win=ipar(1);
1523         per=rpar(1);
1524         wdim=[-1;-1]
1525         wpos=[-1;-1]
1526         clrs=[1;3;5;7;9;11;13;15];
1527         model(9)=[win;1;clrs;wpos(:);wdim(:)]
1528         label=[sci2exp(nclock);
1529         strcat(sci2exp(clrs)," ");
1530         string(win);
1531         sci2exp([]);
1532         sci2exp([]);
1533         string(per)]
1534         gr_i=["thick=xget(''thickness'');xset(''thickness'',2);";
1535         "xrect(orig(1)+sz(1)/10,orig(2)+(1-1/10)*sz(2),sz(1)*8/10,sz(2)*8/10);";
1536         "xx=[orig(1)+sz(1)/5,orig(1)+sz(1)/5;";
1537         "orig(1)+(1-1/5)*sz(1),orig(1)+sz(1)/5];";
1538         "yy=[orig(2)+sz(2)/5,orig(2)+sz(2)/5;";
1539         "orig(2)+sz(2)/5,orig(2)+(1-1/5)*sz(2)];";
1540         "xarrows(xx,yy);";
1541         "t=(0:0.3:2*%pi)'';";
1542         "xx=orig(1)+(1/5+3*t/(10*%pi))*sz(1);";
1543         "yy=orig(2)+(1/4.3+(sin(t)+1)*3/10)*sz(2);";
1544         "xpoly(xx,yy,''lines'');";
1545         "xset(''thickness'',thick);"]
1546     case "EVTDLY_f" then
1547         dt=model(8);
1548         if model(11) then ff=0; else ff=-1; end
1549         model(11)=ff
1550         label=[string(dt);string(ff)]
1551         gr_i=["dt=model(8);";
1552         "txt=[''Delay'';string(dt)];";
1553         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
1554     case "EVTGEN_f" then
1555         tt=model(11);
1556         label=string(tt)
1557         gr_i=["xstringb(orig(1),orig(2),''Event'',sz(1),sz(2),''fill'');"]
1558     case "FOR_f" then
1559         write(%io(2),"FOR block nor more exist")
1560     else
1561         ok=%f
1562     end
1563     if ok then
1564         graphics(4)=label
1565         graphics(9)=gr_i
1566         o(2)=graphics
1567         model(13)=" ";model(14)=list()
1568         o(3)=model
1569         o=replace_firing(o)
1570         return
1571     end
1572     ok=%t
1573     select blocktype
1574     case "GAIN_f" then
1575         [in,out]=model(2:3)
1576         gain=matrix(model(8),out,in)
1577         label=[strcat(sci2exp(gain))]
1578         gr_i=["[nin,nout]=model(2:3);";
1579         "if nin*nout==1 then gain=string(model(8)),else gain=''Gain'',end";
1580         "dx=sz(1)/5;";
1581         "dy=sz(2)/10;";
1582         "xx=orig(1)+      [1 4 1 1]*dx;";
1583         "yy=orig(2)+sz(2)-[1 5 9 1]*dy;";
1584         "xpoly(xx,yy,''lines'');";
1585         "w=sz(1)-2*dx;h=sz(2)-2*dy;";
1586         "xstringb(orig(1)+dx,orig(2)+dy,gain,w,h,''fill'');"]
1587     case "GENERAL_f" then
1588         in=model(2);out=model(5)
1589         label=[strcat(sci2exp(in));strcat(sci2exp(out))]
1590         gr_i=["xstringb(orig(1),orig(2),''GENERAL'',sz(1),sz(2),''fill'');"]
1591     case "GENSIN_f" then
1592         rpar=model(8)
1593         label=[string(rpar(1));string(rpar(2));string(rpar(3))]
1594         gr_i=["txt=[''sinusoid'';''generator''];";
1595         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
1596     case "GENSQR_f" then
1597         //rpar=model(8); ?
1598         Amplitude=model(7)
1599         label=string(Amplitude)
1600         gr_i=["txt=[''square wave'';''generator''];";
1601         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
1602     case "HALT_f" then
1603         n=model(9);
1604         label=string(n)
1605         gr_i=["xstringb(orig(1),orig(2),''STOP'',sz(1),sz(2),''fill'');"]
1606     case "IFTHEL_f" then
1607         label=[]
1608         model(11)=[-1,-1]
1609         gr_i=["txt=[''If in>=0'';'' '';'' then    else''];";
1610         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
1611     case "INTEGRAL_f" then
1612         x0=model(6);
1613         label=strcat(sci2exp(x0))
1614         gr_i=["xstringb(orig(1),orig(2),''  1/s  '',sz(1),sz(2),''fill'');"]
1615     case "INVBLK_f" then
1616         model(2)=-1;model(3)=-1
1617         label=" "
1618         gr_i=["xstringb(orig(1),orig(2),''1/u'',sz(1),sz(2),''fill'');"]
1619     case "IN_f" then
1620         prt=model(9);
1621         label=[string(prt)]
1622         model(3)=-1
1623         gr_i=[]
1624     case "LOGBLK_f" then
1625         a=model(8)
1626         in=model(2)
1627         label=[string(a)]
1628         model(2)=-1;model(3)=-1
1629         gr_i=["xstringb(orig(1),orig(2),''log'',sz(1),sz(2),''fill'');"]
1630     case "LOOKUP_f" then
1631         model(10)="c"
1632         gr_i=["rpar=model(8);n=size(rpar,''*'')/2;";
1633         "thick=xget(''thickness'');xset(''thickness'',2);";
1634         "xx=rpar(1:n);yy=rpar(n+1:2*n);";
1635         "mnx=min(xx);xx=xx-mnx*ones(xx);mxx=max(xx);";
1636         "xx=orig(1)+sz(1)*(1/10+(4/5)*xx/mxx);";
1637         "mnx=min(yy);yy=yy-mnx*ones(yy);mxx=max(yy);";
1638         "yy=orig(2)+sz(2)*(1/10+(4/5)*yy/mxx);";
1639         "xpoly(xx,yy,''lines'');";
1640         "xset(''thickness'',thick);"]
1641         label=[]
1642     case "MAX_f" then
1643         in=model(2);nin=sum(in)
1644         if nin<>1 then
1645             write(%io(2),["Pb with MAX_f block";
1646             "previously block has more than one input port";
1647             "It is better to change it with the new block version";
1648             "preceded by a multiplexer"])
1649         end
1650         label=" "
1651         gr_i=["xstringb(orig(1),orig(2),''Max'',sz(1),sz(2),''fill'');"]
1652     case "MCLOCK_f" then
1653         label=[]
1654         gr_i=["txt=[''2freq clock'';''  f/n     f''];";
1655         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'')"]
1656     case "MFCLCK_f" then
1657         dt=model(8)
1658         nn=model(9)
1659         label=[string(dt);string(nn)]
1660         gr_i=["txt=[''M. freq'';''clock''];";
1661         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'')"]
1662     case "MIN_f" then
1663         in=model(2);nin=sum(in)
1664         if nin<>1 then
1665             write(%io(2),["Pb with MIN_f block";
1666             "previously block has more than one input port";
1667             "It is better to change it with the new block version";
1668             "preceded by a multiplexer"])
1669         end
1670         label=" "
1671         gr_i=["xstringb(orig(1),orig(2),''MIN'',sz(1),sz(2),''fill'')"]
1672     case "NEGTOPOS_f" then
1673         label=[]
1674         gr_i=["xstringb(orig(1),orig(2),'' - to + '',sz(1),sz(2),''fill'');"]
1675     case "OUT_f" then
1676         prt=model(9);
1677         model(2)=-1
1678         label=[string(prt)]
1679         gr_i=[]
1680     case "POSTONEG_f" then
1681         label=[]
1682         gr_i=["xstringb(orig(1),orig(2),'' + to - '',sz(1),sz(2),''fill'')"]
1683     case "POWBLK_f" then
1684         in=model(2);nin=sum(in)
1685         if nin<>1 then
1686             write(%io(2),["Pb with MIN_f block";
1687             "previously block has more than one input port";
1688             "It is better to change it with the new block version";
1689             "preceded by a multiplexer and followed by a demux"])
1690         end
1691         if model(8)<>[] then
1692             a=model(8)
1693         else
1694             a=model(9)
1695         end
1696         in=model(2)
1697         label=[string(a)]
1698         gr_i=["xstringb(orig(1),orig(2),''u^a'',sz(1),sz(2),''fill'');"]
1699     case "PROD_f" then
1700         label=[]
1701         gr_i=[]
1702         model(1)=list("prod",2)
1703     case "QUANT_f" then
1704         rpar=model(8);ipar=model(9);
1705         pas=rpar(1)
1706         meth=ipar
1707         label=[string(pas);string(meth)]
1708         gr_i=["thick=xget(''thickness'');xset(''thickness'',2);";
1709         "xx=orig(1)+[1;2;2;3;3;4;4]/5*sz(1);";
1710         "yy= orig(2)+[1;1;2;2;3;3;4]/5*sz(2);";
1711         "xpoly(xx,yy,''lines'');";
1712         "xset(''thickness'',thick);"]
1713     case "RAND_f" then
1714         rpar=model(8);flag=model(9);
1715         out=model(3);nout=sum(out)
1716         if nout<>1 then
1717             write(%io(2),["Pb with RAND_f block";
1718             "previously block has more than one output port";
1719             "It is better to change it with the new block version";
1720             " followed by a demux"])
1721         end
1722
1723         a=rpar(1:nout)
1724         b=rpar(nout+1:2*nout)
1725         label=[string(flag);sci2exp(a(:));sci2exp(b(:))]
1726         gr_i=["txt=[''random'';''generator''];";
1727         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'')"]
1728     case "REGISTER_f" then
1729         z0=model(7)
1730         label=strcat(string(z0),";")
1731
1732         gr_i=["dly=model(8);";
1733         "txt=[''Shift'';''Register'';string(dly)];";
1734         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'')"]
1735     else
1736         ok=%f
1737     end
1738     if ok then
1739         graphics(4)=label
1740         graphics(9)=gr_i
1741         o(2)=graphics
1742         model(13)=" ";model(14)=list()
1743         o(3)=model
1744         o=replace_firing(o)
1745         return
1746     end
1747     ok=%t
1748     select blocktype
1749     case "RFILE_f" then
1750         [out,state,ipar]=model([3 7 9])
1751         nout=sum(out)
1752         ievt=ipar(3);N=ipar(4);
1753         imask=5+ipar(1)+ipar(2)
1754         if ievt<>0 then tmask=ipar(imask),else tmask=[],end
1755         outmask=ipar(imask+ievt:imask+nout+ievt-1)
1756         lunit=state(2)
1757         ievt=ipar(3);N=ipar(4);
1758         imask=5+ipar(1)+ipar(2)
1759         if ievt<>0 then tmask=ipar(imask),else tmask=[],end
1760         outmask=ipar(imask+ievt:imask+nout+ievt-1)
1761         lfil=ipar(1)
1762         lfmt=ipar(2)
1763         if lfil>0 then fname=ascii(ipar(5:4+lfil)),else fname=" ",end
1764         if lfmt>0 then Fmt=ascii(ipar(5+lfil:4+lfil+lfmt)),else Fmt=" ",end
1765         label=[ sci2exp(tmask);
1766         sci2exp(outmask);
1767         fname;
1768         Fmt;
1769         string(N);
1770         sci2exp(out)]
1771         gr_i=["txt=[''read from'';''input file''];";
1772         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'')"]
1773     case "SAT_f" then
1774         rpar=model(8)
1775         minp=rpar(1),maxp=rpar(2),pente=rpar(3)
1776         label=[string(minp);string(maxp);string(pente)]
1777
1778         gr_i=["thick=xget(''thickness'');xset(''thickness'',2);";
1779         "xx=orig(1)+[4/5;1/2+1/5;1/2-1/5;1/5]*sz(1);";
1780         "yy=orig(2)+[1-1/5;1-1/5;1/5;1/5]*sz(2);";
1781         "xpoly(xx,yy,''lines'');";
1782         "xset(''thickness'',thick)"]
1783     case "SAWTOOTH_f" then
1784         model(10)="c"
1785         gr_i=["txt=[''sawtooth'';''generator''];";
1786         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
1787     case "SCOPE_f" then
1788         [in,rpar,ipar]=model([2 8 9])
1789         in=model(2);nin=sum(in)
1790         if nin<>1 then
1791             write(%io(2),["Pb with SCOPE_f block";
1792             "previously block has more than one input port";
1793             "It is better to change it with the new block version";
1794             "preceded by a multiplexer"])
1795         end
1796         win=ipar(1);N=ipar(3);
1797         clrs=-ipar(4:nin+3)
1798         if size(clrs,"*")<8 then clrs(8)=1;end
1799
1800         wdim=[-1;-1]
1801         wpos=[-1;-1]
1802         model(9)=[win;1;N;clrs;wpos(:);wdim(:)]
1803         dt=rpar(1);ymin=rpar(2);ymax=rpar(3);per=rpar(4)
1804         label=[strcat(string(clrs)," ");
1805         string(win);
1806         sci2exp([]);
1807         sci2exp([]);
1808         string(ymin);
1809         string(ymax);
1810         string(per);
1811         string(N)];
1812
1813         gr_i=["thick=xget(''thickness'');xset(''thickness'',2);";
1814         "xrect(orig(1)+sz(1)/10,orig(2)+(1-1/10)*sz(2),sz(1)*8/10,sz(2)*8/10);";
1815         "xx=[orig(1)+sz(1)/5,orig(1)+sz(1)/5;";
1816         "orig(1)+(1-1/5)*sz(1),orig(1)+sz(1)/5];";
1817         "yy=[orig(2)+sz(2)/5,orig(2)+sz(2)/5;";
1818         "orig(2)+sz(2)/5,orig(2)+(1-1/5)*sz(2)];";
1819         "xarrows(xx,yy);";
1820         "t=(0:0.3:2*%pi)'';";
1821         "xx=orig(1)+(1/5+3*t/(10*%pi))*sz(1);";
1822         "yy=orig(2)+(1/4.3+(sin(t)+1)*3/10)*sz(2);";
1823         "xpoly(xx,yy,''lines'');";
1824         "xset(''thickness'',thick)"]
1825     case "SCOPXY_f" then
1826         [rpar,ipar]=model(8:9)
1827         win=ipar(1);N=ipar(3);clrs=-ipar(4);siz=ipar(5)
1828         xmin=rpar(1);xmax=rpar(2);ymin=rpar(3);ymax=rpar(4)
1829         wdim=[-1;-1]
1830         wpos=[-1;-1]
1831         label=[sci2exp(clrs);
1832         sci2exp(siz);
1833         string(win);
1834         sci2exp([]);
1835         sci2exp([]);
1836         string(xmin);
1837         string(xmax);
1838         string(ymin);
1839         string(ymax);
1840         string(N)];
1841         model(9)=[win;1;N;clrs;siz;1;wpos(:);wdim(:)]
1842         gr_i=["thick=xget(''thickness'');xset(''thickness'',2);";
1843         "t=(0:0.2:2*%pi)'';";
1844         "xx=orig(1)+(1/5+(cos(3*t)+1)*3/10)*sz(1);";
1845         "yy=orig(2)+(1/4.3+(sin(t+1)+1)*3/10)*sz(2);";
1846         "xpoly(xx,yy,''lines'');";
1847         "xset(''thickness'',thick)"]
1848     case "SELECT_f" then
1849         z0=model(7);nin=size(model(2),1);
1850         label=[string(nin);string(z0-1)]
1851         model(1)=list("selector",2)
1852         gr_i=["xstringb(orig(1),orig(2),''Selector'',sz(1),sz(2),''fill'');"]
1853     case "SINBLK_f" then
1854         in=model(2);nin=sum(in)
1855         if nin<>1 then
1856             write(%io(2),["Pb with MIN_f block";
1857             "previously block has more than one input port";
1858             "It is better to change it with the new block version";
1859             "preceded by a multiplexer and followed by a demux"])
1860         end
1861         label=" "
1862         gr_i=["xstringb(orig(1),orig(2),''sin'',sz(1),sz(2),''fill'')"]
1863     case "SOM_f" then
1864         sgn=model(8);
1865         label=sci2exp(sgn)
1866         model(1)=list("sum",2)
1867         gr_i=[]
1868     case "SPLIT_f" then
1869         label=[]
1870         gr_i=[]
1871     case "SUPER_f" then
1872         label=[]
1873         gr_i=["thick=xget(''thickness'');xset(''thickness'',2);";
1874         "xx=orig(1)+      [2 4 4]*(sz(1)/7);";
1875         "yy=orig(2)+sz(2)-[2 2 6]*(sz(2)/10);";
1876         "xrects([xx;yy;[sz(1)/7;sz(2)/5]*ones(1,3)]);";
1877         "xx=orig(1)+      [1 2 3 4 5 6 3.5 3.5 3.5 4 5 5.5 5.5 5.5]*sz(1)/7;";
1878         "yy=orig(2)+sz(2)-[3 3 3 3 3 3 3   7   7   7 7 7   7   3  ]*sz(2)/10;";
1879         "xsegs(xx,yy,0);";
1880         "xset(''thickness'',thick)"]
1881     case "TANBLK_f" then
1882         in=model(2);nin=sum(in)
1883         if nin<>1 then
1884             write(%io(2),["Pb with TANBLK_f block";
1885             "previously block has more than one input port";
1886             "It is better to change it with the new block version";
1887             "preceded by a multiplexer and followed by a demux"])
1888         end
1889         label=" "
1890         gr_i=["xstringb(orig(1),orig(2),''tan'',sz(1),sz(2),''fill'');"]
1891     case "TCLSS_f" then
1892         in=model(2);nin=sum(in)
1893         out=model(3);nout=sum(out)
1894         x0=model(6),rpar=model(8)
1895
1896         ns=prod(size(x0));nin=nin-ns
1897         A=matrix(rpar(1:ns*ns),ns,ns)
1898         B=matrix(rpar(ns*ns+1:ns*(ns+nin)),ns,nin)
1899         C=matrix(rpar(ns*(ns+nin)+1:ns*(ns+nin+nout)),nout,ns)
1900         D=matrix(rpar(ns*(ns+nin+nout)+1:ns*(ns+nin+nout)+(nin*nout)),nout,nin)
1901         nin1=nin;nout1=nout
1902
1903         label=[strcat(sci2exp(A));
1904         strcat(sci2exp(B));
1905         strcat(sci2exp(C));
1906         strcat(sci2exp(D));
1907         strcat(sci2exp(x0))]
1908         gr_i=["txt=[''Jump'';''(A,B,C,D)''];";
1909         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'')"]
1910     else
1911         ok=%f
1912     end
1913     if ok then
1914         graphics(4)=label
1915         graphics(9)=gr_i
1916         o(2)=graphics
1917         model(13)=" "
1918         model(14)=list()
1919         o(3)=model
1920         o=replace_firing(o)
1921         return
1922     end
1923     ok=%t
1924     select blocktype
1925     case "TEXT_f" then
1926         ipar=model(9)
1927         font=ipar(1);siz=ipar(2)
1928         label=[graphics(4);string(font);string(siz)]
1929         gr_i=[]
1930     case "TIME_f" then
1931         label=[]
1932         gr_i=["wd=xget(''wdim'').*[1.016,1.12];";
1933         "thick=xget(''thickness'');xset(''thickness'',2);";
1934         "p=wd(2)/wd(1);p=1;";
1935         "rx=sz(1)*p/2;ry=sz(2)/2;";
1936         "xarc(orig(1)+0.05*sz(1),orig(2)+0.95*sz(2),0.9*sz(1)*p,0.9*sz(2),0,360*64);";
1937         "xset(''thickness'',1);";
1938         "xx=[orig(1)+rx    orig(1)+rx;";
1939         "orig(1)+rx    orig(1)+rx+0.6*rx*cos(%pi/6)];";
1940         "yy=[orig(2)+ry    orig(2)+ry ;";
1941         "     orig(2)+1.8*ry  orig(2)+ry+0.6*ry*sin(%pi/6)];";
1942         "xsegs(xx,yy,0);";
1943         "xset(''thickness'',thick);"]
1944     case "TRASH_f" then
1945         in=model(2);nin=sum(in)
1946         if nin<>1 then
1947             write(%io(2),["Pb with MIN_f block";
1948             "previously block has more than one input port";
1949             "It is better to change it with the new block version";
1950             "preceded by a multiplexer"])
1951         end
1952         label=" "
1953         gr_i=["xstringb(orig(1),orig(2),''Trash'',sz(1),sz(2),''fill'')"]
1954     case "WFILE_f" then
1955         state=model(7)
1956         [in,ipar]=model([2  9])
1957         N=ipar(3);
1958         lunit=state(2)
1959         N=ipar(4)
1960         lfil=ipar(1)
1961         lfmt=ipar(2)
1962         if lfil>0 then fname=ascii(ipar(5:4+lfil)),else fname=" ",end
1963         if lfmt>0 then Fmt=ascii(ipar(5+lfil:4+lfil+lfmt)),else Fmt=" ",end
1964         label=[sci2exp(in);
1965         fname;
1966         Fmt;
1967         string(N)]
1968
1969         gr_i=["txt=[''write to'';''output file''];";
1970         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'')"]
1971     case "ZCROSS_f" then
1972         in=model(2)
1973         label=strcat(sci2exp(in))
1974         gr_i=["xstringb(orig(1),orig(2),''Zcross'',sz(1),sz(2),''fill'');"]
1975     case "func_block" then
1976         write(%io(2),["PB with func_block";
1977         "version change is not implemented"])
1978         label=[]
1979         gr_i=["xstringb(orig(1),orig(2),''Func'',sz(1),sz(2),''fill'');"]
1980     case "m_sin" then
1981         rpar=model(8);gain=rpar(1);phase=rpar(2)
1982         label=[string(gain);string(phase)]
1983         gr_i=[]
1984     case "sci_block" then
1985         write(%io(2),["PB with sci_block";
1986         "version change is not implemented"])
1987         label=[]
1988         gr_i=["xstringb(orig(1),orig(2),''Sci_Block'',sz(1),sz(2),''fill'');"]
1989     case "scifunc_block" then
1990         write(%io(2),["PB with scifunc_block";
1991         "version change is not implemented"])
1992         i1=model(2);o1=model(3);ci1=model(4);co1=model(5);x1=model(6);
1993         z1=model(7);auto1=model(11);type_1=model(10);
1994         tt=model(9),rpar=model(8)
1995         label=list([sci2exp(i1);sci2exp(o1);sci2exp(ci1);sci2exp(co1);
1996         strcat(sci2exp(x1));strcat(sci2exp(z1));type_1;
1997         strcat(sci2exp(rpar));sci2exp(auto1)],tt)
1998
1999         gr_i=["xstringb(orig(1),orig(2),''Scifunc'',sz(1),sz(2),''fill'');"]
2000     case "standard_block" then
2001         write(%io(2),["PB with standard_block";
2002         "version change is not implemented"])
2003         label=[]
2004         gr_i=[]
2005     else
2006         disp(blocktype+" unknown, parameters values may be lost, please check")
2007         label=[]
2008         gr_i=[]
2009     end
2010     graphics(4)=label
2011     graphics(9)=gr_i
2012     o(2)=graphics
2013     model(13)=" "
2014     model(14)=list()
2015     o(3)=model
2016     o=replace_firing(o)
2017
2018 endfunction
2019
2020 function o=replace_firing(o)
2021     firing=o(3)(11)
2022     cout=o(3)(5)
2023     if firing==%f|firing==0 then
2024         o(3)(11)=-ones(cout)
2025         //disp('firing changed from %f to '+sci2exp(o(3)(11))+' in '+o(3)(1)(1))
2026     elseif firing==%t|firing==1  then
2027         o(3)(11)=0*cout
2028         //disp('firing changed from %t to '+sci2exp(o(3)(11))+' in '+o(3)(1)(1))
2029     elseif firing==[] then
2030         o(3)(11)=[]
2031     else
2032         write(%io(2),"Problem with block "+o(3)(1)(1))
2033         pause
2034     end
2035
2036 endfunction
2037 function x_new=do_version22(scs_m)
2038     x_new=list()
2039     wpar=scs_m(1)
2040     wsiz=wpar(1)
2041
2042     if size(wsiz,"*")>=4 then x_new=scs_m,return,end
2043
2044     wpar(3)(4)=wpar(4)+1
2045     x_new(1)=wpar
2046     nx=size(scs_m)
2047     for k=2:nx
2048         o=scs_m(k)
2049         if o(1)=="Link" then
2050         elseif o(1)=="Block" then
2051             model=o(3)
2052             if model(1)=="super"|model(1)=="csuper" then
2053                 model(8)=do_version22(model(8))
2054                 o(3)=model
2055                 o=block_version(o)
2056                 scs_m(k)=o
2057             else
2058                 o=block_version(o)
2059             end
2060         elseif o(1)=="Text" then
2061             o=block_version(o)
2062         end
2063         x_new(k)=o;
2064     end
2065 endfunction
2066
2067 function scs_m_new=do_version27(scs_m)
2068     if typeof(scs_m)=="diagram" then
2069         //following code reported into do_version273
2070         //     scs_m_new=scs_m,
2071         //     nlstsize=lstsize(scs_m_new.objs)
2072         //     for k=1:nlstsize
2073         //       if typeof(scs_m_new.objs(k))=='Link' then
2074         //  o=scs_m_new.objs(k)
2075         //  if size(o.from,'*')==2 then o.from(3)=0,end
2076         //  if size(o.to,'*')==2 then o.to(3)=1,end
2077         //  scs_m_new.objs(k)=o
2078         //       elseif typeof(scs_m_new.objs(k))=='Block' then
2079
2080         //       end
2081         //     end
2082         scs_m_new=scs_m
2083         return,
2084     end
2085     scs_m_new=scicos_diagram()
2086     tf=scs_m(1)(4)
2087     if tf==[] then tf=100;end
2088     tol=scs_m(1)(3)
2089     if size(tol,"*")<4 then tol(4)=tf+1,end
2090     if size(tol,"*")<5 then tol(5)=0,end
2091     if size(tol,"*")<6 then tol(6)=0,end
2092     for iix=size(scs_m(1))+1:10,scs_m(1)(iix)=[];end
2093     scs_m_new.props=scicos_params(wpar=scs_m(1)(1),Title=scs_m(1)(2),..
2094     tol=tol,tf=tf,..
2095     context=scs_m(1)(5),options=scs_m(1)(7),..
2096     doc=scs_m(1)(10))
2097
2098     if scs_m(1)(7).Background==[] then
2099         scs_m_new.props.options.Background=[8 1]
2100     end
2101
2102     scs_m_new.objs(1)=mlist("Deleted") // not to change the internal numbering
2103     n=lstsize(scs_m)
2104     back_col=8   //white background
2105
2106     mprintf(".")
2107
2108     for i=2:n //loop on objects
2109         o=scs_m(i);
2110         if o(1)=="Block" then
2111             if size(o(2)) > 8 then
2112                 if type(o(2)(9))==15 then
2113                     gr_io=o(2)(9)(1);
2114                     if o(2)(9)(2)<>[] then
2115                         back_col=o(2)(9)(2);,
2116                     end
2117                 else
2118                     gr_io=o(2)(9);
2119                     back_col=8
2120                 end
2121                 gr_i=convert_gri(o(5),gr_io);
2122                 if gr_i==[] then gr_i=gr_io;, end
2123             elseif size(o(2)) < 9 then
2124                 gr_i=[];
2125                 back_col=8
2126             end
2127             gr_i=list(gr_i,back_col)
2128
2129             mdl=o(3);
2130             if size(o(3))<=12 then
2131                 mdl(13)=""; mdl(14)=[] ; mdl(15)="";
2132             elseif size(o(3))<=13 then
2133                 mdl(14)=[] ; mdl(15)="";
2134             elseif size(o(3))<=14 then
2135                 mdl(15)="";
2136             end
2137
2138             if mdl(1)(1)=="super"|mdl(1)(1)=="csuper" then
2139                 if type(mdl(8))==15 then
2140                     mdl(8)=do_version27(mdl(8))
2141                 end
2142             end
2143
2144             graphics=scicos_graphics27(orig=o(2)(1),sz=o(2)(2),flip=o(2)(3),..
2145             exprs=o(2)(4),pin=o(2)(5),pout=o(2)(6),..
2146             pein=o(2)(7),peout=o(2)(8),gr_i=gr_i,..
2147             id=mdl(15))
2148
2149
2150             model=scicos_model27(sim=mdl(1),in=mdl(2),out=mdl(3),evtin=mdl(4),..
2151             evtout=mdl(5),state=mdl(6),dstate=mdl(7),..
2152             rpar=mdl(8),ipar=mdl(9),blocktype=mdl(10),..
2153             firing=mdl(11),dep_ut=mdl(12),label=mdl(13))
2154
2155
2156             objsi=scicos_block(graphics=graphics,model=model,gui=o(5),..
2157             doc=mdl(14))
2158             if objsi.gui=="ESELECT_f" then objsi.model.sim(2)=-2,end
2159             scs_m_new.objs(i)=objsi
2160
2161         elseif o(1)=="Link" then
2162             from=o(8);from(3)=0;
2163             to=o(9);to(3)=1;
2164
2165             objsi=scicos_link(xx=o(2),yy=o(3),id=o(5),thick=o(6),..
2166             ct=o(7),from=from,to=to)
2167             scs_m_new.objs(i)=objsi
2168         elseif o(1)=="Text" then
2169
2170             objsi=TEXT_f("define")
2171             objsi.model.rpar=o(3)(8)
2172             objsi.model.ipar=o(3)(9)
2173             objsi.graphics.orig=o(2)(1)
2174             objsi.graphics.sz=o(2)(2)
2175             objsi.graphics.exprs=o(2)(4)
2176             scs_m_new.objs(i)=objsi
2177         elseif o(1)=="Deleted" then
2178             scs_m_new.objs(i)=mlist("Deleted")
2179         end
2180     end
2181
2182     [%cpr,edited]=resume(list(),%t) // doit etre enleve
2183 endfunction
2184
2185 function  gr_i=convert_gri(name,gri)
2186     gr_i=[];
2187     select name
2188     case "BIGSOM_f" then
2189         gr_i=["[x,y,typ]=standard_inputs(o) ";
2190         "sgn=o.model.rpar";
2191         "for k=1:size(x,''*'')";
2192         "  if sgn(k)>0 then";
2193         "    xstring(orig(1)+sz(1)/8 ,y(k)-4,''+'')";
2194         "  else";
2195         "    xstring(orig(1)+sz(1)/8 ,y(k)-4,''-'')";
2196         "  end";
2197         "end";
2198         "xx=sz(1)*[.8 .4 0.75 .4 .8]+orig(1)";
2199         "yy=sz(2)*[.8 .8 .5 .2 .2]+orig(2)";
2200         "xpoly(xx,yy,''lines'')"]
2201
2202     case "CONST_f" then
2203         gr_i=["dx=sz(1)/5;dy=sz(2)/10;";
2204         "w=sz(1)-2*dx;h=sz(2)-2*dy;";
2205         "txt=C;"
2206         "xstringb(orig(1)+dx,orig(2)+dy,txt,w,h,''fill'');"]
2207
2208     case "CURV_f" then
2209         gr_i=["model=arg1.model;rpar=model.rpar;ipar=model.ipar;n=ipar(1);";
2210         "thick=xget(''thickness'');xset(''thickness'',2);";
2211         "xx=rpar(1:n);yy=rpar(n+1:2*n);";
2212         "rect=rpar(2*n+1:2*n+4);";
2213         "mxx=rect(3)-rect(1);";
2214         "mxy=rect(4)-rect(2);";
2215         "xx=orig(1)+sz(1)*(1/10+(4/5)*((xx-rect(1))/mxx));";
2216         "yy=orig(2)+sz(2)*(1/10+(4/5)*((yy-rect(2))/mxy));";
2217         "xpoly(xx,yy,''lines'');";
2218         "xset(''thickness'',thick);"]
2219
2220     case "EVTDLY_f" then
2221         gr_i=["dt=model.rpar;";
2222         "txt=[''Delay'';string(dt)];";
2223         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
2224
2225     case "EVTGEN_f" then
2226         gr_i=["tt=model.firing;";
2227         "txt=[''Event at'';''time ''+string(tt)];";
2228         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'');"]
2229
2230     case "GAIN_f" then
2231
2232         gr_i=["gain=C,"
2233         "dx=sz(1)/5;";
2234         "dy=sz(2)/10;";
2235         "xx=orig(1)+      [1 4 1 1]*dx;";
2236         "yy=orig(2)+sz(2)-[1 5 9 1]*dy;";
2237         "xpoly(xx,yy,''lines'');";
2238         "w=sz(1)-2*dx;h=sz(2)-2*dy;";
2239         "xstringb(orig(1)+dx,orig(2)+dy,gain,w,h,''fill'');"]
2240
2241     case "LOOKUP_f" then
2242         gr_i=["rpar=model.rpar;n=size(rpar,''*'')/2;";
2243         "thick=xget(''thickness'');xset(''thickness'',2);";
2244         "xx=rpar(1:n);yy=rpar(n+1:2*n);";
2245         "mnx=min(xx);xx=xx-mnx*ones(xx);mxx=max(xx);";
2246         "xx=orig(1)+sz(1)*(1/10+(4/5)*xx/mxx);";
2247         "mnx=min(yy);yy=yy-mnx*ones(yy);mxx=max(yy);";
2248         "yy=orig(2)+sz(2)*(1/10+(4/5)*yy/mxx);";
2249         "xpoly(xx,yy,''lines'');";
2250         "xset(''thickness'',thick);"]
2251
2252     case "REGISTER_f" then
2253
2254         gr_i=["dly=model.rpar;";
2255         "txt=[''Shift'';''Register'';string(dly)];";
2256         "xstringb(orig(1),orig(2),txt,sz(1),sz(2),''fill'')"]
2257     case "SWITCH_f" then
2258
2259         gr_i="xstringb(orig(1),orig(2),[''switch'';string(model.ipar+1)],sz(1),sz(2),''fill'');"
2260     case "EXPBLK_f" then
2261         gr_i="xstringb(orig(1),orig(2),''a^u'',sz(1),sz(2),''fill'');"
2262     case "POWBLK_f" then
2263         gr_i="xstringb(orig(1),orig(2),''u^a'',sz(1),sz(2),''fill'');"
2264
2265     end
2266 endfunction
2267
2268
2269 function scs_m_new=do_versionxx(scs_m)
2270     //A SUPPRIMER CF ci dessus
2271     if typeof(scs_m)=="diagram" then scs_m_new=scs_m,return,end
2272     if typeof(scs_m(1))<>"params" then scs_m_new=scs_m,return,end
2273     scs_m_new=scicos_diagram()
2274     scs_m_new.props=scs_m(1)
2275     scs_m_new.objs(1)=mlist("Deleted") // not to change the internal numbering
2276     n=lstsize(scs_m)
2277     for i=2:n //loop on objects
2278         o=scs_m(i)
2279         scs_m_new.objs(i)=o
2280         if typeof(o)=="Block" then
2281             if o.model.sim(1)=="super"| o.model.sim(1)=="csuper" then
2282                 scs_m_new.objs(i).model.rpar=do_versionxx(o.model.rpar)
2283             end
2284         end
2285     end
2286     edited=resume(%t)
2287 endfunction
2288
2289
2290 function model=scicos_model27(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13)
2291     //initialisation de model scicos_new
2292     if exists("sim","local")==0 then sim="",end
2293     if exists("in","local")==0 then in=[],end
2294     if exists("out","local")==0 then out=[],end
2295     if exists("evtin","local")==0 then evtin=[],end
2296     if exists("evtout","local")==0 then evtout=[],end
2297     if exists("state","local")==0 then state=[],end
2298     if exists("dstate","local")==0 then dstate=[],end
2299     if exists("rpar","local")==0 then rpar=[],end
2300     if exists("ipar","local")==0 then ipar=[],end
2301     if exists("blocktype","local")==0 then blocktype="c",end
2302     if exists("firing","local")==0 then firing=[],end
2303     if exists("dep_ut","local")==0 then dep_ut=[%f %f],end
2304     if exists("label","local")==0 then label="",end
2305
2306     model=scicos_new(["model","sim","in","out","evtin","evtout","state","dstate",..
2307     "rpar","ipar","blocktype","firing","dep_ut","label"],..
2308     sim,in,out,evtin,evtout,state,dstate,..
2309     rpar,ipar,blocktype,firing,dep_ut,label)
2310 endfunction
2311
2312 function graphics=scicos_graphics27(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10)
2313     //initialisation de graphics scicos_new
2314     if exists("orig","local")==0 then orig=[0 0],end
2315     if exists("sz","local")==0 then sz=[20 20],end
2316     if exists("flip","local")==0 then flip=%t,end
2317     if exists("exprs","local")==0 then exprs=[],end
2318     if exists("pin","local")==0 then pin=[],end
2319     if exists("pout","local")==0 then pout=[],end
2320     if exists("pein","local")==0 then pein=[],end
2321     if exists("peout","local")==0 then peout=[],end
2322     if exists("gr_i","local")==0 then gr_i=[],end
2323     if exists("id","local")==0 then id="",end
2324
2325     graphics=scicos_new(["graphics","orig","sz","flip","exprs","pin",..
2326     "pout","pein","peout","gr_i","id"],..
2327     orig,sz,flip,exprs,pin,pout,pein,peout,gr_i,id)
2328 endfunction