Scicos_blocks: clean NonLinear blocks interfaces
[scilab.git] / scilab / modules / scicos_blocks / macros / NonLinear / PRODUCT.sci
1 //  Scicos
2 //
3 //  Copyright (C) INRIA - METALAU Project <scicos@inria.fr>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 //
19 // See the file ../license.txt
20 //
21
22 function [x,y,typ] = PRODUCT(job,arg1,arg2)
23     x=[];
24     y=[];
25     typ=[];
26     select job
27     case "set" then
28         x=arg1;
29         graphics=arg1.graphics
30         model=arg1.model
31         exprs=graphics.exprs
32         while %t do
33             [ok,sgn,exprs]=scicos_getvalue(["         Set multiplication block parameters";
34             "(multiplication is set with + 1, division with -1)";""],...
35             "Number of inputs or sign vector",...
36             list("vec",-1),exprs)
37             if ~ok then
38                 break,
39             end
40             sgn=sgn(:);
41             if size(sgn,1)==1 then
42                 if sgn<1 then
43                     message("Number of inputs must be > 0")
44                     ok=%f
45                 elseif sgn==1 then
46                     in=-1
47                     sgn=[]
48                     nout=1
49                 else
50                     in=-ones(sgn,1)
51                     sgn=ones(sgn,1)
52                     nout=-1
53                 end
54             else
55                 if ~and(abs(sgn)==1) then
56                     message("Signs can only be +1 or -1")
57                     ok=%f
58                 else
59                     in=-ones(size(sgn,1),1)
60                     nout=-1
61                 end
62             end
63             if ok then
64                 [model,graphics,ok]=check_io(model,graphics,in,nout,[],[])
65             end
66             if ok then
67                 model.ipar=sgn
68                 graphics.exprs=exprs
69                 x.graphics=graphics;
70                 x.model=model
71                 break
72             end
73         end
74     case "define" then
75         sgn=[1;-1]
76         model=scicos_model()
77         model.sim=list("product",4)
78         model.in=[-1;-1]
79         model.out=-1
80         model.ipar=sgn
81         model.blocktype="c"
82         model.dep_ut=[%t %f]
83
84
85         exprs=sci2exp(sgn)
86         gr_i=[]
87         x=standard_define([2 3],model, exprs,gr_i)
88     end
89 endfunction