00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef MDA_H
00022 #define MDA_H
00023
00024 #include <stdlib.h>
00025 #include <string.h>
00026 #include <stdio.h>
00027 #include "chainlink_complex.h"
00028
00029 #define MAX_MDA_DIMS 50
00030 #define MDA_COMMAND_MASK -3
00031
00032 #define MDA_TYPE_COMPLEX -1
00033 #define MDA_TYPE_BYTE -2
00034 #define MDA_TYPE_REAL -3
00035 #define MDA_TYPE_SHORT -4
00036 #define MDA_TYPE_INT32 -5
00037
00038
00061 class mda {
00062 private:
00064
00065 int32 data_type;
00066 int32 num_dims;
00067 int32 dims[MAX_MDA_DIMS];
00068 int32 dimprod;
00069 unsigned char dummy_mask;
00071 public:
00072 char pathname[200];
00073
00085 int32 get_data_type() {
00086 return data_type;
00087 }
00090 int32 get_num_dims() {
00091 return num_dims;
00092 }
00096 int32 size(int j) {
00097 return dims[j];
00098 }
00101 int32 size() {
00102 return dimprod;
00103 }
00108 int32 *get_dims() {
00109 return dims;
00110 }
00112
00113 public:
00114
00117 unsigned char *data_byte;
00120 int32 *data_int32;
00123 short int *data_short;
00126 real *data_real;
00129 complex *data_complex;
00132 unsigned char *mask;
00133
00135
00137
00138 mda();
00139 mda(mda &X);
00140 virtual ~mda();
00142
00144 void clear();
00150 void allocate(int32 data_type_in,
00151 int32 N1, int32 N2=-1,int32 N3=-1,int32 N4=-1,
00152 int32 N5=-1,int32 N6=-1,int32 N7=-1,int32 N8=-1);
00158 void allocate(int32 data_type,int32 num_dims,int32 *dims);
00161 void allocate_mask(unsigned char val=0);
00167 void setall(complex val);
00173 void setall(real val);
00178 void setall_mask(unsigned char val);
00186 complex get(int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1);
00194 void set(complex val, int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1);
00202 void set(real val, int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1);
00205 complex get(int32 *inds);
00208 void set(complex val, int32 *inds);
00211 void set(real val, int32 *inds);
00216 unsigned char &maskat(int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1);
00221 unsigned char &maskat(int32 *inds);
00222
00227 complex &complexat(int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1);
00228
00233 real &realat(int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1);
00234
00239 int32 &int32at(int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1);
00240
00245 short int &intat(int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1);
00246
00251 unsigned char &byteat(int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1);
00252
00253
00254 void operator=(mda &X);
00255
00258 void tocomplex();
00261 void toreal();
00264 void toint32();
00267 void toshort();
00270 void tobyte();
00271
00274 void add(real val);
00277 void add(complex val);
00280 void multiply(real val);
00283 void multiply(complex val);
00284
00290 void crop(int32 *inds1,int32 *inds2);
00291
00292 bool is_in_range(int32 *index);
00293
00298 bool write_mda(char *fname);
00299 void write_mda(FILE *outf);
00304 bool read_mda(char *fname);
00305 bool read_mda(FILE *inf);
00308 bool read_mda_slices(char *fname,int slice_min,int slice_max);
00309 void read_mda_slices(FILE *inf,int slice_min,int slice_max);
00310
00313 bool read_center_slice(char *fname);
00314
00315 void squeeze();
00321 void shift(int32 *shifts);
00322
00325 bool matches_dimensions(int32 num_dims_in,int32 *dims_in);
00326
00329 bool permute(int32 *vec);
00330
00333 bool is_1d();
00334
00335 int32 get_1d_index(int32 j0, int32 j1=-1, int32 j2=-1, int32 j3=-1, int32 j4=-1, int32 j5=-1);
00336 int32 get_1d_index(int32 *inds);
00337
00338 void readreal(char *fname,int32 N1,int32 N2,int32 N3);
00339 private:
00340 void initialize();
00341
00342 };
00343
00344 #endif