/*
 *	 FUZZY.C   Based on the Matlab YPRIME example
 */

#include <math.h>
#include <mex.h>
#include <fcdslib.h>
#include "mlpend.h"

/* Input Arguments */

#define   Error_IN prhs[0]
#define   dError_IN prhs[1]


/* Output Arguments */

#define   P_OUT    plhs[0]

void mexFunction( int nlhs, Matrix *plhs[], int nrhs, Matrix *prhs[] )
{
	double    *Output;
	double    *Error,*dError;


	/* Check for proper number of arguments */

	if (nrhs != 2) {
		mexErrMsgTxt("FUZZY requires two input arguments.");
	} else if (nlhs > 1) {
		mexErrMsgTxt("FUZZY requires one output argument.");
	}



	/* Create a matrix for the return argument */

	P_OUT = mxCreateFull(1, 1, REAL);


	/* Assign pointers to the various parameters */

	Output = mxGetPr(P_OUT);

	Error = mxGetPr(Error_IN);
	dError = mxGetPr(dError_IN);

	if( *Error > 1 )
		*Error = 1;
	if( *Error < -1 )
		*Error = -1;
	if( *dError > 1 )
		*dError = 1;
	if( *dError < -1 )
		*dError = -1;



	/* Do the actual computations in a subroutine */

	Pend((double) *Error, (double) *dError, (double*) Output);
}
