Listing 2. A MEX Function

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "mex.h"
#include "pops.h"
void latcalc(double *x, double *erp, double *alpha,
             double *tau, double *coupling,
             double *range, double *inresultlat,
             double *inresulterp, int M, int R,
             int T, int NsoFar);

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

    int M, R, T, NsoFar;
    const int *dim_array;

    if ((nrhs != 6) || (nlhs != 2))
        mexErrMsgTxt("wrong # of args to c_mLAT");

    dim_array = mxGetDimensions(prhs[0]);

    M = dim_array[0];
    R = dim_array[1];
    T = dim_array[2];

    NsoFar = mxGetM(prhs[1]);

    plhs[0] =
        mxCreateDoubleMatrix(NsoFar, R, mxREAL);
    plhs[1] =
        mxCreateDoubleMatrix(NsoFar, T, mxREAL);

    /* Call the function that does the actual work */
    latcalc(mxGetPr(prhs[0]), mxGetPr(prhs[1]),
            mxGetPr(prhs[2]), mxGetPr(prhs[3]),
            mxGetPr(prhs[4]), mxGetPr(prhs[5]),
            mxGetPr(plhs[0]), mxGetPr(plhs[1]), M,
            R, T, NsoFar);


}