mda Class Reference

ChainLink Multi-Dimensional Array type. More...

#include <mda.h>

List of all members.

Public Member Functions

int32 get_data_type ()
int32 get_num_dims ()
int32 size (int j)
int32 size ()
int32 * get_dims ()
 mda (mda &X)
void clear ()
void allocate (int32 data_type_in, int32 N1, int32 N2=-1, int32 N3=-1, int32 N4=-1, int32 N5=-1, int32 N6=-1, int32 N7=-1, int32 N8=-1)
void allocate (int32 data_type, int32 num_dims, int32 *dims)
void allocate_mask (unsigned char val=0)
void setall (complex val)
void setall (real val)
void setall_mask (unsigned char val)
complex get (int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1)
void set (complex val, int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1)
void set (real val, int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1)
complex get (int32 *inds)
void set (complex val, int32 *inds)
void set (real val, int32 *inds)
unsigned char & maskat (int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1)
unsigned char & maskat (int32 *inds)
complexcomplexat (int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1)
realrealat (int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1)
int32 & int32at (int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1)
short int & intat (int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1)
unsigned char & byteat (int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1)
void operator= (mda &X)
void tocomplex ()
void toreal ()
void toint32 ()
void toshort ()
void tobyte ()
void add (real val)
void add (complex val)
void multiply (real val)
void multiply (complex val)
void crop (int32 *inds1, int32 *inds2)
bool is_in_range (int32 *index)
bool write_mda (char *fname)
void write_mda (FILE *outf)
bool read_mda (char *fname)
bool read_mda (FILE *inf)
bool read_mda_slices (char *fname, int slice_min, int slice_max)
void read_mda_slices (FILE *inf, int slice_min, int slice_max)
bool read_center_slice (char *fname)
void squeeze ()
void shift (int32 *shifts)
bool matches_dimensions (int32 num_dims_in, int32 *dims_in)
bool permute (int32 *vec)
bool is_1d ()
int32 get_1d_index (int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1)
int32 get_1d_index (int32 *inds)
void readreal (char *fname, int32 N1, int32 N2, int32 N3)

Public Attributes

char pathname [200]
unsigned char * data_byte
int32 * data_int32
short int * data_short
realdata_real
complexdata_complex
unsigned char * mask


Detailed Description

ChainLink Multi-Dimensional Array type.

Example

  mda X,Y,Z; 
  X.allocate(MDA_TYPE_COMPLEX,10,5,3); //allocate 10x5x3 complex array 
  Y.allocate(MDA_TYPE_REAL,10,5,3);    //allocate 10x5x3 real array

  int32 x,y,z; 
  for (x=0; x<X.size(0); x++) 
	  for (y=0; y<X.size(1); y++) 
	    for (z=0; z<X.size(2); z++) { 
	      X.set(cplex(x,y), x,y,z); //set X[x,y,z]=x+iy 
	      Y.set((real)z, x,y,z);   //set Y[x,y,z]=z 
	    }

  //now print Y[4,2,0] 
  printf("Y at [4,2,0] is %g\n", Y.get(4,2,0).re); 
  


Member Function Documentation

int32 mda::get_data_type (  )  [inline]

Returns the internal numerical data type for the mda.

The return value is one of the following values:

int32 mda::get_num_dims (  )  [inline]

Returns the number of dimensions in the mda.

int32 mda::size ( int  j  )  [inline]

Returns the number of elements along the jth dimension of j. Note: make sure that 0 <= j < get_num_dims() or you will get an access violation

int32 mda::size (  )  [inline]

Returns the total number of elements in the array.

int32* mda::get_dims (  )  [inline]

For convenience, returns a pointer to the private member "dims".such that dims[j]=size(j).

Note: Do not change the value of dims[j]. Use allocate() instead.

void mda::clear (  ) 

Clears all data and and resets to a 1D array of size 1

void mda::allocate ( int32  data_type_in,
int32  N1,
int32  N2 = -1,
int32  N3 = -1,
int32  N4 = -1,
int32  N5 = -1,
int32  N6 = -1,
int32  N7 = -1,
int32  N8 = -1 
)

Allocate array of size N1xN2xN3x... with a specified data type

For example, allocate(MDA_TYPE_COMPLEX,4,5) allocates a 4x5 complex matrix and allocate(MDA_TYPE_REAL,100,100,10) allocates a 100x100x10 array of real numbers.

void mda::allocate ( int32  data_type,
int32  num_dims,
int32 *  dims 
)

Allocate array with the specified data type and size

For example, if to make Y have the same data type and size as X, use Y.allocate(X.get_data_type(),X.get_num_dims(),X.get_dims());

void mda::allocate_mask ( unsigned char  val = 0  ) 

Allocate mask. The mask is simply an array of unsigned characters with the same dimensions as the mda.

void mda::setall ( complex  val  ) 

Set all entries to be equal to val.

Note: using this function won't change the data type to MDA_TYPE_COMPLEX. Therefore information will be lost if, for example, val=1+i and get_data_type()==MDA_TYPE_REAL.

void mda::setall ( real  val  ) 

Set all entries to be equal to val.

Note: using this function won't change the data type to MDA_TYPE_REAL. Therefore information will be lost if, for example, val=1.57 and get_data_type()==MDA_TYPE_BYTE.

void mda::setall_mask ( unsigned char  val  ) 

Set all mask entries equal to val

This function will first call allocate_mask() if the mask has not been allocated

complex mda::get ( int32  j0,
int32  j1 = -1,
int32  j2 = -1,
int32  j3 = -1,
int32  j4 = -1,
int32  j5 = -1 
)

Get value at a given zero-based index

For example, if X is a 3D array, then X.get(3,0,9) returns the value at position [3,0,9] Note that this function always returns a complex number, even if the data type is not MDA_TYPE_COMPLEX

An alternative would be to directly access the data via data_byte, data_short, data_real, or data_complex

void mda::set ( complex  val,
int32  j0,
int32  j1 = -1,
int32  j2 = -1,
int32  j3 = -1,
int32  j4 = -1,
int32  j5 = -1 
)

Set complex value at a given zero-based index

For example, if X is a complex 3D array, then X.set(cplex(1,i),3,0,9) sets the complex number at position [3,0,9] to 1+i. Note that this function always accepts a complex number, even if the data type is not MDA_TYPE_COMPLEX

An alternative would be to directly access the data via data_byte, data_short, data_real, or data_complex

void mda::set ( real  val,
int32  j0,
int32  j1 = -1,
int32  j2 = -1,
int32  j3 = -1,
int32  j4 = -1,
int32  j5 = -1 
)

Set real value at a given zero-based index

For example, if X is a 3D array, then X.set(2.75,3,0,9) sets the complex number at position [3,0,9] to 2.75. Note that this function always accepts a real number, even if the data type is not MDA_TYPE_REAL

An alternative would be to directly access the data via data_byte, data_short, data_real, or data_complex

complex mda::get ( int32 *  inds  ) 

Set value at a given zero-based multi-index

void mda::set ( complex  val,
int32 *  inds 
)

Set complex value at a given zero-based multi-index

void mda::set ( real  val,
int32 *  inds 
)

Set real value at a given zero-based multi-index

unsigned char & mda::maskat ( int32  j0,
int32  j1 = -1,
int32  j2 = -1,
int32  j3 = -1,
int32  j4 = -1,
int32  j5 = -1 
)

Returns reference to the mask at a given index. Use this to get or set the mask.

See allocate_mask()

unsigned char & mda::maskat ( int32 *  inds  ) 

Returns reference to the mask at a given index. Use this to get or set the mask.

See allocate_mask()

complex & mda::complexat ( int32  j0,
int32  j1 = -1,
int32  j2 = -1,
int32  j3 = -1,
int32  j4 = -1,
int32  j5 = -1 
)

Returns reference to complex number at a given index.

Warning: use this function only when get_data_type()==MDA_TYPE_COMLEX

real & mda::realat ( int32  j0,
int32  j1 = -1,
int32  j2 = -1,
int32  j3 = -1,
int32  j4 = -1,
int32  j5 = -1 
)

Returns reference to real number at a given index.

Warning: use this function only when get_data_type()==MDA_TYPE_REAL

int32& mda::int32at ( int32  j0,
int32  j1 = -1,
int32  j2 = -1,
int32  j3 = -1,
int32  j4 = -1,
int32  j5 = -1 
)

Returns reference to integer at a given index.

Warning: use this function only when get_data_type()==MDA_TYPE_INT32

short int & mda::intat ( int32  j0,
int32  j1 = -1,
int32  j2 = -1,
int32  j3 = -1,
int32  j4 = -1,
int32  j5 = -1 
)

Returns reference to integer at a given index.

Warning: use this function only when get_data_type()==MDA_TYPE_SHORT

unsigned char & mda::byteat ( int32  j0,
int32  j1 = -1,
int32  j2 = -1,
int32  j3 = -1,
int32  j4 = -1,
int32  j5 = -1 
)

Returns reference to unsigned char at a given index.

Warning: use this function only when get_data_type()==MDA_TYPE_BYTE

void mda::tocomplex (  ) 

Convert mda to complex so that get_data_type()==MDA_TYPE_COMPLEX

void mda::toreal (  ) 

Convert mda to real so that get_data_type()==MDA_TYPE_REAL

void mda::toint32 (  ) 

Convert mda to integer so that get_data_type()==MDA_TYPE_INT32

void mda::toshort (  ) 

Convert mda to short integer so that get_data_type()==MDA_TYPE_SHORT

void mda::tobyte (  ) 

Convert mda to unsigned char so that get_data_type()==MDA_TYPE_BYTE

void mda::add ( real  val  ) 

Add a real value to all entries

void mda::add ( complex  val  ) 

Add a complex value to all entries

void mda::multiply ( real  val  ) 

Multiply all entries by a real number

void mda::multiply ( complex  val  ) 

Multiply all entries by a complex number

void mda::crop ( int32 *  inds1,
int32 *  inds2 
)

Crop the multi-dimensional array.

inds1 is the lower-bound index for cropping inds2 is the upper-bound index for cropping

bool mda::write_mda ( char *  fname  ) 

Write mda to file.

The file will contain raw data as well as the data type and mask

bool mda::read_mda ( char *  fname  ) 

Read mda data from file

See write_mda()

bool mda::read_mda_slices ( char *  fname,
int  slice_min,
int  slice_max 
)

Read a particular slice from a 3D mda file

bool mda::read_center_slice ( char *  fname  ) 

Read center slice from a 3D mda file

void mda::shift ( int32 *  shifts  ) 

Shift with wrapping.

bool mda::matches_dimensions ( int32  num_dims_in,
int32 *  dims_in 
)

Returns true if num_dims_in and dims_in match get_num_dims() and get_dims()

bool mda::permute ( int32 *  vec  ) 

Permuate the dimensions of the mda

bool mda::is_1d (  ) 

Returns true if the mda is 1-dimensional


Member Data Documentation

unsigned char* mda::data_byte

Pointer to the actual data if get_data_type()==MDA_TYPE_BYTE

int32* mda::data_int32

Pointer to the actual data if get_data_type()==MDA_TYPE_INT32

short int* mda::data_short

Pointer to the actual data if get_data_type()==MDA_TYPE_SHORT

real* mda::data_real

Pointer to the actual data if get_data_type()==MDA_TYPE_REAL

complex* mda::data_complex

Pointer to the actual data if get_data_type()==MDA_TYPE_COMPLEX

unsigned char* mda::mask

Pointer to mask data. The mask is simply an array of unsigned characters with the same dimensions as the mda.


The documentation for this class was generated from the following files:
Generated on Mon Feb 5 12:16:37 2007 for ChainLinkBase by  doxygen 1.5.1-p1