function W = gram_(sys,type,options)
%

% Copyright 1986-2014 The MathWorks, Inc.
D = sys.Data_;
if isempty(D)
   Nx = 0;
else
   Nx = order(D(1));
end
W = zeros([Nx Nx size(D)]);
FactorFlag = any(type=='f');
for ct=1:numel(D)
   if ct>1 && order(D(ct))~=Nx
      error(message('Control:general:RequiresUniformNumberOfStates','gram'))
   end
   R = gram(D(ct),type,options);
   if FactorFlag
      W(:,:,ct) = R;
   else
      W(:,:,ct) = R' * R;
   end
end