function mfc_siplt_install(varargin)
  v='0.0.1';
  v_fc_simesh='0.2.0'; % uses fc_simesh install with 'graphics' option to true
  p = inputParser; 
  p.addParamValue('version', v, @ischar ); 
  p.addParamValue('dir', './fc-siplt-full', @ischar );
  p.addParamValue('fc_simesh',v_fc_simesh , @ischar );
  %p.addParamValue('fc_graphimesh',v_fc_simesh , @ischar );
  %p.addParamValue('gmsh_bin','',@ischar);
  p.parse(varargin{:});
  version=p.Results.version;
  fprintf('Parts of the Matlab <fc-siplt> toolbox.\nCopyright (C) 2016-2017 F. Cuvelier <cuvelier@math.univ-paris13.fr>\n\n');
  currentdir=pwd;
  fprintf('**************************************\n');
  fprintf('Downloading and installing the toolbox\n');
  fprintf('    <fc-simesh>[%s]\n',p.Results.fc_simesh)
  fprintf('**************************************\n');
  fc_simesh_dir=get_install('simesh',p.Results.fc_simesh,p.Results.dir,'graphics',true);
  fprintf('    <fc-simesh>[%s]: installed\n\n',p.Results.fc_simesh)
  
%    fprintf('*** Setting the <fc-siplt> toolbox\n');
%    cd(fc_vfemp1_dir)
%    fc_vfemp1.configure('simesh_dir',fc_simesh_dir);
%    cd(currentdir)
%    fprintf('*** The <fc-vfemp1>[%s] is installed\n',p.Results.version)
  fprintf('*** Using instructions \n');
  fprintf('   To use the <fc-siplt> toolbox:\n');
  fprintf('   addpath(''%s'')\n',fc_simesh_dir);
  fprintf('   fc_simesh.init()\n');
  logfile=[currentdir,filesep,'mfc_siplt_set.m'];
  fprintf('\n   See %s\n',logfile);
  fid=fopen(logfile,'w');
  fprintf(fid,'addpath(''%s'')\n',fc_simesh_dir);
  fprintf(fid,'fc_simesh.init()\n');
  fclose(fid);
end

%  function fulldir=get_inst_fc_vfemp1(ver,dir)
%    urlfile=sprintf('http://www.math.univ-paris13.fr/~cuvelier/software/codes/fc-vfemp1/%s/mfc-vfemp1-%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-vfemp1-%s',dir,filesep,ver));
%  end
%  
function fulldir=get_install(name,ver,dir,varargin)
  mfile=sprintf('mfc_%s_install',name);
  urlfile=sprintf('http://www.math.univ-paris13.fr/~cuvelier/software/codes/Matlab/fc-%s/%s/%s.m',name,ver,mfile);
  try
    urlwrite(urlfile,[mfile,'.m']);
  catch
    error('Unable to get :\n  -> %s\n',urlfile);
  end
  A=ls();% force to (re)read current directory (needed with Matlab <= R2015a)
  eval([mfile,'(''dir'',dir,varargin{:})']) % run installation 
  fulldir=fullfile(pwd,sprintf('%s%sfc_%s-%s',dir,filesep,name,ver));
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

