% aconnect - serial connection of two arrows
%
% aconnect :: 
%    arrow(T1,T2,S1), arrow(T2,T3,S2) 
% -> arrow(T1,T3, pair(S1,S2)).
%
% The first arrow must have the same number of outputs
% and as the second arrow has inputs. The resulting
% arrow has a state type consisting of a two element
% cell array with elements of type S1 and S2.

function o=aconnect(o1,o2,varargin)

	if nargin<1, o1=aid; o2=aid; end
	if nargout(o1)~=nargin(o2)
		error(sprintf('Connecting units: port number mismatch between \n    %s (%d outputs)\nand %s (%d inputs)', ...
			tostring(o1),nargout(o1),tostring(o2),nargin(o2)));
	end

	s.unit1=o1;
	s.unit2=o2;

	o=class(s,'aconnect',arrow(nargin(o1),nargout(o2)));
end
