Close This Window

Please download official ILL logos here

 

For using on the web or on a screenFor printing in high resolutionWhite version, for dark backgrounds

Download PNG

Download AI

Download white PNG

Download JPG

 

Download white AI

Install

The Computing for Science (CS) group supports ILL scientists, students and visitors in a number of activities including data analysis, instrument simulation and sample simulation.

Back to ILL Homepage
English French Deutsch 

All Software

Install

function install(MyDest)
% installation script for MFit, Mview, Rescal, SpecTools
%

% /tmp_mnt/home/tas/matroot/matlab/
% /tmp_mnt/home/cs/farhi/matlab
if nargin == 0
MyDest = '';
end

disp('Welcome on the Installation routine for ILL libraries')
disp(' ');
disp(['Running from ' pwd ' on ' date ])
InstallDir = pwd;

% identify system and program version

ComputerSystem = 'unix';
if ~isempty(findstr('apple', lower(computer))) | ~isempty(findstr('powerpc', lower(computer))) | ~isempty(findstr('mac', lower(computer)))
ComputerSystem = 'mac';
end
if ~isempty(findstr('pc', lower(computer))) | ~isempty(findstr('windows', lower(computer)))
ComputerSystem = 'win';
end

disp([ 'Your computer is a ' computer ' (' ComputerSystem ').' ])
if ~exist('filesep')
if strcmp(ComputerSystem,'mac')
pathsep2 = ';';
filesep2 = ':';
end
if strcmp(ComputerSystem, 'win')
pathsep2 = ';';
filesep2 = '\\';
end
if strcmp(ComputerSystem, 'unix')
pathsep2 = ':';
filesep2 = '/';
end
else
pathsep2 = pathsep;
filesep2 = filesep;
end

Program = '';
if exist('OCTAVE_VERSION')
% for Octave : LOADPATH, DEFAULT_LOADPATH, OCTAVE_HOME, OCTAVE_VERSION, EXEC_PATH
Program = 'Octave';
Target = [ strtok(LOADPATH, pathsep2) ] ;
Target = [ Target filesep2 'm' ];
mkdirOk = 0; % mkdir=0 is ok in Octave
rmdirCmd = 'rmdir';
elseif exist('matlabroot')
Program = 'Matlab';
Target = [ matlabroot filesep2 'toolbox' filesep2 'local' ];
mkdirOk = 1; % mkdir=1 is ok in Matlab
rmdirCmd = 'delete';
end
if isempty(Program)
disp('Warning: I do not recognize the Matlab/Octave program.');
disp(' I will install base packages only (as for Octave).');
Program = 'Octave';
end
disp([ 'You are using ' Program ' ' version ])
disp(' ');


% set destination
% now check if I can use the default install location
if ~isempty(MyDest)
Target = MyDest;
end

cd(Target)
if ~exist('mkdir')
eval('!mkdir TestInst');
eval('cd (''TestInst''); c=1; cd ..','c=0;');
else
c=mkdir('TestInst');
end
b = 0;

if c ~= mkdirOk
Target = InstallDir;
disp('You are NOT superuser (can not write anywhere on disk), ');
if strcmp(ComputerSystem, 'unix')
a = '/home/tas/matroot/matlab'; eval('cd (a); b=1;','b=0;');
if b == 1
disp('I''ll setup the installation using the ILL Matlab libraries installed on serhom');
end
end
if b == 0
disp('I will install packages in the default location:')
disp([ ' ' InstallDir ]);
end
else % remove with rmdirCmd
disp('You are superuser (can write anywhere on disk), ');
disp('I will install packages in the default location:')
disp([ ' ' Target ])
if strcmp(ComputerSystem, 'unix') | strcmp(ComputerSystem, 'win')
eval([ '! rmdir TestInst']);
else
eval([ rmdirCmd '(''TestInst'')' ]);
end
end

if b == 0
cd (InstallDir);
disp('You may enter any other location further (needs the permission to write inside)');
disp(' ');
disp(' ');
disp('Enter the full directory path where to install ILL package');
disp('For instance your $HOME/matlab');
disp(['Default is: ' Target ]);
b = 0;
while b == 0
a=input('[Return for default] Install in: ','s');
if isempty(a)
a = Target;
end
eval('cd (a); b=1; cd ..','b=0;');
if b == 0
disp([ 'Sorry ' a ' is not a valid directory.' ]);
c = input('Do you want me to create it ? [Y/n] ','s');
if isempty(c) | strcmp(lower(c),'y')
if strcmp(Program,'Matlab')
if ~exist('mkdir')
eval(['!mkdir ' a ]);
msg = '';
eval([ 'cd (a); c=1; cd ..' ],'c=0; msg=''error'';');
else
eval('[c, msg] = mkdir(filesep2,a);');
end
else
if ~exist('mkdir')
eval(['!mkdir ' a ]);
msg = '';
eval([ 'cd (a); c=1;' ],'c=0; msg=''error'';');
else
eval('[c, msg] = mkdir(a);');
end
end
if c ~= mkdirOk
b == 0;
disp(msg);
disp([ 'Sorry I can not create ' a '.' ]);
disp('Please make it yourself and go on...');
else
b = 1;
cd (InstallDir);
end
end
else
cd (a);
if ~exist('mkdir')
eval('!mkdir TestInst');
eval('cd (''TestInst''); c=1; cd ..','c=0;');
else
c=mkdir('TestInst');
end
if c ~= mkdirOk
b == 0;
disp(msg);
disp([ 'Sorry I can not write into ' a '.' ]);
else
if strcmp(ComputerSystem, 'unix') | strcmp(ComputerSystem, 'win')
eval([ '!rmdir TestInst']);
else
eval([ rmdirCmd '(''TestInst'')' ]);
end
cd (InstallDir);
end
end
end
Dest = a;

% copy to destination for each package, replacing if required

if (~strcmp(Dest, InstallDir))

disp([ 'Origin: ' InstallDir ])
disp([ 'Destination: ' Dest ]);

cd (Dest)

% for all
if strcmp(Program,'Octave')
dirlist = ['nllsq';'funcs';'load';'ResLib2';'FileTools';'MiscTools';'SpectralTools'];
else
dirlist = str2mat('nllsq','funcs','load','ResLib2','FileTools','MiscTools','SpectralTools');
end

% only with Matlab
if strcmp(Program,'Matlab')
dirlist = str2mat(dirlist,'mfit4','rescal5','mview4','ssym1','spec1d',[ 'funcs' filesep2 'trix' ]);
end
for index = 1:size(dirlist,1)
disp([ 'Now installing ' dirlist(index,:) '.' ]);
orig = [ InstallDir filesep2 deblank(fliplr(deblank(fliplr(dirlist(index,:))))) ];
dest = [ Dest filesep2 deblank(fliplr(deblank(fliplr(dirlist(index,:))))) ];
if exist('OCTAVE_VERSION')
system([ 'cp -R ' orig ' ' dest ]);
elseif strcmp(ComputerSystem, 'unix')
eval([ '!cp -R ' orig ' ' dest ]);
elseif strcmp(ComputerSystem, 'win')

eval('cd (dest); b=1; cd ..','b=0;');
if b == 0
if exist('mkdir')
mkdir('',dest);
else
eval(['!mkdir ' dest ]);
disp(['!mkdir ' dest ]);
end
end
disp([ '!copy ' orig '\*.* ' dest ]);
eval([ '!copy ' orig '\*.* ' dest ]);
elseif exist('matlabroot')
dest = deblank(dest);
orig = deblank(orig);
directory = dir(orig);
eval('cd (dest); b=1; cd ..','b=0;');
if b == 0
if exist('mkdir')
mkdir('',dest);
else
eval(['!mkdir ' dest ]);
disp(['!mkdir ' dest ]);
end
end
for index = 1:length(directory)
thisdir = directory(index);
if (thisdir.isdir ~= 1)
if exist('copyfile')
copyfile([ orig filesep2 thisdir.name ], [ dest filesep2 thisdir.name ]);
else
if strcmp(ComputerSystem, 'unix')
eval([ '!cp ' orig filesep2 thisdir.name ' ' dest filesep2 thisdir.name ]);
elseif strcmp(ComputerSystem, 'win')
eval([ '!copy ' orig filesep2 thisdir.name ' ' dest filesep2 thisdir.name ]);
else
disp('I do not know how to copy files...')
return;
end
end
end
end
end
end
else
disp('I do not need to copy files, as you are using the installation directory.')
end
useILLlib = 0;
else
% ADD POSSIBILITY TO USE MATROOT , AND CREATE STARTUP FILE FOR IT...
Dest = '/home/tas/matroot/matlab';
if strcmp(Program,'Octave')
dirlist = ['nllsq';'funcs';'load';'ResLib2';'FileTools';'MiscTools';'SpectralTools'];
else
dirlist = str2mat('nllsq','funcs','load','ResLib2','FileTools','MiscTools','SpectralTools');
end
if strcmp(Program,'Matlab')
dirlist = str2mat('mfit4','rescal5','mview4','ssym1','spec1d',[ 'funcs' filesep2 'trix' ]);
end
disp([ ' ' Dest ])
useILLlib = 1;
end


% generate startup/octaverc with path list (in any case), with Dest.
disp(['** Creating startup file for package installed in ' Dest ]);
if exist('OCTAVE_VERSION')
startfile = 'startup/octaverc';
else
startfile = 'startup.m';
end

if (useILLlib == 1)
if strcmp(ComputerSystem, 'unix')
if exist('OCTAVE_VERSION')
startfile = 'octaverc';
end
startfile = [ getenv('HOME') filesep2 startfile ];
else
startfile = [ InstallDir filesep2 startfile ];
end
else
startfile = [ Dest filesep2 startfile ];
end

disp(['Startup file is: ' startfile]);

if exist(startfile)
disp([ 'File ' startfile ' already exists. I make a copy...' ]);
t=clock;
tmpfile = [ startfile '.' num2str(round(t(6)*10000)) ];
disp(tmpfile);
if exist('copyfile')
copyfile(startfile, tmpfile);
elseif strcmp(ComputerSystem, 'unix')
eval([ '!cp ' startfile ' ' tmpfile ]);
elseif strcmp(ComputerSystem, 'win')
eval([ '!copy ' startfile ' ' tmpfile ]);
else
disp([ 'Can not copy: I will overwrite old startup file ' startfile ]);
disp('Press Ctrl-C to stop install, and save old version');
disp('or press a key to continue (and overwrite).');
pause
end
end
[fid, msg] = fopen(startfile,'w');
if (fid == -1)
disp(msg);
else
if exist('OCTAVE_VERSION')
fprintf(fid,'LOADPATH = [ "/usr/local/share/octave/site//:", LOADPATH ];\n');
fprintf(fid,'default_save_format = "mat-binary";\n');
fprintf(fid,'define_all_return_values = 1;\n');
fprintf(fid,'do_fortran_indexing = 1;\n');
fprintf(fid,'crash_dumps_octave_core = 0;\n');
fprintf(fid,'empty_list_elements_ok = 1;\n');
fprintf(fid,'implicit_str_to_num_ok = 1;\n');
fprintf(fid,'ok_to_lose_imaginary_part = 1;\n');
fprintf(fid,'prefer_column_vectors = 0;\n');
fprintf(fid,'treat_neg_dim_as_zero = 1;\n');
else
fprintf(fid,'%% Matlab TAS libraries startup file\n');
fprintf(fid,[ '%% Date: ' date ]);
fprintf(fid,'\nif exist(''matlab.log'')\n');
fprintf(fid,' disp(''Previous Matlab Log file is renamed as matlab.log.old'')\n');
if exist('copyfile')
fprintf(fid,' copyfile(''matlab.log'', ''matlab.log.old'')\n');
elseif strcmp(ComputerSystem, 'unix')
fprintf(fid,' eval(''!cp matlab.log matlab.log.old'');');
elseif strcmp(ComputerSystem, 'win')
fprintf(fid,' eval(''!copy /Y matlab.log matlab.log.old'');');
end
fprintf(fid,' delete(''matlab.log'');\n');
fprintf(fid,'end\n');
fprintf(fid,'diary matlab.log\n');
fprintf(fid,'disp([ ''matlab.log started on : '' datestr(now) ])\n');
fprintf(fid,'%% Install path, then launch startuser.m if exists\n');
fprintf(fid,'\n%% This line indicates the path to Matlab libraries\n');
if strcmp(filesep2,'\')
newDest = '';
a = Dest;
while ~isempty(a)
[t, a] = strtok(a,'\');
if ~isempty(newDest)
newDest = [ newDest '\\' t ];
else
newDest = [ t ];
end
if length(a) > 1
a = a(2:length(a));
else
a = '';
end
end
else
newDest = Dest;
end
fprintf(fid, [ 'libroot = ''' newDest ]);
fprintf(fid,''';\npath(path,libroot);\n');
fprintf(fid,'libroot = [ libroot filesep ];\n');
fprintf(fid,'st_user = eval(''genpath(libroot)'',''genpath(libroot,'''''''')'');\n');
fprintf(fid,'while ~isempty(st_user)\n [st_t, st_user] = strtok(st_user,''%s'');\n', pathsep2);
fprintf(fid,' if ~isempty(st_t) addpath(st_t); end\nend\n');
fprintf(fid,'disp([ ''Install '' libroot ]);\n');
fprintf(fid,'disp(''ILL libs: ');
fprintf(fid,'%s ',dirlist');
fprintf(fid,''');\n%% Now display infos\n');
fprintf(fid,'eval(''st_user = getenv(''''USER'''');'',''st_user = computer;'');\n');
fprintf(fid,'eval(''st_printer = getenv(''''PRINTER'''');'',''st_printer = ''''<unknown>'''';'');\n');
fprintf(fid,'disp([ ''Hello '' st_user '' ! Your PRINTER is '' st_printer ''.'' ]);\n\n');
fprintf(fid,'clear libroot st_user st_printer st_t st_r\n');
fprintf(fid,'disp(''use "doc" command to access Hypertext OnLine Help.'');\n');
fprintf(fid,'disp(''TIP : Ctrl-a = go to start of line, Ctrl-e = go to end of line'');\n');
fprintf(fid,'disp('' Up ar. = backward history completion. Type "help cedit" for more.'');\n');
fprintf(fid,'if exist(''startuser'')\n');
fprintf(fid,' disp(''Now reading your startuser.m file ...'');\n');
fprintf(fid,' eval(''startuser'');\n');
fprintf(fid,'else\n');
fprintf(fid,' disp(''OK, you don"t have any startuser.m file.'');\n');
fprintf(fid,'end\n');
fprintf(fid,'disp([ ''Current directory is '' pwd ]);\n');
fprintf(fid,'if exist(''matlab.mat'')\n');
fprintf(fid,' disp(''Getting previous workspace data from matlab.mat'')\n');
fprintf(fid,' load matlab.mat\n');
fprintf(fid,'end\n');
fprintf(fid,'set(0,''DefaultFigurePaperUnits'',''centimeters'');\n');
fprintf(fid,'set(0,''DefaultFigurePaperType'',''A4'');\n');
end
fclose(fid);
if (useILLlib == 1)
disp([ 'To activate ILL libraries, you have to start ' Program ' from ']);
disp([ 'the directory where ' startfile ' is.' ])
end
end

% now compile external and MeX programs
cd([ Dest filesep2 'load' ])

cflags = '-O';
if ~isempty(findstr(lower(computer),'hp')) | ~isempty(findstr(lower(computer),'hpux'))
cflags = [ cflags '+z -Ae' ];
elseif ~isempty(findstr(lower(computer),'osf')) | ~isempty(findstr(lower(computer),'dec')) | ~isempty(findstr(lower(computer),'alpha'))
cflags = [ cflags ' -std1' ];
end

% looktxt
if exist('OCTAVE_VERSION')
system([ 'cc ' cflags ' -o looktxt looktxt.c ']);
system([ 'cp looktxt /usr/local/bin' ]);
elseif strcmp(ComputerSystem, 'unix')
eval(['!cc ' cflags ' -o looktxt looktxt.c ']);
eval([ '!cp looktxt /usr/local/bin' ]);
else
disp('Info: Compile the looktxt executable file with your own compiler');
disp('This file is a standard ANSI C source code');
disp('Command should be something like:');
disp([' cc ' cflags ' -o looktxt looktxt.c ']);
disp('Then copy it to your BIN/COMMAND directory');
disp('Note: this file is perhaps already in this distribution...');
end

if exist('matlabroot') & (useILLlib == 0)
% make MeX versions (-DMATLAB_MEX_FILE)
if exist('looktxt') == 2
% looktxt
disp('load:mex -O -output looktxt texmex.c');
cd([ Dest filesep2 'load' ])
eval('mex -O -output looktxt texmex.c','')
end
if exist('looktxt') ~= 3
disp('** I will use M version (looktxt.m), that calls looktxt the system command.');
end
if exist('ffind') == 2
% ffind
disp('load: mex -O ffind.c');
eval('mex -O ffind.c','');
end
if exist('ffind') ~= 3
disp('** I will use M version (ffind.m).');
end
% trix
if exist('ffind') == 2
cd([ Dest filesep2 'funcs' filesep2 'trix' ])
disp('trix: mex -O mcint.c');
if exist('mcint.c'), eval('mex -O mcint.c',''); end
if exist('mcint2.c'), eval('mex -O mcint2.c',''); end
end
end


cd (InstallDir);
disp('Install is now finished. I made what I could !')
return