public class ArrayStructureMA extends ArrayStructure
ArrayStructureMA asma = new ArrayStructureMA(smembers, getShape()); for (int i = 0; i < orgVariables.size(); i++) { Variable v = (Variable) orgVariables.get(i); Array data = v.read(); asma.setMemberArray(v.getName(), data); }How to do Nested Structures:
Structure { float f1; short f2(3); Structure { int g1; double(2) g2; double(3,4) g3; Structure { int h1; double(2) h2; } nested2(7); } nested1(12); } s(4);
public void testMA() throws IOException, InvalidRangeException { StructureMembers members = new StructureMembers("s"); StructureMembers.Member m = members.addMember("f1", "desc", CDM.UNITS, DataType.FLOAT, new int[] {1}); Array data = Array.factory(DataType.FLOAT, new int[] {4}); m.setDataArray(data); fill(data); m = members.addMember("f2", "desc", CDM.UNITS, DataType.SHORT, new int[] {3}); data = Array.factory(DataType.SHORT, new int[] {4, 3}); m.setDataArray(data); fill(data); m = members.addMember("nested1", "desc", CDM.UNITS, DataType.STRUCTURE, new int[] {9}); data = makeNested1(m); m.setDataArray(data); ArrayStructureMA as = new ArrayStructureMA(members, new int[] {4}); new TestStructureArray().testArrayStructure(as); // get f2 out of the 3nd "s" StructureMembers.Member f2 = as.getStructureMembers().findMember("f2"); short[] f2data = as.getJavaArrayShort(2, f2); assert f2data[0] == 20; assert f2data[1] == 21; assert f2data[2] == 22; // get nested1 out of the 3nd "s" StructureMembers.Member nested1 = as.getStructureMembers().findMember("nested1"); ArrayStructure nested1Data = as.getArrayStructure(2, nested1); // get g1 out of the 7th "nested1" StructureMembers.Member g1 = nested1Data.getStructureMembers().findMember("g1"); int g1data = nested1Data.getScalarInt(6, g1); assert g1data == 26; // get nested2 out of the 7th "nested1" StructureMembers.Member nested2 = nested1Data.getStructureMembers().findMember("nested2"); ArrayStructure nested2Data = nested1Data.getArrayStructure(6, nested2); // get h1 out of the 4th "nested2" StructureMembers.Member h1 = nested2Data.getStructureMembers().findMember("h1"); int val = nested2Data.getScalarInt(4, h1); assert (val == 264); } public ArrayStructure makeNested1(StructureMembers.Member parent) throws IOException, InvalidRangeException { StructureMembers members = new StructureMembers(parent.getName()); parent.setStructureMembers(members); StructureMembers.Member m = members.addMember("g1", "desc", CDM.UNITS, DataType.INT, new int[] {1}); Array data = Array.factory(DataType.INT, new int[] {4, 9}); m.setDataArray(data); fill(data); m = members.addMember("g2", "desc", CDM.UNITS, DataType.DOUBLE, new int[] {2}); data = Array.factory(DataType.DOUBLE, new int[] {4, 9, 2}); m.setDataArray(data); fill(data); m = members.addMember("g3", "desc", CDM.UNITS, DataType.DOUBLE, new int[] {3, 4}); data = Array.factory(DataType.DOUBLE, new int[] {4, 9, 3, 4}); m.setDataArray(data); fill(data); m = members.addMember("nested2", "desc", CDM.UNITS, DataType.STRUCTURE, new int[] {7}); data = makeNested2(m); m.setDataArray(data); return new ArrayStructureMA(members, new int[] {4, 9}); } public ArrayStructure makeNested2(StructureMembers.Member parent) throws IOException, InvalidRangeException { StructureMembers members = new StructureMembers(parent.getName()); parent.setStructureMembers(members); StructureMembers.Member m = members.addMember("h1", "desc", CDM.UNITS, DataType.INT, new int[] {1}); Array data = Array.factory(DataType.INT, new int[] {4, 9, 7}); m.setDataArray(data); fill(data); m = members.addMember("h2", "desc", CDM.UNITS, DataType.DOUBLE, new int[] {2}); data = Array.factory(DataType.DOUBLE, new int[] {4, 9, 7, 2}); m.setDataArray(data); fill(data); return new ArrayStructureMA(members, new int[] {4, 9, 7}); }
Array
ArrayStructure.ArrayStructureIterator
Constructor and Description |
---|
ArrayStructureMA(StructureMembers members,
int[] shape)
Create a new Array of type StructureData and the given members and shape.
|
ArrayStructureMA(StructureMembers members,
int[] shape,
StructureData[] sdata) |
Modifier and Type | Method and Description |
---|---|
static ArrayStructureMA |
factoryMA(ArrayStructure from)
Turn any ArrayStructure into a ArrayStructureMA
|
static ArrayStructureMA |
factoryMA(Structure from,
int[] shape)
Create an ArrayStructure for a Structure.
|
Array |
getArray(int recno,
StructureMembers.Member m)
Get member data of any type for a specific record as an Array.
|
void |
setMemberArray(String memberName,
Array data)
Set the data array for this member.
|
convertScalarDouble, convertScalarFloat, convertScalarInt, convertScalarLong, copy, createView, extractMemberArray, findMember, getArrayObject, getArraySequence, getArrayStructure, getBoolean, getBoolean, getByte, getByte, getChar, getChar, getDouble, getDouble, getElementType, getFloat, getFloat, getInt, getInt, getJavaArrayByte, getJavaArrayChar, getJavaArrayDouble, getJavaArrayFloat, getJavaArrayInt, getJavaArrayLong, getJavaArrayShort, getJavaArrayString, getLong, getLong, getMembers, getObject, getObject, getScalarByte, getScalarChar, getScalarDouble, getScalarFloat, getScalarInt, getScalarLong, getScalarObject, getScalarShort, getScalarString, getScalarStructure, getShort, getShort, getSizeBytes, getStorage, getStructureData, getStructureData, getStructureDataIterator, getStructureMemberNames, getStructureMembers, getStructureSize, iterator, sectionNoReduce, setBoolean, setBoolean, setByte, setByte, setChar, setChar, setDouble, setDouble, setFloat, setFloat, setInt, setInt, setLong, setLong, setMemberArray, setObject, setObject, setShort, setShort, showInternal, showInternalMembers
arraycopy, copyTo1DJavaArray, copyToNDJavaArray, factory, factory, factory, factory, factoryConstant, flip, get1DJavaArray, getDataAsByteBuffer, getDataAsByteBuffer, getDataAsByteBuffer, getDataType, getIndex, getIndexIterator, getRangeIterator, getRank, getShape, getSize, hasNext, isConstant, isUnsigned, isVlen, makeArray, makeArray, makeArray, makeArrayRankPlusOne, makeFromJavaArray, makeFromJavaArray, makeObjectArray, makeVlenArray, next, nextBoolean, nextByte, nextChar, nextDouble, nextFloat, nextInt, nextLong, nextShort, permute, reduce, reduce, resetLocalIterator, reshape, reshapeNoCopy, section, section, section, sectionNoReduce, shapeToString, slice, toString, transpose
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public ArrayStructureMA(StructureMembers members, int[] shape)
You must set the data Arrays on each of the Members, using setDataObject(). These data Arrays contain the data for that member Variable, for all the StructureData. Therefore it has rank one greater that the Members. The extra dimension must be the outermost (slowest varying) dimension. ie, if some member has shape [3,10], the array would have shape [nrows, 3, 10].
members
- a description of the structure membersshape
- the shape of the Array.public ArrayStructureMA(StructureMembers members, int[] shape, StructureData[] sdata)
public static ArrayStructureMA factoryMA(ArrayStructure from) throws IOException
from
- copy from here. If from is a ArrayStructureMA, return it.IOException
- on error reading a sequencepublic static ArrayStructureMA factoryMA(Structure from, int[] shape)
from
- copy from here. If from is a ArrayStructureMA, return it.shape
- the shape of the ArrayStructurepublic Array getArray(int recno, StructureMembers.Member m)
ArrayStructure
getArray
in class ArrayStructure
recno
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member.