www.pudn.com > Closid30.rar > CLDATIMP.M, change:1998-09-13,size:3707b


function CLEVALSTRING=cldatimp(action,dat1,dat2,dat3,dat4) 
% function CLEVALSTRING=cldatimp(action,dat1,dat2,dat3,dat4) 
% 
% Function file for callback of data import 
% reading input and storing it in the data frame 
 
% Functions called: cldebl,clerrdia,clobjins 
 
% 01-11-1996 
% (c) Douwe de Vries, Paul Van den Hof 
% Mechanical Engineering Systems and Control Group 
% Delft University of Technology 
% Last update: 19-05-1998. 
% 
%************************************************************* 
 
% Defaults 
if nargin==0,action='start';end 
 
% Get the data 
FIGUS=get(gcf,'Userdata'); 
 
if strcmp(action,'start'), 
 
% Determine input strings 
  SDATAU=cldebl(get(FIGUS(4,1),'String')); 
  SDATAY=cldebl(get(FIGUS(6,1),'String')); 
  SDATAR1=cldebl(get(FIGUS(15,1),'String')); 
  SDATAR2=cldebl(get(FIGUS(17,1),'String')); 
  SFILENM=cldebl(get(FIGUS(23,1),'String')); 
 
  CLEVALSTRING=[' ']; 
  if isempty(SDATAY) 
     clerrdia(['ERROR IMPORTING DATA: an output signal y must be specified'],1); 
     return 
  end 
  if isempty(SDATAR1) & isempty(SDATAR2) & isempty(SDATAU) 
    clerrdia(['ERROR IMPORTING DATA: need at least one reference/input signal'],1); 
    return 
  end 
  if isempty(SDATAR1)  
    SDATAR1=['zeros(length(',SDATAY,'),1)']; 
  end 
  if isempty(SDATAR2)  
    SDATAR2=['zeros(length(',SDATAY,'),1)']; 
  end 
  if isempty(SDATAU)  
    SDATAU=['zeros(length(',SDATAY,'),1)']; 
  end 
  
% Read from workspace or window or file 
  if isempty(SFILENM) 
    CLEVALSTRING=['cldatimp(''cont'',' SDATAU ',' SDATAY ',' SDATAR1 ',' SDATAR2 ');']; 
    return 
  else 
    ERR=0; 
    [ERR,DATAU,DATAY,DATAR1,DATAR2]=clload(SFILENM,SDATAU,SDATAY,SDATAR1,SDATAR2); 
    if ERR, return; end 
  end 
 
elseif strcmp(action,'cont'), 
   DATAU=dat1;DATAY=dat2;DATAR1=dat3;DATAR2=dat4; 
end 
 
% Check data size 
if min(size(DATAU))~=1|min(size(DATAY))~=1|min(size(DATAR1))~=1|min(size(DATAR2))~=1, 
  clerrdia(['ERROR IMPORTING DATA: data signals are not vectors'],1); 
  return 
end 
 
% Check data ranges 
DATARANGE=cldebl(get(FIGUS(10,1),'String')); 
 
ERR=0; 
if ~isempty(DATARANGE), 
   eval(['DATAU=DATAU(' DATARANGE ');'],'ERR=1;'); 
   eval(['DATAY=DATAY(' DATARANGE ');'],'ERR=2;'); 
   eval(['DATAR1=DATAR1(' DATARANGE ');'],'ERR=3;'); 
   eval(['DATAR2=DATAR2(' DATARANGE ');'],'ERR=4;'); 
else, 
   DATARANGE=['[1:' num2str(size(DATAU,1)) ']']; 
   if any(size(DATAU)~=size(DATAR1)),ERR=5;end 
   if any(size(DATAY)~=size(DATAR2)),ERR=5;end 
   if any(size(DATAU,1)~=size(DATAY,1)),ERR=5;end 
end 
 
if ERR==1, 
   clerrdia(['ERROR IMPORTING DATA: cannot evaluate range for: input variable'],1); 
elseif ERR==2, 
   clerrdia(['ERROR IMPORTING DATA: cannot evaluate range for: output variable'],1); 
elseif ERR==3, 
   clerrdia(['ERROR IMPORTING DATA: cannot evaluate range for: refer1 variable'],1); 
elseif ERR==4, 
   clerrdia(['ERROR IMPORTING DATA: cannot evaluate range for: refer2 variable'],1); 
elseif ERR==5, 
   clerrdia(['ERROR IMPORTING DATA: variables have different sizes'],1); 
end 
if ERR, return; end 
 
% Store data in userdata of data object in main window 
eval(['rng=' DATARANGE ';']); 
rng=[rng(1) rng(length(rng))]; 
 
tmp=cldebl(get(FIGUS(19,1),'String')); 
if ~isempty(tmp),eval(['tsamp=' tmp ';']); 
else,tsamp=1;end 
 
tmp=cldebl(get(FIGUS(21,1),'String')); 
if ~isempty(tmp),eval(['tstart=' tmp ';']); 
else,tstart=rng(1)*tsamp;end 
 
h=findobj('TAG','CLDATADES'); 
us=get(h,'Userdata'); 
us(1,[1 2])=rng; 
us(4,[1 2])=[tsamp tstart]; 
us(5,[1 2])=[size(DATAY,2) size(DATAU,2)]; 
set(h,'Userdata',us); 
 
title=cldebl(get(FIGUS(8,1),'String')); 
info=' '; 
p=[rng;tsamp tstart]; 
clobjins([DATAY DATAU DATAR2 DATAR1],'data',title,info,p);