function globalInd = hLocalToGlobalIndices(codistr, localInd, dim, workerIdx)
; %#ok<NOSEM> % Undocumented

%   Implementation of hLocalToGlobalIndices for codistributor1d.

%   Copyright 2011-2022 The MathWorks, Inc.

    if nargin < 4
        workerIdx = spmdIndex;
    end
    
    if ~distributedutil.CodistParser.isValidSPMDIndex(workerIdx)
        error(message('parallel:codistributors:InvalidSpmdIndex'));
    end
    
    if ~isscalar(dim) || ~isPositiveIntegerValuedNumeric(dim) || ...
            dim > length(codistr.Cached.GlobalSize)
        error(message('parallel:codistributors:InvalidDimInput'));
    end
    
    localSize = codistr.hLocalSize();
    if dim>numel(localSize)
        localSizeInDim = 1;
    else
        localSizeInDim = localSize(dim);
    end
    if  any(~isPositiveIntegerValuedNumeric(localInd) | ...
            localInd < 1 | localInd > localSizeInDim)
        error(message('parallel:codistributors:InvalidLocalIndex'));
    end

    
    [partitionStart, ~] = codistr.hGlobalIndicesImpl(dim, workerIdx);
    globalInd = localInd + partitionStart - 1;
end

