function OPTIONS=optim_options(options_in)
% OPTIM_OPTIONS Default parameters used by the optimization routines.
%
%   OPTIONS = OPTIM_OPTIONS returns the default OPTIONS.
%
%   OPTIONS = OPTIM_OPTIONS(SOME_OPTIONS) takes the non-empty vector 
%     SOME_OPTIONS and replaces the zero or missing values of 
%     SOME_OPTIONS with the default OPTIONS.
%
%   The parameters are:                                        Default Values
%   OPTIONS(1) : 1,2,or 3 displays some results,  0: don't             1
%   OPTIONS(2) : Termination tolerance for parameters.                 1e-4
%   OPTIONS(3) : Termination tolerance on cost.                        1e-4
%   OPTIONS(4) : Termination tolerance on max constraint.              1e-4
%   OPTIONS(5) : Maximum number of function evaluations.            1000
%   OPTIONS(6) : Penalty on constraint violations                     10
%   OPTIONS(7) : Exponent on constraint violations                     1
%   OPTIONS(8) : number of function evaluations in average             1
%   OPTIONS(9) : desired coefficient of variation on the mean estimate 0.1
%   OPTIONS(10) : initialize   1: stop when feasible solution           0
%   OPTIONS(11): 1st index for plotting cost function surface          1
%   OPTIONS(12): 2nd index for plotting cost function surface          2
%   OPTIONS(13): number of 1st index values to plot cost funct surface 25
%   OPTIONS(14): number of 2nd index values to plot cost funct surface 35
%   OPTIONS(15): 1: check gradient calculation, 0: don't               0 
%   OPTIONS(16): Penalty type 0: none, 1: interior, 2: exterior        2
%   OPTIONS(17): Minimum param. change for finite difference gradients 1e-6
%   OPTIONS(18): Maximum param. change for finite difference gradients 1e-1
%   OPTIONS(19): Number of equality constraints                        0

default_options = [ 1 , 1e-3 , 1e-3 , 0e-4, 1000 , 10 , 1 , 1 , 0.1 , 0 , 1 , 2 , 25 , 35 , 1e-6 , 2 , 1e-6 , 1e-1 , 0  ];

options_in = abs(options_in);

if nargin<1;
   options_in = [];
end
n=length(options_in);

OPTIONS=zeros(1,19);
OPTIONS(1:n)=options_in(1:n);
OPTIONS(2:end) = OPTIONS(2:end) + (OPTIONS(2:end)<2*eps) .* default_options(2:end);
if n > 5, if options_in(6) == 0, OPTIONS(6) = 0; end; end
OPTIONS(1)  = abs(round(OPTIONS(1)));
OPTIONS(2)  = max(OPTIONS(2),1e-4);
OPTIONS(7)  = min(OPTIONS(7),5);
OPTIONS(7)  = max(OPTIONS(7),0.001);
OPTIONS(8)  = max(OPTIONS(8),1);
OPTIONS(9)  = abs(OPTIONS(9));
OPTIONS(10) = abs(OPTIONS(10));

% ==========================================================================
% updated 2015-03-02 , 2016-03-25, 2020-02-03
