function Store_Parameters

multiple_population_handle = findobj('Tag','Fig_multiple_population');
status_bar_handle = findobj(multiple_population_handle,'Tag','StaticText_status_bar');
populations_handle = findobj(multiple_population_handle,'Tag','PopupMenu_populations');
number_of_populations_handle = findobj(multiple_population_handle,'Tag','EditText_number_of_populations');

maximum_time_handle = findobj(multiple_population_handle,'Tag','EditText_maximum_time');
number_of_time_steps_handle = findobj(multiple_population_handle,'Tag','EditText_number_of_time_steps');
maximum_x_handle = findobj(multiple_population_handle,'Tag','EditText_maximum_x');
maximum_time_handle = findobj(multiple_population_handle,'Tag','EditText_maximum_time');
number_of_x_intervals_handle = findobj(multiple_population_handle,'Tag','EditText_number_of_x_intervals');
uo_handle = findobj(multiple_population_handle,'Tag','EditText_uo');
growth_rate_handle = findobj(multiple_population_handle,'Tag','EditText_growth_rate');
morality_rate_handle = findobj(multiple_population_handle,'Tag','EditText_morality_rate');
reproduction_rate_handle = findobj(multiple_population_handle,'Tag','EditText_reproduction_rate');
inflow_handle = findobj(multiple_population_handle,'Tag','EditText_inflow');
weighing_function_handle = findobj(multiple_population_handle,'Tag','EditText_weighing_function');

parameters = get(multiple_population_handle,'UserData');
value = get(gcbo,'String');
current_population =get(populations_handle,'Value');

num_populations = str2num(get(number_of_populations_handle,'String'));
for i = 1:num_populations
    Pvar{i} = ['P',num2str(i)];
end
   
ERROR=0;

switch gcbo
   
case maximum_time_handle
    
    if(isempty(value))
        set(errordlg('The maximum time must be a positive number!'),'Color','Red');
        ERROR = 1;
     else
         value = str2num(value);
         if(value<=0)
            set(errordlg('The maximum time must be a positive number!'),'Color','Red');
            ERROR = 2;
        else
            parameters{2}(1) =value; 
        end
     end
   
case number_of_time_steps_handle
    
    if(isempty(value))
        set(errordlg('The # of time steps must be a positive integer!'),'Color','Red');
        ERROR = 1;
     else
         value = str2num(value);
         if(value<=0 | mod(value,1) > 0)
            set(errordlg('The # of time steps must be a positive integer!'),'Color','Red');
            ERROR = 2;
        else
            parameters{2}(2) =value; 
        end
     end
   
case maximum_x_handle
     
     if(isempty(value))
        set(errordlg('The maximum x must be a positive number!'),'Color','Red');
        ERROR = 1;
     else
         value = str2num(value);
         if(value<=0)
            set(errordlg('The maximum x must be a positive number!'),'Color','Red');
            ERROR = 2;
        else
            parameters{2}(3) =value; 
        end
     end
   
case number_of_x_intervals_handle
    
    if(isempty(value))
        set(errordlg('The # of x divisions must be a positive integer!'),'Color','Red');
        ERROR = 1;
     else
         value = str2num(value);
         if(value<=0 | mod(value,1) > 0)
            set(errordlg('The # of x divisions must be a positive integer!'),'Color','Red');
            ERROR = 2;
        else
            parameters{2}(4) =value; 
        end
     end
   
case uo_handle
    
   if(isempty(value))
      set(errordlg('The Initial Population Distribution is empty!'),'Color','Red');
      ERROR = 1;
   else
      var = symvar(value);
      if(~isempty(var))
         L=length(var);
         i = 1;
         while(i<=L)
            if( ~strcmp(var{i},'x'))
               ERROR = 3;
               i=L;
            end
            i = i+1;
         end
         
         if(ERROR)
            set(errordlg('The Initial Population Distribution equation only depends on x!'),'Color','Red');
         else
            x = 0;
            errordlg_str = ...
               'set(errordlg(''There is a syntax error in the Initial Population Distribution equation''),''Color'',''Red''); ERROR = 4;';
            eval(value,errordlg_str);
         end
      else
         errordlg_str = ...
            'set(errordlg(''There is a syntax error in the Initial Population Distribution equation''),,''Color'',''Red''); ERROR = 4;';
         eval(value,errordlg_str);
      end
   end
   
   if(ERROR==0)
      parameters{3}(current_population) = setfield(parameters{3}(current_population),'uo',value);
   end
   
   
case growth_rate_handle
    
   if(isempty(value))
      set(errordlg('The Growth Rate is empty!'),'Color','Red');
      ERROR = 1;
   else      
      var=symvar(value);
      if(~isempty(var))
          
         L=length(var);
         i = 1;
         while(i<=L)
            if (length(var{i})<=2)
                if(~strcmp(var{i},'x') & ~any(strcmp(var{i},Pvar)))
                   ERROR = 3;
                   i=L;
                end
            else
                j=1;
                while(j<=length(var{i}))
                    if(j+1<=length(var{i}))
                       if(~strcmp(var{i}(j),'x') & ~any(strcmp(var{i}(j:j+1),Pvar)))
                          ERROR=3;
                          i=L;
                          j=length(var{i})+1;
                       else
                           if (strcmp(var{i}(j),'x'))
                              j=j+1;
                           else
                              j=j+2;
                           end
                       end
                   else
                       if(~strcmp(var{i}(j),'x'))
                           ERROR=3;
                           i=L;
                           j=length(var{i})+1;
                       end
                   end
                end
            end
            i = i+1;
         end
         
         if(ERROR)
            if(num_populations==1)
               set(errordlg('The Growth Rate has variables of x and P1 only!'),'Color','Red');
            else
                if(num_populations==2)
                    set(errordlg('The Growth Rate has variables of x, P1 and P2 only!'),'Color','Red');
                else
                    set(errordlg(['The Growth Rate has variables of x, P1, P2,...P',num2str(num_populations),'only!']),'Color','Red');
                end
            end
         else
            x = 0;
            P1=0; P2=0; P3=0; P4=0; P5=0; P6=0; P7=0; P8=0; P9=0; P10=0;
            errordlg_str = 'set(errordlg(''There is a syntax error in the Growth Rate equation''),''Color'',''Red''); ERROR = 4;';
            eval(value,errordlg_str);
         end
      else
         errordlg_str = 'set(errordlg(''There is a syntax error in the Growth Rate equation''),''Color'',''Red''); ERROR = 4;';
         eval(value,errordlg_str);
      end
   end
   
   if(ERROR==0)
      parameters{3}(current_population) = setfield(parameters{3}(current_population),'g',value); 
   end
 
case morality_rate_handle
    
   if(isempty(value))
      set(errordlg('The Mortality Rate is empty!'),'Color','Red');
      ERROR = 1;
   else      
      var=symvar(value);
      if(~isempty(var))
          
         L=length(var);
         i = 1;
         while(i<=L)
            if (length(var{i})<=2)
                if(~strcmp(var{i},'x') & ~any(strcmp(var{i},Pvar)))
                   ERROR = 3;
                   i=L;
                end
            else
                j=1;
                while(j<=length(var{i}))
                    if(j+1<=length(var{i}))
                       if(~strcmp(var{i}(j),'x') & ~any(strcmp(var{i}(j:j+1),Pvar)))
                          ERROR=3;
                          i=L;
                          j=length(var{i})+1;
                       else
                           if (strcmp(var{i}(j),'x'))
                              j=j+1;
                           else
                              j=j+2;
                           end
                       end
                   else
                       if(~strcmp(var{i}(j),'x'))
                           ERROR=3;
                           i=L;
                           j=length(var{i})+1;
                       end
                   end
                end
            end
            i = i+1;
         end
         
         if(ERROR)
            if(num_populations==1)
               set(errordlg('The Mortality Rate has variables of x and P1 only!'),'Color','Red');
            else
                if(num_populations==2)
                    set(errordlg('The Mortality Rate has variables of x, P1 and P2 only!'),'Color','Red');
                else
                    set(errordlg(['The Mortality Rate has variables of x, P1, P2,...P',num2str(num_populations),' only!']),'Color','Red');
                end
            end
         else
            x = 0;
            P1=0; P2=0; P3=0; P4=0; P5=0; P6=0; P7=0; P8=0; P9=0; P10=0;
            errordlg_str = 'set(errordlg(''There is a syntax error in the Mortality Rate equation''),''Color'',''Red''); ERROR = 4;';
            eval(value,errordlg_str);
         end
      else
         errordlg_str = 'set(errordlg(''There is a syntax error in the Mortality Rate equation''),''Color'',''Red''); ERROR = 4;';
         eval(value,errordlg_str);
      end
   end
   
   if (ERROR==0)
       parameters{3}(current_population) = setfield(parameters{3}(current_population),'m',value);  
   end
   
case reproduction_rate_handle
    
   if(isempty(value))
      set(errordlg('The Reprodcution Rate is empty!'),'Color','Red');
      ERROR = 1;
   else      
      var=symvar(value);
      if(~isempty(var))
          
         L=length(var);
         i = 1;
         while(i<=L)
            if (length(var{i})<=2)
                if(~strcmp(var{i},'x') & ~any(strcmp(var{i},Pvar)))
                   ERROR = 3;
                   i=L;
                end
            else
                j=1;
                while(j<=length(var{i}))
                    if(j+1<=length(var{i}))
                       if(~strcmp(var{i}(j),'x') & ~any(strcmp(var{i}(j:j+1),Pvar)))
                          ERROR=3;
                          i=L;
                          j=length(var{i})+1;
                       else
                           if (strcmp(var{i}(j),'x'))
                              j=j+1;
                           else
                              j=j+2;
                           end
                       end
                   else
                       if(~strcmp(var{i}(j),'x'))
                           ERROR=3;
                           i=L;
                           j=length(var{i})+1;
                       end
                   end
                end
            end
            i = i+1;
         end
         
         if(ERROR)
            if(num_populations==1)
               set(errordlg('The Reproduction Rate has variables of x and P1 only!'),'Color','Red');
            else
                if(num_populations==2)
                    set(errordlg('The Reproduction Rate has variables of x, P1 and P2 only!'),'Color','Red');
                else
                    set(errordlg(['The Reproduction Rate has variables of x, P1, P2,...P',num2str(num_populations),' only!']),'Color','Red');
                end
            end
         else
            x = 0;
            P1=0; P2=0; P3=0; P4=0; P5=0; P6=0; P7=0; P8=0; P9=0; P10=0;
            errordlg_str = 'set(errordlg(''There is a syntax error in the Reproduction Rate equation''),''Color'',''Red''); ERROR = 4;';
            eval(value,errordlg_str);
         end
      else
         errordlg_str = 'set(errordlg(''There is a syntax error in the Reprodcution Rate equation''),''Color'',''Red''); ERROR = 4;';
         eval(value,errordlg_str);
      end
   end
   
   if(ERROR==0)
      parameters{3}(current_population) = setfield(parameters{3}(current_population),'b',value);
   end
   
   
case inflow_handle
    
    if (isempty(value))
       set(errordlg('The Inflow of Zero-Sized is empty!'),'Color','Red');
       ERROR = 1;
    else
        var = symvar(value);
        if (~isempty(var))
           L=length(var);
           i = 1;
           while(i<=L)
                if( ~strcmp(var{i},'t'))
                   ERROR = 3;
                   i=L;
                end
                i = i+1;
           end
         
           if(ERROR)
              set(errordlg('The Inflow of Zero-Sized equation only depends on t!'),'Color','Red');
           else
              t = 0;
              errordlg_str = ...
               'set(errordlg(''There is a syntax error in the Inflow of Zero-Sized equation''),''Color'',''Red''); ERROR = 4;';
              eval(value,errordlg_str);
           end
        else
           errordlg_str = ...
              'set(errordlg(''There is a syntax error in the Inflow of Zero-Sized equation''),''Color'',''Red''); ERROR = 4;';
           eval(value,errordlg_str);
        end
    end
    
    if(ERROR==0)
       parameters{3}(current_population) = setfield(parameters{3}(current_population),'c',value);
    end
    

case weighing_function_handle
    if (isempty(value))
       set(errordlg('The Weighting Function is empty!'),'Color','Red');
       ERROR = 1;
    else
        var = symvar(value);
        if (~isempty(var))
           L=length(var);
           i = 1;
           while(i<=L)
                if( ~strcmp(var{i},'y') & ~strcmp(var{i},'x'))
                   ERROR = 3;
                   i=L;
                end
                i = i+1;
           end
         
           if(ERROR)
              set(errordlg('The Weighting Function depends on x and y only!'),'Color','Red');
           else
              x = 0;
              y = 0;
              errordlg_str = ...
               'set(errordlg(''There is a syntax error in the Weighting Function''),''Color'',''Red''); ERROR = 4;';
              eval(value,errordlg_str);
           end
        else
           errordlg_str = ...
              'set(errordlg(''There is a syntax error in the Weighting Function''),''Color'',''Red''); ERROR = 4;';
           eval(value,errordlg_str);
        end
    end
    if(ERROR==0)
       parameters{3}(current_population) = setfield(parameters{3}(current_population),'w',value); 
    end
   
end

if(ERROR)
   set(gcbo,'BackgroundColor','Red');
   set(gcbo,'ForegroundColor','White');
   set(status_bar_handle,'String','PLEASE CORRECT YOUR ERROR');
   set(status_bar_handle,'BackgroundColor','Red');
   set(status_bar_handle,'ForegroundColor','White');
   
   if (ERROR==1)
      load wav_files empty_error;
      sound(empty_error{1,1},empty_error{1,2},empty_error{1,3});
   end
   if (ERROR==2)
       load wav_files wrong_number;
       sound(wrong_number{1,1},wrong_number{1,2},wrong_number{1,3});
   end
   if (ERROR==3)
       load wav_files arguments_error;
       sound(arguments_error{1,1},arguments_error{1,2},arguments_error{1,3});
   end
   if (ERROR==4)
       load wav_files syntax_error;
       sound(syntax_error{1,1},syntax_error{1,2},syntax_error{1,3});
   end
else
   set(gcbo,'BackgroundColor','White');
   set(gcbo,'ForegroundColor','Black');
   if(strcmp('PLEASE CORRECT YOUR ERROR',get(status_bar_handle,'String')))
      set(status_bar_handle,'String','');
      set(status_bar_handle,'BackgroundColor','White');
      set(status_bar_handle,'ForegroundColor','Black');
   end
end
set(multiple_population_handle,'UserData',parameters);
