LogParser.java 7.78 KiB
package fr.cs.examples.estimation;
import org.orekit.data.DataProvidersManager;
import org.orekit.data.DirectoryCrawler;
import java.io.*;
import java.lang.Math;
public class LogParser {
/** 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(", ");
double[] output = new double[3];
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
//double sigma = 0.25;
String stationID = "Kir-virt";
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\\");
/* Initial data for extended log files */
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();
}
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")){
String[] chunks = line.split(":");
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();
while (line != null) {
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();
}
}
}
}
}