org.javaseis.array
Class MultiArray

java.lang.Object
  extended by org.javaseis.array.MultiArray
All Implemented Interfaces:
IMultiArray
Direct Known Subclasses:
DistributedArray

public class MultiArray
extends java.lang.Object
implements IMultiArray

Author:
moshecc

Field Summary
protected  int _arrayLength
           
protected  int _bufLength
           
protected  java.lang.Class _classType
           
protected  int _elementCount
           
protected  int _frameLength
           
protected  int _hypercubeLength
           
protected  int[] _lengths
           
protected  int _maxIndex
           
protected  int _ndim
           
protected  int _offset
           
protected  int[] _offsetMultiplier
           
protected  int _traceLength
           
protected  int _volumeLength
           
protected  byte[] bytes
           
protected  double[] doubles
           
protected  float[] floats
           
protected  int[] ints
           
protected  long[] longs
           
protected  java.lang.Object[] objects
           
protected  short[] shorts
           
 
Constructor Summary
MultiArray()
          Default constructor
MultiArray(int ndim, java.lang.Class classType, int[] lengths)
          Constructor to create a new SeismicArray without storage.
 
Method Summary
 void allocate()
          Convenience method to allocate primitive storage once all other fields are set
 byte[] bytes()
           
 IMultiArray clone()
           
 void deallocate()
          Convenience method to de-reference the underlying storage
 double[] doubles()
           
static MultiArray factory(int ndim, java.lang.Class classType, int elementCount, int[] lengths)
          Factory method to create a new SeismicArray with allocated storage
static
<T> MultiArray
factory(int ndim, T[] obuf, int count, int[] lengths)
          Factory method to create a new SeismicArray from an array of objects
static MultiArray float2D(int n1, int n2)
          Factory method to create a new 2D float array
static MultiArray float3D(int n1, int n2, int n3)
          Factory method to create a new 3D float array
 float[] floats()
           
 int getDimensions()
          Return the number of dimensions in this MultiArray
 int getElementCount()
           
 void getFrame(byte[][] buf, int[] position)
           
 void getFrame(double[][] buf, int[] position)
           
 void getFrame(float[][] buf, int[] position)
           
 void getFrame(int[][] buf, int[] position)
           
 void getFrame(long[][] buf, int[] position)
           
 void getFrame(short[][] buf, int[] position)
           
<T> void
getFrame(T[][] buf, int[] position)
          Place a 2-dimensional array of values into the multiarray
 int getLength(int index)
          Return the length of a particular dimension
 int getOffset()
          Return the zero-based offset within the underlying storage for this array
 int[] getShape()
          Return the length of each dimension in this MultiArray
 void getTrace(byte[] buf, int[] position)
           
 void getTrace(double[] buf, int[] position)
           
 void getTrace(float[] buf, int[] position)
           
 void getTrace(int[] buf, int[] position)
           
 void getTrace(long[] buf, int[] position)
           
 void getTrace(short[] buf, int[] position)
           
<T> void
getTrace(T[] buf, int[] position)
          Return a 1-dimensional array of values from the multiarray
 int index(int[] position)
          Return the index in the underlying storage of the data at a particular position in the MultiArray
 int index(int[] position, int element)
          Return the index in the underlying storage of an element at a particular position in the MultiArray.
 int indexFortran(int[] position)
          Return the index in the underlying storage of the data at a particular position in the MultiArray.
 int indexFortran(int[] position, int element)
          Return the index in the underlying storage of an element at a particular position in the MultiArray.
 int[] ints()
           
 long[] longs()
           
static void main(java.lang.String[] args)
           
<T> T[]
objects()
          Return the underlying storage for this MultiArray as a 1D array
 void putFrame(byte[][] buf, int[] position)
           
 void putFrame(double[][] buf, int[] position)
           
 void putFrame(float[][] buf, int[] position)
           
 void putFrame(int[][] buf, int[] position)
           
 void putFrame(long[][] buf, int[] position)
           
 void putFrame(short[][] buf, int[] position)
           
<T> void
putFrame(T[][] buf, int[] position)
          Place a 2-dimensional array of values into the multiarray
 void putTrace(byte[] buf, int[] position)
           
 void putTrace(double[] buf, int[] position)
           
 void putTrace(float[] buf, int[] position)
           
 void putTrace(int[] buf, int[] position)
           
 void putTrace(long[] buf, int[] position)
           
 void putTrace(short[] buf, int[] position)
           
<T> void
putTrace(T[] buf, int[] position)
          Place a 1-dimensional array of values into the multiarray
 int[] range(int[] position, int dimension)
          Return a zero-based index triplet defining start,end,increment that will traverse a specified dimension for this MultiArray.
 int[] range(int[] position, int dimension, int start, int end, int increment)
          Return a zero-based index triplet defining start,end,increment that can be used to access the elements of the underlying 1D array storage for this MultiArray.
 int[] range(int[] position, int dimension, int start, int end, int increment, int element)
          Return a zero-based index triplet defining start,end,increment that can be used to access individual elements of the underlying 1D array storage for this MultiArray.
 int[] rangeFortran(int[] position, int dimension)
          Return a zero-based index triplet defining start,end,increment that will traverse a specified dimension for this MultiArray.
 int[] rangeFortran(int[] position, int dimension, int start, int end, int increment)
          Return a Fortran index triplet defining start,end,increment that can be used to access the elements of the underlying 1D array storage for this MultiArray.
 int[] rangeFortran(int[] position, int dimension, int start, int end, int increment, int element)
          Return a Fortran style index triplet defining start,end,increment that can be used to access individual elements of the underlying 1D array storage for this MultiArray.
 void setArray(byte[] buf)
           
 void setArray(double[] buf)
           
 void setArray(float[] buf)
           
 void setArray(int[] buf)
           
 void setArray(long[] buf)
           
 void setArray(short[] buf)
           
<T> void
setArray(T[] buf)
          Provide the array that is used for underlying storage The "object" version is a generic method that handles arbitrary objects The rest of the methods are for primitive types
 void setClassType(java.lang.Class classType)
          Set the class type of this MultiArray
 void setDimensions(int ndim)
          Set the number of dimensions for this MultiArray
 void setElementCount(int elementCount)
          Set the element count for this MultiArray
 void setOffset(int offset)
          Set the zero-based offset within the underlying storage for this array
 void setShape(int[] lengths)
          Set the shape of this MultiArray, in Fortran style with the "fast" dimension first
 short[] shorts()
           
 void tran1243()
          Transpose the third and fourth dimensions of this MultiArray
 void tran132()
          Transpose the second and third dimensions of an MultiArray
 void tran21()
          Transpose the first two dimensions of a MultiArray If the number of elements per sample is not 1, the transpose is "promoted" to tran132 using the element count as the first dimension.
 void transpose(TransposeType type)
          Apply the requested transpose to this MultiArray
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_arrayLength

protected int _arrayLength

_bufLength

protected int _bufLength

_classType

protected java.lang.Class _classType

_elementCount

protected int _elementCount

_frameLength

protected int _frameLength

_hypercubeLength

protected int _hypercubeLength

_lengths

protected int[] _lengths

_maxIndex

protected int _maxIndex

_ndim

protected int _ndim

_offset

protected int _offset

_offsetMultiplier

protected int[] _offsetMultiplier

_traceLength

protected int _traceLength

_volumeLength

protected int _volumeLength

bytes

protected byte[] bytes

doubles

protected double[] doubles

floats

protected float[] floats

ints

protected int[] ints

longs

protected long[] longs

objects

protected java.lang.Object[] objects

shorts

protected short[] shorts
Constructor Detail

MultiArray

public MultiArray()
Default constructor


MultiArray

public MultiArray(int ndim,
                  java.lang.Class classType,
                  int[] lengths)
Constructor to create a new SeismicArray without storage. The setArray or allocate methods must be called before using.

Parameters:
ndim - number of dimensions
dataType - dat type for the storage
lengths - length of each axis
Method Detail

allocate

public void allocate()
Convenience method to allocate primitive storage once all other fields are set


bytes

public byte[] bytes()
Specified by:
bytes in interface IMultiArray
Returns:
byte array for this MultiArray, null if undefined

clone

public IMultiArray clone()
Specified by:
clone in interface IMultiArray
Overrides:
clone in class java.lang.Object

deallocate

public void deallocate()
Convenience method to de-reference the underlying storage


doubles

public double[] doubles()
Specified by:
doubles in interface IMultiArray
Returns:
double array for this MultiArray, null if undefined

factory

public static MultiArray factory(int ndim,
                                 java.lang.Class classType,
                                 int elementCount,
                                 int[] lengths)
Factory method to create a new SeismicArray with allocated storage

Parameters:
ndim - number of dimensions
dataType - dat type for the storage
lengths - length of each axis
Returns:
a SeismicArray ready for use

factory

public static <T> MultiArray factory(int ndim,
                                     T[] obuf,
                                     int count,
                                     int[] lengths)
Factory method to create a new SeismicArray from an array of objects

Parameters:
ndim - number of dimensions
obuf - 1D java array of objects
count - element count for each sample
lengths - length of each axis
Returns:
a SeismicArray ready for use

float2D

public static MultiArray float2D(int n1,
                                 int n2)
Factory method to create a new 2D float array

Parameters:
n1 - length of first dimension
n2 - length of second dimension
Returns:
a SeismicArray ready for use

float3D

public static MultiArray float3D(int n1,
                                 int n2,
                                 int n3)
Factory method to create a new 3D float array

Parameters:
n1 - length of first dimension
n2 - length of second dimension
n3 - length of third dimension
Returns:
a SeismicArray ready for use

floats

public float[] floats()
Specified by:
floats in interface IMultiArray
Returns:
float array for this MultiArray, null if undefined

getDimensions

public int getDimensions()
Description copied from interface: IMultiArray
Return the number of dimensions in this MultiArray

Specified by:
getDimensions in interface IMultiArray
Returns:
number of dimensions

getElementCount

public int getElementCount()

getFrame

public void getFrame(byte[][] buf,
                     int[] position)
Specified by:
getFrame in interface IMultiArray

getFrame

public void getFrame(double[][] buf,
                     int[] position)
Specified by:
getFrame in interface IMultiArray

getFrame

public void getFrame(float[][] buf,
                     int[] position)
Specified by:
getFrame in interface IMultiArray

getFrame

public void getFrame(int[][] buf,
                     int[] position)
Specified by:
getFrame in interface IMultiArray

getFrame

public void getFrame(long[][] buf,
                     int[] position)
Specified by:
getFrame in interface IMultiArray

getFrame

public void getFrame(short[][] buf,
                     int[] position)
Specified by:
getFrame in interface IMultiArray

getFrame

public <T> void getFrame(T[][] buf,
                         int[] position)
Description copied from interface: IMultiArray
Place a 2-dimensional array of values into the multiarray

Specified by:
getFrame in interface IMultiArray
Parameters:
buf - array to be placed into the multiarray
position - zero-based index location in fortran order

getLength

public int getLength(int index)
Description copied from interface: IMultiArray
Return the length of a particular dimension

Specified by:
getLength in interface IMultiArray
Parameters:
index - the index of the dimension whose length will be returned
Returns:
length of the dimension

getOffset

public int getOffset()
Description copied from interface: IMultiArray
Return the zero-based offset within the underlying storage for this array

Specified by:
getOffset in interface IMultiArray
Returns:
zero based offset of the start of this array

getShape

public int[] getShape()
Description copied from interface: IMultiArray
Return the length of each dimension in this MultiArray

Specified by:
getShape in interface IMultiArray
Returns:
length of each dimension

getTrace

public void getTrace(byte[] buf,
                     int[] position)
Specified by:
getTrace in interface IMultiArray

getTrace

public void getTrace(double[] buf,
                     int[] position)
Specified by:
getTrace in interface IMultiArray

getTrace

public void getTrace(float[] buf,
                     int[] position)
Specified by:
getTrace in interface IMultiArray

getTrace

public void getTrace(int[] buf,
                     int[] position)
Specified by:
getTrace in interface IMultiArray

getTrace

public void getTrace(long[] buf,
                     int[] position)
Specified by:
getTrace in interface IMultiArray

getTrace

public void getTrace(short[] buf,
                     int[] position)
Specified by:
getTrace in interface IMultiArray

getTrace

public <T> void getTrace(T[] buf,
                         int[] position)
Description copied from interface: IMultiArray
Return a 1-dimensional array of values from the multiarray

Specified by:
getTrace in interface IMultiArray
Parameters:
buf - array to receive data from the multiarray
position - zero-based index location in fortran order

index

public int index(int[] position)
Description copied from interface: IMultiArray
Return the index in the underlying storage of the data at a particular position in the MultiArray

Specified by:
index in interface IMultiArray
Parameters:
position - position of the sample to be accessed using zero-based indices
Returns:
zero-based index in the underlying storage of this sample

index

public int index(int[] position,
                 int element)
Description copied from interface: IMultiArray
Return the index in the underlying storage of an element at a particular position in the MultiArray. This method is used for Arrays where the SeisDataType defines multiple "elements" for each "sample" (i.e. complex or multicomponent data)

Specified by:
index in interface IMultiArray
Parameters:
position - position of the sample to be accessed using zero-based indices
element - index of the "sample" "element" that will be accessed
Returns:
zero-based index in the underlying storage of the element

indexFortran

public int indexFortran(int[] position)
Description copied from interface: IMultiArray
Return the index in the underlying storage of the data at a particular position in the MultiArray. This method uses Fortran style 1 to N based indexing.

Specified by:
indexFortran in interface IMultiArray
Parameters:
position - position of the sample to be accessed using Fortran indices
Returns:
Fortran index in the underlying storage of this sample

indexFortran

public int indexFortran(int[] position,
                        int element)
Description copied from interface: IMultiArray
Return the index in the underlying storage of an element at a particular position in the MultiArray. This method uses Fortran style 1 to N based indexing.

Specified by:
indexFortran in interface IMultiArray
Parameters:
position - position of the sample to be accessed using Fortran indices
element - index of the "sample" "element" that will be accessed
Returns:
Fortran index in the underlying storage of the element

ints

public int[] ints()
Specified by:
ints in interface IMultiArray
Returns:
int array for this MultiArray, null if undefined

longs

public long[] longs()
Specified by:
longs in interface IMultiArray
Returns:
long array for this MultiArray, null if undefined

main

public static void main(java.lang.String[] args)
Parameters:
args -

objects

public <T> T[] objects()
Description copied from interface: IMultiArray
Return the underlying storage for this MultiArray as a 1D array

Specified by:
objects in interface IMultiArray
Returns:
Object array for this MultiArray, null if undefined

putFrame

public void putFrame(byte[][] buf,
                     int[] position)
Specified by:
putFrame in interface IMultiArray

putFrame

public void putFrame(double[][] buf,
                     int[] position)
Specified by:
putFrame in interface IMultiArray

putFrame

public void putFrame(float[][] buf,
                     int[] position)
Specified by:
putFrame in interface IMultiArray

putFrame

public void putFrame(int[][] buf,
                     int[] position)
Specified by:
putFrame in interface IMultiArray

putFrame

public void putFrame(long[][] buf,
                     int[] position)
Specified by:
putFrame in interface IMultiArray

putFrame

public void putFrame(short[][] buf,
                     int[] position)
Specified by:
putFrame in interface IMultiArray

putFrame

public <T> void putFrame(T[][] buf,
                         int[] position)
Description copied from interface: IMultiArray
Place a 2-dimensional array of values into the multiarray

Specified by:
putFrame in interface IMultiArray
Parameters:
buf - array to be placed into the multiarray
position - zero-based index location in fortran order

putTrace

public void putTrace(byte[] buf,
                     int[] position)
Specified by:
putTrace in interface IMultiArray

putTrace

public void putTrace(double[] buf,
                     int[] position)
Specified by:
putTrace in interface IMultiArray

putTrace

public void putTrace(float[] buf,
                     int[] position)
Specified by:
putTrace in interface IMultiArray

putTrace

public void putTrace(int[] buf,
                     int[] position)
Specified by:
putTrace in interface IMultiArray

putTrace

public void putTrace(long[] buf,
                     int[] position)
Specified by:
putTrace in interface IMultiArray

putTrace

public void putTrace(short[] buf,
                     int[] position)
Specified by:
putTrace in interface IMultiArray

putTrace

public <T> void putTrace(T[] buf,
                         int[] position)
Description copied from interface: IMultiArray
Place a 1-dimensional array of values into the multiarray

Specified by:
putTrace in interface IMultiArray
Parameters:
buf - array to be placed into the multiarray
position - zero-based index location in fortran order

range

public int[] range(int[] position,
                   int dimension)
Description copied from interface: IMultiArray
Return a zero-based index triplet defining start,end,increment that will traverse a specified dimension for this MultiArray. If the SeisDataType defines "samples" that are arrays (i.e. complex or multicomponent samples) the range points to the first element of each "sample". The dimension argument defines which dimension will be traversed. The corresponding element of the "position" argument is ignored (in favor of the "start" value).

Specified by:
range in interface IMultiArray
Parameters:
position - starting position in Fortran style indexing
dimension - the dimension that will be traversed
Returns:
zero based index triplet for the requested dimesion

range

public int[] range(int[] position,
                   int dimension,
                   int start,
                   int end,
                   int increment)
Description copied from interface: IMultiArray
Return a zero-based index triplet defining start,end,increment that can be used to access the elements of the underlying 1D array storage for this MultiArray. If the SeisDataType defines "samples" that are arrays (i.e. complex or multicomponent samples) the range points to the first element of each "sample". The dimension argument defines which Fortran dimension will be traversed. The corresponding element of the "position" argument is ignored (in favor of the "start" value).

Specified by:
range in interface IMultiArray
Parameters:
position - starting position in Fortran style indexing
dimension - the dimension that will be traversed
start - start index along the requested dimension
end - ending index
increment - index increment
Returns:
offset triplet for the requested range

range

public int[] range(int[] position,
                   int dimension,
                   int start,
                   int end,
                   int increment,
                   int element)
Description copied from interface: IMultiArray
Return a zero-based index triplet defining start,end,increment that can be used to access individual elements of the underlying 1D array storage for this MultiArray. This method is used to access the individual "elements" of "samples" that contain multiple values (i.e. complex or multicomponent).

Specified by:
range in interface IMultiArray
Parameters:
position - starting position in Fortran style indexing
dimension - the dimension that will be traversed
start - start index along the requested dimension
end - ending index
increment - index increment
element - the index of the element that will be accessed for the range selection
Returns:
offset triplet for the requested range

rangeFortran

public int[] rangeFortran(int[] position,
                          int dimension)
Description copied from interface: IMultiArray
Return a zero-based index triplet defining start,end,increment that will traverse a specified dimension for this MultiArray. If the SeisDataType defines "samples" that are arrays (i.e. complex or multicomponent samples) the range points to the first element of each "sample". The dimension argument defines which dimension will be traversed. The corresponding element of the "position" argument is ignored (in favor of the "start" value).

Specified by:
rangeFortran in interface IMultiArray
Parameters:
position - starting position in Fortran style indexing
dimension - the dimension that will be traversed
Returns:
zero based index triplet for the requested dimesion

rangeFortran

public int[] rangeFortran(int[] position,
                          int dimension,
                          int start,
                          int end,
                          int increment)
Description copied from interface: IMultiArray
Return a Fortran index triplet defining start,end,increment that can be used to access the elements of the underlying 1D array storage for this MultiArray. If the SeisDataType defines "samples" that are arrays (i.e. complex or multicomponent samples) the range points to the first element of each "sample". The dimension argument defines which Fortran dimension will be traversed. The corresponding element of the "position" argument is ignored (in favor of the "start" value).

Specified by:
rangeFortran in interface IMultiArray
Parameters:
position - starting position in Fortran style indexing
dimension - the dimension that will be traversed
start - start index along the requested dimension
end - ending index
increment - index increment
Returns:
Fortran index triplet for the requested range

rangeFortran

public int[] rangeFortran(int[] position,
                          int dimension,
                          int start,
                          int end,
                          int increment,
                          int element)
Description copied from interface: IMultiArray
Return a Fortran style index triplet defining start,end,increment that can be used to access individual elements of the underlying 1D array storage for this MultiArray. This method is used to access the individual "elements" of "samples" that contain multiple values (i.e. complex or multicomponent).

Specified by:
rangeFortran in interface IMultiArray
Parameters:
position - starting position in Fortran style indexing
dimension - the dimension that will be traversed
start - start index along the requested dimension
end - ending index
increment - index increment
element - the index of the element that will be accessed for the range selection
Returns:
Fortran index triplet for the requested range

setArray

public void setArray(byte[] buf)
Specified by:
setArray in interface IMultiArray

setArray

public void setArray(double[] buf)
Specified by:
setArray in interface IMultiArray

setArray

public void setArray(float[] buf)
Specified by:
setArray in interface IMultiArray

setArray

public void setArray(int[] buf)
Specified by:
setArray in interface IMultiArray

setArray

public void setArray(long[] buf)
Specified by:
setArray in interface IMultiArray

setArray

public void setArray(short[] buf)
Specified by:
setArray in interface IMultiArray

setArray

public <T> void setArray(T[] buf)
Description copied from interface: IMultiArray
Provide the array that is used for underlying storage The "object" version is a generic method that handles arbitrary objects The rest of the methods are for primitive types

Specified by:
setArray in interface IMultiArray
Parameters:
buf - array that is used for underlying storage

setClassType

public void setClassType(java.lang.Class classType)
Description copied from interface: IMultiArray
Set the class type of this MultiArray

Specified by:
setClassType in interface IMultiArray
Parameters:
classType - - the class type for this array

setDimensions

public void setDimensions(int ndim)
Description copied from interface: IMultiArray
Set the number of dimensions for this MultiArray

Specified by:
setDimensions in interface IMultiArray
Parameters:
ndim - number of dimensions

setElementCount

public void setElementCount(int elementCount)
Description copied from interface: IMultiArray
Set the element count for this MultiArray

Specified by:
setElementCount in interface IMultiArray
Parameters:
elementCount - - the number of "elements" per "sample"

setOffset

public void setOffset(int offset)
Description copied from interface: IMultiArray
Set the zero-based offset within the underlying storage for this array

Specified by:
setOffset in interface IMultiArray
Parameters:
offset - zero based offset to the start of this array

setShape

public void setShape(int[] lengths)
Description copied from interface: IMultiArray
Set the shape of this MultiArray, in Fortran style with the "fast" dimension first

Specified by:
setShape in interface IMultiArray
Parameters:
lengths - length of each dimension

shorts

public short[] shorts()
Specified by:
shorts in interface IMultiArray
Returns:
short array for this MultiArray, null if undefined

tran1243

public void tran1243()
Transpose the third and fourth dimensions of this MultiArray


tran132

public void tran132()
Transpose the second and third dimensions of an MultiArray


tran21

public void tran21()
Transpose the first two dimensions of a MultiArray If the number of elements per sample is not 1, the transpose is "promoted" to tran132 using the element count as the first dimension.


transpose

public void transpose(TransposeType type)
Apply the requested transpose to this MultiArray

Specified by:
transpose in interface IMultiArray
Parameters:
type - the type of transpose to apply