int insideBoundaries = 0;
    public List getBestCoverageEntry(float ullat, float ullon, float lrlat,                                     float lrlon, CADRG proj,                                     RpfViewAttributes viewAtts) {        if (!valid)            return null;        List coverageEntries = new Vector();        int insideBoundaries = 0;        double scaleFactor = 0;        double lowerScaleFactorLimit = 1.0;        double upperScaleFactorLimit = 1.0;        // Good for a preliminary check. It has to start at least as        // 4 to have one corner matching.        int prevBoundaryHits = 0;        if (viewAtts != null) {            lowerScaleFactorLimit = (double) (1.0 / viewAtts.imageScaleFactor);            upperScaleFactorLimit = (double) viewAtts.imageScaleFactor;        }        int nscale = 0;        int scale = (int) proj.getScale();        RpfTocEntry bestEntry = null;        if (DEBUG_RPFTOCDETAIL) {            Debug.output("getBestCoverageEntry(): Checking for coverage");            Debug.output("  nw_lat: " + ullat);            Debug.output("  se_lat: " + lrlat);            Debug.output("  nw_lon: " + ullon);            Debug.output("  se_lon: " + lrlon);        }        int zone = getASCIIZone(ullat, proj.getZone());        char okZones[] = getOkZones(ullat, lrlat, (char) zone);        for (int i = 0; i < numBoundaries; i++) {            RpfTocEntry currentEntry = entries[i];            if (DEBUG_RPFTOCDETAIL) {                Debug.output("********************");                Debug.output("  tochandler: Boundary #" + i);                Debug.output(currentEntry.toString());            }            // Try to get the boundary rectangle with the most            // coverage, so reset the entry for this particular query.            currentEntry.coverage.reset();            //  Find the scale of the boundary rectangle            if (currentEntry.info == null                    || currentEntry.info.scale == RpfConstants.Various) {                nscale = (int) textScaleToLong(currentEntry.scale);                currentEntry.info = new RpfProductInfo();                // Reset the RpfProductInfo to the listed parameters                // in the A.TOC file.                currentEntry.info.scale = (float) nscale;                currentEntry.info.scaleString = currentEntry.scale;                currentEntry.coverage.scale = (float) nscale;            } else {                currentEntry.coverage.scale = currentEntry.info.scale;                nscale = (int) currentEntry.info.scale;            }            if (DEBUG_RPFTOCDETAIL) {                Debug.output("getBestCoverageEntry(): Query scale = " + scale                        + " vs. brect scale = " + nscale);            }            // if you want an exact match for scale...            if (viewAtts != null && !viewAtts.scaleImages) {                if (scale == nscale) {                    scaleFactor = 1.0;                } else                    scaleFactor = lowerScaleFactorLimit - 1.0;            } else {                scaleFactor = (double) nscale / (double) scale;            }            String chartSeries;            if (viewAtts == null) {                chartSeries = RpfViewAttributes.ANY;            } else {                chartSeries = viewAtts.chartSeries;            }            if (scaleFactor >= lowerScaleFactorLimit                    && scaleFactor <= upperScaleFactorLimit                    && (chartSeries.equalsIgnoreCase(RpfViewAttributes.ANY) || chartSeries.equalsIgnoreCase(currentEntry.info.seriesCode))) {                if (isOkZone(currentEntry.zone, okZones)) {                    // sets currentEntry.coverage.boundaryHits                    int hits = currentEntry.coverage.setBoundaryHits(ullat,                            ullon,                            lrlat,                            lrlon);                    if (DEBUG_RPFTOCDETAIL) {                        Debug.output("getBestCoverageEntry(): Boundary Hits = "                                + hits);                    }                    if (bestEntry != null) {                        boolean betterScale = false;                        float newScaleDiff = RpfFrameCacheHandler.scaleDifference(proj,                                currentEntry.coverage);                        float bestScaleDiff = RpfFrameCacheHandler.scaleDifference(proj,                                bestEntry.coverage);                        if (newScaleDiff <= bestScaleDiff) {                            betterScale = true;                        }                        if (betterScale                                && (currentEntry.coverage.setPercentCoverage(ullat,                                        ullon,                                        lrlat,                                        lrlon) >= bestEntry.coverage.getPercentCoverage())                                && (hits >= prevBoundaryHits || hits >= 6)) {                            // Add to list if has any hits and is                            // the best possible scale. If new scale                            // difference                            // is strictly better, remove other                            // entries                            if (newScaleDiff < bestScaleDiff) {                                coverageEntries.clear();                            }                            coverageEntries.add(currentEntry);                            bestEntry = currentEntry;                            prevBoundaryHits = hits;                            if (DEBUG_RPFTOC) {                                Debug.output("getBestCoverageEntry(): Found a match in a BR with coverage of "                                        + currentEntry.coverage.getPercentCoverage()                                        + "%.");                            }                        } else if (betterScale                                && currentEntry.coverage.getPercentCoverage() > 0f) {                            if (newScaleDiff < bestScaleDiff) {                                coverageEntries.clear();                            }                            coverageEntries.add(currentEntry);                        }                    } else if (hits > prevBoundaryHits                            && (currentEntry.coverage.setPercentCoverage(ullat,                                    ullon,                                    lrlat,                                    lrlon) > 0f)) {                        bestEntry = currentEntry;                        prevBoundaryHits = hits;                        // Add to list of coverageEntries                        coverageEntries.add(currentEntry);                        if (DEBUG_RPFTOC) {                            Debug.output("getBestCoverageEntry(): Found a match in a BR with coverage of "                                    + currentEntry.coverage.getPercentCoverage()                                    + "%.");                        }                    }                }            }        }        if (DEBUG_RPFTOC) {            if (bestEntry != null) {                Debug.output("getBestCoverageEntry(): found the best");                Debug.output("################");                Debug.output(bestEntry.toString());                Debug.output("Returning the following coverage boxes: ");                for (int i = 0; i < coverageEntries.size(); i++) {                    Debug.output(coverageEntries.get(i).toString());                }            } else {                Debug.output("getBestCoverageEntry(): no box found");            }        }        return coverageEntries;    }