Java Code Examples for ucar.ma2.Range#first()
The following examples show how to use
ucar.ma2.Range#first() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CDMUtil.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Test a List<Range> against a List<DapDimension> * to see if the range list represents the whole * set of dimensions within the specified indices. * * @param rangelist the set of ucar.ma2.Range * @param dimset the set of DapDimensions * @param start start looking here * @param stop stop looking here * @result true if rangelist is whole; false otherwise. */ public static boolean isWhole(List<Range> rangelist, List<DapDimension> dimset, int start, int stop) throws dap4.core.util.DapException { int rsize = (rangelist == null ? 0 : rangelist.size()); if (rsize != dimset.size()) throw new dap4.core.util.DapException("range/dimset rank mismatch"); if (rsize == 0) return true; if (start < 0 || stop < start || stop > rsize) throw new dap4.core.util.DapException("Invalid start/stop indices"); for (int i = start; i < stop; i++) { Range r = rangelist.get(i); DapDimension d = dimset.get(i); if (r.stride() != 1 || r.first() != 0 || r.length() != d.getSize()) return false; } return true; }
Example 2
Source File: AggregationOuterDimension.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Get the desired Range, reletive to this Dataset, if no overlap, return null. * <p> * wantStart, wantStop are the indices in the aggregated dataset, wantStart <= i < wantEnd. * if this overlaps, set the Range required for the nested dataset. * note this should handle strides ok. * * @param totalRange desired range, reletive to aggregated dimension. * @return desired Range or null if theres nothing wanted from this datase. * @throws InvalidRangeException if invalid range request */ protected Range getNestedJoinRange(Range totalRange) throws InvalidRangeException { int wantStart = totalRange.first(); int wantStop = totalRange.last() + 1; // Range has last inclusive, we use last exclusive // see if this dataset is needed if (!isNeeded(wantStart, wantStop)) return null; int firstInInterval = totalRange.getFirstInInterval(aggStart); if ((firstInInterval < 0) || (firstInInterval >= aggEnd)) return null; int start = Math.max(firstInInterval, wantStart) - aggStart; int stop = Math.min(aggEnd, wantStop) - aggStart; return new Range(start, stop - 1, totalRange.stride()); // Range has last inclusive }
Example 3
Source File: AggDatasetOuter.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Get the desired Range, reletive to this Dataset, if no overlap, return null. * <p> * wantStart, wantStop are the indices in the aggregated dataset, wantStart <= i < wantEnd. * if this overlaps, set the Range required for the nested dataset. * note this should handle strides ok. * * @param totalRange desired range, reletive to aggregated dimension. * @return desired Range or null if theres nothing wanted from this datase. * @throws InvalidRangeException if invalid range request */ protected Range getNestedJoinRange(Range totalRange) throws InvalidRangeException { int wantStart = totalRange.first(); int wantStop = totalRange.last() + 1; // Range has last inclusive, we use last exclusive // see if this dataset is needed if (!isNeeded(wantStart, wantStop)) return null; int firstInInterval = totalRange.getFirstInInterval(aggStart); if ((firstInInterval < 0) || (firstInInterval >= aggEnd)) return null; int start = Math.max(firstInInterval, wantStart) - aggStart; int stop = Math.min(aggEnd, wantStop) - aggStart; return new Range(start, stop - 1, totalRange.stride()); // Range has last inclusive }
Example 4
Source File: CDMUtil.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Convert a list of ucar.ma2.Range to a list of Slice * More or less the inverst of create CDMRanges * * @param rangelist the set of ucar.ma2.Range * @result the equivalent list of Slice */ public static List<Slice> createSlices(List<Range> rangelist) throws dap4.core.util.DapException { List<Slice> slices = new ArrayList<Slice>(rangelist.size()); for (int i = 0; i < rangelist.size(); i++) { Range r = rangelist.get(i); // r does not store last int stride = r.stride(); int first = r.first(); int n = r.length(); int stop = first + (n * stride); Slice cer = new Slice(first, stop - 1, stride); slices.add(cer); } return slices; }
Example 5
Source File: CDMUtil.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test a List<Range> against a List<Slice> * to see if the range list is whole * wrt the slices * * @param rangelist the set of ucar.ma2.Range * @param slices the set of slices * @result true if rangelist is whole wrt slices; false otherwise. */ public static boolean isWhole(List<Range> rangelist, List<Slice> slices) throws dap4.core.util.DapException { if (rangelist.size() != slices.size()) return false; for (int i = 0; i < rangelist.size(); i++) { Range r = rangelist.get(i); Slice slice = slices.get(i); if (r.stride() != 1 || r.first() != 0 || r.length() != slice.getCount()) return false; } return true; }
Example 6
Source File: CDMUtil.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test a List<Range> against the CDM variable's dimensions * to see if the range list is whole * wrt the dimensions * * @param rangelist the set of ucar.ma2.Range * @param var the cdm var * @result true if rangelist is whole wrt slices; false otherwise. */ public static boolean isWhole(List<Range> rangelist, Variable var) throws dap4.core.util.DapException { List<Dimension> dimset = var.getDimensions(); if (rangelist.size() != dimset.size()) return false; for (int i = 0; i < rangelist.size(); i++) { Range r = rangelist.get(i); Dimension dim = dimset.get(i); if (r.stride() != 1 || r.first() != 0 || r.length() != dim.getLength()) return false; } return true; }
Example 7
Source File: DataTable.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Get data rows * * @param range Range * @return DataRowCollection The data rows */ public DataRowCollection getRows(Range range) { DataRowCollection r = new DataRowCollection(); for (int i = range.first(); i < range.last(); i++){ r.add(this.rows.get(i)); } return r; }
Example 8
Source File: AggregationOuterDimension.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
protected boolean isNeeded(Range totalRange) { int wantStart = totalRange.first(); int wantStop = totalRange.last() + 1; // Range has last inclusive, we use last exclusive return isNeeded(wantStart, wantStop); }
Example 9
Source File: AggDatasetOuter.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
protected boolean isNeeded(Range totalRange) { int wantStart = totalRange.first(); int wantStop = totalRange.last() + 1; // Range has last inclusive, we use last exclusive return isNeeded(wantStart, wantStop); }