static public ucar.ma2.Array readSection(ParsedSectionSpec cer) throws IOException, InvalidRangeException { Variable inner = null; List<Range> totalRanges = new ArrayList<>(); ParsedSectionSpec current = cer; while (current != null) { totalRanges.addAll(current.section.getRanges()); inner = current.v; current = current.child; } assert inner != null; Section total = new Section(totalRanges); Array result = Array.factory(inner.getDataType(), total.getShape()); // must be a Structure Structure outer = (Structure) cer.v; Structure outerSubset = outer.select(cer.child.v.getShortName()); // allows IOSPs to optimize for this case ArrayStructure outerData = (ArrayStructure) outerSubset.read(cer.section); extractSection(cer.child, outerData, result.getIndexIterator()); return result; }
static private void extractSection(ParsedSectionSpec child, ArrayStructure outerData, IndexIterator to) throws IOException, InvalidRangeException { long wantNelems = child.section.computeSize(); StructureMembers.Member m = outerData.findMember(child.v.getShortName()); for (int recno = 0; recno < outerData.getSize(); recno++) { Array innerData = outerData.getArray(recno, m); if (child.child == null) { // inner variable if (wantNelems != innerData.getSize()) innerData = innerData.section(child.section.getRanges()); MAMath.copy(child.v.getDataType(), innerData.getIndexIterator(), to); } else { // not an inner variable - must be an ArrayStructure if (innerData instanceof ArraySequence) extractSectionFromSequence(child.child, (ArraySequence) innerData, to); else { if (wantNelems != innerData.getSize()) innerData = sectionArrayStructure(child, (ArrayStructure) innerData, m); extractSection(child.child, (ArrayStructure) innerData, to); } } } }
static private void extractSection(ParsedSectionSpec child, ArrayStructure outerData, IndexIterator to) throws IOException, InvalidRangeException { long wantNelems = child.section.computeSize(); StructureMembers.Member m = outerData.findMember(child.v.getShortName()); for (int recno = 0; recno < outerData.getSize(); recno++) { Array innerData = outerData.getArray(recno, m); if (child.child == null) { // inner variable if (wantNelems != innerData.getSize()) innerData = innerData.section(child.section.getRanges()); MAMath.copy(child.v.getDataType(), innerData.getIndexIterator(), to); } else { // not an inner variable - must be an ArrayStructure if (innerData instanceof ArraySequence) extractSectionFromSequence(child.child, (ArraySequence) innerData, to); else { if (wantNelems != innerData.getSize()) innerData = sectionArrayStructure(child, (ArrayStructure) innerData, m); extractSection(child.child, (ArrayStructure) innerData, to); } } } }
static public ucar.ma2.Array readSection(ParsedSectionSpec cer) throws IOException, InvalidRangeException { Variable inner = null; List<Range> totalRanges = new ArrayList<>(); ParsedSectionSpec current = cer; while (current != null) { totalRanges.addAll(current.section.getRanges()); inner = current.v; current = current.child; } assert inner != null; Section total = new Section(totalRanges); Array result = Array.factory(inner.getDataType(), total.getShape()); // must be a Structure Structure outer = (Structure) cer.v; Structure outerSubset = outer.select(cer.child.v.getShortName()); // allows IOSPs to optimize for this case ArrayStructure outerData = (ArrayStructure) outerSubset.read(cer.section); extractSection(cer.child, outerData, result.getIndexIterator()); result.setUnsigned(cer.v.isUnsigned()); return result; }
static private void extractSection(ParsedSectionSpec child, ArrayStructure outerData, IndexIterator to) throws IOException, InvalidRangeException { long wantNelems = child.section.computeSize(); StructureMembers.Member m = outerData.findMember(child.v.getShortName()); for (int recno = 0; recno < outerData.getSize(); recno++) { Array innerData = outerData.getArray(recno, m); if (child.child == null) { // inner variable if (wantNelems != innerData.getSize()) innerData = innerData.section(child.section.getRanges()); MAMath.copy(child.v.getDataType(), innerData.getIndexIterator(), to); } else { // not an inner variable - must be an ArrayStructure if (innerData instanceof ArraySequence) extractSectionFromSequence(child.child, (ArraySequence) innerData, to); else { if (wantNelems != innerData.getSize()) innerData = sectionArrayStructure(child, (ArrayStructure) innerData, m); extractSection(child.child, (ArrayStructure) innerData, to); } } } }
static public ucar.ma2.Array readSection(ParsedSectionSpec cer) throws IOException, InvalidRangeException { Variable inner = null; List<Range> totalRanges = new ArrayList<Range>(); ParsedSectionSpec current = cer; while (current != null) { totalRanges.addAll(current.section.getRanges()); inner = current.v; current = current.child; } Section total = new Section(totalRanges); Array result = Array.factory(inner.getDataType(), total.getShape()); // must be a Structure Structure outer = (Structure) cer.v; Structure outerSubset = outer.select(cer.child.v.getShortName()); // allows IOSPs to optimize for this case ArrayStructure outerData = (ArrayStructure) outerSubset.read(cer.section); extractSection(cer.child, outerData, result.getIndexIterator()); result.setUnsigned(cer.v.isUnsigned()); return result; }