@SuppressWarnings("PMD.NPathComplexity") // external code, do not refactor
    private OsmTrack searchRoutedTrack(MatchedWaypoint startWp, MatchedWaypoint endWp, OsmTrack nearbyTrack, OsmTrack refTrack) {
        OsmTrack track = null;
        final double[] airDistanceCostFactors = new double[]{
                routingContext.pass1coefficient,
                routingContext.pass2coefficient
        };
        boolean isDirty = false;
        IllegalArgumentException dirtyMessage = null;

        if (nearbyTrack != null) {
            airDistanceCostFactor = 0.;
            try {
                track = findTrack("re-routing", startWp, endWp, nearbyTrack, refTrack, true);
            } catch (IllegalArgumentException iae) {
                if (terminated) {
                    throw iae;
                }

                // fast partial recalcs: if that timed out, but we had a match,
                // build the concatenation from the partial and the nearby track
                if (matchPath != null) {
                    track = mergeTrack(matchPath, nearbyTrack);
                    isDirty = true;
                    dirtyMessage = iae;
                    logInfo("using fast partial recalc");
                }
                if (maxRunningTime > 0) {
                    maxRunningTime += System.currentTimeMillis() - startTime; // reset timeout...
                }
            }
        }

        if (track == null) {
            for (int cfi = 0; cfi < airDistanceCostFactors.length; cfi++) {
                if (cfi > 0) {
                    lastAirDistanceCostFactor = airDistanceCostFactors[cfi - 1];
                }
                airDistanceCostFactor = airDistanceCostFactors[cfi];

                if (airDistanceCostFactor < 0.) {
                    continue;
                }

                OsmTrack t;
                try {
                    t = findTrack(cfi == 0 ? "pass0" : "pass1", startWp, endWp, track, refTrack, false);
                } catch (IllegalArgumentException iae) {
                    if (!terminated && matchPath != null) { // timeout, but eventually prepare a dirty ref track
                        logInfo("supplying dirty reference track after timeout");
                        foundRawTrack = mergeTrack(matchPath, track);
                        foundRawTrack.endPoint = endWp;
                        foundRawTrack.nogoChecksums = routingContext.getNogoChecksums();
                        foundRawTrack.profileTimestamp = routingContext.profileTimestamp;
                        foundRawTrack.isDirty = true;
                    }
                    throw iae;
                }

                if (t == null && track != null && matchPath != null) {
                    // ups, didn't find it, use a merge
                    t = mergeTrack(matchPath, track);
                    logInfo("using sloppy merge cause pass1 didn't reach destination");
                }
                if (t != null) {
                    track = t;
                } else {
                    throw new IllegalArgumentException("no track found at pass=" + cfi);
                }
            }
        }
        if (track == null) {
            throw new IllegalArgumentException("no track found");
        }

        final boolean wasClean = nearbyTrack != null && !nearbyTrack.isDirty;
        if (refTrack == null && !(wasClean && isDirty)) { // do not overwrite a clean with a dirty track
            logInfo("supplying new reference track, dirty=" + isDirty);
            track.endPoint = endWp;
            track.nogoChecksums = routingContext.getNogoChecksums();
            track.profileTimestamp = routingContext.profileTimestamp;
            track.isDirty = isDirty;
            foundRawTrack = track;
        }

        if (!wasClean && isDirty) {
            throw dirtyMessage;
        }

        // final run for verbose log info and detail nodes
        airDistanceCostFactor = 0.;
        lastAirDistanceCostFactor = 0.;
        guideTrack = track;
        startTime = System.currentTimeMillis(); // reset timeout...
        try {
            final OsmTrack tt = findTrack("re-tracking", startWp, endWp, null, refTrack, false);
            if (tt == null) {
                throw new IllegalArgumentException("error re-tracking track");
            }
            return tt;
        } finally {
            guideTrack = null;
        }
    }
find the elevation type for position
to determine the filter value

@param n  the point
@return  the filter value for 1sec / 3sec elevation source
main/src/main/java/cgeo/geocaching/brouter/core/RoutingEngine.java