Page MenuHomec4science

TwoDTab.cpp
No OneTemporary

File Metadata

Created
Sun, Feb 23, 11:55

TwoDTab.cpp

//
// Created by Pauline Ollitrault on 28.11.16.
//
#include "TwoDTab.hpp"
/**
* @brief Default constructor
*/
TwoDTab::TwoDTab() : AbstractTabFunction() {}
/**
* @brief Alternate constructor that sets the function
* @details Calls the @e SetFunction() method with the string passed as argument
* @param function string containing the name of the data file
*/
TwoDTab::TwoDTab(const std::string function) : AbstractTabFunction()
{
SetFunction(function);
}
/**
* @brief Sets the function to be integrated
* @details Reads the data file and stores the datas into class member vectors
* Returns an error if the number of nodes in the data file is not greated than 1.
* @param function
*/
void TwoDTab::SetFunction(const std::string function)
{
std::ifstream read_file(function);
try {
if (!read_file.is_open())
{
throw Error("Error opening data file : ");
}
}
catch(Error err)
{
std::cerr << "ERROR : " << err.what() << function <<std::endl;
exit(0);
}
double x;
double y;
double z;
while (!read_file.eof())
{
read_file >> x >> y >> z;
X.push_back(x);
Y.push_back(y);
Z.push_back(z);
}
read_file.close();
try {
if (X.size() <= 1 or Y.size() <=1 or Z.size()<=1)
{
throw Error("Number of nodes must be greater than 1.");
}
}
catch(Error err)
{
std::cerr << "ERROR : " << err.what() << std::endl;
exit(0);
}
}

Event Timeline