/*
    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 "matrices_all.h"
#include <boost/filesystem/path.hpp>



void helpMsg(char* av)
{


	std::cout<<"Converting supermatrix format to ST format (compatible with SVD).\n"
			<<"Runtime format: "<<av<<" supermatrix_path output_file\n";
}

int main(int ac, char** av)
{
	Matrices::init_logging();
	if(ac>0 && (strcmp(av[1],"--help")==0))
	{
		helpMsg(av[0]);
		return 1;
	}
	if(ac!=3)
	{
		helpMsg(av[0]);
		throw std::runtime_error("Invalid number of parameters!\n");
		return -1;
	}
	std::string str(av[1]);
	char last_char = str[ str.length() -1 ];
	if(last_char == '\\' || last_char == '/')
		str = str.substr(0, str.length() -1 );
	boost::filesystem::path smPath(str);
	smPath.normalize();
	Matrices::SuperMatrixPtr superMatrix = Matrices::IO::LoadSuperMatrix(smPath.branch_path().string(), smPath.filename().c_str(),true,false);
	Matrices::IO::WriteCCSToST(*(superMatrix->GetCCS()),av[2]);
	return 0;
}
