CoordinateUtils { public static int findMaxDepthIndex(double[] depths, double to) { int last = Arrays.binarySearch(depths, to); if (last < 0) { last = -1 - last; if (last == depths.length || Math.floor(100 * depths[last]) - Math.floor(100 * to) > 1) { last--; } } else if (last == 0 && Math.floor(100 * depths[0]) - Math.floor(100 * to) > 1) { last = -1; } else if (last == depths.length) { last--; } return last; }  static double getLongitudeM180P180(double longitude); static List<Range> createRange(int minj, int maxj, int mini, int maxi); static int findCoordElementBounded(CoordinateAxis1D axis, double pos, int lastIndex); static List<Range> getRangesFromLatLonRect(GridCoordSys gcs, LatLonRect rect); static double getMinOrMaxLon(double lon1, double lon2, boolean wantMin); static MinMax computeMinMax(MinMax ref, MinMax work); static MAMath.MinMax computeLatMinMax(MAMath.MinMax minMaxYValue2D, CoordinateAxis2D latAxis, int minj, int mini, int maxj, int maxi); static MAMath.MinMax computeLonMinMax(MAMath.MinMax minMaxXValue2D,
                                                 CoordinateAxis2D lonAxis,
                                                 int minj,
                                                 int mini,
                                                 int maxj,
                                                 int maxi,
                                                 double minx,
                                                 double maxx); static MinMax computeMinMaxX(Projection dataProjection, LatLonRect rect); static MinMax computeMinMaxY(Projection dataProjection, LatLonRect rect); static MinMax[] computeMinMaxXY(Projection dataProjection, LatLonRect rect); static void checkXYAxis(CoordinateAxis xaxis, CoordinateAxis yaxis, GridCoordSys gcs); static double checkLon(double lon, double refXMin); static boolean isInside(double lat, double lon, MinMax minMaxX, MinMax minMaxY); static void removeEmptyYXRanges(List<List<Range>> listRanges); static boolean hasEmptyYXRanges(List<List<Range>> listRanges); static List<Range> createEmptyYXRanges(); static boolean hasRange(List<Range> ranges); static boolean hasRange(Range range); static void getRangeValues(GridCoordSys gcs, Range rangeLat, Range rangeLon, double[] rangeValueLat, double[] rangeValueLon); static MAMath.MinMax getMinMaxValueForAxis(CoordinateAxis axis); static double getMinValueForAxis(CoordinateAxis axis); static double getMaxValueForAxis(CoordinateAxis axis); static String getMinValForAxisAsString(CoordinateAxis axis); static String getMaxValForAxisAsString(CoordinateAxis axis); static int findMinDepthIndex(double[] depths, double from); static int findMaxDepthIndex(double[] depths, double to);  }
@Test public void testFindMaxDepthIndex() { double[] depths = { 0.18234, 0.235, 0.24, 0.245, 1.1 }; assertTrue(CoordinateUtils.findMaxDepthIndex(depths, 0.16) == -1); assertTrue(CoordinateUtils.findMaxDepthIndex(depths, 0.17) == 0); assertTrue(CoordinateUtils.findMaxDepthIndex(depths, 0.19) == 0); assertTrue(CoordinateUtils.findMaxDepthIndex(depths, 0.191) == 0); assertTrue(CoordinateUtils.findMaxDepthIndex(depths, 0.219) == 0); assertTrue(CoordinateUtils.findMaxDepthIndex(depths, 0.22) == 1); assertTrue(CoordinateUtils.findMaxDepthIndex(depths, 0.24275) == 3); assertTrue(CoordinateUtils.findMaxDepthIndex(depths, 1.1) == 4); }