/* This file was automatically generated by pyNLControl.*/


#include <stdlib.h>
#include <math.h>
#include "qpOASES.hpp"
#include "{{FileName}}_EVAL_CODE_Call.h"
#include "{{FileName}}.h"

{%if Mex %}
#include "mex.h"
{%endif%}

void {{FileName}}_Call(double *xGuess, {%for xin in InName%}double *{{xin}}, {%endfor%} double *xOpt, double *Obj)
{
    USING_NAMESPACE_QPOASES

    {%set NumOut = OutName|length %}
    real_t {%for k in range(NumOut-1)%}{{OutName[loop.index0]}}[{{OutSize[loop.index0]}}], {%endfor%}{{OutName[NumOut-1]}}[{{OutSize[NumOut-1]}}];

    int nV = {{nV}}, nC = {{nC}};

    {{FileName}}_EVAL_CODE_Call_Func({%for xin in InName%}{{xin}}, {%endfor%} {%for k in range(NumOut-1)%}{{OutName[loop.index0]}}, {%endfor%}{{OutName[NumOut-1]}});

    Options options;
    options.setToMPC();

    options.printLevel = PL_NONE;
    {%for key, val in Options.items()%}
    options.{{key}} = {{val}};
    {%endfor%}

    SQProblem qp(nV, nC);
    int_t nWSR;

    qp.setOptions(options);

    if (!qp.isInitialised())
    {
        nWSR = {{MaxIter}};
        qp.init(H, g, {%for k in range(5)%}{{OutPointer[loop.index0]}}, {%endfor%} nWSR, NULL, xGuess);
    }
    else
    {
        nWSR = {{MaxIter}};
        qp.hotstart(H, g, {%for k in range(5)%}{{OutPointer[loop.index0]}}, {%endfor%} nWSR, NULL);
    }

    qp.getPrimalSolution(xOpt);
    Obj[0] = qp.getObjVal();


}