Commit aeadc9ac authored by Laurent Belcour's avatar Laurent Belcour

Fixing a bug spotted by Gael

parent dbc6495c
......@@ -7,6 +7,7 @@
#include "common.h"
#include "args.h"
#include "data.h"
class function
{
......@@ -25,6 +26,8 @@ class function
virtual void setDimX(int nX) { _nX = nX ; } ;
virtual void setDimY(int nY) { _nY = nY ; } ;
virtual void save_gnuplot(const std::string& filename, const data* d, const arguments& args) const ;
protected:
// Dimension of the function
......
......@@ -56,7 +56,7 @@ void rational_data::load(const std::string& filename, const arguments& args)
_min.resize(dimX()) ;
_max.resize(dimX()) ;
for(int k=0; k<dimY(); ++k)
for(int k=0; k<dimX(); ++k)
{
_min[k] = std::numeric_limits<double>::max() ;
_max[k] = -std::numeric_limits<double>::max() ;
......
......@@ -195,8 +195,8 @@ void rational_function::save_gnuplot(const std::string& filename, const data* d,
for(int i=0; i<d->size(); ++i)
{
vec v = d->get(i) ;
vec y1 ; y1.assign(d->dimY(), 0.0) ;
for(int k=0; k<d->dimY(); ++k) { y1[k] = v[d->dimX() + k] ; }
// vec y1 ; y1.assign(d->dimY(), 0.0) ;
// for(int k=0; k<d->dimY(); ++k) { y1[k] = v[d->dimX() + k] ; }
vec y2 = value(v) ;
for(int u=0; u<d->dimX(); ++u)
......@@ -213,8 +213,8 @@ void rational_function::save_rational_function(const std::string& filename) cons
{
std::ofstream file(filename.c_str(), std::ios_base::trunc);
file << "#DIM " << _nX << " " << _nY << std::endl ;
file << "#NP " << a.size() << std::endl ;
file << "#NQ " << b.size() << std::endl ;
file << "#NP " << a.size() / _nY << std::endl ;
file << "#NQ " << b.size() / _nY << std::endl ;
file << "#BASIS poly" << std::endl ;
for(unsigned int i=0; i<a.size(); ++i)
......
SOURCES += main.cpp
DESTDIR = ../../build
INCLUDEPATH += ../../
......@@ -2,17 +2,28 @@
#include <fstream>
#include <cmath>
int main(int argc, int argv)
#include <core/args.h>
int main(int argc, char** argv)
{
std::ofstream f("input.gnuplot") ;
arguments args(argc, argv);
int nbx = 100;
int nby = 100;
int nbz = 100;
if(args.is_defined("nbx"))
nbx = args.get_int("nbx", 100) ;
if(args.is_defined("nby"))
nby = args.get_int("nby", 100) ;
const int k = 2 ;
const int k = args.get_int("f", 1) ;
if(k == 1)
{
f << "#DIM 1 1" << std::endl ;
for(int i=0; i<100; ++i)
for(int i=0; i<nbx; ++i)
{
const float x = i / (float)100.0f ;
const float x = i / (float)nbx ;
const float y = 100.0f * exp(-10.0 * x*x) * x*x - 0.01 *x*x*x ;
f << x << "\t" << y << "\t" << 0.1f << std::endl ;
......@@ -21,12 +32,25 @@ int main(int argc, int argv)
else if(k == 2)
{
f << "#DIM 2 1" << std::endl ;
for(int i=0; i<100; ++i)
for(int j=0; j<100; ++j)
for(int i=0; i<nbx; ++i)
for(int j=0; j<nby; ++j)
{
const float x = i / (float)nbx ;
const float y = j / (float)nby ;
const float z = 1 + 0.1f*x;
f << x << "\t" << y << "\t" << z << "\t" << 0.1f << std::endl ;
}
}
else if(k == 3)
{
f << "#DIM 2 1" << std::endl ;
for(int i=0; i<nbx; ++i)
for(int j=0; j<nby; ++j)
{
const float x = i / (float)100.0f ;
const float y = j / (float)100.0f ;
const float z = 100.0f * exp(-10.0 * x*x) * y*y - 0.01 *y*x*y ;
const float x = i / (float)nbx ;
const float y = j / (float)nby ;
const float z = exp(-10.0 * x*x) + x*y ;
f << x << "\t" << y << "\t" << z << "\t" << 0.1f << std::endl ;
}
......
......@@ -148,7 +148,8 @@ int main(int argc, char** argv)
size_t n = args["output"].find('.') ;
std::string gnuplot_filename = args["output"].substr(0,n);
gnuplot_filename.append(".gnuplot") ;
std::ofstream file(gnuplot_filename.c_str(), std::ios_base::trunc);
f->save_gnuplot(gnuplot_filename, d, args);
/* std::ofstream file(gnuplot_filename.c_str(), std::ios_base::trunc);
for(int i=0; i<d->size(); ++i)
{
vec v = d->get(i) ;
......@@ -164,7 +165,7 @@ int main(int argc, char** argv)
file << std::endl ;
}
*/
std::string error_filename = args["output"].substr(0,n);
error_filename.append(".errorplot") ;
std::ofstream efile(error_filename.c_str(), std::ios_base::trunc);
......
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