Skip to content
Snippets Groups Projects
initialise_gt.m 11.4 KiB
Newer Older
function initialise_gt(ignore_id19)
% INITIALISE.M for Matlab installations on Windows, Macs, and Linux
% ADD DESIRED PATH ENTRIES TO THIS LIST FOLLOWING THE EXISTING FORMAT!!
% PT, big bug with image display due to openGL. crashed completely
% ganymedes. disabled the 03/12/07
% '/graintracking',...  % Grain tracking project (WL,MHG,AK) * symlink *
% 24/05/2010  PT correction to ensure that personnal startup is read at the
% end of the initialisation if present for non DCT people
% 2011-2013, Modified and improved by Nicola Vigano', vigano@esrf.fr
% 2012, Modified and improved by Yoann Guilhem, guilhem@esrf.fr
    if (~exist('ignore_id19', 'var'))
    pathstruct={...                     % Tools from ID19's legacy code
            {'/' },...
            {'/art' },...               % Algebraic reconstruction attempts
            {'/util' },...
            {'/stitching' },...         % Image stitching code
            {'/stitching/heprom' },...
            {'/sliceomatic' },...       % Viewing tool for volumes
            {'/IBF' },...               % IBF tools (Olivier Hignette & Greg Johnson)
            {'/moretomo' },...          % tomography tools in development
            {'/tracking' },...          % particle tracking (Weitzlab, www.harvard.edu)
            {'/ringcorrection' },...    % ring correction code
            {'/imagej' },...            % imagej support
            {'/lsge-matlab' },...       % fitting routines from the NPL in the UK
            {'/lamino' }...             % laminography specific (LH)
            {'/tomotools', '-begin'}... % Tools for tomography
            };
%             {'/parallel' },...          % embarrasingly parallel matlab (ML and GJ)

    disp('Graintracking settings in progress...');

    % No multi platform support, at the moment.
Yoann Guilhem's avatar
Yoann Guilhem committed
    disp(['Machine is: ', computer]);
    if (~ignore_id19)
        deprecated_id19_paths = fullfile('/data','id19','archive','matlab');
        % Linux machines
        if (~exist(deprecated_id19_paths, 'dir'))
Yoann Guilhem's avatar
Yoann Guilhem committed
            error(['ERROR: No folder called: "' deprecated_id19_paths '"']);
        % Adding paths
        for n = 1:length(pathstruct)
            switch size(pathstruct{n}, 2)
            case 1
Yoann Guilhem's avatar
Yoann Guilhem committed
                addpath(fullfile(deprecated_id19_paths, pathstruct{n}{1}));
Yoann Guilhem's avatar
Yoann Guilhem committed
                addpath(fullfile(deprecated_id19_paths, pathstruct{n}{1}), pathstruct{n}{2});
Yoann Guilhem's avatar
Yoann Guilhem committed
                disp(['Wrong parameters number for entry "', n, '"(', pathstruct{n}{1} ,') of structure "pathstruct"']);
                addpath(fullfile(deprecated_id19_paths, pathstruct{n}{1}));
    % suppress extra linefeeds in command window
Yoann Guilhem's avatar
Yoann Guilhem committed
    format compact;

    %%%%%%%%%%%%%%%%%%%%%%
    % other special settings

    % changing default settings at root level
Yoann Guilhem's avatar
Yoann Guilhem committed
    set(0,'DefaultFigurePaperType','A4');
    set(0,'DefaultFigurePaperUnits','centimeters');

    % beamline (for alignment)
Yoann Guilhem's avatar
Yoann Guilhem committed
    global FT_BL;
    FT_BL = 'id19';

    % volume selection in fasttomo; values are 'total', 'manual', 'graphics'
Yoann Guilhem's avatar
Yoann Guilhem committed
    global FT_VOLSELECT;
    FT_VOLSELECT = 'graphics';

    % initialise path for graintracking project
Yoann Guilhem's avatar
Yoann Guilhem committed
    disp('Adding graintracking specific folders to the path');
    global GT_MATLAB_HOME;
    if (isempty(GT_MATLAB_HOME))
        GT_MATLAB_HOME = pwd;
    end
Yoann Guilhem's avatar
Yoann Guilhem committed
    disp(['Using the DCT code in directory ' GT_MATLAB_HOME]);
Yoann Guilhem's avatar
Yoann Guilhem committed
    addpath(GT_MATLAB_HOME);

    addpath(fullfile(GT_MATLAB_HOME, '1_preprocessing'));
    addpath(fullfile(GT_MATLAB_HOME, '1_preprocessing', 'gtSetup_Utils'));
    addpath(fullfile(GT_MATLAB_HOME, '2_difspot'));
    addpath(fullfile(GT_MATLAB_HOME, '3_pairmatching'));
    addpath(fullfile(GT_MATLAB_HOME, '3_pairmatchingGUI'));
    addpath(fullfile(GT_MATLAB_HOME, '4_grains'));
    addpath(fullfile(GT_MATLAB_HOME, '5_reconstruction'));
    addpath(fullfile(GT_MATLAB_HOME, '6_rendering'));
    addpath(fullfile(GT_MATLAB_HOME, '7_fed'));
    addpath(fullfile(GT_MATLAB_HOME, '7_fed', 'AndyFunctions'));
    addpath(fullfile(GT_MATLAB_HOME, '7_fed', 'geometry'));
    addpath(fullfile(GT_MATLAB_HOME, '7_fed', 'Ccode_SpreadInt'));
    addpath(fullfile(GT_MATLAB_HOME, '7_fed2'));
    addpath(fullfile(GT_MATLAB_HOME, '8_optimization'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Analysis'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Boundaries'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Crack'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Cryst'));
Nicola Vigano's avatar
Nicola Vigano committed
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Cryst', 'file_cif'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_DataStructures'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Deformation'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_DB'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Distortion'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Drawing'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Drawing', 'cm_and_cb_utilities'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Drawing', 'freezeColors'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_EDF'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_ErrorHandling'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Fit'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_ForwardSim'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Geo'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_GUI'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_GUI', 'GUILayout-v1p17'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_GUI', 'GUILayout-v1p17', 'Patch'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_GUI', 'FindJObj'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_GVF'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Help'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Help', 'ExportFig'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Help', 'cprintf'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_ICP'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_ID19'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Imaging'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Indexter'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Maths'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_NoiseAnalysis'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_OAR'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Parameters'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Python'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Strain'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Strain2'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Taper'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_TIFF'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_TomoUtils'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_Twins'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_VTK'));
    addpath(fullfile(GT_MATLAB_HOME, 'zUtil_XML'));

    addpath(fullfile(GT_MATLAB_HOME, 'FigureManagement'));
    addpath(fullfile(GT_MATLAB_HOME, 'm2html'));

    % matGeom toolbox
    addpath(fullfile(GT_MATLAB_HOME, 'matGeom'));

    % C Compiled code
    addpath(fullfile(GT_MATLAB_HOME, 'bin', 'mex'));
Yoann Guilhem's avatar
Yoann Guilhem committed
    disp('Loading configuration about external libraries from conf.xml');
    xmlConf = xml_read(fullfile(GT_MATLAB_HOME, 'conf.xml'));
    % File and dirs patterns
Yoann Guilhem's avatar
Yoann Guilhem committed
    global GT_DB;
    GT_DB = [];
    if isfield(xmlConf, 'database')
        GT_DB.name = xmlConf.database.name;
        GT_DB.host = xmlConf.database.host;
        GT_DB.user = xmlConf.database.user;
        GT_DB.password = xmlConf.database.password;
    else
        GT_DB.name = 'graintracking';
        GT_DB.host = 'graindb.esrf.fr';
        GT_DB.user = 'gtadmin';
        GT_DB.password = 'gtadmin';
    end

    [~, hostname] = system('hostname');
Nicola Vigano's avatar
Nicola Vigano committed
    % ASTRA toolkit
Nicola Vigano's avatar
Nicola Vigano committed
    try
        inCellForm = iscell(xmlConf.astra.mex.path);
        for n = 1:length(xmlConf.astra.mex.path)
Nicola Vigano's avatar
Nicola Vigano committed
            if inCellForm
                tmp_path = xmlConf.astra.mex.path{n};
            else
                tmp_path = xmlConf.astra.mex.path(n);
            end
            if isfield(tmp_path, 'ATTRIBUTE')
                if isfield(tmp_path.('ATTRIBUTE'), 'hostname')
                    hosts = tmp_path.('ATTRIBUTE').('hostname');
                    for host = regexp(hosts, ',', 'split')
                        if ~isempty(regexp(hostname, host{1}, 'once'))
                            addpath(tmp_path.('CONTENT'));
Yoann Guilhem's avatar
Yoann Guilhem committed
                            break;
Nicola Vigano's avatar
Nicola Vigano committed
                    addpath(tmp_path.('CONTENT'));
Nicola Vigano's avatar
Nicola Vigano committed
    catch mexc
        gtPrintException(mexc, ...
Yoann Guilhem's avatar
Yoann Guilhem committed
            'No Astra Configuration. Using hardcoded paths for Astra mex files');
        addpath('/scisoft/users/batenbur/gpu/matlab');
        addpath('/scisoft/users/batenbur/gpu/matlab/algorithms');
    end
    % Check which version of matlab compiled the oar executables
    if isfield(xmlConf, 'matlab') && isfield(xmlConf.matlab, 'version')
        matlabVersion = xmlConf.matlab.version;
        currentMatlabRelease = version('-release');
        if (~strcmpi(currentMatlabRelease, matlabVersion))
            warning('MATLAB_COMPILED:version_mismatch', ...
                    ['You are now running matlab "%s", but the matlab ' ...
                    'command specified in conf.xml is "%s".\nThere is no ' ...
                    'guarantee that OAR jobs will work'], ...
                    currentMatlabRelease, matlabVersion);
Nicola Vigano's avatar
Nicola Vigano committed
        warning('XML:no_matlab_version', ...
                'Couldn''t find matlab version in conf.xml');
    disp('Finished adding.');

    disp('Checking compiled functions...');
    cd(fullfile(GT_MATLAB_HOME, 'bin', 'scripts'));
    mFiles = compile(false, false);
    funcNames = fieldnames(mFiles);

    defaultColor  = sprintf(gtGetANSIColour());
    yellowColor = sprintf(gtGetANSIColour('yellow'));
    boldColor = sprintf(gtGetANSIColour('bold'));
    for funcName = reshape(funcNames, [1 numel(funcNames)])
        func = mFiles.(funcName{1});

        mat_file_path = func.('in_mfile');
        comp_file_path = func.('out_file');
        [upToDate, msg] = gtCheckFunctionUpToDate(mat_file_path, comp_file_path);
        if (~upToDate)
            out = [yellowColor 'Function should be recompiled: ' ...
                defaultColor funcName{1}];
            disp(out);
            fprintf(msg);
        end
    end
    disp('Finished checking.');
	
	% Warning when launched on a Windows PC
		% Rendering: the default renderer may have to be changed
		disp('If you are running the code on a Windows PC and experiencing')
		disp('problems with colormaps or graphics resolution, you may have to')
		disp('change the default graphics rendering mode to one of these:')
		disp(' set(0, ''DefaultFigureRenderer'', ''opengl'')')
		disp(' set(0, ''DefaultFigureRenderer'', ''zbuffer'')')
		disp(' set(0, ''DefaultFigureRenderer'', ''painters'')')
	end
    disp(' ')
    cd(fullfile(GT_MATLAB_HOME, 'matGeom'));
    setupMatGeom();
    % load MTex toolbox if logged on rnice6-0101
    % it has been installed only on this host
    % to be generalized
%     mtex_dir = '/sware/com/matlab-tbx/mtex-3.4.2/';
%     if (~isdeployed && exist(mtex_dir, 'dir'))
%         cd(mtex_dir);
%         startup_mtex();
%         cd(current_dir);
%     else
%         warning('MTex:not_installed', 'MTex toolbox is not installed')
%     end
    disp([boldColor 'To report a bug, create a ticket at https://sourceforge.net/p/dct/tickets' defaultColor]);
Andrew King's avatar
Andrew King committed