@@ -60,8 +60,8 @@ public class CRUSH extends Configurator implements BasicMessaging {
60
60
*/
61
61
private static final long serialVersionUID = 6284421525275783456L ;
62
62
63
- private static String version = "2.42-1 " ;
64
- private static String revision = "" ;
63
+ private static String version = "2.42-2 " ;
64
+ private static String revision = "devel.2 " ;
65
65
66
66
public static String workPath = "." ;
67
67
public static String home = "." ;
@@ -84,26 +84,8 @@ public class CRUSH extends Configurator implements BasicMessaging {
84
84
private int configDepth = 0 ; // Used for 'nested' output of invoked configurations.
85
85
86
86
87
- public static void main (String [] args ) {
88
- info ();
89
-
90
- Util .setReporter (broadcaster );
91
-
92
- if (args .length == 0 ) {
93
- usage ();
94
- new CRUSH ().checkJavaVM (0 );
95
- System .exit (0 );
96
- }
97
-
98
- if (args [0 ].equalsIgnoreCase ("-help" )) {
99
- help (null );
100
- System .exit (0 );
101
- }
102
-
103
- home = System .getenv ("CRUSH" );
104
- if (home == null ) home = "." ;
105
-
106
- CRUSH crush = new CRUSH (args [0 ]);
87
+ public static void main (String [] args ) {
88
+ CRUSH crush = new CRUSH ();
107
89
108
90
crush .checkJavaVM (5 );
109
91
crush .checkForUpdates ();
@@ -114,19 +96,78 @@ public static void main(String[] args) {
114
96
}
115
97
catch (Exception e ) { crush .error (e ); }
116
98
99
+ crush .shutdown ();
100
+
117
101
// TODO should not be needed if background processes are all wrapped up...
118
- crush .exit (0 );
102
+ System .exit (0 );
119
103
}
120
104
121
- private CRUSH () {
105
+ public CRUSH () {
106
+ info ();
107
+
122
108
Locale .setDefault (Locale .US );
123
109
FitsFactory .setUseHierarch (true );
124
110
FitsFactory .setLongStringsEnabled (true );
111
+
112
+ Util .setReporter (broadcaster );
113
+
114
+ home = System .getenv ("CRUSH" );
115
+ if (home == null ) home = "." ;
116
+ }
117
+
118
+ /**
119
+ * Initialize CRUSH for the given instrument, and no extra options...
120
+ *
121
+ * @param instrumentName The instrument to use CRUSH with, e.g. "sharc2", or "hirmes"
122
+ * @throws Exception If CRUSH could not be initialized with the specified instrument name.
123
+ */
124
+ public final void init (String instrumentName ) throws Exception {
125
+ init (new String [] { instrumentName });
125
126
}
127
+
128
+ /**
129
+ * Same as {@link init(String[])} except the arguments as specified as a List rather than
130
+ * an array.
131
+ * @see init(String[])
132
+ *
133
+ * @param args A list of arguments, like on the command-line. See {@link init(String[]) for
134
+ * more.
135
+ * @throws Exception An exception indicative of a problem encountered during initialization.
136
+ */
137
+ public final void init (List <String > args ) throws Exception {
138
+ String [] array = new String [args .size ()];
139
+ args .toArray (array );
140
+ init (array );
141
+ }
142
+
143
+
144
+ /**
145
+ * Initialize CRUSH for the given argument list, as if the list were command-line arguments.
146
+ *
147
+ *
148
+ * @param args The list of argument to initialize CRUSH with. The first argument must be the
149
+ * instrument name to use CRUSH with, e.g. "sharc2" or "hirmes", or else "-help"
150
+ * to print just a help screen. The arguments that follow must either be options,
151
+ * starting with a dash ('-'), or else scan specifiers. E.g.
152
+ *
153
+ * { "hirmes", "-faint", "-flight=405", "68", "70-77" }
154
+ *
155
+ * @throws Exception An exception indicative of a problem encountered during initialization.
156
+ */
157
+ public void init (String [] args ) throws Exception {
126
158
127
- public CRUSH (String instrumentName ) {
128
- this ();
159
+ if (args .length == 0 ) {
160
+ usage ();
161
+ System .exit (0 );
162
+ }
129
163
164
+ if (args [0 ].equalsIgnoreCase ("-help" )) {
165
+ help (null );
166
+ System .exit (0 );
167
+ }
168
+
169
+ String instrumentName = args [0 ];
170
+
130
171
instrument = Instrument .forName (instrumentName .toLowerCase ());
131
172
instrument .setOptions (this );
132
173
@@ -135,16 +176,8 @@ public CRUSH(String instrumentName) {
135
176
System .exit (1 );
136
177
}
137
178
138
- info (this , "Instrument is " + instrument .getName ().toUpperCase ());
139
- }
140
-
141
- public boolean hasOption (String name ) {
142
- return isConfigured (name );
143
- }
144
-
145
- public Configurator option (String name ) { return get (name ); }
146
-
147
- public void init (String [] args )throws Exception {
179
+ info (this , "Instrument is " + instrument .getName ().toUpperCase ());
180
+
148
181
readConfig ("default.cfg" );
149
182
150
183
this .args = args ;
@@ -153,6 +186,14 @@ public void init(String[] args)throws Exception {
153
186
validate ();
154
187
}
155
188
189
+ public boolean hasOption (String name ) {
190
+ return isConfigured (name );
191
+ }
192
+
193
+ public Configurator option (String name ) { return get (name ); }
194
+
195
+
196
+
156
197
private void parseArgument (String arg ) {
157
198
if (arg .charAt (0 ) == '-' ) parseSilent (arg .substring (1 ));
158
199
else read (arg );
@@ -1003,10 +1044,13 @@ public void editHeader(Header header) throws HeaderCardException {
1003
1044
c .add (new HeaderCard ("COMMENT" , " ----------------------------------------------------" , false ));
1004
1045
}
1005
1046
1006
-
1007
- public void exit (int exitValue ) {
1047
+ public void shutdown () {
1008
1048
if (instrument != null ) instrument .shutdown ();
1009
1049
Util .setDefaultReporter ();
1050
+ }
1051
+
1052
+ public void exit (int exitValue ) {
1053
+ shutdown ();
1010
1054
System .exit (exitValue );
1011
1055
}
1012
1056
@@ -1123,9 +1167,9 @@ public final void process(int threads, ExecutorService executor) {
1123
1167
public static void remove (Reporter r ) { broadcaster .remove (r ); }
1124
1168
1125
1169
public static void removeReporter (String id ) { broadcaster .remove (id ); }
1170
+
1126
1171
1127
-
1128
-
1172
+
1129
1173
public static CRUSHConsoleReporter consoleReporter = new CRUSHConsoleReporter ("crush-console" );
1130
1174
public static Broadcaster broadcaster = new Broadcaster ("CRUSH-broadcast" , consoleReporter );
1131
1175
0 commit comments