function c = bitreplicate(a,N)
% MATLAB Code Generation Library function.
%
% CONCAT Perform concatenation of fixpt input operands N times.
%

%   Copyright 2002-2014 The MathWorks, Inc.
%#codegen

if eml_ambiguous_types
    c = coder.ignoreConst(reshape(zeros(size(a)),size(a)));
    return;
end

eml_invariant(isfi(a), 'fixed:fi:firstInputNotFi');
eml_invariant(eml_is_const(N) && isreal(N) && isscalar(N) && isnumeric(N), ...
    'fixed:coder:bitRepInvalid2ndInpArg')
eml_invariant(~isempty(N),  ...
    'fixed:fi:emptyNotAllowed','BITREPLICATE');
eml_invariant(coder.internal.scalexpCompatible(a,N), ...
    'fixed:fi:DimAgree');

Ta    = eml_typeof(a);
wlen  = Ta.WordLength;
maxWL = getFixedPointWidthLimit();
eml_invariant((coder.const(wlen*N) <= maxWL), ...
    'fixed:coder:bitRepCannotRepBits', maxWL);

eml_invariant(N > 0, 'fixed:fi:invalidBitReplicationConstant');

if N == 1
  c = a;
else
  c = bitconcat(a,bitreplicate(a, N-1));
end

end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% function c = bitreplicate_unary(a, n)
% if n == 1
%     c = a;
% else
%     c = bitreplicate_unary2(a,1,n);
% end
% end
% 
% function c = bitreplicate_unary2(a,i,n)
% 
% if i == n
%     c = a;
% else
%     c = bitconcat(a,bitreplicate_unary2(a,i+1,n));
% end
% 
% end
