diff --git a/cdm/src/main/java/ucar/nc2/iosp/netcdf3/N3iosp.java b/cdm/src/main/java/ucar/nc2/iosp/netcdf3/N3iosp.java index e6159f6..36ecf82 100644 --- a/cdm/src/main/java/ucar/nc2/iosp/netcdf3/N3iosp.java +++ b/cdm/src/main/java/ucar/nc2/iosp/netcdf3/N3iosp.java @@ -411,6 +411,56 @@ public String NC_check_name(String name) { } /** + * query to see if this IOSP supports the getLocalityInformation() function + * + * @return a boolean indicating that this IOSP supports the getLocalityInformation() call + */ + public boolean supportsLocalityInformation() { + return true; + } + + /** + * Returns an ArrayLong with each entry corresponding to the offset in the filestream + * of the same data cell in the section arguement to the function + * + * @param v2 the variable to get the data from + * @param section the record range to read + * @return an ArrayLong object that's the shape as the section arguement + * @throws InvalidRangeException on error + * @throws IOException on error + */ + public ArrayLong getLocalityInformation(ucar.nc2.Variable v2, Section section) + throws InvalidRangeException, IOException { + + // An array to hold the offsets that will be returned + ArrayLong array = new ArrayLong(section.getShape()); + + // Index into the results array + Index aIndex = array.getIndex(); + + // dataSize is used to increment the offsets within a given + // chunk appropriately + DataType type = v2.getDataType(); + int dataSize = type.getSize(); + + Layout layout = getLayout(v2, section); + + // iterate over all the chunks in the calculated Layout + while( layout.hasNext() ){ + Layout.Chunk chunk = layout.next(); + + // iterate over the elements in this chunk + for( int i = 0; i < chunk.getNelems(); i++){ + // write the offset into the results array, then iterate the index + array.setLong(aIndex, chunk.getSrcPos() + (i * dataSize)); + aIndex.incr(); + } + } + + return array; + } + + /** * Returns a Layout object for use by an N3iosp object * * @param v2 the variable to get the layout information for