function mfc_hypermesh_install(varargin)
  if  verLessThan('matlab','8.6.0') % 2015b
    error('Running MATLAB older than MATLAB 8.6.0 (R2015b)')
  end
  v='0.0.7';
  v_fc_tools='0.0.21';
  p = inputParser; 
  p.addParamValue('version', v, @ischar ); % default - dim=-1 has
  p.addParamValue('dir', './fc-hypermesh-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 <fc-hypermesh> Matlab toolbox.\nCopyright (C) 2017-2018 F. Cuvelier <cuvelier@math.univ-paris13.fr>\n\n');
  vprintf(verbose,1,'1- Downloading and extracting the toolboxes\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-hypermesh>[%s] ...',p.Results.version)
  fc_hypermesh_dir=get_inst_fc_gen('hypermesh',p.Results.version,p.Results.dir);
  vprintf(verbose,2,' OK\n');
  currentdir=pwd;
  cd(fc_hypermesh_dir)
  vprintf(verbose,1,'2- Setting the <fc-hypermesh> toolbox\n');
  fc_hypermesh.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-hypermesh',p.Results.version)
  
  vprintf(verbose,1,'*** Using instructions \n');
  vprintf(verbose,1,'   To use the <fc-hypermesh> toolbox:\n');
  vprintf(verbose,1,'   addpath(''%s'')\n',fc_hypermesh_dir);
  vprintf(verbose,1,'   fc_hypermesh.init()\n');
  logfile=[currentdir,filesep,'mfc_hypermesh_set.m'];
  vprintf(verbose,1,'\n   See %s\n',logfile);
  fid=fopen(logfile,'w');
  fprintf(fid,'addpath(''%s'')\n',fc_hypermesh_dir);
  fprintf(fid,'fc_hypermesh.init()\n');
  fclose(fid);
end

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

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