eidors_startup

PURPOSE ^

Script to start EIDORS

SYNOPSIS ^

function eidors_startup( path_array )

DESCRIPTION ^

 Script to start EIDORS
 Set path and variables correctly
 USAGE:
   startup - setup basic eidors usage functions
   startup( { dev directory paths })

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function eidors_startup( path_array )
0002 % Script to start EIDORS
0003 % Set path and variables correctly
0004 % USAGE:
0005 %   startup - setup basic eidors usage functions
0006 %   startup( { dev directory paths })
0007 
0008 % NOTE: this is a function, so that we don't put variables into the
0009 % workspace
0010 
0011 % (C) 2005 Andy Adler. License: GPL version 2 or version 3
0012 % $Id: eidors_startup.m 6021 2019-09-15 14:34:01Z aadler $
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 % make EIDORS less verbose by default
0026 eidors_msg('log_level', 2); 
0027 set_defaults(HOMEDIR);
0028 print_welcome(HOMEDIR,archdir, ver);
0029 
0030 function set_defaults(HOMEDIR)
0031     % default functions
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     %models are NOT normalized by default
0042     eidors_default('set','mdl_normalize',@(x) 0); 
0043     %netgen finelevel is coarse
0044     eidors_default('set','call_netgen_finelevel','');
0045 
0046     calc_colours('defaults'); % default calc_colours
0047 
0048     %  Set max cache size. Not completely sure about this
0049     %  but 1GB should be available in most modern machines
0050     eidors_cache('cache_size', 1024^3 );
0051     eidors_cache('boost_priority', 0 ); % set default priority
0052 
0053     % Set default model cache location
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     else
0069         if ver.ver < 7.006
0070             warning(['EIDORS REQUIRES AT LEAST MATLAB V7.6.\n' ...
0071                 'Several functions may not work with your version']);
0072         end
0073     end
0074 
0075 function archdir = set_paths(HOMEDIR, ver,path_array)
0076 
0077     
0078     addpath( HOMEDIR );
0079     addpath([HOMEDIR, '/solvers']);
0080     addpath([HOMEDIR, '/solvers/inverse']);
0081     addpath([HOMEDIR, '/solvers/forward']);
0082     addpath([HOMEDIR, '/solvers/forward/tools-beta']); % Tools for MC's solvers which are not yet general
0083     addpath([HOMEDIR, '/algorithms']);
0084     addpath([HOMEDIR, '/interface']);
0085     addpath([HOMEDIR, '/models']);
0086     addpath([HOMEDIR, '/meshing']);
0087     addpath([HOMEDIR, '/meshing/netgen']);
0088     addpath([HOMEDIR, '/meshing/distmesh']);
0089     addpath([HOMEDIR, '/meshing/gmsh']);
0090     addpath([HOMEDIR, '/meshing/stl']);
0091     addpath([HOMEDIR, '/sample_data']);
0092     addpath([HOMEDIR, '/examples']);
0093     addpath([HOMEDIR, '/tools']);
0094     addpath([HOMEDIR, '/graphics/matlab']);
0095     addpath([HOMEDIR, '/graphics/vtk']);
0096     addpath(genpath([HOMEDIR, '/external'])); %add subdirectories
0097     addpath([HOMEDIR, '/deprecated']);
0098     % we will be overloading built-in functions. Disable the warning.
0099     warning off MATLAB:dispatcher:nameConflict
0100     addpath([HOMEDIR, '/overloads']);
0101     warning on MATLAB:dispatcher:nameConflict
0102 
0103     %addpath([HOMEDIR, '/tests']);
0104 
0105     DEVDIR = [HOMEDIR(1:find(HOMEDIR == '/',1,'last')-1) '/dev'];
0106     for i = 1:length(path_array)
0107         p = genpath([DEVDIR, '/', path_array{i}]);
0108         addpath(p);
0109     end
0110 
0111     % We need to add an architecture specific directory for mex files
0112     if ver.isoctave
0113         archdir= strcat('/arch/octave/',computer);
0114 % Make sure that the archdir exists
0115         [status] = mkdir([HOMEDIR,archdir]);
0116     else
0117         % problem was that MSVC compiles depended on versions of MSVCRT1xx.dll.
0118     % which was not available with all windows/matlab versions.
0119     % New concept is to try building with MINGW compiler
0120         archdir= '/arch/matlab';
0121     end
0122     addpath([HOMEDIR, archdir]);
0123     fname = [HOMEDIR, archdir, '/eidors_var_id.', mexext];
0124     
0125     if ~exist(fname, 'file')
0126        eidors_msg('STARTUP: missing a required, pre-compiled mex file: eidors_var_id', 1);
0127        compile_mex(HOMEDIR,archdir,ver);
0128     end
0129 
0130     % check that the compiled mex file is newer than the source file
0131     srcf = strcat(HOMEDIR,'/arch/eidors_var_id.cpp');
0132     mexf = strcat(fname);
0133     if exist(srcf) == 2 && exist(mexf) == 3
0134         srcd=dir(srcf);
0135         mexd=dir(mexf);
0136 
0137 
0138         % We thank MATLAB for their version issues
0139         newer_src = false;
0140         try newer_src = datenum(srcd.date) > datenum(mexd.date);
0141         catch
0142            newer_src = srcd.datenum > mexd.datenum;
0143         end
0144 
0145         if newer_src
0146            warning('eidors_var_id.mex file is older than source file and should be recompiled.');
0147         end
0148 
0149         ok = eidors_var_id_ok;
0150         if newer_src || ~ok
0151            while 1
0152               if ~ok
0153                  resp = input('Would you like to compile now? [Y/n]: ','s');
0154               else
0155                  resp = input('Would you like to compile now? [y/N]: ','s');
0156                  if isempty(resp)
0157                     resp = 'n';
0158                  end
0159               end
0160               
0161               switch lower(resp)
0162                  case {'n', 'no'}
0163                     if ver.isoctave
0164                        eidors_msg([...
0165                           '  Please compile it using:\n'...
0166                           '    cd ',HOMEDIR,'/arch\n'...
0167                           '    mkoctfile -v --mex eidors_var_id.cpp\n'...
0168                           '    mkdir -p ..',archdir,'\n'...
0169                           '    mv *.mex ..',archdir ...
0170                           ],1);
0171                     else
0172                        eidors_msg([ ...
0173                           '  Please compile it using:\n'...
0174                           '     cd ',HOMEDIR,'/arch\n'...
0175                           '     mex "',HOMEDIR,'/arch/eidors_var_id.cpp"\n'...
0176                           '     mv *.mex* ',HOMEDIR,'/arch/matlab\n' ...
0177                           'If you have a 64 bit machine, please use "mex -largeArrayDims ..."' ...
0178                           ],1);
0179                     end
0180                     break;
0181                  case {'','y','yes'}
0182                    compile_mex(HOMEDIR,archdir,ver);
0183                    break;
0184               end
0185            end
0186         end
0187     end
0188 
0189 function compile_mex(HOMEDIR,archdir, ver)
0190     eidors_msg('Attempting to compile eidors_var_id',2);
0191     c = computer;
0192     flags = [];
0193 
0194     if ver.isoctave
0195          curdir = cd;
0196          cd(sprintf('%s/arch',HOMEDIR));
0197          mex eidors_var_id.cpp
0198 % We create the directory earlier
0199 %        system(sprintf('mkdir -p ..%s',archdir));
0200 %    Has to be absolute paths because Matlab coders are so stupid!!
0201          movefile(sprintf('%s/arch/*.mex',HOMEDIR), ...
0202                   sprintf('%s%s/',HOMEDIR,archdir));
0203          cd(curdir)
0204          return
0205     end
0206     
0207     if strcmp(c(end-1:end),'64')
0208        flags = '-largeArrayDims';
0209     end  
0210     cmd = sprintf('mex %s "%s/arch/eidors_var_id.cpp"', flags, HOMEDIR);
0211 % it seems to be better to use matlabs mex, especially since
0212 % there is a latex derivative called mex to interfere with us
0213     eval(cmd);
0214 
0215 % the assholes at matlab don"t respect the 'f' flag in their own
0216 % documentation. this means we need to rewrite the whole file move.
0217 % after 60 years of pcs you would think that copying files is
0218 % understood technology!
0219     targ = sprintf('%s%s/eidors_var_id.%s',HOMEDIR,archdir,mexext);
0220     try
0221     delete( targ );
0222     end
0223     movefile(sprintf('%s/eidors_var_id.%s',HOMEDIR, mexext), targ)
0224 
0225     ok = eidors_var_id_ok; % test it
0226     if ~ok
0227        fprintf([ ...
0228     'After compilation, eidors_var_id does not seem to be working.' ...
0229     'Sorry, you will need to debug this yourself. Some ideas are:\n\n' ...
0230     'On windows, try "mex -setup". You may need to install a compiler.' ...
0231     'For your matlab version (ie R2013a), see:' ...
0232     'http://www.mathworks.com/support/compilers/R2013a\n\n' ...
0233     'On linux, you may need to install older compilers like gcc-4.4.' ...
0234     'These can be used by writing\n' ...
0235     '   mex CC=gcc-4.4 CXX=g++-4.4 -largeArrayDims eidors_var_id.cpp\n']);
0236     end
0237 
0238 function print_welcome(HOMEDIR,archdir,ver)
0239     eidors_ver = eidors_obj('eidors_version');
0240     if eidors_ver(end) == '+' % post release version
0241        % THIS IS HORRIBLE, HORRIBLE CRAP IN SVN. LOTS OF USERS WANT GlobalRev
0242        % BUT THE ARROGANT SVN AUTHORS REFUSE TO PROVIDE IT!!!!
0243        % If available, we could write it into each checkin without having
0244        % to rely on a broken system call.
0245        [status, result] = system('svnversion');
0246        if status==0;
0247           eidors_ver = [eidors_ver, ' SVN_ID=', result(1:end-1)];
0248        else
0249           eidors_ver = [eidors_ver, ' SVN_ID=unknown'];
0250        end
0251     end
0252     eidors_msg('Installed EIDORS (Ver: %s)', eidors_ver,1);
0253 
0254     eidors_msg('Parameter: cache_size=%.0f MB',eidors_cache('cache_size')/(1024*1024),1);
0255     eidors_msg('Parameter: mapped_colour=%d',calc_colours('mapped_colour'),1);
0256     if calc_colours('greylev')>=0
0257         eidors_msg('Default background colour: black',1);
0258     else
0259         eidors_msg('Default background colour: white',1);
0260     end
0261     eidors_msg('EIDORS mex folder: %s%s',HOMEDIR,archdir,1);
0262     eidors_msg('EIDORS cache folder: %s (must be writable)', ...
0263          eidors_cache('cache_path'),1);
0264     eidors_msg('EIDORS model cache: %s', mk_library_model('LIBRARY_PATH'),1);
0265 
0266 
0267     % helpful messages
0268     % TODO: test if desktop is available
0269     if ver.isoctave
0270         canwritehtml=0;
0271     else try
0272             mf = com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame;
0273             if isempty(mf)
0274                 canwritehtml=0;
0275             else
0276                 canwritehtml=1;
0277             end
0278         catch
0279             canwritehtml=0;
0280         end
0281     end
0282     if canwritehtml
0283         tutorials = '<a href="http://eidors3d.sf.net/tutorial/tutorial.shtml">Tutorials</a>';
0284     else
0285         tutorials = 'Tutorials';
0286     end
0287     eidors_msg(['New to EIDORS? Have a look at the ',tutorials,'.'],1);
0288 
0289 function ok = eidors_var_id_ok;
0290     id0 = '';
0291     try id0 = eidors_var_id([]); end
0292     if strcmp(id0, ...
0293       'id_DA39A3EE5E6B4B0D3255BFEF95601890AFD80709')  % SHA1 of nothing
0294        ok = 1;
0295     else
0296        ok = 0;
0297     end
0298     if ok==0
0299        warning('caching (function eidors_var_id) is not working');
0300     else
0301        eidors_msg('tested function eidors_var_id: OK',1);
0302     end

Generated on Tue 31-Dec-2019 17:03:26 by m2html © 2005