/*\file Reducematrixfromgtof.c
 *\brief: reduce matrix from g set to f set.
 */

#include "./Reducematrixfromgtof.h"

void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]){

	/*diverse: */
	int   noerr=1;

	/*input datasets: */
	Mat Kgg=NULL;
	Mat Gmn=NULL;
	NodeSets* nodesets=NULL;

	/* output datasets: */
	Mat Kff=NULL;
	Mat Kfs=NULL;

	/*Boot module: */
	MODULEBOOT();

	/*checks on arguments on the matlab side: */
	CheckNumMatlabArguments(nlhs,NLHS,nrhs,NRHS,__FUNCT__,&ReducematrixfromgtofUsage);

	/*Input datasets: */
	FetchData((void**)&Kgg,NULL,NULL,KGG,"Matrix",NULL);
	FetchData((void**)&Gmn,NULL,NULL,GMN,"Matrix",NULL);
	FetchNodeSets(&nodesets,NODESETS);

	/*!Reduce matrix from g to f size:*/
	Reducematrixfromgtofx(&Kff,&Kfs,Kgg,Gmn,nodesets);

	/*write output datasets: */
	WriteData(KFF,Kff,0,0,"Matrix",NULL);
	WriteData(KFS,Kfs,0,0,"Matrix",NULL);

	/*Free ressources: */
	delete nodesets;
	MatFree(&Kgg);
	MatFree(&Gmn);
	MatFree(&Kff);
	MatFree(&Kfs);

	/*end module: */
	MODULEEND();
}

void ReducematrixfromgtofUsage(void)
{
	_printf_("\n");
	_printf_("   usage: [Kff,Kfs] = %s(Kgg,Gmn,nodeses);\n",__FUNCT__);
	_printf_("\n");
}
