misc.h File Reference


Detailed Description

Miscellaneous functions.

Definition in file misc.h.

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

Go to the source code of this file.

Data Structures

struct  string_comp
 Naive 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.
void screenify (const std::string *in_cols, int nin, std::string *&outc, int &nout, int max_size=80)
 Reformat the columns for output of width size.
template<class string_arr_t>
int screenify2 (size_t nin, const string_arr_t &in_cols, std::vector< std::string > &out_cols, size_t max_size=80)
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.


Function Documentation

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.

$ \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 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.

void screenify ( const std::string *  in_cols,
int  nin,
std::string *&  outc,
int &  nout,
int  max_size = 80 
)

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 outc with size nout.

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
      

The string array given in outc must be deleted with delete[] after usage.

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.

Todo:
Convert to the new version "screenify2"


Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.

Project hosting provided by SourceForge.net Logo, O2scl Sourceforge Project Page