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

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

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

Array.copyTo1DJavaArray介绍

[英]Copy this array to a 1D Java primitive array of type getElementType(), with the physical order of the result the same as logical order.
[中]将此数组复制到getElementType()类型的1D Java基元数组中,结果的物理顺序与逻辑顺序相同。

代码示例

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

static private void reflectArrayCopyOut(Object jArray, Array aa, IndexIterator aaIter) {
 Class cType = jArray.getClass().getComponentType();
 //if (cType.isPrimitive()) { // Rob Weingruber <weingrub@rap.ucar.edu> May 11, 2011
 if (!cType.isArray()) {
  aa.copyTo1DJavaArray(aaIter, jArray);  // subclass does type-specific copy
 } else {
  for (int i = 0; i < java.lang.reflect.Array.getLength(jArray); i++)  // recurse
   reflectArrayCopyOut(java.lang.reflect.Array.get(jArray, i), aa, aaIter);
 }
}

代码示例来源:origin: openmicroscopy/bioformats

private String arrayToString(Array values) {
 Object v = values.copyTo1DJavaArray();
 if (v instanceof Object[]) {
  Object[] array = (Object[]) v;
  final StringBuilder sb = new StringBuilder();
  for (int i = 0; i < array.length; i++) {
   sb.append((String) array[i]);
  }
  return sb.toString().trim();
 }
 return values.toString().trim();
}

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

static private void reflectArrayCopyOut(Object jArray, Array aa, IndexIterator aaIter) {
 Class cType = jArray.getClass().getComponentType();
 //if (cType.isPrimitive()) { // Rob Weingruber <weingrub@rap.ucar.edu> May 11, 2011
 if (!cType.isArray()) {
  aa.copyTo1DJavaArray(aaIter, jArray);  // subclass does type-specific copy
 } else {
  for (int i = 0; i < java.lang.reflect.Array.getLength(jArray); i++)  // recurse
   reflectArrayCopyOut(java.lang.reflect.Array.get(jArray, i), aa, aaIter);
 }
}

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

static private void reflectArrayCopyOut(Object jArray, Array aa, IndexIterator aaIter) {
 Class cType = jArray.getClass().getComponentType();
 //if (cType.isPrimitive()) { // Rob Weingruber <weingrub@rap.ucar.edu> May 11, 2011
 if (!cType.isArray()) {
  aa.copyTo1DJavaArray(aaIter, jArray);  // subclass does type-specific copy
 } else {
  for (int i = 0; i < java.lang.reflect.Array.getLength(jArray); i++)  // recurse
   reflectArrayCopyOut(java.lang.reflect.Array.get(jArray, i), aa, aaIter);
 }
}

代码示例来源:origin: ome/formats-gpl

private String arrayToString(Array values) {
 Object v = values.copyTo1DJavaArray();
 if (v instanceof Object[]) {
  Object[] array = (Object[]) v;
  final StringBuilder sb = new StringBuilder();
  for (int i = 0; i < array.length; i++) {
   sb.append((String) array[i]);
  }
  return sb.toString().trim();
 }
 return values.toString().trim();
}

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

public Array concatArray(Array array1, Array array2) {
 float[] data1 = (float[]) array1.copyTo1DJavaArray();
 float[] data2 = (float[]) array2.copyTo1DJavaArray();
 float[] result = new float[data1.length + data2.length];
 System.arraycopy(data1, 0, result, 0, data1.length);
 System.arraycopy(data2, 0, result, data1.length, data2.length);
 // now put it back into an ucar.ma2.Array
 int[] resultShape = new int[] {result.length};
 return Array.factory(DataType.FLOAT, resultShape, result);
}

代码示例来源:origin: bcdev/beam

public ProductData readDataFlip(Variable variable) throws ProductIOException {
  final int dataType = getProductDataType(variable);
  Array array;
  Object storage;
  try {
    array = variable.read();
    storage = array.flip(0).copyTo1DJavaArray();
  } catch (IOException e) {
    throw new ProductIOException(e.getMessage(), e);
  }
  return ProductData.createInstance(dataType, storage);
}

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

try {
  Array tArray = t.read();
  time = (double[]) tArray.copyTo1DJavaArray();
  Array eArray = ele.read();
  elevation = (float[]) eArray.copyTo1DJavaArray();
  Array aArray = azi.read();
  azimuth = (float[]) aArray.copyTo1DJavaArray();
  Array rArray = rng.read();
  range       = (float[]) rArray.copyTo1DJavaArray();
  rayStartIdx = (int[]) sidx0.read().copyTo1DJavaArray();
  rayEndIdx   = (int[]) sidx1.read().copyTo1DJavaArray();
  Array sn = snumber.read();
  nsweeps = ((int[]) sn.copyTo1DJavaArray()).length;

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

Variable t = ds.findVariable("time");
Array tArray = t.read();
time = (double[]) tArray.copyTo1DJavaArray();
elevation = (float[]) eArray.copyTo1DJavaArray();
azimuth = (float[]) aArray.copyTo1DJavaArray();
range = (float[]) rArray.copyTo1DJavaArray();
rayStartIdx = (int[]) sidx0.read().copyTo1DJavaArray();
rayEndIdx = (int[]) sidx1.read().copyTo1DJavaArray();
  ray_n_gates = (int[]) var.read().copyTo1DJavaArray();
  ray_start_index = (int[]) var.read().copyTo1DJavaArray();

代码示例来源:origin: bcdev/beam

/**
 * Creates a ProductData instance for the given netcdf attribute.
 *
 * @param attribute A netcdf attribute.
 *
 * @return A new ProductData instance with the attribute's data type and value.
 */
public static ProductData createProductData(Attribute attribute) {
  ProductData attributeValue;
  int productDataType = DataTypeUtils.getEquivalentProductDataType(attribute.getDataType(), false, false);
  if (productDataType == ProductData.TYPE_ASCII) {
    attributeValue = ProductData.createInstance(attribute.getStringValue());
  } else {
    attributeValue = ProductData.createInstance(productDataType, attribute.getValues().copyTo1DJavaArray());
  }
  return attributeValue;
}

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

/**
 * This gets the equivalent java array of the wanted type, in correct order.
 * It avoids copying if possible.
 *
 * @param wantType returned object will be an array of this type. This must be convertible to it.
 * @return java array of type want
 */
public Object get1DJavaArray(DataType wantType) {
 if (wantType == getDataType()) {
  if (indexCalc.isFastIterator())
   return getStorage(); // already in order
  else return copyTo1DJavaArray(); // gotta copy
 }
 // gotta convert to new type
 Array newA = factory(wantType, getShape());
 MAMath.copy(newA, this);
 return newA.getStorage();
}

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

/**
 * This gets the equivalent java array of the wanted type, in correct order.
 * It avoids copying if possible.
 *
 * @param wantType returned object will be an array of this type. This must be convertible to it.
 * @return java array of type want
 */
public Object get1DJavaArray(Class wantType) {
 if (wantType == getElementType()) {
  if (indexCalc.isFastIterator())
    return getStorage(); // already in order
  else return copyTo1DJavaArray(); // gotta copy
 }
 // gotta convert to new type
 Array newA = factory(wantType, getShape());
 MAMath.copy(newA, this);
 return newA.getStorage();
}

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

/**
 * This gets the equivalent java array of the wanted type, in correct order.
 * It avoids copying if possible.
 *
 * @param wantType returned object will be an array of this type. This must be convertible to it.
 * @return java array of type want
 */
public Object get1DJavaArray(Class wantType) {
 if (wantType == getElementType()) {
  if (indexCalc.isFastIterator()) return getStorage(); // already in order
  else return copyTo1DJavaArray(); // gotta copy
 }
 // gotta convert to new type
 Array newA = factory(wantType, getShape());
 MAMath.copy(newA, this);
 return newA.getStorage();
}

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

@Test
public void testReadMrutpTimeRangeWithSingleVerticalLevel() throws IOException, InvalidRangeException {
 // read more than one time coordinate at a time in a MRUTP, with vertical
 try (NetcdfDataset ds = NetcdfDataset.openDataset(TestDir.cdmUnitTestDir + "gribCollections/tp/GFSonedega.ncx4")) {
  Variable v = ds.findVariable(null, "Relative_humidity_sigma");
  assert v != null;
  Array data = v.read("0:1, 0, 50, 50");
  assert data != null;
  assert data.getRank() == 4;
  assert data.getDataType() == DataType.FLOAT;
  assert data.getSize() == 2;
  logger.debug("{}", NCdumpW.toString(data));
  while (data.hasNext()) {
   float val = data.nextFloat();
   assert !Float.isNaN(val);
  }
  float[] got = (float []) data.copyTo1DJavaArray();
  float[] expect = new float[] {68.0f, 74.0f};
  Assert.assertArrayEquals(expect, got, (float) Misc.defaultMaxRelativeDiffFloat);
 }
}

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

@Test
public void testReadMrutpTimeRangeWithMultipleVerticalLevel() throws IOException, InvalidRangeException {
 // read more than one time coordinate at a time in a MRUTP. multiple verticals
 try (NetcdfDataset ds = NetcdfDataset.openDataset(TestDir.cdmUnitTestDir + "gribCollections/tp/GFSonedega.ncx4")) {
  Variable v = ds.findVariable(null, "Relative_humidity_isobaric");
  assert v != null;
  Array data = v.read("0:1, 10:20:2, 50, 50");
  assert data != null;
  assert data.getRank() == 4;
  assert data.getDataType() == DataType.FLOAT;
  assert data.getSize() == 12;
  logger.debug("{}", NCdumpW.toString(data));
  while (data.hasNext()) {
   float val = data.nextFloat();
   assert !Float.isNaN(val);
  }
  float[] got = (float []) data.copyTo1DJavaArray();
  float[] expect = new float[] {57.8f, 53.1f, 91.3f, 85.5f, 80.0f, 69.3f, 32.8f, 41.8f, 88.9f, 81.3f, 70.9f, 70.6f};
  Assert.assertArrayEquals(expect, got, (float) Misc.defaultMaxRelativeDiffFloat);
 }
}

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

@Test
public void testReadMrutpTimeRange() throws IOException, InvalidRangeException {
 // read more than one time coordinate at a time in a MRUTP, no vertical
 try (NetcdfDataset ds = NetcdfDataset.openDataset(TestDir.cdmUnitTestDir + "gribCollections/tp/GFSonedega.ncx4")) {
  Variable v = ds.findVariable(null, "Pressure_surface");
  assert v != null;
  Array data = v.read("0:1,50,50");
  assert data != null;
  assert data.getRank() == 3;
  assert data.getDataType() == DataType.FLOAT;
  assert data.getSize() == 2;
  float[] got = (float []) data.copyTo1DJavaArray();
  float[] expect = new float[] {103031.914f, 103064.164f};
  Assert.assertArrayEquals(expect, got, (float) Misc.defaultMaxRelativeDiffFloat);
 }
}

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

assert (shape[1] == Asection2.getShape()[1]);
Assert2.assertArrayNearlyEquals((double[]) Asection.copyTo1DJavaArray(),
    (double[]) Asection2.copyTo1DJavaArray());

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

@Test
public void checkPaddingOnWriteReadOneDimByteArrayOnlyRecordVar()
    throws IOException, InvalidRangeException {
 File tmpDataDir = tempFolder.newFolder();
 File testFile = new File(tmpDataDir, "file.nc");
 try( NetcdfFileWriter ncfWriteable = NetcdfFileWriter.createNew(testFile.getPath(), true)) {
  Dimension recDim = ncfWriteable.addUnlimitedDimension("v");
  Variable var = ncfWriteable.addVariable("v", DataType.BYTE, "v");
  assertEquals(1, var.getElementSize());
  ncfWriteable.create();
  N3header.Vinfo vinfo = (N3header.Vinfo) var.getSPobject();
  assertTrue(vinfo.isRecord);
  assertEquals(1, vinfo.vsize);
  byte[] data = {1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -2, -3, -4, -5, -6, -7, -8, -9};
  Array dataArray = Array.factory(DataType.BYTE, new int[]{data.length}, data);
  ncfWriteable.write(var.getFullNameEscaped(), dataArray);
  ncfWriteable.close();
  NetcdfFile ncf = NetcdfFile.open(testFile.getPath());
  Variable readVar = ncf.findVariable("v");
  assertEquals(readVar.getDataType(), DataType.BYTE);
  assertEquals(1, readVar.getElementSize());
  vinfo = (N3header.Vinfo) readVar.getSPobject();
  assertTrue(vinfo.isRecord);
  assertEquals(1, vinfo.vsize);
  int[] org = {0};
  byte[] readdata = (byte[]) readVar.read(org, readVar.getShape()).copyTo1DJavaArray();
  assertArrayEquals(data, readdata);
 }
}

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

@Test
public void checkPaddingOnWriteReadOneDimCharArrayOnlyRecordVar()
    throws IOException, InvalidRangeException {
 File tmpDataDir = tempFolder.newFolder();
 File testFile = new File(tmpDataDir, "file.nc");
 try(NetcdfFileWriter ncfWriteable = NetcdfFileWriter.createNew(testFile.getPath(), true)) {
  Dimension recDim = ncfWriteable.addUnlimitedDimension("v");
  Variable var = ncfWriteable.addVariable("v", DataType.CHAR, "v");
  assertEquals(1, var.getElementSize());
  ncfWriteable.create();
  N3header.Vinfo vinfo = (N3header.Vinfo) var.getSPobject();
  assertTrue(vinfo.isRecord);
  assertEquals(1, vinfo.vsize);
  char[] data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50};
  Array dataArray = Array.factory(DataType.CHAR, new int[]{data.length}, data);
  ncfWriteable.write(var.getFullNameEscaped(), dataArray);
  ncfWriteable.close();
  NetcdfFile ncf = NetcdfFile.open(testFile.getPath());
  Variable readVar = ncf.findVariable("v");
  assertEquals(readVar.getDataType(), DataType.CHAR);
  assertEquals(1, readVar.getElementSize());
  vinfo = (N3header.Vinfo) readVar.getSPobject();
  assertTrue(vinfo.isRecord);
  assertEquals(1, vinfo.vsize);
  int[] org = {0};
  char[] readdata = (char[]) readVar.read(org, readVar.getShape()).copyTo1DJavaArray();
  assertArrayEquals(data, readdata);
 }
}

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

byte[] readdata = (byte[]) inv.read(org, inv.getShape()).copyTo1DJavaArray();

相关文章

微信公众号

最新文章

更多