function mfc_simesh_install(varargin)
  v='0.0.3';
  v_fc_tools='0.0.14';
  v_fc_hypermesh='0.0.2';
  v_fc_oogmsh='0.0.10';
  p = inputParser; 
  p.addParamValue('version', v, @ischar ); % default - dim=-1 has
  p.addParamValue('dir', './fc-simesh-full', @ischar );
  p.addParamValue('fc_tools',v_fc_tools , @ischar ); % fc_tools version
  p.addParamValue('fc_oogmsh',v_fc_oogmsh , @ischar ); % fc_oogmsh version
  p.addParamValue('fc_hypermesh',v_fc_hypermesh , @ischar ); % fc_hypermesh version
  p.addParamValue('gmsh_bin','/usr/bin/gmsh',@ischar);
  p.parse(varargin{:});
  version=p.Results.version;
  fprintf('Parts of the Matlab <fc-simesh> toolbox.\nCopyright (C) 2016 Francois Cuvelier <cuvelier@math.univ-paris13.fr>\n\n');
  
  fprintf('1- Downloading and extracting the toolboxes\n');
  fprintf('   -> <fc-tools>[%s] ...',p.Results.fc_tools)
  fc_tools_dir=get_inst_fc_tools(p.Results.fc_tools,p.Results.dir);
  fprintf(' OK\n');
  fprintf('   -> <fc-hypermesh>[%s] ...',p.Results.version)
  fc_hypermesh_dir=get_inst_fc_hypermesh(p.Results.fc_hypermesh,p.Results.dir);
  fprintf(' OK\n');
  fprintf('   -> <fc-oogmsh>[%s] ...',p.Results.fc_hypermesh)
  fc_oogmsh_dir=get_inst_fc_oogmsh(p.Results.fc_oogmsh,p.Results.dir);
  fprintf(' OK\n');
  fprintf('   -> <fc-simesh>[%s] ...',p.Results.version)
  fc_simesh_dir=get_inst_fc_simesh(p.Results.version,p.Results.dir);
  fprintf(' OK\n');
  
  fprintf('2- Setting the toolboxes\n');
  currentdir=pwd;
  fprintf('2-a) Setting the <fc-hypermesh> toolbox\n');
  cd(fc_hypermesh_dir)
  fc_hypermesh.configure('fc_tools_dir',fc_tools_dir);
  fprintf('2-b) Setting the <fc-oogmsh> toolbox\n');
  cd(fc_oogmsh_dir)
  if exist( p.Results.gmsh_bin)~=2
    fprintf('     -> Select gmsh binary ...\n');
    [gmsh_bin, gmsh_dir]=uigetfile('*','Select GMSH binary',p.Results.gmsh_bin);
  else
    [gmsh_dir,gmsh_bin,gmsh_ext]=fileparts(p.Results.gmsh_bin);
    if ~isempty(gmsh_ext),gmsh_bin=[gmsh_bin,'.',gmsh_ext];end
  end
  fprintf('     -> Using gmsh binary : %s\n',[gmsh_dir,filesep,gmsh_bin]);
  try
    mkdir(fc_oogmsh_dir,'meshes');
  catch
    error('Unable to create <meshes> directory in %s\n',fc_oogmsh_dir)
  end
  fc_oogmsh.configure('fc_tools_dir',fc_tools_dir,'gmsh_bin',[gmsh_dir,filesep,gmsh_bin],'mesh_dir',[fc_oogmsh_dir,filesep,'meshes']);
  cd(fc_simesh_dir)
  fprintf('2-d) Setting the <fc-simesh> toolbox\n');
  fc_simesh.configure('oogmsh_dir',fc_oogmsh_dir,'hypermesh_dir',fc_hypermesh_dir);
  cd(currentdir)
  
  fprintf('3- Using instructions \n');
  fprintf('   To use the <fc-simesh> toolbox:\n');
  fprintf('   addpath(''%s'')\n',fc_simesh_dir);
  fprintf('   fc_simesh.init()\n');
  logfile=[currentdir,filesep,'mfc_simesh_set.m'];
  fprintf('\n   See %s\n',logfile);
  fid=fopen(logfile,'w');
  fprintf(fid,'addpath(''%s'')\n',fc_hypermesh_dir);
  fprintf(fid,'fc_simesh.init()\n');
  fclose(fid);
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-%s.tar.gz',ver,ver);
  try
    untar(urlfile,dir)
  catch
    error('Unable to get :\n  -> %s\n',urlfile);
  end
  %fprintf('Getting <fc-simesh>[%s] toolbox\n',ver);
  fulldir=fullfile(pwd,sprintf('%s%smfc-simesh-%s',dir,filesep,ver));
end
  
function fulldir=get_inst_fc_tools(ver,dir)
  urlfile=sprintf('http://www.math.univ-paris13.fr/~cuvelier/software/codes/fc-tools/%s/mfc-tools-%s.tar.gz',ver,ver);
  try
    untar(urlfile,dir)
  catch
    error('Unable to get :\n  -> %s\n',urlfile);
  end
  %fprintf('Getting <fctools>[%s] toolbox\n',ver)
  fulldir=fullfile(pwd,sprintf('%s%smfc-tools-%s',dir,filesep,ver));
end

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

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


