PyNE C++
utils.h
1 
7 // Header for general library file.
8 
9 #ifndef PYNE_KMMHYNANYFF5BFMEYIP7TUNLHA
10 #define PYNE_KMMHYNANYFF5BFMEYIP7TUNLHA
11 
12 //standard libraries
13 #include <string>
14 #include <string.h>
15 #include <sstream>
16 #include <cctype>
17 #include <stdlib.h>
18 #include <iostream>
19 #include <cmath>
20 #include <exception>
21 #include <sys/stat.h>
22 #include <sys/types.h>
23 #include <cstdlib>
24 #include <vector>
25 #include <algorithm>
26 
27 #if (__GNUC__ >= 4)
28  #include <cmath>
29  #define isnan(x) std::isnan(x)
30 #else
31  #include <math.h>
32  #define isnan(x) __isnand((double)x)
33 #endif
34 
35 #ifdef __WIN_MSVC__
36  #define isnan(x) ((x) != (x))
37 #endif
38 
39 #ifndef JSON_IS_AMALGAMATION
40  #define JSON_IS_AMALGAMATION
41 #endif
42 
44 namespace pyne {
45 
46  void pyne_start ();
47 
49  extern std::string PYNE_DATA;
50  extern std::string NUC_DATA_PATH;
51 
52  // String Transformations
54  static std::string digits = "0123456789";
56  static std::string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
58  static std::string words = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_";
59 
63  std::string to_str(int t);
64  std::string to_str(unsigned int t);
65  std::string to_str(double t);
66  std::string to_str(bool t);
68 
69  int to_int(std::string s);
70 
71  double to_dbl(std::string s);
72 
75  double endftod_cpp(char * s);
76  double endftod_f(char * s);
77  extern double (*endftod)(char * s);
78 
79  void use_fast_endftod();
80 
82  std::string to_upper(std::string s);
83 
85  std::string to_lower(std::string s);
86 
88  std::string capitalize(std::string s);
89 
94  std::string get_flag(char line[], int max_l);
95 
97  std::string remove_substring(std::string s, std::string substr);
98 
100  std::string remove_characters(std::string s, std::string chars);
101 
103  std::string replace_all_substrings(std::string s, std::string substr,
104  std::string repstr);
105 
107  std::string last_char(std::string s);
108 
111  std::string slice_from_end(std::string s, int n=-1, int l=1);
112 
114  bool ternary_ge(int a, int b, int c);
115 
117  bool contains_substring(std::string s, std::string substr);
118 
121  std::string natural_naming(std::string name);
122 
124  double slope (double x2, double y2, double x1, double y1);
125 
128  double solve_line (double x, double x2, double y2, double x1, double y1);
129 
130  double tanh(double x);
131  double coth(double x);
132 
133 
134  // File Helpers
136  bool file_exists(std::string strfilename);
137 
138  // Message Helpers
139  extern bool USE_WARNINGS;
141  bool toggle_warnings();
142 
144  void warning(std::string s);
145 
148  class FileNotFound : public std::exception
149  {
150  public:
151 
154 
156  ~FileNotFound () throw () {};
157 
159  FileNotFound(std::string fname)
160  {
161  filename = fname;
162  };
163 
165  virtual const char* what() const throw()
166  {
167  std::string FNFstr ("File not found: ");
168  if (!filename.empty())
169  FNFstr += filename;
170 
171  return (const char *) FNFstr.c_str();
172  };
173 
174  private:
175  std::string filename;
176  };
177 
178 
179 // End PyNE namespace
180 }
181 
182 #endif // PYNE_KMMHYNANYFF5BFMEYIP7TUNLHA
double to_dbl(std::string s)
Converts a valid string to a float using atof().
Definition: utils.cpp:78
double b(int nuc)
Computes the scattering length [cm] from the coherent and incoherent components.
Definition: data.cpp:835
std::string get_flag(char line[], int max_l)
Definition: utils.cpp:179
std::string natural_naming(std::string name)
Definition: utils.cpp:253
std::string last_char(std::string s)
Returns the last character in a string.
Definition: utils.cpp:228
double coth(double x)
The hyperbolic cotangent function.
Definition: utils.cpp:303
std::string PYNE_DATA
Path to the directory containing the PyNE data.
Definition: utils.cpp:13
bool ternary_ge(int a, int b, int c)
Returns true if a <= b <= c and flase otherwise.
Definition: utils.cpp:240
std::string to_lower(std::string s)
Returns an all lower case copy of the string.
Definition: utils.cpp:158
Definition: utils.h:148
bool contains_substring(std::string s, std::string substr)
Returns true if substr is in s.
Definition: utils.cpp:246
bool toggle_warnings()
Toggles warnings on and off.
Definition: utils.cpp:343
double endftod_f(char *s)
Converts a string from ENDF format to a float.
Definition: utils.cpp:137
std::string NUC_DATA_PATH
Path to the nuc_data.h5 file.
Definition: utils.h:50
double endftod_cpp(char *s)
Definition: utils.cpp:82
~FileNotFound()
default destructor
Definition: utils.h:156
std::string slice_from_end(std::string s, int n=-1, int l=1)
Definition: utils.cpp:234
FileNotFound()
default constructor
Definition: utils.h:153
int to_int(std::string s)
Converts a string of digits to an int using atoi().
Definition: utils.cpp:74
virtual const char * what() const
Creates a helpful error message.
Definition: utils.h:165
std::string to_upper(std::string s)
switches endftod to fast cpp version
Definition: utils.cpp:151
double slope(double x2, double y2, double x1, double y1)
Finds the slope of a line from the points (x1, y1) and (x2, y2).
Definition: utils.cpp:288
FileNotFound(std::string fname)
constructor with the filename fname.
Definition: utils.h:159
std::string capitalize(std::string s)
Returns a capitalized copy of the string.
Definition: utils.cpp:166
void warning(std::string s)
Prints a warning message.
Definition: utils.cpp:348
A container representing enrichment cascades.
Definition: _atomic_data.h:7
std::string replace_all_substrings(std::string s, std::string substr, std::string repstr)
Replaces all instance of substr in s with repstr.
Definition: utils.cpp:216
bool file_exists(std::string strfilename)
Returns true if the file can be found.
Definition: utils.cpp:311
void pyne_start()
Initializes PyNE based on environment.
Definition: utils.cpp:16
double(* endftod)(char *s)
endftod function pointer. defaults to fortran
Definition: utils.cpp:145
std::string remove_characters(std::string s, std::string chars)
Removes all characters in the string chars from s.
Definition: utils.cpp:207
double solve_line(double x, double x2, double y2, double x1, double y1)
Definition: utils.cpp:294
double tanh(double x)
The hyperbolic tangent function.
Definition: utils.cpp:299
std::string remove_substring(std::string s, std::string substr)
Creates a copy of s with all instances of substr taken out.
Definition: utils.cpp:196