main.cpp 1.92 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

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

	plugins_manager manager(args) ;

	if(args.is_defined("help")) {
25
		std::cout << "<<HELP>> data2gnuplot --input data.file --output gnuplot.file --loader loader.so" << std::endl ;
Laurent Belcour's avatar
Laurent Belcour committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39
		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
		double theta_in = (double)args.get_float("theta", 0.0f);
		double phi_in   = (double)args.get_float("phi", 0.0f);
52
		vec in(3), out(3) ;
53 54 55
		in[0] = cos(phi_in)*sin(theta_in);
		in[1] = sin(phi_in)*sin(theta_in);
		in[2] = cos(theta_in);
56 57 58 59

		const int N = 1000;
		for(int i=0; i<N; ++i)
			for(int j=0; j<N; ++j)
60
			{
61 62
				double phi   = (i-N/2) * M_PI / (N-1) * 2;
				double theta = (j-N/2) * M_PI / (N-1) ;
63 64 65 66
				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
67

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

	return 0 ;
}