11 #ifndef EASYLINK_BASEFUNCTION_H 12 #define EASYLINK_BASEFUNCTION_H 18 #ifndef INPUT_PORT_NUMBER 19 #define INPUT_PORT_NUMBER 0 27 #ifndef OUTPUT_PORT_NUMBER 28 #define OUTPUT_PORT_NUMBER 0 46 const static mxArray **
prhs;
48 static vector<mxArray *>
plhs;
73 if (!mxIsChar(
prhs[i]))
74 throw runtime_error(
"Argument " +
toString(i+1) +
" must be a string.");
81 throw runtime_error(
"Argument " +
toString(i+1) +
" must be a valid identifier.");
87 if (mxIsSparse(
prhs[i])||!mxIsDouble(
prhs[i]))
88 throw runtime_error(
"Argument " +
toString(i+1) +
" must be a scalar or an array of real values.");
117 for (
int i=0;i<
nlhs;i++) {
138 return mxGetScalar(
prhs[port]);
163 mxGetString(
prhs[port], buffer, 256);
164 return string(buffer);
182 return mxGetM(
prhs[port]);
190 return mxGetN(
prhs[port]);
199 double *x=mxGetPr(
plhs[port]);
209 throw runtime_error(
"easyLink error: Unable to write "+array.
getName()+
" to output port "+
toString(port)+
". Array dimensions must agree.");
211 memcpy((
void*)mxGetPr(
plhs[port]),(
void*)array.
getData(), array.
getWidth()*
sizeof(double) );
213 printf(
"easyLink test message: hard copy of array in setOutputArray(\"%s\").\n",array.
getName().c_str());
240 return mxGetM(
plhs[port]);
248 return mxGetN(
plhs[port]);
257 if (ncols>0 && nrows>0) {
258 plhs[port]=mxCreateDoubleMatrix(nrows,ncols, mxREAL);
static int getInputWidth(int port)
static void setOutputArray(int port, Array &array)
static int getOutputWidth(int port)
static void setOutputDouble(int port, double value)
static void initializeInputPortSizes()
#define OUTPUT_PORT_NUMBER
static string getInputString(int port)
static int getOutputNCols(int port)
static int getInputNCols(int port)
static double getInputDouble(int port)
bool isIdentifier(string str)
static void initializeOutputPortSizes()
static Array getInputArray(int port)
static vector< mxArray * > plhs
static Array getOutputArray(int port)
#define INPUT_PORT_NUMBER
static int getInputNRows(int port)
static const mxArray ** prhs
static int getOutputNRows(int port)
static double getInputInt(int port)
static void setOutputPortDimensions(int port, int nrows, int ncols)