#include <stdio.h>
#include <math.h>
#include "mex.h"

double  *NFArray(int size)
{
	double	*p;
	p = (double *)mxCalloc(sizeof(*p),size);
	return p;
}

/*************************************************************/
/* MexTanh.c                                                 */
/* A fast implementation of the hyperbolic tangent           */
/* function (why this is not a built-in function in MATLAB?) */
/*       By Aki Härmä 17. 5. 1999  		             */
/*************************************************************/
void trans(double *sig, long int len, 
	   long int dim, double *OUT)
{
 long int t, j, ind;
 double Sum;
 /* Constants */
 for (t=0;t<dim;t++)
   {
   for (j=0;j<len;j++)OUT[t*len+j]=tanh(sig[t*len+j]);     
   }
return;
}

/************************  MEXFUNCTION *****************************/
void mexFunction(
	int		nlhs,
	mxArray	*plhs[],
	int		nrhs,
	const mxArray    *prhs[]
	)
{
  long int len, dim, m, n;
  double *sig, *OUT;
  double yy, fs;
  
        sig = mxGetPr(prhs[0]);
      	len = (long int)mxGetM(prhs[0]);
	dim = (long int)mxGetN(prhs[0]);
	if (len==1) {len=dim;dim=1;}

 /* 	mexPrintf("Dim: %d   Len: %d",dim,len);  */

       plhs[0] = mxCreateDoubleMatrix(len, dim, mxREAL);
	OUT = mxGetPr(plhs[0]);
	trans(sig,len,dim,OUT);	
	return;
}


