function msToProcess = calcTrackingLengthMs( settings, fileSizeBytes )

%==============================================================================%
%                                                                              %
%   msToProcess = calcTrackingLengthMs( settings, fileSizeBytes )              %
%                                                                              %
%   Calculate the maximum tracking duration                                    %
%   David S. De Lorenzo                                                        %
%   07 March 2011                                                              %
%                                                                              %
%==============================================================================%
%                       GPS Software Receiver in Matlab                        %
%     Copyright (c) 2003-2017 David S. De Lorenzo / 2018-2023 Trimble Inc.     %
%==============================================================================%

% Assign temporary variables, making code more readable
msToSkip           = settings.msToSkip;
extraSamplesToSkip = settings.extraSamplesToSkip;
samplesPer1ms      = settings.samplesPer1ms;
bytesPerSample     = settings.bytesPerSample;
endOfFileBufferMs  = settings.trk.endOfFileBufferMs;

% How big is the input file in units of data samples
fileSizeSamples = fileSizeBytes / bytesPerSample;

% How many milliseconds would this file support
maxMilliseconds = ...
    (fileSizeSamples - extraSamplesToSkip) / samplesPer1ms ...
    - msToSkip - endOfFileBufferMs;

% Truncate to the nearest 10 milliseconds
msToProcess = 10 * floor(maxMilliseconds/10);

return
%===============================================================================