Java Code Examples for ucar.ma2.Range#stride()

The following examples show how to use ucar.ma2.Range#stride() . 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 vote down vote up
/**
 * 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 vote down vote up
/**
 * 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 vote down vote up
/**
 * 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 vote down vote up
/**
 * 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 vote down vote up
/**
 * 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 vote down vote up
/**
 * 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: IndexChunkerTiled.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
Dim(Range data, Range want, Range intersect, int dataStride, int wantStride) {
  // assert want.length() <= maxSize : want.last() +" > "+ maxSize ;
  this.data = data;
  this.want = want;
  this.intersect = intersect;
  this.dataStride = dataStride;
  this.wantStride = wantStride;
  this.ncontigElements = intersect.stride() == 1 ? intersect.length() : 1;
  this.wantNelems = intersect.length();

  if (debugMerge)
    System.out.println("Dim=" + this);
}