* Bug #12619 fixed - The discrete block DLR was not displaying latex formula
[scilab.git] / scilab / modules / scicos_blocks / macros / Linear / DLR.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]=DLR(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         x0=model.dstate;ns=prod(size(x0));
38         %scicos_context=%scicos_context; //copy the semi-global variable locally
39         %scicos_context.z=%z //add z definition to the context
40         while %t do
41             [ok,num,den,exprs]=scicos_getvalue("Set discrete SISO transfer parameters",..
42             ["Numerator (z)";
43             "Denominator (z)"],..
44             list("pol",1,"pol",1),exprs)
45             if ~ok then break,end
46             if degree(num)>degree(den) then
47                 message("Transfer function must be proper")
48                 ok=%f
49             end
50             if ok then
51                 H=cont_frm(num,den)
52                 [A,B,C,D]=H(2:5);
53                 graphics.exprs=exprs;
54                 [ns1,ns1]=size(A)
55                 if ns1<=ns then
56                     x0=x0(1:ns1)
57                 else
58                     x0(ns1,1)=0
59                 end
60                 rpar=[A(:);
61                 B(:);
62                 C(:);
63                 D(:)]
64                 model.dstate=x0
65                 model.rpar=rpar
66                 if norm(D,1)<>0 then
67                     mmm=[%t %f];
68                 else
69                     mmm=[%f %f];
70                 end
71                 if or(model.dep_ut<>mmm) then
72                 model.dep_ut=mmm,end
73                 x.graphics=graphics;x.model=model
74                 break
75             end
76         end
77         x.model.firing=[] //compatibility
78     case "define" then
79         x0=0;A=-1;B=1;C=1;D=0;
80         exprs=["1";"1+z"]
81
82         model=scicos_model()
83         model.sim=list("dsslti4",4)
84         model.in=1
85         model.out=1
86         model.evtin=1
87         model.dstate=x0(:)
88         model.rpar=[A(:);B(:);C(:);D(:)]
89         model.blocktype="d"
90         model.dep_ut=[%f %f]
91
92         gr_i=["xstringb(orig(1),orig(2),[''num(z)'';''den(z)''],sz(1),sz(2),''fill'')";
93         "xpoly([orig(1)+.1*sz(1),orig(1)+.9*sz(1)],[1,1]*(orig(2)+sz(2)/2))"]
94         x=standard_define([4 3],model,exprs,gr_i)
95     end
96 endfunction