// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-// Copyright (C) INRIA -
-//
+// Copyright (C) INRIA -
+//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution. The terms
-// are also available at
+// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
function h=trfmod(h,job)
// hm=trfmod(h [,job])
-// To visualize the pole-zero structure of a SISO transfer function h
+// To visualize the pole-zero structure of a SISO transfer function h
// job='p' : visualization of polynomials (default)
// job='f' : visualization of natural frequencies and damping
//
else
error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space or a transfer function expected.\n"),"trfmod",1))
end
-
-
+
+
//
- format('v',15)
+ ft = format();
+ format('v', 15);
+
[lhs,rhs]=argn(0)
if rhs==1 then job='p',end
//
if type(h('num'))==1 then h('num')=poly(h('num'),varn(h('den')),'c'),end
if type(h('den'))==1 then h('den')=poly(h('den'),varn(h('num')),'c'),end
-
+
var=varn(h('num')),nv=length(var);
while part(var,nv)==' ' then nv=nv-1,end;var=part(var,1:nv);
-
+
fnum=polfact(h('num'))
fden=polfact(h('den'))
g=coeff(fnum(1))/coeff(fden(1))
num=[num;pol2str(p)]
else
if degree(p)==2 then
- p=coeff(p)
- omeg=sqrt(p(1))
- xsi=p(2)/(2*omeg)
- num=[num;string(omeg)+' '+string(xsi)]
+ p=coeff(p)
+ omeg=sqrt(p(1))
+ xsi=p(2)/(2*omeg)
+ num=[num;string(omeg)+' '+string(xsi)]
else
- num=[num;string(-coeff(p,0))]
+ num=[num;string(-coeff(p,0))]
end
end
end
den=[den;pol2str(p)]
else
if degree(p)==2 then
- p=coeff(p)
- omeg=sqrt(p(1))
- xsi=p(2)/(2*omeg)
- den=[den;string(omeg)+' '+string(xsi)]
+ p=coeff(p)
+ omeg=sqrt(p(1))
+ xsi=p(2)/(2*omeg)
+ den=[den;string(omeg)+' '+string(xsi)]
else
- den=[den;string(-coeff(p,0))]
+ den=[den;string(-coeff(p,0))]
end
end
end
-
+
txt=[_("Gain :");string(g);_("Numerator :");num;_("Denominator :");den]
-
+
id=[]
if job=='p' then
tit=[gettext("Irreducible Factors of transfer function (click below)")]
id=find(t==_("Denominator :"))
end
txt=t;
-
+
tgain=txt(2)
tnum=txt(4:id-1)
tden=txt(id+1:prod(size(txt)))
if job=='p' then
t=' ';
for k=1:length(txt),
- tk=part(txt,k),
- if tk<>' ' then t=t+tk,end
+ tk=part(txt,k),
+ if tk<>' ' then t=t+tk,end
end
f=1;if t<>' ' then f=evstr(t),end
else
if txt==part(' ',1:length(txt)) then
- f=1
+ f=1
else
- f=evstr(txt)
- select prod(size(f))
- case 1 then
- f=poly(f,var)
- case 2 then
- f=poly([f(1)*f(1), 2*f(1)*f(2),1],var,'c')
- else
- error(msprintf(gettext("%s: Incorrect answer.\n"),"trfmod"))
- end
+ f=evstr(txt)
+ select prod(size(f))
+ case 1 then
+ f=poly(f,var)
+ case 2 then
+ f=poly([f(1)*f(1), 2*f(1)*f(2),1],var,'c')
+ else
+ error(msprintf(gettext("%s: Incorrect answer.\n"),"trfmod"))
+ end
end
end
num=num*f
if job=='p' then
t=' ';
for k=1:length(txt),
- tk=part(txt,k),
- if tk<>' ' then t=t+tk,end
+ tk=part(txt,k),
+ if tk<>' ' then t=t+tk,end
end
f=1;if t<>' ' then f=evstr(t),end
else
if txt==part(' ',1:length(txt)) then
- f=1
+ f=1
else
- f=evstr(txt)
- select prod(size(f))
- case 1 then
- f=poly(f,var)
- case 2 then
- f=poly([f(1)*f(1), 2*f(1)*f(2),1],var,'c')
- else
- error(msprintf(gettext("%s: Incorrect answer.\n"),"trfmod"))
- end
+ f=evstr(txt)
+ select prod(size(f))
+ case 1 then
+ f=poly(f,var)
+ case 2 then
+ f=poly([f(1)*f(1), 2*f(1)*f(2),1],var,'c')
+ else
+ error(msprintf(gettext("%s: Incorrect answer.\n"),"trfmod"))
+ end
end
end
den=den*f
x=evstr(tgain)/coeff(den,degree(den))
h('num')=num*x
h('den')=den/coeff(den,degree(den))
- format(10)
+ format(ft(2),ft(1));
if flag=='lss' then h=tf2ss(h),end
endfunction
//
// See the file ../license.txt
//
-function [ok,t]=cos2xml(scs_m,name,atomicflag)
- ok=%t;t=[];format(20);
- if argn(2)<3 then atomicflag=%f,end
- if exists('scicos_scicoslib')==0 then load("SCI/modules/scicos/macros/scicos_scicos/lib") ;,end
+function [ok, t] = cos2xml(scs_m, name, atomicflag)
+ ok = %t;
+ t=[];
+ ft = format();
+ format(20);
+ if argn(2)<3 then atomicflag=%f,end
+ if exists('scicos_scicoslib') ==0 then load("SCI/modules/scicos/macros/scicos_scicos/lib"),end
exec(loadpallibs,-1) //to load the palettes libraries
Bn='OBJ';
tit=scs_m.props.title(1);
version=scs_m.version
- if exists('supername') then
+ if exists('supername') then
Bn=supername+'_',
if atomicflag then flg='yes'; else flg='no';end
head=[' <Diagram Name=""'+tit+'"">'
' <ScicosVersion Name=""'+version+'"" />'
- ' <AtomicDiagram Atomic=""'+flg+'"" />']
+ ' <AtomicDiagram Atomic=""'+flg+'"" />']
tail=[' </Diagram>']
[%scicos_context,ierr]=script2var(scs_m.props.context,%scicos_context)
else
head=['<?xml version=""1.0"" encoding=""UTF-8""?>'
' <ScicosModel Name=""'+tit+'"" >'
' <Diagram Name=""'+tit+'"">'
- ' <ScicosVersion Name=""'+version+'"" />']
+ ' <ScicosVersion Name=""'+version+'"" />']
tail=[
' </Diagram>'
' </ScicosModel>']
o=objs(k)
x=getfield(1,o);
if x(1)=='Block' then
- //disp('it is block');//pause
+ //disp('it is block');//pause
if o.model.sim=='super'|o.model.sim=='csuper'|o.model.sim(1)=='asuper' then
- supername=name
- t=[t;
- '<Block Name=""'+name+'"" >']
- if o.model.sim(1)=='asuper' then
- atomicflag=%t;
- [ok,t1]=cos2xml(o.model.rpar,name,%t);
- else
- atomicflag=%f;
- [ok,t1]=cos2xml(o.model.rpar,name,%f);
- end
- if ~ok then t=[];ok=%f;return; end
- xml_txt=block2xml(o,2,t1,atomicflag)
- t=[t;
- xml_txt;
- '</Block>' ]
+ supername=name
+ t=[t;
+ '<Block Name=""'+name+'"" >']
+ if o.model.sim(1)=='asuper' then
+ atomicflag=%t;
+ [ok,t1]=cos2xml(o.model.rpar,name,%t);
+ else
+ atomicflag=%f;
+ [ok,t1]=cos2xml(o.model.rpar,name,%f);
+ end
+ if ~ok then t=[];ok=%f;return; end
+ xml_txt=block2xml(o,2,t1,atomicflag)
+ t=[t;
+ xml_txt;
+ '</Block>' ]
else //standard block
xml_txt=block2xml(o,1);
- t=[t;
- '<Block Name=""'+name+'"" >';
- xml_txt;
- '</Block>'];
+ t=[t;
+ '<Block Name=""'+name+'"" >';
+ xml_txt;
+ '</Block>'];
end
elseif x(1)=='Deleted' then
t=[t;' <Deleted Name=""'+name+'""></Deleted>']
t=[t;
'<Text Name=""'+name+'"" >';
xml_txt;
- '</Text>'];
+ '</Text>'];
else //links
xml_txt=block2xml(o);
t=[t;
end //end of loop on objects
t=[t;
'</Objects>'];
-t=[head;' '+t;tail]
+ t=[head;' '+t;tail]
+
+ format(ft(2),ft(1));
+
endfunction
function xml_txt=block2xml(o,flag,t1,atomicflag)
for i=2:size(x,'*')
if x(i)=='context' then
xml_txt=[xml_txt;
- ' <'+x(1)+' id='''+x(i)+''' >';
- ' '+xml_subst(sci2exp(o(x(i)),0));
- ' </'+x(1)+'>'];
+ ' <'+x(1)+' id='''+x(i)+''' >';
+ ' '+xml_subst(sci2exp(o(x(i)),0));
+ ' </'+x(1)+'>'];
elseif x(1)=='Link'|(x(1)=='params' & x(i)<>'options') then
xml_txt=[xml_txt;
- ' <'+x(1)+' id='''+x(i)+''' value='''+sci2exp(o(x(i)),0)+''' />'];
+ ' <'+x(1)+' id='''+x(i)+''' value='''+sci2exp(o(x(i)),0)+''' />'];
elseif x(i)=='doc'|x(i)=='void'| x(i)=='gui' then
//S. Steer strcat added because of a bug in sci2exp for functions
xml_txt=[xml_txt;
- ' <'+x(i)+' id='''+x(i)+''' value='''+strcat(sci2exp(o(x(i)),0))+''' />'];
+ ' <'+x(i)+' id='''+x(i)+''' value='''+strcat(sci2exp(o(x(i)),0))+''' />'];
else
if x(i)<>'model' then
xml_txt=[xml_txt;
- ' <'+x(1)+' id='''+x(i)+''' >'];
+ ' <'+x(1)+' id='''+x(i)+''' >'];
end
xx=getfield(1,evstr('o.'+x(i)));
for j=2:size(xx,'*')
- if x(i)=='model' & xx(j)<>'rpar'
+ if x(i)=='model' & xx(j)<>'rpar'
elseif xx(j)=='gr_i' then
- xml_txt=[xml_txt;
- ' <'+x(i)+' id='''+xx(j)+'''>';
- ' '+xml_subst(sci2exp(o(x(i))(xx(j)),0));
- ' </'+x(i)+'>'];
+ xml_txt=[xml_txt;
+ ' <'+x(i)+' id='''+xx(j)+'''>';
+ ' '+xml_subst(sci2exp(o(x(i))(xx(j)),0));
+ ' </'+x(i)+'>'];
elseif xx(j)=='exprs' then
- if flag==2 & atomicflag then
- xml_txt=[xml_txt;
- ' <'+x(i)+' id='''+xx(j)+'''>';
- ' <p>'+xml_subst(sci2exp(o(x(i))(xx(j))(1),90))+'</p>';
- ' </'+x(i)+'>'];
- else
- xml_txt=[xml_txt;
- ' <'+x(i)+' id='''+xx(j)+'''>';
- ' <p>'+xml_subst(sci2exp(o(x(i))(xx(j)),90))+'</p>';
- ' </'+x(i)+'>'];
- end
+ if flag==2 & atomicflag then
+ xml_txt=[xml_txt;
+ ' <'+x(i)+' id='''+xx(j)+'''>';
+ ' <p>'+xml_subst(sci2exp(o(x(i))(xx(j))(1),90))+'</p>';
+ ' </'+x(i)+'>'];
+ else
+ xml_txt=[xml_txt;
+ ' <'+x(i)+' id='''+xx(j)+'''>';
+ ' <p>'+xml_subst(sci2exp(o(x(i))(xx(j)),90))+'</p>';
+ ' </'+x(i)+'>'];
+ end
elseif xx(j)=='rpar' & flag==2 then
- xml_txt=[xml_txt;
- ' <Block id=''diagram'' >';
- ' '+t1;
- ' </Block>'];
+ xml_txt=[xml_txt;
+ ' <Block id=''diagram'' >';
+ ' '+t1;
+ ' </Block>'];
elseif xx(j)=='rpar' then
- xml_txt=[xml_txt;
- ' <'+x(1)+' id=''diagram'' >';
- ' </'+x(1)+'>'];
+ xml_txt=[xml_txt;
+ ' <'+x(1)+' id=''diagram'' >';
+ ' </'+x(1)+'>'];
elseif xx(j)=='3D' then
- xml_txt=[xml_txt;
- ' <'+x(i)+' id='''+xx(j)+''' value='''+sci2exp(o(x(i))(j),0)+''' />'];
+ xml_txt=[xml_txt;
+ ' <'+x(i)+' id='''+xx(j)+''' value='''+sci2exp(o(x(i))(j),0)+''' />'];
else
- xml_txt=[xml_txt;
- ' <'+x(i)+' id='''+xx(j)+''' value='''+xml_subst(strsubst(sci2exp(o(x(i))(xx(j)),0),' ',''))+''' />'];
+ xml_txt=[xml_txt;
+ ' <'+x(i)+' id='''+xx(j)+''' value='''+xml_subst(strsubst(sci2exp(o(x(i))(xx(j)),0),' ',''))+''' />'];
end
end
if x(i)<>'model' then
xml_txt=[xml_txt;
- ' </'+x(1)+'>'];
+ ' </'+x(1)+'>'];
end
end
end