/** * For rank 1 array of Structures, read count Structures and return the data as an ArrayStructure. * Use only when this is a one dimensional array of Structures. * @param start start at this index * @param count return this many StructureData * @return the StructureData recordsfrom start to start+count-1 * @throws java.io.IOException on read error * @throws ucar.ma2.InvalidRangeException if start, count out of range */ public ArrayStructure readStructure(int start, int count) throws IOException, ucar.ma2.InvalidRangeException { if (getRank() != 1) throw new java.lang.UnsupportedOperationException("not a vector structure"); int[] origin = new int[] {start}; int[] shape = new int[] {count}; if (NetcdfFile.debugStructureIterator) System.out.println("readStructure "+start+" "+count); return (ArrayStructure) read(origin, shape); }
/** * For rank 1 array of Structures, read count Structures and return the data as an ArrayStructure. * Use only when this is a one dimensional array of Structures. * @param start start at this index * @param count return this many StructureData * @return the StructureData recordsfrom start to start+count-1 * @throws java.io.IOException on read error * @throws ucar.ma2.InvalidRangeException if start, count out of range */ public ArrayStructure readStructure(int start, int count) throws IOException, ucar.ma2.InvalidRangeException { if (getRank() != 1) throw new java.lang.UnsupportedOperationException("not a vector structure"); int[] origin = new int[] {start}; int[] shape = new int[] {count}; if (NetcdfFile.debugStructureIterator) System.out.println("readStructure "+start+" "+count); return (ArrayStructure) read(origin, shape); }
/** * Use this when this is a scalar Structure. Its the same as read(), but it extracts the single * StructureData out of the Array. * @return StructureData for a scalar * @throws java.io.IOException on read error */ public StructureData readStructure() throws IOException { if (getRank() != 0) throw new java.lang.UnsupportedOperationException("not a scalar structure"); Array dataArray = read(); ArrayStructure data = (ArrayStructure) dataArray; return data.getStructureData(0); }
/** * Use this when this is a scalar Structure. Its the same as read(), but it extracts the single * StructureData out of the Array. * @return StructureData for a scalar * @throws java.io.IOException on read error */ public StructureData readStructure() throws IOException { if (getRank() != 0) throw new java.lang.UnsupportedOperationException("not a scalar structure"); Array dataArray = read(); ArrayStructure data = (ArrayStructure) dataArray; return data.getStructureData(0); }
/** * Use this when this is a scalar Structure. Its the same as read(), but it extracts the single * StructureData out of the Array. * @return StructureData for a scalar * @throws java.io.IOException on read error */ public StructureData readStructure() throws IOException { if (getRank() != 0) throw new java.lang.UnsupportedOperationException("not a scalar structure"); Array dataArray = read(); ArrayStructure data = (ArrayStructure) dataArray; return data.getStructureData(0); }
private void readNextGeneralRank() throws IOException { try { Section section = new Section(shape); section.setRange( 0, new Range(outerCount, outerCount)); as = (ArrayStructure) read( section); if (NetcdfFile.debugStructureIterator) System.out.println("readNext inner="+outerCount+" total="+outerCount); outerCount++; } catch (InvalidRangeException e) { log.error("Structure.Iterator.readNext() ",e); throw new IllegalStateException("Structure.Iterator.readNext() ",e); } // cant happen readStart += as.getSize(); readCount = 0; }
private void readNextGeneralRank() throws IOException { try { Section section = new Section(shape); section.setRange( 0, new Range(outerCount, outerCount)); as = (ArrayStructure) read( section); if (NetcdfFile.debugStructureIterator) System.out.println("readNext inner="+outerCount+" total="+outerCount); outerCount++; } catch (InvalidRangeException e) { log.error("Structure.Iterator.readNext() ",e); throw new IllegalStateException("Structure.Iterator.readNext() ",e); } // cant happen readStart += as.getSize(); readCount = 0; }
@Override public Array reallyRead(Variable client, CancelTask cancelTask) throws IOException { Array result; if (hasCachedData()) result = super.reallyRead(client, cancelTask); else if (orgVar != null) result = orgVar.read(); else { throw new IllegalStateException("StructureDS has no way to get data"); //Object data = smProxy.getFillValue(getDataType()); //return Array.factoryConstant(dataType.getPrimitiveClassType(), getShape(), data); } return convert(result, null); }
@Override public Array reallyRead(Variable client, CancelTask cancelTask) throws IOException { Array result; if (hasCachedData()) result = super.reallyRead(client, cancelTask); else if (orgVar != null) result = orgVar.read(); else { throw new IllegalStateException("StructureDS has no way to get data"); //Object data = smProxy.getFillValue(getDataType()); //return Array.factoryConstant(dataType.getPrimitiveClassType(), getShape(), data); } return convert(result, null); }
private void readNextGeneralRank() throws IOException { try { Section section = new Section(shape); section.setRange( 0, new Range(outerCount, outerCount)); as = (ArrayStructure) read( section); if (NetcdfFile.debugStructureIterator) System.out.println("readNext inner="+outerCount+" total="+outerCount); outerCount++; } catch (InvalidRangeException e) { log.error("Structure.Iterator.readNext() ",e); throw new IllegalStateException("Structure.Iterator.readNext() ",e); } // cant happen readStart += as.getSize(); readCount = 0; }
@Override public Array reallyRead(Variable client, CancelTask cancelTask) throws IOException { Array result; if (hasCachedData()) result = super.reallyRead(client, cancelTask); else if (orgVar != null) result = orgVar.read(); else { throw new IllegalStateException("StructureDS has no way to get data"); //Object data = smProxy.getFillValue(getDataType()); //return Array.factoryConstant(dataType.getPrimitiveClassType(), getShape(), data); } return convert(result, null); }
@Override public Array reallyRead(Variable client, Section section, CancelTask cancelTask) throws IOException, InvalidRangeException { if (section.computeSize() == getSize()) return _read(); Array result; if (hasCachedData()) result = super.reallyRead(client, section, cancelTask); else if (orgVar != null) result = orgVar.read(section); else { throw new IllegalStateException("StructureDS has no way to get data"); //Object data = smProxy.getFillValue(getDataType()); //return Array.factoryConstant(dataType.getPrimitiveClassType(), section.getShape(), data); } // do any needed conversions (scale/offset, enums, etc) return convert(result, section); }
@Override public Array reallyRead(Variable client, Section section, CancelTask cancelTask) throws IOException, InvalidRangeException { if (section.computeSize() == getSize()) return _read(); Array result; if (hasCachedData()) result = super.reallyRead(client, section, cancelTask); else if (orgVar != null) result = orgVar.read(section); else { throw new IllegalStateException("StructureDS has no way to get data"); //Object data = smProxy.getFillValue(getDataType()); //return Array.factoryConstant(dataType.getPrimitiveClassType(), section.getShape(), data); } // do any needed conversions (scale/offset, enums, etc) return convert(result, section); }
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 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; }
public void compare(Structure obs) throws IOException, InvalidRangeException { int start = 0; for (Message m : msgs) { Array data1; if (!m.isTablesComplete()) continue; if (!m.dds.isCompressed()) { MessageUncompressedDataReader reader = new MessageUncompressedDataReader(); data1 = reader.readEntireMessage(construct.recordStructure, protoMessage, m, raf, null); } else { MessageCompressedDataReader reader = new MessageCompressedDataReader(); data1 = reader.readEntireMessage(construct.recordStructure, protoMessage, m, raf, null); } int n = m.getNumberDatasets(); m.calcTotalBits(null); Array data2 = obs.read(new Section().appendRange(start, start + n - 1)); CompareNetcdf2 cn = new CompareNetcdf2( new Formatter(System.out), true, true, true); cn.compareData("all", data1, data2, true); start += n; } }
@Test public void testRead() throws IOException { DODSNetcdfFile dodsfile = TestDODSRead.open("test.04"); Variable v = null; Array a = null; // byte assert null != (v = dodsfile.findVariable("types")); assert v instanceof Structure; Structure s = (Structure) v; Array sdata = s.read(); checkSD( (StructureData) sdata.getObject( sdata.getIndex())); }
public void testW(String url, String sname, boolean isScalar) throws IOException, InvalidRangeException { NetcdfFile ncfile = NetcdfDataset.openFile(url, null); Structure v = (Structure) ncfile.findVariable(sname); assert v != null; assert( v.getDataType() == DataType.STRUCTURE); Array data = v.read(); assert( data instanceof ArrayStructure); assert(data.getElementType() == StructureData.class); new UtilsTestStructureArray().testArrayStructure( (ArrayStructure) data); ncfile.close(); }
public void testBB() throws IOException, InvalidRangeException { NetcdfFile ncfile = TestDir.openFileLocal("testWriteRecord.nc"); ncfile.sendIospMessage(NetcdfFile.IOSP_MESSAGE_ADD_RECORD_STRUCTURE); Structure v = (Structure) ncfile.findVariable("record"); assert v != null; assert( v.getDataType() == DataType.STRUCTURE); Array data = v.read(); assert( data instanceof ArrayStructure); assert( data instanceof ArrayStructureBB); assert(data.getElementType() == StructureData.class); test.testArrayStructure( (ArrayStructure) data); ncfile.close(); }
public void testMA() throws IOException, InvalidRangeException { NetcdfFile ncfile = TestDir.openFileLocal("jan.nc"); NetcdfDataset ncd = new NetcdfDataset( ncfile); Dimension dim = ncd.findDimension("time"); assert dim != null; Structure p = new ucar.nc2.dataset.StructurePseudoDS( ncd, null, "Psuedo", null, dim); assert( p.getDataType() == DataType.STRUCTURE); Array data = p.read(); assert( data instanceof ArrayStructure); assert( data instanceof ArrayStructureMA); assert(data.getElementType() == StructureData.class); test.testArrayStructure( (ArrayStructure) data); ncfile.close(); }