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 if ~ver.isoctave && ver.ver < 9.0073
0105 addpath([HOMEDIR, '/overloads/vecnorm']);
0106 end
0107 if ver.isoctave
0108 warning off Octave:shadowed-function
0109 addpath([HOMEDIR, '/overloads/octave']);
0110 warning on Octave:shadowed-function
0111 end
0112 warning on MATLAB:dispatcher:nameConflict
0113
0114
0115
0116 DEVDIR = [HOMEDIR(1:find(HOMEDIR == '/',1,'last')-1) '/dev'];
0117 for i = 1:length(path_array)
0118 p = genpath([DEVDIR, '/', path_array{i}]);
0119 addpath(p);
0120 end
0121
0122
0123 if ver.isoctave
0124 archdir= strcat('/arch/octave/',computer);
0125
0126 [status] = mkdir([HOMEDIR,archdir]);
0127 else
0128
0129
0130
0131 archdir= '/arch/matlab';
0132 end
0133 addpath([HOMEDIR, archdir]);
0134 fname = [HOMEDIR, archdir, '/eidors_var_id.', mexext];
0135
0136 if ~exist(fname, 'file')
0137 eidors_msg('STARTUP: missing a required, pre-compiled mex file: eidors_var_id', 1);
0138 compile_mex(HOMEDIR,archdir,ver);
0139 end
0140
0141
0142 srcf = strcat(HOMEDIR,'/arch/eidors_var_id.cpp');
0143 mexf = strcat(fname);
0144 if exist(srcf) == 2 && exist(mexf) == 3
0145 srcd=dir(srcf);
0146 mexd=dir(mexf);
0147
0148
0149
0150 newer_src = false;
0151 try newer_src = datenum(srcd.date) > datenum(mexd.date);
0152 catch
0153 newer_src = srcd.datenum > mexd.datenum;
0154 end
0155
0156 if newer_src
0157 warning('eidors_var_id.mex file is older than source file and should be recompiled.');
0158 end
0159
0160 ok = eidors_var_id_ok;
0161 if newer_src || ~ok
0162 while 1
0163 if ~ok
0164 resp = input('Would you like to compile now? [Y/n]: ','s');
0165 else
0166 resp = input('Would you like to compile now? [y/N]: ','s');
0167 if isempty(resp)
0168 resp = 'n';
0169 end
0170 end
0171
0172 switch lower(resp)
0173 case {'n', 'no'}
0174 if ver.isoctave
0175 eidors_msg([...
0176 ' Please compile it using:\n'...
0177 ' cd ',HOMEDIR,'/arch\n'...
0178 ' mkoctfile -v --mex eidors_var_id.cpp\n'...
0179 ' mkdir -p ..',archdir,'\n'...
0180 ' mv *.mex ..',archdir ...
0181 ],1);
0182 else
0183 eidors_msg([ ...
0184 ' Please compile it using:\n'...
0185 ' cd ',HOMEDIR,'/arch\n'...
0186 ' mex "',HOMEDIR,'/arch/eidors_var_id.cpp"\n'...
0187 ' mv *.mex* ',HOMEDIR,'/arch/matlab\n' ...
0188 'If you have a 64 bit machine, please use "mex -largeArrayDims ..."' ...
0189 ],1);
0190 end
0191 break;
0192 case {'','y','yes'}
0193 compile_mex(HOMEDIR,archdir,ver);
0194 break;
0195 end
0196 end
0197 end
0198 end
0199
0200 function compile_mex(HOMEDIR,archdir, ver)
0201 eidors_msg('Attempting to compile eidors_var_id',2);
0202 c = computer;
0203 flags = [];
0204
0205 if ver.isoctave
0206 curdir = cd;
0207 cd(sprintf('%s/arch',HOMEDIR));
0208 mex eidors_var_id.cpp
0209
0210
0211
0212 movefile(sprintf('%s/arch/*.mex',HOMEDIR), ...
0213 sprintf('%s%s/',HOMEDIR,archdir));
0214 cd(curdir)
0215 return
0216 end
0217
0218 if strcmp(c(end-1:end),'64')
0219 flags = '-largeArrayDims';
0220 end
0221 cmd = sprintf('mex %s "%s/arch/eidors_var_id.cpp"', flags, HOMEDIR);
0222
0223
0224 eval(cmd);
0225
0226
0227
0228
0229
0230 targ = sprintf('%s%s/eidors_var_id.%s',HOMEDIR,archdir,mexext);
0231 try
0232 delete( targ );
0233 end
0234 movefile(sprintf('%s/eidors_var_id.%s',HOMEDIR, mexext), targ)
0235
0236 ok = eidors_var_id_ok;
0237 if ~ok
0238 fprintf([ ...
0239 'After compilation, eidors_var_id does not seem to be working.' ...
0240 'Sorry, you will need to debug this yourself. Some ideas are:\n\n' ...
0241 'On windows, try "mex -setup". You may need to install a compiler.' ...
0242 'For your matlab version (ie R2013a), see:' ...
0243 'http://www.mathworks.com/support/compilers/R2013a\n\n' ...
0244 'On linux, you may need to install older compilers like gcc-4.4.' ...
0245 'These can be used by writing\n' ...
0246 ' mex CC=gcc-4.4 CXX=g++-4.4 -largeArrayDims eidors_var_id.cpp\n']);
0247 end
0248
0249 function print_welcome(HOMEDIR,archdir,ver)
0250 eidors_ver = eidors_obj('eidors_version');
0251 if eidors_ver(end) == '+'
0252
0253
0254
0255
0256 [status, result] = system('svnversion');
0257 if status==0;
0258 eidors_ver = [eidors_ver, ' SVN_ID=', result(1:end-1)];
0259 else
0260 eidors_ver = [eidors_ver, ' SVN_ID=unknown'];
0261 end
0262 end
0263 eidors_msg('Installed EIDORS (Ver: %s)', eidors_ver,1);
0264
0265 eidors_msg('Parameter: cache_size=%.0f MB',eidors_cache('cache_size')/(1024*1024),1);
0266 eidors_msg('Parameter: mapped_colour=%d',calc_colours('mapped_colour'),1);
0267 if calc_colours('greylev')>=0
0268 eidors_msg('Default background colour: black',1);
0269 else
0270 eidors_msg('Default background colour: white',1);
0271 end
0272 eidors_msg('EIDORS mex folder: %s%s',HOMEDIR,archdir,1);
0273 eidors_msg('EIDORS cache folder: %s (must be writable)', ...
0274 eidors_cache('cache_path'),1);
0275 eidors_msg('EIDORS model cache: %s', mk_library_model('LIBRARY_PATH'),1);
0276
0277
0278
0279
0280 if ver.isoctave
0281 canwritehtml=0;
0282 else try
0283 mf = com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame;
0284 if isempty(mf)
0285 canwritehtml=0;
0286 else
0287 canwritehtml=1;
0288 end
0289 catch
0290 canwritehtml=0;
0291 end
0292 end
0293 if canwritehtml
0294 tutorials = '<a href="http://eidors3d.sf.net/tutorial/tutorial.shtml">Tutorials</a>';
0295 else
0296 tutorials = 'Tutorials';
0297 end
0298 eidors_msg(['New to EIDORS? Have a look at the ',tutorials,'.'],1);
0299
0300 function ok = eidors_var_id_ok;
0301 id0 = '';
0302 try id0 = eidors_var_id([]); end
0303 if strcmp(id0, ...
0304 'id_DA39A3EE5E6B4B0D3255BFEF95601890AFD80709')
0305 ok = 1;
0306 else
0307 ok = 0;
0308 end
0309 if ok==0
0310 warning('caching (function eidors_var_id) is not working');
0311 else
0312 eidors_msg('tested function eidors_var_id: OK',1);
0313 end