GWOLLUM 4.2.0
Tools for gravitational-wave analyses
Loading...
Searching...
No Matches
CUtils.h File Reference

Generic C utility functions. More...

#include "Config.h"
Include dependency graph for CUtils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define GOLDENNUMBER   1.6180339887498949025257388711906969547271728515625
 \((1+\sqrt{5})/2)\)
 
#define LN10   2.30258509299404590109361379290930926799774169921875
 \(\ln(10)\)
 
#define LN2   0.6931471805599453094172321214581766
 \(\ln(2)\)
 
#define PIOVERTWO   1.5707963267948965579989817342720925807952880859375
 \(\pi/2\)
 
#define SQRT2   1.4142135623730951454746218587388284504413604736328125
 \(\sqrt{2}\)
 

Functions

bool CopyFile (error_code &aErrorCode, const string aFrom, const string aTo, const bool aOverwrite=false)
 Copy a file to a destination.
 
bool CreateDirectory (error_code &aErrorCode, const string aPath)
 Creates a directory.
 
string GetFileNameFromPath (const string filepathname)
 Returns the file name given the file path.
 
double GetMedian (const unsigned int aSize, double *aVect)
 Returns the median value of an array of doubles.
 
double * GetTukeyWindow (const unsigned int aSize, const double aAlpha)
 Returns a Tukey window.
 
vector< string > Glob (const char *pattern)
 C utility to extract a list of files.
 
int GwlPrintVersion (void)
 Prints the version.
 
bool IsPowerOfTwo (unsigned int x)
 Tests if an integer is a power of 2.
 
bool ListDirectories (vector< string > &subdir, const string maindir)
 Returns a list of sub-directories.
 
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.
 
double medianbiasfactor (const unsigned int nn)
 Returns the bias factor when computing a median with a finite number of samples.
 
unsigned int NextPowerOfTwo (double x)
 Returns the next power of 2.
 
unsigned int RemoveFileOrDirectory (error_code &aErrorCode, const string aPath)
 Removes a file or a directory.
 
string ReplaceAll (string str, const string &from, const string &to)
 Replaces all occurences of a sub-string by another sub-string.
 
vector< string > SplitString (const string stringtodivide, const char separator=' ')
 Splits a string into sub-strings.
 
string StringToUpper (string stringtoconvert)
 Transforms a string to uppercase.
 

Detailed Description

Generic C utility functions.

Author
Florent Robinet - florent.robinet@ijclab.in2p3.fr

Macro Definition Documentation

◆ GOLDENNUMBER

#define GOLDENNUMBER   1.6180339887498949025257388711906969547271728515625

\((1+\sqrt{5})/2)\)

◆ LN10

#define LN10   2.30258509299404590109361379290930926799774169921875

\(\ln(10)\)

◆ LN2

#define LN2   0.6931471805599453094172321214581766

\(\ln(2)\)

◆ PIOVERTWO

#define PIOVERTWO   1.5707963267948965579989817342720925807952880859375

\(\pi/2\)

◆ SQRT2

#define SQRT2   1.4142135623730951454746218587388284504413604736328125

\(\sqrt{2}\)

Function Documentation

◆ CopyFile()

bool CopyFile ( error_code &  aErrorCode,
const string  aFrom,
const string  aTo,
const bool  aOverwrite = false 
)

Copy a file to a destination.

Returns
true if the copy operation is successful, false otherwise.
Parameters
[out]aErrorCodePlatform-dependent error code: see std::error_code.
[in]aFromPath to the original file. It must exist.
[in]aToPath to destination. This can be either a directory or a file path.
[in]aOverwriteSet this flag to true to overwrite the destimation if the file already exists.

◆ CreateDirectory()

bool CreateDirectory ( error_code &  aErrorCode,
const string  aPath 
)
inline

Creates a directory.

This is equivalent to mkdir -p.

Returns
true if the directory is successfully created, false otherwise.
Parameters
[out]aErrorCodePlatform-dependent error code: see std::error_code.
[in]aPathPath to directory to create.

◆ GetFileNameFromPath()

string GetFileNameFromPath ( const string  filepathname)
inline

Returns the file name given the file path.

For example "myprog.exe" is returned from:

  • the full path "/usr/bin/myprog.exe"
  • the relative path "./bin/myprog.exe"
    Parameters
    [in]filepathnameFile path.

◆ GetMedian()

double GetMedian ( const unsigned int  aSize,
double *  aVect 
)

Returns the median value of an array of doubles.

The input vector is sorted. Then the median value is returned.

Parameters
[in]aSizeArray size.
[in,out]aVectPointer to the input array. The array values are sorted after calling this function.
Precondition
The size of the input vector is expected to be non 0.

◆ GetTukeyWindow()

double * GetTukeyWindow ( const unsigned int  aSize,
const double  aAlpha 
)

Returns a Tukey window.

Parameters
[in]aSizeWindow size.
[in]aAlphaTotal fraction of the window used to transition from 0 to 1 and 1 to 0. =0: rectangle, =1: HAnn window.

◆ Glob()

vector< string > Glob ( const char *  pattern)

C utility to extract a list of files.

Returns
A list of sorted files matching a pattern.
Parameters
[in]patternFile pattern.

◆ GwlPrintVersion()

int GwlPrintVersion ( void  )

Prints the version.

This function also checks the GWOLLUM environment:

  • A temp directory must esist.
  • $GWOLLUM_DATA must point to an existing directory.
  • $GWOLLUM_PIX must point to an existing directory.
Returns
0 if the environment is correctly set.

◆ IsPowerOfTwo()

bool IsPowerOfTwo ( unsigned int  x)
inline

Tests if an integer is a power of 2.

Returns
true if this is the case.
Parameters
[in]xInteger to test.

◆ ListDirectories()

bool ListDirectories ( vector< string > &  subdir,
const string  maindir 
)

Returns a list of sub-directories.

The vector 'subdir' is filled with directories contained in 'maindir'

Note
The returned list of directories includes the main directory path.
Returns
false if the main directory does not exist.
Parameters
[out]subdirList of sub-directories.
[in]maindirPath to the main directory.

◆ MakeStereoSoundFile()

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.

Parameters
[in]aFileNameOutput .wav file name.
[in]aNNumber of samples.
[in]aSamplingRateSampling rate [Hz].
[in]aAmplitudeLeftAmplitudes for left audio.
[in]aAmplitudeRightAmplitudes for right audio.
[in]aScaleScale factor ("volume") applied to amplitudes.
[in]aOffsetOffset applied to the number of samples.
Precondition
The size of the amplitude array should match the number of samples.

◆ medianbiasfactor()

double medianbiasfactor ( const unsigned int  nn)

Returns the bias factor when computing a median with a finite number of samples.

The bias factor is (see Eq. B12 in gr-qc/0509116):

\[ \alpha = \sum_{l=1}^{n}{\frac{(-1)^{l+1}}{l}}. \]

Parameters
[in]nnNumber of samples \(n\).

◆ NextPowerOfTwo()

unsigned int NextPowerOfTwo ( double  x)
inline

Returns the next power of 2.

Parameters
[in]xValue from which to get the next power of 2.

◆ RemoveFileOrDirectory()

unsigned int RemoveFileOrDirectory ( error_code &  aErrorCode,
const string  aPath 
)
inline

Removes a file or a directory.

Returns
The number of files and directories that were deleted (which may be 0 if the target did not exist to begin with).
Note
Symlinks are not followed (symlink is removed, not its target).
Parameters
[out]aErrorCodePlatform-dependent error code: see std::error_code.
[in]aPathPath to the file/directory to remove.

◆ ReplaceAll()

string ReplaceAll ( string  str,
const string &  from,
const string &  to 
)

Replaces all occurences of a sub-string by another sub-string.

All occurences of substring 'from' are replaced by 'to'.

Returns
The modified string is returned.
Parameters
[in]strString to modify.
[in]fromSubstring to replace from.
[in]toSubstring to replace to.

◆ SplitString()

vector< string > SplitString ( const string  stringtodivide,
const char  separator = ' ' 
)

Splits a string into sub-strings.

A string is divided into an array of words. The separator defines where to break the string. The separator should be a single character.

Returns
A vector of string.
Parameters
[in]stringtodivideString to divide.
[in]separatorSeparator.

◆ StringToUpper()

string StringToUpper ( string  stringtoconvert)

Transforms a string to uppercase.

Parameters
[in]stringtoconvertString to transform.