function [coll, spec] = coll_get_settings(prob, tbid, coll)
%COLL_GET_SETTINGS   Merge COLL toolbox settings with default values.

% Copyright (C) Frank Schilder, Harry Dankowicz
% $Id: coll_get_settings.m 2862 2015-07-26 22:11:32Z hdankowicz $

spec1 = {% Name   Type  Default  Action  Args  Description
         'var', 'log|on', false, 'switch', {}, 'enable/disable temporary storage of solution to variational problem'
        'NTST',    'int',    10,   'read', {}, 'number of mesh intervals'
        'NCOL',    'int',     4,   'read', {}, 'number of collocation nodes'
         'SAD',    'num',  0.95,   'read', {}, 'equidistribution weight for error estimator'
      'method',    'str',  '3I',   'read', {}, 'choice of Banach iteration boundary condition'
       'NBeta',    'int',     5,   'read', {}, 'number of homotopy steps for initialization of fundamental solution'
      'NBItMX',    'int',    10,   'read', {}, 'maximum number of Banach iterations for fundamental solution'
  };

coll = coco_parse_settings(prob, spec1, coll, tbid);
if ~coco_exist('TOL', 'class_prop', prob, tbid, '-no-inherit-all')
  coll.TOL = coco_get(prob, 'corr', 'TOL')^(2/3);
end
assert(coll.SAD<=1 && coll.SAD>=0, ...
  '%s: input for option ''SAD'' not in [0,1]', tbid);

spec2 = {% Name   Type  Default  Action  Args  Description
   'TOLINC', 'num',  coll.TOL/5, 'read', {}, 'Upper bound on adaptation window'
   'TOLDEC', 'num', coll.TOL/20, 'read', {}, 'Lower bound on adaptation window'
   'NTSTMN', 'int', min(  5, coll.NTST), 'read', {}, 'Lower bound on number of discretization intervals'
   'NTSTMX', 'int', max(100, coll.NTST), 'read', {}, 'Upper bound on number of discretization intervals'
  };
coll = coco_parse_settings(prob, spec2, coll, tbid);
if ~coco_exist('TOL', 'class_prop', prob, tbid, '-no-inherit-all') % Bug: shouldn't have to do this twice
  coll.TOL = coco_get(prob, 'corr', 'TOL')^(2/3);
end

spec = [spec1; spec2];

end
