main.cpp 1.7 KB
Newer Older
Laurent Belcour's avatar
Laurent Belcour committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <core/args.h>
#include <core/data.h>
#include <core/function.h>
#include <core/fitter.h>
#include <core/plugins_manager.h>

#include <QApplication>

#include <iostream>
#include <vector>
#include <iostream>
#include <fstream>
#include <limits>
#include <cstdlib>
15
#include <cmath>
Laurent Belcour's avatar
Laurent Belcour committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

int main(int argc, char** argv)
{
	QApplication app(argc, argv, false);
	arguments args(argc, argv) ;

	plugins_manager manager(args) ;

	if(args.is_defined("help")) {
		std::cout << "<<HELP>> data2gnuplot --input data.file --output gnuplot.file" << std::endl ;
		std::cout << " - input and output are mandatory parameters" << std::endl ;
		return 0 ;
	}

	if(! args.is_defined("input")) {
		std::cerr << "<<ERROR>> the input filename is not defined" << std::endl ;
		return 1 ;
	}
	if(! args.is_defined("output")) {
		std::cerr << "<<ERROR>> the output filename is not defined" << std::endl ;
		return 1 ;
	}

	data* d = NULL ;
40
	d = manager.get_data(args["loader"]) ;
Laurent Belcour's avatar
Laurent Belcour committed
41 42 43 44 45 46 47
	d->load(args["input"]);

	// Create output file
	std::ofstream file(args["output"].c_str(), std::ios_base::trunc);

	if(d != NULL)
	{
48
		std::cout << "<<INFO>> will export " << d->size() << " elements" << std::endl ;
49 50 51 52 53 54 55 56 57 58 59 60 61 62
	
		vec in(3), out(3) ;
		in[0] = 0.0;
		in[1] = 0.0;
		in[2] = 1.0;
		for(int i=0; i<90; ++i)
			for(int j=0; j<90; ++j)
			{
				double phi   = i * M_PI / 89 ;
				double theta = j * M_PI / 89 * 0.5 ;
				out[0] = cos(phi)*sin(theta);
				out[1] = sin(phi)*sin(theta);
				out[2] = cos(theta);
				vec v = d->value(in, out) ;
Laurent Belcour's avatar
Laurent Belcour committed
63

64 65 66
				file << phi << "\t" << theta << "\t" ;
				for(int u=0; u<d->dimY(); ++u)
					file << v[u] << "\t" ;
Laurent Belcour's avatar
Laurent Belcour committed
67
			
68 69
				file << std::endl ;
			}
Laurent Belcour's avatar
Laurent Belcour committed
70 71 72 73 74 75 76 77
	}	
	else
	{
		std::cerr << "<<ERROR>> cannot export data" << std::endl ;
	}

	return 0 ;
}