include/GTools.hpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                       GTools.hpp - GammaLib tools                       *
00003  * ----------------------------------------------------------------------- *
00004  *  copyright (C) 2008-2016 by Juergen Knoedlseder                         *
00005  * ----------------------------------------------------------------------- *
00006  *                                                                         *
00007  *  This program is free software: you can redistribute it and/or modify   *
00008  *  it under the terms of the GNU General Public License as published by   *
00009  *  the Free Software Foundation, either version 3 of the License, or      *
00010  *  (at your option) any later version.                                    *
00011  *                                                                         *
00012  *  This program is distributed in the hope that it will be useful,        *
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00015  *  GNU General Public License for more details.                           *
00016  *                                                                         *
00017  *  You should have received a copy of the GNU General Public License      *
00018  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
00019  *                                                                         *
00020  ***************************************************************************/
00021 /**
00022  * @file GTools.hpp
00023  * @brief Gammalib tools definition
00024  * @author Juergen Knoedlseder
00025  */
00026 
00027 #ifndef GTOOLS_HPP
00028 #define GTOOLS_HPP
00029 
00030 /* __ Includes ___________________________________________________________ */
00031 #include <vector>
00032 #include <string>
00033 #include <complex>
00034 #include <cmath>
00035 #include <cfloat>
00036 
00037 /* __ Forward declarations _______________________________________________ */
00038 class GEnergy;
00039 class GFilename;
00040 class GXmlElement;
00041 
00042 /* __ Constants __________________________________________________________ */
00043 namespace gammalib {
00044     const double MeV2erg      =  1.6021765e-6;    // MeV => erg
00045     const double erg2MeV      =  624150.96;       // erg => MeV
00046     const double MeV2Angstrom =  1.239841875e-2;  // MeV => Angstrom
00047     const double pc2cm        =  3.08568025e18;   // pc => cm
00048     const double sec_in_day   = 86400.0;          // seconds per day
00049     const double sec2day      = 1.0 / sec_in_day; // seconds => days
00050     const double tai2tt       = 32.184;           // TAI => TT time system
00051 }
00052 
00053 /* __ Prototypes ________________________________________________________ */
00054 namespace gammalib {
00055     std::string              strip_whitespace(const std::string& arg);
00056     std::string              strip_chars(const std::string& arg,
00057                                          const std::string& chars);
00058     std::string              rstrip_chars(const std::string& arg,
00059                                           const std::string& chars);
00060     std::string              expand_env(const std::string& arg);
00061     std::string              filepath(const std::string& pathname,
00062                                       const std::string& filename);
00063     std::string              str(const unsigned short int& value);
00064     std::string              str(const unsigned int& value);
00065     std::string              str(const unsigned long int& value);
00066     std::string              str(const unsigned long long int& value);
00067     std::string              str(const short int& value);
00068     std::string              str(const int& value);
00069     std::string              str(const long int& value);
00070     std::string              str(const long long int& value);
00071     std::string              str(const float& value, const int& precision = 0);
00072     std::string              str(const double& value, const int& precision = 0);
00073     std::string              str(const std::complex<double>& value,
00074                                  const int& precision = 0);
00075     char*                    tochar(const std::string& arg);
00076     short                    toshort(const std::string& arg);
00077     unsigned short           toushort(const std::string& arg);
00078     int                      toint(const std::string& arg);
00079     unsigned int             touint(const std::string& arg);
00080     long                     tolong(const std::string& arg);
00081     unsigned long            toulong(const std::string& arg);
00082     long long                tolonglong(const std::string& arg);
00083     unsigned long long       toulonglong(const std::string& arg);
00084     float                    tofloat(const std::string& arg);
00085     double                   todouble(const std::string& arg);
00086     std::string              toupper(const std::string& s);
00087     std::string              tolower(const std::string& s);
00088     std::vector<std::string> split(const std::string& s, const std::string& sep);
00089     std::string              fill(const std::string& s, const int& n);
00090     std::string              left(const std::string& s, const int& n,
00091                                   const char& c = ' ');
00092     std::string              right(const std::string& s, const int& n,
00093                                    const char& c = ' ');
00094     std::string              centre(const std::string& s, const int& n,
00095                                     const char& c = ' ');
00096     std::string              parformat(const std::string& s, const int& indent = 0);
00097     std::string              number(const std::string& noun, const int& number);
00098     double                   plaw_photon_flux(const double& emin,
00099                                               const double& emax,
00100                                               const double& epivot,
00101                                               const double& gamma);
00102     double                   plaw_energy_flux(const double& emin,
00103                                               const double& emax,
00104                                               const double& epivot,
00105                                               const double& gamma);
00106     GEnergy                  elogmean(const GEnergy& a, const GEnergy& b);
00107     bool                     dir_exists(const std::string& dirname);
00108     bool                     is_infinite(const double& x);
00109     bool                     is_notanumber(const double& x);
00110     bool                     contains(const std::string& str,
00111                                       const std::string& substring);
00112     bool                     contains(const std::vector<std::string> strings,
00113                                       const std::string& string);
00114     void                     warning(const std::string& origin,
00115                                      const std::string& message);
00116     std::string              xml2str(const std::string& arg);
00117     std::string              str2xml(const std::string& arg);
00118     bool                     xml_has_par(const GXmlElement& xml,
00119                                          const std::string& name);
00120     GXmlElement*             xml_need_par(const std::string& origin,
00121                                           GXmlElement&       xml,
00122                                           const std::string& name);
00123     const GXmlElement*       xml_get_par(const std::string& origin,
00124                                          const GXmlElement& xml,
00125                                          const std::string& name);
00126     std::string              xml_get_attr(const std::string& origin,
00127                                           const GXmlElement& xml,
00128                                           const std::string& name,
00129                                           const std::string& attribute);
00130     void                     xml_check_par(const std::string& origin,
00131                                            const std::string& name,
00132                                            const int&         number);
00133     GFilename                xml_file_expand(const GXmlElement& xml,
00134                                              const std::string& filename);
00135     GFilename                xml_file_reduce(const GXmlElement& xml,
00136                                              const std::string& filename);
00137     int                      recv(int fd, char *buffer, int len, int flags,
00138                                   int timeout);
00139 }
00140 
00141 
00142 /***********************************************************************//**
00143  * @brief Signal if argument is infinite
00144  *
00145  * @param[in] x Argument.
00146  * @return True if argument @p x is infinite, false otherwise.
00147  *
00148  * Signals if the argument @p x is infinite.
00149  *
00150  * This function has been copied from gnulib.
00151  ***************************************************************************/
00152 inline
00153 bool gammalib::is_infinite(const double& x)
00154 {
00155     return (x < -DBL_MAX || x > DBL_MAX);
00156 }
00157 
00158 
00159 /***********************************************************************//**
00160  * @brief Signal if argument is not a number
00161  *
00162  * @param[in] x Argument.
00163  * @return True if argument @p x is not a number, false otherwise.
00164  *
00165  * Signals if the argument @p x is not a number.
00166  *
00167  * This function is a very simple kluge. It may not work on all systems.
00168  ***************************************************************************/
00169 inline
00170 bool gammalib::is_notanumber(const double& x)
00171 {
00172     return (x != x);
00173 }
00174 
00175 #endif /* GTOOLS_HPP */

Generated on Tue Jan 24 12:37:18 2017 for GammaLib by  doxygen 1.4.7