### Question:
InsituReader extends NetcdfReader { static void extractSubset(Array source, Array subset, List<Range> subsetRanges) throws InvalidRangeException { final List<Range> sourceRanges = new ArrayList<>(source.getRank()); for (int i = 0; i < source.getRank(); i++) { sourceRanges.add(null); } final IndexIterator subsetIterator = subset.getIndexIterator(); for (final Range s : subsetRanges) { sourceRanges.set(0, s); final Array sourceSection = source.section(sourceRanges); final IndexIterator sourceIterator = sourceSection.getIndexIterator(); while (sourceIterator.hasNext()) { subsetIterator.setObjectNext(sourceIterator.getObjectNext()); } } } InsituReader(String sensorName); @Override void open(DataFile datafile, File archiveRoot); @Override void close(); @Override int getNumRecords(); @Override InsituObservation readObservation(int recordNo); @Override List<SamplingPoint> readSamplingPoints(); @Override final Array read(String role, ExtractDefinition extractDefinition); @Override GeoCoding getGeoCoding(int recordNo); @Override double getDTime(int recordNo, int scanLine); @Override long getTime(int recordNo, int scanLine); @Override InsituSource getInsituSource(); @Override String getDatasetName(); @Override int getScanLineCount(); @Override int getElementCount();  }### Answer:
@Test public void testCreateSubset_1D() throws InvalidRangeException { final Array historyTimes = InsituData.createHistoryTimeArray_MJD(); final Range range = InsituReaderHelper.findRange(historyTimes, 2455090.56, 0.5); final List<Range> s = InsituReaderHelper.createSubsampling(historyTimes, range, 10); final Array subset = Array.factory(historyTimes.getElementType(), new int[]{1, 10}); InsituReader.extractSubset(historyTimes, subset, s); assertEquals(2, subset.getRank()); assertEquals(10, subset.getIndexPrivate().getShape(1)); assertEquals(historyTimes.getDouble(s.get(0).first()), subset.getDouble(0), 0.0); assertEquals(historyTimes.getDouble(s.get(9).first()), subset.getDouble(9), 0.0); }
@Test public void testCreateSubset_2D() throws InvalidRangeException { final Array historyTimes = InsituData.createHistoryTimeArray_MJD(); final int historyLength = historyTimes.getIndexPrivate().getShape(0); final Range range = InsituReaderHelper.findRange(historyTimes, 2455090.56, 0.5); final List<Range> s = InsituReaderHelper.createSubsampling(historyTimes, range, 10); final Array array = Array.factory(DataType.INT, new int[]{historyLength, 2}); final Array subset = Array.factory(array.getElementType(), new int[]{1, 10, 2}); InsituReader.extractSubset(array, subset, s); assertEquals(3, subset.getRank()); assertEquals(10, subset.getIndexPrivate().getShape(1)); assertEquals(2, subset.getIndexPrivate().getShape(2)); }