#include <cstdlib>
#include <iostream>
#include <cmath>
#include <string>
#include <fstream>
#include <sstream>
#include <vector>
#include <gsl/gsl_ieee_utils.h>
#include <o2scl/err_hnd.h>
#include <o2scl/lib_settings.h>
Go to the source code of this file.
Definition in file misc.h.
Data Structures | |
struct | string_comp |
Simple string comparison. More... | |
class | gen_test_number |
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 . | |
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. |
std::string binary_to_hex | ( | std::string | s | ) |
Take a string of binary quads and compress them to hexadecimal digits.
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.
int count_words | ( | std::string | str | ) |
Count the number of words in the 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.
double fermi_function | ( | double | E, | |
double | mu, | |||
double | T, | |||
double | limit = 40.0 | |||
) |
Calculate a Fermi-Dirac distribution function safely.
This calculates a Fermi-Dirac distribution function guaranteeing that numbers larger than and smaller than
will be avoided. The default value of
limit=40
ensures accuracy to within 1 part in 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.
int gsl_alloc_arrays | ( | size_t | nv, | |
size_t | msize, | |||
const char * | names[], | |||
type_t * | ptrs[], | |||
std::string | func_name | |||
) | [inline] |
A convenient function to allocate several arrays of the same size.
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 GSL vectors in succession, taking care to call the error handler when necessary.
int screenify | ( | size_t | nin, | |
const string_arr_t & | in_cols, | |||
std::vector< std::string > & | out_cols, | |||
size_t | max_size = 80 | |||
) | [inline] |
Reformat the columns for output of width size
.
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
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
.
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page