1 //  $Id: mmdb_mattype.h $
2 //  =================================================================
3 //
4 //   CCP4 Coordinate Library: support of coordinate-related
5 //   functionality in protein crystallography applications.
6 //
7 //   Copyright (C) Eugene Krissinel 2000-2008.
8 //
9 //    This library is free software: you can redistribute it and/or
10 //    modify it under the terms of the GNU Lesser General Public
11 //    License version 3, modified in accordance with the provisions
12 //    of the license to address the requirements of UK law.
13 //
14 //    You should have received a copy of the modified GNU Lesser
15 //    General Public License along with this library. If not, copies
16 //    may be downloaded from http://www.ccp4.ac.uk/ccp4license.php
17 //
18 //    This program is distributed in the hope that it will be useful,
19 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
20 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 //    GNU Lesser General Public License for more details.
22 //
23 //  =================================================================
24 //
25 //    10.09.13   <--  Date of Last Modification.
26 //                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 //  -----------------------------------------------------------------
28 //
29 //  **** Module  :  MatType_ <interface>
30 //       ~~~~~~~~~
31 //  **** Functions :
32 //       ~~~~~~~~~~~
33 //               GetString  ( reads substring from a string         )
34 //               GetStrTer  ( reads substring and put term-ing null )
35 //               strcpy_n   ( copies not more than n characters     )
36 //               strcpy_ns  ( like strcpy_ns and pads with spaces   )
37 //               strcpy_n0  ( like strcpy_n and adds terminating 0  )
38 //               PadSpaces  ( pads a string with spaces             )
39 //
40 //  (C) E. Krissinel 2000-2013
41 //
42 //  =================================================================
43 //
44 
45 
46 #ifndef  __MMDB_MatType__
47 #define  __MMDB_MatType__
48 
49 #include <math.h>
50 
51 #define  UseDoubleFloat
52 
53 #ifndef __ClassMacros
54 
55 # define __ClassMacros
56 
57  //  A Class definition macros
58 # define DefineClass(ClassName)             \
59    class ClassName;                         \
60    typedef ClassName    * P##ClassName;     \
61    typedef ClassName    & R##ClassName;     \
62    typedef P##ClassName * PP##ClassName;    \
63    typedef P##ClassName & RP##ClassName;
64 
65  //  A Structure definition macros
66 # define DefineStructure(StructureName)             \
67    struct StructureName;                            \
68    typedef StructureName    * P##StructureName;     \
69    typedef StructureName    & R##StructureName;     \
70    typedef P##StructureName * PP##StructureName;    \
71    typedef P##StructureName & RP##StructureName;
72 
73 #endif
74 
75 #define UNUSED_ARGUMENT(x) (void)x
76 
77 // -----------------------------------------------------
78 
79 namespace mmdb  {
80 
81 #ifdef  UseDoubleFloat
82 
83   typedef  double       realtype;
84   const realtype MinReal  = 2.2250e-307;
85   const realtype MaxReal  = 1.7976e+308;
86   const realtype fMinReal = 2.2250e-307;
87   const realtype fMaxReal = 1.7976e+308;
88 
89 #else
90 
91   typedef  float       realtype;
92   const realtype MinReal  = 1.1755e-38;
93   const realtype MaxReal  = 3.4020e+38;
94   const realtype fMinReal = 1.1755e-38;
95   const realtype fMaxReal = 3.4020e+38;
96 
97 #endif
98 
99   typedef   float     shortreal;
100   const shortreal MinShortReal = 1.1755e-38;
101   const shortreal MaxShortReal = 3.4020e+38;
102 
103 /*
104 #define   strrchr   LastOccurence
105 #define   fstrrchr  LastOccurence
106 #define   strchr    FirstOccurence
107 #define   fstrchr   FirstOccurence
108 */
109 
110   typedef   char     *         pstr;
111   typedef   const char *       cpstr;
112   typedef   unsigned int       word;
113   typedef   unsigned char      byte;
114   typedef   signed   char      short_int;
115 //  typedef   byte               Boolean;
116   typedef   unsigned int       word2;
117   typedef   byte *             byteptr;
118   typedef   unsigned long      lword;
119 
120   typedef   byte intUniBin      [4];
121   typedef   byte shortUniBin    [2];
122   typedef   byte longUniBin     [4];
123   typedef   byte wordUniBin     [4];
124   typedef   byte realUniBin     [10];
125   typedef   byte floatUniBin    [5];
126   typedef   byte shortrealUniBin[5];
127 
128 #ifdef _WIN32
129   pstr strcasestr ( pstr s1, cpstr s2 );
130 #endif
131 
132 #ifdef _MSC_VER
133 #define   strncasecmp _strnicmp
134 #define   strcasecmp  _stricmp
135 #endif
136 
137   const int      MaxInt  =  32767;
138   const int      MinInt  = -32768;
139   const word     MaxWord =  65535L;
140   const long int MaxInt4 =  2147483647L;
141 
142   //    MinInt4 would have to be defined as  -2147483648,
143   // however some compilers do not like that. To be on safe,
144   // we define it as -2147483647:
145   const long int MinInt4  = -2147483647;
146   const lword    MaxWord4 =  4294967295UL;
147 
148   const realtype Pi   = 3.141592653589793238462643;
149   const realtype Eu   = 2.718281828459045235360287;
150   const realtype ln10 = 2.3025850929940456840179915;
151 
152   // ***  vectors   X[1..N] :
153   typedef   realtype * rvector;
154   typedef   int      * ivector;
155   typedef   word     * wvector;
156   typedef   byte     * bvector;
157   typedef   bool     * ovector;
158   typedef   long     * lvector;
159   typedef   lword    * lwvector;
160   typedef   pstr     * psvector;
161 
162   // ***  matrices   X[1..N][1..M] :
163   typedef   rvector  * rmatrix;
164   typedef   ivector  * imatrix;
165   typedef   wvector  * wmatrix;
166   typedef   bvector  * bmatrix;
167   typedef   ovector  * omatrix;
168   typedef   lvector  * lmatrix;
169   typedef   lwvector * lwmatrix;
170   typedef   psvector * psmatrix;
171 
172   // ***  matrices   X[1..N][1..M][1..K] :
173   typedef   rmatrix  * rmatrix3;
174   typedef   imatrix  * imatrix3;
175   typedef   wmatrix  * wmatrix3;
176   typedef   bmatrix  * bmatrix3;
177   typedef   omatrix  * omatrix3;
178   typedef   lmatrix  * lmatrix3;
179   typedef   lwmatrix * lwmatrix3;
180   typedef   psmatrix * psmatrix3;
181 
182 
183   // ------------------------------------------------------------
184 
185   //  Initialization. Some C++ enviroments do not do call
186   // InitMatType() automatically, therefore it is always
187   // advisable to call InitMatType() explicitely from the top of
188   // main(). It is completely harmless and cheap (although
189   // unnecessary) to call InitMatType() multiple times.
190   extern bool InitMatType();
191 
192   // ------------------------------------------------------------
193 
mround(realtype X)194   inline int mround ( realtype X )  { return (int)floor(X+0.5);   }
ifloor(realtype X)195   inline int ifloor ( realtype X )  { return (int)floor(X);       }
Abs(int x)196   inline int Abs    ( int x )       { return ( x >= 0 ? x : -x ); }
197 
ISwap(int & x,int & y)198   inline void ISwap ( int & x, int & y )
199   { int  b = x;  x = y;  y = b; }
200 
WSwap(word & x,word & y)201   inline void WSwap ( word & x, word & y )
202   { word  b = x;  x = y;  y = b; }
203 
BSwap(byte & x,byte & y)204   inline void BSwap ( byte & x, byte & y )
205   { byte b = x;  x = y;  y = b; }
206 
OSwap(bool & x,bool & y)207   inline void OSwap ( bool & x, bool & y )
208   { bool b = x;  x = y;  y = b; }
209 
LSwap(long & x,long & y)210   inline void LSwap ( long & x, long & y )
211   { long b = x;  x = y;  y = b; }
212 
RSwap(realtype & x,realtype & y)213   inline void RSwap ( realtype & x, realtype & y )
214   { realtype b = x;  x = y;  y = b; }
215 
RMax(const realtype x1,const realtype x2)216   inline realtype RMax ( const realtype x1, const realtype x2 )
217   { return ( x1 > x2 ? x1 : x2 );  }
218 
LMax(const long x1,const long x2)219   inline long LMax ( const long x1, const long x2 )
220   { return ( x1 > x2 ? x1 : x2 );  }
221 
WMax(const word x1,const word x2)222   inline word WMax ( const word x1, const word x2 )
223   { return ( x1 > x2 ? x1 : x2 );  }
224 
IMax(const int x1,const int x2)225   inline int IMax ( const int x1,  const int x2  )
226   { return ( x1 > x2 ? x1 : x2 );  }
227 
RMin(const realtype x1,const realtype x2)228   inline realtype RMin ( const realtype x1, const realtype x2 )
229   { return ( x1 < x2 ? x1 : x2 );  }
230 
LMin(const long x1,const long x2)231   inline long LMin ( const long x1, const long x2 )
232   { return ( x1 < x2 ? x1 : x2 );  }
233 
WMin(const word x1,const word x2)234   inline word WMin ( const word x1, const word x2 )
235   { return ( x1 < x2 ? x1 : x2 );  }
236 
IMin(const int x1,const int x2)237   inline int  IMin ( const int x1,  const int x2  )
238   { return ( x1 < x2 ? x1 : x2 );  }
239 
fsign(const realtype x1,const realtype x2)240   inline realtype fsign ( const realtype x1,  const realtype x2 )  {
241   realtype  ax;
242     if (x1>=0.0)  ax = x1;
243             else  ax = -x1;
244     return ( x2 >= 0.0 ? ax : -ax );
245   }
246 
247 
248   // ------------------------------------------------------------
249 
250   //    Allocated vectors are enumerated as [Shift..Shift+N-1]
251   //  rather than [0..N-1] !
252   //    Get-functions return  <true>  if memory was allocated;
253   //  if allocation attemt fails,  vector is assigned with  NULL
254 
255   extern bool GetVectorMemory ( rvector  & V, word N, word Shift=1 );
256   extern bool GetVectorMemory ( ivector  & I, word N, word Shift=1 );
257   extern bool GetVectorMemory ( wvector  & W, word N, word Shift=1 );
258   extern bool GetVectorMemory ( bvector  & B, word N, word Shift=1 );
259   extern bool GetVectorMemory ( ovector  & O, word N, word Shift=1 );
260   extern bool GetVectorMemory ( lvector  & L, word N, word Shift=1 );
261   extern bool GetVectorMemory ( lwvector & L, word N, word Shift=1 );
262   extern bool GetVectorMemory ( psvector & P, word N, word Shift=1 );
263 
264   //    Shift at deallocation MUST be the same as that at allocation !
265   //   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
266   //    Free-functions do nothing if vector has value  NULL (e.g.
267   //  after unsuccessful allocation).
268 
269   extern void FreeVectorMemory ( rvector  & V, word Shift=1 );
270   extern void FreeVectorMemory ( ivector  & I, word Shift=1 );
271   extern void FreeVectorMemory ( wvector  & W, word Shift=1 );
272   extern void FreeVectorMemory ( bvector  & B, word Shift=1 );
273   extern void FreeVectorMemory ( ovector  & O, word Shift=1 );
274   extern void FreeVectorMemory ( lvector  & L, word Shift=1 );
275   extern void FreeVectorMemory ( lwvector & L, word Shift=1 );
276   extern void FreeVectorMemory ( psvector & P, word Shift=1 );
277 
278   // -------------------------------------------------------------
279 
280   //    Allocated matrices are enumerated as
281   //          [ShiftN..ShiftN+N-1, ShiftM..ShiftM+M-1]
282   //  rather than [0..N-1,0..M-1] !
283   //    Get-functions return  <true>  if memory was allocated;
284   //  if allocation attemt fails,  matrix is assigned with  NULL
285   //    Free-functions do nothing if matrix has value  NULL (e.g.
286   //  after unsuccessful allocation).
287 
288   extern bool GetMatrixMemory
289        ( rmatrix  & A, word N, word M, word ShiftN=1, word ShiftM=1 );
290   extern bool GetMatrixMemory
291        ( imatrix  & A, word N, word M, word ShiftN=1, word ShiftM=1 );
292   extern bool GetMatrixMemory
293        ( wmatrix  & W, word N, word M, word ShiftN=1, word ShiftM=1 );
294   extern bool GetMatrixMemory
295        ( bmatrix  & B, word N, word M, word ShiftN=1, word ShiftM=1 );
296   extern bool GetMatrixMemory
297        ( omatrix  & O, word N, word M, word ShiftN=1, word ShiftM=1 );
298   extern bool GetMatrixMemory
299        ( lmatrix  & L, word N, word M, word ShiftN=1, word ShiftM=1 );
300   extern bool GetMatrixMemory
301        ( lwmatrix & L, word N, word M, word ShiftN=1, word ShiftM=1 );
302   extern bool GetMatrixMemory
303        ( psmatrix & P, word N, word M, word ShiftN=1, word ShiftM=1 );
304 
305   //    ShiftN and ShiftM at deallocation MUST be the same as those at
306   //   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
307   //                          allocation !
308   //                         ~~~~~~~~~~~~~
309 
310   extern  void FreeMatrixMemory  ( rmatrix  & A,  word N,
311                    word ShiftN=1, word ShiftM=1 );
312   extern  void FreeMatrixMemory  ( imatrix  & A,  word N,
313                    word ShiftN=1, word ShiftM=1 );
314   extern  void FreeMatrixMemory  ( wmatrix  & W,  word N,
315                    word ShiftN=1, word ShiftM=1 );
316   extern  void FreeMatrixMemory  ( bmatrix  & B,  word N,
317                    word ShiftN=1, word ShiftM=1 );
318   extern  void FreeMatrixMemory  ( omatrix  & O,  word N,
319                    word ShiftN=1, word ShiftM=1 );
320   extern  void FreeMatrixMemory  ( lmatrix  & L,  word N,
321                    word ShiftN=1, word ShiftM=1 );
322   extern  void FreeMatrixMemory  ( lwmatrix & L,  word N,
323                    word ShiftN=1, word ShiftM=1 );
324   extern  void FreeMatrixMemory  ( psmatrix & P,  word N,
325                    word ShiftN=1, word ShiftM=1 );
326 
327 
328   // -------------------------------------------------------------
329   //   3D matrices
330 
331   extern bool GetMatrix3Memory
332              ( rmatrix3  & A, word N, word M, word K,
333                    word ShiftN=1, word ShiftM=1, word ShiftK=1 );
334   extern bool GetMatrix3Memory
335              ( imatrix3  & A, word N, word M, word K,
336                    word ShiftN=1, word ShiftM=1, word ShiftK=1 );
337   extern bool GetMatrix3Memory
338              ( wmatrix3  & A, word N, word M, word K,
339                    word ShiftN=1, word ShiftM=1, word ShiftK=1 );
340   extern bool GetMatrix3Memory
341              ( bmatrix3  & A, word N, word M, word K,
342                    word ShiftN=1, word ShiftM=1, word ShiftK=1 );
343   extern bool GetMatrix3Memory
344              ( omatrix3  & A, word N, word M, word K,
345                    word ShiftN=1, word ShiftM=1, word ShiftK=1 );
346   extern bool GetMatrix3Memory
347              ( lmatrix3  & A, word N, word M, word K,
348                    word ShiftN=1, word ShiftM=1, word ShiftK=1 );
349   extern bool GetMatrix3Memory
350              ( lwmatrix3 & A, word N, word M, word K,
351                    word ShiftN=1, word ShiftM=1, word ShiftK=1 );
352   extern bool GetMatrix3Memory
353              ( psmatrix3 & A, word N, word M, word K,
354                    word ShiftN=1, word ShiftM=1, word ShiftK=1 );
355 
356   //
357   //    ShiftN, ShiftM and ShiftK at deallocation MUST be
358   //   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
359   //         the same as those at allocation !
360   //        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
361 
362   extern void FreeMatrix3Memory
363                  ( rmatrix3  & A, word N, word M,
364                    word ShiftN=1, word ShiftM=1, word ShiftK=1 );
365   extern void FreeMatrix3Memory
366                  ( imatrix3  & A, word N, word M,
367                    word ShiftN=1, word ShiftM=1, word ShiftK=1 );
368   extern void FreeMatrix3Memory
369                  ( wmatrix3  & A, word N, word M,
370                    word ShiftN=1, word ShiftM=1, word ShiftK=1 );
371   extern void FreeMatrix3Memory
372                  ( bmatrix3  & A, word N, word M,
373                    word ShiftN=1, word ShiftM=1, word ShiftK=1 );
374   extern void FreeMatrix3Memory
375                  ( omatrix3  & A, word N, word M,
376                    word ShiftN=1, word ShiftM=1, word ShiftK=1 );
377   extern void FreeMatrix3Memory
378                  ( lmatrix3  & A, word N, word M,
379                    word ShiftN=1, word ShiftM=1, word ShiftK=1 );
380   extern void FreeMatrix3Memory
381                  ( lwmatrix3 & A, word N, word M,
382                    word ShiftN=1, word ShiftM=1, word ShiftK=1 );
383   extern void FreeMatrix3Memory
384                  ( psmatrix3 & A, word N, word M,
385                    word ShiftN=1, word ShiftM=1, word ShiftK=1 );
386 
387   // -------------------------------------------------------------
388 
389   extern  realtype  MachEps;
390   extern  realtype  floatMachEps;
391   extern  realtype  LnMaxReal;
392   extern  realtype  LnMinReal;
393 
394   extern  realtype  MachinEps     ();
395   extern  realtype  floatMachinEps();
396   extern  realtype  frac  ( realtype R   );
397   extern  long      mod   ( long     x, long     y );
398   extern  realtype  Pow   ( realtype X, int      y );
399   extern  realtype  Pow1  ( realtype X, realtype Y );
400   extern  realtype  Exp   ( realtype X );   // use to avoid catastrophies
401   extern  bool      Odd   ( int      i );
402   extern  long    HexValL ( cpstr S );
403   extern  long    OctValL ( cpstr S );
404   extern  long    BinValL ( cpstr S );
405   extern  pstr    BinValS ( long L, pstr S  );  // S[sizeof(long)+1] at least
406 
407   extern  pstr ParamStr ( pstr D, cpstr S, realtype V, int M=5,
408                           cpstr S1=(pstr)"" );
409   extern  pstr ParamStr ( pstr D, cpstr S, realtype V, int M,
410                           cpstr S1, realtype V2, int M2=5,
411                           cpstr S2=(pstr)"" );
412 
413 
414   //  ----------  Strings
415 
416   //   CreateCopy(..) allocates Dest string and copies the contents of
417   // Source into it. If Dest is not NULL prior calling the function,
418   // it is attempted to deallocate first.
419 
420   extern pstr CreateCopy     ( pstr & Dest, cpstr Source );
421   extern pstr CreateCopy_n   ( pstr & Dest, cpstr Source, int n );
422 
423   extern pstr CreateConcat   ( pstr & Dest, cpstr Source );
424   extern pstr CreateConcat   ( pstr & Dest, cpstr Source1,
425                                           cpstr Source2 );
426   extern pstr CreateConcat   ( pstr & Dest, cpstr Source1,
427                                             cpstr Source2,
428                                             cpstr Source3 );
429   extern pstr CreateConcat   ( pstr & Dest, cpstr Source1,
430                                             cpstr Source2,
431                                             cpstr Source3,
432                                             cpstr Source4 );
433   extern pstr CreateConcat   ( pstr & Dest, cpstr Source1,
434                                             cpstr Source2,
435                                             cpstr Source3,
436                                             cpstr Source4,
437                                             cpstr Source5 );
438 
439   extern pstr CreateCopCat   ( pstr & Dest, cpstr Source1,
440                                             cpstr Source2,
441                                             cpstr Source3,
442                                             cpstr Source4,
443                                             cpstr Source5 );
444   extern pstr CreateCopCat   ( pstr & Dest, cpstr Source1,
445                                             cpstr Source2,
446                                             cpstr Source3,
447                                             cpstr Source4 );
448   extern pstr CreateCopCat   ( pstr & Dest, cpstr Source1,
449                                             cpstr Source2,
450                                             cpstr Source3 );
451   extern pstr CreateCopCat   ( pstr & Dest, cpstr Source1,
452                                             cpstr Source2 );
453 
454   extern pstr LastOccurence  ( cpstr S     , char c      );
455   extern pstr FirstOccurence ( cpstr S     , char c      );
456   extern int  indexOf        ( cpstr S     , char c      );
457   extern pstr FirstOccurence ( cpstr S, int Slen,
458                                cpstr Q, int Qlen );
459   extern int  indexOf        ( cpstr S, int Slen,
460                                cpstr Q, int Qlen );
461 
462   extern pstr LowerCase ( pstr s );
463   extern pstr UpperCase ( pstr s );
464 
465   //   GetString(..) copies first M characters of string S into string
466   // L, appending the terminating null. If S contains less then M
467   // characters, L will be padded with spaces.
468   extern void GetString ( pstr L, cpstr S, int M );
469 
470   //   GetStrTer(..) copies at least n (or LMax if LMax<n) first symbols
471   // of string S into string L, then continues copying until first space
472   // or terminating null is found. If the terminating null is met among
473   // the first n characters or if SMax<n, the string L will be padded
474   // with spaces till the length of minimum of n and LMax and then
475   // terminated with the null.
476   //   LMax and SMax are the buffer lengths of L and S,
477   // respectively. Even if no space is found, the last character
478   // in L will be the terminating null.
479   extern void GetStrTer ( pstr L, cpstr S, int n, int LMax,
480                           int SMax );
481 
482 
483   // Version of GetStrTer(..) allowing for spaces in the string.
484   //
485   //   Copies at least n (or LMax if LMax<n) first symbols of
486   // string S into string L, then continues copying until first
487   // terminating null is found. If the terminating null
488   // is met among the first n characters or if SMax<n, the string
489   // L will be padded with spaces till the length of minimum of
490   // n and LMax and then terminated with the null.
491   //   SMax are buffer lengths of L and S, respectively. The last
492   // character in L will be the terminating null.
493   extern void GetStrTerWin32File ( pstr L, cpstr S, int n,
494                                    int LMax, int SMax );
495 
496 
497   //   strcpy_n(..) copies at most n symbols from string s to d,
498   // but no more than strlen(s) (s must contain a terminating
499   // null). The terminating null IS NEITHER appended OR copied
500   // to d.
501   extern void strcpy_n  ( pstr d, cpstr s, int n );
502 
503   //   strcpy_n1(..) copies at most n last symbols from string s
504   // to d, but no more than strlen(s) (s must contain a terminating
505   // null). The string in d is aligned to the right and added with
506   // spaces at the left, if necessary. The terminating null
507   // IS NEITHER appended OR copied to d.
508   extern void strcpy_n1 ( pstr d, cpstr s, int n );
509 
510   //   Copies at most n symbols from string s to d, but no
511   // more than strlen(s) (s must contain a terminating null).
512   // The string in d is aligned to the right and added with
513   // spaces at the left, if necessary. The terminating null
514   // IS NEITHER appended NOR copied to d.
515   extern void strcpy_nr ( pstr d, cpstr s, int n );
516 
517   //   strcpy_ns(..) copies at most n symbols from string s to d,
518   // but no more than strlen(s) (s must contain a terminating
519   // null). The terminating null IS NEITHER appended NOR copied
520   // to d; rather, d is padded with spaces up to the length of n
521   // if strlen(s)<n.
522   extern void strcpy_ns ( pstr d, cpstr s, int n );
523 
524   //   strcpy_cs(..) copies string s to string d cutting all
525   // spaces at the end. Thus, " abcde   " will be copied
526   // like " abcde" (terminating null appended).
527   //   The function returns d.
528   extern pstr strcpy_cs ( pstr d, cpstr s );
529 
530   //   strcpy_ncs(..) copies at most n characters from string s
531   // to string d cutting all spaces at at the end. Thus, " abcde   "
532   // will be copied like " abc" at n=4 and like " abcde" at n>5
533   // (terminating null appended).
534   //   The function returns d.
535   extern pstr strcpy_ncs ( pstr d, cpstr s, int n );
536 
537   //   strcpy_css(..) copies string s to string d cutting all
538   // spaces at the begining and at the end. Thus, " ab c de  "
539   // will be copied like "ab c de" (terminating null appended).
540   //   The function returns d.
541   extern pstr strcpy_css ( pstr d, cpstr s );
542 
543   //   strcpy_ncss(..) copies at most n characters from string s
544   // to string d cutting all spaces at the begining and at the end.
545   // Thus, " ab c de  " will be copied like "ab" at n=3 (terminating
546   // null appended).
547   //   The function returns d.
548   extern pstr strcpy_ncss ( pstr d, cpstr s, int n );
549 
550   //   strcpy_n0(..) copies at most n symbols from string s to d,
551   // but no more than strlen(s) (s must contain a terminating
552   // null). The terminating null IS appended to d.
553   //   The function returns d.
554   extern pstr strcpy_n0 ( pstr d, cpstr s, int n );
555 
556   //   strlen_des returns the length of a string as if all extra
557   // spaces from the latter have been deleted. Extra spaces
558   // include all leading and tracing spaces and any sequential
559   // spaces when more than one. The string does not change.
560   extern int strlen_des ( cpstr s );
561 
562   //   strcpy_des copies string s into string d removing all extra
563   // spaces from the latter. Extra spaces include all leading and
564   // tracing spaces and any sequential spaces when more than one.
565   extern pstr strcpy_des ( pstr d, cpstr s );
566 
567   //   strcat_des appends string s to string d removing all extra
568   // spaces from the latter. Extra spaces include all leading and
569   // tracing spaces and any sequential spaces when more than one.
570   extern pstr strcat_des ( pstr d, cpstr s );
571 
572   //  PadSpaces(..) pads string S with spaces making its length
573   // equal to len. The terminating zero is added, so that S should
574   // reserve space of a minimum len+1 characters.
575   extern void PadSpaces ( pstr S, int len );
576 
577   enum SCUTKEY  {
578     SCUTKEY_BEGIN  = 0x00000001,
579     SCUTKEY_END    = 0x00000002,
580     SCUTKEY_BEGEND = 0x00000003
581   };
582 
583   //   CutSpaces(..) cuts spaces at the begining or end of
584   // string S according to the value of CutKey. The function
585   // returns S.
586   extern pstr CutSpaces ( pstr S, int CutKey );
587 
588   //   DelSpaces(..) removes all spaces (or other symbols as
589   // specified by 'c') from the string. The string is then
590   // shrinked by the number of removed characters. Thus,
591   // " as ttt  " becomes "asttt".
592   extern pstr DelSpaces ( pstr S, char c=' ' );
593 
594   //   EnforceSpaces(..) replaces all unprintable characters,
595   // except <CR>, <LF>, <TAB> and some others, for spaces
596   extern pstr EnforceSpaces ( pstr S );
597 
598   // -------------------------------------------------------------
599 
600   ///   This call will produce correct floats in universal binaries but
601   /// make them incompatible with old files. Without this call, float
602   /// read/write will result in error after 6th digit.
603   ///   UniBin read/write of other types (realtype, shortreal, int etc)
604   /// is not affected by this call, and to the best of knowledge is
605   /// correct (no loss of precision).
606   extern void  set_new_float_unibin();
607   extern bool  is_new_float_unibin();
608   extern void  set_old_float_unibin();
609 
610   extern void __modify4();
611 
612   extern void int2UniBin       ( int       I,  intUniBin        iUB  );
613   extern void short2UniBin     ( short     S,  shortUniBin      sUB  );
614   extern void long2UniBin      ( long      L,  longUniBin       lUB  );
615   extern void word2UniBin      ( word      W,  wordUniBin       wUB  );
616   extern void real2UniBin      ( realtype  R,  realUniBin       rUB  );
617   extern void float2UniBin     ( realtype  R,  floatUniBin      fUB  );
618   extern void shortreal2UniBin ( shortreal R,  shortrealUniBin  srUB );
619   extern void UniBin2int       ( intUniBin        iUB, int       & I );
620   extern void UniBin2short     ( shortUniBin      sUB, short     & S );
621   extern void UniBin2long      ( longUniBin       lUB, long      & L );
622   extern void UniBin2word      ( wordUniBin       wUB, word      & W );
623   extern void UniBin2real      ( realUniBin       rUB, realtype  & R );
624   extern void UniBin2shortreal ( shortrealUniBin srUB, shortreal & R );
625   extern void UniBin2float     ( floatUniBin      fUB, realtype  & R );
626 
627   extern void mem_write ( int       I, pstr S, int & l );
628   extern void mem_write ( short     I, pstr S, int & l );
629   extern void mem_write ( long      I, pstr S, int & l );
630   extern void mem_write ( word      W, pstr S, int & l );
631   extern void mem_write ( realtype  R, pstr S, int & l );
632   extern void mem_write ( shortreal R, pstr S, int & l );
633   extern void mem_write ( pstr      L, int len, pstr S, int & l );
634   extern void mem_write ( pstr      L, pstr S, int & l );
635   extern void mem_write ( bool      B, pstr S, int & l );
636   extern void mem_write_byte ( byte B, pstr S, int & l );
637 
638   extern void mem_read  ( int       & I, cpstr S, int & l );
639   extern void mem_read  ( short     & I, cpstr S, int & l );
640   extern void mem_read  ( long      & I, cpstr S, int & l );
641   extern void mem_read  ( word      & W, cpstr S, int & l );
642   extern void mem_read  ( realtype  & R, cpstr S, int & l );
643   extern void mem_read  ( shortreal & R, cpstr S, int & l );
644   extern void mem_read  ( pstr        L, int len, cpstr S, int & l );
645   extern void mem_read  ( pstr      & L, cpstr S, int & l );
646   extern void mem_read  ( bool      & B, cpstr S, int & l );
647   extern void mem_read_byte ( byte  & B, cpstr S, int & l );
648 
649 }
650 
651 #endif
652 
653 /* ===================================================  */
654 
655