043d13272c669d7cf1a399a6efccf27331aaa8fd
[scilab.git] / scilab / modules / scicos_blocks / macros / NonLinear / LOOKUP_f.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]=LOOKUP_f(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;rpar=model.rpar;
37         n=size(rpar,"*")/2
38         xx=rpar(1:n);yy=rpar(n+1:2*n)
39         while %t do
40             [ln,fun]=where();
41
42             if ~or(fun == "do_eval") then // cas standard
43                 [xx,yy,ok,gc] = edit_curv(xx,yy,"axy");
44             else
45                 ok=%t
46             end  // no need anymore to overload edit_curv in do_eval
47
48             if ~ok then break,end
49             n=size(xx,"*")
50             if or(xx(2:n)-xx(1:n-1)<=0) then
51                 message("You have not defined a function")
52                 ok=%f
53             end
54             if ok then
55                 model.rpar=[xx(:);yy(:)]
56                 x.graphics=graphics;x.model=model
57                 break
58             end
59         end
60     case "define" then
61         model=scicos_model()
62         model.sim="lookup"
63         model.in=1
64         model.out=1
65         model.rpar=[-2;-1;1;2;-1;1;-1;1]
66         model.blocktype="c"
67         model.dep_ut=[%t %f]
68
69         gr_i=["rpar=model.rpar;n=size(rpar,''*'')/2;";
70         "thick=xget(''thickness'');xset(''thickness'',2);";
71         "xx=rpar(1:n);yy=rpar(n+1:2*n);";
72         "mnx=min(xx);xx=xx-mnx*ones(xx);mxx=max(xx);";
73         "xx=orig(1)+sz(1)*(1/10+(4/5)*xx/mxx);";
74         "mnx=min(yy);yy=yy-mnx*ones(yy);mxx=max(yy);";
75         "yy=orig(2)+sz(2)*(1/10+(4/5)*yy/mxx);";
76         "xpoly(xx,yy,''lines'');";
77         "xset(''thickness'',thick);"]
78         x=standard_define([2 2],model,[],gr_i)
79     end
80 endfunction