function []=test_crash_submit(varargin); 

opt_id=figure('name', 'Crash uitable', 'position', [300   200   600   800] , 'tag', 'main_figure' );

init_parameters=cellfun(@num2str,num2cell(rand(2,2)), 'UniformOutput', false);

h.table= uitable (opt_id, 
'unit', 'normalized', ...
'Position', [ 0.15 0.15 0.70 0.70 ], ...   
'Data', init_parameters, ... 
'ColumnName', {'Parameters', 'Values'}, ...    
'units', 'normalized', ...
'ColumnWidth', {200 200}, ...   
'ColumnEditable',true, ...  
'tag', 'uitable_crash'); 

case_n=varargin{3}; 

if case_n==1, 
%%{
% Case 1: crash the 2nd run in a same Octave session.  Sometime works, sometime does not. 
% Octave does not crash in the first run.  Octave crashes the 2nd run on windows 10 64x with the same function.  It is likely related to true/false in the table data. If true/false (Line 62) is removed, no issue.   
% command: test_crash_submit([],[],1); close figure manually; test_crash_submit([],[],1) 
    parameters=opt_spq_global_parameters;   parameters=struct2cell(parameters); set(findobj(0, 'tag', 'uitable_crash'), 'data', [parameters(1,:)' parameters(2,:)']); [parameters(1,:)' parameters(2,:)']
    parameters=opt_pso_parameters;          parameters=struct2cell(parameters); set(findobj(0, 'tag', 'uitable_crash'), 'data', [parameters(1,:)' parameters(2,:)']); [parameters(1,:)' parameters(2,:)']
    parameters=opt_ga_UoS_parameters;       parameters=struct2cell(parameters); set(findobj(0, 'tag', 'uitable_crash'), 'data', [parameters(1,:)' parameters(2,:)']); [parameters(1,:)' parameters(2,:)']
    parameters=opt_pso_parameters;          parameters=struct2cell(parameters); set(findobj(0, 'tag', 'uitable_crash'), 'data', [parameters(1,:)' parameters(2,:)']); [parameters(1,:)' parameters(2,:)']
%}
elseif case_n==2
%%{
% case 2, Octave crashes with true/false.  Very repeatable.  100% of the time.   If true/false (Line 62) is removed, no issue 100% of the time.   
% command: test_crash_submit([],[],2)
for ii=1:5  
    parameters=opt_spq_global_parameters;   parameters=struct2cell(parameters); set(findobj(0, 'tag', 'uitable_crash'), 'data', [parameters(1,:)' parameters(2,:)']); [parameters(1,:)' parameters(2,:)']
    parameters=opt_pso_parameters;          parameters=struct2cell(parameters); set(findobj(0, 'tag', 'uitable_crash'), 'data', [parameters(1,:)' parameters(2,:)']); [parameters(1,:)' parameters(2,:)']
    parameters=opt_ga_UoS_parameters;       parameters=struct2cell(parameters); set(findobj(0, 'tag', 'uitable_crash'), 'data', [parameters(1,:)' parameters(2,:)']); [parameters(1,:)' parameters(2,:)']
    parameters=opt_pso_parameters;          parameters=struct2cell(parameters); set(findobj(0, 'tag', 'uitable_crash'), 'data', [parameters(1,:)' parameters(2,:)']); [parameters(1,:)' parameters(2,:)']
end 
%}
else 
   error('need an input')
end 
end 

function parameters=opt_spq_local_parameters(varargin); 
ii=0; 
ii=ii+1;parameters(ii).name='method';           parameters(ii).value='spq_local'; 
ii=ii+1;parameters(ii).name='MaxFunEvals';      parameters(ii).value=500;  
ii=ii+1;parameters(ii).name='tolX';             parameters(ii).value=1e-4;
end 
function parameters=opt_spq_global_parameters(varargin);   
ii=0; 
ii=ii+1;parameters(ii).name='method';           parameters(ii).value='global_opt'; 
ii=ii+1;parameters(ii).name='MaxFunEvals';      parameters(ii).value=500;  
ii=ii+1;parameters(ii).name='obj_fcn_form' ;    parameters(ii).value='classical';   %{'classical' 'penalty'};   %  'classical' or 'penalty' for sqp & ga.  No need for PSO, which is penalty only.  I don't know anything ga can do other than penalty.  It is pre-generated or ga-generated penalty.  

end 
function parameters=opt_pso_parameters(varargin); 
ii=0; 
ii=ii+1;parameters(ii).name='method';           parameters(ii).value='global_opt'; 
ii=ii+1;parameters(ii).name='guessWeight';      parameters(ii).value= 0.5;          % PSO inertia weight 
ii=ii+1;parameters(ii).name='flagVectorize' ;   parameters(ii).value= false;        % is the objective function vectorized?  <====    %%===>  
ii=ii+1;parameters(ii).name='plotFun' ;         parameters(ii).value= '';           % Handle to a function for plotting the progress
end
function parameters=opt_ga_UoS_parameters(varargin); 
ii=0; 
ii=ii+1;parameters(ii).name='method';           parameters(ii).value='global_opt'; 
ii=ii+1;parameters(ii).name='GGAP' ;            parameters(ii).value=.8;            % Generation gap, how many new individuals are created
ii=ii+1;parameters(ii).name='SEL_F' ;           parameters(ii).value= 'sus';        % Name of selection function (stochastic universal sampling)
end 
