Commit 63c3f6be authored by Laurent Belcour's avatar Laurent Belcour

Updating argument informations

parent 1ec84393
......@@ -69,11 +69,10 @@ class arguments
} ;
int get_int(const std::string& key, int default_value = 0) const
{
std::string value = _map.at(key) ;
if(value.empty())
return default_value ;
if(_map.count(key) > 0)
return atoi(_map.at(key).c_str()) ;
else
return atoi(value.c_str()) ;
return default_value ;
} ;
private: // data
......
......@@ -6,6 +6,7 @@
#include <QtPlugin>
#include "common.h"
#include "args.h"
class function //: public std::function<double(double)>
{
......@@ -16,7 +17,7 @@ class function //: public std::function<double(double)>
// IO function to text files
virtual void load(const std::string& filename) = 0 ;
virtual void save() const = 0 ;
virtual void save(const std::string& filename, const arguments& args) const = 0 ;
virtual int dimX() const { return _nX ; } ;
virtual int dimY() const { return _nY ; } ;
......
......@@ -121,8 +121,22 @@ double rational_function::q(const vec& x, int i) const
void rational_function::load(const std::string& filename)
{
}
void rational_function::save() const
void rational_function::save(const std::string& filename, const arguments& args) const
{
vec min, max ;
min.assign(_nX, args.get_float("min", 0.0f)) ;
max.assign(_nX, args.get_float("max", 1.5f)) ;
int nb_samples = args.get_int("nb_samples", 100) ;
double dt = (max[0]-min[0]) / nb_samples ;
std::ofstream file(filename.c_str(), std::ios_base::trunc);
for(double x=min[0]; x<=max[0]; x+=dt)
{
vec vx ; vx.push_back(x) ;
file << x << "\t" << ((*this)(vx))[0] << std::endl ;
std::cout << x << "\t" << ((*this)(vx))[0] << std::endl ;
}
}
std::ostream& operator<< (std::ostream& out, const rational_function& r)
......
......@@ -32,7 +32,7 @@ class rational_function : public QObject, public function
// IO function to text files
void load(const std::string& filename) ;
void save() const ;
void save(const std::string& filename, const arguments& args) const ;
// STL stream ouput
friend std::ostream& operator<< (std::ostream& out, const rational_function& r) ;
......
......@@ -108,13 +108,7 @@ int main(int argc, char** argv)
// Display the result
if(is_fitted)
{
std::ofstream file(args["output"].c_str(), std::ios_base::trunc);
const double dt = (d->max()[0] - d->min()[0]) / 100.0f ;
for(double x=d->min()[0]; x<=d->max()[0]; x+=dt)
{
vec vx ; vx.push_back(x) ;
file << x << "\t" << ((*f)(vx))[0] << std::endl ;
}
functions[0]->save(args["output"], args) ;
}
else
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment