00001 #ifndef DEF_VECTOR
00002 #define DEF_VECTOR
00003 #include <stdio.h>
00004 #include <assert.h>
00005
00006
00007 #include "iotools.h"
00008
00009 #ifdef DEBUG_VECTOR
00010 static unsigned long Aciv;
00011 static unsigned long Acv;
00012 #endif
00013
00014 struct vector
00015
00016
00017
00018
00019
00020 {
00021 long n;
00022 double *a;
00023
00024 vector() { n = 0; a = NULL;};
00025 vector(long n);
00026 vector(const vector &v);
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 double& operator () (long i)
00038 {
00039 #ifdef DEBUG_VECTOR
00040 if ((i >= n) || (i < 0))
00041 print_err("vector row index %ld is out of range <0,%ld>", __FILE__, __LINE__, __func__, i, n-1);
00042
00043 assert(i < n);
00044 #endif
00045 return (a[i]);
00046 };
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 double& operator [] (long i)
00058 {
00059 #ifdef DEBUG_VECTOR
00060 if ((i >= n) || (i < 0))
00061 print_err("vector row index %ld is out of range <0,%ld>", __FILE__, __LINE__, __func__, i, n-1);
00062
00063 assert(i < n);
00064 #endif
00065 return (a[i]);
00066 };
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 double operator [] (long i) const
00078 {
00079 #ifdef DEBUG_VECTOR
00080 if ((i >= n) || (i < 0))
00081 print_err("vector row index %ld is out of range <0,%ld>", __FILE__, __LINE__, __func__, i, n-1);
00082
00083 assert(i < n);
00084 #endif
00085 return (a[i]);
00086 };
00087
00088 double get_item(long i) { return a[i]; }
00089 void set_item(long i, double val) { a[i] = val; }
00090
00091 ~vector();
00092 };
00093
00094
00095 struct ivector
00096
00097
00098
00099
00100 {
00101 long n;
00102 long *a;
00103
00104 ivector() { n = 0; a = NULL;};
00105 ivector(long n);
00106 ivector(const ivector &v);
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 long& operator () (long i)
00118 {
00119 #ifdef DEBUG_VECTOR
00120 if ((i >= n) || (i < 0))
00121 print_err("ivector row index %ld is out of range <0,%ld>", __FILE__, __LINE__, __func__, i, n-1);
00122
00123 assert(i < n);
00124 #endif
00125 return (a[i]);
00126 };
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 long& operator [] (long i)
00138 {
00139 #ifdef DEBUG_VECTOR
00140 if ((i >= n) || (i < 0))
00141 print_err("ivector row index %ld is out of range <0,%ld>", __FILE__, __LINE__, __func__, i, n-1);
00142
00143 assert(i < n);
00144 #endif
00145 return (a[i]);
00146 };
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 long& operator [] (long i) const
00158 {
00159 #ifdef DEBUG_VECTOR
00160 if ((i >= n) || (i < 0))
00161 print_err("ivector row index %ld is out of range <0,%ld>", __FILE__, __LINE__, __func__, i, n-1);
00162
00163 assert(i < n);
00164 #endif
00165 return (a[i]);
00166 };
00167
00168 ~ivector();
00169
00170 long get_item(long i) { return a[i]; }
00171 void set_item(long i, long val) { a[i] = val; }
00172 };
00173
00174
00175
00176
00177
00178
00179
00180 struct atsel{
00181
00182 long num;
00183
00184 long nba;
00185
00186 long nia;
00187
00188 long *atrib;
00189
00190 atsel (){
00191 num=0;
00192 nba=0;
00193 nia=0;
00194 atrib=NULL;
00195 };
00196 ~atsel (){ delete [] atrib; };
00197
00198 long read(XFILE* in);
00199 };
00200
00201
00202
00203 long allocv(long n, vector &vec);
00204
00205 long allocv(long n, ivector &vec);
00206
00207 long reallocv(long n, vector &vec);
00208
00209 long reallocv(long n, ivector &vec);
00210
00211
00212 long copyv(const vector &src, vector &dest);
00213
00214 long copyv(const ivector &src, ivector &dest);
00215 long copyv(const long *src,long *dest,long n);
00216
00217 long copyv(const double *src, double *dest, long n);
00218
00219 long copyv(const double *src, vector &dest);
00220
00221 long copyv(const vector &src, double *dest);
00222
00223
00224 long copymultv(const vector &src, vector &dest, const double c);
00225
00226 long copymultv(const ivector &src, ivector &dest, const long c);
00227
00228 long copymultv(const double *src, double *dest, const double c, long n);
00229
00230
00231 long fillv(double c, vector &vec);
00232
00233 long fillv(long c, ivector &vec);
00234
00235 void fillv(long c, long *vec,long n);
00236
00237 void fillv(double c, double *vec,long n);
00238
00239
00240 long nullv (double *a,long n);
00241 long nullv (ivector &a);
00242
00243
00244 long destrv(vector &vec);
00245
00246 long destrv(ivector &vec);
00247
00248
00249 long addv(const vector &a, const vector &b, vector &c);
00250
00251 void addmultv(const vector &a, const vector &b, double bc, vector &c);
00252
00253 void addmultv(vector &a, const vector &b, double bc);
00254
00255
00256 long addv(const ivector &a, const ivector &b, ivector &c);
00257
00258
00259 void addv(double *a,double *b,long n);
00260
00261
00262 void addv(double *a,double *b, double *c, long n);
00263
00264
00265 void addmultv (double *a,double *b,double bc,long n);
00266
00267 void addmultv (double *a,double *b,double bc, double *c, long n);
00268
00269
00270 long subv(const vector &a, const vector &b, vector &c);
00271
00272 long subv(const vector &a, const vector &b);
00273
00274 long subv(const ivector &a, const ivector &b, ivector &c);
00275
00276
00277 void subv(double *a,double *b,long n);
00278
00279 void subv (double *a,double *b,double *c,long n);
00280
00281
00282 long crprd(const vector &a, const vector &b, vector &c);
00283
00284 long crprd(const ivector &a, const ivector &b, ivector &c);
00285
00286
00287 long scprd(const vector &a, const vector &b, double &scalar);
00288
00289 long scprd(const ivector &a, const ivector &b, long &scalar);
00290
00291 double scprd(const double *a, const double *b, long n);
00292
00293 double ss (double *a,double *b,long n);
00294
00295
00296 long cmulv(double c, const vector &a, vector &u);
00297
00298 long cmulv(double c, const ivector &a, vector &u);
00299
00300 long cmulv(long c, const ivector &a, ivector &u);
00301
00302
00303 long cmulv(double c, vector &a);
00304
00305 long cmulv(long c, ivector &a);
00306
00307 void cmulv(double c, double *a, long n);
00308
00309 void cmulv(double c, double *a, double *u, long n);
00310
00311
00312 double normv(const vector &a);
00313
00314 double normv(const double *a, long n);
00315
00316 double normv(const ivector &a);
00317
00318
00319 long cosav(const vector &a, const vector &b, double &cos);
00320
00321 long cosav(const ivector &a, const ivector &b, double &cos);
00322
00323
00324 void absv(vector &a);
00325
00326 void absv(ivector &a);
00327
00328
00329 long printv(const vector &u, FILE *out = stdout, int prec = 3, int width = 11);
00330
00331 long printv(const double *u, long n, FILE *out = stdout, int prec = 3, int width = 11);
00332
00333 long printv(FILE *out, vector &u);
00334
00335 long printv(const ivector &u, FILE *out = stdout, int width = 11);
00336
00337 long printv(const long *u, long n, FILE *out = stdout, int width = 11);
00338
00339
00340 long readv(XFILE *in, vector &u);
00341
00342 long readv(char *in, vector &u);
00343
00344
00345 void extract (vector &a, vector &b, long fi, long ncomp);
00346
00347
00348 long extractposv (vector &a, vector &b);
00349
00350 long extractnegv (vector &a, vector &b);
00351
00352
00353 void shell_sort(ivector &v);
00354
00355
00356 void shell_sort(long *v, long n);
00357
00358 #endif