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

The following examples show how to use ucar.ma2.Range#length() . 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: 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 3
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 4
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 5
Source File: SigmetIOServiceProvider.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void readOneRadial(Ray r, Range gateRange, IndexIterator ii) throws IOException {
  if (r == null) {
    for (int i = 0; i < gateRange.length(); i++)
      ii.setFloatNext(Float.NaN);
    return;
  }
  r.readData(volScan.raf, gateRange, ii);
}
 
Example 6
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);
}
 
Example 7
Source File: N3iospNew.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Read data from record structure. For N3, this is the only possible structure, and there can be no nesting.
 * Read all variables for each record, put in ByteBuffer.
 *
 * @param s the record structure
 * @param section the record range to read
 * @return an ArrayStructure, with all the data read in.
 * @throws IOException on error
 */
private ucar.ma2.Array readRecordData(ucar.nc2.Structure s, Section section) throws java.io.IOException {
  // has to be 1D
  Range recordRange = section.getRange(0);

  // create the ArrayStructure
  StructureMembers members = s.makeStructureMembers();
  for (StructureMembers.Member m : members.getMembers()) {
    Variable v2 = s.findVariable(m.getName());
    Vinfo vinfo = (Vinfo) v2.getSPobject();
    m.setDataParam((int) (vinfo.begin - header.recStart));
  }

  // protect against too large of reads
  if (header.recsize > Integer.MAX_VALUE)
    throw new IllegalArgumentException("Cant read records when recsize > " + Integer.MAX_VALUE);
  long nrecs = section.computeSize();
  if (nrecs * header.recsize > Integer.MAX_VALUE)
    throw new IllegalArgumentException(
        "Too large read: nrecs * recsize= " + (nrecs * header.recsize) + "bytes exceeds " + Integer.MAX_VALUE);

  members.setStructureSize((int) header.recsize);
  ArrayStructureBB structureArray = new ArrayStructureBB(members, new int[] {recordRange.length()});

  // loop over records
  byte[] result = structureArray.getByteBuffer().array();
  int count = 0;
  for (int recnum : recordRange) {
    if (debugRecord)
      System.out.println(" read record " + recnum);
    raf.seek(header.recStart + recnum * header.recsize); // where the record starts

    if (recnum != header.numrecs - 1) {
      raf.readFully(result, (int) (count * header.recsize), (int) header.recsize);
    } else {
      // "wart" allows file to be one byte short. since its always padding, we allow
      raf.read(result, (int) (count * header.recsize), (int) header.recsize);
    }
    count++;
  }

  return structureArray;
}
 
Example 8
Source File: IndexChunker.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
Dim(long byteStride, int maxSize, Range want) {
  this.stride = byteStride;
  this.maxSize = maxSize;
  this.wantSize = want.length();
  this.want = want;
}