function [inp,outp,x0]=chknl(pmod,minfoi)

% Checks SIMULAB plant model for consistency with a model in the
% MPC mod format, assuming that they both represent the same
% plant.  If OK, returns number of plant input and output variables.
% Otherwise stops with an error message.  PMOD is the SIMULAB plant
% model and MINFOI is the MINFO vector (MOD format) for the
% internal model.  Called by SCMPCNL.  
%
% INP and OUTP are the number of plant inputs and outputs, and
% x0 is the initial plant state.

% Copyright by N. L. Ricker, 12/91.
% $Revision: 1.1 $  $Date: 1994/05/09 15:44:20 $

% Get info on plant model.  Uses SIMULAB system call format.

[sizes,x0]=feval(pmod);

% Check for inconsistencies

nui=minfoi(3);
nvi=minfoi(4);
mi=nui+nvi;
nwi=minfoi(5);
nymi=minfoi(6);
nyui=minfoi(7);
nyi=nymi+nyui;

outp=sizes(3);
if nyi ~= outp   
   disp(['++Plant has ',num2str(outp),' outputs.'])
   disp(['++Internal model has ',num2str(nymi),' measured outputs and',...
          num2str(nyui),' unmeasured outputs.'])
   if outp < nymi
      error('Too few plant outputs.')
   else
      disp(['WARNING:  first ',num2str(nymi),...
             ' plant output(s) assumed measured.'])
   end
end

inp=sizes(4);
if mi ~= inp   
   disp(['++Plant has ',num2str(inp),' inputs.'])
   disp(['++Internal model has ',num2str(nui),' manipulated variable(s)'])
   disp(['                 and ',num2str(nvi),...
         ' measured disturbance input(s).'])
   if inp < mi
      error('Too few plant inputs.')
   elseif inp > mi
      disp(['WARNING:  last ',num2str(inp-mi),' plant input(s) assumed to',...
            ' be unmeasured disturbance(s).'])
   end
end






