Exemple #1
0
  /**
   * Determine if a given Range intersects this one. NOTE: we dont yet support intersection when
   * both Ranges have strides
   *
   * @param r range to intersect
   * @return true if they intersect
   * @throws UnsupportedOperationException if both Ranges have strides
   */
  public boolean intersects(Range r) {
    if ((length() == 0) || (r.length() == 0)) return false;
    if (this == VLEN || r == VLEN) return true;

    int last = Math.min(this.last(), r.last());
    int stride = stride() * r.stride();

    int useFirst;
    if (stride == 1) {
      useFirst = Math.max(this.first(), r.first());

    } else if (stride() == 1) { // then r has a stride

      if (r.first() >= first()) useFirst = r.first();
      else {
        int incr = (first() - r.first()) / stride;
        useFirst = r.first() + incr * stride;
        if (useFirst < first()) useFirst += stride;
      }

    } else if (r.stride() == 1) { // then this has a stride

      if (first() >= r.first()) useFirst = first();
      else {
        int incr = (r.first() - first()) / stride;
        useFirst = first() + incr * stride;
        if (useFirst < r.first()) useFirst += stride;
      }

    } else {
      throw new UnsupportedOperationException("Intersection when both ranges have a stride");
    }

    return (useFirst <= last);
  }
Exemple #2
0
  @Test
  public void testStride() throws InvalidRangeException {
    int nx = 1237;
    Range r = new Range(0, nx - 1, 9);
    System.out.printf("%s%n", r);
    System.out.printf("%d %d %d %d%n", r.first(), r.last(), r.stride(), r.length());
    assert r.first() == 0;
    assert r.last() == 1233;
    assert r.stride() == 9;
    assert r.length() == 138;

    Section s = new Section(r, r);
    Section.Iterator iter = s.getIterator(new int[] {nx, nx});
    int[] iterResult = new int[2];
    int count = 0;
    for (int y = r.first(); y <= r.last(); y += r.stride()) {
      for (int x = r.first(); x <= r.last(); x += r.stride()) {
        assert iter.hasNext();
        int iterN = iter.next(iterResult);
        assert iterResult[0] == y;
        assert iterResult[1] == x;
        assert iterN == y * nx + x;
        count++;
      }
    }
    assert count == 138 * 138;
  }
  public Array readData(Variable v2, Section section) throws IOException, InvalidRangeException {
    // Vgroup vgroup = (Vgroup) v2.getSPobject();
    // Range scanRange = section.getRange(0);
    // Range radialRange = section.getRange(1);
    // Range gateRange = section.getRange(2);

    Array data = Array.factory(v2.getDataType().getPrimitiveClassType(), section.getShape());
    IndexIterator ii = data.getIndexIterator();

    List<List<Ray>> groups;
    String shortName = v2.getShortName();
    if (shortName.startsWith("Reflectivity")) groups = volScan.getReflectivityGroups();
    else if (shortName.startsWith("Velocity")) groups = volScan.getVelocityGroups();
    else if (shortName.startsWith("TotalPower")) groups = volScan.getTotalPowerGroups();
    else if (shortName.startsWith("Width")) groups = volScan.getWidthGroups();
    else if (shortName.startsWith("DiffReflectivity"))
      groups = volScan.getDifferentialReflectivityGroups();
    else throw new IllegalStateException("Illegal variable name = " + shortName);

    if (section.getRank() == 2) {
      Range radialRange = section.getRange(0);
      Range gateRange = section.getRange(1);
      List<Ray> lli = groups.get(0);
      readOneScan(lli, radialRange, gateRange, ii);
    } else {
      Range scanRange = section.getRange(0);
      Range radialRange = section.getRange(1);
      Range gateRange = section.getRange(2);
      for (int i = scanRange.first(); i <= scanRange.last(); i += scanRange.stride()) {
        readOneScan(groups.get(i), radialRange, gateRange, ii);
      }
    }
    return data;
  }
 private void readOneRadial(Ray r, Range gateRange, IndexIterator ii) throws IOException {
   if (r == null) {
     for (int i = gateRange.first(); i <= gateRange.last(); i += gateRange.stride())
       ii.setFloatNext(Float.NaN);
     return;
   }
   r.readData(volScan.raf, gateRange, ii);
 }
 private void readOneScan(
     Cinrad2Record[] mapScan, Range radialRange, Range gateRange, int datatype, IndexIterator ii)
     throws IOException {
   for (int i = radialRange.first(); i <= radialRange.last(); i += radialRange.stride()) {
     Cinrad2Record r = mapScan[i];
     readOneRadial(r, datatype, gateRange, ii);
   }
 }
 private void readOneRadial(Cinrad2Record r, int datatype, Range gateRange, IndexIterator ii)
     throws IOException {
   if (r == null) {
     for (int i = gateRange.first(); i <= gateRange.last(); i += gateRange.stride())
       ii.setByteNext(Cinrad2Record.MISSING_DATA);
     return;
   }
   r.readData(volScan.raf, datatype, gateRange, ii);
 }
Exemple #7
0
 /**
  * Create a new Range by composing a Range that is reletive to this Range. Revised 2013/04/19 by
  * Dennis Heimbigner to handle edge cases. See the commentary associated with the netcdf-c file
  * dceconstraints.h, function dceslicecompose().
  *
  * @param r range reletive to base
  * @return combined Range, may be EMPTY
  * @throws InvalidRangeException elements must be nonnegative, 0 <= first <= last
  */
 public Range compose(Range r) throws InvalidRangeException {
   if ((length() == 0) || (r.length() == 0)) return EMPTY;
   if (this == VLEN || r == VLEN) return VLEN;
   if (false) { // Original version
     // Note that this version assumes that range r is
     // correct with respect to this.
     int first = element(r.first());
     int stride = stride() * r.stride();
     int last = element(r.last());
     return new Range(name, first, last, stride);
   } else { // new version: handles versions all values of r.
     int sr_stride = stride() * r.stride();
     int sr_first = element(r.first()); // MAP(this,i) == element(i)
     int lastx = element(r.last());
     int sr_last = (last() < lastx ? last() : lastx); // min(last(),lastx)
     // unused int sr_length = (sr_last + 1) - sr_first;
     return new Range(name, sr_first, sr_last, sr_stride);
   }
 }
 private void readOneScan(List<Ray> mapScan, Range radialRange, Range gateRange, IndexIterator ii)
     throws IOException {
   int siz = mapScan.size();
   for (int i = radialRange.first(); i <= radialRange.last(); i += radialRange.stride()) {
     if (i >= siz) readOneRadial(null, gateRange, ii);
     else {
       Ray r = mapScan.get(i);
       readOneRadial(r, gateRange, ii);
     }
   }
 }
Exemple #9
0
  /**
   * Create a new Range by intersecting with a Range using same interval as this Range. NOTE: we
   * dont yet support intersection when both Ranges have strides
   *
   * @param r range to intersect
   * @return intersected Range, may be EMPTY
   * @throws InvalidRangeException elements must be nonnegative
   */
  public Range intersect(Range r) throws InvalidRangeException {
    if ((length() == 0) || (r.length() == 0)) return EMPTY;
    if (this == VLEN || r == VLEN) return VLEN;

    int last = Math.min(this.last(), r.last());
    int stride = stride() * r.stride();

    int useFirst;
    if (stride == 1) {
      useFirst = Math.max(this.first(), r.first());

    } else if (stride() == 1) { // then r has a stride

      if (r.first() >= first()) useFirst = r.first();
      else {
        int incr = (first() - r.first()) / stride;
        useFirst = r.first() + incr * stride;
        if (useFirst < first()) useFirst += stride;
      }

    } else if (r.stride() == 1) { // then this has a stride

      if (first() >= r.first()) useFirst = first();
      else {
        int incr = (r.first() - first()) / stride;
        useFirst = first() + incr * stride;
        if (useFirst < r.first()) useFirst += stride;
      }

    } else {
      throw new UnsupportedOperationException("Intersection when both ranges have a stride");
    }

    if (useFirst > last) return EMPTY;
    return new Range(name, useFirst, last, stride);
  }
  public Array readData(Variable v2, Section section) throws IOException, InvalidRangeException {
    Vgroup vgroup = (Vgroup) v2.getSPobject();

    Range scanRange = section.getRange(0);
    Range radialRange = section.getRange(1);
    Range gateRange = section.getRange(2);

    Array data = Array.factory(v2.getDataType().getPrimitiveClassType(), section.getShape());
    IndexIterator ii = data.getIndexIterator();

    for (int i = scanRange.first(); i <= scanRange.last(); i += scanRange.stride()) {
      Cinrad2Record[] mapScan = vgroup.map[i];
      readOneScan(mapScan, radialRange, gateRange, vgroup.datatype, ii);
    }

    return data;
  }
Exemple #11
0
 /**
  * Copy Constructor with name
  *
  * @param name result name
  * @param r copy from here
  */
 public Range(String name, Range r) {
   this.name = name;
   first = r.first();
   n = r.length();
   stride = r.stride();
 }
Exemple #12
0
 /**
  * Copy Constructor
  *
  * @param r copy from here
  */
 public Range(Range r) {
   first = r.first();
   n = r.length();
   stride = r.stride();
   name = r.getName();
 }