libatomprobe
Library for Atom Probe Tomography (APT) computation
helpFuncs.h
Go to the documentation of this file.
1 /* helpFuncs.h: Helper functions for libatomprobe
2  * Copyright (C) 2014 Daniel Haley
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 #ifndef ATOMPROBE_HELPFUNCS_H
18 #define ATOMPROBE_HELPFUNCS_H
19 
20 #include <cstdio>
21 #include <cmath>
22 
24 
25 #include <gsl/gsl_blas.h>
26 
27 namespace AtomProbe
28 {
29 #ifndef XOR
30 #define XOR(a,b) ((!(a)) ^ (!(b)))
31 #endif
32 
33 #ifndef ARRAYSIZE
34 #define ARRAYSIZE(f) (sizeof (f) / sizeof(*f))
35 #endif
36 
37 #if defined(__CYGWIN__) || defined(__MINGW__)
38  int isascii(int c);
39 #endif
40 
41 //Set new locale code. Must be followed by a popLocale call before completion
42 // Only one locale type can be pushed at a time this way
43 void pushLocale(const char *newLocale, int type);
44 
45 //Restore old locale code
46 void popLocale();
47 
49 {
50  public:
51  template<class T1, class T2>
52  bool operator()(const std::pair< T1, T2 > &p1, const std::pair<T1,T2> &p2) const
53  {
54  return p1.first< p2.first;
55  }
56 };
57 
59 {
60  public:
61  template<class T1, class T2>
62  bool operator()(const std::pair< T1, T2 > &p1, const std::pair<T1,T2> &p2) const
63  {
64  return p1.second< p2.second;
65  }
66 };
67 
68 //C file peek function
69 inline int fpeek(FILE *stream)
70 {
71  int c;
72 
73  c = fgetc(stream);
74  ungetc(c, stream);
75 
76  return c;
77 }
78 
80 {
81  public:
82  template<class T1, class T2>
83  bool operator()(const std::pair< T1, T2 > &p1, const std::pair<T1,T2> &p2) const
84  {
85  return p1.first> p2.first;
86  }
87 };
88 
89 bool getFilesize(const char *fname, size_t &size);
90 
91 //Print a GSL matrix to stdout
92 void gsl_print_matrix(const gsl_matrix *m);
93 
94 //Print a GSL vector to stdout
95 void gsl_print_vector(const gsl_vector *m);
96 
97 //Compute the determinant of a matrix
98 float gsl_determinant(const gsl_matrix *m);
99 
100 
101 
102 #if !defined(__WIN32__) && !defined(__WIN64)
103 //Confirm that the selected file is not a directory (posix-like systems only)
104 bool isNotDirectory(const char *filename);
105 #endif
106 
107 
108 #ifdef DEBUG
109 #ifndef TOL_EQ
110 #define TOL_EQ(a,b) ( fabs(a-b) < 1e-4)
111 #endif
112 
113 #define TOL_EQ_V(f,g,h) (fabs( (f) - (g)) < (h))
114 #endif
115 }
116 #endif
float gsl_determinant(const gsl_matrix *m)
Definition: helpFuncs.cpp:143
void gsl_print_matrix(const gsl_matrix *m)
Definition: helpFuncs.cpp:122
bool isNotDirectory(const char *filename)
Definition: helpFuncs.cpp:170
void pushLocale(const char *newLocale, int type)
Definition: helpFuncs.cpp:62
bool operator()(const std::pair< T1, T2 > &p1, const std::pair< T1, T2 > &p2) const
Definition: helpFuncs.h:52
bool getFilesize(const char *fname, size_t &size)
Definition: helpFuncs.cpp:107
void gsl_print_vector(const gsl_vector *v)
Definition: helpFuncs.cpp:134
void popLocale()
Definition: helpFuncs.cpp:96
int fpeek(FILE *stream)
Definition: helpFuncs.h:69
bool operator()(const std::pair< T1, T2 > &p1, const std::pair< T1, T2 > &p2) const
Definition: helpFuncs.h:62
bool operator()(const std::pair< T1, T2 > &p1, const std::pair< T1, T2 > &p2) const
Definition: helpFuncs.h:83