//---------------------------------------------------------------------------

#include "stdafx.h"

#ifdef _MSC_VER
#pragma hdrstop
#endif

using namespace std;

#include "../../Kernel/myExcept.h"

#include "CovMatrix.h"

CovMatrix::CovMatrix( const unsigned int _rows, const unsigned int _cols )
{
	unsigned int i;

	rownum = _rows;
	colnum = _cols;

	matrix = new bool*[rownum];
	if ( matrix == NULL) throw RuntimeException( "CovMatrix: Not enough memory" );
	for ( i = 0; i < rownum; i++ ) {
		matrix[i] = new bool[colnum];
		if ( matrix[i] == NULL) throw RuntimeException( "CovMatrix: Not enough memory" );
	}
	costs.resize( colnum, 1 );
}

CovMatrix::~CovMatrix(void)
{
	unsigned int i;

	for ( i = 0; i < rownum; i++ ) delete matrix[i];
	delete matrix;
}

void CovMatrix::DumpMatrix( const char *fn ) const
{
	unsigned int i, j;
	ofstream f;

	f.open(fn);
	f << rownum << endl;
	f << colnum << endl;
	for ( i = 0; i < colnum; i++ )
		f << costs[i] << " ";
	f << endl;
	for ( i = 0; i < rownum; i++ ) {
		for ( j = 0; j < colnum; j++ )
			if ( matrix[i][j] ) f << "1";
			else f << "0";
		f << endl;
	}
	f.close();
}
