* Bug 16320 fixed: typos in blocks interfaces + a few files
[scilab.git] / scilab / modules / scicos_blocks / macros / Misc / BOUNCE.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]=BOUNCE(job,arg1,arg2)
23     x=[];
24     y=[];
25     typ=[];
26     select job
27     case "set" then
28         x=arg1;
29         graphics=arg1.graphics;
30         exprs=graphics.exprs
31         model=arg1.model;
32         if size(exprs,"*")<9 then
33             exprs(8)="9.81";
34             exprs(9)="0";
35         end
36         while %t do
37             [ok,rpar1,rpar2,walls,xt,xd,y,yd,g,C,exprs]=scicos_getvalue(..
38             msprintf(_("Set %s block parameters"), "BOUNCE"),..
39             [_("Mass");
40              _("Radius");
41              "[xmin,xmax,ymin,ymax]";
42              "xpos";
43              "xdpos";
44              "ypos";..
45              "ydpos";
46              _("g (gravity)");
47              _("C (aerodynamic coeff)")],..
48             list("vec",-1,"vec",-1,"vec",-1,"vec",-1,"vec",-1,..
49             "vec",-1,"vec",-1,"vec",1,"vec",1),exprs)
50             if ~ok then
51                 break,
52             end
53             xt=xt(:);
54             y=y(:);
55             xd=xd(:);
56             yd=yd(:);
57             rpar1=rpar1(:);
58             rpar2=rpar2(:);
59             n=size(xt,"*");
60             walls=walls(:);
61             if walls(1)>walls(2) then
62                 walls=walls([2,1]);
63             end
64             if walls(3)>walls(3) then
65                 walls=walls([3,4]);
66             end
67             if n<>size(y,"*")|n<>size(rpar1,"*")|n<>size(rpar2,"*")|..
68                 n<>size(xd,"*")|n<>size(yd,"*") then
69                 message(_("All vectors must have the same size"))
70                 ok=%f
71             elseif ~(min([rpar1;rpar2])>0) then
72                 message(_("Mass and radius must be > 0"))
73                 ok=%f
74             end
75             if ~ok then
76                 break,
77             end
78             [model,graphics,ok]=check_io(model,graphics,[],[n,n],[],[])
79             if ok then
80                 k=1;ipar=[];
81                 for i=1:n
82                     for j=i+1:n
83                         ipar(k)=i
84                         k=k+1
85                         ipar(k)=j
86                         k=k+1
87                     end
88                 end
89                 model.rpar=[rpar1;rpar2;walls;g;C];
90                 model.ipar=ipar;
91                 state=[xt,xd,y,yd];
92                 state=state';
93                 model.state=state(:)
94                 model.nzcross=n*(n-1)/2+4*n;
95                 graphics.exprs=exprs;
96                 x.graphics=graphics;
97                 x.model=model
98                 break
99             end
100         end
101     case "define" then
102         n=2
103         k=1;ipar=[];
104         for i=1:n
105             for j=i+1:n
106                 ipar(k)=i
107                 k=k+1
108                 ipar(k)=j
109                 k=k+1
110             end
111         end
112         walls=[0;5;0;5]
113         x=[2;2.5];
114         xd=[0;0];
115         y=[3;5];
116         yd=[0;0];
117         g=9.81;
118         C=0
119         rpar1=ones(n,1);
120         rpar2=rpar1;
121         state=[x,xd,y,yd];
122         state=state';
123         model=scicos_model()
124         model.sim=list("bounce_ball",4)
125         model.in=[]
126         model.out=[n;n]
127         model.state=state(:)
128         model.rpar=[rpar1;rpar2;walls;g;C];
129         model.ipar=ipar;
130         model.nzcross=n*(n-1)/2+4*n;
131         model.blocktype="c"
132         model.dep_ut=[%f %t]
133
134         exprs=[strcat(sci2exp(rpar1));strcat(sci2exp(rpar2));strcat(sci2exp(walls));strcat(sci2exp(x));strcat(sci2exp(xd));strcat(sci2exp(y));strcat(sci2exp(yd))]
135         gr_i=[]
136         x=standard_define([3 2],model,exprs,gr_i)
137     end
138 endfunction