www.pudn.com > Closid30.rar > CLMCIMP.M, change:1997-06-18,size:3688b


function CLEVALSTRING=clmcimp(action,string,dat1) 
% function CLEVALSTRING=clmcimp(action,string,dat1) 
% 
% Callback for model/controller import 
% and storing information in the GUI. 
% 
% action: 
% dat1: 
% string: 'M': model'; 'C': controller. 
 
% Functions called: cldebl, clmcimp, clload, clobjins, clsplit, 
%                   poly2th,ss2tf,tf2ss,th2ss            
 
% 01-11-1997 originally named clmodimp-clctlimp 
% (c) Douwe de Vries, Paul Van den Hof 
% Mechanical Engineering Systems and Control Group 
% Delft University of Technology 
% Last update: 17-06-1997 
  
 
if strcmp(string,'M') 
   option1 = 1; 
elseif strcmp(string,'C') 
   option1 = 2; 
else 
   error('Input argument string to clmcimp is invalid.') 
end 
 
% Defaults 
if nargin==0,action='start';end 
 
% Get the data 
FIGUS=get(gcf,'Userdata'); 
 
if strcmp(action,'start'), 
 
   % Determine input strings 
   SCONTR=cldebl(get(FIGUS(6,1),'String')); 
   SFILENM=cldebl(get(FIGUS(11,1),'String')); 
 
   % Read from workspace or window or file 
   CLEVALSTRING=[' ']; 
   if isempty(SFILENM) 
     if option1==1 
       CLEVALSTRING=['clmcimp(''cont'',''M'',' SCONTR ');']; 
     elseif option1==2 
       CLEVALSTRING=['clmcimp(''cont'',''C'',' SCONTR ');']; 
     end 
     return 
   else 
      ERR=0; 
      [ERR,CONTR]=clload(SFILENM,SCONTR); 
      if ERR, return; end 
   end 
 
elseif strcmp(action,'cont'), 
   CONTR=dat1; 
end 
 
% Get the format 
if get(FIGUS(4,1),'value')==1        % [num;den] 
   frmt=1; 
elseif get(FIGUS(4,1),'value')==2    % [A B;C D] 
   frmt=2; 
elseif get(FIGUS(4,1),'value')==3    % theta 
   frmt=3; 
elseif get(FIGUS(4,1),'value')==4    % freqfunc 
   frmt=4; 
end 
 
% Check data 
ERR=0; 
if frmt==1 
   if size(CONTR,1)~=2, ERR=1; end 
   if CONTR(2,1)~=1, ERR=2; end 
elseif frmt==2 
   if strcmp(string,'C') 
     if size(CONTR,1)~=size(CONTR,2), ERR=4; end 
   elseif strcmp(string,'M') 
     if size(CONTR,1)~=size(CONTR,2) & size(CONTR,1)~=size(CONTR,2)-1 
	   ERR=5; 
	 end 
   end 
elseif frmt==4 
   a=find(CONTR(1,:)==1); 
   b=find(CONTR(1,:)==21); 
   c=find(CONTR(1,:)==101); 
   if isempty(a)|isempty(b)|isempty(c)|size(CONTR,1)<size(CONTR,2)  
     ERR=3;  
   end 
end 
 
if ERR==1 
 clerrdia(['ERROR IMPORTING MODEL/CONTROLLER: object has >1 outputs'],1); 
elseif ERR==2 
 clerrdia(['ERROR IMPORTING MODEL/CONTROLLER: denominator should start with 1'],1); 
elseif ERR==3 
 clerrdia(['ERROR IMPORTING MODEL: Freqfunc format is not correct'],1); 
elseif ERR==4 
 clerrdia(['ERROR IMPORTING CONTROLLER: no SISO controller'],1); 
elseif ERR==5 
 clerrdia(['ERROR IMPORTING MODEL: i/o dimensions not correct'],1); 
end 
if ERR, return; end 
 
% Convert parametric models to theta-format: 
if option1==1 
  if frmt==1 
    CONTR=poly2th(1,CONTR(1,:),1,1,CONTR(2,:),[],1); 
  elseif frmt==2 
    [a,b,c,d]=clsplit(CONTR,size(CONTR,1)-1); 
    na=size(a); 
    if size(d,2)==1,  
      [num,den]=ss2tf(a,b,c,d); 
      CONTR=poly2th(1,num,1,1,den,[],1); 
    elseif size(d,2)==2 & d(1,2)==1, 
      [numg,deng]=ss2tf(a,b(:,1),c,d(:,1),1); 
	  [numh,denh]=ss2tf(a,b(:,2),c,1,1); 
	  CONTR=poly2th(1,numg,1,1,deng,[],1); 
	end 
  end 
% Convert controllers to system-format: 
elseif option1==2 
  if frmt==1 
    [a,b,c,d]=tf2ss(CONTR(1,:),CONTR(2,:)); 
    CONTR=[a b;c d]; 
  elseif frmt==3 
    [a,b,c,d]=th2ss(CONTR); 
    CONTR=[a b;c d]; 
  end 
end 
 
% Set indicator for nonparametric model: 
if frmt==4 
  param=0; 
else 
  param=1; 
end 
 
% Store data in userdata of data object in main window 
title=cldebl(get(FIGUS(6,1),'String')); 
if option1==1 
 clobjins(CONTR,'P',title,' ',param); 
elseif option1==2 
 clobjins(CONTR,'C',title); 
end