Blame view

Sources/get_Orbit.cpp 2.46 KB
4921d9e8   Elena.Budnik   src
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/////////////////
// CPP HEADERS //
/////////////////
#include <iostream>
#include <fstream>
#include <stdlib.h> 

////////////
/// DDLIB //
////////////
#include "DD.h"

////////////////
// NAMESPACES //
///////////////
using namespace std;

int main(int argc, char const *argv[])
{
	if (argc != 6)
	{
		cout << "[ERROR] Usage : ./get_Orbit (data filename) (body VI) (frame) (ddStart) (ddInterval)" << endl;
		exit(EXIT_FAILURE);
	}

	string timeParameter  = "Time";

	string dataFilename = argv[1];
	string bodyVI       = argv[2];
	string frame        = argv[3];
	string ddStart      = argv[4];
	string ddInterval   = argv[5];

	ofstream orbitFile(dataFilename.c_str(), ios::out); 

	int id = DD_SetVariable( const_cast<char*>( bodyVI.c_str() ) );

	char *st = const_cast<char*>( ddStart.c_str() );

	int error = DD_SetTime(id, st);

	if (error < 0)
	{
		std::string ddSetTimeErr = "[ERROR] Bad time pointer init in DD_SetTime -> err value : " +  error;
		throw std::string(ddSetTimeErr);
	}

	// GET DATA
	char *params[2];
	
	params[0] = const_cast<char*>( timeParameter.c_str() );
	params[1] = const_cast<char*>( frame.c_str() );
	
	char *timeIntervall = const_cast<char*>( ddInterval.c_str() );
	
	DD_data_t *data;

	int status = 0;

	orbitFile << "Time,X,Y,Z" << endl;

	do {

		status = DD_GetMultiData(id, 2, static_cast<char**>(params), timeIntervall, &data, 1);
		
		if (status < 0)
		{
			std::string ddGetDataErr = "[ERROR] Failed to get data -> status : " + status;
			throw std::string(ddGetDataErr);
		}

		int dataType = data[1].type;
		
		for (int j = 0; j < data->VarNumber; j++)	
		{
			orbitFile << static_cast<char*>(data[0].Variables[j]) << ",";

			if ( dataType == 3 ) // DOUBLE
			{
				orbitFile << static_cast<float>(static_cast<double*>(data[1].Variables[j])[0]) << ","
		  				  << static_cast<float>(static_cast<double*>(data[1].Variables[j])[1]) << ","
		  				  << static_cast<float>(static_cast<double*>(data[1].Variables[j])[2]) << endl;

			}
			else if ( dataType == 2 ) // FLOAT
			{
				
				orbitFile << static_cast<float*>(data[1].Variables[j])[0] << ","
		  		          << static_cast<float*>(data[1].Variables[j])[1] << ","
		  		          << static_cast<float*>(data[1].Variables[j])[2] << endl;

			}
			else
			{
				std::string ddGetDataTypeErr = "[ERROR] getOrbit : failed to get data -> Unknown data type (not double nor float)";
				throw std::string(ddGetDataTypeErr);	
			}
		}


	} while (status == MOREDATA);
	
    DD_Close(id);

    orbitFile.close();

	return 0;
}