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}); //System.out.println( NCdumpW.printArray(as, "", null)); 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
members, nelems, sdata
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.
|
protected StructureData |
makeStructureData(ArrayStructure as,
int index) |
void |
setMemberArray(java.lang.String memberName,
Array data)
Set the data array for this member.
|
convertScalarDouble, convertScalarFloat, convertScalarInt, convertScalarLong, copy, copyBytes, copyChars, copyDoubles, copyFloats, copyFrom1DJavaArray, copyInts, copyLongs, copyObjects, copySequences, copyShorts, copyStructures, copyTo1DJavaArray, createView, extractMemberArray, findMember, getArray, 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, 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, factory, factory, factoryConstant, flip, get1DJavaArray, getDataAsByteBuffer, getDataAsByteBuffer, getDataAsByteBuffer, getDataType, getIndex, getIndexIterator, getIndexIteratorFast, getIndexPrivate, getRangeIterator, getRank, getShape, getSize, hasNext, isConstant, isUnsigned, makeArray, makeArray, makeArray, makeArray, makeArrayRankPlusOne, next, nextBoolean, nextByte, nextChar, nextDouble, nextFloat, nextInt, nextLong, nextShort, permute, reduce, reduce, resetLocalIterator, reshape, reshapeNoCopy, section, section, section, sectionNoReduce, setUnsigned, shapeToString, slice, toString, transpose
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 java.io.IOException
from
- copy from here. If from is a ArrayStructureMA, return it.java.io.IOException
- on error reading a sequenceprotected StructureData makeStructureData(ArrayStructure as, int index)
makeStructureData
in class ArrayStructure
public void setMemberArray(java.lang.String memberName, Array data)
memberName
- name of memberdata
- Array for this member.public static ArrayStructureMA factoryMA(Structure from, int[] shape) throws java.io.IOException
from
- copy from here. If from is a ArrayStructureMA, return it.shape
- the shape of the ArrayStructurejava.io.IOException
- on error reading a sequence