/*
 * MakeC.c
 *
 *  Created on: 2009/02/15
 *      Author: H.Shouno
 *  This is a wrapper program for make_c() in Neocog.c by Prof.Fukushima.
 *
 */

#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include "mex.h"
#include "neocog_proto.h"

void mexFunction( int nlhs, mxArray *lhs[], int nrhs, const mxArray *rhs[] );

/*
 * Input & Output Arguments
 */

#define C_OUT		lhs[0] // output Gaussian filter matrix
#define C_SIZE_IN	rhs[0] // Size of C (in diameter)
#define A_IN		rhs[1] // connection radius
#define GAMMA_IN	rhs[2] // Decay late
#define CO_IN		rhs[3] // center value of C

//
// available expressions...
// C = MakeC( SIZE, Area, Gamma, CenterValue )
//


//
// Gateway function
//
void mexFunction( int nlhs, mxArray *lhs[], int nrhs, const mxArray *rhs[] )
{
	int na, i;
	double *coefp;
	double **c;
	double a, gamma, co;

	if( nrhs != 4 )		mexErrMsgTxt( "MakeC() requires input parameter(s): MakeC( SIZE, Area, Gamma, CenterValue )" );
	if( nlhs < 1 )		mexErrMsgTxt( "MakeC() requires ouput parameter(s): C = MakeC( Params )" );

	// right side
	na = (int)mxGetScalar( C_SIZE_IN );
	a = mxGetScalar( A_IN );
	gamma = mxGetScalar( GAMMA_IN );
	co = mxGetScalar( CO_IN );

	if( na < 0 )		mexErrMsgTxt("Size is illegal.");
	C_OUT = mxCreateDoubleMatrix( na, na, mxREAL );
	coefp = (double*)mxGetPr( C_OUT );

	c = (double**)mxCalloc( sizeof(double*), na );
	c[0] = coefp;
	for( i = 1 ; i < na ; i++ )		c[i] = c[i-1] + na;

	make_c( c, na, a, gamma, co );

	return;
}
