function placeFilePositionPointer( fidIn, msToSkip, samplesToSkip, settings )

%==============================================================================%
%                                                                              %
%   placeFilePositionPointer( fidIn, msToSkip, samplesToSkip, settings )       %
%                                                                              %
%   Seek forward to the specified file position pointer location               %
%   David S. De Lorenzo                                                        %
%   05 April 2006                                                              %
%                                                                              %
%==============================================================================%
%                       GPS Software Receiver in Matlab                        %
%     Copyright (c) 2003-2017 David S. De Lorenzo / 2018-2023 Trimble Inc.     %
%==============================================================================%

% Assign temporary variables, making code more readable
samplesPer1ms  = settings.samplesPer1ms;
dataSource     = settings.dataSource;
bytesPerSample = settings.bytesPerSample;

% Special handling instructions
switch dataSource
    case 'Spirent'
        error('***  Spirent data source not supported!!  ***');
    otherwise
        % do nothing -- fall through
end

% Calculate total sample offset into the file
samplesToSkip = samplesToSkip + (msToSkip * samplesPer1ms);

% Calculate the total number of bytes to be skipped
bytesToSkip = samplesToSkip * bytesPerSample;

% Calculate the whole number of bytes and the extra fractional byte
wholeBytesToSkip = floor(bytesToSkip);
fractionalBytes  = bytesToSkip - wholeBytesToSkip;

% Calculate the extra samples to skip via an "fread" call
extraSamplesToRead = fractionalBytes / bytesPerSample;

% Rewind and then seek relative to the beginning of the file
status = fseek(fidIn, wholeBytesToSkip, -1);
if (status == -1)
    error('***  FSEEK ERROR!!  ***');
end

% Complete fractional-byte movement of the file position pointer
%   Note that final file traversal is done in this way, rather than
%   with an 'fseek' call, since this method handles data samples
%   that are of fractional byte in size.
if (extraSamplesToRead ~= 0)
    readDataFromFile(fidIn, extraSamplesToRead, settings);
end

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