function acqResults = acquisitionQuickDetect( pathName, fileName, ...
                                              settings, acqResultsAll )

%==============================================================================%
%                                                                              %
%   acqResults = acquisitionQuickDetect( pathName, fileName, ...               %
%                                        settings, acqResultsAll )             %
%                                                                              %
%   Quick (and simple) detection logic                                         %
%   David S. De Lorenzo                                                        %
%   28 January 2008                                                            %
%                                                                              %
%==============================================================================%
%                       GPS Software Receiver in Matlab                        %
%     Copyright (c) 2003-2017 David S. De Lorenzo / 2018-2023 Trimble Inc.     %
%==============================================================================%

%--- Initialize variables ------------------------------------------------------
acqResults  = [];
numDetected = 0;

%--- Detection - loop over each satellite in the search vector -----------------
for ii = 1:length(settings.acq.prnSearchVec)
    
    %--- Maximum value of correlation-peak-to-next-peak ratio ------------------
    [cpprMax,detectionIndex] = max([acqResultsAll(ii).acqResults.cppr]);
    
    %--- Satellite detection - compare CPPM to threshold -----------------------
    if (cpprMax >= settings.acq.detectionThresholdCPPR)
        
        %--- Increment number of detected signals ------------------------------
        numDetected = numDetected + 1;
        
        %--- Extract results from raw acquisition results structure ------------
        prn          = acqResultsAll(ii).acqResults(1).prn;
        codePhase    = acqResultsAll(ii).acqResults(detectionIndex).codePhase;
        dopplerFreq  = acqResultsAll(ii).acqResults(detectionIndex).dopplerFreq;
        carrierPhase = 0;           % hard-coded to zero!!!!
        cppr         = acqResultsAll(ii).acqResults(detectionIndex).cppr;
        
        %--- Store results in acquisition structure ----------------------------
        acqResults(numDetected).signalType   = settings.signalType;  %#ok<AGROW>
        acqResults(numDetected).prn          = prn;                  %#ok<AGROW>
        acqResults(numDetected).codePhase    = codePhase;            %#ok<AGROW>
        acqResults(numDetected).dopplerFreq  = dopplerFreq;          %#ok<AGROW>
        acqResults(numDetected).carrierPhase = carrierPhase;         %#ok<AGROW>
        acqResults(numDetected).cppr         = cppr;                 %#ok<AGROW>
        
        %--- Save 2D plots to JPEG ---------------------------------------------
        if ~(exist('OCTAVE_VERSION','builtin') > 0)
            if ((settings.acq.plotToJPEG == true) ...
             && (strcmp( settings.acq.plotSwitch, '2D') ...
              || strcmp(settings.acq.plotSwitch, '3D')))
                print('-djpeg', sprintf('-f%d', 600+prn), ...
                      fullfile(pathName, ...
                               [fileName '__acq_' sprintf('PRN%02d', prn)]));
            end
        end
        
    end % satellite detection
    
end % loop over satellite number

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