function Dd = d2dXC(Dd,Ts,options)
% D2D conversion with state and delay consistency across array.
% Given an SS array with constant number of states and internal delays,
% D2DXC returns an SS array with the same property.

%   Copyright 2023 The MathWorks, Inc.
nsys = numel(Dd);
METHOD = options.Method(1);
switch METHOD
   case 't'
      % Tustin
      for ct=1:nsys
         Dd(ct) = d2d(Dd(ct),Ts,options);
      end
   case 'z'
      % ZOH
      if any(arrayfun(@hasdelay,Dd))
         % Use consistent versions of d2c/c2d
         Dc = d2cXC(Dd,d2cOptions(Method='zoh',Consistency='on'));
         Dd = c2dXC(Dc,Ts,c2dOptions(Method='zoh',Consistency='on'));
      else
         % Consistently eliminate E and convert
         nx = size(Dd(1).a,1);
         for ct=1:nsys
            D = des2exp(Dd(ct),true);
            if ~isfinite(D)
               error(message('Control:transformation:dss2ss1'))
            end
            Dd(ct) = d2d(D,Ts,options);
            if size(Dd(ct).a,1)>nx
               error(message('Control:transformation:d2c13'))
            end
        end
      end
end
