1818
1919import fr .jmmc .oitools .fits .FitsUtils ;
2020import fr .jmmc .oitools .model .OIFitsChecker ;
21+ import fr .jmmc .oitools .model .OIFitsCollection ;
2122import fr .jmmc .oitools .model .OIFitsFile ;
2223import fr .jmmc .oitools .model .OIFitsLoader ;
2324import fr .jmmc .oitools .model .OIFitsWriter ;
@@ -37,9 +38,11 @@ public class OIFitsProcessor extends OIFitsCommand {
3738 private static final String COMMAND_HELP = "help" ;
3839 private static final String COMMAND_LIST = "list" ;
3940 private static final String COMMAND_CONVERT = "convert" ;
41+ private static final String COMMAND_DUMP = "dump" ;
4042 private static final String COMMAND_MERGE = "merge" ;
4143
4244 private static final String OPTION_OUTPUT = "-output" ;
45+ private static final String OPTION_TARGET = "-target" ;
4346 private static final String OPTION_INSNAME = "-insname" ;
4447
4548 /**
@@ -62,7 +65,7 @@ public static void main(final String[] args) {
6265 // command processing
6366 if (COMMAND_HELP .equals (command )) {
6467 showArgumentsHelp ();
65- } else if ("dump" .equals (command )) {
68+ } else if (COMMAND_DUMP .equals (command )) {
6669 dump (args );
6770 } else if (COMMAND_LIST .equals (command )) {
6871 list (args );
@@ -88,9 +91,17 @@ public static void main(final String[] args) {
8891 */
8992 private static void list (final String [] args ) throws FitsException , IOException {
9093 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+ }
91103
92- // TODO: implement later a simplified output
93- OIFitsViewer .process (false , true , false , false , fileLocations );
104+ OIFitsCollectionViewer .process (oiFitsCollection );
94105 }
95106
96107 /**
@@ -101,18 +112,18 @@ private static void list(final String[] args) throws FitsException, IOException
101112 private static void dump (final String [] args ) throws FitsException , IOException {
102113 final List <String > fileLocations = getInputFiles (args );
103114
104- FitsUtils .setup ();
105-
115+ FitsUtils .setup ();
116+
106117 final StringBuilder sb = new StringBuilder (16 * 1024 );
107-
118+
108119 for (String fileLocation : fileLocations ) {
109120 info ("Processing: " + fileLocation );
110121 try {
111122 FitsUtils .dumpFile (fileLocation , false , sb );
112-
123+
113124 info (sb .toString ());
114125 sb .setLength (0 ); // reset
115-
126+
116127 } catch (Exception e ) {
117128 error ("Error reading file '" + fileLocation + "'" , e );
118129 }
@@ -153,29 +164,28 @@ private static void merge(final String[] args) throws FitsException, IOException
153164 final String outputFilePath = getOutputFilepath (args );
154165 final boolean check = hasOptionArg (args , "-c" , "-check" );
155166
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 );
157170
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 );
162172
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 );
168179 }
169180
170181 // Call merge
171- final OIFitsFile result = Merger .process (selector , inputs );
182+ final OIFitsFile result = Merger .process (oiFitsCollection , selector );
172183 if (result .hasOiData ()) {
173184 // Store result
174185 write (outputFilePath , result , check );
175186 } else {
176187 info ("Result is empty, no file created." );
177188 }
178-
179189 }
180190
181191 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,
185195 info ("validation results:\n " + checker .getCheckReport ());
186196 }
187197
198+ info ("Writing: " + outputFilePath );
188199 // Store result
189200 OIFitsWriter .writeOIFits (outputFilePath , result );
190201 }
@@ -221,7 +232,9 @@ private static List<String> getInputFiles(String[] args) {
221232
222233 for (int i = 1 ; i < args .length ; i ++) {
223234 // 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 ])
225238 || OPTION_INSNAME .equals (args [i ])) {
226239 i ++; // skip next parameter which is the output file
227240 } else if (args [i ].startsWith ("-" )) {
@@ -248,13 +261,15 @@ protected static void showArgumentsHelp() {
248261 info ("|------------------------------------------------------------------------------------|" );
249262 info ("| command " + COMMAND_HELP + " Show this help |" );
250263 info ("| command " + COMMAND_LIST + " List content of several oifits files |" );
264+ info ("| command " + COMMAND_DUMP + " Dump the given oifits files |" );
251265 info ("| command " + COMMAND_CONVERT + " Convert the given input file |" );
252266 info ("| command " + COMMAND_MERGE + " Merge several oifits files |" );
253267 info ("| " + OPTION_OUTPUT .substring (0 , 2 ) + " or " + OPTION_OUTPUT
254268 + " <file_path> Complete path, absolute or relative, for output file |" );
255269 info ("| [-l] or [-log] Enable logging (quiet by default) |" );
256270 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 |" );
258273 info ("--------------------------------------------------------------------------------------" );
259274 }
260275
0 commit comments