Page MenuHomec4science

DumperSeries.cc
No OneTemporary

File Metadata

Created
Tue, May 28, 12:15

DumperSeries.cc

#include "DumperSeries.hh"
#include <iostream>
#include <fstream>
#include "Series.hh"
#include <string>
#include <cctype>
#include <typeinfo> // to check the class type
#include <cmath>
#include <iomanip>
using namespace std;
using UInt = unsigned int;
//Parent class methods
DumperSeries::DumperSeries(){}
DumperSeries::~DumperSeries(){}
void DumperSeries::dump(std::ostream & os){}
void DumperSeries::setPrecision(unsigned int precision){}
//Printseies methods
PrintSeries::PrintSeries(){}
PrintSeries::~PrintSeries(){}
// Using this method we set the class internal variable prec to desired precision. Afterwards, we use it in dump method.
void PrintSeries::setPrecision(unsigned int precision) {
prec=precision;
}
void PrintSeries::dump(Series *srs, UInt MaxItr, UInt Freq) {
//Setting precision according to the input from main, or by the default value
std::cout << setprecision(prec);
for (UInt i = 0; i <= MaxItr; i+= Freq){std::cout << "Iterations used: " << i << " , The Evaluation: " << srs->Compute(i)<< std::endl;} //Then here the output is according to set precision
// std::cout<< "Final iterated value is " << srs->Compute(i)<<" , analytical value is " << srs->getAnalyticPrediction() << ", the difference is " << srs->Compute(i)-srs->getAnalyticPrediction() << endl;
}
//WriteSeries methods
WriteSeries::WriteSeries(){}
WriteSeries::~WriteSeries(){}
//According to input argument , which is passed to dump method, the filetype is decided. This method will be called within dump method.
string WriteSeries::setSeparator(char bla) {
if (bla==',') {return "Dumpfile.csv";}
else if (bla=='|'){return "Dumpfile.psv";}
else {return "Dumpfile.txt";} // for space/tab
}
void WriteSeries::dump(Series *srs, UInt MaxItr, UInt Freq, char dlmt) {
ofstream writeobject; //Creating object writeobject, an instance of ofstream
std::string formattype=setSeparator(dlmt); // At this point the method setSeparator is called, and returns string which is given to the formattype variable
writeobject.open(formattype); // Then here formattype variable is used in order to create the file of desired name and format.
srs->current_index=1; // By repeating the value for current index and current value here, we avoid case of these variables changes if the dump from other class has already been called
srs->current_value=0;
for (UInt i=0;i<=MaxItr;i+=Freq){
writeobject << i << dlmt << srs->Compute(i)<<dlmt<< srs->getAnalyticPrediction()<< endl; // Writing iteration number, value and analytical prediction (nan in case of arithmetic series)
}
}

Event Timeline