function iduimod(Figno,Kmod,CKmod)
%IDUIMOD Main manager of the plot windows.
%       Makes sure that the models/data with numbers Kmod are visible/plotted
%       (and CKmod invisible) in the windows with numbers Figno.

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

global  XIDplotw  XIDmen 


iduistat('Showing desired curves ...')
if nargin==2, CKmod=[];end
for fig=Figno  % Generating the curves if they have not been computed
               % before
   if any(fig==[14,15]),eval('iddatfig(Kmod,Figno);');return,end
   if any(fig==[1,13,14,15]),isdata=1;else isdata=0;end
   if isempty(iduiwok(fig)) % Check that plot window is OK
       eval('XIDplotw(fig,1)=idbuildw(fig);')
   end
   Fighand=XIDplotw(fig,1);
   if ~isdata,   hsd=findobj(Fighand,'tag','confonoff');end
   fusd=get(Fighand,'userdata');[rfusd,cfusd]=size(fusd);
   axch=fusd(3:rfusd,1)';
   genall=0;
   eval('xusd=get(axch(1),''UserData'');','genall=1;xusd=[];')
   [rrusd,ccusd]=size(xusd);mkmod=max(2*Kmod+1);
   if rrusd<mkmod,xusd=[xusd;zeros(mkmod-rrusd,ccusd)];end
   eval('index=find(xusd(2*Kmod+1,1)==0);','genall=1;')
   if genall
      genmod=Kmod;
   else
      if isempty(index),genmod=[];else genmod=Kmod(index);end
   end

   if ~isempty(genmod), 
       if ~isdata 
           eval('idgenfig(genmod,fig)')
       else
           eval('iddatfig(genmod,fig)')
       end
    end
   
   for kk=axch   % Setting the visibility status of the curves
    xusd=get(kk,'Userdata');
    if strcmp(get(kk,'visible'),'on')
       [rusd,cusd]=size(xusd);maxmod=max([CKmod Kmod]');
       if rusd<2*maxmod+2
           xusd(2*maxmod+2,1)=0;set(kk,'Userdata',xusd);
       end
       if ~isempty(Kmod),iduivis(xusd(2*Kmod+1,:),'on'),end
       if ~isempty(CKmod),iduivis(xusd(2*CKmod+1,:),'off'),end
       if ~isdata,if strcmp(get(hsd,'checked'),'on')
          if ~isempty(Kmod),iduivis(xusd(2*Kmod+2,:),'on'),end
          if any(any(xusd(2*Kmod+2,:)==-1))
             iduistat('No confidence region for N4SID models.',0,fig)
           elseif any(any(xusd(2*Kmod+2,:)==-2))
             iduistat('No confidence region for ETFE models.',0,fig)
          end
          if ~isempty(CKmod),
               eval('iduivis(xusd(2*CKmod+2,:),''off'')','')
          end
       end,end
     end
   end
end
   
iduistat('')

