/*
 * Academic License - for use in teaching, academic research, and meeting
 * course requirements at degree granting institutions only.  Not for
 * government, commercial, or other organizational use.
 *
 * _coder_digital_option_price_cg_api.c
 *
 * Code generation for function '_coder_digital_option_price_cg_api'
 *
 */

/* Include files */
#include "_coder_digital_option_price_cg_api.h"
#include "digital_option_price_cg.h"
#include "digital_option_price_cg_data.h"
#include "digital_option_price_cg_emxutil.h"
#include "digital_option_price_cg_types.h"
#include "rt_nonfinite.h"

/* Variable Definitions */
static emlrtRTEInfo cd_emlrtRTEI = {
    1,                                    /* lineNo */
    1,                                    /* colNo */
    "_coder_digital_option_price_cg_api", /* fName */
    ""                                    /* pName */
};

/* Function Declarations */
static void b_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u,
                               const emlrtMsgIdentifier *parentId,
                               emxArray_real_T *y);

static real_T c_emlrt_marshallIn(const emlrtStack *sp, const mxArray *nullptr,
                                 const char_T *identifier);

static real_T d_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u,
                                 const emlrtMsgIdentifier *parentId);

static void e_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src,
                               const emlrtMsgIdentifier *msgId,
                               emxArray_real_T *ret);

static void emlrt_marshallIn(const emlrtStack *sp, const mxArray *nullptr,
                             const char_T *identifier, emxArray_real_T *y);

static const mxArray *emlrt_marshallOut(emxArray_real_T *u);

static real_T f_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src,
                                 const emlrtMsgIdentifier *msgId);

/* Function Definitions */
static void b_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u,
                               const emlrtMsgIdentifier *parentId,
                               emxArray_real_T *y)
{
  e_emlrt_marshallIn(sp, emlrtAlias(u), parentId, y);
  emlrtDestroyArray(&u);
}

static real_T c_emlrt_marshallIn(const emlrtStack *sp, const mxArray *nullptr,
                                 const char_T *identifier)
{
  emlrtMsgIdentifier thisId;
  real_T y;
  thisId.fIdentifier = (const char_T *)identifier;
  thisId.fParent = NULL;
  thisId.bParentIsCell = false;
  y = d_emlrt_marshallIn(sp, emlrtAlias(nullptr), &thisId);
  emlrtDestroyArray(&nullptr);
  return y;
}

static real_T d_emlrt_marshallIn(const emlrtStack *sp, const mxArray *u,
                                 const emlrtMsgIdentifier *parentId)
{
  real_T y;
  y = f_emlrt_marshallIn(sp, emlrtAlias(u), parentId);
  emlrtDestroyArray(&u);
  return y;
}

static void e_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src,
                               const emlrtMsgIdentifier *msgId,
                               emxArray_real_T *ret)
{
  static const int32_T dims = -1;
  int32_T i;
  int32_T i1;
  boolean_T b = true;
  emlrtCheckVsBuiltInR2012b((emlrtConstCTX)sp, msgId, src, "double", false, 1U,
                            (const void *)&dims, &b, &i);
  ret->allocatedSize = i;
  i1 = ret->size[0];
  ret->size[0] = i;
  emxEnsureCapacity_real_T(sp, ret, i1, (emlrtRTEInfo *)NULL);
  ret->data = (real_T *)emlrtMxGetData(src);
  ret->canFreeData = false;
  emlrtDestroyArray(&src);
}

static void emlrt_marshallIn(const emlrtStack *sp, const mxArray *nullptr,
                             const char_T *identifier, emxArray_real_T *y)
{
  emlrtMsgIdentifier thisId;
  thisId.fIdentifier = (const char_T *)identifier;
  thisId.fParent = NULL;
  thisId.bParentIsCell = false;
  b_emlrt_marshallIn(sp, emlrtAlias(nullptr), &thisId, y);
  emlrtDestroyArray(&nullptr);
}

static const mxArray *emlrt_marshallOut(emxArray_real_T *u)
{
  static const int32_T i = 0;
  const mxArray *m;
  const mxArray *y;
  real_T *u_data;
  u_data = u->data;
  y = NULL;
  m = emlrtCreateNumericArray(1, (const void *)&i, mxDOUBLE_CLASS, mxREAL);
  emlrtMxSetData((mxArray *)m, &u_data[0]);
  emlrtSetDimensions((mxArray *)m, &u->size[0], 1);
  u->canFreeData = false;
  emlrtAssign(&y, m);
  return y;
}

static real_T f_emlrt_marshallIn(const emlrtStack *sp, const mxArray *src,
                                 const emlrtMsgIdentifier *msgId)
{
  static const int32_T dims = 0;
  real_T ret;
  emlrtCheckBuiltInR2012b((emlrtConstCTX)sp, msgId, src, "double", false, 0U,
                          (const void *)&dims);
  ret = *(real_T *)emlrtMxGetData(src);
  emlrtDestroyArray(&src);
  return ret;
}

void digital_option_price_cg_api(const mxArray *const prhs[13], int32_T nlhs,
                                 const mxArray *plhs[5])
{
  static const uint32_T uv[4] = {3610849628U, 3394130256U, 3884972681U,
                                 1530279734U};
  static const uint32_T uv1[4] = {4109474362U, 3889436611U, 3310931734U,
                                  3907662658U};
  static const char_T *s = "distr";
  static const char_T *s1 = "x";
  emlrtStack st = {
      NULL, /* site */
      NULL, /* tls */
      NULL  /* prev */
  };
  emxArray_real_T *CDF;
  emxArray_real_T *K;
  emxArray_real_T *S0;
  emxArray_real_T *VC;
  emxArray_real_T *VCdelta;
  emxArray_real_T *VCgamma;
  emxArray_real_T *VCvega;
  real_T CP;
  real_T L;
  real_T N;
  real_T T;
  real_T rf;
  real_T sv1;
  real_T sv2;
  real_T sv3;
  real_T zeta;
  int32_T i;
  st.tls = emlrtRootTLSGlobal;
  emlrtHeapReferenceStackEnterFcnR2012b(&st);
  /* Check constant function inputs */
  i = 4;
  emlrtCheckArrayChecksumR2018b(&st, prhs[0], false, &i, (const char_T **)&s,
                                &uv[0]);
  emlrtCheckArrayChecksumR2018b(&st, prhs[3], false, &i, (const char_T **)&s1,
                                &uv1[0]);
  /* Marshall function inputs */
  emxInit_real_T(&st, &S0, 1, &cd_emlrtRTEI);
  S0->canFreeData = false;
  emlrt_marshallIn(&st, emlrtAlias(prhs[1]), "S0", S0);
  emxInit_real_T(&st, &K, 1, &cd_emlrtRTEI);
  K->canFreeData = false;
  emlrt_marshallIn(&st, emlrtAlias(prhs[2]), "K", K);
  T = c_emlrt_marshallIn(&st, emlrtAliasP(prhs[4]), "T");
  CP = c_emlrt_marshallIn(&st, emlrtAliasP(prhs[5]), "CP");
  sv1 = c_emlrt_marshallIn(&st, emlrtAliasP(prhs[6]), "sv1");
  sv2 = c_emlrt_marshallIn(&st, emlrtAliasP(prhs[7]), "sv2");
  sv3 = c_emlrt_marshallIn(&st, emlrtAliasP(prhs[8]), "sv3");
  rf = c_emlrt_marshallIn(&st, emlrtAliasP(prhs[9]), "rf");
  zeta = c_emlrt_marshallIn(&st, emlrtAliasP(prhs[10]), "zeta");
  N = c_emlrt_marshallIn(&st, emlrtAliasP(prhs[11]), "N");
  L = c_emlrt_marshallIn(&st, emlrtAliasP(prhs[12]), "L");
  /* Invoke the target function */
  emxInit_real_T(&st, &VC, 1, &cd_emlrtRTEI);
  emxInit_real_T(&st, &CDF, 1, &cd_emlrtRTEI);
  emxInit_real_T(&st, &VCdelta, 1, &cd_emlrtRTEI);
  emxInit_real_T(&st, &VCgamma, 1, &cd_emlrtRTEI);
  emxInit_real_T(&st, &VCvega, 1, &cd_emlrtRTEI);
  digital_option_price_cg(&st, S0, K, T, CP, sv1, sv2, sv3, rf, zeta, N, L, VC,
                          CDF, VCdelta, VCgamma, VCvega);
  emxFree_real_T(&st, &K);
  emxFree_real_T(&st, &S0);
  /* Marshall function outputs */
  VC->canFreeData = false;
  plhs[0] = emlrt_marshallOut(VC);
  emxFree_real_T(&st, &VC);
  if (nlhs > 1) {
    CDF->canFreeData = false;
    plhs[1] = emlrt_marshallOut(CDF);
  }
  emxFree_real_T(&st, &CDF);
  if (nlhs > 2) {
    VCdelta->canFreeData = false;
    plhs[2] = emlrt_marshallOut(VCdelta);
  }
  emxFree_real_T(&st, &VCdelta);
  if (nlhs > 3) {
    VCgamma->canFreeData = false;
    plhs[3] = emlrt_marshallOut(VCgamma);
  }
  emxFree_real_T(&st, &VCgamma);
  if (nlhs > 4) {
    VCvega->canFreeData = false;
    plhs[4] = emlrt_marshallOut(VCvega);
  }
  emxFree_real_T(&st, &VCvega);
  emlrtHeapReferenceStackLeaveFcnR2012b(&st);
}

/* End of code generation (_coder_digital_option_price_cg_api.c) */
