e437d80a78b768705453779279f62f4c20e3da8f
[scilab.git] / scilab / modules / scicos_blocks / macros / NonLinear / SATURATION.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]=SATURATION(job,arg1,arg2)
23     x=[];y=[];typ=[];
24     select job
25     case "plot" then
26         standard_draw(arg1)
27     case "getinputs" then
28         [x,y,typ]=standard_inputs(arg1)
29     case "getoutputs" then
30         [x,y,typ]=standard_outputs(arg1)
31     case "getorigin" then
32         [x,y]=standard_origin(arg1)
33     case "set" then
34         x=arg1;
35         graphics=arg1.graphics;exprs=graphics.exprs
36         model=arg1.model;
37         while %t do
38             [ok,maxp,minp,zeroc,exprs]=scicos_getvalue("Set Saturation parameters",..
39             ["Upper limit";"Lower limit";"zero crossing (0:no, 1:yes)"],list("vec",1,"vec",1,"vec",1),exprs)
40             if ~ok then break,end
41             if maxp<=minp  then
42                 message("Upper limit must be > Lower limit")
43             else
44                 rpar=[maxp;minp]
45                 model.rpar=rpar
46                 if zeroc<>0 then
47                     model.nzcross=2
48                     model.nmode=1
49                 else
50                     model.nzcross=0
51                     model.nmode=0
52                 end
53                 graphics.exprs=exprs
54                 x.graphics=graphics;x.model=model
55                 break
56             end
57         end
58     case "define" then
59         minp=-1;maxp=1;rpar=[maxp;minp]
60         model=scicos_model()
61         model.sim=list("satur",4)
62         model.in=1
63         model.nzcross=2
64         model.nmode=1
65         model.out=1
66         model.rpar=rpar
67         model.blocktype="c"
68         model.dep_ut=[%t %f]
69
70         exprs=[string(maxp);string(minp);string(model.nmode)]
71         gr_i=["thick=xget(''thickness'');xset(''thickness'',2);";
72         "xx=orig(1)+[4/5;1/2+1/5;1/2-1/5;1/5]*sz(1);";
73         "yy=orig(2)+[1-1/5;1-1/5;1/5;1/5]*sz(2);";
74         "xpoly(xx,yy,''lines'');";
75         "xset(''thickness'',thick)"]
76         x=standard_define([2 2],model,exprs,gr_i)
77     end
78 endfunction