From a0f07490e3f37236796c44d3d9b751b42d1d685a Mon Sep 17 00:00:00 2001 From: Joshua Moerman Date: Sat, 13 Nov 2010 20:41:02 +0100 Subject: [PATCH] added bash script to clean up code --- Attractor.hpp | 10 +++++----- AttractorKernel.cpp | 28 ++++++++++++++-------------- AttractorKernel.hpp | 14 +++++++------- attractors/testUnravelNew.stf | 2 +- cleanCode.sh | 12 ++++++++++++ kernels/Logistic.hpp | 4 ++-- kernels/Lorenz3D.cpp | 2 +- kernels/Lorenz3D.hpp | 2 +- kernels/Polynomial.cpp | 2 +- kernels/Polynomial.hpp | 2 +- 10 files changed, 45 insertions(+), 33 deletions(-) create mode 100644 cleanCode.sh diff --git a/Attractor.hpp b/Attractor.hpp index aa5c89d..2d63062 100644 --- a/Attractor.hpp +++ b/Attractor.hpp @@ -12,20 +12,20 @@ private: AttractorKernel * myAttractor; public: - + // should be private really std::vector projectors; - + Attractor(const char* const filename); ~Attractor(); - + void init_range(); bool is_chaos(); - + void iterate(); void plot(); void output(); - + }; #endif // ATTRACTOR_HPP diff --git a/AttractorKernel.cpp b/AttractorKernel.cpp index c9398df..fd055f9 100644 --- a/AttractorKernel.cpp +++ b/AttractorKernel.cpp @@ -16,7 +16,7 @@ AttractorKernel::AttractorKernel(const unsigned int dimension, const unsigned int numberOfParameters) : numberOfParameters(numberOfParameters), dimension(dimension){ - + try { allocate(); } @@ -24,7 +24,7 @@ numberOfParameters(numberOfParameters), dimension(dimension){ std::cout << "Couldn't construct AttractorKernel: " << e.what() << std::endl; dealloc(); } - + std::fill_n(parameters, numberOfParameters, 0.0); std::fill_n(vectorNew, dimension, 0.0); std::fill_n(vectorOld, dimension, 0.0); @@ -93,22 +93,22 @@ unsigned int AttractorKernel::getDimension() const{ #include "kernels/Unravel3D.hpp" AttractorKernel * AttractorKernel::createAttractorKernel(stfu::node& attractor){ - + AttractorKernel * myAttractor = NULL; - + // reading basic stuff const std::string attractorType = attractor.getValue("type"); const std::string attractorDimension = attractor.getValue("dimensions"); - + // for ( unsigned int i = 0; attractorType[i] != '\0'; i++ ) { // attractorType[i] = tolower(attractorType[i]); // } const unsigned int dimension = atoi(attractorDimension.c_str()); - + std::cout << " Formula: " << attractorType << std::endl; std::cout << " Dimensions: " << dimension << std::endl; - - + + // depending on type, make the formula object if ( attractorType == "lorenz" ){ if ( dimension == 3 ) { @@ -122,7 +122,7 @@ AttractorKernel * AttractorKernel::createAttractorKernel(stfu::node& attractor){ const unsigned int orde = atoi(attractorOrde.c_str()); std::cout << " Orde: " << orde << std::endl; myAttractor = new Polynomial(dimension, orde); - + } else if ( attractorType == "polynomial a" ) { if ( dimension == 3 ) { myAttractor = new PolynomialA3D(); @@ -143,19 +143,19 @@ AttractorKernel * AttractorKernel::createAttractorKernel(stfu::node& attractor){ std::cout << "'" << attractorType << "' not recognized" << std::endl; exit(3); } - - + + // read parameters const unsigned int numberOfParameters = myAttractor->getNumberOfParameters(); - + for ( unsigned int i = 0; i < numberOfParameters; i++ ) { stfu::node attractorParameters = attractor.getChild("parameters"); (*myAttractor)[i] = atof(attractorParameters.getValue(i).c_str()); std::cout << " Parameter " << i << " set to " << (*myAttractor)[i] << ", "; } - + std::cout << std::endl << " Reading file complete" << std::endl; - + return myAttractor; } diff --git a/AttractorKernel.hpp b/AttractorKernel.hpp index e629f2e..c661c8d 100644 --- a/AttractorKernel.hpp +++ b/AttractorKernel.hpp @@ -5,10 +5,10 @@ class AttractorKernel { private: - + void allocate(); void dealloc(); - + protected: // biggest type first, this will reduce sizeof(AttractorKernel) @@ -16,14 +16,14 @@ protected: double * parameters; double * vectorNew; double * vectorOld; - + unsigned int numberOfParameters; unsigned int dimension; // stuff used by subclasses AttractorKernel(const unsigned int dimension, const unsigned int numberOfParameters); void reallocParameters(const unsigned int numberOfParameters); - + public: // parameters are stored in a array of doubles @@ -38,13 +38,13 @@ public: double const * vector() const; double const * previousVector() const; unsigned int getDimension() const; - + // dtor, should be virtual for subclasses to be deleted virtual ~AttractorKernel(); - + // factory function static AttractorKernel * createAttractorKernel(stfu::node& attractorKernel); - + }; #endif // ATTRACTORKERNEL_HPP diff --git a/attractors/testUnravelNew.stf b/attractors/testUnravelNew.stf index d1ee475..40cd0d9 100644 --- a/attractors/testUnravelNew.stf +++ b/attractors/testUnravelNew.stf @@ -25,7 +25,7 @@ projections: Applied in order they appear { } :{ type: "lineair map" - + matrix: { :{ :"1" :"0" :"0" } diff --git a/cleanCode.sh b/cleanCode.sh new file mode 100644 index 0000000..de0ee5e --- /dev/null +++ b/cleanCode.sh @@ -0,0 +1,12 @@ + +DIRS="./*.cpp ./*.hpp ./kernels/*.cpp ./kernels/*.hpp ./attractors/*.stf" +echo "This program will delete all trailing whitespaces and will replace spaces with tabs" + +for file in ${DIRS} +do + echo "yay ${file}" + unexpand -t 4 ${file} | sed 's/[ \t]*$//' > ${file}.new + cat ${file}.new > ${file} + rm ${file}.new +done + diff --git a/kernels/Logistic.hpp b/kernels/Logistic.hpp index 99c2328..8e85f06 100644 --- a/kernels/Logistic.hpp +++ b/kernels/Logistic.hpp @@ -5,9 +5,9 @@ class Logistic : public AttractorKernel { private: - + void init(); - + public: Logistic(); diff --git a/kernels/Lorenz3D.cpp b/kernels/Lorenz3D.cpp index 0c73e32..508845a 100644 --- a/kernels/Lorenz3D.cpp +++ b/kernels/Lorenz3D.cpp @@ -6,7 +6,7 @@ #pragma mark ctors Lorenz3D::Lorenz3D(): - AttractorKernel(3, 4){ + AttractorKernel(3, 4){ init(); } diff --git a/kernels/Lorenz3D.hpp b/kernels/Lorenz3D.hpp index 347a3bb..cdeac47 100644 --- a/kernels/Lorenz3D.hpp +++ b/kernels/Lorenz3D.hpp @@ -5,7 +5,7 @@ class Lorenz3D : public AttractorKernel { private: - + void init(); public: diff --git a/kernels/Polynomial.cpp b/kernels/Polynomial.cpp index 4445a3c..bbb8c41 100644 --- a/kernels/Polynomial.cpp +++ b/kernels/Polynomial.cpp @@ -15,7 +15,7 @@ unsigned int calculateNumberOfParameters(const unsigned int dimension, const uns for (unsigned int i = 2; i <= dimension; i++) { n_coef = n_coef*(orde + i)/(i - 1); } - + const unsigned int output = (unsigned int) n_coef; return output; } diff --git a/kernels/Polynomial.hpp b/kernels/Polynomial.hpp index 2f18731..94335a8 100644 --- a/kernels/Polynomial.hpp +++ b/kernels/Polynomial.hpp @@ -5,7 +5,7 @@ class Polynomial : public AttractorKernel { private: - + unsigned int orde; void recur(unsigned int curr_dimension, unsigned int prev_i, unsigned int n, unsigned int& m, double prev_product=1.0);