/*
 * MATLAB Compiler: 3.0
 * Date: Thu Aug 07 20:04:08 2008
 * Arguments: "-B" "macro_default" "-O" "all" "-O" "fold_scalar_mxarrays:on"
 * "-O" "fold_non_scalar_mxarrays:on" "-O" "optimize_integer_for_loops:on" "-O"
 * "array_indexing:on" "-O" "optimize_conditionals:on" "-x" "-W" "mex" "-L" "C"
 * "-t" "-T" "link:mexlibrary" "libmatlbmx.mlib" "prognoz_maxr" 
 */

#ifndef MLF_V2
#define MLF_V2 1
#endif

#include "libmatlb.h"
#include "prognoz_maxr.h"
#include "dy2sost.h"
#include "random.h"

extern _mex_information _mex_info;

mxArray * bif_flag = NULL;

mxArray * type_prirash = NULL;

static mexGlobalTableEntry global_table[2]
  = { { "bif_flag", &bif_flag }, { "type_prirash", &type_prirash } };

static mexFunctionTableEntry function_table[1]
  = { { "prognoz_maxr", mlxPrognoz_maxr, 6, 5,
        &_local_function_table_prognoz_maxr } };

static _mexInitTermTableEntry init_term_table[1]
  = { { InitializeModule_prognoz_maxr, TerminateModule_prognoz_maxr } };

/*
 * The function "Mrandom" is the MATLAB callback version of the "random"
 * function from file "e:\matlab6p5\toolbox\stats\random.m". It performs a
 * callback to MATLAB to run the "random" function, and passes any resulting
 * output arguments back to its calling function.
 */
static mxArray * Mrandom(int nargout_,
                         mxArray * name,
                         mxArray * a,
                         mxArray * b,
                         mxArray * c,
                         mxArray * d,
                         mxArray * e) {
    mxArray * r = NULL;
    mclFevalCallMATLAB(
      mclNVarargout(nargout_, 0, &r, NULL),
      "random",
      name, a, b, c, d, e, NULL);
    return r;
}

/*
 * The function "Mdy2sost" is the MATLAB callback version of the "dy2sost"
 * function from file "d:\dayly\20080807\markovchains1_1mex20080807\dy2sost.m".
 * It performs a callback to MATLAB to run the "dy2sost" function, and passes
 * any resulting output arguments back to its calling function.
 */
static mxArray * Mdy2sost(mxArray * * sredn,
                          mxArray * * stdotklon_group,
                          mxArray * * stdotklon_all,
                          mxArray * * matrix_kol,
                          int nargout_,
                          mxArray * dydiscr,
                          mxArray * numsost,
                          mxArray * r,
                          mxArray * dx) {
    mxArray * ysost = NULL;
    mclFevalCallMATLAB(
      mclNVarargout(
        nargout_,
        0,
        &ysost, sredn, stdotklon_group, stdotklon_all, matrix_kol, NULL),
      "dy2sost",
      dydiscr, numsost, r, dx, NULL);
    return ysost;
}

/*
 * The function "mexLibrary" is a Compiler-generated mex wrapper, suitable for
 * building a MEX-function. It initializes any persistent variables as well as
 * a function table for use by the feval function. It then calls the function
 * "mlxPrognoz_maxr". Finally, it clears the feval table and exits.
 */
mex_information mexLibrary(void) {
    mclMexLibraryInit();
    return &_mex_info;
}

_mex_information _mex_info
  = { 1, 1, function_table, 2, global_table, 0, NULL, 1, init_term_table };

/*
 * The function "mlfRandom" contains the normal interface for the "random"
 * M-function from file "e:\matlab6p5\toolbox\stats\random.m" (lines 0-0). This
 * function processes any input arguments and passes them to the implementation
 * version of the function, appearing above.
 */
mxArray * mlfRandom(mxArray * name,
                    mxArray * a,
                    mxArray * b,
                    mxArray * c,
                    mxArray * d,
                    mxArray * e) {
    int nargout = 1;
    mxArray * r = NULL;
    mlfEnterNewContext(0, 6, name, a, b, c, d, e);
    r = Mrandom(nargout, name, a, b, c, d, e);
    mlfRestorePreviousContext(0, 6, name, a, b, c, d, e);
    return mlfReturnValue(r);
}

/*
 * The function "mlxRandom" contains the feval interface for the "random"
 * M-function from file "e:\matlab6p5\toolbox\stats\random.m" (lines 0-0). The
 * feval function calls the implementation version of random through this
 * function. This function processes any input arguments and passes them to the
 * implementation version of the function, appearing above.
 */
void mlxRandom(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
    mxArray * mprhs[6];
    mxArray * mplhs[1];
    int i;
    if (nlhs > 1) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: random Line: 1 Column: "
            "1 The function \"random\" was called with mor"
            "e than the declared number of outputs (1)."),
          NULL);
    }
    if (nrhs > 6) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: random Line: 1 Column: "
            "1 The function \"random\" was called with mor"
            "e than the declared number of inputs (6)."),
          NULL);
    }
    for (i = 0; i < 1; ++i) {
        mplhs[i] = NULL;
    }
    for (i = 0; i < 6 && i < nrhs; ++i) {
        mprhs[i] = prhs[i];
    }
    for (; i < 6; ++i) {
        mprhs[i] = NULL;
    }
    mlfEnterNewContext(
      0, 6, mprhs[0], mprhs[1], mprhs[2], mprhs[3], mprhs[4], mprhs[5]);
    mplhs[0]
      = Mrandom(
          nlhs, mprhs[0], mprhs[1], mprhs[2], mprhs[3], mprhs[4], mprhs[5]);
    mlfRestorePreviousContext(
      0, 6, mprhs[0], mprhs[1], mprhs[2], mprhs[3], mprhs[4], mprhs[5]);
    plhs[0] = mplhs[0];
}

/*
 * The function "mlfDy2sost" contains the normal interface for the "dy2sost"
 * M-function from file
 * "d:\dayly\20080807\markovchains1_1mex20080807\dy2sost.m" (lines 0-0). This
 * function processes any input arguments and passes them to the implementation
 * version of the function, appearing above.
 */
mxArray * mlfDy2sost(mxArray * * sredn,
                     mxArray * * stdotklon_group,
                     mxArray * * stdotklon_all,
                     mxArray * * matrix_kol,
                     mxArray * dydiscr,
                     mxArray * numsost,
                     mxArray * r,
                     mxArray * dx) {
    int nargout = 1;
    mxArray * ysost = NULL;
    mxArray * sredn__ = NULL;
    mxArray * stdotklon_group__ = NULL;
    mxArray * stdotklon_all__ = NULL;
    mxArray * matrix_kol__ = NULL;
    mlfEnterNewContext(
      4,
      4,
      sredn,
      stdotklon_group,
      stdotklon_all,
      matrix_kol,
      dydiscr,
      numsost,
      r,
      dx);
    if (sredn != NULL) {
        ++nargout;
    }
    if (stdotklon_group != NULL) {
        ++nargout;
    }
    if (stdotklon_all != NULL) {
        ++nargout;
    }
    if (matrix_kol != NULL) {
        ++nargout;
    }
    ysost
      = Mdy2sost(
          &sredn__,
          &stdotklon_group__,
          &stdotklon_all__,
          &matrix_kol__,
          nargout,
          dydiscr,
          numsost,
          r,
          dx);
    mlfRestorePreviousContext(
      4,
      4,
      sredn,
      stdotklon_group,
      stdotklon_all,
      matrix_kol,
      dydiscr,
      numsost,
      r,
      dx);
    if (sredn != NULL) {
        mclCopyOutputArg(sredn, sredn__);
    } else {
        mxDestroyArray(sredn__);
    }
    if (stdotklon_group != NULL) {
        mclCopyOutputArg(stdotklon_group, stdotklon_group__);
    } else {
        mxDestroyArray(stdotklon_group__);
    }
    if (stdotklon_all != NULL) {
        mclCopyOutputArg(stdotklon_all, stdotklon_all__);
    } else {
        mxDestroyArray(stdotklon_all__);
    }
    if (matrix_kol != NULL) {
        mclCopyOutputArg(matrix_kol, matrix_kol__);
    } else {
        mxDestroyArray(matrix_kol__);
    }
    return mlfReturnValue(ysost);
}

/*
 * The function "mlxDy2sost" contains the feval interface for the "dy2sost"
 * M-function from file
 * "d:\dayly\20080807\markovchains1_1mex20080807\dy2sost.m" (lines 0-0). The
 * feval function calls the implementation version of dy2sost through this
 * function. This function processes any input arguments and passes them to the
 * implementation version of the function, appearing above.
 */
void mlxDy2sost(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
    mxArray * mprhs[4];
    mxArray * mplhs[5];
    int i;
    if (nlhs > 5) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: dy2sost Line: 1 Column: "
            "1 The function \"dy2sost\" was called with mor"
            "e than the declared number of outputs (5)."),
          NULL);
    }
    if (nrhs > 4) {
        mlfError(
          mxCreateString(
            "Run-time Error: File: dy2sost Line: 1 Column:"
            " 1 The function \"dy2sost\" was called with m"
            "ore than the declared number of inputs (4)."),
          NULL);
    }
    for (i = 0; i < 5; ++i) {
        mplhs[i] = NULL;
    }
    for (i = 0; i < 4 && i < nrhs; ++i) {
        mprhs[i] = prhs[i];
    }
    for (; i < 4; ++i) {
        mprhs[i] = NULL;
    }
    mlfEnterNewContext(0, 4, mprhs[0], mprhs[1], mprhs[2], mprhs[3]);
    mplhs[0]
      = Mdy2sost(
          &mplhs[1],
          &mplhs[2],
          &mplhs[3],
          &mplhs[4],
          nlhs,
          mprhs[0],
          mprhs[1],
          mprhs[2],
          mprhs[3]);
    mlfRestorePreviousContext(0, 4, mprhs[0], mprhs[1], mprhs[2], mprhs[3]);
    plhs[0] = mplhs[0];
    for (i = 1; i < 5 && i < nlhs; ++i) {
        plhs[i] = mplhs[i];
    }
    for (; i < 5; ++i) {
        mxDestroyArray(mplhs[i]);
    }
}
