diff --git a/core/resources/datafiles/thrustcurves/thrustcurves.ser b/core/resources/datafiles/thrustcurves/thrustcurves.ser index 785f8b208..8fe6792d7 100644 Binary files a/core/resources/datafiles/thrustcurves/thrustcurves.ser and b/core/resources/datafiles/thrustcurves/thrustcurves.ser differ diff --git a/core/src/net/sf/openrocket/file/motor/AbstractMotorLoader.java b/core/src/net/sf/openrocket/file/motor/AbstractMotorLoader.java index f15b43148..00c79716d 100644 --- a/core/src/net/sf/openrocket/file/motor/AbstractMotorLoader.java +++ b/core/src/net/sf/openrocket/file/motor/AbstractMotorLoader.java @@ -203,6 +203,45 @@ public abstract class AbstractMotorLoader implements MotorLoader { thrust.remove(0); } + // Very rare but not unheard of issue: two + // data points with identical time and thrust (see KBA K1750). + // We'll throw out the second, and hope the data in any other + // lists passed in is also duplicated (it *can't* make a big + // difference in the simulations) + for (int i = 0; i < time.size()-1; i++) { + while ((i < time.size()-1) && + MathUtil.equals(time.get(i), time.get(i+1)) && + MathUtil.equals(thrust.get(i), thrust.get(i+1))) { + System.out.println("\twarning: deleting duplicate data point time[" + i+1 + "]=" + time.get(i+1) + ", thrust=" + thrust.get(i+1)); + time.remove(i); + thrust.remove(i); + for (List l : lists) { + l.remove(i); + } + } + } + + // Occasional issue: two final data points at the same time, + // one zero and one not. We'll throw the 0 point out. + int n = time.size() - 1; + if (MathUtil.equals(time.get(n-1), time.get(n))) { + if (MathUtil.equals(thrust.get(n-1), 0)) { + System.out.println("\twarning: two final data points at time=" + time.get(n) + "; one is 0"); + time.remove(n-1); + thrust.remove(n-1); + for (List l : lists) { + l.remove(n-1); + } + } else if (MathUtil.equals(thrust.get(n), 0)) { + System.out.println("\twarning: two final data points at time=" + time.get(n) + "; one is 0"); + time.remove(n); + thrust.remove(n); + for (List l : lists) { + l.remove(n); + } + } + } + // End // Ah, no, we don't want to do this (I'm leaving the dead code // in case there's a temptation to put it back in). This ends @@ -221,6 +260,7 @@ public abstract class AbstractMotorLoader implements MotorLoader { // l.add(o); // } // } + } } diff --git a/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java b/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java index 68073b0ee..d2f8a7f51 100644 --- a/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java +++ b/core/src/net/sf/openrocket/motor/ThrustCurveMotor.java @@ -145,14 +145,15 @@ public class ThrustCurveMotor implements Motor, Comparable, Se if (motor.time.length < 2) { throw new IllegalArgumentException("Too short thrust-curve, length=" + motor.time.length); } + for (int i = 0; i < motor.time.length - 1; i++) { if (motor.time[i + 1] <= motor.time[i]) { - throw new IllegalArgumentException("Time stalls or goes backwards, " + - "time[" + i + "]=" + motor.time[i] + " " + - "time[" + (i + 1) + "]=" + motor.time[i + 1] + - ", thrust=(" + motor.thrust[i] + ", " + motor.thrust[i+1] + ")"); + throw new IllegalArgumentException("Two thrust values for single time point, " + + "time[" + i + "]=" + motor.time[i] + ", thrust=" + motor.thrust[i] + + "; time[" + (i + 1) + "]=" + motor.time[i + 1] + ", thrust=" + motor.thrust[i+1]); } } + if (!MathUtil.equals(motor.time[0], 0)) { throw new IllegalArgumentException("Curve starts at time " + motor.time[0]); } diff --git a/core/src/net/sf/openrocket/thrustcurve/SerializeThrustcurveMotors.java b/core/src/net/sf/openrocket/thrustcurve/SerializeThrustcurveMotors.java index 173e26375..7adef3a03 100644 --- a/core/src/net/sf/openrocket/thrustcurve/SerializeThrustcurveMotors.java +++ b/core/src/net/sf/openrocket/thrustcurve/SerializeThrustcurveMotors.java @@ -145,7 +145,7 @@ public class SerializeThrustcurveMotors { allMotors.add(builder.build()); } catch (IllegalArgumentException e) { - System.out.println("\tError in simFile " + burnFile.getSimfileId() + ": " + e.getMessage() + " (continuing)"); + System.out.println("\tError in simFile " + burnFile.getSimfileId() + ": " + e.getMessage()); try { FileOutputStream out = new FileOutputStream(("simfile-" + burnFile.getSimfileId()).toString()); out.write(burnFile.getContents().getBytes());