NOTICE: This version of the NSF Unidata web site (archive.unidata.ucar.edu) is no longer being updated.
Current content can be found at unidata.ucar.edu.

To learn about what's going on, see About the Archive Site.

Re: skip, stride reading...

Tom Rink wrote:

Hi,

How can skip or stride reading be done in the Java
implementation of NetCDF? Is there an equivalent
operation?

Tom Rink

Hi Tom:

I seem to have overlooked implementing a stride-based read, probably because the original (version 1) library doesnt have one. I will add this to the to-do list.

Meanwhile, you can get a strided subset of an Array, which will be equivilent except that you probably have to read more than you need:

Suppose you have a 3D Array, and you want to access it with stride 2, 1, and 3 in the three dimensions. The following will give you a logical view of the data with those strides, using the same backing data as the original:

Array data = var.read();
int[] shape = data.getShape();
Array dataS;
Range[] ranges = new Range[] { new Range(0,shape[0]-1, 2), null, new Range(0,shape[2]-1, 3) };

try {
dataS = data.section( ranges);
} catch (InvalidRangeException e) {
System.out.println("testStride failed == "+ e);
}

Note that the null second Range means “use all with stride one”. You can make a copy to get just the subset you want, so that the original data memory can be freed up:

dataS = dataS.copy(); // now is a separate data array





  • 2003 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: