1 package com.billkuker.rocketry.motorsim.io;
4 import java.io.FileOutputStream;
5 import java.io.IOException;
6 import java.io.OutputStream;
7 import java.text.DecimalFormat;
8 import java.text.NumberFormat;
9 import java.util.Collection;
12 import javax.measure.quantity.Duration;
13 import javax.measure.quantity.Force;
14 import javax.measure.quantity.Mass;
15 import javax.measure.unit.SI;
17 import org.jscience.physics.amount.Amount;
19 import com.billkuker.rocketry.motorsim.Burn;
20 import com.billkuker.rocketry.motorsim.CylindricalChamber;
21 import com.billkuker.rocketry.motorsim.GraphSimplifier;
23 public class ENGExporter {
25 public static void export(Iterable<Burn> bb, File f) throws IOException {
26 export(bb, new FileOutputStream(f));
29 public static void export(Iterable<Burn> bb, OutputStream os) throws IOException {
35 public static void export(Burn b, OutputStream os) throws IOException {
37 CylindricalChamber cha = (CylindricalChamber) b.getMotor().getChamber();
39 NumberFormat nf = new DecimalFormat("00.###");
41 StringBuffer out = new StringBuffer();
43 out.append(";Output from Motorsim, motorsim@billkuker.com\n");
44 out.append(";You must fill in Delays and Total Weight\n");
45 out.append(";Name Diameter Length Delays ProWt Wt Manufacturer\n");
46 out.append(b.getMotor().getName().replace(" ", "-") + " ");
48 double dia = cha.getOD().doubleValue(SI.MILLIMETER);
49 double len = cha.getLength().doubleValue(SI.MILLIMETER);
51 Amount<Mass> prop = b.getMotor().getGrain().volume(
52 Amount.valueOf(0, SI.MILLIMETER)).times(
53 b.getMotor().getFuel().getIdealDensity().times(
54 b.getMotor().getFuel().getDensityRatio())).to(
56 double wt = prop.doubleValue(SI.KILOGRAM);
58 out.append(nf.format(dia) + " " + nf.format(len) + " 0-0-0 "
59 + nf.format(wt) + " " + nf.format(wt) + " MF\n");
61 GraphSimplifier<Duration, Force> gs = null;
63 gs = new GraphSimplifier<Duration, Force>(b, "thrust", b.getData()
64 .keySet().iterator());
65 } catch (Exception e) {
71 for (Amount<Duration> t : gs.getDomain()) {
73 double thrust = gs.value(t).doubleValue(SI.NEWTON);
74 if (cnt < 10 && thrust == 0.0) {
75 continue; // This is a hack to ignore 0 thrust early in burn
78 out.append(nf.format(t.doubleValue(SI.SECOND)));
80 out.append(nf.format(thrust));
85 os.write(out.toString().getBytes());