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

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

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

Array.factory介绍

[英]Generate new Array with given type and shape and zeroed storage.
[中]生成具有给定类型和形状以及零存储的新阵列。

代码示例

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

/**
 * Create an MAVector out of a double array
 */
public MAVector( double[] values) {
 this( Array.factory( values));
}

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

public boolean compareData(String name, double[] data1, double[] data2) {
 Array data1a = Array.factory(DataType.DOUBLE, new int[] {data1.length}, data1);
 Array data2a = Array.factory(DataType.DOUBLE, new int[] {data2.length}, data2);
 return compareData(name, data1a, data2a, TOL, false, false);
}

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

@Override
public Array getCoordsAsArray() {
 double[] values = getValues();
 return Array.factory(DataType.DOUBLE, shape, values);
}

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

/**
 * Generate new Array with given dataType, shape, storage.
 *
 * @param dataType DataType, eg DataType.DOUBLE.
 * @param shape    shape of the array.
 * @param storage  primitive array of correct type
 * @return new Array<type> or Array<type>.D<rank> if 0 <= rank <= 7.
 * @throws ClassCastException wrong storage type
 */
static public Array factory(DataType dataType, int[] shape, Object storage) {
 return factory(dataType, Index.factory(shape), storage);
}

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

private Array convertStringToChar(Array data, Variable ncVar) {
 String s = (String) data.getObject(Index.scalarIndexImmutable);
 int total = (int) ncVar.getSize();
 char[] storage = new char[total];
 int len = Math.min( s.length(), total);
 for (int k=0; k<len; k++)
  storage[k] = s.charAt(k);
 return Array.factory( DataType.CHAR, ncVar.getShape(), storage);
}

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

public MAMath.MinMax getMinMaxData( float[] data) {
  int[] shape = new int[1];
  shape[0] = data.length;
  Array a = Array.factory( DataType.FLOAT.getPrimitiveClassType(), shape, data);
  return MAMath.getMinMax( a);
}
int getGateDimsIndex(int cell, Dimension [] dList, int numSensor)

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

/**
 * Get the value as an Array.
 *
 * @return Array of values.
 */
public Array getValues() {
 if (values == null && svalue != null) {
  values = Array.factory(DataType.STRING, new int[]{1});
  values.setObject(values.getIndex(), svalue);
 }
 return values;
}

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

private Attribute readOpaqueAttValues(int grpid, int varid, String attname, int len, UserType userType) throws IOException {
 int total = len * userType.size;
 byte[] bb = new byte[total];
 int ret = nc4.nc_get_att(grpid, varid, attname, bb);
 if (ret != 0)
  throw new IOException(ret + ": " + nc4.nc_strerror(ret));
 return new Attribute(attname, Array.factory(DataType.BYTE, new int[]{total}, bb));
}

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

public ArrayDouble.D3 getCoordinateArray(int timeIndex)
  throws IOException, InvalidRangeException {
 Array data = readArray(existingData, timeIndex);
 // copy for now - better to just return Array, with promise its rank 3
 int[] shape = data.getShape();
 ArrayDouble.D3 ddata = (ArrayDouble.D3) Array.factory(double.class, shape);
 MAMath.copyDouble(ddata, data);
 return ddata;
}

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

/**
 * Create a copy of this Array, copying the data so that physical order is the same as
 * logical order
 *
 * @return the new Array
 */
public Array copy() {
 Array newA = factory(getDataType(), getShape());
 MAMath.copy(newA, this);
 return newA;
}

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

Cache(int[] shape, int[] newshape, DataType dataType)  {
 this.shape = shape;
 this.newshape = newshape;
 this.result = Array.factory(dataType, newshape);
 nt = shape[0];
 Section s = new Section(shape);
 chunksize = (int)(s.computeSize() / nt);
 // get view of result as a 2d array (any..., nt);
 int[] reshape = new int[] {chunksize, nt};
 this.work = this.result.reshapeNoCopy(reshape);
}

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

/**
 * Add extra outermost dimension with len = 1.
 *
 * @param org original array
 * @return rank1 array of rank + 1
 */
static public Array makeArrayRankPlusOne(Array org) {
 int[] shape = new int[org.getRank() + 1];
 System.arraycopy(org.getShape(), 0, shape, 1, org.getRank());
 shape[0] = 1;
 return factory(org.getDataType(), shape, org.getStorage());
}

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

/**
 * Create a copy of this Array, copying the data so that physical order is the same as
 * logical order
 *
 * @return the new Array
 */
public Array copy() {
 Array newA = factory(getElementType(), getShape());
 MAMath.copy(newA, this);
 newA.setUnsigned(isUnsigned());
 return newA;
}

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

@Override
public Array getCoordBoundsAsArray() {
 Array result = Array.factory(getDataType(), new int[]{ncoords, 2});
 int count = 0;
 for (int i = 0; i < ncoords; i++) {
  result.setDouble(count++, getCoordEdge1(i));
  result.setDouble(count++, getCoordEdge2(i));
 }
 return result;
}

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

public static Array convert2Unpacked(Array packed, ScaleOffset scaleOffset) {
 Array result = Array.factory(DataType.DOUBLE, packed.getShape());
 IndexIterator riter = result.getIndexIterator();
 while (packed.hasNext())  {
  riter.setDoubleNext( packed.nextDouble() * scaleOffset.scale + scaleOffset.offset);
 }
 return result;
}

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

static public StructureData make(String name, Object value) {
 StructureMembers members = new StructureMembers("");
 DataType dtype = DataType.getType(value.getClass());
 StructureMembers.Member m = members.addMember(name, null, null, dtype, new int[]{1});
 StructureDataW sw = new StructureDataW(members);
 Array dataArray = Array.factory(dtype, new int[]{1});
 dataArray.setObject(dataArray.getIndex(), value);
 sw.setMemberData(m, dataArray);
 return sw;
}

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

public static Array convert2packed(Array unpacked, double missingValue, int nbits, boolean isUnsigned, DataType packedType) {
 MAMath.ScaleOffset scaleOffset = calcScaleOffsetSkipMissingData(unpacked, missingValue, nbits, isUnsigned);
 Array result = Array.factory(packedType, unpacked.getShape());
 IndexIterator riter = result.getIndexIterator();
 while (unpacked.hasNext()) {
  double uv = unpacked.nextDouble();
  double pv = (uv - scaleOffset.offset) / scaleOffset.scale;
  riter.setDoubleNext( pv);
 }
 return result;
}

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

public Array readData(Variable v2, Section section) throws IOException, InvalidRangeException {
 Vgroup vgroup = (Vgroup) v2.getSPobject();    Range scanRange = section.getRange(0);
 Range radialRange = section.getRange(1);
 Range gateRange = section.getRange(2);
 Array data = Array.factory(v2.getDataType(), section.getShape());
 IndexIterator ii = data.getIndexIterator();
 for (int scanIdx : scanRange) {
  Level2Record[] mapScan = vgroup.map[scanIdx];
  readOneScan(mapScan, radialRange, gateRange, vgroup.datatype, ii);
 }
 return data;
}

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

public Array readData2(Variable v2, Section section, double[] values) {
 Array data = Array.factory(v2.getDataType().getPrimitiveClassType(), section.getShape());
 IndexIterator ii = data.getIndexIterator();
 Range radialRange = section.getRange(0);
 for (int r = radialRange.first(); r <= radialRange.last(); r += radialRange.stride()) {
  ii.setDoubleNext(values[r]);
 }
 return data;
}

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

public Array readData2(Variable v2, Section section, double[] values) {
 Array data = Array.factory(v2.getDataType().getPrimitiveClassType(), section.getShape());
 IndexIterator ii = data.getIndexIterator();
 Range radialRange = section.getRange(0);
 for (int r = radialRange.first(); r <= radialRange.last(); r += radialRange.stride()) {
  ii.setDoubleNext(values[r]);
 }
 return data;
}

相关文章

微信公众号

最新文章

更多