use of com.beanit.openiec61850.Array in project risky by amsa-code.
the class NetCdfWriterTest method test.
@Test
public void test() throws IOException, InvalidRangeException {
File file = new File("target/temp.nc");
file.delete();
NetCdfWriter n = new NetCdfWriter(file, "0.1");
Var<Long> v = n.addVariable("time", Long.class).longName("time in epoch milliseconds").units("epoch milliseconds").numRecords(2).build();
v.add(100L);
v.add(200L);
n.close();
// now read the file just written and assert
NetcdfFile nc = NetcdfFile.open(file.getCanonicalPath());
List<Attribute> attributes = nc.findGroup(null).getAttributes();
System.out.println(attributes);
assertFalse(attributes.isEmpty());
System.out.println(nc.getDimensions());
{
Array array = nc.readSection("time");
assertEquals(100, array.getLong(0));
assertEquals(200, array.getLong(1));
assertEquals(2, array.getSize());
}
}
use of com.beanit.openiec61850.Array in project Protocol-Adapter-IEC61850 by OSGP.
the class NodeContainer method writeFloatArray.
public void writeFloatArray(final SubDataAttribute child, final Float[] values) throws NodeWriteException {
final Array array = (Array) this.parent.getChild(child.getDescription());
if (array.size() != values.length) {
throw new NodeWriteException(String.format("Invalid array size %d. Size on device is %d", values.length, array.size()));
}
for (int i = 0; i < values.length; i++) {
final BdaFloat32 bdaFloat = (BdaFloat32) array.getChild(i);
bdaFloat.setFloat(values[i]);
this.writeNode(bdaFloat);
}
// Unfortunately writing an array using "this.writeNode(array);"
// doesn't seem to work...
// Therefore the items are written in individual calls...
}
use of com.beanit.openiec61850.Array in project Protocol-Adapter-IEC61850 by OSGP.
the class NodeContainer method writeDateArray.
public void writeDateArray(final SubDataAttribute child, final Date[] values) throws NodeWriteException {
final Array array = (Array) this.parent.getChild(child.getDescription());
if (array.size() != values.length) {
throw new NodeWriteException(String.format("Invalid array size %d. Size on device is %d", values.length, array.size()));
}
for (int i = 0; i < values.length; i++) {
final BdaTimestamp bdaTimestamp = (BdaTimestamp) array.getChild(i);
bdaTimestamp.setDate(values[i]);
this.writeNode(bdaTimestamp);
}
// Unfortunately writing an array using "this.writeNode(array);"
// doesn't seem to work...
// Therefore the items are written in individual calls...
}
use of com.beanit.openiec61850.Array in project sis by apache.
the class VariableWrapper method read.
/**
* Reads a sub-sampled sub-area of the variable.
*
* @param areaLower index of the first value to read along each dimension.
* @param areaUpper index after the last value to read along each dimension.
* @param subsampling sub-sampling along each dimension. 1 means no sub-sampling.
* @return the data as an array of a Java primitive type.
*/
@Override
public Vector read(final int[] areaLower, final int[] areaUpper, final int[] subsampling) throws IOException, DataStoreException {
final int[] size = new int[areaUpper.length];
for (int i = 0; i < size.length; i++) {
size[i] = areaUpper[i] - areaLower[i];
}
final Array array;
try {
array = variable.read(new Section(areaLower, size, subsampling));
} catch (InvalidRangeException e) {
throw new DataStoreContentException(e);
}
return Vector.create(array.get1DJavaArray(array.getElementType()), variable.isUnsigned());
}
use of com.beanit.openiec61850.Array in project sis by apache.
the class VariableWrapper method readArray.
/**
* Reads the data from this variable and returns them as an array of a Java primitive type.
* Multi-dimensional variables are flattened as a one-dimensional array (wrapped in a vector).
* This method may replace fill/missing values by NaN values and caches the returned vector.
*
* @param area indices of cell values to read along each dimension, in "natural" order.
* @param subsampling subsampling along each dimension, or {@code null} if none.
* @return the data as an array of a Java primitive type.
*
* @see #read()
* @see #read(GridExtent, int[])
*/
private Object readArray(final GridExtent area, final int[] subsampling) throws IOException, DataStoreException {
int n = area.getDimension();
final int[] lower = new int[n];
final int[] size = new int[n];
final int[] sub = (subsampling != null) ? new int[n] : null;
n--;
for (int i = 0; i <= n; i++) {
final int j = (n - i);
lower[j] = Math.toIntExact(area.getLow(i));
size[j] = Math.toIntExact(area.getSize(i));
if (sub != null) {
sub[j] = subsampling[i];
}
}
final Array array;
try {
array = variable.read(sub != null ? new Section(lower, size, sub) : new Section(lower, size));
} catch (InvalidRangeException e) {
throw new DataStoreException(e);
}
return get1DJavaArray(array);
}
Aggregations