00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #ifndef __MMDB_MatType__
00047 #define __MMDB_MatType__
00048
00049 #include <math.h>
00050
00051 #define UseDoubleFloat
00052
00053 #ifndef __ClassMacros
00054
00055 # define __ClassMacros
00056
00057
00058 # define DefineClass(ClassName) \
00059 class ClassName; \
00060 typedef ClassName * P##ClassName; \
00061 typedef ClassName & R##ClassName; \
00062 typedef P##ClassName * PP##ClassName; \
00063 typedef P##ClassName & RP##ClassName;
00064
00065
00066 # define DefineStructure(StructureName) \
00067 struct StructureName; \
00068 typedef StructureName * P##StructureName; \
00069 typedef StructureName & R##StructureName; \
00070 typedef P##StructureName * PP##StructureName; \
00071 typedef P##StructureName & RP##StructureName;
00072
00073 #endif
00074
00075 #define UNUSED_ARGUMENT(x) (void)x
00076
00077
00078
00079 namespace mmdb {
00080
00081 #ifdef UseDoubleFloat
00082
00083 typedef double realtype;
00084 const realtype MinReal = 2.2250e-307;
00085 const realtype MaxReal = 1.7976e+308;
00086 const realtype fMinReal = 2.2250e-307;
00087 const realtype fMaxReal = 1.7976e+308;
00088
00089 #else
00090
00091 typedef float realtype;
00092 const realtype MinReal = 1.1755e-38;
00093 const realtype MaxReal = 3.4020e+38;
00094 const realtype fMinReal = 1.1755e-38;
00095 const realtype fMaxReal = 3.4020e+38;
00096
00097 #endif
00098
00099 typedef float shortreal;
00100 const shortreal MinShortReal = 1.1755e-38;
00101 const shortreal MaxShortReal = 3.4020e+38;
00102
00103 #define strrchr LastOccurence
00104 #define fstrrchr LastOccurence
00105 #define strchr FirstOccurence
00106 #define fstrchr FirstOccurence
00107
00108 typedef char * pstr;
00109 typedef const char * cpstr;
00110 typedef unsigned int word;
00111 typedef unsigned char byte;
00112 typedef signed char short_int;
00113
00114 typedef unsigned int word2;
00115 typedef byte * byteptr;
00116 typedef unsigned long lword;
00117
00118 typedef byte intUniBin [4];
00119 typedef byte shortUniBin [2];
00120 typedef byte longUniBin [4];
00121 typedef byte wordUniBin [4];
00122 typedef byte realUniBin [10];
00123 typedef byte floatUniBin [5];
00124 typedef byte shortrealUniBin[5];
00125
00126 #ifdef _WIN32
00127 pstr strcasestr ( pstr s1, cpstr s2 );
00128 #endif
00129
00130 #ifdef _MSC_VER
00131 #define strncasecmp _strnicmp
00132 #define strcasecmp _stricmp
00133 #endif
00134
00135 const int MaxInt = 32767;
00136 const int MinInt = -32768;
00137 const word MaxWord = 65535L;
00138 const long int MaxInt4 = 2147483647L;
00139
00140
00141
00142
00143 const long int MinInt4 = -2147483647;
00144 const lword MaxWord4 = 4294967295UL;
00145
00146 const realtype Pi = 3.141592653589793238462643;
00147 const realtype Eu = 2.718281828459045235360287;
00148 const realtype ln10 = 2.3025850929940456840179915;
00149
00150
00151 typedef realtype * rvector;
00152 typedef int * ivector;
00153 typedef word * wvector;
00154 typedef byte * bvector;
00155 typedef bool * ovector;
00156 typedef long * lvector;
00157 typedef lword * lwvector;
00158 typedef pstr * psvector;
00159
00160
00161 typedef rvector * rmatrix;
00162 typedef ivector * imatrix;
00163 typedef wvector * wmatrix;
00164 typedef bvector * bmatrix;
00165 typedef ovector * omatrix;
00166 typedef lvector * lmatrix;
00167 typedef lwvector * lwmatrix;
00168 typedef psvector * psmatrix;
00169
00170
00171 typedef rmatrix * rmatrix3;
00172 typedef imatrix * imatrix3;
00173 typedef wmatrix * wmatrix3;
00174 typedef bmatrix * bmatrix3;
00175 typedef omatrix * omatrix3;
00176 typedef lmatrix * lmatrix3;
00177 typedef lwmatrix * lwmatrix3;
00178 typedef psmatrix * psmatrix3;
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188 extern bool InitMatType();
00189
00190
00191
00192 inline int mround ( realtype X ) { return (int)floor(X+0.5); }
00193 inline int ifloor ( realtype X ) { return (int)floor(X); }
00194 inline int Abs ( int x ) { return ( x >= 0 ? x : -x ); }
00195
00196 inline void ISwap ( int & x, int & y )
00197 { int b = x; x = y; y = b; }
00198
00199 inline void WSwap ( word & x, word & y )
00200 { word b = x; x = y; y = b; }
00201
00202 inline void BSwap ( byte & x, byte & y )
00203 { byte b = x; x = y; y = b; }
00204
00205 inline void OSwap ( bool & x, bool & y )
00206 { bool b = x; x = y; y = b; }
00207
00208 inline void LSwap ( long & x, long & y )
00209 { long b = x; x = y; y = b; }
00210
00211 inline void RSwap ( realtype & x, realtype & y )
00212 { realtype b = x; x = y; y = b; }
00213
00214 inline realtype RMax ( const realtype x1, const realtype x2 )
00215 { return ( x1 > x2 ? x1 : x2 ); }
00216
00217 inline long LMax ( const long x1, const long x2 )
00218 { return ( x1 > x2 ? x1 : x2 ); }
00219
00220 inline word WMax ( const word x1, const word x2 )
00221 { return ( x1 > x2 ? x1 : x2 ); }
00222
00223 inline int IMax ( const int x1, const int x2 )
00224 { return ( x1 > x2 ? x1 : x2 ); }
00225
00226 inline realtype RMin ( const realtype x1, const realtype x2 )
00227 { return ( x1 < x2 ? x1 : x2 ); }
00228
00229 inline long LMin ( const long x1, const long x2 )
00230 { return ( x1 < x2 ? x1 : x2 ); }
00231
00232 inline word WMin ( const word x1, const word x2 )
00233 { return ( x1 < x2 ? x1 : x2 ); }
00234
00235 inline int IMin ( const int x1, const int x2 )
00236 { return ( x1 < x2 ? x1 : x2 ); }
00237
00238 inline realtype fsign ( const realtype x1, const realtype x2 ) {
00239 realtype ax;
00240 if (x1>=0.0) ax = x1;
00241 else ax = -x1;
00242 return ( x2 >= 0.0 ? ax : -ax );
00243 }
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253 extern bool GetVectorMemory ( rvector & V, word N, word Shift=1 );
00254 extern bool GetVectorMemory ( ivector & I, word N, word Shift=1 );
00255 extern bool GetVectorMemory ( wvector & W, word N, word Shift=1 );
00256 extern bool GetVectorMemory ( bvector & B, word N, word Shift=1 );
00257 extern bool GetVectorMemory ( ovector & O, word N, word Shift=1 );
00258 extern bool GetVectorMemory ( lvector & L, word N, word Shift=1 );
00259 extern bool GetVectorMemory ( lwvector & L, word N, word Shift=1 );
00260 extern bool GetVectorMemory ( psvector & P, word N, word Shift=1 );
00261
00262
00263
00264
00265
00266
00267 extern void FreeVectorMemory ( rvector & V, word Shift=1 );
00268 extern void FreeVectorMemory ( ivector & I, word Shift=1 );
00269 extern void FreeVectorMemory ( wvector & W, word Shift=1 );
00270 extern void FreeVectorMemory ( bvector & B, word Shift=1 );
00271 extern void FreeVectorMemory ( ovector & O, word Shift=1 );
00272 extern void FreeVectorMemory ( lvector & L, word Shift=1 );
00273 extern void FreeVectorMemory ( lwvector & L, word Shift=1 );
00274 extern void FreeVectorMemory ( psvector & P, word Shift=1 );
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 extern bool GetMatrixMemory
00287 ( rmatrix & A, word N, word M, word ShiftN=1, word ShiftM=1 );
00288 extern bool GetMatrixMemory
00289 ( imatrix & A, word N, word M, word ShiftN=1, word ShiftM=1 );
00290 extern bool GetMatrixMemory
00291 ( wmatrix & W, word N, word M, word ShiftN=1, word ShiftM=1 );
00292 extern bool GetMatrixMemory
00293 ( bmatrix & B, word N, word M, word ShiftN=1, word ShiftM=1 );
00294 extern bool GetMatrixMemory
00295 ( omatrix & O, word N, word M, word ShiftN=1, word ShiftM=1 );
00296 extern bool GetMatrixMemory
00297 ( lmatrix & L, word N, word M, word ShiftN=1, word ShiftM=1 );
00298 extern bool GetMatrixMemory
00299 ( lwmatrix & L, word N, word M, word ShiftN=1, word ShiftM=1 );
00300 extern bool GetMatrixMemory
00301 ( psmatrix & P, word N, word M, word ShiftN=1, word ShiftM=1 );
00302
00303
00304
00305
00306
00307
00308 extern void FreeMatrixMemory ( rmatrix & A, word N,
00309 word ShiftN=1, word ShiftM=1 );
00310 extern void FreeMatrixMemory ( imatrix & A, word N,
00311 word ShiftN=1, word ShiftM=1 );
00312 extern void FreeMatrixMemory ( wmatrix & W, word N,
00313 word ShiftN=1, word ShiftM=1 );
00314 extern void FreeMatrixMemory ( bmatrix & B, word N,
00315 word ShiftN=1, word ShiftM=1 );
00316 extern void FreeMatrixMemory ( omatrix & O, word N,
00317 word ShiftN=1, word ShiftM=1 );
00318 extern void FreeMatrixMemory ( lmatrix & L, word N,
00319 word ShiftN=1, word ShiftM=1 );
00320 extern void FreeMatrixMemory ( lwmatrix & L, word N,
00321 word ShiftN=1, word ShiftM=1 );
00322 extern void FreeMatrixMemory ( psmatrix & P, word N,
00323 word ShiftN=1, word ShiftM=1 );
00324
00325
00326
00327
00328
00329 extern bool GetMatrix3Memory
00330 ( rmatrix3 & A, word N, word M, word K,
00331 word ShiftN=1, word ShiftM=1, word ShiftK=1 );
00332 extern bool GetMatrix3Memory
00333 ( imatrix3 & A, word N, word M, word K,
00334 word ShiftN=1, word ShiftM=1, word ShiftK=1 );
00335 extern bool GetMatrix3Memory
00336 ( wmatrix3 & A, word N, word M, word K,
00337 word ShiftN=1, word ShiftM=1, word ShiftK=1 );
00338 extern bool GetMatrix3Memory
00339 ( bmatrix3 & A, word N, word M, word K,
00340 word ShiftN=1, word ShiftM=1, word ShiftK=1 );
00341 extern bool GetMatrix3Memory
00342 ( omatrix3 & A, word N, word M, word K,
00343 word ShiftN=1, word ShiftM=1, word ShiftK=1 );
00344 extern bool GetMatrix3Memory
00345 ( lmatrix3 & A, word N, word M, word K,
00346 word ShiftN=1, word ShiftM=1, word ShiftK=1 );
00347 extern bool GetMatrix3Memory
00348 ( lwmatrix3 & A, word N, word M, word K,
00349 word ShiftN=1, word ShiftM=1, word ShiftK=1 );
00350 extern bool GetMatrix3Memory
00351 ( psmatrix3 & A, word N, word M, word K,
00352 word ShiftN=1, word ShiftM=1, word ShiftK=1 );
00353
00354
00355
00356
00357
00358
00359
00360 extern void FreeMatrix3Memory
00361 ( rmatrix3 & A, word N, word M,
00362 word ShiftN=1, word ShiftM=1, word ShiftK=1 );
00363 extern void FreeMatrix3Memory
00364 ( imatrix3 & A, word N, word M,
00365 word ShiftN=1, word ShiftM=1, word ShiftK=1 );
00366 extern void FreeMatrix3Memory
00367 ( wmatrix3 & A, word N, word M,
00368 word ShiftN=1, word ShiftM=1, word ShiftK=1 );
00369 extern void FreeMatrix3Memory
00370 ( bmatrix3 & A, word N, word M,
00371 word ShiftN=1, word ShiftM=1, word ShiftK=1 );
00372 extern void FreeMatrix3Memory
00373 ( omatrix3 & A, word N, word M,
00374 word ShiftN=1, word ShiftM=1, word ShiftK=1 );
00375 extern void FreeMatrix3Memory
00376 ( lmatrix3 & A, word N, word M,
00377 word ShiftN=1, word ShiftM=1, word ShiftK=1 );
00378 extern void FreeMatrix3Memory
00379 ( lwmatrix3 & A, word N, word M,
00380 word ShiftN=1, word ShiftM=1, word ShiftK=1 );
00381 extern void FreeMatrix3Memory
00382 ( psmatrix3 & A, word N, word M,
00383 word ShiftN=1, word ShiftM=1, word ShiftK=1 );
00384
00385
00386
00387 extern realtype MachEps;
00388 extern realtype floatMachEps;
00389 extern realtype LnMaxReal;
00390 extern realtype LnMinReal;
00391
00392 extern realtype MachinEps ();
00393 extern realtype floatMachinEps();
00394 extern realtype frac ( realtype R );
00395 extern long mod ( long x, long y );
00396 extern realtype Pow ( realtype X, int y );
00397 extern realtype Pow1 ( realtype X, realtype Y );
00398 extern realtype Exp ( realtype X );
00399 extern bool Odd ( int i );
00400 extern long HexValL ( cpstr S );
00401 extern long OctValL ( cpstr S );
00402 extern long BinValL ( cpstr S );
00403 extern pstr BinValS ( long L, pstr S );
00404
00405 extern pstr ParamStr ( pstr D, cpstr S, realtype V, int M=5,
00406 cpstr S1=(pstr)"" );
00407 extern pstr ParamStr ( pstr D, cpstr S, realtype V, int M,
00408 cpstr S1, realtype V2, int M2=5,
00409 cpstr S2=(pstr)"" );
00410
00411
00412
00413
00414
00415
00416
00417
00418 extern pstr CreateCopy ( pstr & Dest, cpstr Source );
00419 extern pstr CreateCopy_n ( pstr & Dest, cpstr Source, int n );
00420
00421 extern pstr CreateConcat ( pstr & Dest, cpstr Source );
00422 extern pstr CreateConcat ( pstr & Dest, cpstr Source1,
00423 cpstr Source2 );
00424 extern pstr CreateConcat ( pstr & Dest, cpstr Source1,
00425 cpstr Source2,
00426 cpstr Source3 );
00427 extern pstr CreateConcat ( pstr & Dest, cpstr Source1,
00428 cpstr Source2,
00429 cpstr Source3,
00430 cpstr Source4 );
00431 extern pstr CreateConcat ( pstr & Dest, cpstr Source1,
00432 cpstr Source2,
00433 cpstr Source3,
00434 cpstr Source4,
00435 cpstr Source5 );
00436
00437 extern pstr CreateCopCat ( pstr & Dest, cpstr Source1,
00438 cpstr Source2,
00439 cpstr Source3,
00440 cpstr Source4,
00441 cpstr Source5 );
00442 extern pstr CreateCopCat ( pstr & Dest, cpstr Source1,
00443 cpstr Source2,
00444 cpstr Source3,
00445 cpstr Source4 );
00446 extern pstr CreateCopCat ( pstr & Dest, cpstr Source1,
00447 cpstr Source2,
00448 cpstr Source3 );
00449 extern pstr CreateCopCat ( pstr & Dest, cpstr Source1,
00450 cpstr Source2 );
00451
00452 extern pstr LastOccurence ( cpstr S , char c );
00453 extern pstr FirstOccurence ( cpstr S , char c );
00454 extern int indexOf ( cpstr S , char c );
00455 extern pstr FirstOccurence ( cpstr S, int Slen,
00456 cpstr Q, int Qlen );
00457 extern int indexOf ( cpstr S, int Slen,
00458 cpstr Q, int Qlen );
00459
00460 extern pstr LowerCase ( pstr s );
00461 extern pstr UpperCase ( pstr s );
00462
00463
00464
00465
00466 extern void GetString ( pstr L, cpstr S, int M );
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477 extern void GetStrTer ( pstr L, cpstr S, int n, int LMax,
00478 int SMax );
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491 extern void GetStrTerWin32File ( pstr L, cpstr S, int n,
00492 int LMax, int SMax );
00493
00494
00495
00496
00497
00498
00499 extern void strcpy_n ( pstr d, cpstr s, int n );
00500
00501
00502
00503
00504
00505
00506 extern void strcpy_n1 ( pstr d, cpstr s, int n );
00507
00508
00509
00510
00511
00512
00513 extern void strcpy_nr ( pstr d, cpstr s, int n );
00514
00515
00516
00517
00518
00519
00520 extern void strcpy_ns ( pstr d, cpstr s, int n );
00521
00522
00523
00524
00525
00526 extern pstr strcpy_cs ( pstr d, cpstr s );
00527
00528
00529
00530
00531
00532
00533 extern pstr strcpy_ncs ( pstr d, cpstr s, int n );
00534
00535
00536
00537
00538
00539 extern pstr strcpy_css ( pstr d, cpstr s );
00540
00541
00542
00543
00544
00545
00546 extern pstr strcpy_ncss ( pstr d, cpstr s, int n );
00547
00548
00549
00550
00551
00552 extern pstr strcpy_n0 ( pstr d, cpstr s, int n );
00553
00554
00555
00556
00557
00558 extern int strlen_des ( cpstr s );
00559
00560
00561
00562
00563 extern pstr strcpy_des ( pstr d, cpstr s );
00564
00565
00566
00567
00568 extern pstr strcat_des ( pstr d, cpstr s );
00569
00570
00571
00572
00573 extern void PadSpaces ( pstr S, int len );
00574
00575 enum SCUTKEY {
00576 SCUTKEY_BEGIN = 0x00000001,
00577 SCUTKEY_END = 0x00000002,
00578 SCUTKEY_BEGEND = 0x00000003
00579 };
00580
00581
00582
00583
00584 extern pstr CutSpaces ( pstr S, int CutKey );
00585
00586
00587
00588
00589
00590 extern pstr DelSpaces ( pstr S, char c=' ' );
00591
00592
00593
00594 extern pstr EnforceSpaces ( pstr S );
00595
00596
00597
00604 extern void set_new_float_unibin();
00605 extern bool is_new_float_unibin();
00606 extern void set_old_float_unibin();
00607
00608 extern void __modify4();
00609
00610 extern void int2UniBin ( int I, intUniBin iUB );
00611 extern void short2UniBin ( short S, shortUniBin sUB );
00612 extern void long2UniBin ( long L, longUniBin lUB );
00613 extern void word2UniBin ( word W, wordUniBin wUB );
00614 extern void real2UniBin ( realtype R, realUniBin rUB );
00615 extern void float2UniBin ( realtype R, floatUniBin fUB );
00616 extern void shortreal2UniBin ( shortreal R, shortrealUniBin srUB );
00617 extern void UniBin2int ( intUniBin iUB, int & I );
00618 extern void UniBin2short ( shortUniBin sUB, short & S );
00619 extern void UniBin2long ( longUniBin lUB, long & L );
00620 extern void UniBin2word ( wordUniBin wUB, word & W );
00621 extern void UniBin2real ( realUniBin rUB, realtype & R );
00622 extern void UniBin2shortreal ( shortrealUniBin srUB, shortreal & R );
00623 extern void UniBin2float ( floatUniBin fUB, realtype & R );
00624
00625 extern void mem_write ( int I, pstr S, int & l );
00626 extern void mem_write ( short I, pstr S, int & l );
00627 extern void mem_write ( long I, pstr S, int & l );
00628 extern void mem_write ( word W, pstr S, int & l );
00629 extern void mem_write ( realtype R, pstr S, int & l );
00630 extern void mem_write ( shortreal R, pstr S, int & l );
00631 extern void mem_write ( pstr L, int len, pstr S, int & l );
00632 extern void mem_write ( pstr L, pstr S, int & l );
00633 extern void mem_write ( bool B, pstr S, int & l );
00634 extern void mem_write_byte ( byte B, pstr S, int & l );
00635
00636 extern void mem_read ( int & I, cpstr S, int & l );
00637 extern void mem_read ( short & I, cpstr S, int & l );
00638 extern void mem_read ( long & I, cpstr S, int & l );
00639 extern void mem_read ( word & W, cpstr S, int & l );
00640 extern void mem_read ( realtype & R, cpstr S, int & l );
00641 extern void mem_read ( shortreal & R, cpstr S, int & l );
00642 extern void mem_read ( pstr L, int len, cpstr S, int & l );
00643 extern void mem_read ( pstr & L, cpstr S, int & l );
00644 extern void mem_read ( bool & B, cpstr S, int & l );
00645 extern void mem_read_byte ( byte & B, cpstr S, int & l );
00646
00647 }
00648
00649 #endif
00650
00651
00652