Package ucar.nc2.iosp
Class IndexChunker
- java.lang.Object
-
- ucar.nc2.iosp.IndexChunker
-
public class IndexChunker extends Object
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(IndexChunker index, int[] src) { int[] dest = new int[index.getTotalNelems()]; while (index.hasNext()) { Indexer2.Chunk chunk = index.next(); System.arraycopy(src, chunk.getSrcElem(), dest, chunk.getDestElem(), chunk.getNelems()); } return dest; } int[] read(IndexChunker index, RandomAccessFile raf, long start_pos) { int[] dest = new int[index.getTotalNelems()]; while (index.hasNext()) { Indexer2.Chunk chunk = index.next(); raf.seek(start_pos + chunk.getSrcElem() * 4); raf.readInt(dest, chunk.getDestElem(), chunk.getNelems()); } return dest; } // note src and dest misnamed void write(IndexChunker index, int[] src, RandomAccessFile raf, long start_pos) { while (index.hasNext()) { Indexer2.Chunk chunk = index.next(); raf.seek(start_pos + chunk.getSrcElem() * 4); raf.writeInt(src, chunk.getDestElem(), chunk.getNelems()); } }- Since:
- Jan 2, 2008
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classIndexChunker.ChunkA chunk of data that is contiguous in both the source and destination.
-
Constructor Summary
Constructors Constructor Description IndexChunker(int[] srcShape, Section wantSection)Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetTotalNelems()Get total number of elements in wantSectionbooleanhasNext()If there are more chunks to processIndexChunker.Chunknext()Get the next chunkprotected static Stringprinta(int[] a)protected static voidprinta(String name, int[] a)protected static voidprintl(String name, long[] a)StringtoString()
-
-
-
Constructor Detail
-
IndexChunker
public IndexChunker(int[] srcShape, @Nullable Section wantSection) throws InvalidRangeExceptionConstructor- Parameters:
srcShape- the shape of the source, eg Variable.getShape()wantSection- the wanted section in srcShape, ie must be subset of srcShape.- Throws:
InvalidRangeException- if wantSection is incorrect
-
-
Method Detail
-
getTotalNelems
public long getTotalNelems()
Get total number of elements in wantSection- Returns:
- total number of elements in wantSection
-
hasNext
public boolean hasNext()
If there are more chunks to process- Returns:
- true if there are more chunks to process
-
next
public IndexChunker.Chunk next()
Get the next chunk- Returns:
- the next chunk
-
printa
protected static String printa(int[] a)
-
printa
protected static void printa(String name, int[] a)
-
printl
protected static void printl(String name, long[] a)
-
-