Page MenuHomec4science

OneDTab.cpp
No OneTemporary

File Metadata

Created
Sun, Feb 23, 04:27

OneDTab.cpp

//
// Created by Pauline Ollitrault on 28.11.16.
//
#include "OneDTab.hpp"
/**
* @brief Default constructor
*/
OneDTab::OneDTab(){}
/**
* @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.
*/
OneDTab::OneDTab(const std::string function) : AbstractTabFunction()
{
SetFunction(function);
}
/**
* @brief Sets the function to be integrated
* @details Reads the data from file and stores in X and Y vectors. Returns an error is the number
* of nodes is not greater than one.
* @param function string containing the name of the data file.
*/
void OneDTab::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;
while(!read_file.eof())
{
read_file >> x >> y;
X.push_back(x);
Y.push_back(y);
}
read_file.close();
try {
if (X.size() <= 1 or Y.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