/*
Takes a scalar x, and returns 2*z.

Example:

TimesTwo(5)
ans =
10
*/
#include <mex.h>
#include <math.h>
#include <iostream.h>
#include <stdio.h>

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{

	/*****Checking input and output: optional*****/

	//Check that number of input and output arguements are correct.
	if (nrhs != 1)
		mexErrMsgTxt("One input required.");
	else if (nlhs > 1)
		mexErrMsgTxt("Too many output arguments. One is enough.");
	
	//Input 1 must be a noncomplex scalar double.
	int mrowsx = mxGetM(prhs[0]);
	int ncolsx = mxGetN(prhs[0]);
	if(!mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) || !(mrowsx == 1 && ncolsx == 1))
		mexErrMsgTxt("The input must be a noncomplex scalar double.");

	/*****Retrieving input****/
	
	double x = (double)mxGetScalar(prhs[0]);

	/****Multiplication****/
	x *= 2;
	
	/****Sending output*****/
	//scalars
	plhs[0] = mxCreateDoubleScalar(x);

	return;
}
