0001 function eidors_startup( path_array )
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 if nargin == 0
0015 path_array = {};
0016 end
0017
0018 eidors_msg('=== SETTING UP EIDORS version %s ===', ...
0019 eidors_obj('eidors_version'), 0);
0020
0021 HOMEDIR=strrep(pwd,'\','/');
0022 ver = version_check;
0023 archdir = set_paths(HOMEDIR, ver, path_array);
0024 eidors_cache('init');
0025
0026 eidors_msg('log_level', 2);
0027 set_defaults(HOMEDIR);
0028 print_welcome(HOMEDIR,archdir, ver);
0029
0030 function set_defaults(HOMEDIR)
0031
0032 eidors_default('set','fwd_solve','fwd_solve_1st_order');
0033 eidors_default('set','calc_system_mat','system_mat_1st_order');
0034 eidors_default('set','calc_jacobian','jacobian_adjoint');
0035 eidors_default('set','inv_solve','inv_solve_diff_GN_one_step');
0036 eidors_default('set','calc_RtR_prior','prior_laplace');
0037 eidors_default('set','calc_R_prior','prior_laplace');
0038 eidors_default('set','fwd_solve','fwd_solve_1st_order');
0039 eidors_default('set','GREIT_desired_img','GREIT_desired_img_sigmoid');
0040 eidors_default('set','mk_coarse_fine_mapping','mk_analytic_c2f');
0041
0042 eidors_default('set','mdl_normalize',@(x) 0);
0043
0044 eidors_default('set','call_netgen_finelevel','');
0045
0046 calc_colours('defaults');
0047
0048
0049
0050 eidors_cache('cache_size', 1024^3 );
0051 eidors_cache('boost_priority', 0 );
0052
0053
0054 mk_library_model('LIBRARY_PATH',[HOMEDIR, '/models/cache']);
0055 eidors_cache('cache_path',[HOMEDIR, '/models/cache']);
0056
0057 eidors_cache('eidors_path',HOMEDIR);
0058
0059
0060 function ver = version_check
0061 ver= eidors_obj('interpreter_version');
0062
0063 if ver.isoctave
0064 if ver.ver < 3.008
0065 warning(['EIDORS REQUIRES AT LEAST OCTAVE V3.8.0\n' ...
0066 'Several functions may not work with your version']);
0067 end
0068
0069 warning('off','Octave:load-file-in-path')
0070 else
0071 if ver.ver < 7.006
0072 warning(['EIDORS REQUIRES AT LEAST MATLAB V7.6.\n' ...
0073 'Several functions may not work with your version']);
0074 end
0075 end
0076
0077 function archdir = set_paths(HOMEDIR, ver,path_array)
0078
0079 warning off MATLAB:dispatcher:nameConflict
0080 addpath( HOMEDIR );
0081 addpath([HOMEDIR, '/solvers']);
0082 addpath([HOMEDIR, '/solvers/inverse']);
0083 addpath([HOMEDIR, '/solvers/forward']);
0084 addpath([HOMEDIR, '/solvers/forward/tools-beta']);
0085 addpath([HOMEDIR, '/algorithms']);
0086 addpath([HOMEDIR, '/interface']);
0087 addpath([HOMEDIR, '/models']);
0088 addpath([HOMEDIR, '/meshing']);
0089 addpath([HOMEDIR, '/meshing/netgen']);
0090 addpath([HOMEDIR, '/meshing/distmesh']);
0091 addpath([HOMEDIR, '/meshing/gmsh']);
0092 addpath([HOMEDIR, '/meshing/stl']);
0093 addpath([HOMEDIR, '/sample_data']);
0094 addpath([HOMEDIR, '/examples']);
0095 addpath([HOMEDIR, '/tools']);
0096 addpath([HOMEDIR, '/graphics/matlab']);
0097 addpath([HOMEDIR, '/graphics/vtk']);
0098 addpath(genpath([HOMEDIR, '/external']));
0099 addpath([HOMEDIR, '/deprecated']);
0100 addpath([HOMEDIR, '/overloads']);
0101 if ~ver.isoctave && ver.ver < 9.008
0102 addpath([HOMEDIR, '/overloads/sparse']);
0103 end
0104
0105
0106
0107
0108 if ver.isoctave
0109 warning off Octave:shadowed-function
0110 addpath([HOMEDIR, '/overloads/octave']);
0111 warning on Octave:shadowed-function
0112 end
0113 warning on MATLAB:dispatcher:nameConflict
0114
0115
0116
0117 DEVDIR = [HOMEDIR(1:find(HOMEDIR == '/',1,'last')-1) '/dev'];
0118 for i = 1:length(path_array)
0119 p = genpath([DEVDIR, '/', path_array{i}]);
0120 addpath(p);
0121 end
0122
0123
0124 if ver.isoctave
0125 archdir= strcat('/arch/octave/',computer);
0126
0127 [status] = mkdir([HOMEDIR,archdir]);
0128 else
0129
0130
0131
0132 archdir= '/arch/matlab';
0133 end
0134 addpath([HOMEDIR, archdir]);
0135 fname = [HOMEDIR, archdir, '/eidors_var_id.', mexext];
0136
0137 if ~exist(fname, 'file')
0138 eidors_msg('STARTUP: missing a required, pre-compiled mex file: eidors_var_id', 1);
0139 compile_mex(HOMEDIR,archdir,ver);
0140 end
0141
0142
0143 srcf = strcat(HOMEDIR,'/arch/eidors_var_id.cpp');
0144 mexf = strcat(fname);
0145 if exist(srcf) == 2 && exist(mexf) == 3
0146 srcd=dir(srcf);
0147 mexd=dir(mexf);
0148
0149
0150
0151 newer_src = false;
0152 try newer_src = datenum(srcd.date) > datenum(mexd.date);
0153 catch
0154 newer_src = srcd.datenum > mexd.datenum;
0155 end
0156
0157 if newer_src
0158 warning('eidors_var_id.mex file is older than source file and should be recompiled.');
0159 end
0160
0161 ok = eidors_var_id_ok;
0162 if newer_src || ~ok
0163 while 1
0164 if ~ok
0165 resp = input('Would you like to compile now? [Y/n]: ','s');
0166 else
0167 resp = input('Would you like to compile now? [y/N]: ','s');
0168 if isempty(resp)
0169 resp = 'n';
0170 end
0171 end
0172
0173 switch lower(resp)
0174 case {'n', 'no'}
0175 if ver.isoctave
0176 eidors_msg([...
0177 ' Please compile it using:\n'...
0178 ' cd ',HOMEDIR,'/arch\n'...
0179 ' mkoctfile -v --mex eidors_var_id.cpp\n'...
0180 ' mkdir -p ..',archdir,'\n'...
0181 ' mv *.mex ..',archdir ...
0182 ],1);
0183 else
0184 eidors_msg([ ...
0185 ' Please compile it using:\n'...
0186 ' cd ',HOMEDIR,'/arch\n'...
0187 ' mex "',HOMEDIR,'/arch/eidors_var_id.cpp"\n'...
0188 ' mv *.mex* ',HOMEDIR,'/arch/matlab\n' ...
0189 'If you have a 64 bit machine, please use "mex -largeArrayDims ..."' ...
0190 ],1);
0191 end
0192 break;
0193 case {'','y','yes'}
0194 compile_mex(HOMEDIR,archdir,ver);
0195 break;
0196 end
0197 end
0198 end
0199 end
0200
0201 function compile_mex(HOMEDIR,archdir, ver)
0202 eidors_msg('Attempting to compile eidors_var_id',2);
0203 c = computer;
0204 flags = [];
0205
0206 if ver.isoctave
0207 curdir = cd;
0208 cd(sprintf('%s/arch',HOMEDIR));
0209 mex eidors_var_id.cpp
0210
0211
0212
0213 movefile(sprintf('%s/arch/*.mex',HOMEDIR), ...
0214 sprintf('%s%s/',HOMEDIR,archdir));
0215 cd(curdir)
0216 return
0217 end
0218
0219 if strcmp(c(end-1:end),'64')
0220 flags = '-largeArrayDims';
0221 end
0222 cmd = sprintf('mex %s "%s/arch/eidors_var_id.cpp"', flags, HOMEDIR);
0223
0224
0225 eval(cmd);
0226
0227
0228
0229
0230
0231 targ = sprintf('%s%s/eidors_var_id.%s',HOMEDIR,archdir,mexext);
0232 try
0233 delete( targ );
0234 end
0235 movefile(sprintf('%s/eidors_var_id.%s',HOMEDIR, mexext), targ)
0236
0237 ok = eidors_var_id_ok;
0238 if ~ok
0239 fprintf([ ...
0240 'After compilation, eidors_var_id does not seem to be working.' ...
0241 'Sorry, you will need to debug this yourself. Some ideas are:\n\n' ...
0242 'On windows, try "mex -setup". You may need to install a compiler.' ...
0243 'For your matlab version (ie R2013a), see:' ...
0244 'http://www.mathworks.com/support/compilers/R2013a\n\n' ...
0245 'On linux, you may need to install older compilers like gcc-4.4.' ...
0246 'These can be used by writing\n' ...
0247 ' mex CC=gcc-4.4 CXX=g++-4.4 -largeArrayDims eidors_var_id.cpp\n']);
0248 end
0249
0250 function print_welcome(HOMEDIR,archdir,ver)
0251 eidors_ver = eidors_obj('eidors_version');
0252 if eidors_ver(end) == '+'
0253
0254
0255
0256
0257 [status, result] = system('svnversion');
0258 if status==0;
0259 eidors_ver = [eidors_ver, ' SVN_ID=', result(1:end-1)];
0260 else
0261 eidors_ver = [eidors_ver, ' SVN_ID=unknown'];
0262 end
0263 end
0264 eidors_msg('Installed EIDORS (Ver: %s)', eidors_ver,1);
0265
0266 eidors_msg('Parameter: cache_size=%.0f MB',eidors_cache('cache_size')/(1024*1024),1);
0267 eidors_msg('Parameter: mapped_colour=%d',calc_colours('mapped_colour'),1);
0268 if calc_colours('greylev')>=0
0269 eidors_msg('Default background colour: black',1);
0270 else
0271 eidors_msg('Default background colour: white',1);
0272 end
0273 eidors_msg('EIDORS mex folder: %s%s',HOMEDIR,archdir,1);
0274 eidors_msg('EIDORS cache folder: %s (must be writable)', ...
0275 eidors_cache('cache_path'),1);
0276 eidors_msg('EIDORS model cache: %s', mk_library_model('LIBRARY_PATH'),1);
0277
0278
0279
0280
0281 if ver.isoctave
0282 canwritehtml=0;
0283 else try
0284 mf = com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame;
0285 if isempty(mf)
0286 canwritehtml=0;
0287 else
0288 canwritehtml=1;
0289 end
0290 catch
0291 canwritehtml=0;
0292 end
0293 end
0294 if canwritehtml
0295 tutorials = '<a href="http://eidors3d.sf.net/tutorial/tutorial.shtml">Tutorials</a>';
0296 else
0297 tutorials = 'Tutorials';
0298 end
0299 eidors_msg(['New to EIDORS? Have a look at the ',tutorials,'.'],1);
0300
0301 function ok = eidors_var_id_ok;
0302 id0 = '';
0303 try id0 = eidors_var_id([]); end
0304 if strcmp(id0, ...
0305 'id_DA39A3EE5E6B4B0D3255BFEF95601890AFD80709')
0306 ok = 1;
0307 elseif strcmp(id0, ...
0308 'id_99AA06D3014798D86001C324468D497F8C010DD2')
0309 ok = 1;
0310 else
0311 ok = 0;
0312 end
0313 if ok==0
0314 warning('caching (function eidors_var_id) is not working');
0315 else
0316 eidors_msg('tested function eidors_var_id: OK',1);
0317 end