ucar.ma2.Array.nextInt()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(94)

本文整理了Java中ucar.ma2.Array.nextInt()方法的一些代码示例,展示了Array.nextInt()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Array.nextInt()方法的具体详情如下:
包路径:ucar.ma2.Array
类名称:Array
方法名:nextInt

Array.nextInt介绍

[英]Return the next int in the local iterator. Uses the local iterator, which is not thread-safe. Use getIndexIterator if you need thread-safety.
[中]返回本地迭代器中的下一个int。使用本地迭代器,这不是线程安全的。如果需要线程安全,请使用getIndexIterator。

代码示例

代码示例来源:origin: edu.ucar/cdm

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);
}

代码示例来源:origin: Unidata/thredds

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);
}

代码示例来源:origin: edu.ucar/netcdf

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);
}

代码示例来源:origin: edu.ucar/cdm

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);
  }
 }
}

代码示例来源:origin: Unidata/thredds

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);
  }
 }
}

代码示例来源:origin: Unidata/thredds

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;
}

代码示例来源:origin: edu.ucar/bufr

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;
}

代码示例来源:origin: edu.ucar/netcdf

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);
}

代码示例来源:origin: edu.ucar/cdm

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;
 }
}

代码示例来源:origin: edu.ucar/netcdf

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;
 }
}

代码示例来源:origin: Unidata/thredds

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;
}

代码示例来源:origin: edu.ucar/netcdf

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;
}

代码示例来源:origin: edu.ucar/cdm

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;
}

代码示例来源:origin: Unidata/thredds

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;
}

代码示例来源:origin: Unidata/thredds

assert data.nextInt() == count * 3;
count++;

代码示例来源:origin: Unidata/thredds

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();
}

代码示例来源:origin: Unidata/thredds

@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();
}

代码示例来源:origin: edu.ucar/netcdf

unsigned.resetLocalIterator();
while (unsigned.hasNext())
 ii.setLongNext( DataType.unsignedIntToLong(unsigned.nextInt()));
return result;

代码示例来源:origin: Unidata/thredds

assert data.nextInt() == count : data.nextInt() +"!="+ count;
count++;

代码示例来源:origin: Unidata/thredds

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++;
 }
}

相关文章

微信公众号

最新文章

更多