Package ucar.nc2.iosp
Interface Layout
- All Known Subinterfaces:
LayoutBB
- All Known Implementing Classes:
LayoutBBTiled,LayoutRegular,LayoutRegularSegmented,LayoutSegmented,LayoutTiled
public interface Layout
Iterator to read/write subsets of a multidimensional array, finding the contiguous chunks.
The iteration is monotonic in both src and dest positions.
Example for Integers:
int[] read( Layout index, int[] src) {
int[] dest = new int[index.getTotalNelems()];
while (index.hasNext()) {
Layout.Chunk chunk = index.next();
System.arraycopy(src, chunk.getSrcElem(), dest, chunk.getDestElem(), chunk.getNelems());
}
return dest;
}
int[] read( Layout index, RandomAccessFile raf) {
int[] dest = new int[index.getTotalNelems()];
while (index.hasNext()) {
Layout.Chunk chunk = index.next();
raf.seek( chunk.getSrcPos());
raf.readInt(dest, chunk.getDestElem(), chunk.getNelems());
}
return dest;
}
// note src and dest misnamed
void write( Layout index, int[] src, RandomAccessFile raf) {
while (index.hasNext()) {
Layout.Chunk chunk = index.next();
raf.seek ( chunk.getSrcPos());
for (int k=0; k<chunk.getNelems(); k++)
raf.writeInt(src, chunk.getDestElem(), chunk.getNelems());
raf.writeInt( ii.getByteNext());
}
- Since:
- Jan 2, 2008
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA chunk of data that is contiguous in both the source and destination. -
Method Summary
-
Method Details
-
getTotalNelems
long getTotalNelems()Get total number of elements in the wanted subset.- Returns:
- total number of elements in the wanted subset.
-
getElemSize
int getElemSize()Get size of each element in bytes.- Returns:
- size of each element in bytes.
-
hasNext
boolean hasNext()Is there more to do- Returns:
- true if theres more to do
-
next
Layout.Chunk next()Get the next chunk- Returns:
- next chunk, or null if !hasNext()
-