updates for 0.9.3
[debian/openrocket] / src / net / sf / openrocket / utils / MotorCheck.java
1 package net.sf.openrocket.utils;
2
3 import java.io.FileInputStream;
4 import java.io.IOException;
5 import java.io.InputStream;
6 import java.util.List;
7
8 import net.sf.openrocket.file.GeneralMotorLoader;
9 import net.sf.openrocket.file.MotorLoader;
10 import net.sf.openrocket.motor.Manufacturer;
11 import net.sf.openrocket.motor.Motor;
12 import net.sf.openrocket.motor.ThrustCurveMotor;
13
14 public class MotorCheck {
15
16         // Warn if less that this many points
17         public static final int WARN_POINTS = 6;
18         
19
20         public static void main(String[] args) {
21                 MotorLoader loader = new GeneralMotorLoader();
22
23                 // Load files
24                 for (String file: args) {
25                         System.out.print("Checking " + file + "... ");
26                         System.out.flush();
27                         
28                         boolean ok = true;
29                         
30                         List<Motor> motors = null;
31                         try {
32                                 InputStream stream = new FileInputStream(file);
33                                 motors = loader.load(stream, file);
34                                 stream.close();
35                         } catch (IOException e) {
36                                 System.out.println("ERROR: " + e.getMessage());
37                                 e.printStackTrace(System.out);
38                                 ok = false;
39                         }
40                         
41                         String base = file.split("_")[0];
42                         Manufacturer mfg = Manufacturer.getManufacturer(base);
43                         
44                         if (motors != null) {
45                                 if (motors.size() == 0) {
46                                         System.out.println("ERROR: File contained no motors");
47                                         ok = false;
48                                 } else {
49                                         for (Motor m: motors) {
50                                                 double sum = 0;
51                                                 sum += m.getAverageThrust();
52                                                 sum += m.getAverageTime();
53                                                 sum += m.getTotalImpulse();
54                                                 sum += m.getTotalTime();
55                                                 sum += m.getDiameter();
56                                                 sum += m.getLength();
57                                                 sum += m.getMass(0);
58                                                 sum += m.getMass(Double.POSITIVE_INFINITY);
59                                                 sum += m.getCG(0).x;
60                                                 sum += m.getCG(0).weight;
61                                                 sum += m.getMaxThrust();
62                                                 if (Double.isInfinite(sum) || Double.isNaN(sum)) {
63                                                         System.out.println("ERROR: Invalid motor values");
64                                                         ok = false;
65                                                 }
66                                                 
67                                                 if (m.getManufacturer() != mfg) {
68                                                         System.out.println("ERROR: Inconsistent manufacturer " + 
69                                                                         m.getManufacturer() + " (file name indicates " + mfg 
70                                                                         + ")");
71                                                         ok = false;
72                                                 }
73                                                 
74                                                 int points = ((ThrustCurveMotor)m).getTimePoints().length;
75                                                 if (points < WARN_POINTS) {
76                                                         System.out.println("WARNING: Only " + points + " data points");
77                                                         ok = false;
78                                                 }
79                                         }
80                                 }
81                         }
82                         
83                         if (ok) {
84                                 System.out.println("OK");
85                         }
86                 }
87         }
88 }