35#include <sys/select.h>
37#include <sys/socket.h>
38#include <netinet/in.h>
67#if defined(__unix__) || defined(__unix) || defined(unix) || (defined(__APPLE__) && defined(__MACH__))
69#include <sys/resource.h>
70#if defined(__APPLE__) && defined(__MACH__)
72#elif (defined(_AIX) || defined(__TOS__AIX__)) || (defined(__sun__) || defined(__sun) || defined(sun) && (defined(__SVR4) || defined(__svr4__)))
75#elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
85#define G_XML2STR "gammalib::xml2str(std::string&)"
86#define G_HTTP_QUERY "gammalib::http_query(str::string&, std::string&)"
89#define G_PARFORMAT_LENGTH 29
90#define G_CHAR_BUFFER 256
114 const std::string& chars)
123 std::string::size_type start = arg.find_first_not_of(chars);
124 std::string::size_type stop = arg.find_last_not_of(chars);
127 if (start != std::string::npos && stop != std::string::npos) {
131 result = arg.substr(start, stop-start+1);
151 const std::string& chars)
160 std::string::size_type stop = arg.find_last_not_of(chars);
163 if (stop != std::string::npos) {
164 result = arg.substr(0, stop+1);
188 const std::string& segment,
189 const std::string& replacement)
192 std::string result = arg;
195 std::string::size_type pos = 0;
196 std::string::size_type start = 0;
199 while (start != std::string::npos) {
200 start = result.find(segment, pos);
201 if (start != std::string::npos) {
202 result = result.replace(start, segment.length(), replacement);
203 pos = start + replacement.length();
236 static const char* begin_delim[] = {
"$ENV{",
"$ENV(",
"${",
"$(",
"$",
"~" };
237 static const char* end_delim[] = {
"}",
")",
"}",
")",
"/",
"/" };
238 static const int num_delim = 6;
241 std::string result = arg;
245 bool in_quote =
false;
248 while (index < result.length()) {
252 if (result[index] ==
'\\') {
258 if (result[index] ==
'\'') {
259 in_quote = !in_quote;
272 size_t begin_length = 0;
274 for (; delim_idx < num_delim; ++delim_idx) {
275 size_t len = std::strlen(begin_delim[delim_idx]);
276 if (result.compare(index, len, begin_delim[delim_idx]) == 0) {
283 if (begin_length > 0) {
291 size_t i_start = index + begin_length;
292 size_t i_end = i_start;
293 size_t end_length = 0;
294 if (delim_idx == 4 || delim_idx == 5) {
295 while (i_end < result.length() &&
296 result.compare(i_end, 1,
"/") != 0 &&
297 result.compare(i_end, 1,
" ") != 0) {
302 end_length = std::strlen(end_delim[delim_idx]);
303 while (i_end < result.length() &&
304 result.compare(i_end, end_length, end_delim[delim_idx]) != 0) {
311 if (i_end < result.length() || delim_idx == 4) {
314 std::string name = result.substr(i_start, i_end-i_start);
315 size_t name_length = name.length();
318 const char* env = NULL;
321 if (delim_idx == 5) {
322 if (name_length == 0) {
323 if ((env = std::getenv(
"HOME")) == NULL) {
324 struct passwd *pw = getpwuid(getuid());
332 env = std::getenv(
"PWD");
334 else if (name ==
"-") {
335 env = std::getenv(
"OLDPWD");
338 struct passwd *pw = getpwnam(name.c_str());
348 env = std::getenv(name.c_str());
356 result.erase(index, begin_length+name_length+end_length);
359 std::string replace(env);
360 size_t replace_length = replace.length();
363 result.insert(index, replace);
366 index += replace_length;
413 const std::string& filename)
419 if (pathname.empty()) {
425 filepath = pathname +
"/" + filename;
443 char default_tmpdir[] =
"/tmp";
448 if ((tmpdir = std::getenv(
"TEMP")) == NULL) {
449 if ((tmpdir = std::getenv(
"TMP")) == NULL) {
450 if ((tmpdir = std::getenv(
"TMPDIR")) == NULL) {
451 tmpdir = default_tmpdir;
461 strcat(filename, tmpdir);
462 strcat(filename,
"/gammalibXXXXXX");
465 int fd = mkstemp(filename);
466 std::string tmpname(filename);
490 const char* ptr = std::getenv(arg.c_str());
494 env = std::string(ptr);
510 std::ostringstream s_value;
512 return s_value.str();
524 std::ostringstream s_value;
526 return s_value.str();
538 std::ostringstream s_value;
540 return s_value.str();
552 std::ostringstream s_value;
554 return s_value.str();
566 std::ostringstream s_value;
568 return s_value.str();
588 std::string str_buffer(buffer);
603 std::ostringstream s_value;
605 return s_value.str();
617 std::ostringstream s_value;
619 return s_value.str();
637 std::ostringstream s_value;
642 s_value.precision(precision);
643 s_value.setf(std::ios::fixed, std::ios::floatfield);
646 s_value.precision(7);
653 std::string result = s_value.str();
674 std::ostringstream s_value;
679 s_value.precision(precision);
680 s_value.setf(std::ios::fixed, std::ios::floatfield);
683 s_value.precision(15);
690 std::string result = s_value.str();
708 const int& precision)
711 std::ostringstream s_value;
716 s_value.precision(precision);
717 s_value.setf(std::ios::fixed, std::ios::floatfield);
720 s_value.precision(15);
724 s_value << value.real();
725 if (value.imag() < 0.0) {
731 s_value << std::abs(value.imag()) <<
"j";
734 std::string result = s_value.str();
749 struct std::tm timeStruct;
754 now = std::time(NULL);
756 std::gmtime_r(&now, &timeStruct);
758 std::memcpy(&timeStruct, gmtime(&now),
sizeof(
struct tm));
762 std::snprintf(buffer, 100,
"%04d-%02d-%02dT%02d:%02d:%02d",
763 timeStruct.tm_year + 1900,
764 timeStruct.tm_mon + 1,
771 std::string date = buffer;
786 std::istringstream iss(arg);
788 iss >> std::dec >> result;
801 std::istringstream iss(arg);
802 unsigned short result;
803 iss >> std::dec >> result;
816 std::istringstream iss(arg);
818 iss >> std::dec >> result;
831 std::istringstream iss(arg);
833 iss >> std::dec >> result;
846 std::istringstream iss(arg);
848 iss >> std::dec >> result;
861 std::istringstream iss(arg);
862 unsigned long result;
863 iss >> std::dec >> result;
876 std::istringstream iss(arg);
878 iss >> std::dec >> result;
891 std::istringstream iss(arg);
892 unsigned long long result;
893 iss >> std::dec >> result;
906 std::istringstream iss(arg);
908 iss >> std::dec >> result;
921 std::istringstream iss(arg);
923 iss >> std::dec >> result;
937 std::transform(s.begin(), s.end(), s.begin(), ::toupper);
951 std::transform(s.begin(), s.end(), s.begin(), ::tolower);
977 const std::string& sep)
980 std::vector<std::string> result;
984 std::size_t len = s.length();
987 while (pos < len && pos != std::string::npos) {
991 std::size_t index = s.find_first_of(sep, pos);
992 std::size_t n = std::string::npos;
996 if (index != std::string::npos) {
1004 if (sep !=
" " && n == 0) {
1005 result.push_back(
"");
1008 result.push_back(s.substr(pos, n));
1012 pos = (index != std::string::npos) ? index + 1 : std::string::npos;
1017 if (sep !=
" " && pos == len) {
1018 result.push_back(
"");
1040 std::string result =
"";
1043 for (
int i = 0; i < n; ++i) {
1066 int n_right = n - s.length();
1069 std::string result = s +
fill(std::string(1,c), n_right);
1090 int n_left = n - s.length();
1093 std::string result =
fill(std::string(1,c), n_left) + s;
1114 int n_right = (n-s.length()) / 2;
1115 int n_left = n - s.length() - n_right;
1118 std::string result =
fill(std::string(1,c), n_left) + s +
1119 fill(std::string(1,c), n_right);
1143 std::string result =
" " + s +
" " +
fill(
".", n_right) +
": ";
1163 std::string result(noun);
1231 const double& epivot,
const double& gamma)
1241 double exponent = gamma + 1.0;
1242 if (std::abs(exponent) > 1.0e-11) {
1243 double xmin = emin / epivot;
1244 double xmax = emax / epivot;
1245 flux = epivot / exponent * (std::pow(xmax, exponent) -
1246 std::pow(xmin, exponent));
1249 double ratio = emax / emin;
1250 flux = epivot * std::log(ratio);
1279 const double& epivot,
const double& gamma)
1289 double exponent = gamma + 2.0;
1290 double epivot2 = epivot * epivot;
1291 if (std::abs(exponent) > 1.0e-11) {
1292 double xmin = emin / epivot;
1293 double xmax = emax / epivot;
1294 flux = epivot2 / exponent * (std::pow(xmax, exponent) -
1295 std::pow(xmin, exponent));
1298 double ratio = emax / emin;
1299 flux = epivot2 * (std::log(ratio));
1326 elogmean.
MeV(std::pow(10.0, 0.5 * (eloga + elogb)));
1345 bool result =
false;
1354 if (ret == 0 && S_ISDIR(info.st_mode)) {
1375 bool result =
false;
1378 if (
str.find(substring) != std::string::npos) {
1397 const std::string&
string)
1400 bool result = std::find(strings.begin(), strings.end(),
string) !=
1417 const std::string& message)
1420 #if defined(G_WARNINGS)
1423 std::string
warning =
"+++ WARNING in " + origin +
": " + message;
1426 std::cout <<
warning << std::endl;
1455 size_t length = arg.length();
1463 while (pos < length) {
1468 start = arg.find(
"&", pos);
1469 if (start != std::string::npos) {
1485 bool decoded =
false;
1489 result += arg.substr(start-len, len);
1493 stop = arg.find(
";", pos);
1496 if (stop != std::string::npos) {
1500 std::string cref = arg.substr(start+1, stop-start-1);
1501 len = cref.length();
1506 if (len >= 2 && cref[0] ==
'#') {
1508 if (cref[1] ==
'x') {
1509 number = (int)std::strtol(cref.substr(2,len-2).c_str(), NULL, 16);
1515 result.push_back((
char)
number);
1519 std::string msg =
"Could not extract number from "
1520 "numerical character reference &"+
1530 if (cref ==
"quot") {
1531 result.push_back((
char)34);
1534 else if (cref ==
"amp") {
1535 result.push_back((
char)38);
1538 else if (cref ==
"apos") {
1539 result.push_back((
char)39);
1542 else if (cref ==
"lt") {
1543 result.push_back((
char)60);
1546 else if (cref ==
"gt") {
1547 result.push_back((
char)62);
1582 result += arg.substr(pos, len);
1606 for (
int i = 0; i < arg.length(); ++i) {
1609 std::string character = arg.substr(i, 1);
1612 if (character ==
"\"") {
1613 character =
""";
1615 else if (character ==
"&") {
1616 character =
"&";
1618 else if (character ==
"'") {
1619 character =
"'";
1621 else if (character ==
"<") {
1624 else if (character ==
">") {
1629 result += character;
1656 for (
int i = 0; i < n; ++i) {
1658 if (element->
attribute(
"name") == name) {
1690 const std::string& name)
1702 for (
int i = 0; i < n; ++i) {
1704 if (element->
attribute(
"name") == name) {
1742 const std::string& name)
1754 for (
int i = 0; i < n; ++i) {
1756 if (element->
attribute(
"name") == name) {
1791 const std::string& name,
1792 const std::string& attribute)
1795 std::string value =
"";
1802 std::string msg =
"Attribute \""+attribute+
"\" not found in XML "
1803 "parameter \""+name+
"\". Please verify the XML "
1836 " child elements in XML file does not correspond "
1838 " elements. Please verify the XML format.";
1844 int npars = xml.
elements(
"parameter");
1846 std::string msg =
"Number of "+
gammalib::str(npars)+
" \"parameter\" "
1847 "child elements in XML file does not correspond to "
1849 " elements. Please verify the XML format.";
1872 const std::string& type)
1881 std::string msg =
"Model type \""+xml.
attribute(
"type")+
"\" is not "
1882 "the expected type \""+type+
"\". Please verify "
1907 const std::string& name,
1912 std::string msg =
"Parameter \""+name+
"\" not found in XML element."
1913 " Please verify the XML format.";
1917 std::string msg =
"Parameter \""+name+
"\" found "+
1919 " Please verify the XML format.";
1941 const std::string& filename)
1951 size_t access_length = fname.
path().length();
1956 if (access_length == 0) {
1957 if (xml_length > 0) {
1963 else if (fname.
path()[0] !=
'/') {
1967 if (access_length >= xml_length) {
1998 const std::string& filename)
2007 size_t access_length = fname.
path().length();
2009 if (xml_length > 0) {
2010 if (access_length == xml_length) {
2012 fname = fname.
file();
2015 else if (access_length > xml_length) {
2017 std::string relpath = fname.
path().substr(xml_length, access_length-xml_length);
2055 name = text->
text();
2060 ptr = node->
element(
"value", 0);
2064 value = text->
text();
2089 const std::string& tag,
2090 const std::string& name,
2091 const std::string& value)
2097 if (element->
name() == tag) {
2099 if (element->
attribute(name) == value) {
2106 if (result == NULL) {
2109 int elements = element->
elements();
2112 for (
int i = 0; i < elements; ++i) {
2121 if (result != NULL) {
2155 FD_SET(fd, &readset);
2159 if (timeout >= 1000) {
2160 tv.tv_sec = timeout/1000;
2165 tv.tv_usec = timeout*1000;
2169 int result = select(fd+1, &readset, NULL, NULL, &tv);
2175 else if (result > 0 && FD_ISSET(fd, &readset)) {
2181 if ((iof = fcntl(fd, F_GETFL, 0)) != -1) {
2182 fcntl(fd, F_SETFL, iof | O_NONBLOCK);
2186 result = ::recv(fd, buffer, len, flags);
2190 fcntl(fd, F_SETFL, iof);
2219 const double& cosdist,
const double& sindist,
2220 const double& roi,
const double& cosroi)
2227 if (rad > roi) arclength = 0.0;
2239 if (dist > roi) arclength = 0.0;
2245 double d = roi - dist;
2249 else if (rad <= d) {
2253 double cosrad = std::cos(rad);
2254 double sinrad = std::sin(rad);
2255 double cosang = (cosroi - cosdist*cosrad) / (sindist*sinrad);
2257 #if defined(G_CHECK_FOR_NAN)
2260 std::cout <<
"roi_arclength: NaN occured";
2261 std::cout <<
" rad=" << rad;
2262 std::cout <<
" sinrad=" << sinrad;
2263 std::cout <<
" cosrad=" << cosrad;
2264 std::cout <<
" sindist=" << sindist;
2265 std::cout <<
" cosdist=" << cosdist;
2266 std::cout <<
" cosang=" << cosang;
2267 std::cout << std::endl;
2304 bool identity =
false;
2308 identity = std::abs(a - b) <= std::abs(a * tol);
2312 else if (b != 0.0) {
2313 identity = std::abs(a - b) <= std::abs(b * tol);
2344 const int portno = 80;
2348 char response[4096];
2349 memset(message, 0,
sizeof(message));
2350 memset(response, 0,
sizeof(response));
2353 #if ((defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L) || \
2354 (defined __cplusplus && __cplusplus >= 201103L))
2355 std::snprintf(message,
sizeof(message),
"GET /%s HTTP/1.1\r\nHost: %s\r\n\r\n",
2356 query.c_str(), host.c_str());
2358 std::sprintf(message,
"GET /%s HTTP/1.1\r\nHost: %s\r\n\r\n",
2359 query.c_str(), host.c_str());
2363 int sockfd = socket(AF_INET, SOCK_STREAM, 0);
2365 std::string msg =
"Unable to open socket.";
2370 struct hostent* server = gethostbyname(host.c_str());
2371 if (server == NULL) {
2372 std::string msg =
"Unable to find host \""+host+
"\".";
2377 struct sockaddr_in serveraddr;
2378 memset(&serveraddr, 0,
sizeof(serveraddr));
2379 serveraddr.sin_family = AF_INET;
2380 memcpy(&serveraddr.sin_addr.s_addr, server->h_addr, server->h_length);
2381 serveraddr.sin_port = htons(portno);
2384 if (connect(sockfd, (
struct sockaddr*)&serveraddr,
sizeof(serveraddr)) < 0) {
2385 std::string msg =
"Unable to connect to socket for host \""+host+
"\".";
2390 write(sockfd, message, strlen(message));
2393 read(sockfd, response,
sizeof(response)-1);
2399 return std::string(response);
2403#if defined(G_USE_CURL)
2447 static std::string country;
2450 if (country.empty()) {
2456 if ((!force_query) && (access(filename.
url().c_str(), R_OK) == 0)) {
2459 #pragma omp critical(GammaLib_host_country)
2464 lock.l_type = F_RDLCK;
2465 lock.l_whence = SEEK_SET;
2468 lock.l_pid = getpid();
2469 int fd = open(filename.
url().c_str(), O_RDONLY);
2473 fcntl(fd, F_SETLKW, &lock);
2477 FILE* fptr = fopen(filename.
url().c_str(),
"r");
2485 fgets(line, n-1, fptr);
2496 lock.l_type = F_UNLCK;
2497 fcntl(fd, F_SETLK, &lock);
2513 #if defined(G_USE_CURL)
2514 #if defined(G_HAS_CURL)
2519 #if defined(G_HAS_PERL)
2520 sprintf(command,
"a=$(perl -e 'alarm shift; exec \"curl --silent"
2521 " http://ip-api.com/line/?fields=countryCode"
2522 " 2>/dev/null\"' \"1\";);echo $a");
2523 #elif defined(G_HAS_TIMEOUT)
2524 sprintf(command,
"timeout 1s curl --silent http://ip-api.com/line/"
2525 "?fields=countryCode 2>/dev/null");
2527 sprintf(command,
"curl --silent http://ip-api.com/line/?fields=countryCode"
2532 FILE* file = popen(command,
"r");
2536 if (fgets(output,
sizeof(output)-1, file) != NULL) {
2547 std::string response =
http_query(
"ip-api.com",
"line/?fields=countryCode");
2548 std::vector<std::string> lines =
split(response,
"\n");
2550 for (
int i = 0; i < lines.size(); ++i) {
2555 if ((lines[i] ==
"\n") || (lines[i] ==
"\r") || (lines[i] ==
" ")) {
2560 catch (
const std::exception& e) {
2567 if (country.length() == 2) {
2570 #pragma omp critical(GammaLib_host_country)
2575 FILE* fptr = fopen(filename.
url().c_str(),
"w");
2577 fprintf(fptr,
"%s\n", country.c_str());
2608 uid_t uid = geteuid();
2609 struct passwd* pw = getpwuid(uid);
2611 filename = std::string(pw->pw_dir) +
"/.gamma/" + name;
2618 char* home_ptr = std::getenv(
"HOME");
2619 if (home_ptr != NULL) {
2620 filename = std::string(home_ptr) +
"/.gamma/" + name;
2625 filename =
"~/.gamma/" + name;
2646 #if defined(__APPLE__) && defined(__MACH__)
2647 #ifdef MACH_TASK_BASIC_INFO
2648 struct mach_task_basic_info info;
2649 mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
2650 if (task_info(mach_task_self( ), MACH_TASK_BASIC_INFO,
2651 (task_info_t)&info, &infoCount) == KERN_SUCCESS) {
2652 rss = (size_t)info.resident_size;
2655 struct task_basic_info info;
2656 mach_msg_type_number_t info_count = TASK_BASIC_INFO_COUNT;
2657 if (task_info(mach_task_self(), TASK_BASIC_INFO,
2658 (task_info_t)&info, &info_count) == KERN_SUCCESS) {
2659 rss = (size_t)info.resident_size;
2663 #elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
2665 if ((fp = fopen(
"/proc/self/statm",
"r" )) != NULL) {
2666 if (fscanf( fp,
"%*s%ld", &rss ) == 1) {
2667 rss *= (size_t)sysconf(_SC_PAGESIZE);
2690 double time = omp_get_wtime();
2692 double time = double(clock()) / (double)CLOCKS_PER_SEC;
Energy value class definition.
Exception handler interface definition.
Filename class interface definition.
FITS file class interface definition.
Mathematical function definitions.
XML element node class interface definition.
Abstract XML node base class interface definition.
XML text node class interface definition.
Class that handles energies in a unit independent way.
double MeV(void) const
Return energy in MeV.
double log10MeV(void) const
Return log10 of energy in MeV.
std::string path(void) const
Return access path.
std::string file(void) const
Return name of file.
std::string url(void) const
Return Uniform Resource Locator (URL)
bool is_empty(void) const
Signal if filename is empty.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
bool has_attribute(const std::string &name) const
Check if element has a given attribute.
const std::string & name(void) const
Return XML element name.
Abstract XML node base class.
virtual GXmlNode * append(const GXmlNode &node)
Append XML child node.
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
GFilename filename(void) const
Return filename of XML file.
virtual int elements(void) const
Return number of GXMLElement children of node.
const std::string & text(void) const
Return text.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
std::string number(const std::string &noun, const int &number)
Convert singular noun into number noun.
GFilename gamma_filename(const std::string &name)
Returns filename in .gamma directory.
bool is_infinite(const double &x)
Signal if argument is infinite.
double plaw_photon_flux(const double &emin, const double &emax, const double &epivot, const double &gamma)
Compute photon flux between two energies for a power law.
std::string strdate(void)
Return current date.
std::string http_query(const std::string &host, const std::string &query)
Return response to a HTTP query.
bool is_notanumber(const double &x)
Signal if argument is not a number.
GEnergy elogmean(const GEnergy &a, const GEnergy &b)
Computes log mean energy.
long tolong(const std::string &arg)
Convert string into long value.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
const GXmlElement * xml_get_par(const std::string &origin, const GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
double todouble(const std::string &arg)
Convert string into double precision value.
std::string xml_get_attr(const std::string &origin, const GXmlElement &xml, const std::string &name, const std::string &attribute)
Return attribute value for a given parameter in XML element.
std::string order(const int &number)
Convert number into order noun.
std::string left(const std::string &s, const int &n, const char &c=' ')
Left justify string to achieve a length of n characters.
bool compare(const double &a, const double &b, const double &tol)
Compare two floating point values with tolerance.
std::string right(const std::string &s, const int &n, const char &c=' ')
Right justify string to achieve a length of n characters.
std::string replace_segment(const std::string &arg, const std::string &segment, const std::string &replacement)
Replace string segment in string.
std::string filepath(const std::string &pathname, const std::string &filename)
Build file path from path name and file name.
std::string tolower(const std::string &s)
Convert string to lower case.
unsigned long long toulonglong(const std::string &arg)
Convert string into unsigned long long value.
int toint(const std::string &arg)
Convert string into integer value.
GXmlElement * xml_need_par(const std::string &origin, GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
std::string rstrip_chars(const std::string &arg, const std::string &chars)
Strip trailing character from string.
std::string xml2str(const std::string &arg)
Convert XML character references in string to characters.
GFilename xml_file_reduce(const GXmlElement &xml, const std::string &filename)
Reduce file name provided for writing as XML attribute.
std::string strip_whitespace(const std::string &arg)
Strip leading and trailing whitespace from string.
std::string str2xml(const std::string &arg)
Convert special characters in string to XML character references.
double roi_arclength(const double &rad, const double &dist, const double &cosdist, const double &sindist, const double &roi, const double &cosroi)
Returns length of circular arc within circular ROI.
float tofloat(const std::string &arg)
Convert string into single precision value.
std::string expand_env(const std::string &arg)
Expand environment variables in string.
unsigned long toulong(const std::string &arg)
Convert string into unsigned long value.
bool dir_exists(const std::string &dirname)
Checks if directory exists.
unsigned int touint(const std::string &arg)
Convert string into unsigned integer value.
bool contains(const std::string &str, const std::string &substring)
Checks if a substring is in a string.
std::string host_country(const bool &force_query=false)
Return two-digit host country code.
short toshort(const std::string &arg)
Convert string into short value.
double get_current_clock(void)
Get current clock in seconds.
double acos(const double &arg)
Computes acos by avoiding NaN due to rounding errors.
std::string centre(const std::string &s, const int &n, const char &c=' ')
Centre string to achieve a length of n characters.
void xml_check_parnum(const std::string &origin, const GXmlElement &xml, const int &number)
Checks number of parameters.
std::string tmpnam(void)
Return temporary file name.
void xml_get_name_value_pair(const GXmlNode *node, std::string &name, std::string &value)
Extract name / value pair from XML node.
void warning(const std::string &origin, const std::string &message)
Emits warning.
const GXmlElement * xml_get_element_by_attribute(const GXmlElement *element, const std::string &tag, const std::string &name, const std::string &value)
Return XML element for a given tag and name/value attribute.
unsigned short toushort(const std::string &arg)
Convert string into unsigned short value.
double plaw_energy_flux(const double &emin, const double &emax, const double &epivot, const double &gamma)
Compute energy flux between two energies for a power law.
std::string fill(const std::string &s, const int &n)
Fill string with n strings of same type.
std::string getenv(const std::string &arg)
Return value of environment variable.
bool xml_has_par(const GXmlElement &xml, const std::string &name)
Checks if parameter with given name in XML element exists.
void xml_check_par(const std::string &origin, const std::string &name, const int &number)
Checks whether a parameter has occured once.
std::vector< std::string > split(const std::string &s, const std::string &sep)
Split string.
int recv(int fd, char *buffer, int len, int flags, int timeout)
Checks whether a parameter has occured once.
std::string toupper(const std::string &s)
Convert string to upper case.
GFilename xml_file_expand(const GXmlElement &xml, const std::string &filename)
Expand file name provided as XML attribute for loading.
long long tolonglong(const std::string &arg)
Convert string into long long value.
void xml_check_type(const std::string &origin, GXmlElement &xml, const std::string &type)
Checks the model type.
std::string strip_chars(const std::string &arg, const std::string &chars)
Strip leading and trailing character from string.
size_t get_current_rss(void)
Get current resident set size (physical memory use) in Bytes.