18
18
19
19
import fr .jmmc .oitools .fits .FitsUtils ;
20
20
import fr .jmmc .oitools .model .OIFitsChecker ;
21
+ import fr .jmmc .oitools .model .OIFitsCollection ;
21
22
import fr .jmmc .oitools .model .OIFitsFile ;
22
23
import fr .jmmc .oitools .model .OIFitsLoader ;
23
24
import fr .jmmc .oitools .model .OIFitsWriter ;
@@ -37,9 +38,11 @@ public class OIFitsProcessor extends OIFitsCommand {
37
38
private static final String COMMAND_HELP = "help" ;
38
39
private static final String COMMAND_LIST = "list" ;
39
40
private static final String COMMAND_CONVERT = "convert" ;
41
+ private static final String COMMAND_DUMP = "dump" ;
40
42
private static final String COMMAND_MERGE = "merge" ;
41
43
42
44
private static final String OPTION_OUTPUT = "-output" ;
45
+ private static final String OPTION_TARGET = "-target" ;
43
46
private static final String OPTION_INSNAME = "-insname" ;
44
47
45
48
/**
@@ -62,7 +65,7 @@ public static void main(final String[] args) {
62
65
// command processing
63
66
if (COMMAND_HELP .equals (command )) {
64
67
showArgumentsHelp ();
65
- } else if ("dump" .equals (command )) {
68
+ } else if (COMMAND_DUMP .equals (command )) {
66
69
dump (args );
67
70
} else if (COMMAND_LIST .equals (command )) {
68
71
list (args );
@@ -88,9 +91,17 @@ public static void main(final String[] args) {
88
91
*/
89
92
private static void list (final String [] args ) throws FitsException , IOException {
90
93
final List <String > fileLocations = getInputFiles (args );
94
+ final boolean check = hasOptionArg (args , "-c" , "-check" );
95
+
96
+ final OIFitsChecker checker = new OIFitsChecker ();
97
+
98
+ final OIFitsCollection oiFitsCollection = OIFitsCollection .create (checker , fileLocations );
99
+
100
+ if (check ) {
101
+ info ("validation results:\n " + checker .getCheckReport ());
102
+ }
91
103
92
- // TODO: implement later a simplified output
93
- OIFitsViewer .process (false , true , false , false , fileLocations );
104
+ OIFitsCollectionViewer .process (oiFitsCollection );
94
105
}
95
106
96
107
/**
@@ -101,18 +112,18 @@ private static void list(final String[] args) throws FitsException, IOException
101
112
private static void dump (final String [] args ) throws FitsException , IOException {
102
113
final List <String > fileLocations = getInputFiles (args );
103
114
104
- FitsUtils .setup ();
105
-
115
+ FitsUtils .setup ();
116
+
106
117
final StringBuilder sb = new StringBuilder (16 * 1024 );
107
-
118
+
108
119
for (String fileLocation : fileLocations ) {
109
120
info ("Processing: " + fileLocation );
110
121
try {
111
122
FitsUtils .dumpFile (fileLocation , false , sb );
112
-
123
+
113
124
info (sb .toString ());
114
125
sb .setLength (0 ); // reset
115
-
126
+
116
127
} catch (Exception e ) {
117
128
error ("Error reading file '" + fileLocation + "'" , e );
118
129
}
@@ -153,29 +164,28 @@ private static void merge(final String[] args) throws FitsException, IOException
153
164
final String outputFilePath = getOutputFilepath (args );
154
165
final boolean check = hasOptionArg (args , "-c" , "-check" );
155
166
156
- final OIFitsFile [] inputs = new OIFitsFile [fileLocations .size ()];
167
+ // Optional filters:
168
+ final String targetUID = getOptionArgValue (args , OPTION_TARGET );
169
+ final String insModeUID = getOptionArgValue (args , OPTION_INSNAME );
157
170
158
- // Get input files
159
- for (int i = 0 ; i < fileLocations .size (); i ++) {
160
- inputs [i ] = OIFitsLoader .loadOIFits (fileLocations .get (i ));
161
- }
171
+ final OIFitsCollection oiFitsCollection = OIFitsCollection .create (null , fileLocations );
162
172
163
- Selector selector = null ;
164
- int positionOptionFilter = getOptionArgPosition (args , OPTION_INSNAME , OPTION_INSNAME );
165
- if (positionOptionFilter > -1 && args .length > positionOptionFilter + 1 ) {
166
- selector = new Selector ();
167
- selector .addPattern (Selector .INSTRUMENT_FILTER , args [positionOptionFilter + 1 ]);
173
+ final Selector selector = new Selector ();
174
+ if (targetUID != null ) {
175
+ selector .setTargetUID (targetUID );
176
+ }
177
+ if (insModeUID != null ) {
178
+ selector .setInsModeUID (insModeUID );
168
179
}
169
180
170
181
// Call merge
171
- final OIFitsFile result = Merger .process (selector , inputs );
182
+ final OIFitsFile result = Merger .process (oiFitsCollection , selector );
172
183
if (result .hasOiData ()) {
173
184
// Store result
174
185
write (outputFilePath , result , check );
175
186
} else {
176
187
info ("Result is empty, no file created." );
177
188
}
178
-
179
189
}
180
190
181
191
private static void write (final String outputFilePath , final OIFitsFile result , final boolean check ) throws IOException , FitsException {
@@ -185,6 +195,7 @@ private static void write(final String outputFilePath, final OIFitsFile result,
185
195
info ("validation results:\n " + checker .getCheckReport ());
186
196
}
187
197
198
+ info ("Writing: " + outputFilePath );
188
199
// Store result
189
200
OIFitsWriter .writeOIFits (outputFilePath , result );
190
201
}
@@ -221,7 +232,9 @@ private static List<String> getInputFiles(String[] args) {
221
232
222
233
for (int i = 1 ; i < args .length ; i ++) {
223
234
// note: should be generalized to any argument having value(s):
224
- if (OPTION_OUTPUT .substring (0 , 2 ).equals (args [i ]) || OPTION_OUTPUT .equals (args [i ])
235
+ if (OPTION_OUTPUT .substring (0 , 2 ).equals (args [i ])
236
+ || OPTION_OUTPUT .equals (args [i ])
237
+ || OPTION_TARGET .equals (args [i ])
225
238
|| OPTION_INSNAME .equals (args [i ])) {
226
239
i ++; // skip next parameter which is the output file
227
240
} else if (args [i ].startsWith ("-" )) {
@@ -248,13 +261,15 @@ protected static void showArgumentsHelp() {
248
261
info ("|------------------------------------------------------------------------------------|" );
249
262
info ("| command " + COMMAND_HELP + " Show this help |" );
250
263
info ("| command " + COMMAND_LIST + " List content of several oifits files |" );
264
+ info ("| command " + COMMAND_DUMP + " Dump the given oifits files |" );
251
265
info ("| command " + COMMAND_CONVERT + " Convert the given input file |" );
252
266
info ("| command " + COMMAND_MERGE + " Merge several oifits files |" );
253
267
info ("| " + OPTION_OUTPUT .substring (0 , 2 ) + " or " + OPTION_OUTPUT
254
268
+ " <file_path> Complete path, absolute or relative, for output file |" );
255
269
info ("| [-l] or [-log] Enable logging (quiet by default) |" );
256
270
info ("| [-c] or [-check] Check output file before writing |" );
257
- info ("| [-insname] <insname_value> Filter result on given insname |" );
271
+ info ("| [-target] <target value> Filter result on given target |" );
272
+ info ("| [-insname] <insname value> Filter result on given insname |" );
258
273
info ("--------------------------------------------------------------------------------------" );
259
274
}
260
275
0 commit comments