#include "mex.h"

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

{

/* Variables for the gateway function: */

int status, mm, nn, buflen, out;

/* Variables of the C function: */

int m,n,lda,incx,incy;
double *alpha,*a,*x,*beta,*y;
char *trans;

/* Make sure that the number of inputs and outputs are correct: */

if (nrhs != 11){
    mexErrMsgTxt("Wrong number of inputs in sgemv");
   }
if (nlhs != 1){
    mexErrMsgTxt("Wrong number of outputs in sgemv");
   }

/*      Check the dimensions of the input matrix */

mm = mxGetM(prhs[4]);
nn = mxGetN(prhs[4]);

/* Retrieve the character input */

buflen = (mxGetM(prhs[0]) * mxGetN(prhs[0])) + 1;
trans = mxCalloc(buflen, sizeof(char));
status = mxGetString(prhs[0],trans,buflen);

m = mxGetScalar(prhs[1]);
n = mxGetScalar(prhs[2]);
lda = mxGetScalar(prhs[5]);
incx = mxGetScalar(prhs[7]);
incy = mxGetScalar(prhs[10]);

plhs[0] = mxCreateDoubleMatrix(nn,1,mxREAL);

alpha = mxGetPr(prhs[3]);
a = mxGetPr(prhs[4]);
x = mxGetPr(prhs[6]);
beta = mxGetPr(prhs[8]);
y = mxGetPr(prhs[9]);

out = mvmult(trans,&m,&n,alpha,a,&lda,x,&incx,beta,y,&incy);

/* The output to Matlab is the 10th input. Note: The compiler
   gives a warning, since plhs is declared constant while prhs
   is not. However, the program works just fine. */

plhs[0] = prhs[9];

}
