39 #include <initializer_list> 44 #include <o2scl/err_hnd.h> 47 int o2scl_python_test(
int x);
50 #ifndef DOXYGEN_NO_O2NS 70 double fermi_function(
double E,
double mu,
double T,
double limit=40.0);
84 bool err_on_fail=
true,
int nmax=80);
126 template<
class string_arr_t>
128 std::vector<std::string> &out_cols,
129 size_t max_size=80) {
135 size_t i,j,lmax,itemp;
136 std::string *in_spaces=
new std::string[nin];
141 if (lmax<in_cols[i].size()) lmax=in_cols[i].size();
146 itemp=in_cols[i].size();
147 in_spaces[i]=in_cols[i];
148 for(j=0;j<lmax+1-itemp;j++) {
155 col=max_size/(lmax+1);
157 if (nin/col*col==nin) row=nin/col;
161 out_cols.reserve(row);
163 out_cols.push_back(
"");
166 out_cols[i]+=in_spaces[i+j*row];
217 void RGBtoHSV(
double r,
double g,
double b,
218 double &h,
double &s,
double &v);
231 void HSVtoRGB(
double h,
double s,
double v,
232 double &r,
double &g,
double &b);
272 #ifndef DOXYGEN_INTERNAL 290 fact=((double)tot)/20.0;
295 double x, dtot=((double)tot), dn=((double)n);
298 }
else if (n==tot/2) {
300 }
else if (n==tot-1) {
306 }
else if (n<((
int)tot)/2) {
309 x=(std::tanh((dn-dtot/4.0)/fact)-1.0)/2.0;
311 x=(std::tanh((dn-0.75*dtot)/fact)+1.0)/2.0;
325 template<
class data_t>
327 const data_t
x3,
const data_t y1,
328 const data_t y2,
const data_t y3) {
330 if (x1==x2 || x2==x3 || x1==x3) {
331 O2SCL_ERR2(
"Two abscissae cannot be equal in function ",
358 data_t a,b,c,den=(x1*x1-x2*
x2)*(x3-x2)-(x3*x3-x2*
x2)*(x1-x2);
360 den=(x2*x2-x1*
x1)*(x3-x1)-(x3*x3-x1*
x1)*(x2-x1);
361 a=((x3-
x1)*(y2-y1)-(x2-
x2)*(y3-y1))/den;
363 a=((x3-
x2)*(y1-y2)-(x1-
x2)*(y3-y2))/den;
365 b=(y1-y2-a*(x1*x1-x2*
x2))/(x1-
x2);
382 template<
class data_t>
384 const data_t
x3,
const data_t y1,
385 const data_t y2,
const data_t y3,
386 const data_t &xmin,
const data_t &ymin,
387 const data_t &a,
const data_t &b,
388 const data_t &c,
const data_t &den) {
390 if (x1==x2 || x2==x3 || x1==x3) {
391 O2SCL_ERR2(
"Two abscissae cannot be equal in function ",
395 den=(x1*x1-x2*
x2)*(x3-x2)-(x3*x3-x2*
x2)*(x1-x2);
397 den=(x2*x2-x1*
x1)*(x3-x1)-(x3*x3-x1*
x1)*(x2-x1);
398 a=((x3-
x1)*(y2-y1)-(x2-
x2)*(y3-y1))/den;
400 a=((x3-
x2)*(y1-y2)-(x1-
x2)*(y3-y2))/den;
402 b=(y1-y2-a*(x1*x1-x2*
x2))/(x1-
x2);
416 template<
class data_t>
418 const data_t
x3,
const data_t y1,
419 const data_t y2,
const data_t y3) {
421 if (x1==x2 || x2==x3 || x1==x3) {
422 O2SCL_ERR2(
"Two abscissae cannot be equal in function ",
426 data_t a,b,c,den=(x1*x1-x2*
x2)*(x3-x2)-(x3*x3-x2*
x2)*(x1-x2);
428 den=(x2*x2-x1*
x1)*(x3-x1)-(x3*x3-x1*
x1)*(x2-x1);
429 a=((x3-
x1)*(y2-y1)-(x2-
x2)*(y3-y1))/den;
431 a=((x3-
x2)*(y1-y2)-(x1-
x2)*(y3-y2))/den;
433 b=(y1-y2-a*(x1*x1-x2*
x2))/(x1-
x2);
446 template<
class data_t>
448 const data_t
x3,
const data_t y1,
449 const data_t y2,
const data_t y3,
450 data_t &x, data_t &y) {
452 if (x1==x2 || x2==x3 || x1==x3) {
453 O2SCL_ERR2(
"Two abscissae cannot be equal in function ",
457 data_t a,b,c,den=(x1*x1-x2*
x2)*(x3-x2)-(x3*x3-x2*
x2)*(x1-x2);
459 den=(x2*x2-x1*
x1)*(x3-x1)-(x3*x3-x1*
x1)*(x2-x1);
460 a=((x3-
x1)*(y2-y1)-(x2-
x2)*(y3-y1))/den;
462 a=((x3-
x2)*(y1-y2)-(x1-
x2)*(y3-y2))/den;
464 b=(y1-y2-a*(x1*x1-x2*
x2))/(x1-
x2);
480 template<
class data_t>
482 const data_t
x3,
const data_t y1,
483 const data_t y2,
const data_t y3,
484 data_t &a, data_t &b, data_t &c) {
486 if (x1==x2 || x2==x3 || x1==x3) {
487 O2SCL_ERR2(
"Two abscissae cannot be equal in function ",
491 data_t den=(x1*x1-x2*
x2)*(x3-x2)-(x3*x3-x2*
x2)*(x1-x2);
493 den=(x2*x2-x1*
x1)*(x3-x1)-(x3*x3-x1*
x1)*(x2-x1);
494 a=((x3-
x1)*(y2-y1)-(x2-
x2)*(y3-y1))/den;
496 a=((x3-
x2)*(y1-y2)-(x1-
x2)*(y3-y2))/den;
498 b=(y1-y2-a*(x1*x1-x2*
x2))/(x1-
x2);
504 #ifndef O2SCL_OLDER_COMPILER 513 std::map<std::string,size_t,std::greater<std::string> >
tmap;
524 for(
size_t i=0;i<list.size();i++) {
525 tmap.insert(std::make_pair(list[i],i));
526 tvec.push_back(list[i]);
533 for(std::initializer_list<std::string>::iterator it=list.begin();
534 it!=list.end();it++) {
535 tmap.insert(std::make_pair(*it,ix));
548 std::map<std::string,size_t,std::greater<std::string> >::iterator it;
550 if (it==tmap.end()) {
551 std::string str=((std::string)
"Failed to find '")+s+
552 "' in vec_index::operator().";
565 std::map<std::string,size_t,std::greater<std::string> >::iterator it;
567 if (it==tmap.end()) {
568 std::string str=((std::string)
"Failed to find '")+s+
569 "' in vec_index::operator[].";
577 tmap.insert(std::make_pair(s,tvec.size()));
583 void append(std::initializer_list<std::string> list) {
584 size_t ix=tvec.size();
585 for(std::initializer_list<std::string>::iterator it=list.begin();
586 it!=list.end();it++) {
587 tmap.insert(std::make_pair(*it,ix));
599 std::vector<std::string> &matches);
603 #ifndef DOXYGEN_NO_O2NS std::string binary_to_hex(std::string s)
Take a string of binary quads and compress them to hexadecimal digits.
double fact
A constant factor for the argument to tanh(), equal to tot divided by 20.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
void remove_whitespace(std::string &s)
Remove all whitespace from the string s.
void HSVtoRGB(double h, double s, double v, double &r, double &g, double &b)
Convert RGB to HSV color.
invalid argument supplied by user
size_t operator()(std::string s)
Return the index of string s.
double fermi_function(double E, double mu, double T, double limit=40.0)
Calculate a Fermi-Dirac distribution function safely.
A class to assign string labels to array indices.
std::map< std::string, size_t, std::greater< std::string > > tmap
The map version for string lookup.
vec_index(std::initializer_list< std::string > list)
Create an assignment based on the strings in list.
std::string operator[](size_t i)
Return the string of index i.
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.
vec_index(std::vector< std::string > &list)
Create an assignment based on the strings in list.
static const double x3[11]
Generate number sequence for testing.
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
double gen()
Return the next number in the sequence.
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.
int glob_wrapper(std::string pattern, std::vector< std::string > &matches)
Wrapper for the glob() function which finds files which match a pattern.
void append(std::string s)
Add string s and assign it the next index.
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.
void append(std::initializer_list< std::string > list)
Add a list of strings.
#define O2SCL_ERR(d, n)
Set an error with message d and code n.
std::string operator()(size_t i)
Return the string of index i.
void RGBtoHSV(double r, double g, double b, double &h, double &s, double &v)
Convert RGB to HSV color.
size_t operator[](std::string s)
Return the index of string s.
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.
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.
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.
std::vector< std::string > tvec
The vector version for size_t lookup.
int n
Count number of numbers generated.
size_t count_words(std::string str)
Count the number of words in the string str.
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...
static const double x2[5]
static const double x1[5]
vec_index()
Create an empty assignment.