Object-oriented Scientific Computing Library: Version 0.910
Data Structures | Functions
misc.h File Reference

Miscellaneous functions. More...

#include <cstdlib>
#include <iostream>
#include <cmath>
#include <string>
#include <fstream>
#include <sstream>
#include <vector>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_ieee_utils.h>
#include <o2scl/err_hnd.h>
#include <o2scl/lib_settings.h>

Go to the source code of this file.


Detailed Description

Definition in file misc.h.

Data Structures

struct  string_comp
 Simple string comparison. More...
class  gen_test_number< tot >
 Generate number sequence for testing. More...

Functions

double fermi_function (double E, double mu, double T, double limit=40.0)
 Calculate a Fermi-Dirac distribution function safely.
template<class string_arr_t >
int 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.
int count_words (std::string str)
 Count the number of words in the string str.
int remove_whitespace (std::string &s)
 Remove all whitespace from the string s.
std::string binary_to_hex (std::string s)
 Take a string of binary quads and compress them to hexadecimal digits.
template<class type_t >
int gsl_alloc_arrays (size_t nv, size_t msize, const char *names[], type_t *ptrs[], std::string func_name)
 A convenient function to allocate several arrays of the same size.
template<class type_t >
int gsl_calloc_arrays (size_t nv, size_t msize, const char *names[], type_t *ptrs[], std::string func_name, type_t val)
 A convenient function to allocate and initialize several arrays of the same size.
int gsl_calloc_gvecs (size_t nv, size_t msize, const char *names[], gsl_vector ***ptrs, std::string func_name)
 A convenient function to allocate and initialize several arrays of the same size.
double quadratic_extremum_x (double x1, double x2, double x3, double y1, double y2, double y3)
 Return the x value of the extremum of a quadratic defined by three $ (x,y) $ pairs.
double quadratic_extremum_y (double x1, double x2, double x3, double y1, double y2, double y3)
 Return the y value of the extremum of a quadratic defined by three $ (x,y) $ pairs.

Function Documentation

double fermi_function ( double  E,
double  mu,
double  T,
double  limit = 40.0 
)

$ \left[1+\exp\left(E/T-\mu/T\right)\right]^{-1} $

This calculates a Fermi-Dirac distribution function guaranteeing that numbers larger than $ \exp(\mathrm{limit}) $ and smaller than $ \exp(-\mathrm{limit}) $ will be avoided. The default value of limit=40 ensures accuracy to within 1 part in $ 10^{17} $ compared to the maximum of the distribution (which is unity).

Note that this function may return Inf or NAN if limit is too large, depending on the machine precision.

template<class string_arr_t >
int screenify ( size_t  nin,
const string_arr_t &  in_cols,
std::vector< std::string > &  out_cols,
size_t  max_size = 80 
)

Given a string array in_cols of size nin, screenify() reformats the array into columns creating a new string array out_cols.

For example, for an array of 10 strings

      test1
      test_of_string2
      test_of_string3
      test_of_string4
      test5
      test_of_string6
      test_of_string7
      test_of_string8
      test_of_string9
      test_of_string10
      

screenify() will create an array of 3 new strings:

      test1            test_of_string4  test_of_string7  test_of_string10
      test_of_string2  test5            test_of_string8
      test_of_string3  test_of_string6  test_of_string9
      

If the value of max_size is less than the length of the longest input string (plus one for a space character), then the output strings may have a larger length than max_size.

Definition at line 94 of file misc.h.

int count_words ( std::string  str)

Words are defined as groups of characters separated by whitespace, where whitespace is any combination of adjacent spaces, tabs, carriage returns, etc. On most systems, whitespace is usually defined as any character corresponding to the integers 9 (horizontal tab), 10 (line feed), 11 (vertical tab), 12 (form feed), 13 (carriage return), and 32 (space bar). The test program misc_ts enumerates the characters between 0 and 255 (inclusive) that count as whitespace for this purpose.

Note that this function is used in text_in_file::string_in to perform string input.

int remove_whitespace ( std::string &  s)

This function removes all characters in s which correspond to the integer values 9, 10, 11, 12, 13, or 32.

std::string binary_to_hex ( std::string  s)

This function proceeds from left to right, ignoring parts of the string that do not consist of squences of four '1's or '0's.

template<class type_t >
int gsl_alloc_arrays ( size_t  nv,
size_t  msize,
const char *  names[],
type_t *  ptrs[],
std::string  func_name 
)

Allocate memory for nv vectors of size msize with names specified in names and function name func_name to produce pointers in ptrs. This function is unsed internally to allocate several vectors in succession, taking care to free memory and call the error handler when an allocation fails.

The caller must make sure that previously allocated memory will be freed and an error is thrown if this function returns a non-zero value.

This function is used, for example, in gsl_miser.

Definition at line 290 of file misc.h.

template<class type_t >
int gsl_calloc_arrays ( size_t  nv,
size_t  msize,
const char *  names[],
type_t *  ptrs[],
std::string  func_name,
type_t  val 
)

The caller must make sure that previously allocated memory will be freed and an error is thrown if this function returns a non-zero value.

Definition at line 320 of file misc.h.

int gsl_calloc_gvecs ( size_t  nv,
size_t  msize,
const char *  names[],
gsl_vector ***  ptrs,
std::string  func_name 
)

The caller must make sure that previously allocated memory will be freed and an error is thrown if this function returns a non-zero value.

double quadratic_extremum_x ( double  x1,
double  x2,
double  x3,
double  y1,
double  y2,
double  y3 
)
Idea for Future:
Make a function quadratic_points(double x1, double x2, double x3, double y1, double y2, double y3, double &a, double &b, double &c)?
Idea for Future:
Make a quadratic_extremum_xy()?
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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

Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads.