summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjan.reininghaus <jan.reininghaus@8e3bb3c2-eed4-f18f-5264-0b6c94e6926d>2013-07-16 12:14:42 +0000
committerjan.reininghaus <jan.reininghaus@8e3bb3c2-eed4-f18f-5264-0b6c94e6926d>2013-07-16 12:14:42 +0000
commita46bd27517be340115c34df6c38ceaa25625f0b4 (patch)
tree09421be3abd756c937fb0b013bd705a5e57ccfe0 /src
parent85132716d335a05bb35f8bb48c65d1c6dce934d3 (diff)
new binary format and convert utility
git-svn-id: https://phat.googlecode.com/svn/trunk@135 8e3bb3c2-eed4-f18f-5264-0b6c94e6926d
Diffstat (limited to 'src')
-rw-r--r--src/convert.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/convert.cpp b/src/convert.cpp
new file mode 100644
index 0000000..ae3304a
--- /dev/null
+++ b/src/convert.cpp
@@ -0,0 +1,70 @@
+/* Copyright 2013 IST Austria
+ Contributed by: Ulrich Bauer, Michael Kerber, Jan Reininghaus
+
+ This file is part of PHAT.
+
+ PHAT is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ PHAT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with PHAT. If not, see <http://www.gnu.org/licenses/>. */
+
+
+#include <phat/representations/vector_vector.h>
+#include <phat/boundary_matrix.h>
+
+void print_help() {
+ std::cerr << "Usage: " << "convert " << "[options] input_filename output_filename" << std::endl;
+ std::cerr << std::endl;
+ std::cerr << "Options:" << std::endl;
+ std::cerr << std::endl;
+ std::cerr << "--ascii -- use ascii file format for input_filename" << std::endl;
+ std::cerr << "--binary -- use binary file format for input_filename (default)" << std::endl;
+ std::cerr << "--help -- prints this screen" << std::endl;
+}
+
+void print_help_and_exit() {
+ print_help();
+ exit( EXIT_FAILURE );
+}
+
+void parse_command_line( int argc, char** argv, bool& use_binary, std::string& input_filename, std::string& output_filename) {
+
+ if( argc < 3 ) print_help_and_exit();
+
+ input_filename = argv[ argc - 2 ];
+ output_filename = argv[ argc - 1 ];
+
+ for( int idx = 1; idx < argc - 2; idx++ ) {
+ const std::string option = argv[ idx ];
+
+ if( option == "--ascii" ) use_binary = false;
+ else if( option == "--binary" ) use_binary = true;
+ else if( option == "--help" ) print_help_and_exit();
+ else print_help_and_exit();
+ }
+}
+
+int main( int argc, char** argv )
+{
+ bool use_binary = true; // interpret input as binary or ascii file
+ std::string input_filename; // name of file that contains the boundary matrix
+ std::string output_filename; // name of file that will contain the boundary matrix in the new binary format
+
+ parse_command_line( argc, argv, use_binary, input_filename, output_filename );
+
+ phat::boundary_matrix< phat::bit_tree_pivot_column > matrix;
+ if( use_binary )
+ matrix.load_binary( input_filename );
+ else
+ matrix.load_ascii( input_filename );
+
+ matrix.save_binary( output_filename );
+}