TableParentIndex(NetcdfDataset ds, TableConfig config) { super(ds, config); this.parentIndexName = config.parentIndex; // construct the map try { Variable rpIndex = ds.findVariable(config.parentIndex); Array index = rpIndex.read(); int childIndex = 0; this.indexMap = new HashMap<>((int) (2 * index.getSize())); while (index.hasNext()) { int parent = index.nextInt(); List<Integer> list = indexMap.get(parent); if (list == null) { list = new ArrayList<>(); indexMap.put(parent, list); } list.add(childIndex); childIndex++; } } catch (IOException e) { throw new RuntimeException(e); } addNonDataVariable(config.parentIndex); }
TableParentIndex(NetcdfDataset ds, TableConfig config) { super(ds, config); this.parentIndexName = config.parentIndex; // construct the map try { Variable rpIndex = ds.findVariable(config.parentIndex); Array index = rpIndex.read(); int childIndex = 0; this.indexMap = new HashMap<>((int) (2 * index.getSize())); while (index.hasNext()) { int parent = index.nextInt(); List<Integer> list = indexMap.get(parent); if (list == null) { list = new ArrayList<>(); indexMap.put(parent, list); } list.add(childIndex); childIndex++; } } catch (IOException e) { throw new RuntimeException(e); } addNonDataVariable(config.parentIndex); }
TableParentIndex(NetcdfDataset ds, TableConfig config) { super(ds, config); this.parentIndexName = config.parentIndex; // construct the map try { Variable rpIndex = ds.findVariable(config.parentIndex); Array index = rpIndex.read(); int childIndex = 0; this.indexMap = new HashMap<Integer, List<Integer>>((int) (2 * index.getSize())); while (index.hasNext()) { int parent = index.nextInt(); List<Integer> list = indexMap.get(parent); if (list == null) { list = new ArrayList<Integer>(); indexMap.put(parent, list); } list.add(childIndex); childIndex++; } } catch (IOException e) { throw new RuntimeException(e); } checkNonDataVariable(config.parentIndex); }
private void init() { if (startVarName == null) { // read numRecords when startVar is not known LOOK this should be deffered try { Variable v = ds.findVariable(numRecordsVarName); Array numRecords = v.read(); int n = (int) numRecords.getSize(); // construct the start variable this.numRecords = new int[n]; this.startIndex = new int[n]; int i = 0; int count = 0; while (numRecords.hasNext()) { this.startIndex[i] = count; this.numRecords[i] = numRecords.nextInt(); count += this.numRecords[i]; i++; } isInit = true; } catch (IOException e) { throw new RuntimeException(e); } } }
private void init() { if (startVarName == null) { // read numRecords when startVar is not known LOOK this should be deffered try { Variable v = ds.findVariable(numRecordsVarName); Array numRecords = v.read(); int n = (int) numRecords.getSize(); // construct the start variable this.numRecords = new int[n]; this.startIndex = new int[n]; int i = 0; int count = 0; while (numRecords.hasNext()) { this.startIndex[i] = count; this.numRecords[i] = numRecords.nextInt(); count += this.numRecords[i]; i++; } isInit = true; } catch (IOException e) { throw new RuntimeException(e); } } }
private boolean isMissingUnsigned(Variable v, Array mdata, int bitWidth) { long val; switch (v.getDataType()) { case ENUM1: case BYTE: val = DataType.unsignedByteToShort(mdata.nextByte()); break; case ENUM2: case SHORT: val = DataType.unsignedShortToInt(mdata.nextShort()); break; case ENUM4: case INT: val = DataType.unsignedIntToLong(mdata.nextInt()); break; default: throw new RuntimeException("illegal datatype " + v.getDataType()); } boolean result = BufrNumbers.isMissing(val, bitWidth); if (showData) out.format("%d %s,", val, result ? "(miss)" : ""); return result; }
private boolean isMissingUnsigned(Variable v, Array mdata, int bitWidth) { long val = 0; switch (v.getDataType()) { case ENUM1: case BYTE: val = DataType.unsignedByteToShort(mdata.nextByte()); break; case ENUM2: case SHORT: val = DataType.unsignedShortToInt(mdata.nextShort()); break; case ENUM4: case INT: val = DataType.unsignedIntToLong(mdata.nextInt()); break; default: throw new RuntimeException("illegal datatype "+v.getDataType()); } boolean result = BufrNumbers.isMissing(val, bitWidth); if (showData) out.format("%d %s,", val, result ? "(miss)" : ""); return result; }
TableContiguous(NetcdfDataset ds, TableConfig config) { super(ds, config); this.startVarName = config.start; this.numRecordsVarName = config.numRecords; if (startVarName == null) { // read numRecords when startVar is not known try { Variable v = ds.findVariable(config.numRecords); Array numRecords = v.read(); int n = (int) v.getSize(); // construct the start variable this.numRecords = new int[n]; this.startIndex = new int[n]; int i = 0; int count = 0; while (numRecords.hasNext()) { this.startIndex[i] = count; this.numRecords[i] = numRecords.nextInt(); count += this.numRecords[i]; i++; } } catch (IOException e) { throw new RuntimeException(e); } } checkNonDataVariable(config.start); checkNonDataVariable(config.numRecords); }
protected Array convertEnums(Array values) { DataType dt = DataType.getType(values.getElementType()); if (!dt.isNumeric()) System.out.println("HEY !dt.isNumeric()"); Array result = Array.factory(DataType.STRING, values.getShape()); IndexIterator ii = result.getIndexIterator(); values.resetLocalIterator(); while (values.hasNext()) { String sval = lookupEnumString(values.nextInt()); ii.setObjectNext(sval); } return result; } }
protected Array convertEnums(Array values) { DataType dt = DataType.getType(values.getElementType()); if (!dt.isNumeric()) System.out.println("HEY !dt.isNumeric()"); Array result = Array.factory(DataType.STRING, values.getShape()); IndexIterator ii = result.getIndexIterator(); values.resetLocalIterator(); while (values.hasNext()) { String sval = lookupEnumString(values.nextInt()); ii.setObjectNext(sval); } return result; } }
protected Array convertEnums(Map<Integer, String> map, DataType dataType, Array values) { Array result = Array.factory(DataType.STRING, values.getShape()); IndexIterator ii = result.getIndexIterator(); values.resetLocalIterator(); while (values.hasNext()) { int ival; if (dataType == DataType.ENUM1) ival = (int) DataType.unsignedByteToShort(values.nextByte()); else if (dataType == DataType.ENUM2) ival = DataType.unsignedShortToInt(values.nextShort()); else ival = values.nextInt(); String sval = map.get(ival); if (sval == null) sval = "Unknown enum value=" + ival; ii.setObjectNext(sval); } return result; }
protected Array convertEnums(Map<Integer, String> map, DataType dataType, Array values) { Array result = Array.factory(DataType.STRING, values.getShape()); IndexIterator ii = result.getIndexIterator(); values.resetLocalIterator(); while (values.hasNext()) { int ival; if (dataType == DataType.ENUM1) ival = (int) DataType.unsignedByteToShort(values.nextByte()); else if (dataType == DataType.ENUM2) ival = DataType.unsignedShortToInt(values.nextShort()); else ival = values.nextInt(); String sval = map.get(ival); if (sval == null) sval = "Unknown enum value="+ival; ii.setObjectNext(sval); } return result; }
protected Array convertEnums(Map<Integer, String> map, DataType dataType, Array values) { Array result = Array.factory(DataType.STRING, values.getShape()); IndexIterator ii = result.getIndexIterator(); values.resetLocalIterator(); while (values.hasNext()) { int ival; if (dataType == DataType.ENUM1) ival = (int) DataType.unsignedByteToShort(values.nextByte()); else if (dataType == DataType.ENUM2) ival = DataType.unsignedShortToInt(values.nextShort()); else ival = values.nextInt(); String sval = map.get(ival); if (sval == null) sval = "Unknown enum value=" + ival; ii.setObjectNext(sval); } return result; }
private Array convertEnums(Array values) { if (!values.getDataType().isIntegral()) { return values; // Nothing to do! } Array result = Array.factory(DataType.STRING, values.getShape()); IndexIterator ii = result.getIndexIterator(); values.resetLocalIterator(); while (values.hasNext()) { String sval = lookupEnumString(values.nextInt()); ii.setObjectNext(sval); } return result; }
assert data.nextInt() == count * 3; count++;
public void testNamExtract() throws IOException, InvalidRangeException { String location = TestDir.cdmUnitTestDir + "ncml/nc/namExtract/test_agg.ncml"; logger.debug(" TestOffAggExistingTimeUnitsChange.open {}", location); NetcdfFile ncfile = NetcdfDataset.openFile(location, null); Variable v = ncfile.findVariable("time"); assert v != null; assert v.getDataType() == DataType.DOUBLE; String units = v.getUnitsString(); assert units != null; assert units.equals("hours since 2006-09-25T06:00:00Z"); int count = 0; Array data = v.read(); logger.debug(NCdumpW.toString(data, "time", null)); while (data.hasNext()) { Assert2.assertNearlyEquals(data.nextInt(), (count + 1) * 3); count++; } ncfile.close(); }
@Test public void testAggExisting() throws IOException, InvalidRangeException { String endpoint = TestOnLocalServer.withHttpPath("dodsC/ExampleNcML/Agg.nc"); logger.debug("{}", endpoint); NetcdfFile ncfile = NetcdfDataset.openFile(endpoint, null); Variable v = ncfile.findVariable("time"); assert v != null; assert v.getDataType() == DataType.DOUBLE; String units = v.getUnitsString(); assert units != null; assert units.equals("hours since 2006-09-25T06:00:00Z"); int count = 0; Array data = v.read(); logger.debug(NCdumpW.toString(data, "time", null)); while (data.hasNext()) { Assert2.assertNearlyEquals(data.nextInt(), (count + 1) * 3); count++; } // test attributes added in NcML String testAtt = ncfile.findAttValueIgnoreCase(null, "ncmlAdded", null); assert testAtt != null; assert testAtt.equals("stuff"); v = ncfile.findVariable("lat"); assert v != null; testAtt = ncfile.findAttValueIgnoreCase(v, "ncmlAdded", null); assert testAtt != null; assert testAtt.equals("lat_stuff"); ncfile.close(); }
unsigned.resetLocalIterator(); while (unsigned.hasNext()) ii.setLongNext( DataType.unsignedIntToLong(unsigned.nextInt())); return result;
public void testAggCoordVarScan(NetcdfFile ncfile) throws IOException { Variable time = ncfile.findVariable("time"); assert null != time; assert time.getShortName().equals("time"); assert time.getRank() == 1 : time.getRank(); assert time.getShape()[0] == 3; assert time.getDataType() == DataType.INT : time.getDataType(); assert time.getDimension(0) == ncfile.findDimension("time"); int count = 0; Array data = time.read(); assert (data instanceof ArrayInt); while (data.hasNext()) { int val = data.nextInt(); assert val == count * 10 : val + "!="+ count * 10; count++; } }