/*
    Copyright (C) 2012 Bartosz Broda, Jacek Bochenek, Łukasz Biłeńkij, 
    Damian Jaworski, Wojciech Mazur, Dominik Piasecki, Maciej Piasecki, 
    Radosław Ramocki
    
    This program 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.

    This program 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 LICENSE and COPYING files for more details.
*/

#include "Options.h"

namespace clustering
{
	namespace som
	{
		Options::Options(int argc, char **argv)
		{
			ParseOptions(argc, argv);
		}

		Params & Options::GetParams()
		{
			return params;
		}

		void Options::ParseOptions(int argc, char**argv)
		{
			using namespace boost::program_options;

			options_description desc;

			desc.add_options()
					("help", "Print this text")
					("matrix-dir", value<std::string>(& params.matrix_dir), "Path to supermatrix")
					("matrix-name", value<std::string>(& params.matrix_name), "Name of supermatrix")
					("output-file", value<std::string>(& params.output_file), "Clustering output file")
					("cluto-file", value<std::string>(& params.cluto_file), "Clustering output file in cluto format")
					("cmp-fun", value<std::string>(& params.cmp_function), "Compare function used to weight matrix")
					("t1", value<double>(& params.t1)->default_value(0.75), "Horizontal expansion threshold")
					("t2", value<double>(& params.t2)->default_value(0.05), "Vertical expansion threshold")
					("first", value<bool>(& params.firstOnly)->default_value(false, "false"), "Save first layer only");

			variables_map vm;
			store(parse_command_line(argc, argv, desc), vm);
			notify(vm);

			if(vm.count("help") || argc == 1)
			{
				std::cout << "Ghsom clustering application\n" << desc << std::endl;
				exit(0);
			}

			if(!vm.count("matrix-dir"))
				throw std::runtime_error("parameter matrix-dir must be defined");
			if(!vm.count("matrix-name"))
				throw std::runtime_error("parameter matrix-name must be defined");
			if(!vm.count("cmp-fun"))
				throw std::runtime_error("parameter cmp-fun must be defined");

			if(!vm.count("output-file"))
				params.output_file = "";
			if(!vm.count("cluto-file"))
				params.cluto_file = "";

		}
	}
}
