* Bug 16320 fixed: typos in blocks interfaces + a few files
[scilab.git] / scilab / modules / scicos_blocks / macros / Events / M_freq.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]=M_freq(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,frequ,offset,exprs]=scicos_getvalue(..
34             msprintf(_("Set %s block parameters"), "M_freq"),..
35             _(["Sample time";"Offset"]),..
36             list("vec",-1,"vec",-1),exprs)
37             if ~ok then
38                 break,
39             end
40             offset=offset(:);
41             frequ=frequ(:);
42             if (size(frequ,"*"))<>(size(offset,"*")) then
43                 message(_("The offset and frequency must have the same size"));
44                 ok=%f;
45             elseif or(frequ<0) then
46                 message(_("The frequency must be a positive number"));
47                 ok=%f;
48             elseif or(abs(offset) > frequ) then
49                 message(_("The |Offset| must be less than the Frequency"));
50                 ok=%f
51             end
52             if ok then
53                 [m,den,off,count,m1,fir,frequ,offset,ok]=mfrequ_clk(frequ,offset);
54             end
55             if ok then
56                 model.opar=list(m,double(den),off,count)
57                 mn=(2**size(m1,"*"))-1;
58                 [model,graphics,ok]=set_io(model,graphics,list(),list(),1,ones(mn,1))
59                 if mn>3 then
60                     graphics.sz=[40+(mn-3)*10 40]
61                 else
62                     graphics.sz=[50 40]
63                 end
64                 model.firing=fir;
65                 graphics.exprs=exprs
66                 x.graphics=graphics
67                 x.model=model
68                 break
69             end
70         end
71     case "define" then
72         model=scicos_model()
73         model.sim=list("m_frequ",4)
74         model.evtout=[1;1;1]
75         model.evtin=1
76         model.rpar=[]
77         model.opar=list([1 1 0;1 1 1;1 3 2],1,0,0);
78         model.blocktype="d"
79         model.firing=[0 -1 -1]
80         model.dep_ut=[%f %f]
81         exprs=[sci2exp([1;2]);sci2exp([0;0])]
82         gr_i=[]
83         x=standard_define([3 2],model,exprs,gr_i)
84     end
85 endfunction
86
87 function [m,k]=uni(fr,of)
88     k=[];
89     m=[];
90     ot=[];
91     for i=1:size(fr,"*")
92         istreated=%f;
93         ind=find(m==fr(i));
94         if ind==[] then
95             m=[m;fr(i)];
96             ot=[ot;of(i)];
97             k=[k;i];
98         else
99             for j=ind
100                 if of(i)==ot(j) then
101                     istreated=%t
102                 end
103             end
104             if ~istreated then
105                 m=[m;fr(i)];
106                 ot=[ot;of(i)]
107                 k=[k;i];
108             end
109         end
110     end
111 endfunction