This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Hello folks, I was just wondering if anyone in the community has been using the netcdf library for manipulating GRIB files and if you have come across any problems related to extracting subsets of data along x-y space of a 4D grid (T,Z,lat,lon) where size (Z=20,lat=630,lon=899). When I am trying to extract it at one go, I am getting the following error messages: for range: myList.add(0, new Range(0, 0, 1)); myList.add(1, new Range(0, 9, 2)); myList.add(2, new Range(500, 550, 1)); myList.add(3, new Range(700, 725, 1)); Array arr = myVar.read(myList); ArrayList newList = new ArrayList(); Error: java.lang.ArrayIndexOutOfBoundsException: 6630 at ucar.ma2.ArrayFloat.setFloat(ArrayFloat.java:193) at ucar.ma2.IteratorFast.setFloatNext(IteratorFast.java:61) at ucar.nc2.iosp.grib.GribServiceProvider.readXY(GribServiceProvider.java:177) at ucar.nc2.iosp.grib.GribServiceProvider.readLevel(GribServiceProvider.java:150) at ucar.nc2.iosp.grib.GribServiceProvider.readData(GribServiceProvider.java:134) at ucar.nc2.NetcdfFile.readData(NetcdfFile.java:848) at ucar.nc2.Variable._read(Variable.java:737) at ucar.nc2.Variable.read(Variable.java:451) at Test2netcdf.readData(Test2netcdf.java:50) at Test2netcdf.main(Test2netcdf.java:112) I have to extract the data in two stages.In the first step, I just have to extract data at a particular time and depth level(s) but all of latitude-longitude space. Then, in second stage I have to apply the range for latitude-longitude. ArrayList myList = new ArrayList(); myList.add(0, new Range(0, 0, 1)); myList.add(1, new Range(0, 9, 2)); myList.add(2, new Range(0, 629, 1));//all of lat myList.add(3, new Range(0, 899, 1));//all of lon Array arr = myVar.read(myList); ArrayList newList = new ArrayList(); int[] newShape = arr.getShape(); newList.add(0, new Range(0, 0, 1)); newList.add(1, new Range(0, (newShape[1]-1), 1)); newList.add(2, new Range(500, 550, 1));//apply range for lat newList.add(3, new Range(700, 725, 1));//apply range for lon Array new_arr = arr.sectionNoReduce(newList); float[] data = (float[])new_arr.copyTo1DJavaArray(); This approach is ok when extracting data from small number of files but the performance would deteriorate if extracting from 100+ files having quite big lat-lon spaces. Your comments would be much appreciated. Cheers, Adit