Newer
Older
package fr.cs.examples.estimation;
import org.orekit.data.DataProvidersManager;
import org.orekit.data.DirectoryCrawler;
/** This class is used to extract the desired data from the log files produced by the Orbit Determination program
* @author Noel Janes
* **/
static private double differencecalculator(double xg , double yg, double zg , double xd , double yd , double zd){
// Simple vector calculation to determine the distance between the estimated and previously known parameters
double diffx = xg - xd;
double diffy = yg - yd;
double diffz = zg - zd;
return Math.sqrt(Math.pow(diffx,2)+ Math.pow(diffy,2)+Math.pow(diffz,2));
static private double[] splitter(String input){
String[] a = input.split("\\)");
String[] b = a[0].split(", ");
for(int i=0; i<b.length;i++){
output[i]=Double.parseDouble(b[i]);
}
return output;
}
static private String splitterExtendedLog(String input){
String[] a = input.split(": ");
String[] b = a[1].split(" ");
return a[1];
}
public static void main(String[] args) throws Exception {
boolean pv = false; // If using the standard logs provided by the OD program setting this to true will extract the Cartesian parameters from the log
boolean extendedLog = true ; // If using the extended log format this will extract the parameters and put them in a text file
// Orbital parameters used in the generation of the measurements
double pxg = -5253194;
double pyg = -4400295;
double pzg = 80075;
double vxg = -559;
double vyg = 764;
double vzg = 7585;
// The sigma used in the generation
File home = new File(System.getProperty("user.home"));
File orekitData = new File(home, "orekit-data");
DataProvidersManager manager = DataProvidersManager.getInstance();
manager.addProvider(new DirectoryCrawler(orekitData));
File pythonPath = new File(home, "\\Documents\\ESA Socis\\Orbit Determination\\Python plotting\\");
File inputFile = new File(pythonPath + "\\orbit-determination-generated-measM-cdmax2-log.out");
File outputFile = new File(pythonPath +"\\twostationsMeasinM-nomax-gen.txt");
if (!outputFile.exists()) {
outputFile.createNewFile();
}
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
if (extendedLog != false) {
BufferedReader reader = new BufferedReader(new FileReader(inputFile));
String line = reader.readLine();
FileWriter fw = new FileWriter(outputFile, true);
BufferedWriter bw = new BufferedWriter(fw);
while (line != null) {
if (line.startsWith("Iteration Number: 0")){
String[] mainline = line.split(",");
int i ;
for (i= 0 ; i < mainline.length; i++ ){
//System.out.println(mainline[i]);
String output = splitterExtendedLog(mainline[i]) + " ";
System.out.println(output);
try {
bw.write(output);
}
catch (IOException ioe) {
System.err.println("Writer failed");
}
}
}
else if (line.startsWith("Iteration Number:")) {
try {
bw.write("\n");
}
catch (IOException ioe) {
System.err.println("Writer Failed");
}
String[] mainline = line.split(",");
int i ;
for (i= 0 ; i < mainline.length; i++ ){
if (mainline[i].contains("Δ")){
continue;
}
else {
//System.out.println(mainline[i]);
String output = splitterExtendedLog(mainline[i]) + " ";
try {
bw.write(output);
} catch (IOException ioe) {
System.err.println("Writer failed");
}
}
}
}
else if (line.startsWith(" The estimated Cartesian parameters:")) {
String[] chunks = line.split("\\(");
double[] position = splitter(chunks[1]);
double[] velocity = splitter(chunks[2]);
double[] a = splitter(chunks[3]);
double pDiff = differencecalculator(pxg, pyg, pzg, position[0], position[1], position[2]);
double vDiff = differencecalculator(vxg, vyg, vzg, velocity[0], velocity[1], velocity[2]);
String output = position[0] + " " + position[1] + " " + position[2] + " " + pDiff + " " + velocity[0] + " " + velocity[1] + " " + velocity[2] + " " + vDiff + " ";
try {
bw.write(output);
} catch (IOException ioe) {
System.err.println("Writer failed");
}
}
else if (line.startsWith(" 1 drag coefficient") || line.contains("1 39")){
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
String[] cd = chunks[1].split("\\)");
try {
bw.write(cd[0] + " ");
}
catch (IOException ioe) {
System.err.println("Writer failed");
}
}
line = reader.readLine();
}
bw.close();
}
if (pv != false) {
/* Initial data path for many log files */
File log = new File(home + "\\orbit-determination-generated-log.out");
String[] folderlist = log.list();
boolean exists = log.exists();
System.out.println(exists);
for( String folderName : folderlist) {
BufferedReader reader = new BufferedReader(new FileReader(log+"\\" + folderName + "\\orbit-determination-log.out"));
String line = reader.readLine();
if (line.startsWith("Estimated orbit: Cartesian parameters:")) {
String[] chunks = line.split("\\(");
double[] position = splitter(chunks[1]);
double[] velocity = splitter(chunks[2]);
double[] a = splitter(chunks[3]);
double pDiff = differencecalculator(pxg, pyg, pzg, position[0], position[1], position[2]);
double vDiff = differencecalculator(vxg, vyg, vzg, velocity[0], velocity[1], velocity[2]);
String outputline = folderName + " " + pDiff + " " + vDiff + "\n";
try {
FileWriter fw = new FileWriter(outputFile, true);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(outputline);
bw.close();
} catch (IOException ioe) {
System.err.println("Writer failed");
}
}
line = reader.readLine();
}
}
}