//
// MATLAB Compiler: 2.2
// Date: Wed Mar 10 16:44:48 2004
// 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" "-p" "-W" "main" "-L"
// "Cpp" "-t" "-T" "link:exe" "-h" "libmmfile.mlib" "-B" "sglcpp" "-p" "-W"
// "main" "-L" "Cpp" "-t" "-T" "link:exe" "-h" "libmmfile.mlib" "-W" "mainhg"
// "libmwsglm.mlib" "hier_community.m" "Default.m" "Stop_Simulation.m"
// "Call_SaveLoad_Fig.m" "SaveLoad_Fig.m" "SaveLoad.m" "Load_Population_Data.m"
// "Save_Population_Data.m" "Start_hier_community.m" "MyInline.m" "My_Eval.m"
// "isnumber.m" "Find_Var.m" "Change_Number_of_Populations.m"
// "Switch_Populations.m" "Store_Parameters.m" 
//
#include "parseparams.hpp"
#include "libmatlbm.hpp"

static mxChar _array1_[140] = { 'R', 'u', 'n', '-', 't', 'i', 'm', 'e', ' ',
                                'E', 'r', 'r', 'o', 'r', ':', ' ', 'F', 'i',
                                'l', 'e', ':', ' ', 'p', 'a', 'r', 's', 'e',
                                'p', 'a', 'r', 'a', 'm', 's', ' ', 'L', 'i',
                                'n', 'e', ':', ' ', '1', ' ', 'C', 'o', 'l',
                                'u', 'm', 'n', ':', ' ', '1', ' ', 'T', 'h',
                                'e', ' ', 'f', 'u', 'n', 'c', 't', 'i', 'o',
                                'n', ' ', '"', 'p', 'a', 'r', 's', 'e', 'p',
                                'a', 'r', 'a', 'm', 's', '"', ' ', 'w', 'a',
                                's', ' ', 'c', 'a', 'l', 'l', 'e', 'd', ' ',
                                'w', 'i', 't', 'h', ' ', 'm', 'o', 'r', 'e',
                                ' ', 't', 'h', 'a', 'n', ' ', 't', 'h', 'e',
                                ' ', 'd', 'e', 'c', 'l', 'a', 'r', 'e', 'd',
                                ' ', 'n', 'u', 'm', 'b', 'e', 'r', ' ', 'o',
                                'f', ' ', 'o', 'u', 't', 'p', 'u', 't', 's',
                                ' ', '(', '2', ')', '.' };
static mwArray _mxarray0_ = mclInitializeString(140, _array1_);

static mxChar _array3_[139] = { 'R', 'u', 'n', '-', 't', 'i', 'm', 'e', ' ',
                                'E', 'r', 'r', 'o', 'r', ':', ' ', 'F', 'i',
                                'l', 'e', ':', ' ', 'p', 'a', 'r', 's', 'e',
                                'p', 'a', 'r', 'a', 'm', 's', ' ', 'L', 'i',
                                'n', 'e', ':', ' ', '1', ' ', 'C', 'o', 'l',
                                'u', 'm', 'n', ':', ' ', '1', ' ', 'T', 'h',
                                'e', ' ', 'f', 'u', 'n', 'c', 't', 'i', 'o',
                                'n', ' ', '"', 'p', 'a', 'r', 's', 'e', 'p',
                                'a', 'r', 'a', 'm', 's', '"', ' ', 'w', 'a',
                                's', ' ', 'c', 'a', 'l', 'l', 'e', 'd', ' ',
                                'w', 'i', 't', 'h', ' ', 'm', 'o', 'r', 'e',
                                ' ', 't', 'h', 'a', 'n', ' ', 't', 'h', 'e',
                                ' ', 'd', 'e', 'c', 'l', 'a', 'r', 'e', 'd',
                                ' ', 'n', 'u', 'm', 'b', 'e', 'r', ' ', 'o',
                                'f', ' ', 'i', 'n', 'p', 'u', 't', 's', ' ',
                                '(', '1', ')', '.' };
static mwArray _mxarray2_ = mclInitializeString(139, _array3_);
static mwArray _mxarray4_ = mclInitializeDoubleVector(0, 0, (double *)NULL);
static mwArray _mxarray5_ = mclInitializeDouble(1.0);
static mwArray _mxarray6_ = mclInitializeDouble(0.0);

void InitializeModule_parseparams() {
}

void TerminateModule_parseparams() {
}

static mwArray Mparseparams(mwArray * proppairs, int nargout_, mwArray args);

_mexLocalFunctionTable _local_function_table_parseparams
  = { 0, (mexFunctionTableEntry *)NULL };

//
// The function "parseparams" contains the normal interface for the
// "parseparams" M-function from file
// "C:\MATLAB6p1\toolbox\matlab\graphics\parseparams.m" (lines 1-33). This
// function processes any input arguments and passes them to the implementation
// version of the function, appearing above.
//
mwArray parseparams(mwArray * proppairs, mwArray args) {
    int nargout(1);
    mwArray regargs(mclGetUninitializedArray());
    mwArray proppairs__(mclGetUninitializedArray());
    if (proppairs != NULL) {
        ++nargout;
    }
    regargs = Mparseparams(&proppairs__, nargout, args);
    if (proppairs != NULL) {
        *proppairs = proppairs__;
    }
    return regargs;
}

//
// The function "mlxParseparams" contains the feval interface for the
// "parseparams" M-function from file
// "C:\MATLAB6p1\toolbox\matlab\graphics\parseparams.m" (lines 1-33). The feval
// function calls the implementation version of parseparams through this
// function. This function processes any input arguments and passes them to the
// implementation version of the function, appearing above.
//
void mlxParseparams(int nlhs, mxArray * plhs[], int nrhs, mxArray * prhs[]) {
    MW_BEGIN_MLX();
    {
        mwArray mprhs[1];
        mwArray mplhs[2];
        int i;
        mclCppUninitializeArrays(2, mplhs);
        if (nlhs > 2) {
            error(_mxarray0_);
        }
        if (nrhs > 1) {
            error(_mxarray2_);
        }
        for (i = 0; i < 1 && i < nrhs; ++i) {
            mprhs[i] = mwArray(prhs[i], 0);
        }
        for (; i < 1; ++i) {
            mprhs[i].MakeDIN();
        }
        mplhs[0] = Mparseparams(&mplhs[1], nlhs, mprhs[0]);
        plhs[0] = mplhs[0].FreezeData();
        for (i = 1; i < 2 && i < nlhs; ++i) {
            plhs[i] = mplhs[i].FreezeData();
        }
    }
    MW_END_MLX();
}

//
// The function "Mparseparams" is the implementation version of the
// "parseparams" M-function from file
// "C:\MATLAB6p1\toolbox\matlab\graphics\parseparams.m" (lines 1-33). It
// contains the actual compiled code for that M-function. It is a static
// function and must only be called from one of the interface functions,
// appearing below.
//
//
// function [regargs, proppairs]=parseparams(args)
//
static mwArray Mparseparams(mwArray * proppairs, int nargout_, mwArray args) {
    mwLocalFunctionTable save_local_function_table_
      (&_local_function_table_parseparams);
    mwArray regargs(mclGetUninitializedArray());
    mwArray charindx(mclGetUninitializedArray());
    mwArray i(mclGetUninitializedArray());
    mwArray charsrch(mclGetUninitializedArray());
    //
    // %PARSEPARAMS Finds first string argument.
    // %   [REG, PROP]=PARSEPARAMS(ARGS) takes cell array ARGS and
    // %   separates it into two argument sets:
    // %      REG being all arguments up to, but excluding, the
    // %   first string argument encountered in ARGS.
    // %      PROP contains all other arguments after, and including,
    // %   the first string argument encountered.
    // %
    // %   PARSEPARAMS is intended to isolate possible property
    // %   value pairs in functions using VARARGIN as the input
    // %   argument.
    // 
    // %   Chris Portal 2-17-98
    // %   Copyright 1984-2001 The MathWorks, Inc. 
    // %   $Revision: 1.5 $  $Date: 2001/04/15 11:59:50 $
    // 
    // charsrch=[];
    //
    charsrch = _mxarray4_;
    //
    // 
    // for i=1:length(args),
    //
    {
        int v_(mclForIntStart(1));
        int e_(mclForIntEnd(mwArray(mclLengthInt(mwVa(args, "args")))));
        if (v_ > e_) {
            i = _mxarray4_;
        } else {
            //
            // charsrch=[charsrch ischar(args{i})];
            // end
            //
            for (; ; ) {
                charsrch
                  = horzcat(
                      mwVarargin(
                        mwVv(charsrch, "charsrch"),
                        mwVe(
                          feval(
                            mwValueVarargout(),
                            mlxIschar,
                            mwVarargin(mwVe(mwVsa(args, "args").cell(v_)))))));
                if (v_ == e_) {
                    break;
                }
                ++v_;
            }
            i = v_;
        }
    }
    //
    // 
    // charindx=find(charsrch);
    //
    charindx = find(mwVv(charsrch, "charsrch"));
    //
    // 
    // if isempty(charindx),
    //
    if (tobool(mwVe(isempty(mwVv(charindx, "charindx"))))) {
        //
        // regargs=args;
        //
        regargs = mwVsa(args, "args");
        //
        // proppairs=args(1:0);
        //
        *proppairs
          = mclArrayRef(mwVsa(args, "args"), colon(_mxarray5_, _mxarray6_));
    //
    // else
    //
    } else {
        //
        // regargs=args(1:charindx(1)-1);
        //
        regargs
          = mclArrayRef(
              mwVsa(args, "args"),
              colon(
                _mxarray5_,
                mwVe(mclIntArrayRef(mwVsv(charindx, "charindx"), 1))
                - _mxarray5_));
        //
        // proppairs=args(charindx(1):end);
        //
        *proppairs
          = mclArrayRef(
              mwVsa(args, "args"),
              colon(
                mwVe(mclIntArrayRef(mwVsv(charindx, "charindx"), 1)),
                end(mwVa(args, "args"), _mxarray5_, _mxarray5_)));
    //
    // end
    //
    }
    mwValidateOutput(regargs, 1, nargout_, "regargs", "parseparams");
    mwValidateOutput(*proppairs, 2, nargout_, "proppairs", "parseparams");
    return regargs;
}
