function mfc_graphics4mesh_install(varargin)
  if  verLessThan('matlab','8.6.0') % 2015b
    error('Running MATLAB older than MATLAB 8.6.0 (R2015b)')
  end
  v='0.0.3';
  v_fc_mesh='0.0.1';
  p = inputParser; 
  p.addParamValue('version', v, @ischar ); % default - dim=-1 has
  p.addParamValue('dir', './fc-graphics4mesh-full', @ischar );
  p.addParamValue('verbose', 1, @(x) ismember(x,0:2) ); % level of verbosity 
  p.addParamValue('fc_mesh',v_fc_mesh , @ischar ); % fc_tools version
  p.parse(varargin{:});
  version=p.Results.version;
  verbose=p.Results.verbose;
  vprintf(verbose,1,'Parts of the Matlab <fc-graphics4mesh> toolbox.\nCopyright (C) 2016-2017 F. Cuvelier <cuvelier@math.univ-paris13.fr>\n\n');
  currentdir=pwd;
  vprintf(verbose,1,'**************************************\n');
  vprintf(verbose,1,'Downloading and installing the toolbox\n');
  vprintf(verbose,1,'    <fc-mesh>[%s]\n',p.Results.fc_mesh)
  vprintf(verbose,1,'*************** start ****************\n');
  fc_mesh_dir=get_install('mesh',p.Results.fc_mesh,p.Results.dir,'graphics',true,'verbose',verbose);
  vprintf(verbose,1,'**************** end *****************\n');
  vprintf(verbose,1,'*** Using instructions \n');
  vprintf(verbose,1,'   To use the <fc-graphics4mesh> toolbox:\n');
  vprintf(verbose,1,'   addpath(''%s'')\n',fc_mesh_dir);
  vprintf(verbose,1,'   fc_mesh.init()\n');
  logfile=[currentdir,filesep,'mfc_graphics4mesh_set.m'];
  vprintf(verbose,1,'\n   See %s\n',logfile);
  fid=fopen(logfile,'w');
  fprintf(fid,'addpath(''%s'')\n',fc_mesh_dir);
  fprintf(fid,'fc_mesh.init()\n');
  fclose(fid);
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 vprintf(verbose,level,varargin)
  if verbose>=level, fprintf(varargin{:});end
end
