1 // =============================================================================
2 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 // Copyright (C) ????-2008 - INRIA
5 // This file is distributed under the same license as the Scilab package.
6 // =============================================================================
7 load('SCI/modules/scicos/macros/scicos_scicos/lib');
8 load('SCI/modules/scicos/macros/scicos_utils/lib');
9 if ( ~isdef("modelica_libs") | ..
10 ~isdef("scicos_pal_libs") ) then
11 [modelica_libs, scicos_pal_libs, %scicos_with_grid, %scs_wgrid]=initial_scicos_tables()
25 !Branching Events Misc Sinks Threshold Linear MatrixOp !
29 !NonLinear Sources Electrical Hydraulics PDE IntegerOp !
35 !SCI/modules/scicos_blocks/macros/Electrical !
39 !SCI/modules/scicos_blocks/macros/Hydraulics !
42 exec('SCI/modules/scicos/tests/unit_tests/scicos_tests.sci');
43 options=default_options();
45 blockslib='scs'+['Branching','Events','Misc','Sinks','Threshold','Linear', ...
46 'NonLinear','Sources','Electrical','Hydraulics']+'lib';
51 for blocklib=blockslib
52 B=string(blocklib);Blocs=[Blocs;B(2:$)];
54 Blocs(Blocs=="m_sin")=[];
56 if checkdefine() then bugmes();quit;end
57 if checkinputs() then bugmes();quit;end
58 if checkoutputs() then bugmes();quit;end
59 if checkorigin() then bugmes();quit;end
60 if checkdeput() then bugmes();quit;end
61 if checkfiring() then bugmes();quit;end
62 if check_define_ports() then bugmes();quit;end
63 if check_set_ports() then bugmes();quit;end
69 // Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
71 // - Alan Layec <alan.layec@inria.fr>
73 // Copyright (C) 2010 - DIGITEO - Clément DAVID <clement.david@scilab.org>
77 // This program is free software; you can redistribute it and/or modify
79 // it under the terms of the GNU General Public License as published by
81 // the Free Software Foundation; either version 2 of the License, or
83 // (at your option) any later version.
87 // This program is distributed in the hope that it will be useful,
89 // but WITHOUT ANY WARRANTY; without even the implied warranty of
91 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
93 // GNU General Public License for more details.
97 // You should have received a copy of the GNU General Public License
99 // along with this program; if not, write to the Free Software
101 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
105 // See the file ../license.txt
110 function [%ok,%1,%2,%3,%4,%5,...
112 %11,%12,%13,%14,%15,...
113 %16,%17,%18,%19,%20,...
114 %21,%22,%23,%24,%25,...
115 %26,%27,%28,%29,%30]=setvalue(%desc,%lables,%typ,%ini)
116 // To avoid infinite loops in set section of blocks during eval
117 if %scicos_prob==%t then
121 %11,%12,%13,%14,%15,...
122 %16,%17,%18,%19,%20,...
123 %21,%22,%23,%24,%25,...
124 %26,%27,%28,%29,%30]=(0,0,0,0,0,...
131 // setvalues - data acquisition, getvalue equivalent without dialog
133 // [%ok,x1,..,x18]=setvalue(desc,labels,typ,ini)
135 // desc : column vector of strings, dialog general comment
136 // labels : n column vector of strings, labels(i) is the label of
137 // the ith required value
138 // typ : list(typ1,dim1,..,typn,dimn)
139 // typi : defines the type of the ith required value
140 // if may have the following values:
141 // 'mat' : stands for matrix of scalars
142 // 'col' : stands for column vector of scalars
143 // 'row' : stands for row vector of scalars
144 // 'vec' : stands for vector of scalars
145 // 'str' : stands for string
146 // 'lis' : stands for list
147 // 'pol' : stands for polynomials
148 // 'r' : stands for rational
149 // dimi : defines the size of the ith required value
151 // - an integer or a 2-vector of integers (-1 stands for
152 // arbitrary dimension)
153 // - an evaluatable character string
154 // ini : n column vector of strings, ini(i) gives the suggested
155 // response for the ith required value
156 // %ok : boolean ,%t if %ok button pressed, %f if cancel button pressed
157 // xi : contains the ith required value if %ok==%t
159 // getvalues function uses ini strings to evaluate required args
160 // with error checking,
162 // All correct scilab syntax may be used as responses, for matrices
163 // and vectors getvalues automatically adds [ ] around the given response
164 // before numerical evaluation
166 // labels=['magnitude';'frequency';'phase '];
167 // [ampl,freq,ph]=setvalue('define sine signal',labels,..
168 // list('vec',1,'vec',1,'vec',1),['0.85';'10^2';'%pi/3'])
173 // 17/01/07 -Alan- - %scicos_context behavior reviewed in accordance to context_evstr macro
174 // - pass int in field of type vec/mat/row/col (F. Nassif's Work)
176 // 05/02/07 -Alan- : update to %20 rhs parameters
180 %nn=prod(size(%lables))
181 if %lhs<>%nn+2&%lhs<>%nn+1 then error(41),end
182 if size(%typ)<>2*%nn then
183 error('typ : list(''type'',[sizes],...)')
185 %1=[];%2=[];%3=[];%4=[];%5=[];
186 %6=[];%7=[];%8=[];%9=[];%10=[];
187 %11=[];%12=[];%13=[];%14=[],%15=[];
188 %16=[];%17=[];%18=[];%19=[],%20=[];
189 %21=[];%22=[];%23=[];%24=[],%25=[];
190 %26=[];%27=[];%28=[];%29=[],%30=[];
191 if %rhs==3 then %ini=emptystr(%nn,1),end
195 if %str==[] then %ok=%f,break,end
197 %cod=ascii(%str(%kk))
201 %cod(%spe)=%semi*ones(%spe')
202 %str(%kk)=ascii(%cod)
205 [%vv_list,%ierr_vec]=context_evstr(%str,%scicos_context,%typ);
210 select part(%typ(2*%kk-1),1:6)
216 //the type of %vv is accepted if it is constant or integer
217 if and(type(%vv)<>[1 8]) then %nok=-%kk,break,end
218 %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
219 [%mmmm,%nnnnn]=size(%vv)
220 %ssss=string(%sz(1))+' x '+string(%sz(2))
221 if %mmmm*%nnnnn==0 then
222 if %sz(1)>=0&%sz(2)>=0&%sz(1)*%sz(2)<>0 then %noooo=%kk,break,end
224 if %sz(1)>=0 then if %mmmm<>%sz(1) then %noooo=%kk,break,end,end
225 if %sz(2)>=0 then if %nnnnn<>%sz(2) then %noooo=%kk,break,end,end
232 //the type of %vv is accepted if it is constant or integer
233 if and(type(%vv)<>[1 8]) then %nok=-%kk,break,end
234 %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
236 %nnnnn=prod(size(%vv))
237 if %sz(1)>=0 then if %nnnnn<>%sz(1) then %noooo=%kk,break,end,end
242 //the type of %vv is accepted if it is constant or integer
243 if and(type(%vv)<>[1 8]) then %nok=-%kk,break,end
244 %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
246 %nnnnn=prod(size(%vv))
247 if %sz(1)>=0 then if %nnnnn<>%sz(1) then %noooo=%kk,break,end,end
252 if %ierr<>0 then %noooo=-%kk;break,end
253 if (type(%vv)>2 & type(%vv)<>8) then %noooo=-%kk,break,end
254 %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
256 %nnnnn=prod(size(%vv))
257 if %sz(1)>=0 then if %nnnnn<>%sz(1) then %noooo=%kk,break,end,end
263 //the type of %vv is accepted if it is constant or integer
264 if and(type(%vv)<>[1 8]) then %nok=-%kk,break,end
265 %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
269 %ssss='1 x '+string(%sz(1))
271 [%mmmm,%nnnnn]=size(%vv)
272 if %mmmm<>1 then %noooo=%kk,break,end,
273 if %sz(1)>=0 then if %nnnnn<>%sz(1) then %noooo=%kk,break,end,end
279 //the type of %vv is accepted if it is constant or integer
280 if and(type(%vv)<>[1 8]) then %nok=-%kk,break,end
281 %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
285 %ssss=string(%sz(1))+' x 1'
287 [%mmmm,%nnnnn]=size(%vv)
288 if %nnnnn<>1 then %noooo=%kk,break,end,
289 if %sz(1)>=0 then if %nnnnn<>%sz(1) then %noooo=%kk,break,end,end
293 if type(%vv)<>10 then %noooo=-%kk,break,end
294 %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
296 %nnnnn=prod(size(%vv))
297 if %sz(1)>=0 then if %nnnnn<>1 then %noooo=%kk,break,end,end
302 if type(%vv)<>15& type(%vv)<>16& type(%vv)<>17 then %noooo=-%kk,break,end
303 %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
306 if %sz(1)>=0 then if %nnnnn<>%sz(1) then %noooo=%kk,break,end,end
311 if type(%vv)<>16 then %noooo=-%kk,break,end
312 if typeof(%vv)<>'rational' then %noooo=-%kk,break,end
313 %sz=%typ(2*%kk);if type(%sz)==10 then %sz=evstr(%sz),end
314 [%mmmm,%nnnnn]=size(%vv(2))
315 %ssss=string(%sz(1))+' x '+string(%sz(2))
316 if %mmmm*%nnnnn==0 then
317 if %sz(1)>=0&%sz(2)>=0&%sz(1)*%sz(2)<>0 then %noooo=%kk,break,end
319 if %sz(1)>=0 then if %mmmm<>%sz(1) then %noooo=%kk,break,end,end
320 if %sz(2)>=0 then if %nnnnn<>%sz(2) then %noooo=%kk,break,end,end
325 str = gettext("%s: Type %s is not implemented.\n");
326 mess = msprintf(str, 'setvalue', %typ(2*%kk-1));
327 warnBlockByUID(arg1.doc(1), mess); // arg1 is from the block interface function
330 execstr('%'+string(%kk)+'=%vv')
334 str = gettext("%s: invalid dimension for ''%s'', waiting for %s");
335 mess = msprintf(str, 'setvalue', %lables(%noooo), %ssss);
336 warnBlockByUID(arg1.doc(1), mess); // arg1 is from the block interface function
340 str = gettext("%s: incorrect type for ''%s'', getting %s");
341 mess = msprintf(str, 'setvalue', %lables(-%noooo), %typ(-2*%noooo-1));
342 warnBlockByUID(arg1.doc(1), mess); // arg1 is from the block interface function
350 execstr('%'+string(%lhs-1)+'=%str')