Browse Source

added bash script to clean up code

master
Joshua Moerman 14 years ago
parent
commit
a0f07490e3
  1. 10
      Attractor.hpp
  2. 28
      AttractorKernel.cpp
  3. 14
      AttractorKernel.hpp
  4. 2
      attractors/testUnravelNew.stf
  5. 12
      cleanCode.sh
  6. 4
      kernels/Logistic.hpp
  7. 2
      kernels/Lorenz3D.cpp
  8. 2
      kernels/Lorenz3D.hpp
  9. 2
      kernels/Polynomial.cpp
  10. 2
      kernels/Polynomial.hpp

10
Attractor.hpp

@ -12,20 +12,20 @@ private:
AttractorKernel * myAttractor; AttractorKernel * myAttractor;
public: public:
// should be private really // should be private really
std::vector<Projector *> projectors; std::vector<Projector *> projectors;
Attractor(const char* const filename); Attractor(const char* const filename);
~Attractor(); ~Attractor();
void init_range(); void init_range();
bool is_chaos(); bool is_chaos();
void iterate(); void iterate();
void plot(); void plot();
void output(); void output();
}; };
#endif // ATTRACTOR_HPP #endif // ATTRACTOR_HPP

28
AttractorKernel.cpp

@ -16,7 +16,7 @@
AttractorKernel::AttractorKernel(const unsigned int dimension, const unsigned int numberOfParameters) : AttractorKernel::AttractorKernel(const unsigned int dimension, const unsigned int numberOfParameters) :
numberOfParameters(numberOfParameters), dimension(dimension){ numberOfParameters(numberOfParameters), dimension(dimension){
try { try {
allocate(); allocate();
} }
@ -24,7 +24,7 @@ numberOfParameters(numberOfParameters), dimension(dimension){
std::cout << "Couldn't construct AttractorKernel: " << e.what() << std::endl; std::cout << "Couldn't construct AttractorKernel: " << e.what() << std::endl;
dealloc(); dealloc();
} }
std::fill_n(parameters, numberOfParameters, 0.0); std::fill_n(parameters, numberOfParameters, 0.0);
std::fill_n(vectorNew, dimension, 0.0); std::fill_n(vectorNew, dimension, 0.0);
std::fill_n(vectorOld, dimension, 0.0); std::fill_n(vectorOld, dimension, 0.0);
@ -93,22 +93,22 @@ unsigned int AttractorKernel::getDimension() const{
#include "kernels/Unravel3D.hpp" #include "kernels/Unravel3D.hpp"
AttractorKernel * AttractorKernel::createAttractorKernel(stfu::node& attractor){ AttractorKernel * AttractorKernel::createAttractorKernel(stfu::node& attractor){
AttractorKernel * myAttractor = NULL; AttractorKernel * myAttractor = NULL;
// reading basic stuff // reading basic stuff
const std::string attractorType = attractor.getValue("type"); const std::string attractorType = attractor.getValue("type");
const std::string attractorDimension = attractor.getValue("dimensions"); const std::string attractorDimension = attractor.getValue("dimensions");
// for ( unsigned int i = 0; attractorType[i] != '\0'; i++ ) { // for ( unsigned int i = 0; attractorType[i] != '\0'; i++ ) {
// attractorType[i] = tolower(attractorType[i]); // attractorType[i] = tolower(attractorType[i]);
// } // }
const unsigned int dimension = atoi(attractorDimension.c_str()); const unsigned int dimension = atoi(attractorDimension.c_str());
std::cout << " Formula: " << attractorType << std::endl; std::cout << " Formula: " << attractorType << std::endl;
std::cout << " Dimensions: " << dimension << std::endl; std::cout << " Dimensions: " << dimension << std::endl;
// depending on type, make the formula object // depending on type, make the formula object
if ( attractorType == "lorenz" ){ if ( attractorType == "lorenz" ){
if ( dimension == 3 ) { if ( dimension == 3 ) {
@ -122,7 +122,7 @@ AttractorKernel * AttractorKernel::createAttractorKernel(stfu::node& attractor){
const unsigned int orde = atoi(attractorOrde.c_str()); const unsigned int orde = atoi(attractorOrde.c_str());
std::cout << " Orde: " << orde << std::endl; std::cout << " Orde: " << orde << std::endl;
myAttractor = new Polynomial(dimension, orde); myAttractor = new Polynomial(dimension, orde);
} else if ( attractorType == "polynomial a" ) { } else if ( attractorType == "polynomial a" ) {
if ( dimension == 3 ) { if ( dimension == 3 ) {
myAttractor = new PolynomialA3D(); myAttractor = new PolynomialA3D();
@ -143,19 +143,19 @@ AttractorKernel * AttractorKernel::createAttractorKernel(stfu::node& attractor){
std::cout << "'" << attractorType << "' not recognized" << std::endl; std::cout << "'" << attractorType << "' not recognized" << std::endl;
exit(3); exit(3);
} }
// read parameters // read parameters
const unsigned int numberOfParameters = myAttractor->getNumberOfParameters(); const unsigned int numberOfParameters = myAttractor->getNumberOfParameters();
for ( unsigned int i = 0; i < numberOfParameters; i++ ) { for ( unsigned int i = 0; i < numberOfParameters; i++ ) {
stfu::node attractorParameters = attractor.getChild("parameters"); stfu::node attractorParameters = attractor.getChild("parameters");
(*myAttractor)[i] = atof(attractorParameters.getValue(i).c_str()); (*myAttractor)[i] = atof(attractorParameters.getValue(i).c_str());
std::cout << " Parameter " << i << " set to " << (*myAttractor)[i] << ", "; std::cout << " Parameter " << i << " set to " << (*myAttractor)[i] << ", ";
} }
std::cout << std::endl << " Reading file complete" << std::endl; std::cout << std::endl << " Reading file complete" << std::endl;
return myAttractor; return myAttractor;
} }

14
AttractorKernel.hpp

@ -5,10 +5,10 @@
class AttractorKernel { class AttractorKernel {
private: private:
void allocate(); void allocate();
void dealloc(); void dealloc();
protected: protected:
// biggest type first, this will reduce sizeof(AttractorKernel) // biggest type first, this will reduce sizeof(AttractorKernel)
@ -16,14 +16,14 @@ protected:
double * parameters; double * parameters;
double * vectorNew; double * vectorNew;
double * vectorOld; double * vectorOld;
unsigned int numberOfParameters; unsigned int numberOfParameters;
unsigned int dimension; unsigned int dimension;
// stuff used by subclasses // stuff used by subclasses
AttractorKernel(const unsigned int dimension, const unsigned int numberOfParameters); AttractorKernel(const unsigned int dimension, const unsigned int numberOfParameters);
void reallocParameters(const unsigned int numberOfParameters); void reallocParameters(const unsigned int numberOfParameters);
public: public:
// parameters are stored in a array of doubles // parameters are stored in a array of doubles
@ -38,13 +38,13 @@ public:
double const * vector() const; double const * vector() const;
double const * previousVector() const; double const * previousVector() const;
unsigned int getDimension() const; unsigned int getDimension() const;
// dtor, should be virtual for subclasses to be deleted // dtor, should be virtual for subclasses to be deleted
virtual ~AttractorKernel(); virtual ~AttractorKernel();
// factory function // factory function
static AttractorKernel * createAttractorKernel(stfu::node& attractorKernel); static AttractorKernel * createAttractorKernel(stfu::node& attractorKernel);
}; };
#endif // ATTRACTORKERNEL_HPP #endif // ATTRACTORKERNEL_HPP

2
attractors/testUnravelNew.stf

@ -25,7 +25,7 @@ projections: Applied in order they appear {
} }
:{ :{
type: "lineair map" type: "lineair map"
matrix: matrix:
{ {
:{ :"1" :"0" :"0" } :{ :"1" :"0" :"0" }

12
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

4
kernels/Logistic.hpp

@ -5,9 +5,9 @@
class Logistic : public AttractorKernel { class Logistic : public AttractorKernel {
private: private:
void init(); void init();
public: public:
Logistic(); Logistic();

2
kernels/Lorenz3D.cpp

@ -6,7 +6,7 @@
#pragma mark ctors #pragma mark ctors
Lorenz3D::Lorenz3D(): Lorenz3D::Lorenz3D():
AttractorKernel(3, 4){ AttractorKernel(3, 4){
init(); init();
} }

2
kernels/Lorenz3D.hpp

@ -5,7 +5,7 @@
class Lorenz3D : public AttractorKernel { class Lorenz3D : public AttractorKernel {
private: private:
void init(); void init();
public: public:

2
kernels/Polynomial.cpp

@ -15,7 +15,7 @@ unsigned int calculateNumberOfParameters(const unsigned int dimension, const uns
for (unsigned int i = 2; i <= dimension; i++) { for (unsigned int i = 2; i <= dimension; i++) {
n_coef = n_coef*(orde + i)/(i - 1); n_coef = n_coef*(orde + i)/(i - 1);
} }
const unsigned int output = (unsigned int) n_coef; const unsigned int output = (unsigned int) n_coef;
return output; return output;
} }

2
kernels/Polynomial.hpp

@ -5,7 +5,7 @@
class Polynomial : public AttractorKernel { class Polynomial : public AttractorKernel {
private: private:
unsigned int orde; unsigned int orde;
void recur(unsigned int curr_dimension, unsigned int prev_i, unsigned int n, unsigned int& m, double prev_product=1.0); void recur(unsigned int curr_dimension, unsigned int prev_i, unsigned int n, unsigned int& m, double prev_product=1.0);