sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1799206 - in /sis/branches/JDK8/storage: sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/ sis-netcdf/src/ma...
Date Mon, 19 Jun 2017 12:50:06 GMT
Author: desruisseaux
Date: Mon Jun 19 12:50:05 2017
New Revision: 1799206

URL: http://svn.apache.org/viewvc?rev=1799206&view=rev
Log:
Allow NetCDF GridGeometry to query the values of a localisation grid when constructing metadata
about axes.
Various documentation improvements.

Modified:
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/GridGeometry.java
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/FeaturesInfo.java
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridGeometryWrapper.java
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
    sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/ConformanceTest.java
    sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
    sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/HyperRectangleReader.java

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java?rev=1799206&r1=1799205&r2=1799206&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Axis.java
[UTF-8] Mon Jun 19 12:50:05 2017
@@ -16,8 +16,10 @@
  */
 package org.apache.sis.internal.netcdf;
 
+import java.io.IOException;
 import org.apache.sis.util.ArraysExt;
 import org.apache.sis.storage.netcdf.AttributeNames;
+import org.apache.sis.storage.DataStoreException;
 
 
 /**
@@ -64,14 +66,16 @@ public final class Axis {
      * by itself which grid dimension varies fastest and reorder in-place the elements in
the given arrays
      * (those array are modified, not cloned).
      *
-     * @param owner             provides callback for the conversion from grid coordinates
to geodetic coordinates.
-     * @param axis              an implementation-dependent object representing the two-dimensional
axis, or {@code null} if none.
-     * @param attributeNames    the attributes to use for fetching dimension information,
or {@code null} if unknown.
-     * @param sourceDimensions  the index of the grid dimension associated to this axis.
-     * @param sourceSizes       the number of cell elements along that axis.
+     * @param  owner             provides callback for the conversion from grid coordinates
to geodetic coordinates.
+     * @param  axis              an implementation-dependent object representing the two-dimensional
axis, or {@code null} if none.
+     * @param  attributeNames    the attributes to use for fetching dimension information,
or {@code null} if unknown.
+     * @param  sourceDimensions  the index of the grid dimension associated to this axis.
+     * @param  sourceSizes       the number of cell elements along that axis.
+     * @throws IOException if an I/O operation was necessary but failed.
+     * @throws DataStoreException if a logical error occurred.
      */
     public Axis(final GridGeometry owner, final Object axis, final AttributeNames.Dimension
attributeNames,
-            final int[] sourceDimensions, final int[] sourceSizes)
+            final int[] sourceDimensions, final int[] sourceSizes) throws IOException, DataStoreException
     {
         this.attributeNames   = attributeNames;
         this.sourceDimensions = sourceDimensions;

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java?rev=1799206&r1=1799205&r2=1799206&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java
[UTF-8] Mon Jun 19 12:50:05 2017
@@ -217,6 +217,7 @@ public abstract class Decoder implements
      *
      * @return all grid geometries, or an empty array if none.
      * @throws IOException if an I/O operation was necessary but failed.
+     * @throws DataStoreException if a logical error occurred.
      */
-    public abstract GridGeometry[] getGridGeometries() throws IOException;
+    public abstract GridGeometry[] getGridGeometries() throws IOException, DataStoreException;
 }

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/GridGeometry.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/GridGeometry.java?rev=1799206&r1=1799205&r2=1799206&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/GridGeometry.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/GridGeometry.java
[UTF-8] Mon Jun 19 12:50:05 2017
@@ -16,6 +16,9 @@
  */
 package org.apache.sis.internal.netcdf;
 
+import java.io.IOException;
+import org.apache.sis.storage.DataStoreException;
+
 
 /**
  * Information about the grid geometry and the conversion from grid coordinates to geodetic
coordinates.
@@ -53,21 +56,27 @@ public abstract class GridGeometry {
     /**
      * Returns the axes of the coordinate reference system. The size of this array is expected
equals to the
      * value returned by {@link #getTargetDimensions()}, but the caller should be robust
to inconsistencies.
-     * This array may not be a clone, so callers shall not modify it.
+     *
+     * <p>This method is used mostly for producing ISO 19115 metadata. It is typically
invoked only once.</p>
      *
      * @return the CRS axes, in NetCDF order (reverse of "natural" order).
+     * @throws IOException if an I/O operation was necessary but failed.
+     * @throws DataStoreException if a logical error occurred.
      */
-    public abstract Axis[] getAxes();
+    public abstract Axis[] getAxes() throws IOException, DataStoreException;
 
     /**
-     * Returns a coordinate for the given two-dimensional grid coordinate axis. This is (indirectly)
-     * a callback method for {@link #getAxes()}. In the NetCDF UCAR API, this method maps
directly
-     * to {@link ucar.nc2.dataset.CoordinateAxis2D#getCoordValue(int, int)}.
+     * Returns a coordinate for the given two-dimensional grid coordinate axis. This is (indirectly)
a callback
+     * method for {@link #getAxes()}. The (<var>i</var>, <var>j</var>)
indices are grid indices <em>before</em>
+     * they get reordered by the {@link Axis} constructor. In the NetCDF UCAR API, this method
maps directly to
+     * {@link ucar.nc2.dataset.CoordinateAxis2D#getCoordValue(int, int)}.
      *
      * @param  axis  an implementation-dependent object representing the two-dimensional
axis, or {@code null} if none.
      * @param  j     the fastest varying (right-most) index.
      * @param  i     the slowest varying (left-most) index.
      * @return the coordinate at the given index, or {@link Double#NaN} if it can not be
computed.
+     * @throws IOException if an I/O operation was necessary but failed.
+     * @throws DataStoreException if a logical error occurred.
      */
-    protected abstract double coordinateForAxis(Object axis, int j, int i);
+    protected abstract double coordinateForAxis(Object axis, int j, int i) throws IOException,
DataStoreException;
 }

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java?rev=1799206&r1=1799205&r2=1799206&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
[UTF-8] Mon Jun 19 12:50:05 2017
@@ -166,6 +166,28 @@ public abstract class Variable extends N
 
     /**
      * Reads all the data for this variable and returns them as an array of a Java primitive
type.
+     * Multi-dimensional variables are flattened as a one-dimensional array (wrapped in a
vector).
+     * Example:
+     *
+     * {@preformat text
+     *   DIMENSIONS:
+     *     time: 3
+     *     lat : 2
+     *     lon : 4
+     *
+     *   VARIABLES:
+     *     temperature (time,lat,lon)
+     *
+     *   DATA INDICES:
+     *     (0,0,0) (0,0,1) (0,0,2) (0,0,3)
+     *     (0,1,0) (0,1,1) (0,1,2) (0,1,3)
+     *     (1,0,0) (1,0,1) (1,0,2) (1,0,3)
+     *     (1,1,0) (1,1,1) (1,1,2) (1,1,3)
+     *     (2,0,0) (2,0,1) (2,0,2) (2,0,3)
+     *     (2,1,0) (2,1,1) (2,1,2) (2,1,3)
+     * }
+     *
+     * This method may cache the returned vector, at implementation choice.
      *
      * @return the data as an array of a Java primitive type.
      * @throws IOException if an error occurred while reading the data.
@@ -183,6 +205,9 @@ public abstract class Variable extends N
      *       to {@code Integer.toUnsignedLong(getGridEnvelope()[i])} exclusive.</li>
      * </ul>
      *
+     * If the variable has more than one dimension, then the data are packed in a one-dimensional
vector
+     * in the same way than {@link #read()}.
+     *
      * @param  areaLower    index of the first value to read along each dimension.
      * @param  areaUpper    index after the last value to read along each dimension.
      * @param  subsampling  sub-sampling along each dimension. 1 means no sub-sampling.

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java?rev=1799206&r1=1799205&r2=1799206&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
[UTF-8] Mon Jun 19 12:50:05 2017
@@ -773,7 +773,8 @@ public final class ChannelDecoder extend
             /*
              * First, find all variables which are used as coordinate system axis. The keys
in the map are
              * the grid dimensions which are the domain of the variable (i.e. the sources
of the conversion
-             * from grid coordinates to CRS coordinates).
+             * from grid coordinates to CRS coordinates). For each key there is usually only
one value, but
+             * we try to make this code robust to unusual NetCDF files.
              */
             final Map<Dimension, List<VariableInfo>> dimToAxes = new IdentityHashMap<>();
             for (final VariableInfo variable : variables) {
@@ -804,7 +805,7 @@ nextVar:    for (final VariableInfo vari
                      * This is a "all or nothing" operation.
                      */
                     for (final Dimension dimension : variable.dimensions) {
-                        final List<VariableInfo> axis = dimToAxes.get(dimension);
+                        final List<VariableInfo> axis = dimToAxes.get(dimension); 
     // Should have only 1 element.
                         if (axis == null) {
                             axes.clear();
                             continue nextVar;

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/FeaturesInfo.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/FeaturesInfo.java?rev=1799206&r1=1799205&r2=1799206&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/FeaturesInfo.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/FeaturesInfo.java
[UTF-8] Mon Jun 19 12:50:05 2017
@@ -148,7 +148,7 @@ search: for (final VariableInfo counts :
                         }
                     }
                     /*
-                     * At this point, all information has been verified as valid.
+                     * At this point, all information have been verified as valid.
                      */
                     features.add(new FeaturesInfo(counts.read().compress(0), identifiers));
                 }

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java?rev=1799206&r1=1799205&r2=1799206&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/GridGeometryInfo.java
[UTF-8] Mon Jun 19 12:50:05 2017
@@ -16,10 +16,15 @@
  */
 package org.apache.sis.internal.netcdf.impl;
 
+import java.io.IOException;
+import java.util.TreeMap;
+import java.util.SortedMap;
 import org.apache.sis.util.ArraysExt;
 import org.apache.sis.internal.netcdf.Axis;
 import org.apache.sis.internal.netcdf.GridGeometry;
 import org.apache.sis.storage.netcdf.AttributeNames;
+import org.apache.sis.storage.DataStoreException;
+import org.apache.sis.util.resources.Errors;
 
 
 /**
@@ -103,17 +108,31 @@ final class GridGeometryInfo extends Gri
      * "two-dimensional axes" (in {@link ucar.nc2.dataset.CoordinateAxis2D} sense).</p>
      *
      * @return the CRS axes, in NetCDF order (reverse of "natural" order).
+     * @throws IOException if an I/O operation was necessary but failed.
+     * @throws DataStoreException if a logical error occurred.
      */
     @Override
-    public Axis[] getAxes() {
+    public Axis[] getAxes() throws IOException, DataStoreException {
+        /*
+         * Process the variables in the order the appear in the sequence of bytes that make
the NetCDF files.
+         * This is often the same order than the indices, but not necessarily. The intend
is to reduce the
+         * amount of disk seek operations.
+         */
+        final SortedMap<VariableInfo,Integer> variables = new TreeMap<>();
+        for (int i=0; i<range.length; i++) {
+            final VariableInfo v = range[i];
+            if (variables.put(v, i) != null) {
+                throw new DataStoreException(Errors.format(Errors.Keys.DuplicatedElement_1,
v.getName()));
+            }
+        }
         /*
          * In this method, 'sourceDim' and 'targetDim' are relative to "grid to CRS" conversion.
          * So 'sourceDim' is the grid (domain) dimension and 'targetDim' is the CRS (range)
dimension.
          */
-        int targetDim = range.length;
-        final Axis[] axes = new Axis[targetDim];
-        while (--targetDim >= 0) {
-            final VariableInfo axis = range[targetDim];
+        final Axis[] axes = new Axis[range.length];
+        for (final SortedMap.Entry<VariableInfo,Integer> entry : variables.entrySet())
{
+            final int targetDim = entry.getValue();
+            final VariableInfo axis = entry.getKey();
             /*
              * The AttributeNames are for ISO 19115 metadata. They are not used for locating
grid cells
              * on Earth, but we nevertheless get them now for making MetadataReader work
easier.
@@ -138,7 +157,7 @@ final class GridGeometryInfo extends Gri
             final int[] indices = new int[axisDomain.length];
             final int[] sizes   = new int[axisDomain.length];
             for (final Dimension dimension : axisDomain) {
-                for (int sourceDim=domain.length; --sourceDim>=0;) {
+                for (int sourceDim = domain.length; --sourceDim >= 0;) {
                     if (domain[sourceDim] == dimension) {
                         indices[i] = sourceDim;
                         sizes[i++] = dimension.length;
@@ -146,15 +165,21 @@ final class GridGeometryInfo extends Gri
                     }
                 }
             }
-            axes[targetDim] = new Axis(this, null, attributeNames,
-                                 ArraysExt.resize(indices, i),
-                                 ArraysExt.resize(sizes, i));
+            axes[targetDim] = new Axis(this, axis, attributeNames,
+                                       ArraysExt.resize(indices, i),
+                                       ArraysExt.resize(sizes, i));
         }
         return axes;
     }
 
+    /**
+     * Returns a coordinate for the given two-dimensional grid coordinate axis.
+     * This is (indirectly) a callback method for {@link #getAxes()}.
+     */
     @Override
-    protected double coordinateForAxis(final Object axis, final int j, final int i) {
-        throw new UnsupportedOperationException();
+    protected double coordinateForAxis(final Object axis, final int j, final int i) throws
IOException, DataStoreException {
+        final VariableInfo v = ((VariableInfo) axis);
+        final int n = v.getGridEnvelope()[0];
+        return v.read().doubleValue(j + n*i);
     }
 }

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java?rev=1799206&r1=1799205&r2=1799206&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/VariableInfo.java
[UTF-8] Mon Jun 19 12:50:05 2017
@@ -37,6 +37,8 @@ import org.apache.sis.math.Vector;
 
 /**
  * Description of a variable found in a NetCDF file.
+ * The natural ordering of {@code VariableInfo} is the order in which the variables appear
in the stream of bytes
+ * that make the NetCDF file. Reading variables in natural order reduces the amount of channel
seek operations.
  *
  * @author  Johann Sorel (Geomatys)
  * @author  Martin Desruisseaux (Geomatys)
@@ -44,7 +46,7 @@ import org.apache.sis.math.Vector;
  * @since   0.3
  * @module
  */
-final class VariableInfo extends Variable {
+final class VariableInfo extends Variable implements Comparable<VariableInfo> {
     /**
      * The array to be returned by {@link #numberValues(Object)} when the given value is
null.
      */
@@ -119,6 +121,13 @@ final class VariableInfo extends Variabl
     private final boolean isCoordinateSystemAxis;
 
     /**
+     * The values of the whole variable, or {@code null} if not yet read. This vector should
be assigned only
+     * for relatively small variables, or for variables that are critical to the use of other
variables
+     * (for example the values in coordinate system axes).
+     */
+    private transient Vector values;
+
+    /**
      * Creates a new variable.
      *
      * @param  input       the channel together with a buffer for reading the variable data.
@@ -353,31 +362,39 @@ final class VariableInfo extends Variabl
 
     /**
      * Reads all the data for this variable and returns them as an array of a Java primitive
type.
+     * Multi-dimensional variables are flattened as a one-dimensional array (wrapped in a
vector).
+     * The vector is cached and returned as-is in all future invocation of this method.
      */
     @Override
+    @SuppressWarnings("ReturnOfCollectionOrArrayField")
     public Vector read() throws IOException, DataStoreException {
-        if (reader == null) {
-            throw new DataStoreContentException(unknownType());
-        }
-        long length = 1;
-        for (final Dimension dimension : dimensions) {
-            length *= dimension.length;
-        }
-        if (length > Integer.MAX_VALUE) {
-            throw new DataStoreContentException(Errors.format(Errors.Keys.ExcessiveListSize_2,
name, length));
-        }
-        final int dimension = dimensions.length;
-        final long[] size  = new long[dimension];
-        final int [] sub   = new int [dimension];
-        for (int i=0; i<dimension; i++) {
-            sub [i] = 1;
-            size[i] = dimensions[(dimension - 1) - i].length();
+        if (values == null) {
+            if (reader == null) {
+                throw new DataStoreContentException(unknownType());
+            }
+            long length = 1;
+            for (final Dimension dimension : dimensions) {
+                length *= dimension.length();
+            }
+            if (length > Integer.MAX_VALUE) {
+                throw new DataStoreContentException(Errors.format(Errors.Keys.ExcessiveListSize_2,
name, length));
+            }
+            final int dimension = dimensions.length;
+            final long[] size  = new long[dimension];
+            final int [] sub   = new int [dimension];
+            for (int i=0; i<dimension; i++) {
+                sub [i] = 1;
+                size[i] = dimensions[(dimension - 1) - i].length();
+            }
+            values = Vector.create(reader.read(new Region(size, new long[dimension], size,
sub)), dataType.isUnsigned)
+                    .compress(0);
         }
-        return Vector.create(reader.read(new Region(size, new long[dimension], size, sub)),
dataType.isUnsigned);
+        return values;
     }
 
     /**
      * Reads a sub-sampled sub-area of the variable.
+     * Multi-dimensional variables are flattened as a one-dimensional array (wrapped in a
vector).
      *
      * @param  areaLower    index of the first value to read along each dimension, as unsigned
integers.
      * @param  areaUpper    index after the last value to read along each dimension, as unsigned
integers.
@@ -429,4 +446,15 @@ final class VariableInfo extends Variabl
     private String unknownType() {
         return Errors.format(Errors.Keys.UnknownType_1, "NetCDF:" + dataType);
     }
+
+    /**
+     * Returns -1 if this variable is located before the other variable in the streal of
bytes that make
+     * the NetCDF file, or +1 if it is located after.
+     */
+    @Override
+    public int compareTo(final VariableInfo other) {
+        int c = Long.compare(reader.origin, other.reader.origin);
+        if (c == 0) c = name.compareTo(other.name);                 // Should not happen,
but we are paranoiac.
+        return c;
+    }
 }

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridGeometryWrapper.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridGeometryWrapper.java?rev=1799206&r1=1799205&r2=1799206&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridGeometryWrapper.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/GridGeometryWrapper.java
[UTF-8] Mon Jun 19 12:50:05 2017
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.internal.netcdf.ucar;
 
+import java.io.IOException;
 import java.util.List;
 import ucar.nc2.Dimension;
 import ucar.nc2.constants.AxisType;
@@ -25,6 +26,7 @@ import ucar.nc2.dataset.CoordinateSystem
 import org.apache.sis.internal.netcdf.Axis;
 import org.apache.sis.internal.netcdf.GridGeometry;
 import org.apache.sis.storage.netcdf.AttributeNames;
+import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.util.ArraysExt;
 
 
@@ -87,9 +89,11 @@ final class GridGeometryWrapper extends
      * of {@link CoordinateAxis2D}.</p>
      *
      * @return the CRS axes, in NetCDF order (reverse of "natural" order).
+     * @throws IOException if an I/O operation was necessary but failed.
+     * @throws DataStoreException if a logical error occurred.
      */
     @Override
-    public Axis[] getAxes() {
+    public Axis[] getAxes() throws IOException, DataStoreException {
         final List<Dimension> domain = netcdfCS.getDomain();
         final List<CoordinateAxis> range = netcdfCS.getCoordinateAxes();
         /*
@@ -136,15 +140,15 @@ final class GridGeometryWrapper extends
                  */
             }
             axes[targetDim] = new Axis(this, axis, attributeNames,
-                                 ArraysExt.resize(indices, i),
-                                 ArraysExt.resize(sizes, i));
+                                       ArraysExt.resize(indices, i),
+                                       ArraysExt.resize(sizes, i));
         }
         return axes;
     }
 
     /**
      * Returns a coordinate for the given two-dimensional grid coordinate axis.
-     * This is a callback method for {@link #getAxes()}.
+     * This is (indirectly) a callback method for {@link #getAxes()}.
      */
     @Override
     protected double coordinateForAxis(final Object axis, final int j, final int i) {

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java?rev=1799206&r1=1799205&r2=1799206&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
[UTF-8] Mon Jun 19 12:50:05 2017
@@ -165,10 +165,12 @@ final class VariableWrapper extends Vari
 
     /**
      * Reads all the data for this variable and returns them as an array of a Java primitive
type.
+     * Multi-dimensional variables are flattened as a one-dimensional array (wrapped in a
vector).
+     * This method may cache the returned vector, at UCAR library choice.
      */
     @Override
     public Vector read() throws IOException {
-        final Array array = variable.read();
+        final Array array = variable.read();                // May be cached by the UCAR
library.
         return Vector.create(array.get1DJavaArray(array.getElementType()), variable.isUnsigned());
     }
 

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java?rev=1799206&r1=1799205&r2=1799206&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
[UTF-8] Mon Jun 19 12:50:05 2017
@@ -49,6 +49,7 @@ import org.opengis.referencing.crs.Verti
 
 import org.apache.sis.util.iso.Types;
 import org.apache.sis.util.iso.SimpleInternationalString;
+import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.metadata.iso.DefaultMetadata;
 import org.apache.sis.metadata.iso.citation.*;
 import org.apache.sis.metadata.iso.identification.*;
@@ -629,7 +630,7 @@ split:  while ((start = CharSequences.sk
      *
      * @param  cs  the grid geometry (related to the NetCDF coordinate system).
      */
-    private void addSpatialRepresentationInfo(final GridGeometry cs) {
+    private void addSpatialRepresentationInfo(final GridGeometry cs) throws IOException,
DataStoreException {
         final Axis[] axes = cs.getAxes();
         for (int i=axes.length; i>0;) {
             final int dim = axes.length - i;
@@ -879,8 +880,9 @@ split:  while ((start = CharSequences.sk
      *
      * @return the ISO metadata object.
      * @throws IOException if an I/O operation was necessary but failed.
+     * @throws DataStoreException if a logical error occurred.
      */
-    public Metadata read() throws IOException {
+    public Metadata read() throws IOException, DataStoreException {
         addFileIdentifier();
         addResourceScope(ScopeCode.DATASET, null);
         Set<InternationalString> publisher = addCitation();

Modified: sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/ConformanceTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/ConformanceTest.java?rev=1799206&r1=1799205&r2=1799206&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/ConformanceTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/ConformanceTest.java
[UTF-8] Mon Jun 19 12:50:05 2017
@@ -30,6 +30,7 @@ import org.apache.sis.metadata.iso.Defau
 import org.apache.sis.internal.netcdf.Decoder;
 import org.apache.sis.internal.netcdf.ucar.DecoderWrapper;
 import org.apache.sis.internal.netcdf.TestCase;
+import org.apache.sis.storage.DataStoreException;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestUtilities;
 import org.junit.Test;
@@ -69,8 +70,12 @@ public final strictfp class ConformanceT
     protected Metadata wrap(final NetcdfFile file) throws IOException {
         final Decoder decoder = new DecoderWrapper(TestCase.LISTENERS, file);
         final MetadataReader ncISO = new MetadataReader(decoder);
-        return ncISO.read();
-        // Do not close the file, as this will be done by the parent test class.
+        try {
+            return ncISO.read();
+            // Do not close the file, as this will be done by the parent test class.
+        } catch (DataStoreException e) {
+            throw new AssertionError(e);
+        }
     }
 
     /**

Modified: sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java?rev=1799206&r1=1799205&r2=1799206&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
[UTF-8] Mon Jun 19 12:50:05 2017
@@ -77,9 +77,10 @@ public final strictfp class MetadataRead
      * its string representation with the expected one.
      *
      * @throws IOException if an I/O error occurred.
+     * @throws DataStoreException if a logical error occurred.
      */
     @Test
-    public void testUCAR() throws IOException {
+    public void testUCAR() throws IOException, DataStoreException {
         final Metadata metadata;
         try (Decoder input = new DecoderWrapper(TestCase.LISTENERS, new NetcdfDataset(open(NCEP))))
{
             metadata = new MetadataReader(input).read();

Modified: sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/HyperRectangleReader.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/HyperRectangleReader.java?rev=1799206&r1=1799205&r2=1799206&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/HyperRectangleReader.java
[UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/io/HyperRectangleReader.java
[UTF-8] Mon Jun 19 12:50:05 2017
@@ -45,8 +45,11 @@ public final class HyperRectangleReader
 
     /**
      * The {@code input} position of the first sample (ignoring sub-area and sub-sampling).
+     * This is the {@code origin} argument given to the constructor, copied verbatim.
+     * This field is public for callers wanting to order {@code HyperRectangleReader} instances
+     * in increasing file offset order, for more sequential reading (less seek operations).
      */
-    private final long origin;
+    public final long origin;
 
     /**
      * Creates a new reader for the given input and source region.



Mime
View raw message