#include "mex.h"
#include "simulator.h"

void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) {
	 double usa, usb;
	 double *x_out, *y_out;

	/* Check the number of inputs and output arguments */
    if ( n_input==2 ) {
			 usa = *mxGetPr(input[0]);
			 usb = *mxGetPr(input[1]);
	pmsmsim_noreg_step(usa,usb);
      } 
    if ( n_input==1 ) {
	double Ww = *mxGetPr(input[0]);
	for (int i=0;i<125; i++){
	  pmsmsim_step(Ww,0.0);
	}
    }
    if (n_input==0){
      pmsmsim_set_parameters ( 0.28,0.003465,0.1989,0.0,4,1.5,0.04, 200., 3e-6, 1e-6 );
    }

      output[0]= mxCreateDoubleMatrix(9, 1, mxREAL); 
	x_out= mxGetPr(output[0]);
	
	for (int i=0; i<9; i++){
	    x_out[i]=x[i];
	}

      output[1]= mxCreateDoubleMatrix(6, 1, mxREAL); 
	y_out= mxGetPr(output[1]);
	
	for (int i=0; i<5; i++){
	    y_out[i]=KalmanObs[i];
	}

  
}

