//
// 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 "Change_Number_of_Populations.hpp"
#include "libmatlbm.hpp"
#include "libmmfile.hpp"

static mxChar _array1_[174] = { 'R', 'u', 'n', '-', 't', 'i', 'm', 'e', ' ',
                                'E', 'r', 'r', 'o', 'r', ':', ' ', 'F', 'i',
                                'l', 'e', ':', ' ', 'C', 'h', 'a', 'n', 'g',
                                'e', '_', 'N', 'u', 'm', 'b', 'e', 'r', '_',
                                'o', 'f', '_', 'P', 'o', 'p', 'u', 'l', 'a',
                                't', 'i', 'o', 'n', 's', ' ', 'L', 'i', 'n',
                                'e', ':', ' ', '1', ' ', 'C', 'o', 'l', 'u',
                                'm', 'n', ':', ' ', '1', ' ', 'T', 'h', 'e',
                                ' ', 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n',
                                ' ', '"', 'C', 'h', 'a', 'n', 'g', 'e', '_',
                                'N', 'u', 'm', 'b', 'e', 'r', '_', 'o', 'f',
                                '_', 'P', 'o', 'p', 'u', 'l', 'a', 't', 'i',
                                'o', 'n', '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', ' ', '(',
                                '0', ')', '.' };
static mwArray _mxarray0_ = mclInitializeString(174, _array1_);

static mxChar _array3_[173] = { 'R', 'u', 'n', '-', 't', 'i', 'm', 'e', ' ',
                                'E', 'r', 'r', 'o', 'r', ':', ' ', 'F', 'i',
                                'l', 'e', ':', ' ', 'C', 'h', 'a', 'n', 'g',
                                'e', '_', 'N', 'u', 'm', 'b', 'e', 'r', '_',
                                'o', 'f', '_', 'P', 'o', 'p', 'u', 'l', 'a',
                                't', 'i', 'o', 'n', 's', ' ', 'L', 'i', 'n',
                                'e', ':', ' ', '1', ' ', 'C', 'o', 'l', 'u',
                                'm', 'n', ':', ' ', '1', ' ', 'T', 'h', 'e',
                                ' ', 'f', 'u', 'n', 'c', 't', 'i', 'o', 'n',
                                ' ', '"', 'C', 'h', 'a', 'n', 'g', 'e', '_',
                                'N', 'u', 'm', 'b', 'e', 'r', '_', 'o', 'f',
                                '_', 'P', 'o', 'p', 'u', 'l', 'a', 't', 'i',
                                'o', 'n', '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', ' ', '(', '0',
                                ')', '.' };
static mwArray _mxarray2_ = mclInitializeString(173, _array3_);

static mxChar _array5_[3] = { 'T', 'a', 'g' };
static mwArray _mxarray4_ = mclInitializeString(3, _array5_);

static mxChar _array7_[23] = { 'F', 'i', 'g', '_', 'm', 'u', 'l', 't',
                               'i', 'p', 'l', 'e', '_', 'p', 'o', 'p',
                               'u', 'l', 'a', 't', 'i', 'o', 'n' };
static mwArray _mxarray6_ = mclInitializeString(23, _array7_);

static mxChar _array9_[30] = { 'E', 'd', 'i', 't', 'T', 'e', 'x', 't',
                               '_', 'n', 'u', 'm', 'b', 'e', 'r', '_',
                               'o', 'f', '_', 'p', 'o', 'p', 'u', 'l',
                               'a', 't', 'i', 'o', 'n', 's' };
static mwArray _mxarray8_ = mclInitializeString(30, _array9_);

static mxChar _array11_[21] = { 'P', 'o', 'p', 'u', 'p', 'M', 'e',
                                'n', 'u', '_', 'p', 'o', 'p', 'u',
                                'l', 'a', 't', 'i', 'o', 'n', 's' };
static mwArray _mxarray10_ = mclInitializeString(21, _array11_);

static mxChar _array13_[22] = { 'S', 't', 'a', 't', 'i', 'c', 'T', 'e',
                                'x', 't', '_', 'g', 'r', 'o', 'w', 't',
                                'h', '_', 'r', 'a', 't', 'e' };
static mwArray _mxarray12_ = mclInitializeString(22, _array13_);

static mxChar _array15_[24] = { 'S', 't', 'a', 't', 'i', 'c', 'T', 'e',
                                'x', 't', '_', 'm', 'o', 'r', 'a', 'l',
                                'i', 't', 'y', '_', 'r', 'a', 't', 'e' };
static mwArray _mxarray14_ = mclInitializeString(24, _array15_);

static mxChar _array17_[28] = { 'S', 't', 'a', 't', 'i', 'c', 'T',
                                'e', 'x', 't', '_', 'r', 'e', 'p',
                                'r', 'o', 'd', 'u', 'c', 't', 'i',
                                'o', 'n', '_', 'r', 'a', 't', 'e' };
static mwArray _mxarray16_ = mclInitializeString(28, _array17_);

static mxChar _array19_[20] = { 'E', 'd', 'i', 't', 'T', 'e', 'x',
                                't', '_', 'P', 'r', 'o', 'b', 'a',
                                'b', 'i', 'l', 'i', 't', 'y' };
static mwArray _mxarray18_ = mclInitializeString(20, _array19_);

static mxChar _array21_[6] = { 'S', 't', 'r', 'i', 'n', 'g' };
static mwArray _mxarray20_ = mclInitializeString(6, _array21_);

static mxChar _array23_[8] = { 'U', 's', 'e', 'r', 'D', 'a', 't', 'a' };
static mwArray _mxarray22_ = mclInitializeString(8, _array23_);

static mxChar _array25_[5] = { 'V', 'a', 'l', 'u', 'e' };
static mwArray _mxarray24_ = mclInitializeString(5, _array25_);
static mwArray _mxarray26_ = mclInitializeDouble(1.0);
static mwArray _mxarray27_ = mclInitializeDouble(3.0);

static mxChar _array29_[2] = { 'u', 'o' };
static mwArray _mxarray28_ = mclInitializeString(2, _array29_);
static mwArray _mxarray30_ = mclInitializeDoubleVector(0, 0, (double *)NULL);

static mxChar _array32_[1] = { 'g' };
static mwArray _mxarray31_ = mclInitializeString(1, _array32_);

static mxChar _array34_[1] = { 'm' };
static mwArray _mxarray33_ = mclInitializeString(1, _array34_);

static mxChar _array36_[1] = { 'b' };
static mwArray _mxarray35_ = mclInitializeString(1, _array36_);

static mxChar _array38_[1] = { 'c' };
static mwArray _mxarray37_ = mclInitializeString(1, _array38_);

static mxChar _array40_[1] = { 'w' };
static mwArray _mxarray39_ = mclInitializeString(1, _array40_);

static mxChar _array42_[3] = { 'g', 'a', 'm' };
static mwArray _mxarray41_ = mclInitializeString(3, _array42_);

static mxChar _array44_[11] = { 'P', 'o', 'p', 'u', 'l', 'a',
                                't', 'i', 'o', 'n', ' ' };
static mwArray _mxarray43_ = mclInitializeString(11, _array44_);

static mxChar _array46_[20] = { 'G', 'r', 'o', 'w', 't', 'h', ' ',
                                'R', 'a', 't', 'e', ',', ' ', 'g',
                                '(', 'x', ',', 'P', '1', ')' };
static mwArray _mxarray45_ = mclInitializeString(20, _array46_);

static mxChar _array48_[22] = { 'M', 'o', 'r', 'a', 'l', 'i', 't', 'y',
                                ' ', 'R', 'a', 't', 'e', ',', ' ', 'm',
                                '(', 'x', ',', 'P', '1', ')' };
static mwArray _mxarray47_ = mclInitializeString(22, _array48_);

static mxChar _array50_[26] = { 'R', 'e', 'p', 'r', 'o', 'd', 'u', 'c', 't',
                                'i', 'o', 'n', ' ', 'R', 'a', 't', 'e', ',',
                                ' ', 'b', '(', 'x', ',', 'P', '1', ')' };
static mwArray _mxarray49_ = mclInitializeString(26, _array50_);
static mwArray _mxarray51_ = mclInitializeDouble(2.0);

static mxChar _array53_[23] = { 'G', 'r', 'o', 'w', 't', 'h', ' ', 'R',
                                'a', 't', 'e', ',', ' ', 'g', '(', 'x',
                                ',', 'P', '1', ',', 'P', '2', ')' };
static mwArray _mxarray52_ = mclInitializeString(23, _array53_);

static mxChar _array55_[25] = { 'M', 'o', 'r', 'a', 'l', 'i', 't', 'y', ' ',
                                'R', 'a', 't', 'e', ',', ' ', 'm', '(', 'x',
                                ',', 'P', '1', ',', 'P', '2', ')' };
static mwArray _mxarray54_ = mclInitializeString(25, _array55_);

static mxChar _array57_[29] = { 'R', 'e', 'p', 'r', 'o', 'd', 'u', 'c',
                                't', 'i', 'o', 'n', ' ', 'R', 'a', 't',
                                'e', ',', ' ', 'b', '(', 'x', ',', 'P',
                                '1', ',', 'P', '2', ')' };
static mwArray _mxarray56_ = mclInitializeString(29, _array57_);

static mxChar _array59_[25] = { 'G', 'r', 'o', 'w', 't', 'h', ' ', 'R', 'a',
                                't', 'e', ',', ' ', 'g', '(', 'x', ',', 'P',
                                '1', ',', '.', '.', '.', ',', 'P' };
static mwArray _mxarray58_ = mclInitializeString(25, _array59_);

static mxChar _array61_[1] = { ')' };
static mwArray _mxarray60_ = mclInitializeString(1, _array61_);

static mxChar _array63_[27] = { 'M', 'o', 'r', 'a', 'l', 'i', 't', 'y', ' ',
                                'R', 'a', 't', 'e', ',', ' ', 'm', '(', 'x',
                                ',', 'P', '1', ',', '.', '.', '.', ',', 'P' };
static mwArray _mxarray62_ = mclInitializeString(27, _array63_);

static mxChar _array65_[31] = { 'R', 'e', 'p', 'r', 'o', 'd', 'u', 'c',
                                't', 'i', 'o', 'n', ' ', 'R', 'a', 't',
                                'e', ',', ' ', 'b', '(', 'x', ',', 'P',
                                '1', ',', '.', '.', '.', ',', 'P' };
static mwArray _mxarray64_ = mclInitializeString(31, _array65_);

void InitializeModule_Change_Number_of_Populations() {
}

void TerminateModule_Change_Number_of_Populations() {
}

static void MChange_Number_of_Populations();

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

//
// The function "Change_Number_of_Populations" contains the normal interface
// for the "Change_Number_of_Populations" M-function from file
// "C:\shu\hier_community_exe\Change_Number_of_Populations.m" (lines 1-50).
// This function processes any input arguments and passes them to the
// implementation version of the function, appearing above.
//
void Change_Number_of_Populations() {
    MChange_Number_of_Populations();
}

//
// The function "mlxChange_Number_of_Populations" contains the feval interface
// for the "Change_Number_of_Populations" M-function from file
// "C:\shu\hier_community_exe\Change_Number_of_Populations.m" (lines 1-50). The
// feval function calls the implementation version of
// Change_Number_of_Populations through this function. This function processes
// any input arguments and passes them to the implementation version of the
// function, appearing above.
//
void mlxChange_Number_of_Populations(int nlhs,
                                     mxArray * plhs[],
                                     int nrhs,
                                     mxArray * prhs[]) {
    MW_BEGIN_MLX();
    {
        if (nlhs > 0) {
            error(_mxarray0_);
        }
        if (nrhs > 0) {
            error(_mxarray2_);
        }
        MChange_Number_of_Populations();
    }
    MW_END_MLX();
}

//
// The function "MChange_Number_of_Populations" is the implementation version
// of the "Change_Number_of_Populations" M-function from file
// "C:\shu\hier_community_exe\Change_Number_of_Populations.m" (lines 1-50). 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 Change_Number_of_Populations
//
static void MChange_Number_of_Populations() {
    mwLocalFunctionTable save_local_function_table_
      (&_local_function_table_Change_Number_of_Populations);
    mwArray populations(mclGetUninitializedArray());
    mwArray i(mclGetUninitializedArray());
    mwArray ans(mclGetUninitializedArray());
    mwArray current_population(mclGetUninitializedArray());
    mwArray parameters(mclGetUninitializedArray());
    mwArray num_populations(mclGetUninitializedArray());
    mwArray probability_handle(mclGetUninitializedArray());
    mwArray reproduction_rate_str_handle(mclGetUninitializedArray());
    mwArray morality_rate_str_handle(mclGetUninitializedArray());
    mwArray growth_rate_str_handle(mclGetUninitializedArray());
    mwArray populations_handle(mclGetUninitializedArray());
    mwArray number_of_populations_handle(mclGetUninitializedArray());
    mwArray multiple_population_handle(mclGetUninitializedArray());
    //
    // 
    // multiple_population_handle = findobj('Tag','Fig_multiple_population');
    //
    multiple_population_handle = findobj(mwVarargin(_mxarray4_, _mxarray6_));
    //
    // number_of_populations_handle = findobj(multiple_population_handle,'Tag','EditText_number_of_populations');
    //
    number_of_populations_handle
      = findobj(
          mwVarargin(
            mwVv(multiple_population_handle, "multiple_population_handle"),
            _mxarray4_,
            _mxarray8_));
    //
    // populations_handle = findobj(multiple_population_handle,'Tag','PopupMenu_populations');
    //
    populations_handle
      = findobj(
          mwVarargin(
            mwVv(multiple_population_handle, "multiple_population_handle"),
            _mxarray4_,
            _mxarray10_));
    //
    // growth_rate_str_handle = findobj(multiple_population_handle,'Tag','StaticText_growth_rate');
    //
    growth_rate_str_handle
      = findobj(
          mwVarargin(
            mwVv(multiple_population_handle, "multiple_population_handle"),
            _mxarray4_,
            _mxarray12_));
    //
    // morality_rate_str_handle = findobj(multiple_population_handle,'Tag','StaticText_morality_rate');
    //
    morality_rate_str_handle
      = findobj(
          mwVarargin(
            mwVv(multiple_population_handle, "multiple_population_handle"),
            _mxarray4_,
            _mxarray14_));
    //
    // reproduction_rate_str_handle = findobj(multiple_population_handle,'Tag','StaticText_reproduction_rate');
    //
    reproduction_rate_str_handle
      = findobj(
          mwVarargin(
            mwVv(multiple_population_handle, "multiple_population_handle"),
            _mxarray4_,
            _mxarray16_));
    //
    // probability_handle=findobj(multiple_population_handle,'Tag','EditText_Probability');
    //
    probability_handle
      = findobj(
          mwVarargin(
            mwVv(multiple_population_handle, "multiple_population_handle"),
            _mxarray4_,
            _mxarray18_));
    //
    // 
    // num_populations = get(number_of_populations_handle,'String');
    //
    num_populations
      = Nget(
          1,
          mwVarargin(
            mwVv(number_of_populations_handle, "number_of_populations_handle"),
            _mxarray20_));
    //
    // parameters = get(multiple_population_handle,'UserData');
    //
    parameters
      = Nget(
          1,
          mwVarargin(
            mwVv(multiple_population_handle, "multiple_population_handle"),
            _mxarray22_));
    //
    // 
    // if (~isempty(num_populations))
    //
    if (mclNotBool(mwVe(isempty(mwVv(num_populations, "num_populations"))))) {
        //
        // num_populations = str2num(num_populations);
        //
        num_populations = str2num(mwVv(num_populations, "num_populations"));
        //
        // current_population = get(populations_handle,'Value');
        //
        current_population
          = Nget(
              1,
              mwVarargin(
                mwVv(populations_handle, "populations_handle"), _mxarray24_));
        //
        // 
        // if(num_populations <= current_population)
        //
        if (mclLeBool(
              mwVv(num_populations, "num_populations"),
              mwVv(current_population, "current_population"))) {
            //
            // set(populations_handle,'Value',1);
            //
            ans.EqAns(
              Nset(
                0,
                mwVarargin(
                  mwVv(populations_handle, "populations_handle"),
                  _mxarray24_,
                  _mxarray26_)));
            //
            // parameters{3} = parameters{3}(1:num_populations);
            //
            parameters.cell(_mxarray27_)
            = mwVsv(parameters, "parameters").cell(_mxarray27_)(
                colon(_mxarray26_, mwVv(num_populations, "num_populations")));
        //
        // else
        //
        } else {
            //
            // parameters{3}(num_populations) = struct('uo',[],'g',[],'m',[],'b',[],'c',[],'w',[],'gam',[]);      
            //
            parameters.cell(_mxarray27_)(
              mwVsv(num_populations, "num_populations"))
            = struct_func(
                mwVarargin(
                  _mxarray28_,
                  _mxarray30_,
                  _mxarray31_,
                  _mxarray30_,
                  _mxarray33_,
                  _mxarray30_,
                  _mxarray35_,
                  _mxarray30_,
                  _mxarray37_,
                  _mxarray30_,
                  _mxarray39_,
                  _mxarray30_,
                  _mxarray41_,
                  _mxarray30_));
        //
        // end   
        //
        }
        //
        // 
        // for i = 1:num_populations
        //
        {
            int v_(mclForIntStart(1));
            int e_(mclForIntEnd(mwVv(num_populations, "num_populations")));
            if (v_ > e_) {
                i = _mxarray30_;
            } else {
                //
                // populations{i} = ['Population ',num2str(i)];
                // end
                //
                for (; ; ) {
                    populations.cell(v_)
                    = horzcat(
                        mwVarargin(_mxarray43_, mwVe(num2str(mwArray(v_)))));
                    if (v_ == e_) {
                        break;
                    }
                    ++v_;
                }
                i = v_;
            }
        }
        //
        // set(populations_handle,'String',populations);
        //
        ans.EqAns(
          Nset(
            0,
            mwVarargin(
              mwVv(populations_handle, "populations_handle"),
              _mxarray20_,
              mwVv(populations, "populations"))));
        //
        // 
        // 
        // if(num_populations==1)
        //
        if (mclEqBool(mwVv(num_populations, "num_populations"), _mxarray26_)) {
            //
            // set(growth_rate_str_handle,'String',['Growth Rate, g(x,P1)']);
            //
            ans.EqAns(
              Nset(
                0,
                mwVarargin(
                  mwVv(growth_rate_str_handle, "growth_rate_str_handle"),
                  _mxarray20_,
                  _mxarray45_)));
            //
            // set(morality_rate_str_handle,'String',['Morality Rate, m(x,P1)']);
            //
            ans.EqAns(
              Nset(
                0,
                mwVarargin(
                  mwVv(morality_rate_str_handle, "morality_rate_str_handle"),
                  _mxarray20_,
                  _mxarray47_)));
            //
            // set(reproduction_rate_str_handle,'String',['Reproduction Rate, b(x,P1)']);
            //
            ans.EqAns(
              Nset(
                0,
                mwVarargin(
                  mwVv(
                    reproduction_rate_str_handle,
                    "reproduction_rate_str_handle"),
                  _mxarray20_,
                  _mxarray49_)));
        //
        // elseif (num_populations==2)
        //
        } else if (mclEqBool(
                     mwVv(num_populations, "num_populations"), _mxarray51_)) {
            //
            // set(growth_rate_str_handle,'String',['Growth Rate, g(x,P1,P2)']);
            //
            ans.EqAns(
              Nset(
                0,
                mwVarargin(
                  mwVv(growth_rate_str_handle, "growth_rate_str_handle"),
                  _mxarray20_,
                  _mxarray52_)));
            //
            // set(morality_rate_str_handle,'String',['Morality Rate, m(x,P1,P2)']);
            //
            ans.EqAns(
              Nset(
                0,
                mwVarargin(
                  mwVv(morality_rate_str_handle, "morality_rate_str_handle"),
                  _mxarray20_,
                  _mxarray54_)));
            //
            // set(reproduction_rate_str_handle,'String',['Reproduction Rate, b(x,P1,P2)']);
            //
            ans.EqAns(
              Nset(
                0,
                mwVarargin(
                  mwVv(
                    reproduction_rate_str_handle,
                    "reproduction_rate_str_handle"),
                  _mxarray20_,
                  _mxarray56_)));
        //
        // else
        //
        } else {
            //
            // set(growth_rate_str_handle,'String',['Growth Rate, g(x,P1,...,P',num2str(num_populations),')']);
            //
            ans.EqAns(
              Nset(
                0,
                mwVarargin(
                  mwVv(growth_rate_str_handle, "growth_rate_str_handle"),
                  _mxarray20_,
                  horzcat(
                    mwVarargin(
                      _mxarray58_,
                      mwVe(num2str(mwVv(num_populations, "num_populations"))),
                      _mxarray60_)))));
            //
            // set(morality_rate_str_handle,'String',['Morality Rate, m(x,P1,...,P',num2str(num_populations),')']);
            //
            ans.EqAns(
              Nset(
                0,
                mwVarargin(
                  mwVv(morality_rate_str_handle, "morality_rate_str_handle"),
                  _mxarray20_,
                  horzcat(
                    mwVarargin(
                      _mxarray62_,
                      mwVe(num2str(mwVv(num_populations, "num_populations"))),
                      _mxarray60_)))));
            //
            // set(reproduction_rate_str_handle,'String',['Reproduction Rate, b(x,P1,...,P',num2str(num_populations),')']);
            //
            ans.EqAns(
              Nset(
                0,
                mwVarargin(
                  mwVv(
                    reproduction_rate_str_handle,
                    "reproduction_rate_str_handle"),
                  _mxarray20_,
                  horzcat(
                    mwVarargin(
                      _mxarray64_,
                      mwVe(num2str(mwVv(num_populations, "num_populations"))),
                      _mxarray60_)))));
        //
        // end
        //
        }
        //
        // 
        // set(multiple_population_handle,'UserData',parameters);
        //
        ans.EqAns(
          Nset(
            0,
            mwVarargin(
              mwVv(multiple_population_handle, "multiple_population_handle"),
              _mxarray22_,
              mwVv(parameters, "parameters"))));
    //
    // 
    // end
    //
    }
    //
    // 
    // 
    // 
    //
}
