misc.h
Go to the documentation of this file.
1 /*
2  -------------------------------------------------------------------
3 
4  Copyright (C) 2006-2020, Andrew W. Steiner
5 
6  This file is part of O2scl.
7 
8  O2scl is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  O2scl is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with O2scl. If not, see <http://www.gnu.org/licenses/>.
20 
21  -------------------------------------------------------------------
22 */
23 #ifndef O2SCL_MISC_H
24 #define O2SCL_MISC_H
25 /** \file misc.h
26  \brief Miscellaneous functions
27 */
28 
29 #include <cstdlib>
30 #include <iostream>
31 #include <string>
32 // For stringstream for count_words()
33 #include <sstream>
34 #include <vector>
35 // For std::isinf and std::isnan in C++11
36 #include <cmath>
37 // For the vec_index class below
38 #include <map>
39 #include <initializer_list>
40 
41 #ifdef O2SCL_LD_TYPES
42 #include <boost/multiprecision/cpp_dec_float.hpp>
43 #endif
44 
45 #include <o2scl/err_hnd.h>
46 
47 extern "C" {
48  int o2scl_python_test(int x);
49 }
50 
51 #ifndef DOXYGEN_NO_O2NS
52 namespace o2scl {
53 #endif
54 
55  /*
56  AWS 10/10/19: A new abs() function is probably overkill, but I am
57  concerned that a user who includes math.h before an o2scl header
58  file might get the wrong abs() function. (see
59  https://stackoverflow.com/questions/21392627/
60  abs-vs-stdabs-what-does-the-reference-say ). The usual recommendation
61  is just to use std::abs, but I have had problems with that working
62  on Ubuntu.
63  */
64 
65  /// \name New abs() function
66  //@{
67  /** \brief Absolute value for single precision numbers
68  */
69  float o2abs(const float x);
70 
71  /** \brief Absolute value for double precision numbers
72  */
73  double o2abs(const double x);
74 
75  /** \brief Absolute value for long double
76  */
77  long double o2abs(const long double x);
78 
79 #if defined(O2SCL_LD_TYPES) || defined(DOXYGEN)
80 
81  /** \brief Absolute value for cpp_dec_float_50
82  */
83  boost::multiprecision::cpp_dec_float_50
84  o2abs(const boost::multiprecision::cpp_dec_float_50 x);
85 
86 #endif
87 
88  /** \brief Compatbility function for isfinite()
89 
90  AWS, 11/11/19: Older compilers seem to require std::isfinite(),
91  but then this causes problems making generic code which can use
92  boost multiprecision arithmetic, so this function attempts
93  to solve those problems.
94  */
95  bool o2isfinite(const double x);
96 
97 #if defined(O2SCL_LD_TYPES) || defined(DOXYGEN)
98 
99  /** \brief Compatbility function for isfinite()
100  */
101  bool o2isfinite(const boost::multiprecision::cpp_dec_float_50 x);
102 
103 #endif
104 
105  //@}
106 
107  /// \name Functions from src/base/misc.h
108  //@{
109  /** \brief Calculate a Fermi-Dirac distribution function safely
110 
111  \f$ \left[1+\exp\left(E/T-\mu/T\right)\right]^{-1} \f$
112 
113  This calculates a Fermi-Dirac distribution function guaranteeing
114  that numbers larger than \f$ \exp(\mathrm{limit}) \f$ and
115  smaller than \f$ \exp(-\mathrm{limit}) \f$ will be avoided. The
116  default value of <tt>limit=40</tt> ensures accuracy to within 1
117  part in \f$ 10^{17} \f$ compared to the maximum of the
118  distribution (which is unity).
119 
120  Note that this function may return Inf or NAN if \c limit is too
121  large, depending on the machine precision.
122  */
123  double fermi_function(double E, double mu, double T, double limit=40.0);
124 
125  /** \brief Calculate a Bose-Einstein distribution function safely
126 
127  \f$ \left[\exp\left(E/T-\mu/T\right)-1\right]^{-1} \f$
128 
129  This function computes a Bose-Einstein distribution function
130  using an expansion to ensure accurate results when
131  \f$ (E-\mu)/T \f$ is near zero.
132 
133  \note This function may return Inf or NAN if \c limit is too
134  large, depending on the machine precision.
135 
136  This function is used in the <tt>o2scl::boson_rel</tt> class
137  in \o2p .
138  */
139  double bose_function(double E, double mu, double T, double limit=40.0);
140 
141  /** \brief Store the first line from the output of the shell
142  command \c cmd up to \c nmax characters in \c result
143 
144  \note This function uses popen() and may not work properly on
145  some systems. If HAVE_POPEN was not defined during O2scl's
146  compilation, then this function will throw an exception (or if
147  \c err_on_fail is false, it will return a nonzero value).
148 
149  \note The result string may contain a carriage return at
150  the end.
151  */
152  int pipe_cmd_string(std::string cmd, std::string &result,
153  bool err_on_fail=true, int nmax=80);
154 
155  /** \brief Return the first line from the output of the shell
156  command \c cmd up to \c nmax characters
157 
158  This function always throws exceptions if it fails.
159 
160  \note The result string may contain a carriage return at
161  the end.
162  */
163  std::string pipe_cmd_string(std::string cmd, int nmax=80);
164 
165  /** \brief Return true if file named \c fname exists
166  */
167  bool file_exists(std::string fname);
168 
169  /** \brief Reformat the columns for output of width \c size
170 
171  Given a string array \c in_cols of size \c nin, screenify()
172  reformats the array into columns creating a new string array \c
173  out_cols.
174 
175  For example, for an array of 10 strings
176  \verbatim
177  test1
178  test_of_string2
179  test_of_string3
180  test_of_string4
181  test5
182  test_of_string6
183  test_of_string77
184  test_of_string8
185  test_of_string9
186  test_of_string10
187  \endverbatim
188  screenify() will create an array of 3 new strings:
189  \verbatim
190  test1 test_of_string4 test_of_string77 test_of_string10
191  test_of_string2 test5 test_of_string8
192  test_of_string3 test_of_string6 test_of_string9
193  \endverbatim
194 
195  If the value of \c max_size is less than the length of the
196  longest input string (plus one for a space character), then the
197  output strings may have a larger length than \c max_size.
198  */
199  template<class string_arr_t>
200  void screenify(size_t nin, const string_arr_t &in_cols,
201  std::vector<std::string> &out_cols,
202  size_t max_size=80) {
203 
204  if (nin==0) {
205  O2SCL_ERR("No strings specified in screenify().",exc_efailed);
206  }
207 
208  size_t i,j,lmax,itemp;
209  std::string *in_spaces=new std::string[nin];
210 
211  // Determine size of largest string
212  lmax=0;
213  for(i=0;i<nin;i++) {
214  if (lmax<in_cols[i].size()) lmax=in_cols[i].size();
215  }
216 
217  // Pad with spaces
218  for(i=0;i<nin;i++) {
219  itemp=in_cols[i].size();
220  in_spaces[i]=in_cols[i];
221  for(j=0;j<lmax+1-itemp;j++) {
222  in_spaces[i]+=' ';
223  }
224  }
225 
226  // Determine number of rows and columns
227  size_t row, col;
228  col=max_size/(lmax+1);
229  if (col==0) col=1;
230  if (nin/col*col==nin) row=nin/col;
231  else row=nin/col+1;
232 
233  // Create outc
234  out_cols.reserve(row);
235  for(i=0;i<row;i++) {
236  out_cols.push_back("");
237  for(j=0;j<col;j++) {
238  if (i+j*row<nin) {
239  out_cols[i]+=in_spaces[i+j*row];
240  }
241  }
242  }
243 
244  delete[] in_spaces;
245 
246  return;
247  }
248 
249  /** \brief Count the number of words in the string \c str
250 
251  Words are defined as groups of characters separated by
252  whitespace, where whitespace is any combination of adjacent
253  spaces, tabs, carriage returns, etc. On most systems, whitespace
254  is usually defined as any character corresponding to the
255  integers 9 (horizontal tab), 10 (line feed), 11 (vertical tab),
256  12 (form feed), 13 (carriage return), and 32 (space bar). The
257  test program \c misc_ts enumerates the characters between 0 and
258  255 (inclusive) that count as whitespace for this purpose.
259 
260  \future Make consistent with split_string().
261  */
262  size_t count_words(std::string str);
263 
264  /** \brief Remove all whitespace from the string \c s
265 
266  This function removes all characters in \c s which correspond to
267  the integer values 9, 10, 11, 12, 13, or 32.
268  */
269  void remove_whitespace(std::string &s);
270 
271  /** \brief Take a string of binary quads and compress them to
272  hexadecimal digits
273 
274  This function proceeds from left to right, ignoring parts of the
275  string that do not consist of squences of four '1's or '0's.
276  */
277  std::string binary_to_hex(std::string s);
278 
279  /** \brief Convert RGB to HSV color
280 
281  Taken from Nathan Schaller's webpage at
282  http://www.cs.rit.edu/~ncs/color/t_convert.html
283 
284  The inputs should be in the ranges \f$ h \in [0,360] \f$, \f$ s
285  \in [0,1] \f$, and \f$ v \in [0,1] \f$. The output values \c r,
286  \c g, and \c b are \f$ \in [0,1] \f$.
287 
288  If s == 0, then h = -1 (undefined)
289  */
290  void RGBtoHSV(double r, double g, double b,
291  double &h, double &s, double &v);
292 
293  /** \brief Convert RGB to HSV color
294 
295  Taken from Nathan Schaller's webpage at
296  http://www.cs.rit.edu/~ncs/color/t_convert.html
297 
298  The inputs should be in the ranges \f$ h \in [0,360] \f$, \f$ s
299  \in [0,1] \f$, and \f$ v \in [0,1] \f$. The output values \c r,
300  \c g, and \c b are \f$ \in [0,1] \f$.
301 
302  If s == 0, then h = -1 (undefined)
303  */
304  void HSVtoRGB(double h, double s, double v,
305  double &r, double &g, double &b);
306  //@}
307 
308  /** \brief Generate number sequence for testing
309 
310  A class which generates \c tot numbers from -1 to 1, making sure
311  to include -1, 1, 0, and numbers near -1, 0 and 1 (so long as \c
312  tot is sufficiently large). If gen() is called more than \c tot
313  times, it just recycles through the list again.
314 
315  This class is used to generate combinations of coefficients for
316  testing the polynomial solvers.
317 
318  For example, the first 15 numbers generated by
319  an object of type gen_test_number<10> are:
320  \verbatim
321  0 -1.000000e+00
322  1 -9.975274e-01
323  2 -8.807971e-01
324  3 -1.192029e-01
325  4 -2.472623e-03
326  5 +0.000000e+00
327  6 +2.472623e-03
328  7 +1.192029e-01
329  8 +8.807971e-01
330  9 +1.000000e+00
331  10 -1.000000e+00
332  11 -9.975274e-01
333  12 -8.807971e-01
334  13 -1.192029e-01
335  14 -2.472623e-03
336  \endverbatim
337 
338  This function is used in <tt>src/other/poly_ts.cpp</tt> which
339  tests the polynomial solvers.
340 
341  \future Document what happens if \c tot is pathologically small.
342  */
343  template<size_t tot> class gen_test_number {
344 
345 #ifndef DOXYGEN_INTERNAL
346 
347  protected:
348 
349  /// Count number of numbers generated
350  int n;
351 
352  /** \brief A constant factor for the argument to
353  <tt>tanh()</tt>, equal to \c tot divided by 20.
354  */
355  double fact;
356 
357 #endif
358 
359  public:
360 
361  gen_test_number() {
362  n=0;
363  fact=((double)tot)/20.0;
364  }
365 
366  /// Return the next number in the sequence
367  double gen() {
368  double x, dtot=((double)tot), dn=((double)n);
369  if (n==0) {
370  x=-1.0;
371  } else if (n==tot/2) {
372  x=0.0;
373  } else if (n==tot-1) {
374  x=1.0;
375  } else if (n==tot) {
376  // Start the sequence over
377  x=-1.0;
378  n=0;
379  } else if (n<((int)tot)/2) {
380  // Since we're in the o2scl namespace, we explicitly
381  // specify std::tanh() here
382  x=(std::tanh((dn-dtot/4.0)/fact)-1.0)/2.0;
383  } else {
384  x=(std::tanh((dn-0.75*dtot)/fact)+1.0)/2.0;
385  }
386  n++;
387  return x;
388  }
389  };
390 
391  /// \name Quadratic extrema functions in src/base/misc.h
392  //@{
393  /** \brief Return the x value of the extremum of a quadratic defined by
394  three \f$ (x,y) \f$ pairs
395 
396  This function should work for any floating-point data type,
397  but will suffer from problems due to lack of precision in
398  some cases.
399  */
400  template<class data_t>
401  data_t quadratic_extremum_x(const data_t x1, const data_t x2,
402  const data_t x3, const data_t y1,
403  const data_t y2, const data_t y3) {
404 
405  if (x1==x2 || x2==x3 || x1==x3) {
406  O2SCL_ERR2("Two abscissae cannot be equal in function ",
407  "quadratic_extremum_x().",exc_einval);
408  }
409 
410  /*
411  Start with:
412  y1=a x1^2 + b x1 + c
413  y2=a x2^2 + b x2 + c
414  y3=a x3^2 + b x3 + c
415 
416  Eliminate 'c':
417  (y1-y2)=a(x1^2-x2^2)+b(x1-x2)
418  (y3-y2)=a(x3^2-x2^2)+b(x3-x2)
419 
420  Eliminate 'b':
421  (x3-x2)*(y1-y2)=a*(x1^2-x2^2)*(x3-x2)+b*(x1-x2)*(x3-x2)
422  (x1-x2)*(y3-y2)=a*(x3^2-x2^2)*(x1-x2)+b*(x3-x2)*(x1-x2)
423 
424  Alternatively, eliminate 'c' with:
425  (y2-y1)=a(x2^2-x1^2)+b(x2-x1)
426  (y3-y1)=a(x3^2-x1^2)+b(x3-x1)
427 
428  Eliminate 'b':
429  (x3-x1)*(y2-y1)=a(x2^2-x1^2)*(x3-x1)+b(x2-x1)*(x3-x1)
430  (x2-x1)*(y3-y1)=a(x3^2-x1^2)*(x2-x1)+b(x3-x1)*(x2-x1)
431  */
432 
433  data_t a,b,c,den=(x1*x1-x2*x2)*(x3-x2)-(x3*x3-x2*x2)*(x1-x2);
434  if (den==0.0) {
435  den=(x2*x2-x1*x1)*(x3-x1)-(x3*x3-x1*x1)*(x2-x1);
436  a=((x3-x1)*(y2-y1)-(x2-x2)*(y3-y1))/den;
437  } else {
438  a=((x3-x2)*(y1-y2)-(x1-x2)*(y3-y2))/den;
439  }
440  b=(y1-y2-a*(x1*x1-x2*x2))/(x1-x2);
441  c=y2-a*x2*x2-b*x2;
442 
443  return -b/2.0/a;
444  }
445 
446  /** \brief Return values related to a quadratic defined by
447  three \f$ (x,y) \f$ pairs
448 
449  This function provides the three coefficients of the
450  quadratic, \c a, \c b, and \c c, and the denominator
451  \c den.
452 
453  This function should work for any floating-point data type,
454  but will suffer from problems due to lack of precision in
455  some cases.
456  */
457  template<class data_t>
458  void quadratic_extremum_y_full(const data_t x1, const data_t x2,
459  const data_t x3, const data_t y1,
460  const data_t y2, const data_t y3,
461  const data_t &xmin, const data_t &ymin,
462  const data_t &a, const data_t &b,
463  const data_t &c, const data_t &den) {
464 
465  if (x1==x2 || x2==x3 || x1==x3) {
466  O2SCL_ERR2("Two abscissae cannot be equal in function ",
467  "quadratic_extremum_y().",exc_einval);
468  }
469 
470  den=(x1*x1-x2*x2)*(x3-x2)-(x3*x3-x2*x2)*(x1-x2);
471  if (den==0.0) {
472  den=(x2*x2-x1*x1)*(x3-x1)-(x3*x3-x1*x1)*(x2-x1);
473  a=((x3-x1)*(y2-y1)-(x2-x2)*(y3-y1))/den;
474  } else {
475  a=((x3-x2)*(y1-y2)-(x1-x2)*(y3-y2))/den;
476  }
477  b=(y1-y2-a*(x1*x1-x2*x2))/(x1-x2);
478  c=y2-a*x2*x2-b*x2;
479  xmin=-b/2.0/a;
480  ymin=c-b*b/4.0/a;
481  return;
482  }
483 
484  /** \brief Return the y value of the extremum of a quadratic defined by
485  three \f$ (x,y) \f$ pairs
486 
487  This function should work for any floating-point data type,
488  but will suffer from problems due to lack of precision in
489  some cases.
490  */
491  template<class data_t>
492  data_t quadratic_extremum_y(const data_t x1, const data_t x2,
493  const data_t x3, const data_t y1,
494  const data_t y2, const data_t y3) {
495 
496  if (x1==x2 || x2==x3 || x1==x3) {
497  O2SCL_ERR2("Two abscissae cannot be equal in function ",
498  "quadratic_extremum_y().",exc_einval);
499  }
500 
501  data_t a,b,c,den=(x1*x1-x2*x2)*(x3-x2)-(x3*x3-x2*x2)*(x1-x2);
502  if (den==0.0) {
503  den=(x2*x2-x1*x1)*(x3-x1)-(x3*x3-x1*x1)*(x2-x1);
504  a=((x3-x1)*(y2-y1)-(x2-x2)*(y3-y1))/den;
505  } else {
506  a=((x3-x2)*(y1-y2)-(x1-x2)*(y3-y2))/den;
507  }
508  b=(y1-y2-a*(x1*x1-x2*x2))/(x1-x2);
509  c=y2-a*x2*x2-b*x2;
510 
511  return c-b*b/4/a;
512  }
513 
514  /** \brief Return the (x,y) for the extremum of a quadratic defined by
515  three \f$ (x,y) \f$ pairs
516 
517  This function should work for any floating-point data type,
518  but will suffer from problems due to lack of precision in
519  some cases.
520  */
521  template<class data_t>
522  void quadratic_extremum_xy(const data_t x1, const data_t x2,
523  const data_t x3, const data_t y1,
524  const data_t y2, const data_t y3,
525  data_t &x, data_t &y) {
526 
527  if (x1==x2 || x2==x3 || x1==x3) {
528  O2SCL_ERR2("Two abscissae cannot be equal in function ",
529  "quadratic_extremum_xy().",exc_einval);
530  }
531 
532  data_t a,b,c,den=(x1*x1-x2*x2)*(x3-x2)-(x3*x3-x2*x2)*(x1-x2);
533  if (den==0.0) {
534  den=(x2*x2-x1*x1)*(x3-x1)-(x3*x3-x1*x1)*(x2-x1);
535  a=((x3-x1)*(y2-y1)-(x2-x2)*(y3-y1))/den;
536  } else {
537  a=((x3-x2)*(y1-y2)-(x1-x2)*(y3-y2))/den;
538  }
539  b=(y1-y2-a*(x1*x1-x2*x2))/(x1-x2);
540  c=y2-a*x2*x2-b*x2;
541 
542  x=-b/2/a;
543  y=c-b*b/4/a;
544 
545  return;
546  }
547 
548  /** \brief Return the (x,y) for the extremum of a quadratic defined by
549  three \f$ (x,y) \f$ pairs
550 
551  This function should work for any floating-point data type,
552  but will suffer from problems due to lack of precision in
553  some cases.
554  */
555  template<class data_t>
556  void quadratic_extremum_coeffs(const data_t x1, const data_t x2,
557  const data_t x3, const data_t y1,
558  const data_t y2, const data_t y3,
559  data_t &a, data_t &b, data_t &c) {
560 
561  if (x1==x2 || x2==x3 || x1==x3) {
562  O2SCL_ERR2("Two abscissae cannot be equal in function ",
563  "quadratic_extremum_coeffs().",exc_einval);
564  }
565 
566  data_t den=(x1*x1-x2*x2)*(x3-x2)-(x3*x3-x2*x2)*(x1-x2);
567  if (den==0.0) {
568  den=(x2*x2-x1*x1)*(x3-x1)-(x3*x3-x1*x1)*(x2-x1);
569  a=((x3-x1)*(y2-y1)-(x2-x2)*(y3-y1))/den;
570  } else {
571  a=((x3-x2)*(y1-y2)-(x1-x2)*(y3-y2))/den;
572  }
573  b=(y1-y2-a*(x1*x1-x2*x2))/(x1-x2);
574  c=y2-a*x2*x2-b*x2;
575 
576  return;
577  }
578  //@}
579 
580 #ifndef O2SCL_OLDER_COMPILER
581 
582  /** \brief A class to assign string labels to array indices
583  */
584  class vec_index {
585 
586  protected:
587 
588  /// The map version for string lookup
589  std::map<std::string,size_t,std::greater<std::string> > tmap;
590  /// The vector version for size_t lookup
591  std::vector<std::string> tvec;
592 
593  public:
594 
595  /// Create an empty assignment
597 
598  /// Create an assignment based on the strings in \c list
599  vec_index(std::vector<std::string> &list) {
600  for(size_t i=0;i<list.size();i++) {
601  tmap.insert(std::make_pair(list[i],i));
602  tvec.push_back(list[i]);
603  }
604  }
605 
606  /// Create an assignment based on the strings in \c list
607  vec_index(std::initializer_list<std::string> list) {
608  size_t ix=0;
609  for(std::initializer_list<std::string>::iterator it=list.begin();
610  it!=list.end();it++) {
611  tmap.insert(std::make_pair(*it,ix));
612  tvec.push_back(*it);
613  ix++;
614  }
615  }
616 
617  /// Return the string of index \c i
618  std::string operator()(size_t i) {
619  return tvec[i];
620  }
621 
622  /// Return the index of string \c s
623  size_t operator()(std::string s) {
624  std::map<std::string,size_t,std::greater<std::string> >::iterator it;
625  it=tmap.find(s);
626  if (it==tmap.end()) {
627  std::string str=((std::string)"Failed to find '")+s+
628  "' in vec_index::operator().";
629  O2SCL_ERR(str.c_str(),o2scl::exc_efailed);
630  }
631  return it->second;
632  }
633 
634  /// Return the string of index \c i
635  std::string operator[](size_t i) {
636  return tvec[i];
637  }
638 
639  /// Return the index of string \c s
640  size_t operator[](std::string s) {
641  std::map<std::string,size_t,std::greater<std::string> >::iterator it;
642  it=tmap.find(s);
643  if (it==tmap.end()) {
644  std::string str=((std::string)"Failed to find '")+s+
645  "' in vec_index::operator[].";
646  O2SCL_ERR(str.c_str(),o2scl::exc_efailed);
647  }
648  return it->second;
649  }
650 
651  /// Add string \c s and assign it the next index
652  void append(std::string s) {
653  tmap.insert(std::make_pair(s,tvec.size()));
654  tvec.push_back(s);
655  return;
656  }
657 
658  /// Add a list of strings
659  void append(std::initializer_list<std::string> list) {
660  size_t ix=tvec.size();
661  for(std::initializer_list<std::string>::iterator it=list.begin();
662  it!=list.end();it++) {
663  tmap.insert(std::make_pair(*it,ix));
664  tvec.push_back(*it);
665  ix++;
666  }
667  }
668 
669  };
670 
671 #endif
672 
673  /// \name Filesystem wrapper functions in src/base/misc.h
674  //@{
675  /** \brief Wrapper for the glob() function which
676  finds files which match a pattern
677 
678  \warning This function may not work on all operating
679  systems.
680 
681  \future Fix for openSUSE (see
682  https://github.com/awsteiner/o2scl/issues/8 )
683  */
684  int glob_wrapper(std::string pattern,
685  std::vector<std::string> &matches);
686 
687  /** \brief Wrapper for the wordexp() function
688  */
689  int wordexp_wrapper(std::string word,
690  std::vector<std::string> &matches);
691 
692  /** \brief Use wordexp() to obtain a single file
693  */
694  void wordexp_single_file(std::string &fname);
695  //@}
696 
697 #ifndef DOXYGEN_NO_O2NS
698 }
699 #endif
700 
701 #endif
702 
o2scl::vec_index::operator[]
std::string operator[](size_t i)
Return the string of index i.
Definition: misc.h:635
o2scl::vec_index::append
void append(std::string s)
Add string s and assign it the next index.
Definition: misc.h:652
o2scl::RGBtoHSV
void RGBtoHSV(double r, double g, double b, double &h, double &s, double &v)
Convert RGB to HSV color.
o2scl::exc_efailed
@ exc_efailed
generic failure
Definition: err_hnd.h:61
O2SCL_ERR2
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
Definition: err_hnd.h:281
o2scl::quadratic_extremum_y_full
void quadratic_extremum_y_full(const data_t x1, const data_t x2, const data_t x3, const data_t y1, const data_t y2, const data_t y3, const data_t &xmin, const data_t &ymin, const data_t &a, const data_t &b, const data_t &c, const data_t &den)
Return values related to a quadratic defined by three pairs.
Definition: misc.h:458
o2scl
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
Definition: anneal.h:42
o2scl::gen_test_number
Generate number sequence for testing.
Definition: misc.h:343
o2scl::wordexp_wrapper
int wordexp_wrapper(std::string word, std::vector< std::string > &matches)
Wrapper for the wordexp() function.
o2scl::vec_index::vec_index
vec_index(std::initializer_list< std::string > list)
Create an assignment based on the strings in list.
Definition: misc.h:607
o2scl::vec_index::vec_index
vec_index(std::vector< std::string > &list)
Create an assignment based on the strings in list.
Definition: misc.h:599
o2scl::gen_test_number::fact
double fact
A constant factor for the argument to tanh(), equal to tot divided by 20.
Definition: misc.h:355
o2scl::count_words
size_t count_words(std::string str)
Count the number of words in the string str.
o2scl::file_exists
bool file_exists(std::string fname)
Return true if file named fname exists.
o2scl::vec_index::append
void append(std::initializer_list< std::string > list)
Add a list of strings.
Definition: misc.h:659
o2scl::remove_whitespace
void remove_whitespace(std::string &s)
Remove all whitespace from the string s.
o2scl::bose_function
double bose_function(double E, double mu, double T, double limit=40.0)
Calculate a Bose-Einstein distribution function safely.
o2scl_inte_qng_coeffs::x2
static const double x2[5]
Definition: inte_qng_gsl.h:66
o2scl::screenify
void screenify(size_t nin, const string_arr_t &in_cols, std::vector< std::string > &out_cols, size_t max_size=80)
Reformat the columns for output of width size.
Definition: misc.h:200
o2scl::quadratic_extremum_x
data_t quadratic_extremum_x(const data_t x1, const data_t x2, const data_t x3, const data_t y1, const data_t y2, const data_t y3)
Return the x value of the extremum of a quadratic defined by three pairs.
Definition: misc.h:401
o2scl::vec_index
A class to assign string labels to array indices.
Definition: misc.h:584
o2scl::fermi_function
double fermi_function(double E, double mu, double T, double limit=40.0)
Calculate a Fermi-Dirac distribution function safely.
o2scl_inte_qng_coeffs::x1
static const double x1[5]
Definition: inte_qng_gsl.h:48
o2scl::exc_einval
@ exc_einval
invalid argument supplied by user
Definition: err_hnd.h:59
o2scl::glob_wrapper
int glob_wrapper(std::string pattern, std::vector< std::string > &matches)
Wrapper for the glob() function which finds files which match a pattern.
o2scl::binary_to_hex
std::string binary_to_hex(std::string s)
Take a string of binary quads and compress them to hexadecimal digits.
o2scl::quadratic_extremum_y
data_t quadratic_extremum_y(const data_t x1, const data_t x2, const data_t x3, const data_t y1, const data_t y2, const data_t y3)
Return the y value of the extremum of a quadratic defined by three pairs.
Definition: misc.h:492
o2scl::wordexp_single_file
void wordexp_single_file(std::string &fname)
Use wordexp() to obtain a single file.
o2scl::gen_test_number::gen
double gen()
Return the next number in the sequence.
Definition: misc.h:367
o2scl::vec_index::vec_index
vec_index()
Create an empty assignment.
Definition: misc.h:596
o2scl::vec_index::tvec
std::vector< std::string > tvec
The vector version for size_t lookup.
Definition: misc.h:591
o2scl::quadratic_extremum_xy
void quadratic_extremum_xy(const data_t x1, const data_t x2, const data_t x3, const data_t y1, const data_t y2, const data_t y3, data_t &x, data_t &y)
Return the (x,y) for the extremum of a quadratic defined by three pairs.
Definition: misc.h:522
o2scl::HSVtoRGB
void HSVtoRGB(double h, double s, double v, double &r, double &g, double &b)
Convert RGB to HSV color.
o2scl::quadratic_extremum_coeffs
void quadratic_extremum_coeffs(const data_t x1, const data_t x2, const data_t x3, const data_t y1, const data_t y2, const data_t y3, data_t &a, data_t &b, data_t &c)
Return the (x,y) for the extremum of a quadratic defined by three pairs.
Definition: misc.h:556
O2SCL_ERR
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
Definition: err_hnd.h:273
o2scl::o2abs
float o2abs(const float x)
Absolute value for single precision numbers.
o2scl::pipe_cmd_string
int pipe_cmd_string(std::string cmd, std::string &result, bool err_on_fail=true, int nmax=80)
Store the first line from the output of the shell command cmd up to nmax characters in result.
o2scl::vec_index::tmap
std::map< std::string, size_t, std::greater< std::string > > tmap
The map version for string lookup.
Definition: misc.h:589
o2scl::vec_index::operator()
size_t operator()(std::string s)
Return the index of string s.
Definition: misc.h:623
o2scl::vec_index::operator()
std::string operator()(size_t i)
Return the string of index i.
Definition: misc.h:618
o2scl::o2isfinite
bool o2isfinite(const double x)
Compatbility function for isfinite()
o2scl::gen_test_number::n
int n
Count number of numbers generated.
Definition: misc.h:350
o2scl::vec_index::operator[]
size_t operator[](std::string s)
Return the index of string s.
Definition: misc.h:640
o2scl_inte_qng_coeffs::x3
static const double x3[11]
Definition: inte_qng_gsl.h:94

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).