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

Generated on Wed 21-Jun-2017 09:29:07 by m2html © 2005