GWOLLUM  4.2.0
Tools for gravitational-wave analyses
CUtils.h
Go to the documentation of this file.
1 
6 #ifndef __CUtils__
7 #define __CUtils__
8 
9 #include "Config.h"
10 
11 #define GOLDENNUMBER 1.6180339887498949025257388711906969547271728515625
12 #define LN2 0.6931471805599453094172321214581766
13 #define LN10 2.30258509299404590109361379290930926799774169921875
14 #define SQRT2 1.4142135623730951454746218587388284504413604736328125
15 #define PIOVERTWO 1.5707963267948965579989817342720925807952880859375
17 using namespace std;
18 
22 static stringstream gwl_ss;
23 
33 int GwlPrintVersion(void);
34 
40 inline bool IsPowerOfTwo(unsigned int x){
41  return ((x != 0) && !(x & (x - 1)));
42 };
43 
48 inline unsigned int NextPowerOfTwo(double x){
49  return (unsigned int)pow(2.0, ceil(log(x)/log(2.0)));
50 };
51 
60 double medianbiasfactor(const unsigned int nn);
61 
69 double GetMedian(const unsigned int aSize, double *aVect);
70 
80 vector<string> SplitString(const string stringtodivide, const char separator=' ');
81 
86 string StringToUpper(string stringtoconvert);
87 
95 inline string GetFileNameFromPath(const string filepathname){
96  return filepathname.substr(filepathname.find_last_of("/")+1);
97 };
98 
107 string ReplaceAll(string str, const string& from, const string& to);
108 
117 bool ListDirectories(vector <string> &subdir, const string maindir);
118 
126 inline bool CreateDirectory(error_code& aErrorCode, const string aPath){
127  if(filesystem::is_directory(aPath, aErrorCode)) return true;
128  return filesystem::create_directories(aPath, aErrorCode);
129 };
130 
138 inline unsigned int RemoveFileOrDirectory(error_code& aErrorCode, const string aPath){
139  return (unsigned int)filesystem::remove_all(aPath, aErrorCode);
140 };
141 
150 bool CopyFile(error_code& aErrorCode, const string aFrom, const string aTo, const bool aOverwrite=false);
151 
157 vector<string> Glob(const char* pattern);
158 
164 double* GetTukeyWindow(const unsigned int aSize, const double aAlpha);
165 
177 void MakeStereoSoundFile(const string aFileName, const unsigned int aN, const unsigned int aSamplingRate,
178  double *aAmplitudeLeft, double *aAmplitudeRight,
179  const double aScale=1.0, const int aOffset=0);
180 
181 #endif
182 
183 
string ReplaceAll(string str, const string &from, const string &to)
Replaces all occurences of a sub-string by another sub-string.
Definition: CUtils.cc:150
bool IsPowerOfTwo(unsigned int x)
Tests if an integer is a power of 2.
Definition: CUtils.h:40
vector< string > Glob(const char *pattern)
C utility to extract a list of files.
Definition: CUtils.cc:220
bool CopyFile(error_code &aErrorCode, const string aFrom, const string aTo, const bool aOverwrite=false)
Copy a file to a destination.
Definition: CUtils.cc:175
string GetFileNameFromPath(const string filepathname)
Returns the file name given the file path.
Definition: CUtils.h:95
double medianbiasfactor(const unsigned int nn)
Returns the bias factor when computing a median with a finite number of samples.
Definition: CUtils.cc:86
unsigned int RemoveFileOrDirectory(error_code &aErrorCode, const string aPath)
Removes a file or a directory.
Definition: CUtils.h:138
double GetMedian(const unsigned int aSize, double *aVect)
Returns the median value of an array of doubles.
Definition: CUtils.cc:104
unsigned int NextPowerOfTwo(double x)
Returns the next power of 2.
Definition: CUtils.h:48
string StringToUpper(string stringtoconvert)
Transforms a string to uppercase.
Definition: CUtils.cc:140
int GwlPrintVersion(void)
Prints the version.
Definition: CUtils.cc:49
vector< string > SplitString(const string stringtodivide, const char separator=' ')
Splits a string into sub-strings.
Definition: CUtils.cc:115
bool CreateDirectory(error_code &aErrorCode, const string aPath)
Creates a directory.
Definition: CUtils.h:126
bool ListDirectories(vector< string > &subdir, const string maindir)
Returns a list of sub-directories.
Definition: CUtils.cc:161
double * GetTukeyWindow(const unsigned int aSize, const double aAlpha)
Returns a Tukey window.
Definition: CUtils.cc:239
void MakeStereoSoundFile(const string aFileName, const unsigned int aN, const unsigned int aSamplingRate, double *aAmplitudeLeft, double *aAmplitudeRight, const double aScale=1.0, const int aOffset=0)
C utility to generate a WAV file.
Definition: CUtils.cc:268