error(number): converting occurrences remaining in all .sce .sci files
[scilab.git] / scilab / modules / cacsd / macros / repfreq.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 1984 - 2011 - INRIA - Serge STEER
3 //
4 // Copyright (C) 2012 - 2016 - Scilab Enterprises
5 //
6 // This file is hereby licensed under the terms of the GNU GPL v2.0,
7 // pursuant to article 5.3.4 of the CeCILL v.2.1.
8 // This file was originally licensed under the terms of the CeCILL v2.1,
9 // and continues to be available under such terms.
10 // For more information, see the COPYING file which you should have received
11 // along with this program.
12
13 function [frq,rep,splitf]=repfreq(sys,fmin,fmax,pas)
14
15     pas_def="auto";
16     l10=log(10);
17     [lhs,rhs]=argn(0)
18     //discretization
19     if and(typeof(sys)<>[ "rational" "state-space" "zpk"]) then
20         args=["sys","fmin","fmax","pas"];
21         ierr=execstr("[frq,rep,splitf]=%"+overloadname(sys)+"_repfreq("+strcat(args(1:rhs),",")+")","errcatch")
22         if ierr<>0 then
23             msg = gettext("%s: Wrong type for input argument #%d: Linear dynamical system expected.\n")
24             error(msprintf(msg, "repfreq", 1))
25         end
26         return
27     end
28     if typeof(sys)=="zpk" then sys=zpk2tf(sys);end
29     dom=sys.dt
30     if dom==[] | dom==0 then
31         msg = gettext("%s: Argument #%d: Undefined time domain.\n")
32         error(msprintf(msg, "repfreq", 1));
33     end
34     if dom=="d" then dom=1;end
35
36     select  rhs
37     case 1 then
38         pas=pas_def
39         if dom=="c" then fmax=1.d3; else fmax=1/(2*dom),end
40         fmin=0
41     case 2 then
42         if type(fmin)==10 then
43             rhs=1
44             pas=pas_def
45             if dom=="c" then fmax=1.d3; else fmax=1/(2*dom),end
46             if fmin=="sym" then
47                 fmin=-fmax
48             else
49                 fmin=0
50             end
51         else
52             frq=fmin
53         end
54     case 3 then
55         pas=pas_def
56     case 4 then ,
57     else
58         msg = gettext("%s: Wrong number of input arguments: %d to %d expected.\n")
59         error(msprintf(msg, "repfreq", 1, 4))
60     end;
61     splitf=1
62     if rhs<>2 then
63         if fmin==[] then
64             fmin=0,
65         end
66         if fmax==[]|fmax==%inf then
67             if dom=="c" then
68                 fmax=1.d3;
69             else
70                 fmax=1/(2*dom);
71             end
72         end
73
74         if type(pas)==1 then
75             splitf=1
76             eps=1.e-14
77             if fmin<0&fmax>=0 then
78                 frq=- [exp(l10*((log(eps)/l10):pas:(log(-fmin)/l10))) -fmin];
79                 if fmax>eps then
80                     frq1=[exp(l10*((log(eps)/l10):pas:(log(fmax)/l10))) fmax];
81                     frq=[frq($:-1:1) frq1]
82                 else
83                     frq=frq($:-1:1);
84                 end
85             elseif fmin<0&fmax<0 then
86                 frq= [exp(l10*((log(-fmax)/l10):pas:(log(-fmin)/l10))) -fmin];
87                 frq=-frq($:-1:1);
88             elseif fmin >= fmax then
89                 msg = gettext("%s: Wrong value for input arguments #%d and #%d: %s < %s expected.\n")
90                 error(msprintf(msg, "repfreq", 2, 3, "fmin", "fmax"));
91             else
92                 fmin=max(eps,fmin);
93                 frq=[exp(l10*((log(fmin)/l10):pas:(log(fmax)/l10))) fmax];
94             end
95         else
96             [frq,bnds,splitf]=calfrq(sys,fmin,fmax)
97         end;
98     end
99     //
100     typ=sys(1)
101     select typ(1)
102     case "r" then
103         [n,d]=sys(["num","den"]),
104         [mn,nn]=size(n)
105         if nn<>1 then
106             msg = gettext("%s: Argument #%d: %s expected.\n")
107             error(msprintf(msg, "repfreq", 1, _("SISO system")))
108         end
109         if dom=="c" then
110             rep=freq(n,d,2*%pi*%i*frq),
111         else
112             rep=freq(n,d,exp(2*%pi*%i*dom*frq)),
113         end;
114     case "lss" then
115         [a,b,c,d]=abcd(sys)
116         [mn,nn]=size(d)
117         if nn<>1 then
118             msg = gettext("%s: Argument #%d: %s expected.\n")
119             error(msprintf(msg, "repfreq", 1, _("SISO system")))
120         end
121
122         if dom=="c" then
123             if a==[] then
124                 rep=(d*2*%pi*%i)*frq
125             else
126                 rep=freq(a,b,c,d,2*%pi*%i*frq)
127             end
128         else
129             if a==[] then
130                 rep=d*exp(2*%pi*%i*dom*frq)
131             else
132                 rep=freq(a,b,c,d,exp(2*%pi*%i*dom*frq))
133             end
134         end;
135     else
136         msg = gettext("%s: Argument #%d: A system in state space or transfer matrix form expected.\n")
137         error(msprintf(msg, "repfreq", 1))
138     end;
139     //representation
140     if lhs==1 then frq=rep,end
141 endfunction