From 1bb34cdb5f4ecb24ce7fdb2d6935b07c3ba51d55 Mon Sep 17 00:00:00 2001
From: Thomas Fischer <thomas.fischer@ufz.de>
Date: Thu, 10 May 2012 10:07:10 +0200
Subject: [PATCH] moved the following sources within the BaseLib folder into
 the namespace BaseLib: - binarySearch - class CPUTime - class RunTime -
 methods/functions from DateTools.{h,cpp}

changes in GeoLib and in SimpleTests folder results from changing the namespace
---
 BaseLib/CPUTime.cpp                           | 27 ++++++++++++++++
 BaseLib/CPUTime.h                             | 32 +++++++++++++++++++
 BaseLib/CPUTimeTimer.cpp                      | 17 ----------
 BaseLib/CPUTimeTimer.h                        | 21 ------------
 BaseLib/DateTools.cpp                         |  4 +++
 BaseLib/DateTools.h                           |  4 +++
 BaseLib/{RunTimeTimer.cpp => RunTime.cpp}     | 19 ++++++++---
 BaseLib/{RunTimeTimer.h => RunTime.h}         | 19 ++++++++---
 BaseLib/binarySearch.cpp                      |  4 +++
 BaseLib/binarySearch.h                        |  4 +++
 GeoLib/Station.cpp                            |  4 +--
 SimpleTests/MatrixTests/MatMult.cpp           | 10 +++---
 .../MatrixTests/MatTestRemoveRowsCols.cpp     | 10 +++---
 .../MatrixTests/MatVecMultNDPermOpenMP.cpp    | 10 +++---
 SimpleTests/MatrixTests/MatVecMultPerm.cpp    | 10 +++---
 .../SolverTests/BiCGStabDiagPrecond.cpp       |  8 ++---
 ...onjugateGradientDiagonalPreconditioned.cpp |  8 ++---
 SimpleTests/SolverTests/GMResDiagPrecond.cpp  |  8 ++---
 18 files changed, 139 insertions(+), 80 deletions(-)
 create mode 100644 BaseLib/CPUTime.cpp
 create mode 100644 BaseLib/CPUTime.h
 delete mode 100644 BaseLib/CPUTimeTimer.cpp
 delete mode 100644 BaseLib/CPUTimeTimer.h
 rename BaseLib/{RunTimeTimer.cpp => RunTime.cpp} (60%)
 rename BaseLib/{RunTimeTimer.h => RunTime.h} (61%)

diff --git a/BaseLib/CPUTime.cpp b/BaseLib/CPUTime.cpp
new file mode 100644
index 00000000000..a442b9b79e1
--- /dev/null
+++ b/BaseLib/CPUTime.cpp
@@ -0,0 +1,27 @@
+/*
+ * CPUTime.cpp
+ *
+ *  Created on: May 10, 2012
+ *      Author: TF
+ */
+
+#include "CPUTime.h"
+
+namespace BaseLib {
+
+void CPUTime::start()
+{
+	_start = clock();
+}
+
+void CPUTime::stop()
+{
+	_stop = clock();
+}
+
+double CPUTime::elapsed()
+{
+	return (_stop-_start)/(double)(CLOCKS_PER_SEC);
+}
+
+} // end namespace BaseLib
diff --git a/BaseLib/CPUTime.h b/BaseLib/CPUTime.h
new file mode 100644
index 00000000000..7198c6d3ec2
--- /dev/null
+++ b/BaseLib/CPUTime.h
@@ -0,0 +1,32 @@
+/*
+ * CPUTime.h
+ *
+ *  Created on: May 10, 2012
+ *      Author: TF
+ */
+
+#ifndef CPUTIME_H
+#define CPUTIME_H
+
+#include <ctime>
+
+#include "TimeMeasurementBase.h"
+
+namespace BaseLib {
+
+class CPUTime
+{
+public:
+	virtual void start();
+    virtual void stop();
+    virtual double elapsed();
+	~CPUTime() {};
+private:
+	clock_t _start;
+	clock_t _stop;
+};
+
+} // end namespace BaseLib
+
+#endif
+
diff --git a/BaseLib/CPUTimeTimer.cpp b/BaseLib/CPUTimeTimer.cpp
deleted file mode 100644
index ad8377cd934..00000000000
--- a/BaseLib/CPUTimeTimer.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-#include "CPUTimeTimer.h"
-
-void CPUTimeTimer::start()
-{
-	_start = clock();
-}
-
-void CPUTimeTimer::stop()
-{
-	_stop = clock();
-}
-
-double CPUTimeTimer::elapsed()
-{
-	return (_stop-_start)/(double)(CLOCKS_PER_SEC);
-}
-
diff --git a/BaseLib/CPUTimeTimer.h b/BaseLib/CPUTimeTimer.h
deleted file mode 100644
index 8b5eb18b602..00000000000
--- a/BaseLib/CPUTimeTimer.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef CPUTIMETIMER_H
-#define CPUTIMETIMER_H
-
-#include <ctime>
-
-#include "TimeMeasurementBase.h"
-
-class CPUTimeTimer
-{
-public:
-        virtual void start();
-        virtual void stop();
-        virtual double elapsed();
-	~CPUTimeTimer() {};
-private:
-	clock_t _start;
-	clock_t _stop;
-};
-
-#endif
-
diff --git a/BaseLib/DateTools.cpp b/BaseLib/DateTools.cpp
index 4165c7c754f..c15b18ebf6c 100644
--- a/BaseLib/DateTools.cpp
+++ b/BaseLib/DateTools.cpp
@@ -10,6 +10,8 @@
 #include <cmath>
 #include <cstdlib>
 
+namespace BaseLib {
+
 double date2double(int y, int m, int d)
 {
 	if ( (y<1000 || y>9999) || (m<1 || m>12) || (d<1 || d>31) )
@@ -75,3 +77,5 @@ double xmlDate2double(const std::string &s)
 	}
 	return 0;
 }
+
+} // end namespace BaseLib
diff --git a/BaseLib/DateTools.h b/BaseLib/DateTools.h
index 33e965852e5..1427e6ac08c 100644
--- a/BaseLib/DateTools.h
+++ b/BaseLib/DateTools.h
@@ -9,6 +9,8 @@
 #include "StringTools.h"
 #include <string>
 
+namespace BaseLib {
+
 /**
  * Converts three integers representing a date into a double.
  * Note: It is not really checked if the date actually makes sense.
@@ -39,4 +41,6 @@ double strDate2double(const std::string &s);
  */
 double xmlDate2double(const std::string &s);
 
+} // namespace BaseLib
+
 #endif //DATETOOLS_H
diff --git a/BaseLib/RunTimeTimer.cpp b/BaseLib/RunTime.cpp
similarity index 60%
rename from BaseLib/RunTimeTimer.cpp
rename to BaseLib/RunTime.cpp
index 10599073b8e..d9652790f49 100644
--- a/BaseLib/RunTimeTimer.cpp
+++ b/BaseLib/RunTime.cpp
@@ -1,6 +1,15 @@
-#include "RunTimeTimer.h"
+/*
+ * RunTime.cpp
+ *
+ *  Created on: May 10, 2012
+ *      Author: TF
+ */
 
-void RunTimeTimer::start()
+#include "RunTime.h"
+
+namespace BaseLib {
+
+void RunTime::start()
 {
 #ifndef _WIN32
 	gettimeofday(&_start, 0);
@@ -9,7 +18,7 @@ void RunTimeTimer::start()
 #endif
 }
 
-void RunTimeTimer::stop()
+void RunTime::stop()
 {
 #ifndef _WIN32
 	gettimeofday(&_stop, 0);
@@ -18,7 +27,7 @@ void RunTimeTimer::stop()
 #endif
 }
 
-double RunTimeTimer::elapsed()
+double RunTime::elapsed()
 {
 #ifndef _WIN32
 	return (_stop.tv_sec + _stop.tv_usec/1000000.0 - (_start.tv_sec + _start.tv_usec/1000000.0));
@@ -26,3 +35,5 @@ double RunTimeTimer::elapsed()
 	return (_stop - _start) / 1000;
 #endif
 }
+
+} // end namespace BaseLib
diff --git a/BaseLib/RunTimeTimer.h b/BaseLib/RunTime.h
similarity index 61%
rename from BaseLib/RunTimeTimer.h
rename to BaseLib/RunTime.h
index ebd7d858d6f..8d282958829 100644
--- a/BaseLib/RunTimeTimer.h
+++ b/BaseLib/RunTime.h
@@ -1,5 +1,12 @@
-#ifndef RUNTIMETIMER_H
-#define RUNTIMETIMER_H
+/*
+ * RunTime.h
+ *
+ *  Created on: May 10, 2012
+ *      Author: TF
+ */
+
+#ifndef RUNTIME_H
+#define RUNTIME_H
 
 #include "TimeMeasurementBase.h"
 
@@ -11,13 +18,15 @@
 
 #include "TimeMeasurementBase.h"
 
-class RunTimeTimer : public TimeMeasurementBase
+namespace BaseLib {
+
+class RunTime : public TimeMeasurementBase
 {
 public:
 	virtual void start();
 	virtual void stop();
 	virtual double elapsed();
-	~RunTimeTimer() {};
+	~RunTime() {};
 private:
 #ifndef _WIN32
 	timeval _start;
@@ -28,4 +37,6 @@ private:
 #endif
 };
 
+} // end namespace BaseLib
+
 #endif
diff --git a/BaseLib/binarySearch.cpp b/BaseLib/binarySearch.cpp
index 7ecd110b79c..fe924fa339a 100644
--- a/BaseLib/binarySearch.cpp
+++ b/BaseLib/binarySearch.cpp
@@ -7,6 +7,8 @@
 
 #include "binarySearch.h"
 
+namespace BaseLib {
+
 size_t searchElement (double const& val, size_t beg, size_t end, const std::vector<double>& array)
 {
 	if (beg >= end) return std::numeric_limits<size_t>::max();
@@ -20,3 +22,5 @@ size_t searchElement (double const& val, size_t beg, size_t end, const std::vect
 	}
 	return searchElement (val, m+1, end, array);
 }
+
+} // end namespace BaseLib
diff --git a/BaseLib/binarySearch.h b/BaseLib/binarySearch.h
index 92148b228a0..039244f3e89 100644
--- a/BaseLib/binarySearch.h
+++ b/BaseLib/binarySearch.h
@@ -13,6 +13,8 @@
 #ifndef BINARYSEARCH_H_
 #define BINARYSEARCH_H_
 
+namespace BaseLib {
+
 /**
  * Binary search in a sorted vector of elements to get the
  * id of an element according its key.
@@ -40,4 +42,6 @@ size_t searchElement (const T& key, size_t beg, size_t end, const std::vector<T>
 
 size_t searchElement (double const& val, size_t beg, size_t end, const std::vector<double>& array);
 
+} // end namespace BaseLib
+
 #endif /* BINARYSEARCH_H_ */
diff --git a/GeoLib/Station.cpp b/GeoLib/Station.cpp
index 81a67b624b8..7736cf477dd 100644
--- a/GeoLib/Station.cpp
+++ b/GeoLib/Station.cpp
@@ -308,7 +308,7 @@ StationBorehole* StationBorehole::createStation(const std::string &line)
 			borehole->_date = 0;
 		else
 		{
-			borehole->_date = strDate2double(fields.front());
+			borehole->_date = BaseLib::strDate2double(fields.front());
 			fields.pop_front();
 		}
 	}
@@ -329,7 +329,7 @@ StationBorehole* StationBorehole::createStation(const std::string &name, double
 	(*station)[1]   = y;
 	(*station)[2]   = z;
 	station->_depth = depth;
-	if (date.compare("0000-00-00")) station->_date  = xmlDate2double(date);
+	if (date.compare("0000-00-00")) station->_date  = BaseLib::xmlDate2double(date);
 	return station;
 }
 
diff --git a/SimpleTests/MatrixTests/MatMult.cpp b/SimpleTests/MatrixTests/MatMult.cpp
index 569451bc8ed..bd51cd6676d 100644
--- a/SimpleTests/MatrixTests/MatMult.cpp
+++ b/SimpleTests/MatrixTests/MatMult.cpp
@@ -7,8 +7,8 @@
 #include "LinAlg/Sparse/CRSMatrix.h"
 #include "LinAlg/Sparse/CRSMatrixOpenMP.h"
 #include "LinAlg/Sparse/CRSMatrixPThreads.h"
-#include "RunTimeTimer.h"
-#include "CPUTimeTimer.h"
+#include "RunTime.h"
+#include "CPUTime.h"
 #include "logog.hpp"
 
 #ifdef _OPENMP
@@ -42,7 +42,7 @@ int main(int argc, char *argv[])
 	unsigned *iA(NULL), *jA(NULL), n;
 	if (in) {
 		DBUG("reading matrix from %s ...", fname_mat.c_str());
-		RunTimeTimer timer;
+		BaseLib::RunTime timer;
 		timer.start();
 		CS_read(in, n, iA, jA, A);
 		timer.stop();
@@ -69,8 +69,8 @@ int main(int argc, char *argv[])
 		x[k] = 1.0;
 
 	DBUG("matrix vector multiplication with Toms amuxCRS (%n threads) ...", n_threads);
-	RunTimeTimer run_timer;
-	CPUTimeTimer cpu_timer;
+	BaseLib::RunTime run_timer;
+	BaseLib::CPUTime cpu_timer;
 	run_timer.start();
 	cpu_timer.start();
 	for (size_t k(0); k<n_mults; k++) {
diff --git a/SimpleTests/MatrixTests/MatTestRemoveRowsCols.cpp b/SimpleTests/MatrixTests/MatTestRemoveRowsCols.cpp
index 0526308f936..446bb7c8bf1 100644
--- a/SimpleTests/MatrixTests/MatTestRemoveRowsCols.cpp
+++ b/SimpleTests/MatrixTests/MatTestRemoveRowsCols.cpp
@@ -8,9 +8,9 @@
 #include <fstream>
 #include <iostream>
 
-// Base
-#include "RunTimeTimer.h"
-#include "CPUTimeTimer.h"
+// BaseLib
+#include "RunTime.h"
+#include "CPUTime.h"
 
 // MathLib
 #include "LinAlg/Sparse/CRSMatrix.h"
@@ -33,7 +33,7 @@ int main(int argc, char *argv[])
 		if (verbose) {
 			std::cout << "reading matrix from " << fname_mat << " ... " << std::flush;
 		}
-		RunTimeTimer timer;
+		BaseLib::RunTime timer;
 		timer.start();
 		CS_read(in, n, iA, jA, A);
 		in.close();
@@ -58,7 +58,7 @@ int main(int argc, char *argv[])
 		rows_cols_to_erase[k] = (k+1)*2;
 	}
 
-	RunTimeTimer timer;
+	BaseLib::RunTime timer;
 	std::cout << "erasing " << n_rows_cols_to_erase << " rows and columns ... " << std::flush;
 	timer.start();
 	mat->eraseEntries(n_rows_cols_to_erase, rows_cols_to_erase);
diff --git a/SimpleTests/MatrixTests/MatVecMultNDPermOpenMP.cpp b/SimpleTests/MatrixTests/MatVecMultNDPermOpenMP.cpp
index 1947d62bd2b..4516c703829 100644
--- a/SimpleTests/MatrixTests/MatVecMultNDPermOpenMP.cpp
+++ b/SimpleTests/MatrixTests/MatVecMultNDPermOpenMP.cpp
@@ -8,8 +8,8 @@
 #include <cstdlib>
 
 // BaseLib
-#include "RunTimeTimer.h"
-#include "CPUTimeTimer.h"
+#include "RunTime.h"
+#include "CPUTime.h"
 
 // MathLib
 #include "sparse.h"
@@ -41,7 +41,7 @@ int main(int argc, char *argv[])
 		if (verbose) {
 			std::cout << "reading matrix from " << fname_mat << " ... " << std::flush;
 		}
-		RunTimeTimer timer;
+		BaseLib::RunTime timer;
 		timer.start();
 		CS_read(in, n, iA, jA, A);
 		timer.stop();
@@ -65,8 +65,8 @@ int main(int argc, char *argv[])
 		x[k] = 1.0;
 
 	// create time measurement objects
-	RunTimeTimer run_timer;
-	CPUTimeTimer cpu_timer;
+	BaseLib::RunTime run_timer;
+	BaseLib::CPUTime cpu_timer;
 
 	// calculate the nested dissection reordering
 	if (verbose) {
diff --git a/SimpleTests/MatrixTests/MatVecMultPerm.cpp b/SimpleTests/MatrixTests/MatVecMultPerm.cpp
index 7cd89662751..5598ea14349 100644
--- a/SimpleTests/MatrixTests/MatVecMultPerm.cpp
+++ b/SimpleTests/MatrixTests/MatVecMultPerm.cpp
@@ -8,8 +8,8 @@
 #include <cstdlib>
 
 // BaseLib
-#include "RunTimeTimer.h"
-#include "CPUTimeTimer.h"
+#include "RunTime.h"
+#include "CPUTime.h"
 
 // MathLib
 #include "sparse.h"
@@ -42,7 +42,7 @@ int main(int argc, char *argv[])
 		if (verbose) {
 			std::cout << "reading matrix from " << fname_mat << " ... " << std::flush;
 		}
-		RunTimeTimer timer;
+		BaseLib::RunTime timer;
 		timer.start();
 		CS_read(in, n, iA, jA, A);
 		timer.stop();
@@ -67,8 +67,8 @@ int main(int argc, char *argv[])
 		x[k] = 1.0;
 
 	// create time measurement objects
-	RunTimeTimer run_timer;
-	CPUTimeTimer cpu_timer;
+	BaseLib::RunTime run_timer;
+	BaseLib::CPUTime cpu_timer;
 
 	// calculate the nested dissection reordering
 	if (verbose) {
diff --git a/SimpleTests/SolverTests/BiCGStabDiagPrecond.cpp b/SimpleTests/SolverTests/BiCGStabDiagPrecond.cpp
index 43cf9cc247f..7946ec31de2 100644
--- a/SimpleTests/SolverTests/BiCGStabDiagPrecond.cpp
+++ b/SimpleTests/SolverTests/BiCGStabDiagPrecond.cpp
@@ -6,8 +6,8 @@
 #include "LinAlg/Sparse/CRSMatrixDiagPrecond.h"
 #include "sparse.h"
 #include "vector_io.h"
-#include "RunTimeTimer.h"
-#include "CPUTimeTimer.h"
+#include "RunTime.h"
+#include "CPUTime.h"
 
 #ifdef _OPENMP
 #include <omp.h>
@@ -59,8 +59,8 @@ int main(int argc, char *argv[])
 
 	double eps (1.0e-6);
 	unsigned steps (4000);
-	RunTimeTimer run_timer;
-	CPUTimeTimer cpu_timer;
+	BaseLib::RunTime run_timer;
+	BaseLib::CPUTime cpu_timer;
 	run_timer.start();
 	cpu_timer.start();
 
diff --git a/SimpleTests/SolverTests/ConjugateGradientDiagonalPreconditioned.cpp b/SimpleTests/SolverTests/ConjugateGradientDiagonalPreconditioned.cpp
index bfb4333f459..a79fe47c0f0 100644
--- a/SimpleTests/SolverTests/ConjugateGradientDiagonalPreconditioned.cpp
+++ b/SimpleTests/SolverTests/ConjugateGradientDiagonalPreconditioned.cpp
@@ -6,8 +6,8 @@
 #include "LinAlg/Sparse/CRSMatrixDiagPrecond.h"
 #include "sparse.h"
 #include "vector_io.h"
-#include "RunTimeTimer.h"
-#include "CPUTimeTimer.h"
+#include "RunTime.h"
+#include "CPUTime.h"
 
 #ifdef _OPENMP
 #include <omp.h>
@@ -59,8 +59,8 @@ int main(int argc, char *argv[])
 
 	double eps (1.0e-6);
 	unsigned steps (4000);
-	RunTimeTimer run_timer;
-	CPUTimeTimer cpu_timer;
+	BaseLib::RunTime run_timer;
+	BaseLib::CPUTime cpu_timer;
 	run_timer.start();
 	cpu_timer.start();
 
diff --git a/SimpleTests/SolverTests/GMResDiagPrecond.cpp b/SimpleTests/SolverTests/GMResDiagPrecond.cpp
index 41353a080ce..7062cb20993 100644
--- a/SimpleTests/SolverTests/GMResDiagPrecond.cpp
+++ b/SimpleTests/SolverTests/GMResDiagPrecond.cpp
@@ -11,8 +11,8 @@
 #include "LinAlg/Sparse/CRSMatrixDiagPrecond.h"
 #include "sparse.h"
 #include "vector_io.h"
-#include "RunTimeTimer.h"
-#include "CPUTimeTimer.h"
+#include "RunTime.h"
+#include "CPUTime.h"
 
 int main(int argc, char *argv[])
 {
@@ -56,8 +56,8 @@ int main(int argc, char *argv[])
 
 	double eps(1.0e-6);
 	unsigned steps(4000);
-	RunTimeTimer run_timer;
-	CPUTimeTimer cpu_timer;
+	BaseLib::RunTime run_timer;
+	BaseLib::CPUTime cpu_timer;
 	run_timer.start();
 	cpu_timer.start();
 
-- 
GitLab