@Override protected void showTableExtraInfo(String indent, Formatter f) { f.format("%sArrayStruct=%s, dim=%s%n", indent, new Section(as.getShape()), dim.getShortName()); }
@Override protected void showTableExtraInfo(String indent, Formatter f) { f.format("%sArrayStruct=%s, dim=%s%n", indent, new Section(as.getShape()), dim.getShortName()); }
@Override protected void showTableExtraInfo(String indent, Formatter f) { f.format("%sArrayStruct=%s, dim=%s%n", indent, new Section(as.getShape()), dim.getShortName()); }
/** * @deprecated use StructureDataDeep.copyToArrayBB */ static public ArrayStructureBB makeArrayBB(ArrayStructure as) throws IOException { if (as.getClass().equals(ArrayStructureBB.class)) // no subclasses return (ArrayStructureBB) as; StructureMembers smo = as.getStructureMembers(); StructureMembers sm = new StructureMembers(smo); ArrayStructureBB abb = new ArrayStructureBB(sm, as.getShape()); ArrayStructureBB.setOffsets(sm); try (StructureDataIterator iter = as.getStructureDataIterator()) { while (iter.hasNext()) StructureDataDeep.copyToArrayBB(iter.next(), abb); } return abb; }
NcStreamProto.ArrayStructureCol.Builder encodeStructureData(Array data) { assert data instanceof ArrayStructure; ArrayStructure as = (ArrayStructure) data; int nelems = (int) as.getSize(); // create MemberData to hold extracted data List<MemberData> memberDataList = new ArrayList<>(); StructureMembers sm = as.getStructureMembers(); for (StructureMembers.Member m : sm.getMembers()) { memberDataList.add(new MemberData(m, as.getShape())); } // data extraction for (int recno = 0; recno < nelems; recno++) { for (MemberData md : memberDataList) { if (md.member.isVariableLength()) { md.vlenList.add( as.getArray(recno, md.member)); } else { extractData(as, recno, md); } } } // construct the result recursively return buildNestedStructureData(memberDataList); }
/** * Make deep copy from an ArrayStructure to a ArrayStructureBB whose data is contained in a ByteBuffer * @param as original ArrayStructure * @param bo what byte order to use ? (null for any) * @param canonical packing must be canonical * @return ArrayStructureBB with all data self contained */ static public ArrayStructureBB copyToArrayBB(ArrayStructure as, ByteOrder bo, boolean canonical) throws IOException { if (!canonical && as.getClass().equals(ArrayStructureBB.class)) { // no subclasses, LOOK detect already canonical later ArrayStructureBB abb = (ArrayStructureBB) as; ByteBuffer bb = abb.getByteBuffer(); if (bo == null || bo.equals(bb.order())) return abb; } StructureMembers smo = as.getStructureMembers(); StructureMembers sm = new StructureMembers(smo); ArrayStructureBB abb = new ArrayStructureBB(sm, as.getShape()); ArrayStructureBB.setOffsets(sm); // this makes the packing canonical if (bo != null) { ByteBuffer bb = abb.getByteBuffer(); bb.order(bo); } try (StructureDataIterator iter = as.getStructureDataIterator()) { while (iter.hasNext()) copyToArrayBB(iter.next(), abb); } return abb; }
/** * Make deep copy from an ArrayStructure to a ArrayStructureBB whose data is contained in a ByteBuffer * @param as original ArrayStructure * @param bo what byte order to use ? (null for any) * @return ArrayStructureBB with all data self contained */ static public ArrayStructureBB copyToArrayBB(ArrayStructure as, ByteOrder bo) throws IOException { if (as.getClass().equals(ArrayStructureBB.class)) { // no subclasses ArrayStructureBB abb = (ArrayStructureBB) as; ByteBuffer bb = abb.getByteBuffer(); if (bo == null || bo.equals(bb.order())) return abb; } StructureMembers smo = as.getStructureMembers(); StructureMembers sm = new StructureMembers(smo); ArrayStructureBB abb = new ArrayStructureBB(sm, as.getShape()); ArrayStructureBB.setOffsets(sm); if (bo != null) { ByteBuffer bb = abb.getByteBuffer(); bb.order(bo); } StructureDataIterator iter = as.getStructureDataIterator(); try { while (iter.hasNext()) copyToArrayBB(iter.next(), abb); } finally { iter.finish(); } return abb; }
/** * @deprecated use StructureDataDeep.copyToArrayBB */ static public ArrayStructureBB makeArrayBB(ArrayStructure as) throws IOException { if (as.getClass().equals(ArrayStructureBB.class)) // no subclasses return (ArrayStructureBB) as; StructureMembers smo = as.getStructureMembers(); StructureMembers sm = new StructureMembers(smo); ArrayStructureBB abb = new ArrayStructureBB(sm, as.getShape()); ArrayStructureBB.setOffsets(sm); StructureDataIterator iter = as.getStructureDataIterator(); try { while (iter.hasNext()) StructureDataDeep.copyToArrayBB(iter.next(), abb); } finally { iter.finish(); } return abb; }
/** * Make deep copy to an ArrayStructureBB whose data is contained in a ByteBuffer. * Use the order of the members in the given Structure; skip copying any not in the Structure * @param s list of structure members come from here; must be compatible with ArrayStructure's data * @param as original ArrayStructure * @param bo what byte order to use ? (null for default) * @return ArrayStructureBB with all data self contained */ static public ArrayStructureBB copyToArrayBB(Structure s, ArrayStructure as, ByteOrder bo) throws IOException { StructureMembers sm = s.makeStructureMembers(); ArrayStructureBB abb = new ArrayStructureBB(sm, as.getShape()); ArrayStructureBB.setOffsets(sm); if (bo != null) { ByteBuffer bb = abb.getByteBuffer(); bb.order(bo); } try (StructureDataIterator iter = as.getStructureDataIterator()) { while (iter.hasNext()) copyToArrayBB(iter.next(), abb); } return abb; }
@Override public Array sectionNoReduce(List<Range> ranges) throws InvalidRangeException { Section viewSection = new Section(ranges); ArrayStructureW result = new ArrayStructureW(this.members, viewSection.getShape()); int count = 0; Section.Iterator iter = viewSection.getIterator(getShape()); while (iter.hasNext()) { int recno = iter.next(null); StructureData sd = getStructureData(recno); result.setStructureData(sd, count++); } return result; }
@Override public Array sectionNoReduce(List<Range> ranges) throws InvalidRangeException { Section viewSection = new Section(ranges); ArrayStructureW result = new ArrayStructureW(this.members, viewSection.getShape()); int count = 0; Section.Iterator iter = viewSection.getIterator(getShape()); while (iter.hasNext()) { int recno = iter.next(null); StructureData sd = getStructureData(recno); result.setStructureData(sd, count++); } return result; }
/** * Make deep copy to an ArrayStructureBB whose data is contained in a ByteBuffer. * Use the order of the members in the given Structure; skip copying any not in the Structure * @param s list of structure members come from here; must be compatible with ArrayStructure's data * @param as original ArrayStructure * @param bo what byte order to use ? (null for default) * @return ArrayStructureBB with all data self contained */ static public ArrayStructureBB copyToArrayBB(Structure s, ArrayStructure as, ByteOrder bo) throws IOException { StructureMembers sm = s.makeStructureMembers(); ArrayStructureBB abb = new ArrayStructureBB(sm, as.getShape()); ArrayStructureBB.setOffsets(sm); if (bo != null) { ByteBuffer bb = abb.getByteBuffer(); bb.order(bo); } StructureDataIterator iter = as.getStructureDataIterator(); try { while (iter.hasNext()) copyToArrayBB(iter.next(), abb); } finally { iter.finish(); } return abb; }
ArrayStructureMA to = new ArrayStructureMA(new StructureMembers(from.getStructureMembers()), from.getShape()); for (StructureMembers.Member m : from.getMembers()) { to.setMemberArray(m.getName(), from.extractMemberArray(m));
static public ArrayStructureBB makeArrayBB(ArrayStructure as) throws IOException { if (as instanceof ArrayStructureBB) return (ArrayStructureBB) as; StructureMembers smo = as.getStructureMembers(); StructureMembers sm = new StructureMembers(smo); ArrayStructureBB abb = new ArrayStructureBB(sm, as.getShape()); ArrayStructureBB.setOffsets(sm); StructureDataIterator iter = as.getStructureDataIterator(); try { while (iter.hasNext()) copyToArrayBB(iter.next(), abb); } finally { iter.finish(); } return abb; }
/** * Turn any ArrayStructure into a ArrayStructureMA * @param from copy from here. If from is a ArrayStructureMA, return it. * @return equivilent ArrayStructureMA * @throws java.io.IOException on error reading a sequence */ static public ArrayStructureMA factoryMA(ArrayStructure from) throws IOException { if (from instanceof ArrayStructureMA) return (ArrayStructureMA) from; StructureMembers tosm = new StructureMembers( new StructureMembers(from.getStructureMembers())); ArrayStructureMA to = new ArrayStructureMA(tosm, from.getShape()); for (StructureMembers.Member m : from.getMembers()) { to.setMemberArray(m.getName(), from.extractMemberArray(m)); } return to; }
/** * Turn any ArrayStructure into a ArrayStructureMA * @param from copy from here. If from is a ArrayStructureMA, return it. * @return equivilent ArrayStructureMA * @throws java.io.IOException on error reading a sequence */ static public ArrayStructureMA factoryMA(ArrayStructure from) throws IOException { if (from instanceof ArrayStructureMA) return (ArrayStructureMA) from; StructureMembers tosm = new StructureMembers( new StructureMembers(from.getStructureMembers())); ArrayStructureMA to = new ArrayStructureMA(tosm, from.getShape()); for (StructureMembers.Member m : from.getMembers()) { to.setMemberArray(m.getName(), from.extractMemberArray(m)); } return to; }
public void testReadStructureSubset() throws IOException, InvalidRangeException { Structure record = (Structure) ncfile.findVariable("record"); assert record != null; List<String> vars = new ArrayList<String>(); vars.add( "wind_speed"); vars.add( "wind_gust"); vars.add( "report"); Structure subset = record.select(vars); // read entire subset ArrayStructure dataAll = (ArrayStructure) subset.read(); StructureMembers sm = dataAll.getStructureMembers(); for(StructureMembers.Member m : sm.getMembers()) { Variable v = subset.findVariable(m.getName()); assert v != null; Array mdata = dataAll.extractMemberArray(m); assert mdata.getShape()[0] == dataAll.getShape()[0]; assert mdata.getElementType() == m.getDataType().getPrimitiveClassType(); System.out.println(m.getName()+ " shape="+new Section(mdata.getShape())); } System.out.println("*** TestStructureSubset ok"); }
public void testReadStructureSection() throws IOException, InvalidRangeException { Structure record = (Structure) ncfile.findVariable("record"); assert record != null; Structure subset = (Structure) record.section(new Section("0:10")); assert subset != null; assert subset.getRank() == 1; assert subset.getSize() == 11; // read entire subset ArrayStructure dataAll = (ArrayStructure) subset.read(new Section("0:10")); assert dataAll.getSize() == 11; StructureMembers sm =dataAll.getStructureMembers(); for(StructureMembers.Member m : sm.getMembers()) { Variable v = subset.findVariable(m.getName()); assert v != null; Array mdata = dataAll.extractMemberArray(m); assert mdata.getShape()[0] == dataAll.getShape()[0]; assert mdata.getElementType() == m.getDataType().getPrimitiveClassType(); System.out.println(m.getName()+ " shape="+new Section(mdata.getShape())); } System.out.println("*** TestStructureSubset ok"); }
int rrank = rank + mshape.length; int[] rshape = new int[rrank]; System.arraycopy(getShape(), 0, rshape, 0, rank); System.arraycopy(mshape, 0, rshape, rank, mshape.length);
int rrank = rank + mshape.length; int[] rshape = new int[rrank]; System.arraycopy(getShape(), 0, rshape, 0, rank); System.arraycopy(mshape, 0, rshape, rank, mshape.length);