www.pudn.com > Closid30.rar > Clximp.M, change:1999-02-08,size:5557b


function CLEVALSTRING=clximp(action,string,dat1) 
 
% function CLEVALSTRING=clximp(action,string,dat1) 
% 
% Import either: 
% (coprime factors of) auxiliary model      string='Gx' 
% (coprime factors of) controller           string='Cx'  
% auxiliary (C times) sensitivity function  string='Sx' 
% and store the information in the appropriate frame. 
% This callback is to be used in the "Import Auxiliary Model" 
% windows of Cop-fac and dual-Y identification method (for 'Gx'  
% and 'Cx') and of the two-stage method (for 'Sx'). 
 
% Functions called: clload,clobjget,th2ss,cldncf,tf2ss,clcf2dn,cldebl 
%                   clobjins 
 
% 01-11-1996 (partly based on clyuimpx and cl2scon) 
% (c) Douwe de Vries, Paul Van den Hof 
% Mechanical Engineering Systems and Control Group 
% Delft University of Technology 
% Last update: 05-06-1997 
%              08-02-1999: function th2ss replaced. 
 
if nargin < 3 
  action='start'; 
  if nargin < 2 
    error('Number of arguments of clximp is incorrect.') 
  end 
end 
if strcmp(string,'Gx') 
   option = 1; 
elseif strcmp(string,'Cx') 
   option = 2; 
elseif strcmp(string,'Sx') 
   option=3; 
else 
   error('Input argument string to clximp is invalid.') 
end 
 
% Get the userdata of the figure for reading variable names 
% and formats 
FIGUS=get(gcf,'Userdata'); 
 
% Get the format: 
if option==1 | option==3 
  frmt=get(FIGUS(6,1),'value'); 
elseif option==2 
  frmt=get(FIGUS(10,1),'value'); 
end 
 
% When Gx/C to be copied from the model/controller board, or when 
% Sx to be copied from SITB, no other input is required: 
if frmt==1 & (option==1 | option==2) 
  if option==1 
    [P,title,info,param]=clobjget('P'); 
%	if P==[], return; end 
    if param~=1 
      clerrdia(['ERROR: The highlighted model on the model board'... 
	          ' is not a parametric model']); 
	  return 
    end 
%   [a,b,c,d]=th2ss(P);s=[a b;c d];ns=length(a);  % th2ss removed, 08-02-1999. 
    [numg,deng]=th2tf(P,1);[ag,bg,cg,dg]=tf2ss(numg,deng); 
          [ag,bg,cg,dg]=minreal(ag,bg,cg,dg); 
          if isempty(ag), ag=0;bg=0;cg=0; end 
          s=[ag bg;cg dg];ns=length(ag); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% 
  elseif option==2 
    s=clobjget('C'); 
%	if s==[], return; end 
	ns=length(s)-1; 
  end 
  [AUXIL]=cldncf(s,ns,'r'); 
  CLEVALSTRING=['OK=1;']; 
elseif frmt==3 & option==3 
  [err,th]=sitb2cl; 
%  [a,b,c,d]=th2ss(th);s=[a b;c d];ns=length(na); %Removing th2ss, 08-02-1999. 
  [numg,deng]=th2tf(th,1);[ag,bg,cg,dg]=tf2ss(numg,deng); 
          [ag,bg,cg,dg]=minreal(ag,bg,cg,dg); 
          if isempty(ag), ag=0;bg=0;cg=0; end 
          s=[ag bg;cg dg];ns=length(ag); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  [AUXIL]=cldncf(s,ns,'r'); 
  CLEVALSTRING=['OK=1;']; 
% 
else 
% 
  if strcmp(action,'start'), 
% 
% Determine input strings: 
    if option==1 | option==3 
      SAUXIL=cldebl(get(FIGUS(4,1),'String')); 
      SFILENM=cldebl(get(FIGUS(15,1),'String')); 
	elseif option==2 
	  SAUXIL=cldebl(get(FIGUS(8,1),'String')); 
      SFILENM=cldebl(get(FIGUS(17,1),'String')); 
	end 
% 
% Read from workspace or window or file: 
    CLEVALSTRING=[' ']; 
    if isempty(SFILENM) 
      if option==1 
        CLEVALSTRING=['clximp(''cont'',''Gx'',' SAUXIL ');']; 
      elseif option==2 
        CLEVALSTRING=['clximp(''cont'',''Cx'',' SAUXIL ');']; 
      elseif option==3 
        CLEVALSTRING=['clximp(''cont'',''Sx'',' SAUXIL ');']; 
	  end 
      return 
    else 
      ERR=0; 
      [ERR,AUXIL]=clload(SFILENM,SAUXIL); 
      if ERR, return; end 
    end 
  elseif strcmp(action,'cont'), 
    AUXIL=dat1; 
  end 
% 
  % Check data 
  ERR=0; 
  if frmt==4 & (option==1 | option==2) 
    if  size(AUXIL,1)~=4, ERR=1; 
      elseif AUXIL(2,1)~=1, ERR=2; 
      elseif AUXIL(4,1)~=1, ERR=2;  
	end 
  end 
  if ERR==1 
    clerrdia(['ERROR IMPORTING AUXIL. MODEL/CONTROLLER: only SISO model allowed'],1); 
  elseif ERR==2 
    clerrdia(['ERROR IMPORTING AUXIL. MODEL/CONTROLLER: denominators should start with 1'],1); 
  end 
  if ERR  
    return;  
  end 
 
% Convert to correct format 
  if option==1 | option ==2 
    if frmt==2						% [numx;denx] 
      [a,b,c,d]=tf2ss(AUXIL(1,:),AUXIL(2,:)); 
      s=[a b;c d];ns=length(a);    
      AUXIL=cldncf(s,ns,'r'); 
% 
    elseif frmt==3	     			% [A B;C D] 
      ns=length(AUXIL)-1; 
      AUXIL=cldncf(AUXIL,ns,'r'); 
% 
    elseif frmt==4                     % NumNx;DenNx;NumDx;DenDx 
      [a,b,c,d]=tf2ss(AUXIL(1,:),AUXIL(2,:)); 
      NX=[a b;c d]; nNX=size(a,1); 
      [a,b,c,d]=tf2ss(AUXIL(3,:),AUXIL(4,:)); 
      DX=[a b;c d]; nDX=size(a,1); 
      AUXIL=clcf2dn(DX,NX,nDX,nNX,'r');  % DX,NX in DN-format 
% 
    elseif frmt==5					% [Andx Bndx;Cndx Dndx] 
      [a,b,c,d]=clsplit(AUXIL,length(AUXIL)-1); 
      NX=[a b;c(1,:) d(1,:)]; nNX=size(a,1); 
      DX=[a b;c(2,:) d(2,:)]; nDX=size(a,1); 
      AUXIL=clcf2dn(DX,NX,nDX,nNX,'r');  % DX,NX in DN-format 
    end 
% 
  elseif option==3 
    if frmt==1                      % [num;den] 
	  [a,b,c,d]=tf2ss(AUXIL(1,:),AUXIL(2,:)); 
      AUXIL=[a b;c d];    
    elseif frmt==2                  % [A B;C D] 
	  AUXIL=AUXIL; 
	end 
  end 
end 
 
% Store data in userdata of data object in main window 
if option==1 
  title=cldebl(get(FIGUS(4,1),'String')); 
  clobjins(AUXIL,'Xnd',title); 
elseif option==2 
  title=cldebl(get(FIGUS(8,1),'String')); 
  clobjins(AUXIL,'Cnd',title); 
elseif option==3 
  title=cldebl(get(FIGUS(4,1),'String')); 
  clobjins(AUXIL,'X',title); 
end