1 /**
2  * Copyright 2007-2021 IMP Inventors. All rights reserved.
3  */
4 
5 #include <exception>
6 #include <iostream>
7 #include <string>
8 #include <vector>
9 
10 #include "RMF/FileConstHandle.h"
11 #include "RMF/FileHandle.h"
12 #include "RMF/ID.h"
13 #include "RMF/infrastructure_macros.h"
14 #include "RMF/utility.h"
15 #include "common.h"
16 
17 namespace {
18 std::vector<std::string> inputs;
19 std::string description("Combine two or more rmf files.");
20 std::string output;
21 }
main(int argc,char ** argv)22 int main(int argc, char** argv) {
23   try {
24     positional_options.add_options()(
25         "input-files,i",
26         boost::program_options::value<std::vector<std::string> >(&inputs),
27         "input rmf file");
28     positional_names.push_back("input_1.rmf input_2.rmf ... output.rmf");
29     positional_options_description.add("input-files", -1);
30     process_options(argc, argv);
31     if (inputs.size() < 3) {
32       print_help_and_exit(argv);
33     }
34 
35     output = inputs.back();
36     inputs.pop_back();
37     RMF::FileHandle orh = RMF::create_rmf_file(output);
38     orh.set_producer("rmf_cat");
39     for (unsigned int i = 0; i < inputs.size(); ++i) {
40       RMF::FileConstHandle rh = RMF::open_rmf_file_read_only(inputs[i]);
41       if (i == 0) {
42         RMF::clone_file_info(rh, orh); // creator etc. (not essential)
43         RMF::clone_hierarchy(rh, orh);
44         RMF::clone_static_frame(rh, orh);
45       }
46       orh.set_description(orh.get_description() + "\n" + rh.get_description());
47       RMF_FOREACH(RMF::FrameID ni, rh.get_frames()) {
48         rh.set_current_frame(ni);
49         orh.add_frame(rh.get_name(ni), rh.get_type(ni));
50         RMF::clone_loaded_frame(rh, orh);
51       }
52     }
53     return 0;
54   }
55   catch (const std::exception& e) {
56     std::cerr << "Error: " << e.what() << std::endl;
57   }
58 }
59