dods.clients.matlab
Class MatlabArray

java.lang.Object
  extended by dods.dap.BaseType
      extended by dods.dap.DVector
          extended by dods.dap.DArray
              extended by dods.clients.matlab.MatlabArray
All Implemented Interfaces:
ClientIO, Cloneable

public class MatlabArray
extends DArray

An extention of the DArray class, with optimizations for Matlab.

See Also:
DArray

Constructor Summary
MatlabArray()
          Construct a new MatlabArray.
MatlabArray(String name)
          Construct a new MatlabArray with name name.
 
Method Summary
protected static int get_cm_offset(int[] current_index, int ndims, int[] dims)
          Given an index into, and the dimensions of the array, return the offset needed to access the referenced element assuming column-major storage order.
protected static boolean get_next_rm_index(int[] current_index, int ndims, int[] dims)
          Given a current index tuple and the dimensionality of the data, compute the next tuple.
protected static int get_rm_offset(int[] current_index, int ndims, int[] dims)
          Given an index into, and the dimensions of the array, return the offset needed to access the referenced element assuming row-major storage order.
 String getArrayTypeName()
          Return the type of data held in the array as a String.
 Object getData()
          Return the data held in the MatlabArray as an array of atomic types.
static int[] rm_index2cm_index(int[] rm_dims, int ndims)
          A public interface to rm_index2cm_index which doesn't require memory to be allocated for the array containing the column-major dimensions
protected static void rm_index2cm_index(int[] cm_dims, int[] rm_dims, int ndims)
          Given the row-major index array (with ndims-1 elements), load values into cm_dims so that the dimensions will be listed in Matlab's n-major order.
static double[] rm2cm(double[] src, int ndims, int[] rm_dims)
          Given the double array described by rm_dims[ndims], transform that array from row-major to column-major order.
 
Methods inherited from class dods.dap.DArray
appendDim, appendDim, checkSemantics, clone, getDimension, getDimensions, getFirstDimension, getTypeName, numDimensions, printDecl, printVal
 
Methods inherited from class dods.dap.DVector
addVariable, deserialize, externalize, getLength, getPrimitiveVector, setLength
 
Methods inherited from class dods.dap.BaseType
checkSemantics, elementCount, elementCount, getLongName, getName, getParent, newPrimitiveVector, printDecl, printDecl, printDecl, printDecl, printDecl, printDecl, printDecl, printVal, printVal, printVal, setName, setParent
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatlabArray

public MatlabArray()
Construct a new MatlabArray.


MatlabArray

public MatlabArray(String name)
Construct a new MatlabArray with name name.

Parameters:
name - The name of the array
Method Detail

getArrayTypeName

public String getArrayTypeName()
Return the type of data held in the array as a String.

Returns:
The type of data held in the array.

getData

public Object getData()
Return the data held in the MatlabArray as an array of atomic types.

Returns:
The data.

get_rm_offset

protected static int get_rm_offset(int[] current_index,
                                   int ndims,
                                   int[] dims)
Given an index into, and the dimensions of the array, return the offset needed to access the referenced element assuming row-major storage order.

Parameters:
current_index - The index to retrieve the offset for
ndims - The number of dimensions
dims - An array containing The dimensions of the array
Returns:
The offset needed to retrieve current_index from a single-dimension array in row-major order.

get_cm_offset

protected static int get_cm_offset(int[] current_index,
                                   int ndims,
                                   int[] dims)
Given an index into, and the dimensions of the array, return the offset needed to access the referenced element assuming column-major storage order.

Parameters:
current_index - The index to retrieve the offset for
ndims - The number of dimensions
dims - An array containing the dimensions of the array
Returns:
The offset needed to retrieve current_index from a single-dimension array in column-major order.

rm2cm

public static double[] rm2cm(double[] src,
                             int ndims,
                             int[] rm_dims)
Given the double array described by rm_dims[ndims], transform that array from row-major to column-major order. Put the result in dest.

Assume that the rm_dims array contains the dimension information in row-major order.

Parameters:
src - The column-major array to convert to row-major
ndims - The number of dimensions in the array
dims - An array containing the dimensions of the array

rm_index2cm_index

protected static void rm_index2cm_index(int[] cm_dims,
                                        int[] rm_dims,
                                        int ndims)
Given the row-major index array (with ndims-1 elements), load values into cm_dims so that the dimensions will be listed in Matlab's n-major order.

Assume that enough storage has already been allocated to cm_dims.

Algorithm: RM order: Plane, Row, Column
NM order: Row, Column, Plane.

Move the last two dimensions from the RM order to the first two of the NM order. Then copy each plane dimension from the front of the RM ordering to the back of the NM ordering reversing those entries as they are copied.

Note that if ndims is less then three then this function just copies the values and, in that case, it is better to not use this function.

Parameters:
cm_dims - An array for which the appropriate memory has been already allocated to store the column-major dimensions in
rm_dims - An array containing the row-major dimensions to be converted into column-major
ndims - The number of dimensions

rm_index2cm_index

public static int[] rm_index2cm_index(int[] rm_dims,
                                      int ndims)
A public interface to rm_index2cm_index which doesn't require memory to be allocated for the array containing the column-major dimensions

Parameters:
rm_dims - An array containing the row-major dimensions to be converted into column-major
ndims - The number of dimensions
Returns:
An array containing the column-major dimensions

get_next_rm_index

protected static boolean get_next_rm_index(int[] current_index,
                                           int ndims,
                                           int[] dims)
Given a current index tuple and the dimensionality of the data, compute the next tuple. Vary the rightmost element of the tuple the fastest. Return true if there *is* a next tuple (which is passed back in current_index), false otherwise.

Parameters:
current_index - An array containing the rm index to be incremented
ndims - The number of dimensions in the array
dims - An array containing the dimensions of the array.