#include "Includes/posteriors.ibf";

_labels   = {{"Class","Log likelihood"}};
_CLASSES_ = {_sites,2};

_CLASS_COUNT  = {};
_CLASS_STRING = {};


for (_counter2 = 0; _counter2 < _sites; _counter2 = _counter2 + 1)
{
	_maxP = 0;
	_maxC = 0;
	for (_counter3 = 0; _counter3 < _classes; _counter3 = _counter3 + 1)
	{
		if (_MARGINAL_MATRIX_[_counter3][_counter2] > _maxP)
		{
			_maxP = _MARGINAL_MATRIX_[_counter3][_counter2];
			_maxC = _counter3;
		}
	}
	_CLASSES_ [_counter2][0] = _maxC;
	_CLASSES_ [_counter2][1] = Log(STASH_MARGINAL_MATRIX[_maxC][_counter2]);
	
	_CLASS_COUNT [_maxC] = _CLASS_COUNT [_maxC] + 1;
	if (Abs(_CLASS_STRING[_maxC]))
	{
		_CLASS_STRING[_maxC] = _CLASS_STRING[_maxC] + "," + (3*_counter2) + "-" + (3*_counter2+2);
	}
	else
	{
		_CLASS_STRING[_maxC] =  "" + (3*_counter2) + "-" + (3*_counter2+2);
	}
	
}


promptString = "Class Assignments for Sites for " + _CATEGORY_VARIABLE_ID_;

OpenWindow (CHARTWINDOW,{{promptString}
						   {"_labels"},
						   {"_CLASSES_"},
						   {"Bar Chart"},
						   {"Index"},
						   {"Class"},
						   {""},
						   {""},
						   {""},
						   {"0"}},
						   "SCREEN_WIDTH-60;SCREEN_HEIGHT-50;30;50");
						   
_labels = 0;
_sites  = 0;

for (_counter3 = 0; _counter3 < _classes; _counter3 = _counter3 + 1)
{
	fprintf (stdout, "\n", _CLASS_COUNT[_counter3], " sites in class ", _counter3);
}

fprintf (stdout, "\n");

for (_counter3 = 0; _counter3 < _classes; _counter3 = _counter3 + 1)
{
	fprintf (stdout, "\nSites in class ", _counter3, "\n", _CLASS_STRING[_counter3]);
}

fprintf (stdout, "\n");
