function ofc_mesh_install(varargin)
  if strversion2num(version)<strversion2num('4.2.0')
    error('Using Octave version %s. Version must be >= 4.2.0. ',version)
  end
  warning('off','Octave:shadowed-function');more off
  v='0.0.1';
  v_fc_tools='0.0.20';
  v_fc_graphics4mesh='0.0.3';
  p = inputParser; 
  p.addParamValue('version', v, @ischar ); 
  p.addParamValue('dir', './fc-mesh-full', @ischar );
  p.addParamValue('graphics', true, @islogical );
  p.addParamValue('verbose', 1, @(x) ismember(x,0:2) ); % level of verbosity 
  p.addParamValue('fc_tools',v_fc_tools , @ischar );
  p.addParamValue('graphics4mesh',v_fc_graphics4mesh , @ischar ); % fc_graphics4mesh version
  p.parse(varargin{:});
  version=p.Results.version;
  verbose=p.Results.verbose;
  warning('off','Octave:shadowed-function')
  vprintf(verbose,1,'Parts of the GNU Octave <fc-mesh> package.\nCopyright (C) 2017 Francois Cuvelier <cuvelier@math.univ-paris13.fr>\n\n');
  vprintf(verbose,1,'1- Downloading and extracting the packages\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');
  if p.Results.graphics
    vprintf(verbose,2,'   -> <fc-graphics4mesh>[%s] ...',p.Results.graphics4mesh)
    graphics4mesh_dir=get_inst_fc_gen('graphics4mesh',p.Results.graphics4mesh,p.Results.dir);
    vprintf(verbose,2,' OK\n');
  end
  vprintf(verbose,2,'   -> <fc-mesh>[%s] ...',p.Results.version)
  fc_mesh_dir=get_inst_fc_gen('mesh',p.Results.version,p.Results.dir);
  vprintf(verbose,2,' OK\n');
  
  currentdir=pwd;
  %cd(fc_tools_dir);fc_tools.init()
  if p.Results.graphics
    vprintf(verbose,1,'2- Setting the packages\n');
    vprintf(verbose,2,'2-a) Setting the <fc-graphics4mesh> package\n');
    cd(graphics4mesh_dir)
    fc_graphics4mesh.configure('fc_mesh_dir',fc_mesh_dir);
    vprintf(verbose,2,'2-b) Setting the <fc-mesh> package with graphics\n');
    cd(fc_mesh_dir)
    fc_mesh.configure('fc_tools_dir',fc_tools_dir,'graphics4mesh_dir',graphics4mesh_dir);
  else
    vprintf(verbose,1,'2- Setting the <fc-mesh> package without graphics\n');
    fc_mesh.configure('fc_tools_dir',fc_tools_dir,'graphics',false);
  end
  cd(currentdir)
  
  vprintf(verbose,1,'3- Using toolboxes :\n')
  vprintf(verbose,1,'   -> %20s : %s\n','fc-tools',p.Results.fc_tools)
  if p.Results.graphics,vprintf(verbose,1,'   -> %20s : %s\n','fc-graphics4mesh',p.Results.graphics4mesh);end
  vprintf(verbose,1,'   -> %20s : %s\n','fc-mesh',p.Results.version)
  vprintf(verbose,1,'*** Using instructions \n');
  vprintf(verbose,1,'   To use the <fc-mesh> toolbox:\n');
  vprintf(verbose,1,'   addpath(''%s'')\n',fc_mesh_dir);
  vprintf(verbose,1,'   fc_mesh.init()\n');
  logfile=[currentdir,filesep,'ofc_mesh_set.m'];
  vprintf(verbose,1,'\n   See %s\n',logfile);
  fid=fopen(logfile,'w');
  fprintf(fid,'warning(''off'',''Octave:shadowed-function'');more off\n');
  fprintf(fid,'addpath(''%s'')\n',fc_mesh_dir);
  fprintf(fid,'fc_mesh.init()\n');
  fclose(fid);
end

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

function ver=strversion2num(strv)
% convert version string 'x.y.z' in x*10^6+y*10^3+z
S=strsplit(strv,'.');
assert(length(S)==3);
z=str2num(S{3});assert(z<10^3);
ver=z;
y=str2num(S{2});assert(y<10^3);
ver=ver+10^3*y;
x=str2num(S{1});assert(x<10^3);
ver=ver+10^6*x;
end

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