function [F,TF] = fillmissing(A, varargin)
%FILLMISSING Fill missing entries in codistributed data.
%   B = FILLMISSING(A,'constant',C)
%   B = FILLMISSING(A,INTERP)
%   B = FILLMISSING(A,MOV,K)
%   B = FILLMISSING(A,MOV,[NB NF])
%   B = FILLMISSING(A,fillfun,K)
%   B = FILLMISSING(A,fillfun,[NB NF])
%   B = FILLMISSING(A,METHOD,...,'MissingLocations',M)
%   B = FILLMISSING(A,METHOD,...,'EndValues',E)
%   B = FILLMISSING(A,METHOD,...,'SamplePoints',X)
%   B = FILLMISSING(A,...,'MaxGap',G)
%   B = FILLMISSING(A,METHOD,DIM,...)
%   [B,FB] = FILLMISSING(A,...)
%   B = FILLMISSING(T,...,'DataVariables',DV)
%   B = FILLMISSING(T,...,'ReplaceValues',TF)
%   
%   Limitations:
%   Method 'knn' and 'Distance' argument are not supported.
%   The 'MissingLocations' name-value argument with table or timetable value is not supported.
%   
%   See also FILLMISSING, CODISTRIBUTED.


%   Copyright 2022-2023 The MathWorks, Inc.

% Gather trailing arguments.
[varargin{:}] = gather(varargin{:});
% If A is not distributed then a trailing parameter was. Call in-memory
% version.
if ~iscodistributed(A)
    if nargout>1
        [F, TF] = fillmissing(A, varargin{:});
    else
        F = fillmissing(A, varargin{:});
    end
    return;
end

% try...catch prevents error being reported by internal
try
    if nargout > 1
        [F, TF] = parallel.internal.flowthrough.fillmissing(A, varargin{:});
    else
        F = parallel.internal.flowthrough.fillmissing(A, varargin{:});
    end
catch ME
    throw(ME);
end
end
