double makeObsTimeValue(ArrayStructure abb) { int year = abb.convertScalarInt(0, abb.findMember(yearName)); int hour = abb.convertScalarInt(0, abb.findMember(hourName)); int min = (minName == null) ? 0 : abb.convertScalarInt(0, abb.findMember(minName)); int sec = (secName == null) ? 0 : abb.convertScalarInt(0, abb.findMember(secName)); if (dayName != null) { int day = abb.convertScalarInt(0, abb.findMember(dayName)); int month = abb.convertScalarInt(0, abb.findMember(monthName)); cal.set(year, month-1, day, hour, min, sec); } else { int doy = abb.convertScalarInt(0, abb.findMember(doyName)); cal.set(Calendar.YEAR, year); cal.set(Calendar.DAY_OF_YEAR, doy); cal.set(Calendar.HOUR_OF_DAY, hour); cal.set(Calendar.MINUTE, min); cal.set(Calendar.SECOND, sec); } Date d = cal.getTime(); return dateUnit.makeValue(d); }
/** * public by accident, do not call directly. * @return Array * @throws IOException on error */ @Override public Array reallyRead(Variable client, CancelTask cancelTask) throws IOException { if (isMemberOfStructure()) { // LOOK should be UnsupportedOperationException ?? List<String> memList = new ArrayList<String>(); memList.add(this.getShortName()); Structure s = getParentStructure().select(memList); ArrayStructure as = (ArrayStructure) s.read(); return as.extractMemberArray( as.findMember( getShortName())); } try { return ncfile.readData(this, getShapeAsSection()); } catch (InvalidRangeException e) { e.printStackTrace(); throw new IOException(e.getMessage()); // cant happen haha } }
/** * public by accident, do not call directly. * * @return Array * @throws IOException on error */ @Override public Array reallyRead(Variable client, CancelTask cancelTask) throws IOException { if (isMemberOfStructure()) { // LOOK should be UnsupportedOperationException ?? List<String> memList = new ArrayList<>(); memList.add(this.getShortName()); Structure s = getParentStructure().select(memList); ArrayStructure as = (ArrayStructure) s.read(); return as.extractMemberArray(as.findMember(getShortName())); } try { return ncfile.readData(this, getShapeAsSection()); } catch (InvalidRangeException e) { e.printStackTrace(); throw new IOException(e.getMessage()); // cant happen haha } }
/** * public by accident, do not call directly. * * @return Array * @throws IOException on error */ @Override public Array reallyRead(Variable client, CancelTask cancelTask) throws IOException { if (isMemberOfStructure()) { // LOOK should be UnsupportedOperationException ?? List<String> memList = new ArrayList<>(); memList.add(this.getShortName()); Structure s = getParentStructure().select(memList); ArrayStructure as = (ArrayStructure) s.read(); return as.extractMemberArray(as.findMember(getShortName())); } try { return ncfile.readData(this, getShapeAsSection()); } catch (InvalidRangeException e) { e.printStackTrace(); throw new IOException(e.getMessage()); // cant happen haha } }
private void addTime(ArrayStructure as) throws IOException { int n = (int) as.getSize(); Array timeData = Array.factory(double.class, new int[]{n}); IndexIterator ii = timeData.getIndexIterator(); StructureDataIterator iter = as.getStructureDataIterator(); while (iter.hasNext()) ii.setDoubleNext(construct.makeObsTimeValue(iter.next())); StructureMembers.Member m = as.findMember(ConstructNC.TIME_NAME); m.setDataArray(timeData); }
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 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); } } } }
@Ignore("cant deal with BUFR at the moment") @Test public void testNestedTableEnhanced() throws IOException, InvalidRangeException { String filename = TestDir.cdmLocalTestDataDir + "dataset/nestedTable.bufr"; try (NetcdfFile ncfile = ucar.nc2.dataset.NetcdfDataset.openDataset(filename)) { logger.debug("Open {}", ncfile.getLocation()); SequenceDS outer = (SequenceDS) ncfile.findVariable(BufrIosp2.obsRecord); assert outer != null; try (StructureDataIterator iter = outer.getStructureIterator()) { StructureData data = null; if (iter.hasNext()) data = iter.next(); assert data != null; assert Double.isNaN(data.getScalarFloat("Latitude_coarse_accuracy")); ArrayStructure as = data.getArrayStructure("Geopotential"); assert as != null; Assert2.assertNearlyEquals(as.getScalarFloat(0, as.findMember("Wind_speed")), 6.1); } } } }
@Ignore("cant deal with BUFR at the moment") @Test public void testNestedTable() throws IOException, InvalidRangeException { String filename = TestDir.cdmLocalTestDataDir + "dataset/nestedTable.bufr"; try (NetcdfFile ncfile = ucar.nc2.dataset.NetcdfDataset.openFile(filename, null)) { logger.debug("Open {}", ncfile.getLocation()); Sequence outer = (Sequence) ncfile.findVariable(BufrIosp2.obsRecord); assert outer != null; try (StructureDataIterator iter = outer.getStructureIterator()) { StructureData data = null; if (iter.hasNext()) data = iter.next(); assert data != null; assert data.getScalarShort("Latitude_coarse_accuracy") == 32767; ArrayStructure as = data.getArrayStructure("Geopotential"); assert as != null; assert as.getScalarShort(0, as.findMember("Wind_speed")) == 61; } } }