function axh=iduiinsd(data,data_info,data_n,active,axinfo)
%IDUIINSD Inserts data into the Data Summary Board.
%	DATA: The data. 
%	DATA_INFO: The associated information matrix. 
%	DATA_N: The name of the data set. 
%	ACTIVE: 1 to make icon selected at insert
%	AXINFO: [Board_no,position,color]
%	AXH: the handle number of the data's icon axis.

%	L. Ljung 4-4-94
%	Copyright (c) 1986-95 by the MathWorks, Inc.
%       $Revision: 1.11 $  $Date: 1995/05/10 21:36:59 $


global XIDplotw XIDhw XIDcounters XIDsbmen
if nargin<4,active=1;end
[ny,nu]=iduiiono('old',data_info,'dat');
[nrow,ncol]=size(data);
if nrow<ncol
   errordlg(str2mat('You have more input-output channels',...
            'than data observations. This is not allowed.'));
  return
end
XIDcounters(5)=1;
if XIDcounters(3)<nu|XIDcounters(4)<ny
   XIDcounters([3 4])=max(XIDcounters([3 4]),[nu ny]);
   iduiiono('set',XIDcounters([3 4]));
end

if nargin<5
  [axh,texh,linh]=idnextw('data');
else
  [axh,texh,linh]=idnextw('data',axinfo(1),axinfo(2:5),axinfo(6:8));
  if isempty(linh),  [axh,texh,linh]=idnextw('data');end
end
tagdat=get(axh,'tag');
datanr=eval(tagdat(6:length(tagdat)));
set(linh,'UserData',data,'tag','dataline');
set(texh,'UserData',data_info,'string',data_n);
dl=min(50,nrow);
ll=data(1:dl,1);
   set(linh,'xdata',1:dl,'ydata',ll);
   if active, set(linh,'linewidth',3);end
   set(axh,'ylim',[2*min(ll)-max(ll) max(ll)],'xlim',[0 dl],'color','k');
set([linh axh texh],'vis','on')

usde=get(XIDhw(3,1),'userdata'); % If working data is empty we fill it
if isempty(usde)&active
    idinseva(axh,'seles');idinseva(axh,'selva');
end

set(XIDplotw([1,13],2),'enable','on')
if active,
   if  get(XIDplotw(1,2),'value'),wnr=1;else wnr=[];end
   if  get(XIDplotw(13,2),'value'),wnr=[wnr 13];end

   if ~isempty(wnr),iduimod(wnr,datanr,[]);end
   set(XIDsbmen([3 5]),'enable','on')
   if strcmp(get(XIDsbmen(1),'tag'),'open')
      [label,acc]=menulabel('&Merge session... ^o');
      set(XIDsbmen(1),'label',label,'tag','merge');
   end
   iduistat(['Data set ',data_n,' inserted.',...
         '  Double click on icon (right/middle mouse) for text information.'])
end
