function mfc_psimesh_install(varargin)
  v='0.0.1';
  v_fc_simesh='0.1.2';
  p = inputParser; 
  p.addParamValue('version', v, @ischar ); % default - dim=-1 has
  p.addParamValue('dir', './fc-psimesh-full', @ischar );
  p.addParamValue('fc_simesh',v_fc_simesh , @ischar ); 
  p.addParamValue('gmsh_bin',[],@(x) isempty(x) || ischar(x)); % default dir specify only in fc-oogmsh
  p.parse(varargin{:});
  version=p.Results.version;
  fprintf('Parts of the Matlab <fc-psimesh> toolbox.\nCopyright (C) 2017 Francois Cuvelier <cuvelier@math.univ-paris13.fr>\n\n');
  
  fprintf('**************************************\n');
  fprintf('Downloading and installing the toolbox\n');
  fprintf('    <fc-simesh>[%s]\n',p.Results.fc_simesh)
  fprintf('**************************************\n');
  fc_simesh_dir=get_inst_fc_simesh(p.Results.fc_simesh,p.Results.dir);
  fprintf('    <fc-simesh>[%s]: installed\n\n',p.Results.fc_simesh)
  currentdir=pwd;
  if ~isempty(p.Results.gmsh_bin)
    cd(fc_simesh_dir)
    fc_simesh.configure('gmsh_bin',p.Results.gmsh_bin);
    cd(currentdir)
  end 
  
  fprintf('**************************************\n');
  fprintf('Downloading and installing the toolbox\n');
  fprintf('    <fc-psimesh>[%s]\n',p.Results.version)
  fprintf('**************************************\n');
  fc_psimesh_dir=get_inst_fc_psimesh(p.Results.version,p.Results.dir);
  
  fprintf('*** Setting the <fc-psimesh> toolbox\n');
  cd(fc_psimesh_dir)
  fc_psimesh.configure('simesh_dir',fc_simesh_dir);
  cd(currentdir)
  fprintf('*** The <fc-psimesh>[%s] is installed\n',p.Results.version)
  fprintf('*** Using instructions \n');
  fprintf('   To use the <fc-psimesh> toolbox:\n');
  fprintf('   addpath(''%s'')\n',fc_psimesh_dir);
  fprintf('   fc_psimesh.init()\n');
  logfile=[currentdir,filesep,'mfc_psimesh_set.m'];
  fprintf('\n   See %s\n',logfile);
  fid=fopen(logfile,'w');
  fprintf(fid,'addpath(''%s'')\n',fc_psimesh_dir);
  fprintf(fid,'fc_psimesh.init()\n');
  fclose(fid);
end

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

function fulldir=get_inst_fc_simesh(ver,dir)
  urlfile=sprintf('http://www.math.univ-paris13.fr/~cuvelier/software/codes/fc-simesh/%s/mfc_simesh_install.m',ver);
  try
    urlwrite(urlfile,'mfc_simesh_install.m');
    mfc_simesh_install('dir',dir);
  catch
    error('Unable to get :\n  -> %s\n',urlfile);
  end
  fulldir=fullfile(pwd,sprintf('%s%smfc-simesh-%s',dir,filesep,ver));
end