function ofc_bench_install(varargin)
  if strversion2num(version)<strversion2num('4.2.0')
    error('Using Octave version %s. Version must be >= 4.2.0. ',version)
  end
  warning('off','Octave:shadowed-function');more off
  v='0.0.4';
  v_fc_tools='0.0.23';
  p = inputParser; 
  p.addParamValue('version', v, @ischar ); % default - dim=-1 has
  p.addParamValue('dir', './fc-bench-full', @ischar );
  p.addParamValue('verbose', 1, @(x) ismember(x,0:2) ); % level of verbosity 
  p.addParamValue('fc_tools',v_fc_tools , @ischar ); % fc_tools version
  p.parse(varargin{:});
  version=p.Results.version;
  verbose=p.Results.verbose;
  
  vprintf(verbose,1,'Parts of the GNU Octave <fc-bench> package.\nCopyright (C) 2018 F. Cuvelier\n\n');
  vprintf(verbose,1,'1- Downloading and extracting the packages\n');
  vprintf(verbose,2,'   -> <fc-tools>[%s] ...',p.Results.fc_tools)
  fc_tools_dir=get_inst_fc_gen('tools',p.Results.fc_tools,p.Results.dir);
  vprintf(verbose,2,' OK\n');
  vprintf(verbose,2,'   -> <fc-bench>[%s] ...',p.Results.version)
  fc_bench_dir=get_inst_fc_gen('bench',p.Results.version,p.Results.dir);
  vprintf(verbose,2,' OK\n');
  currentdir=pwd;
  cd(fc_bench_dir)
  vprintf(verbose,1,'2- Setting the <fc-bench> package\n');
  fc_bench.configure('fc_tools_dir',fc_tools_dir);
  cd(currentdir)
  
  vprintf(verbose,1,'3- Using toolboxes :\n')
  vprintf(verbose,1,'   -> %20s : %s\n','fc-tools',p.Results.fc_tools)
  vprintf(verbose,1,'   -> %20s : %s\n','fc-bench',p.Results.version)
  vprintf(verbose,1,'*** Using instructions \n');
  vprintf(verbose,1,'   To use the <fc-bench> toolbox:\n');
  vprintf(verbose,1,'   addpath(''%s'')\n',fc_bench_dir);
  vprintf(verbose,1,'   fc_bench.init()\n');
  
  logfile=[currentdir,filesep,'ofc_bench_set.m'];
  vprintf(verbose,1,'\n   See %s\n',logfile);
  fid=fopen(logfile,'w');
  fprintf(fid,'warning(''off'',''Octave:shadowed-function'');more off\n');
  fprintf(fid,'addpath(''%s'')\n',fc_bench_dir);
  fprintf(fid,'fc_bench.init()\n');
  fclose(fid);
end

function fulldir=get_inst_fc_gen(name,ver,dir)
  file=sprintf('ofc-%s-%s.tar.gz',name,ver);
  urlfile=sprintf('http://www.math.univ-paris13.fr/~cuvelier/software/codes/Octave/fc-%s/%s/fc_%s-%s.tar.gz',name,ver,name,ver);
  urlwrite(urlfile,file);
  try
    untar(file,dir)
  catch
    error('Unable to get :\n  -> %s\n',urlfile);
  end
  if strncmp(dir,['.',filesep],2)
    fulldir=fullfile(pwd,sprintf('%s%sfc_%s-%s',dir(3:end),filesep,name,ver));
  else
    fulldir=sprintf('%s%sfc_%s-%s',dir,filesep,name,ver);
  end
end

function ver=strversion2num(strv)
% convert version string 'x.y.z' in x*10^6+y*10^3+z
S=strsplit(strv,'.');
assert(length(S)==3);
z=str2num(S{3});assert(z<10^3);
ver=z;
y=str2num(S{2});assert(y<10^3);
ver=ver+10^3*y;
x=str2num(S{1});assert(x<10^3);
ver=ver+10^6*x;
end

function vprintf(verbose,level,varargin)
  if verbose>=level, fprintf(varargin{:});end
end
