39 #include <initializer_list> 41 #include <o2scl/err_hnd.h> 44 int o2scl_python_test(
int x);
47 #ifndef DOXYGEN_NO_O2NS 67 double fermi_function(
double E,
double mu,
double T,
double limit=40.0);
81 bool err_on_fail=
true,
int nmax=80);
123 template<
class string_arr_t>
125 std::vector<std::string> &out_cols,
126 size_t max_size=80) {
132 size_t i,j,lmax,itemp;
133 std::string *in_spaces=
new std::string[nin];
138 if (lmax<in_cols[i].size()) lmax=in_cols[i].size();
143 itemp=in_cols[i].size();
144 in_spaces[i]=in_cols[i];
145 for(j=0;j<lmax+1-itemp;j++) {
152 col=max_size/(lmax+1);
154 if (nin/col*col==nin) row=nin/col;
158 out_cols.reserve(row);
160 out_cols.push_back(
"");
163 out_cols[i]+=in_spaces[i+j*row];
214 void RGBtoHSV(
double r,
double g,
double b,
215 double &h,
double &s,
double &v);
228 void HSVtoRGB(
double h,
double s,
double v,
229 double &r,
double &g,
double &b);
269 #ifndef DOXYGEN_INTERNAL 287 fact=((double)tot)/20.0;
292 double x, dtot=((double)tot), dn=((double)n);
295 }
else if (n==tot/2) {
297 }
else if (n==tot-1) {
303 }
else if (n<((
int)tot)/2) {
306 x=(std::tanh((dn-dtot/4.0)/fact)-1.0)/2.0;
308 x=(std::tanh((dn-0.75*dtot)/fact)+1.0)/2.0;
322 template<
class data_t>
324 const data_t
x3,
const data_t y1,
325 const data_t y2,
const data_t y3) {
327 if (x1==x2 || x2==x3 || x1==x3) {
328 O2SCL_ERR2(
"Two abscissae cannot be equal in function ",
355 data_t a,b,c,den=(x1*x1-x2*
x2)*(x3-x2)-(x3*x3-x2*
x2)*(x1-x2);
357 den=(x2*x2-x1*
x1)*(x3-x1)-(x3*x3-x1*
x1)*(x2-x1);
358 a=((x3-
x1)*(y2-y1)-(x2-
x2)*(y3-y1))/den;
360 a=((x3-
x2)*(y1-y2)-(x1-
x2)*(y3-y2))/den;
362 b=(y1-y2-a*(x1*x1-x2*
x2))/(x1-
x2);
379 template<
class data_t>
381 const data_t
x3,
const data_t y1,
382 const data_t y2,
const data_t y3,
383 const data_t &xmin,
const data_t &ymin,
384 const data_t &a,
const data_t &b,
385 const data_t &c,
const data_t &den) {
387 if (x1==x2 || x2==x3 || x1==x3) {
388 O2SCL_ERR2(
"Two abscissae cannot be equal in function ",
392 den=(x1*x1-x2*
x2)*(x3-x2)-(x3*x3-x2*
x2)*(x1-x2);
394 den=(x2*x2-x1*
x1)*(x3-x1)-(x3*x3-x1*
x1)*(x2-x1);
395 a=((x3-
x1)*(y2-y1)-(x2-
x2)*(y3-y1))/den;
397 a=((x3-
x2)*(y1-y2)-(x1-
x2)*(y3-y2))/den;
399 b=(y1-y2-a*(x1*x1-x2*
x2))/(x1-
x2);
413 template<
class data_t>
415 const data_t
x3,
const data_t y1,
416 const data_t y2,
const data_t y3) {
418 if (x1==x2 || x2==x3 || x1==x3) {
419 O2SCL_ERR2(
"Two abscissae cannot be equal in function ",
423 data_t a,b,c,den=(x1*x1-x2*
x2)*(x3-x2)-(x3*x3-x2*
x2)*(x1-x2);
425 den=(x2*x2-x1*
x1)*(x3-x1)-(x3*x3-x1*
x1)*(x2-x1);
426 a=((x3-
x1)*(y2-y1)-(x2-
x2)*(y3-y1))/den;
428 a=((x3-
x2)*(y1-y2)-(x1-
x2)*(y3-y2))/den;
430 b=(y1-y2-a*(x1*x1-x2*
x2))/(x1-
x2);
443 template<
class data_t>
445 const data_t
x3,
const data_t y1,
446 const data_t y2,
const data_t y3,
447 data_t &x, data_t &y) {
449 if (x1==x2 || x2==x3 || x1==x3) {
450 O2SCL_ERR2(
"Two abscissae cannot be equal in function ",
454 data_t a,b,c,den=(x1*x1-x2*
x2)*(x3-x2)-(x3*x3-x2*
x2)*(x1-x2);
456 den=(x2*x2-x1*
x1)*(x3-x1)-(x3*x3-x1*
x1)*(x2-x1);
457 a=((x3-
x1)*(y2-y1)-(x2-
x2)*(y3-y1))/den;
459 a=((x3-
x2)*(y1-y2)-(x1-
x2)*(y3-y2))/den;
461 b=(y1-y2-a*(x1*x1-x2*
x2))/(x1-
x2);
477 template<
class data_t>
479 const data_t
x3,
const data_t y1,
480 const data_t y2,
const data_t y3,
481 data_t &a, data_t &b, data_t &c) {
483 if (x1==x2 || x2==x3 || x1==x3) {
484 O2SCL_ERR2(
"Two abscissae cannot be equal in function ",
488 data_t den=(x1*x1-x2*
x2)*(x3-x2)-(x3*x3-x2*
x2)*(x1-x2);
490 den=(x2*x2-x1*
x1)*(x3-x1)-(x3*x3-x1*
x1)*(x2-x1);
491 a=((x3-
x1)*(y2-y1)-(x2-
x2)*(y3-y1))/den;
493 a=((x3-
x2)*(y1-y2)-(x1-
x2)*(y3-y2))/den;
495 b=(y1-y2-a*(x1*x1-x2*
x2))/(x1-
x2);
501 #ifndef O2SCL_OLDER_COMPILER 510 std::map<std::string,size_t,std::greater<std::string> >
tmap;
521 for(
size_t i=0;i<list.size();i++) {
522 tmap.insert(std::make_pair(list[i],i));
523 tvec.push_back(list[i]);
530 for(std::initializer_list<std::string>::iterator it=list.begin();
531 it!=list.end();it++) {
532 tmap.insert(std::make_pair(*it,ix));
545 std::map<std::string,size_t,std::greater<std::string> >::iterator it;
547 if (it==tmap.end()) {
548 std::string str=((std::string)
"Failed to find '")+s+
549 "' in vec_index::operator().";
562 std::map<std::string,size_t,std::greater<std::string> >::iterator it;
564 if (it==tmap.end()) {
565 std::string str=((std::string)
"Failed to find '")+s+
566 "' in vec_index::operator[].";
574 tmap.insert(std::make_pair(s,tvec.size()));
580 void append(std::initializer_list<std::string> list) {
581 size_t ix=tvec.size();
582 for(std::initializer_list<std::string>::iterator it=list.begin();
583 it!=list.end();it++) {
584 tmap.insert(std::make_pair(*it,ix));
593 #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.
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.