/* [+MEQ MatlabEQuilibrium Toolbox+] Swiss Plasma Center EPFL Lausanne 2022. All rights reserved. */
# include "meq.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{

 /* [Y1,Y2,Y3] = vizrmex(Fx,lyp,ry,iry,rBt,dr,dz) */

# define MEXNAME vizrmex

# define Y1   pout[0]
# define Y2   pout[1]
# define Y3   pout[2] 

# define FX   prhs[0]  /* double, def size=[nz,nr] */
# define LYP  prhs[1]  /* logical, size=(nz-2)*(nr-2) */
# define RY   prhs[2]  /* double, size=(nr-2) */
# define IRY  prhs[3]  /* double, size=(nr-2) */
# define RBT  prhs[4]  /* numeric, scalar */
# define DR   prhs[5]  /* numeric, scalar */
# define DZ   prhs[6]  /* numeric, scalar */

 CHECK_NARGIN_EQ(7);

 int nz=mxGetM(FX), nr=mxGetN(FX);

 CHECK_DOUBLE(FX);
 CHECK_LOGICAL(LYP);
 CHECK_NUMEL(LYP,(nz-2)*(nr-2));
 CHECK_DOUBLE(RY);
 CHECK_NUMEL(RY,(nr-2));
 CHECK_DOUBLE(IRY);
 CHECK_NUMEL(IRY,(nr-2));
 CHECK_NUMERIC(RBT);
 CHECK_SCALAR(RBT);
 CHECK_NUMERIC(DR);
 CHECK_SCALAR(DR);
 CHECK_NUMERIC(DZ);
 CHECK_SCALAR(DZ);

 CHECK_NARGOUT_LE(3);

 mxArray *pout[3];
  
 Y1 = mxCreateDoubleMatrix(1,1,mxREAL);
 Y2 = mxCreateDoubleMatrix(1,1,mxREAL);
 Y3 = mxCreateDoubleMatrix(1,1,mxREAL);

 dvizr(mxGetPr(Y1),mxGetPr(Y2),mxGetPr(Y3),mxGetPr(FX),
       (bool *)mxGetLogicals(LYP),mxGetPr(RY),mxGetPr(IRY),
       mxGetScalar(RBT),mxGetScalar(DR),mxGetScalar(DZ),nr,nz);

 ASSIGN_PLHS;
}
