X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fnet%2Fsf%2Fopenrocket%2Ffile%2FRASPMotorLoader.java;fp=src%2Fnet%2Fsf%2Fopenrocket%2Ffile%2FRASPMotorLoader.java;h=4de79825687bd32c3272ec198ed5058fcb991d4d;hb=0d0afe488300aca47d09ac7651f8185190afb21f;hp=0000000000000000000000000000000000000000;hpb=6afc62224f6f7e581b1d321e125ed97a6ec77dc1;p=debian%2Fopenrocket
diff --git a/src/net/sf/openrocket/file/RASPMotorLoader.java b/src/net/sf/openrocket/file/RASPMotorLoader.java
new file mode 100644
index 00000000..4de79825
--- /dev/null
+++ b/src/net/sf/openrocket/file/RASPMotorLoader.java
@@ -0,0 +1,209 @@
+package net.sf.openrocket.file;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import net.sf.openrocket.rocketcomponent.Motor;
+import net.sf.openrocket.rocketcomponent.ThrustCurveMotor;
+import net.sf.openrocket.util.Coordinate;
+
+public class RASPMotorLoader extends MotorLoader {
+
+ public static final String CHARSET_NAME = "ISO-8859-1";
+
+ public static final Charset CHARSET = Charset.forName(CHARSET_NAME);
+
+
+
+
+ @Override
+ protected Charset getDefaultCharset() {
+ return CHARSET;
+ }
+
+
+ /**
+ * Load a Motor
from a RASP file specified by the Reader
.
+ * The Reader
is responsible for using the correct charset.
+ *
+ * The CG is assumed to be located at the center of the motor casing and the mass
+ * is calculated from the thrust curve by assuming a constant exhaust velocity.
+ *
+ * @param reader the source of the file.
+ * @return a list of the {@link Motor} objects defined in the file.
+ * @throws IOException if an I/O error occurs or if the file format is illegal.
+ */
+ @Override
+ public List load(Reader reader, String filename) throws IOException {
+ List motors = new ArrayList();
+ BufferedReader in = new BufferedReader(reader);
+
+ String manufacturer = "";
+ String designation = "";
+ String comment = "";
+
+ double length = 0;
+ double diameter = 0;
+ ArrayList delays = null;
+
+ List time = new ArrayList();
+ List thrust = new ArrayList();
+
+ double propW = 0;
+ double totalW = 0;
+
+ try {
+ String line;
+ String[] pieces, buf;
+
+ line = in.readLine();
+ main: while (line != null) { // Until EOF
+
+ manufacturer = "";
+ designation = "";
+ comment = "";
+ length = 0;
+ diameter = 0;
+ delays = new ArrayList();
+ propW = 0;
+ totalW = 0;
+ time.clear();
+ thrust .clear();
+
+ // Read comment
+ while (line.length()==0 || line.charAt(0)==';') {
+ if (line.length() > 0) {
+ comment += line.substring(1).trim() + "\n";
+ }
+ line = in.readLine();
+ if (line == null)
+ break main;
+ }
+ comment = comment.trim();
+
+ // Parse header line, example:
+ // F32 24 124 5-10-15-P .0377 .0695 RV
+ // desig diam len delays prop.w tot.w manufacturer
+ pieces = split(line);
+ if (pieces.length != 7) {
+ throw new IOException("Illegal file format.");
+ }
+
+ designation = pieces[0];
+ diameter = Double.parseDouble(pieces[1]) / 1000.0;
+ length = Double.parseDouble(pieces[2]) / 1000.0;
+
+ if (pieces[3].equalsIgnoreCase("None")) {
+
+ } else {
+ buf = split(pieces[3],"[-,]+");
+ for (int i=0; i < buf.length; i++) {
+ if (buf[i].equalsIgnoreCase("P") ||
+ buf[i].equalsIgnoreCase("plugged")) {
+ delays.add(Motor.PLUGGED);
+ } else {
+ // Many RASP files have "100" as an only delay
+ double d = Double.parseDouble(buf[i]);
+ if (d < 99)
+ delays.add(d);
+ }
+ }
+ Collections.sort(delays);
+ }
+
+ propW = Double.parseDouble(pieces[4]);
+ totalW = Double.parseDouble(pieces[5]);
+ manufacturer = convertManufacturer(pieces[6]);
+
+ if (propW > totalW) {
+ throw new IOException("Propellant weight exceeds total weight in " +
+ "RASP file");
+ }
+
+ // Read the data
+ for (line = in.readLine();
+ (line != null) && (line.length()==0 || line.charAt(0) != ';');
+ line = in.readLine()) {
+
+ buf = split(line);
+ if (buf.length == 0) {
+ continue;
+ } else if (buf.length == 2) {
+
+ time.add(Double.parseDouble(buf[0]));
+ thrust .add(Double.parseDouble(buf[1]));
+
+ } else {
+ throw new IOException("Illegal file format.");
+ }
+ }
+
+ // Comment of EOF encountered, marks the start of the next motor
+ if (time.size() < 2) {
+ throw new IOException("Illegal file format, too short thrust-curve.");
+ }
+ double[] delayArray = new double[delays.size()];
+ for (int i=0; i time, List thrust)
+ throws IOException {
+
+ // Add zero time/thrust if necessary
+ sortLists(time, thrust);
+ finalizeThrustCurve(time, thrust);
+ List mass = calculateMass(time,thrust,totalW,propW);
+
+ double[] timeArray = new double[time.size()];
+ double[] thrustArray = new double[time.size()];
+ Coordinate[] cgArray = new Coordinate[time.size()];
+ for (int i=0; i < time.size(); i++) {
+ timeArray[i] = time.get(i);
+ thrustArray[i] = thrust.get(i);
+ cgArray[i] = new Coordinate(length/2,0,0,mass.get(i));
+ }
+
+ designation = removeDelay(designation);
+
+ try {
+
+ return new ThrustCurveMotor(manufacturer, designation, comment, Motor.Type.UNKNOWN,
+ delays, diameter, length, timeArray, thrustArray, cgArray);
+
+ } catch (IllegalArgumentException e) {
+
+ // Bad data read from file.
+ throw new IOException("Illegal file format.", e);
+
+ }
+ }
+}