Main Page | Namespace List | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Examples

pdb_cat.cc

00001 /* Copyright 2004
00002 Stanford University
00003 
00004 This file is part of the DSR PDB Library.
00005 
00006 The DSR PDB Library is free software; you can redistribute it and/or modify
00007 it under the terms of the GNU Lesser General Public License as published by
00008 the Free Software Foundation; either version 2.1 of the License, or (at your
00009 option) any later version.
00010 
00011 The DSR PDB Library is distributed in the hope that it will be useful, but
00012 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00013 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00014 License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public License
00017 along with the DSR PDB Library; see the file COPYING.LIB.  If not, write to
00018 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00019 MA 02111-1307, USA. */
00020 
00021 #include "dsrpdb/PDB.h"
00022 #include <cstdlib>
00023 #include <iostream>
00024 #include <fstream>
00025 
00026 #ifdef PDB_USE_BOOST_PROGRAM_OPTIONS
00027 #include <boost/program_options.hpp>
00028 #endif
00029 
00030 int main(int argc, char *argv[]){
00031   std::vector<std::string> input_files;
00032   std::string output_file;
00033   bool print_help=false;
00034   bool verbose=false;
00035 
00036 #ifdef PDB_USE_BOOST_PROGRAM_OPTIONS
00037   {
00038     boost::program_options::options_description o("Allowed options"), po, ao;
00039     o.add_options()
00040       ("help", boost::program_options::bool_switch(&print_help), "produce help message")
00041       ("verbose,v", boost::program_options::bool_switch(&verbose), 
00042        "Print error messages from reading the pdb files.");
00043     po.add_options()
00044       ("input-pdbs", boost::program_options::value< std::vector<std::string> >(&input_files),
00045        "The input and output files.");
00046 
00047     ao.add(o).add(po);
00048     
00049     boost::program_options::positional_options_description p;
00050     p.add("input-pdbs", -1);
00051 
00052     boost::program_options::variables_map vm;
00053     boost::program_options::store(boost::program_options::command_line_parser(argc, argv).
00054                                   options(ao).positional(p).run(), vm);
00055     boost::program_options::notify(vm);
00056 
00057     
00058     if (input_files.size() <2 || print_help) {
00059       std::cout << "Concatenate a bunch of pdb files into one pdb file with many models.\n";
00060       std::cout << "usage: " << argv[0] << " input-pdb-0 input-pdb-1 ... output-pdb\n";
00061       std::cout << o << "\n";
00062       return EXIT_FAILURE;
00063     }
00064 
00065     output_file=input_files.back();
00066     input_files.pop_back();
00067   }
00068 
00069 #else
00070   for (int i=1; i< argc-1; ++i){
00071     input_files.push_back(argv[i]);
00072   }
00073   output_file = argv[argc-1];
00074 #endif
00075 
00076   
00077   dsrpdb::PDB outpdb;
00078 
00079   for (unsigned int i=0; i < input_files.size(); ++i){
00080     std::ifstream in(input_files[i].c_str());
00081     if (!in){
00082       std::cerr << "Error opening input file " << input_files[i] << std::endl;
00083       return EXIT_FAILURE;
00084     }
00085     dsrpdb::PDB inpdb(in, verbose);
00086     
00087     for (dsrpdb::PDB::Models_iterator mit= inpdb.models_begin(); mit != inpdb.models_end(); ++mit){
00088       dsrpdb::Model m= *mit;
00089       m.set_index(outpdb.number_of_models());
00090       outpdb.new_model(m);
00091     }
00092   }
00093   
00094   if (output_file.empty()){
00095     outpdb.write(std::cout);
00096   } else {
00097     std::ofstream out(output_file.c_str());
00098     outpdb.write(out);
00099   }
00100 
00101 
00102   return EXIT_SUCCESS;
00103 }