function ofc_simesh_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.2.1';
  v_fc_tools='0.0.20';
  v_fc_hypermesh='0.0.6';
  v_fc_oogmsh='0.0.17';
  v_fc_mesh='0.0.1';
  v_fc_graphics4mesh='0.0.3';
  v_fc_siplt='0.0.2';
  p = inputParser; 
  p.addParamValue('version', v, @ischar ); 
  p.addParamValue('dir', './fc-simesh-full', @ischar );
  p.addParamValue('graphics', true, @islogical );
  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('fc_mesh',v_fc_mesh , @ischar ); % fc_mesh version
  p.addParamValue('fc_graphics4mesh',v_fc_graphics4mesh , @ischar ); % fc_graphics4mesh version
  p.addParamValue('fc_siplt',v_fc_siplt , @ischar ); % fc_siplt version
  p.addParamValue('verbose', 1, @(x) ismember(x,0:2) ); % level of verbosity 
  p.parse(varargin{:});
  R=p.Results;
  version=R.version;verbose=R.verbose;
  vprintf(verbose,1,'Parts of the GNU Octave <fc-simesh> package.\nCopyright (C) 2016-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] ...',R.fc_tools)
  fc_tools_dir=get_inst_fc_gen('tools',R.fc_tools,R.dir);
  vprintf(verbose,2,' OK\n');
  vprintf(verbose,2,'   -> <fc-hypermesh>[%s] ...',R.fc_hypermesh)
  fc_hypermesh_dir=get_inst_fc_gen('hypermesh',R.fc_hypermesh,R.dir);
  vprintf(verbose,2,' OK\n');
  vprintf(verbose,2,'   -> <fc-oogmsh>[%s] ...',R.fc_oogmsh)
  fc_oogmsh_dir=get_inst_fc_gen('oogmsh',R.fc_oogmsh,R.dir);
  vprintf(verbose,2,' OK\n');
  vprintf(verbose,2,'   -> <fc-mesh>[%s] ...',R.fc_mesh)
  fc_mesh_dir=get_inst_fc_gen('mesh',R.fc_mesh,R.dir);
  vprintf(verbose,2,' OK\n');
  vprintf(verbose,2,'   -> <fc-simesh>[%s] ...',R.version)
  fc_simesh_dir=get_inst_fc_gen('simesh',R.version,R.dir);
  vprintf(verbose,2,' OK\n');
  if R.graphics
    vprintf(verbose,2,'   -> <fc-graphics4mesh>[%s] ...',R.fc_graphics4mesh)
    fc_graphics4mesh_dir=get_inst_fc_gen('graphics4mesh',R.fc_graphics4mesh,R.dir);
    vprintf(verbose,2,' OK\n');
    vprintf(verbose,2,'   -> <fc-siplt>[%s] ...',R.fc_siplt)
    fc_siplt_dir=get_inst_fc_gen('siplt',R.fc_siplt,R.dir);
    vprintf(verbose,2,' OK\n');
  end

  currentdir=pwd;
  vprintf(verbose,1,'2- Setting toolboxes\n');
  vprintf(verbose,2,'2-a) Setting the <fc-hypermesh> toolbox\n');
  cd(fc_hypermesh_dir)
  fc_hypermesh.configure('fc_tools_dir',fc_tools_dir);
  vprintf(verbose,2,'2-b) Setting the <fc-oogmsh> toolbox\n');
  cd(fc_oogmsh_dir)
  fc_oogmsh.configure('fc_tools_dir',fc_tools_dir);%,'gmsh_bin',R.gmsh_bin);
  if R.graphics
    vprintf(verbose,2,'2-c) Setting the <fc-mesh> toolbox\n');
    cd(fc_mesh_dir)
    fc_mesh.configure('fc_tools_dir',fc_tools_dir,'graphics4mesh_dir',fc_graphics4mesh_dir);
    vprintf(verbose,2,'2-d) Setting the <fc-graphics4mesh> toolbox\n');
    cd(fc_graphics4mesh_dir)
    fc_graphics4mesh.configure('fc_mesh_dir',fc_mesh_dir);
    vprintf(verbose,2,'2-e) Setting the <fc-siplt> toolbox\n');
    cd(fc_siplt_dir)
    fc_siplt.configure('fc_graphics4mesh_dir',fc_graphics4mesh_dir,'fc_simesh_dir',fc_simesh_dir)
    vprintf(verbose,2,'2-f) Setting the <fc-simesh> toolbox with graphics\n');
    cd(fc_simesh_dir)
    fc_simesh.configure('oogmsh_dir',fc_oogmsh_dir,'hypermesh_dir',fc_hypermesh_dir, ...
                        'siplt_dir',fc_siplt_dir);
  else
    vprintf(verbose,2,'2-c) Setting the <fc-mesh> toolbox\n');
    fc_mesh.configure('fc_tools_dir',fc_tools_dir,'graphics',false);
    vprintf(verbose,2,'2-d) Setting the <fc-simesh> toolbox\n');
    fc_simesh.configure('oogmsh_dir',fc_oogmsh_dir,'hypermesh_dir',fc_hypermesh_dir, ...
                        'graphics',false);
  end
  cd(currentdir)
  
  vprintf(verbose,1,'3- Using toolboxes :\n');
  vprintf(verbose,1,'   -> %20s : %s\n','fc-tools',R.fc_tools)
  vprintf(verbose,1,'   -> %20s : %s\n','fc-oogmsh',R.fc_oogmsh)
  vprintf(verbose,1,'   -> %20s : %s\n','fc-hypermesh',R.fc_hypermesh)
  vprintf(verbose,1,'   -> %20s : %s\n','fc-mesh',R.fc_mesh)
  vprintf(verbose,1,'   -> %20s : %s\n','fc-simesh',R.version)
  if R.graphics
    vprintf(verbose,1,'   -> %20s : %s\n','fc-graphics4mesh',R.fc_graphics4mesh)
    vprintf(verbose,1,'   -> %20s : %s\n','fc-siplt',R.fc_siplt)
  end
  vprintf(verbose,1,'*** Using instructions \n');
  vprintf(verbose,1,'   To use the <fc-simesh> toolbox:\n');
  vprintf(verbose,1,'   addpath(''%s'')\n',fc_simesh_dir);
  vprintf(verbose,1,'   fc_simesh.init()\n');
  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,'ofc_simesh_set.m'];
  fprintf('\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_simesh_dir);
  fprintf(fid,'fc_simesh.init()\n');
  fclose(fid);
end

function vprintf(verbose,level,varargin)
  if verbose>=level, fprintf(varargin{:});end
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
