|
|
|
@ -5,7 +5,7 @@ package seng302.DataInput;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import seng302.Exceptions.InvalidPolarFileException;
|
|
|
|
import seng302.Exceptions.InvalidPolarFileException;
|
|
|
|
import seng302.Model.Polar;
|
|
|
|
import seng302.Model.Polars;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.io.*;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
@ -22,11 +22,11 @@ public class PolarParser {
|
|
|
|
* @param filename
|
|
|
|
* @param filename
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
|
|
|
|
///TEMP PolarTable = ArrayList<Polar>
|
|
|
|
///TEMP PolarTable = ArrayList<Polar>
|
|
|
|
public static ArrayList<Polar> parse(String filename) throws InvalidPolarFileException {
|
|
|
|
public static Polars parse(String filename) throws InvalidPolarFileException {
|
|
|
|
//Temporary table to return later.
|
|
|
|
//Temporary table to return later.
|
|
|
|
ArrayList<Polar> polarTable = new ArrayList<Polar>();
|
|
|
|
Polars polarTable = new Polars();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Open the file for reading.
|
|
|
|
//Open the file for reading.
|
|
|
|
@ -84,84 +84,19 @@ public class PolarParser {
|
|
|
|
int rowNumber = 0;
|
|
|
|
int rowNumber = 0;
|
|
|
|
for (String[] row : dataRows) {
|
|
|
|
for (String[] row : dataRows) {
|
|
|
|
//Create Polar row object.
|
|
|
|
//Create Polar row object.
|
|
|
|
Polar polarRow = new Polar();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//For each column...
|
|
|
|
//For each column...
|
|
|
|
for (int i = 0; i < row.length; i++) {
|
|
|
|
for (int i = 0; i < row.length / 2; i += 2) {
|
|
|
|
|
|
|
|
|
|
|
|
//Convert value to a double.
|
|
|
|
//Convert value to a double.
|
|
|
|
Double value;
|
|
|
|
Double value;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
value = Double.parseDouble(row[i]);
|
|
|
|
//Add the polar value to the polar table
|
|
|
|
|
|
|
|
polarTable.addEstimate( Double.parseDouble(row[0]), Double.parseDouble(row[i]), Double.parseDouble(row[i + 1]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (NumberFormatException e) {
|
|
|
|
catch (NumberFormatException e) {
|
|
|
|
throw new InvalidPolarFileException("Could not convert (Row,Col): (" + rowNumber + "," + i +") = " + row[i] + "to a double.", e);
|
|
|
|
throw new InvalidPolarFileException("Could not convert (Row,Col): (" + rowNumber + "," + i +") = " + row[i] + "to a double.", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Set the values of the row.
|
|
|
|
|
|
|
|
//For reference:
|
|
|
|
|
|
|
|
//Tws, Twa0, Bsp0, Twa1, Bsp1, UpTwa, UpBsp, Twa2, Bsp2, Twa3, Bsp3, Twa4, Bsp4, Twa5, Bsp5, Twa6, Bsp6, DnTwa, DnBsp, Twa7, Bsp7
|
|
|
|
|
|
|
|
if (headings[i] == "Tws") {
|
|
|
|
|
|
|
|
polarRow.setTrueWindSpeed(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (headings[i] == "Twa0") {
|
|
|
|
|
|
|
|
polarRow.setTrueWindAngle0(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (headings[i] == "Bsp0") {
|
|
|
|
|
|
|
|
polarRow.setBoatSpeed0(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (headings[i] == "Twa1") {
|
|
|
|
|
|
|
|
polarRow.setTrueWindAngle1(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (headings[i] == "Bsp1") {
|
|
|
|
|
|
|
|
polarRow.setBoatSpeed1(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (headings[i] == "UpTwa") {
|
|
|
|
|
|
|
|
polarRow.setUpTrueWindAngel(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (headings[i] == "UpBsp") {
|
|
|
|
|
|
|
|
polarRow.setUpBoatSpeed(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (headings[i] == "Twa2") {
|
|
|
|
|
|
|
|
polarRow.setTrueWindAngle2(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (headings[i] == "Bsp2") {
|
|
|
|
|
|
|
|
polarRow.setBoatSpeed2(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (headings[i] == "Twa3") {
|
|
|
|
|
|
|
|
polarRow.setTrueWindAngle3(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (headings[i] == "Bsp3") {
|
|
|
|
|
|
|
|
polarRow.setBoatSpeed3(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (headings[i] == "Twa4") {
|
|
|
|
|
|
|
|
polarRow.setTrueWindAngle4(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (headings[i] == "Bsp4") {
|
|
|
|
|
|
|
|
polarRow.setBoatSpeed4(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (headings[i] == "Twa5") {
|
|
|
|
|
|
|
|
polarRow.setTrueWindAngle5(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (headings[i] == "Bsp5") {
|
|
|
|
|
|
|
|
polarRow.setBoatSpeed5(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (headings[i] == "Twa6") {
|
|
|
|
|
|
|
|
polarRow.setTrueWindAngle6(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (headings[i] == "Bsp6") {
|
|
|
|
|
|
|
|
polarRow.setBoatSpeed6(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (headings[i] == "Twa7") {
|
|
|
|
|
|
|
|
polarRow.setTrueWindAngle7(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (headings[i] == "Bsp7") {
|
|
|
|
|
|
|
|
polarRow.setBoatSpeed7(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Add the polar row to the polar table.
|
|
|
|
|
|
|
|
polarTable.add(polarRow);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Increment row number.
|
|
|
|
//Increment row number.
|
|
|
|
@ -172,6 +107,5 @@ public class PolarParser {
|
|
|
|
|
|
|
|
|
|
|
|
return polarTable;
|
|
|
|
return polarTable;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|