function idinseva(ax1,tag2,silent)
%IDINSEVA Inserts the working or validation data set.
%       The data information in ax1 is placed as working data
%	(tag2='seles') or validation data (tag2='selva');
%	if silent==1, no status messages are displayed
 
%	L. Ljung 9-27-94
%	Copyright (c) 1986-95 by the MathWorks, Inc.
%	$Revision: 1.5 $  $Date: 1995/05/10 21:36:59 $

global XIDhw XIDplotw

if nargin<3,silent=0;end
if strcmp(tag2,'seles'),ax2=XIDhw(3,1);else ax2=XIDhw(4,1);end
oldusd = get(ax2,'userdata');
par1=get(ax1,'parent');par2=get(ax2,'parent');
tag1=get(ax1,'tag');
oldtag=get(get(ax2,'zlabel'),'userdata');
if strcmp(tag1,oldtag)
   if strcmp(tag2,'seles')
      dtype='Working ';
   else
      dtype='Validation ';
   end
   iduistat([dtype,'data unchanged. No update necassary.'])
   return
end   
pos2=get(ax2,'pos');pos1=get(ax1,'pos');
   usd2=get(ax2,'userdata');if isempty(usd2),usd2=[0 0];end
   hnrstring2=findobj(ax2,'type','text','tag','name');
   hnrline2=findobj(ax2,'tag','selline');
   hnrstring1=findobj(ax1,'type','text','tag','name');
   hnrline1=findobj(ax1,'tag','dataline');
   set(get(ax2,'zlabel'),'userdata',tag1); % Tagging the working/validation
                                           % data with a name tag
   set(hnrstring2,'string',get(hnrstring1,'string'),'userdata',...
                 get(hnrstring1,'userdata'),'vis','on')
   set(hnrline2,'xdata',get(hnrline1,'xdata'),...
                  'ydata',get(hnrline1,'ydata'),'vis','on',...
                  'userdata',get(hnrline1,'userdata'));
   dat_inf=get(hnrstring1,'userdata');
   eval('[ny,nu]=iduiiono(''old'',dat_inf,''dat'');')%LL!
   nystr=eval(['[',dat_inf(6,:),']']);
   nustr=eval(['[',dat_inf(7,:),']']);
   newusd=[nu,ny,nustr,nystr];
   set(ax2,'xlim',get(ax1,'xlim'),...
                  'ylim',get(ax1,'ylim'),'userdata',newusd);
   newax=0;
   if strcmp(tag2(1:5),'selva')
      set(hnrline2,'color','w');
      if iduiwok(3)
         hpred=findobj(XIDplotw(3,1),'tag','predict');
         hsim=findobj(XIDplotw(3,1),'tag','simul');
         if nu==0, 
            if strcmp(get(hsim,'checked'),'on')
               idopttog('check',hpred,0);
            end
            set(hsim,'enable','off');
         else
            set(hsim,'enable','on');
         end            
      end
      sampp=get(XIDplotw(3,2),'userdata');
      sampp=str2mat(sampp(1,:),sampp(2,:),'[]',sampp(4,:));
      set(XIDplotw(3,2),'userdata',sampp);
      flag=1;
      if length(newusd)==length(oldusd),if newusd==oldusd,flag=0;end,end
      eval('if flag,iduiiono(''set'',dat_inf,[3 6]);end') 
      eval('iduiclpw(3);iduiclpw(6);')
      if ~silent
        iduistat(['Validation data changed to ',get(hnrstring1,'string') '.'])
      end
   else
      set(hnrline2,'color',get(hnrline1,'color'));

      eval(['if strcmp(get(iduiwok(28),''vis''),''on''),',...
            'iduisel(''revert_io'');end'],'')
      eval(['if strcmp(get(iduiwok(30),''vis''),''on''),',...
            'iduisel(''revert_dec'');end'],'')
      eval(['if strcmp(get(iduiwok(14),''vis''),''on''),',...
            'iduisel(''open_portions'');end'],'')
      eval(['if strcmp(get(iduiwok(15),''vis''),''on''),',...
            'iduifilt(''open'');end'],'')

      if nu~=usd2(1)|ny~=usd2(2)
         newms=0;
         eval('if strcmp(get(iduiwok(20),''vis''),''on''),newms=1;end','')
         if newms,eval('idparest(''open'');'),end
      elseif ~all(nustr==usd2(3:2+nu))|~all(nystr==usd2(3+nu:ny+nu+2))
         newms=0;
         eval('if strcmp(get(iduiwok(21),''vis''),''on''),newms=1;end','')
         if newms,eval('iduiio(''open'');','');end
      end
      if ~silent
         iduistat(['Working data changed to ',get(hnrstring1,'string') '.'])
      end
   end
