function item = subsasgn_job(item, subs, val)

% function varargout = subsasgn_job(item, subs)
% Treat a subscript reference as a reference in a job structure instead
% of a cfg_item structure. If subs is empty, then the subtree
% beginning at item will be initialised with val. Otherwise, subs(1)
% should have a subscript type of '()' or '{}', depending on the
% structure of the harvested job (cell or struct array). subs(2) should
% have a subscript type of '.' and the subscript reference should be a
% tagname from item.val.
%
% This code is part of a batch job configuration system for MATLAB. See
%      help matlabbatch
% for a general overview.
%_______________________________________________________________________
% Copyright (C) 2007 Freiburg Brain Imaging

% Volkmar Glauche
% $Id: subsasgn_job.m 5678 2013-10-11 14:58:04Z volkmar $

rev = '$Rev: 5678 $'; %#ok

if isempty(subs)
    item = initialise(item, '<DEFAULTS>', false);
    item = initialise(item, val, false);
elseif numel(subs) == 1
    if any(strcmp(subs(1).type, {'()', '{}'}))
        if max(subs(1).subs{1}) > numel(item.cfg_item.val)
            defsubs = setdiff((numel(item.cfg_item.val)+1):max(subs(1).subs{1}), subs(1).subs{1});
        else
            defsubs = [];
        end
        if strcmp(subs(1).type, '()')
            if numel(val) == 1
                val = repmat(val, 1, numel(subs(1).subs{1}));
            elseif numel(val) ~= numel(subs(1).subs{1})
                cfg_message('matlabbatch:subsref_job', 'Item ''%s'': invalid subscript reference.', gettag(item));
            end
            if numel(item.values) == 1 && ~item.forcestruct
                % struct array reference or () subscript into cell array
                citem = initialise(item.values{1}, '<DEFAULTS>', false);
                item  = subsasgn(item, substruct('.', treepart(item, false), '()', {defsubs}), {citem});
                for k = 1:numel(subs(1).subs{1})
                    citem = initialise(item.values{1}, '<DEFAULTS>', false);
                    if isstruct(val)
                        val1 = val(k);
                    else
                        val1 = val{k};
                    end
                    citem = initialise(citem, val1, false);
                    item  = subsasgn(item, substruct('.', treepart(item, false), '{}', {subs(1).subs{1}(k)}), citem);
                end
            else
                % () subscript into cell array, no default items allowed
                if isempty(defsubs)
                    item1 = initialise(item, '<DEFAULTS>', false);
                    item1 = initialise(item1, val, false);
                    for k = 1:numel(subs(1).subs{1})
                        item = subsasgn(item, substruct('.', treepart(item, false), '{}', {subs(1).subs{1}(k)}), item1.cfg_item.val{k});
                    end
                else
                    cfg_message('matlabbatch:subsref_job', 'Item ''%s'': invalid subscript reference.', gettag(item));
                end
            end
        elseif strcmp(subs(1).type, '{}')
            if numel(item.values) == 1 && ~item.forcestruct
                if isa(item.values{1}, 'cfg_branch')
                    % struct array - no {} reference allowed
                    cfg_message('matlabbatch:subsref_job', 'Item ''%s'': invalid subscript reference.', gettag(item));
                else
                    citem = initialise(item.values{1}, '<DEFAULTS>', false);
                    item  = subsasgn(item, substruct('.', treepart(item, false), '()', {defsubs}), {citem});
                    for k = 1:numel(subs(1).subs{1})
                        citem = initialise(item.values{1}, '<DEFAULTS>', false);
                        citem = initialise(citem, val, false);
                        item  = subsasgn(item, substruct('.', treepart(item, false), '{}', {subs(1).subs{1}(k)}), citem);
                    end
                end
            elseif isstruct(val)
                val1 = cell(size(val));
                for k = 1:numel(val)
                    val1{k} = val(k);
                end
                item1 = initialise(item, '<DEFAULTS>', false);
                item1 = initialise(item1, val1, false);
                for k = 1:numel(subs(1).subs{1})
                    item = subsasgn(item, substruct('.', treepart(item, false), '{}', {subs(1).subs{1}(k)}), item1.cfg_item.val{k});
                end
            else
                cfg_message('matlabbatch:subsref_job', 'Item ''%s'': invalid subscript reference.', gettag(item));
            end
        end
    elseif strcmp(subs(1).type, '.') && (numel(item.values) == 1) && ~item.forcestruct && isa(item.values{1}, 'cfg_branch')
        if numel(item.cfg_item.val) == 0
            item.cfg_item.val{1} = initialise(item.values{1}, '<DEFAULTS>', false);
            item.cfg_item.val{1} = subsasgn_job(item.cfg_item.val{1}, subs, val);
        elseif numel(item.cfg_item.val) == 1
            item.cfg_item.val{1} = subsasgn_job(item.cfg_item.val{1}, subs, val);
        else
            cfg_message('matlabbatch:subsref_job', 'Item ''%s'': invalid subscript reference.', gettag(item));
        end
    else
        cfg_message('matlabbatch:subsref_job', 'Item ''%s'': invalid subscript reference.', gettag(item));
    end
else
    [sts, vind] = checksubs_job(item, subs, false);
    if (numel(item.values) == 1) && ~item.forcestruct && isa(item.values{1}, 'cfg_branch')
        nsubs = subs(2:end);
    else
        nsubs = subs(3:end);
    end
    if sts
        citem = subsasgn_job(subsref(item, substruct('.', treepart(item, false),'{}',{vind})), nsubs, val);
        item  = subsasgn(item, substruct('.', treepart(item, false), '{}', subs(1).subs), citem);
    else
        [sts, vind] = checksubs_job(item, subs, true);
        if sts
            if numel(item.values) == 1
                if max(subs(1).subs{1}) > numel(item.cfg_item.val)
                    defsubs = setdiff((numel(item.cfg_item.val)+1):max(subs(1).subs{1}), subs(1).subs{1});
                else
                    defsubs = [];
                end
                if numel(val) == 1
                    val = repmat(val, 1, numel(subs(1).subs{1}));
                elseif numel(val) ~= numel(subs(1).subs{1})
                    cfg_message('matlabbatch:subsref_job', 'Item ''%s'': invalid subscript reference.', gettag(item));
                end
                citem = initialise(item.values{1}, '<DEFAULTS>', false);
                item  = subsasgn(item, substruct('.', treepart(item, false), '()', {defsubs}), {citem});
                citem = subsasgn_job(subsref(item, substruct('.', treepart(item, true),'{}',{vind})), nsubs, val);
                item  = subsasgn(item, substruct('.', treepart(item, false), '{}', subs(1).subs), citem);
            else
                if max(subs(1).subs{1}) > numel(item.cfg_item.val) + 1
                    cfg_message('matlabbatch:subsref_job', 'Item ''%s'': invalid subscript reference.', gettag(item));
                else
                    citem = subsasgn_job(subsref(item, substruct('.', treepart(item, true),'{}',{vind})), nsubs, val);
                    item  = subsasgn(item, substruct('.', treepart(item, false), '{}', subs(1).subs), citem);
                end
            end
        else
            cfg_message('matlabbatch:subsref_job', 'Item ''%s'': invalid subscript reference.', gettag(item));
        end
    end
end


function res = cellfun2(funer, structy)
%An alias for cellfun with UniformOutput set to false
if nargin<2
  error('Not enough arguments to cellfun2\n');
end
res = cellfun(funer, structy, 'UniformOutput', false);


function [varargout] = webwrite(varargin)

% WEBWRITE is a drop-in replacement for the function with the same
% name that was introduced in MATLAB R2014b. This function is only
% partially compatible with the original.
%
% Use as
%   status = webwrite(url, [data], [options])
%
% This function posts data (which can be a struct or a string) to url.
% The options argument is currently ignored.
%
% Unlike builtin MATLAB webwrite, this function
% - sets headers always to 'Content-Type: application/json; charset=UTF-8'
%   irrespective of the contents of the options argument.
% - the status returned is zero if succesful, and nonzero otherwise
%
% This requires that curl is available on the command-line. If curl
% is not available, or an other error occurs, then this function
% raises an error.

% Copyright (C) 2017-2019, Robert Oostenveld, Nikolaas N. Oosterhof
%
% This file is part of FieldTrip, see http://www.fieldtriptoolbox.org
% for the documentation and details.
%
%    FieldTrip is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    FieldTrip is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with FieldTrip. If not, see <http://www.gnu.org/licenses/>.
%
% $Id$

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% try to automatically remove incorrect compat folders from the path, see https://github.com/fieldtrip/fieldtrip/issues/899

if isempty(strfind(mfilename('fullpath'), matlabroot))
  % automatic cleanup does not work when FieldTrip is installed inside the MATLAB path, see https://github.com/fieldtrip/fieldtrip/issues/1527

  alternatives = which(mfilename, '-all');
  if ~iscell(alternatives)
    % this is needed for octave, see https://github.com/fieldtrip/fieldtrip/pull/1171
    alternatives = {alternatives};
  end

  keep = true(size(alternatives));
  for i=1:numel(alternatives)
    keep(i) = keep(i) && ~any(alternatives{i}=='@');  % exclude methods from classes
    keep(i) = keep(i) && alternatives{i}(end)~='p';   % exclude precompiled files
  end
  alternatives = alternatives(keep);

  if exist(mfilename, 'builtin') || any(strncmp(alternatives, matlabroot, length(matlabroot)) & cellfun(@isempty, strfind(alternatives, fullfile('private', mfilename))))
    % remove this directory from the path
    p = fileparts(mfilename('fullpath'));
    warning('removing "%s" from your path, see http://bit.ly/2SPPjUS', p);
    rmpath(p);
    % call the original MATLAB function
    if exist(mfilename, 'builtin')
      [varargout{1:nargout}] = builtin(mfilename, varargin{:});
    else
      [varargout{1:nargout}] = feval(mfilename, varargin{:});
    end
    return
  end

end % automatic cleanup of compat directories

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% this is where the actual replacement code starts
% function status = webwrite(url, data, options)

% deal with the input arguments
if nargin==1
  [url               ] = deal(varargin{1:1});
elseif nargin==2
  [url, data         ] = deal(varargin{1:2});
elseif nargin==3
  [url, data, options] = deal(varargin{1:3});
else
  error('incorrect number of input arguments')
end

if nargin<2
  data = '';
end

if isstruct(data)
  % convert it to JSON string
  data = struct2json(data);
  assert(ischar(data));

  to_remove=sprintf('[\n ]'); % newlines and spaces
  data = regexprep(data, to_remove, '');
end

if ~ischar(data)
  error('unsupported data: input must be string or struct');
end

cmd = sprintf(['curl '...
                '-s '...                                % quiet (no output)
                '-H "Content-Type: application/json;'...  % JSON data
                    'charset=UTF-8" '...                % charset
                '-X POST '...                           % method
                '-d ''%s'' %s'], ...                    % data and URL
                data, url);

[status, str] = system(cmd);

if status
  error('An error occured when running this command: ''%s'':\n%s',cmd,str);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% deal with the output arguments

varargout = {status};


Here you can see part of the example running log for MV-CNN and RGB CNN.

I use K40 to run these codes.
Please run the following code before running fast_classification_UCF101_spatial.m and fast_classification_UCF101_temporal.m:
nvidia-smi -pm 1
nvidia-smi -ac 3004,875

The compuational time for temporal CNN (MV CNN) should around 0.16-0.17 sec.
The compuational time for spatial CNN (RGB CNN) should around 0.10 sec.

Since 250 optical flow and 25 rgb are processed, the speed should be 925 fps.


function sitem = cfg2struct(item)

% function sitem = cfg2struct(item)
% Return a struct containing all fields of item plus a field type. This is
% the method suitable for cfg_exbranch.
%
% This code is part of a batch job configuration system for MATLAB. See
%      help matlabbatch
% for a general overview.
%_______________________________________________________________________
% Copyright (C) 2007 Freiburg Brain Imaging

% Volkmar Glauche
% $Id: cfg2struct.m 1716 2008-05-23 08:18:45Z volkmar $

rev = '$Rev: 1716 $'; %#ok

% Get parent struct, re-classify as field 'type'
sitem = cfg2struct(item.cfg_branch);
sitem.type = class(item);

% Need to cycle through added fields
fn = mysubs_fields;
for k = 1:numel(fn)
    sitem.(fn{k}) = item.(fn{k});
end;


function make_ref_obj(input_var)

if isa(input_var, 'ref_obj')
    return;
end

one_mutable=ref_obj;
one_mutable.ref=input_var;
assignin('caller', inputname(1), one_mutable);

end


function varargout = configManager(varargin)
% CONFIGMANAGER MATLAB code for configManager.fig
%      CONFIGMANAGER, by itself, creates a new CONFIGMANAGER or raises the existing
%      singleton*.
%
%      H = CONFIGMANAGER returns the handle to a new CONFIGMANAGER or the handle to
%      the existing singleton*.
%
%      CONFIGMANAGER('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in CONFIGMANAGER.M with the given input arguments.
%
%      CONFIGMANAGER('Property','Value',...) creates a new CONFIGMANAGER or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before configManager_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to configManager_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help configManager
% Last Modified by GUIDE v2.5 21-Jul-2013 15:10:10
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This file is part of OLPS: http://OLPS.stevenhoi.org/
% Original authors: Doyen Sahoo
% Contributors: Bin LI, Steven C.H. Hoi
% Change log:
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @configManager_OpeningFcn, ...
                   'gui_OutputFcn',  @configManager_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before configManager is made visible.
function configManager_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to configManager (see VARARGIN)

    load config/config;
    handles.config.algorithmList = algorithmList;
    handles.config.algorithmName = algorithmName;
    handles.config.algorithmParameters = algorithmParameters;
    handles.config.dataList = dataList;
    handles.config.dataName = dataName;
    handles.config.defaultParameters = defaultParameters;
    handles.config.dataFrequency = dataFrequency;

    % The list of data and algorithm names for menu
    set(handles.dataList,'String',handles.config.dataList);
    set(handles.algorithmList,'String',handles.config.algorithmList);

% Choose default command line output for configManager
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes configManager wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = configManager_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

function dataNameString_Callback(hObject, eventdata, handles)
% hObject    handle to dataNameString (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of dataNameString as text
%        str2double(get(hObject,'String')) returns contents of dataNameString as a double

% --- Executes during object creation, after setting all properties.
function dataNameString_CreateFcn(hObject, eventdata, handles)
% hObject    handle to dataNameString (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function dataFileName_Callback(hObject, eventdata, handles)
% hObject    handle to dataFileName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of dataFileName as text
%        str2double(get(hObject,'String')) returns contents of dataFileName as a double

% --- Executes during object creation, after setting all properties.
function dataFileName_CreateFcn(hObject, eventdata, handles)
% hObject    handle to dataFileName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function frequency_Callback(hObject, eventdata, handles)
% hObject    handle to frequency (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of frequency as text
%        str2double(get(hObject,'String')) returns contents of frequency as a double

% --- Executes during object creation, after setting all properties.
function frequency_CreateFcn(hObject, eventdata, handles)
% hObject    handle to frequency (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in addData.
function addData_Callback(hObject, eventdata, handles)
% hObject    handle to addData (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

    set(handles.deleteDataMessage, 'String', '');
    set(handles.deleteAlgorithmMessage, 'String', '');

    [r c] = size(handles.config.dataList);
    fileName = get(handles.dataFileName, 'string');
    handles.config.dataList(r+1,c) = {get(handles.dataNameString, 'string')};
    handles.config.dataName(r+1,c) = {fileName};
    handles.config.dataFrequency(r+1,c) = str2num(get(handles.frequency, 'string'));

    % Check if file exists
    fullPath = strcat('..\Data\',fileName, '.mat');
    if ~(exist(fullPath) == 2)
        errorMessage('File does not exist. Please create the file before running the tool box to avoid errors. If the file exists, please enter file name without the .mat extension to avoid this warning. Data has been added.');
    end

    set(handles.dataList,'String',handles.config.dataList);

    set(handles.addDataMessage, 'String', 'Added!');
    pause(1);
    set(handles.addDataMessage, 'String', '');

    guidata(hObject, handles);

% --- Executes on selection change in dataList.
function dataList_Callback(hObject, eventdata, handles)
% hObject    handle to dataList (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns dataList contents as cell array
%        contents{get(hObject,'Value')} returns selected item from dataList
    set(handles.deleteDataMessage, 'String', '');
    set(handles.deleteAlgorithmMessage, 'String', '');

% --- Executes during object creation, after setting all properties.
function dataList_CreateFcn(hObject, eventdata, handles)
% hObject    handle to dataList (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in deleteData.
function deleteData_Callback(hObject, eventdata, handles)
% hObject    handle to deleteData (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

    set(handles.deleteDataMessage, 'String', '');
    set(handles.deleteAlgorithmMessage, 'String', '');

    [r c] = size(handles.config.dataList);
    if r > 1
        % Delete the selected data set from config
        dataId = get(handles.dataList, 'Value');
        toBeDeleted = handles.config.dataList(dataId);
        handles.config.dataList(dataId) = [];
        handles.config.dataName(dataId) = [];
        handles.config.dataFrequency(dataId) = [];

        % Update data list
        if dataId == r
            set(handles.dataList, 'value', r-1);
        end
        set(handles.dataList,'String',handles.config.dataList);
        guidata(hObject, handles);

        % print an updated message for 1 second that something got deleted
        set(handles.deleteDataMessage, 'String', 'Deleted!');
        message = ['Deleted the following data set:' ' ' toBeDeleted];
        deletedMessage(message);

    else
        set(handles.deleteDataMessage, 'String', 'Cannot delete all the data from config');
    end

function algorithmName_Callback(hObject, eventdata, handles)
% hObject    handle to algorithmName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of algorithmName as text
%        str2double(get(hObject,'String')) returns contents of algorithmName as a double

% --- Executes during object creation, after setting all properties.
function algorithmName_CreateFcn(hObject, eventdata, handles)
% hObject    handle to algorithmName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function algorithmFileName_Callback(hObject, eventdata, handles)
% hObject    handle to algorithmFileName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of algorithmFileName as text
%        str2double(get(hObject,'String')) returns contents of algorithmFileName as a double

% --- Executes during object creation, after setting all properties.
function algorithmFileName_CreateFcn(hObject, eventdata, handles)
% hObject    handle to algorithmFileName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function p1_Callback(hObject, eventdata, handles)
% hObject    handle to p1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of p1 as text
%        str2double(get(hObject,'String')) returns contents of p1 as a double

% --- Executes during object creation, after setting all properties.
function p1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to p1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function p2_Callback(hObject, eventdata, handles)
% hObject    handle to p2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of p2 as text
%        str2double(get(hObject,'String')) returns contents of p2 as a double

% --- Executes during object creation, after setting all properties.
function p2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to p2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function p3_Callback(hObject, eventdata, handles)
% hObject    handle to p3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of p3 as text
%        str2double(get(hObject,'String')) returns contents of p3 as a double

% --- Executes during object creation, after setting all properties.
function p3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to p3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function p4_Callback(hObject, eventdata, handles)
% hObject    handle to p4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of p4 as text
%        str2double(get(hObject,'String')) returns contents of p4 as a double

% --- Executes during object creation, after setting all properties.
function p4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to p4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function p5_Callback(hObject, eventdata, handles)
% hObject    handle to p5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of p5 as text
%        str2double(get(hObject,'String')) returns contents of p5 as a double

% --- Executes during object creation, after setting all properties.
function p5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to p5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function p6_Callback(hObject, eventdata, handles)
% hObject    handle to p6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of p6 as text
%        str2double(get(hObject,'String')) returns contents of p6 as a double

% --- Executes during object creation, after setting all properties.
function p6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to p6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function d1_Callback(hObject, eventdata, handles)
% hObject    handle to d1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of d1 as text
%        str2double(get(hObject,'String')) returns contents of d1 as a double

% --- Executes during object creation, after setting all properties.
function d1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to d1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function d2_Callback(hObject, eventdata, handles)
% hObject    handle to d2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of d2 as text
%        str2double(get(hObject,'String')) returns contents of d2 as a double

% --- Executes during object creation, after setting all properties.
function d2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to d2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function d3_Callback(hObject, eventdata, handles)
% hObject    handle to d3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of d3 as text
%        str2double(get(hObject,'String')) returns contents of d3 as a double

% --- Executes during object creation, after setting all properties.
function d3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to d3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function d4_Callback(hObject, eventdata, handles)
% hObject    handle to d4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of d4 as text
%        str2double(get(hObject,'String')) returns contents of d4 as a double

% --- Executes during object creation, after setting all properties.
function d4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to d4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function d5_Callback(hObject, eventdata, handles)
% hObject    handle to d5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of d5 as text
%        str2double(get(hObject,'String')) returns contents of d5 as a double

% --- Executes during object creation, after setting all properties.
function d5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to d5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function d6_Callback(hObject, eventdata, handles)
% hObject    handle to d6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of d6 as text
%        str2double(get(hObject,'String')) returns contents of d6 as a double

% --- Executes during object creation, after setting all properties.
function d6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to d6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on selection change in algorithmList.
function algorithmList_Callback(hObject, eventdata, handles)
% hObject    handle to algorithmList (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns algorithmList contents as cell array
%        contents{get(hObject,'Value')} returns selected item from algorithmList
    set(handles.deleteDataMessage, 'String', '');
    set(handles.deleteAlgorithmMessage, 'String', '');

% --- Executes during object creation, after setting all properties.
function algorithmList_CreateFcn(hObject, eventdata, handles)
% hObject    handle to algorithmList (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in deleteAlgorithm.
function deleteAlgorithm_Callback(hObject, eventdata, handles)
% hObject    handle to deleteAlgorithm (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

    set(handles.deleteDataMessage, 'String', '');
    set(handles.deleteAlgorithmMessage, 'String', '');

    [r c] = size(handles.config.algorithmList);
    if r > 1

        % Delete the selected algorithm from config
        algorithmId = get(handles.algorithmList, 'Value');
        toBeDeleted = handles.config.algorithmList(algorithmId);
        handles.config.algorithmList(algorithmId) = [];
        handles.config.algorithmName(algorithmId) = [];
        handles.config.algorithmParameters(algorithmId,:) = [];
        handles.config.defaultParameters(algorithmId,:) = [];

        % Update data list
        if algorithmId == r
            set(handles.algorithmList, 'value', r-1);
        end
        set(handles.algorithmList,'String',handles.config.algorithmList);
        guidata(hObject, handles);

        % print an updated message for 1 second that something got deleted
        set(handles.deleteAlgorithmMessage, 'String', 'Deleted!');
        message = ['Deleted the following algorithm:' ' ' toBeDeleted];
        deletedMessage(message);
        guidata(hObject, handles);
    else
        set(handles.deleteAlgorithmMessage, 'String', 'Cannot delete all algorithms from config');
    end

% --- Executes on button press in addAlgorithm.
function addAlgorithm_Callback(hObject, eventdata, handles)
% hObject    handle to addAlgorithm (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    set(handles.deleteDataMessage, 'String', '');
    set(handles.deleteAlgorithmMessage, 'String', '');

    [r c] = size(handles.config.algorithmList);
    fileName = get(handles.algorithmFileName, 'string');

    % Check if file exists, else return
    fullPath = strcat('..\Strategy\',fileName, '.m');
    if ~(exist(fullPath) == 2)
        errorMessage('File does not exist. Please create the file before running the tool box to avoid errors. If the file exists, please enter file name without the .m extension to avoid this warning. Algortihm has been added.');
    end

    handles.config.algorithmList(r+1,c) = {get(handles.algorithmName, 'string')};
    handles.config.algorithmName(r+1,c) = {fileName};

    % Construct input vectors before adding them to config
    newParameters = {};
    newDefault = {};

    temp = get(handles.p1,'string');
    if strcmp(temp ,'-') == 0
        newParameters{1} = (temp);
        newDefault{1} = str2double(get(handles.d1,'string'));
    else
        newParameters{1} = [];
        newDefault{1} = [];
    end
    temp = get(handles.p2,'string');
    if strcmp(temp ,'-') == 0
        newParameters{2} = (temp);
        newDefault{2} = str2double(get(handles.d1,'string'));
    else
        newParameters{2} = [];
        newDefault{2} = [];
    end
    temp = get(handles.p3,'string');
    if strcmp(temp ,'-') == 0
        newParameters{3} = (temp);
        newDefault{3} = str2double(get(handles.d1,'string'));
    else
        newParameters{3} = [];
        newDefault{3} = [];
    end
    temp = get(handles.p4,'string');
    if strcmp(temp ,'-') == 0
        newParameters{4} = (temp);
        newDefault{4} = str2double(get(handles.d1,'string'));
    else
        newParameters{4} = [];
        newDefault{4} = [];
    end
    temp = get(handles.p5,'string');
    if strcmp(temp ,'-') == 0
        newParameters{5} = (temp);
        newDefault{5} = str2double(get(handles.d1,'string'));
    else
        newParameters{5} = [];
        newDefault{5} = [];
    end
    temp = get(handles.p6,'string');
    if strcmp(temp ,'-') == 0
        newParameters{6} = (temp);
        newDefault{6} = str2double(get(handles.d1,'string'));
    else
        newParameters{6} = [];
        newDefault{6} = [];
    end

    % Update the parameters in config
    if length(newParameters) > 0
        handles.config.algorithmParameters(r+1,:) = newParameters;
        handles.config.defaultParameters(r+1,:) = newDefault;
    else
        handles.config.algorithmParameters(r+1,:) = {[]};
        handles.config.algorithmParameters(r+1,:) = {[]};
    end

    set(handles.algorithmList,'String',handles.config.algorithmList);

    set(handles.addAlgorithmMessage, 'String', 'Added!');
    pause(1);
    set(handles.addAlgorithmMessage, 'String', '');

    guidata(hObject, handles);

function configFileName_Callback(hObject, eventdata, handles)
% hObject    handle to configFileName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of configFileName as text
%        str2double(get(hObject,'String')) returns contents of configFileName as a double

% --- Executes during object creation, after setting all properties.
function configFileName_CreateFcn(hObject, eventdata, handles)
% hObject    handle to configFileName (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in activeConfigCheck.
function activeConfigCheck_Callback(hObject, eventdata, handles)
% hObject    handle to activeConfigCheck (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of activeConfigCheck

% --- Executes on button press in saveConfig.
function saveConfig_Callback(hObject, eventdata, handles)
% hObject    handle to saveConfig (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

    % Save the new preferences to config
    try

        chosenFileName = (get(handles.configFileName,'string'));
        if strcmp (chosenFileName, 'config')
            errorMessage('File cannot be named "config"! "config" saves the active preferences.');
            return;
        end

        n = handles.config;
        algorithmList = n.algorithmList;
        algorithmName = n.algorithmName;
        algorithmParameters = n.algorithmParameters;
        dataFrequency = n.dataFrequency;
        dataList = n.dataList;
        dataName = n.dataName;
        defaultParameters = n.defaultParameters;

        filePath = strcat('config/',chosenFileName);

        if ~(exist(strcat(filePath,'.mat')) == 2)

            save(filePath, 'algorithmList','algorithmName', 'algorithmParameters', 'dataFrequency','dataList','dataName','defaultParameters');

            % If the user wants to make this the active configuration
            if get(handles.activeConfigCheck, 'Value')
                filePath = strcat('config/','config');
                save(filePath, 'algorithmList','algorithmName', 'algorithmParameters', 'dataFrequency','dataList','dataName','defaultParameters');
            end

            %display saved message
            set(handles.configSave, 'String', 'Saved this configuration!');

        else
            errorMessage('This configuration file name already exists!');
            return;
        end
    catch exception
        errorMessage('Error in naming config file! Please enter a valid file name.');
    end


%   CLASS GUI_About
% =========================================================================
%
% DESCRIPTION
%   class to manage the about window of goGPSz
%
% EXAMPLE
%   ui = GUI_About.getInstance();
%
% FOR A LIST OF CONSTANTs and METHODS use doc Core_UI

%--------------------------------------------------------------------------
%               ___ ___ ___
%     __ _ ___ / __| _ | __|
%    / _` / _ \ (_ |  _|__ \
%    \__, \___/\___|_| |___/
%    |___/                    v 1.0RC1
%
%--------------------------------------------------------------------------
%  Copyright (C) 2021 Geomatics Research & Development srl (GReD)
%  Written by:        Andrea Gatti
%  Contributors:      Andrea Gatti, Giulio Tagliaferro, Eugenio Realini ...
%  A list of all the historical goGPS contributors is in CREDITS.nfo
%--------------------------------------------------------------------------
%
%    This program is free software: you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation, either version 3 of the License, or
%    (at your option) any later version.
%
%    This program is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with this program.  If not, see <http://www.gnu.org/licenses/>.
%
%--------------------------------------------------------------------------
% 01100111 01101111 01000111 01010000 01010011
%--------------------------------------------------------------------------

classdef GUI_About < handle

    properties (Constant, Access = 'protected')
        BG_COLOR = Core_UI.DARK_GREY_BG;
    end

    %% PROPERTIES SINGLETON POINTERS
    % ==================================================================================================================================================
    properties % Utility Pointers to Singletons
        log
        state
    end

    %% PROPERTIES GUI
    % ==================================================================================================================================================
    properties
        w_main      % Handle of the main window
        win         % Handle to this window
    end

    %% PROPERTIES STATUS
    % ==================================================================================================================================================
    properties (GetAccess = private, SetAccess = private)
    end

    %% METHOD CREATOR
    % ==================================================================================================================================================
    methods (Static)
        function this = GUI_About(w_main)
            % GUI_MAIN object creator
            this.init();
            this.openGUI();
            if nargin == 1
                this.w_main = w_main;
            end
        end
    end
    %% METHODS INIT
    % ==================================================================================================================================================
    methods
        function init(this)
            this.log = Core.getLogger();
            this.state = Core.getState();
        end

        function openGUI(this)
            % Main Window ----------------------------------------------------------------------------------------------

            win = figure( 'Name', 'About', ...
                'Visible', 'on', ...
                'DockControls', 'off', ...
                'MenuBar', 'none', ...
                'ToolBar', 'none', ...
                'NumberTitle', 'off', ...
                'Position', [0 0 680 540], ...
                'Resize', 'off');

            this.win = win;

            if isunix && not(ismac())
                win.Position(1) = round((win.Parent.ScreenSize(3) - win.Position(3)) / 2);
                win.Position(2) = round((win.Parent.ScreenSize(4) - win.Position(4)) / 2);
            else
                win.OuterPosition(1) = round((win.Parent.ScreenSize(3) - win.OuterPosition(3)) / 2);
                win.OuterPosition(2) = round((win.Parent.ScreenSize(4) - win.OuterPosition(4)) / 2);
            end

            try
                main_vb = uix.VBox('Parent', win, ...
                    'Padding', 5, ...
                    'BackgroundColor', Core_UI.DARKER_GREY_BG);
            catch
                log = Core.getLogger;
                log.setOutMode(1,[],0); % to plot a Warning I need to disable GUI and enable
                log.addError('Please install GUI Layout Toolbox (https://it.mathworks.com/matlabcentral/fileexchange/47982-gui-layout-toolbox)');
                open('GUI Layout Toolbox 2.3.4.mltbx');
                log.newLine();
                log.addWarning('After installation re-run goGPS');
                close(win);
                return;
            end
            top_bh = uix.HBox('Parent', main_vb);

            logo_GUI_About.BG_COLOR = Core_UI.DARK_GREY_BG;
            left_tbv = uix.VBox('Parent', top_bh, ...
                'BackgroundColor', logo_GUI_About.BG_COLOR, ...
                'Padding', 5);

            % Logo/title box -------------------------------------------------------------------------------------------

            logo_g = uix.Grid('Parent', left_tbv, ...
                'Padding', 5, ...
                'BackgroundColor', logo_GUI_About.BG_COLOR);

            logo_ax = axes( 'Parent', logo_g);
            logo_g.Widths = 64;
            logo_g.Heights = 64;
            [logo, transparency] = Core_UI.getLogo();
            logo(repmat(sum(logo,3) == 0,1,1,3)) = 0;
            logo = logo - 20;
            image(logo_ax, ones(size(logo)), 'AlphaData', transparency);
            logo_ax.XTickLabel = [];
            logo_ax.YTickLabel = [];
            axis off;

            Core_UI.insertEmpty(left_tbv, logo_GUI_About.BG_COLOR);
            left_tbv.Heights = [82 -1];

            % Title Panel -----------------------------------------------------------------------------------------------
            right_tvb = uix.VBox('Parent', top_bh, ...
                'Padding', 5, ...
                'BackgroundColor', logo_GUI_About.BG_COLOR);

            top_bh.Widths = [106 -1];

            title = uix.HBox('Parent', right_tvb, ...
                'BackgroundColor', logo_GUI_About.BG_COLOR);

            txt = this.insertBoldText(title, 'goGPS', 10, Core_UI.LBLUE, 'left');
            txt.BackgroundColor = logo_GUI_About.BG_COLOR;
            title_l = uix.VBox('Parent', title, 'BackgroundColor', GUI_About.BG_COLOR);
            title.Widths = [54 -1];
            Core_UI.insertEmpty(title_l, logo_GUI_About.BG_COLOR)
            txt = this.insertBoldText(title_l, ['- software V' Core.GO_GPS_VERSION], 8, [], 'left');
            txt.BackgroundColor = logo_GUI_About.BG_COLOR;
            title_l.Heights = [2, -1];

            % Disclaimer Panel -----------------------------------------------------------------------------------------------
            Core_UI.insertEmpty(right_tvb, logo_GUI_About.BG_COLOR)
            txt = this.insertText(right_tvb, {['This release is loosely based on the original goGPS software, most of the code has '...
                'been rewritten for better performances, automation, flexibility, but with the primary goal of quasi static processing. ' ...
                'Legacy version can still be found at:'], ...
                'https://github.com/goGPS-Project/goGPS_MATLAB/tree/legacy'}, 7, [], 'left');
            txt.BackgroundColor = logo_GUI_About.BG_COLOR;

            right_tvb.Heights = [20 3 -1];

            credits_bh = uix.HBox('Parent', main_vb, ...
                'Padding', 5, ...
                'BackgroundColor', GUI_About.BG_COLOR);
            credits_legacy = uix.VBox('Parent', credits_bh, ...
                'BackgroundColor', GUI_About.BG_COLOR);
            credits_new = uix.VBox('Parent', credits_bh, ...
                'BackgroundColor', GUI_About.BG_COLOR);

            % Old Credits -----------------------------------------------------------------------------------------------

            this.insertBoldText(credits_legacy, 'Legacy version', 9);
            bar_cont = uix.HBox('Parent', credits_legacy, ...
                'BackgroundColor', GUI_About.BG_COLOR);

            Core_UI.insertEmpty(bar_cont, GUI_About.BG_COLOR)
            Core_UI.insertHBarDark(bar_cont);
            Core_UI.insertEmpty(bar_cont, GUI_About.BG_COLOR)
            bar_cont.Widths = [-1 220 -1];

            this.insertBoldText(credits_legacy, 'Developers of the original core', 8);
            this.insertText(credits_legacy, {'Mirko Reguzzoni', 'Eugenio Realini'}, 7);
            Core_UI.insertEmpty(credits_legacy, GUI_About.BG_COLOR)

            this.insertBoldText(credits_legacy, 'Founding fathers', 8);
            this.insertText(credits_legacy, {'Alessio Dominioni', ...
                'Roberto Terruzzi', ...
                'Marco Colla', ...
                'Marcello Palmulli', ...
                'Michele Tettamanti'}, 7);

            Core_UI.insertEmpty(credits_legacy, GUI_About.BG_COLOR)
            this.insertBoldText(credits_legacy, 'Contributors (in temporal order)', 8);
            this.insertText(credits_legacy, {'Sara Lucca', ...
                'Lisa Pertusini', ...
                'Daniele Sampietro', ...
                'Luana Valentini', ...
                'Alemu Befkadu Nigussie', ...
                'Ivan Reguzzoni', ...
                'Stefano Caldera', ...
                'Damiano Triglione', ...
                'Giuliano Sirioni', ...
                'Antonio Herrera Olmo', ...
                'Andrea Gatti', ...
                'Hendy F. Suhandri', ...
                'Andrea Nardo', ...
                'Daisuke Yoshida', ...
                'Marco Negretti', ...
                'Yuya Iwaki', ...
                'Louis Osei-Poku', ...
                'Paiyuan Zhou'}, 7);

            credits_legacy.Heights = [22 5 18 14*2 5 18 14*5 5 18 14*17];

            % New Credits -----------------------------------------------------------------------------------------------

            this.insertBoldText(credits_new, 'Object oriented new version', 9);
            bar_cont = uix.HBox('Parent', credits_new, ...
                'BackgroundColor', GUI_About.BG_COLOR);

            Core_UI.insertEmpty(bar_cont, GUI_About.BG_COLOR)
            Core_UI.insertHBarDark(bar_cont);
            Core_UI.insertEmpty(bar_cont, GUI_About.BG_COLOR)
            bar_cont.Widths = [-1 220 -1];

            this.insertBoldText(credits_new, 'Developers of the new goGPS core', 8);
            this.insertText(credits_new, {'Andrea Gatti', 'Giulio Tagliaferro'}, 7);
            Core_UI.insertEmpty(credits_new, GUI_About.BG_COLOR)

            this.insertBoldText(credits_new, 'Other Contributors', 8);
            this.insertText(credits_new, {'Eugenio Realini', ...
                'Stefano Caldera', ...
                'Lisa Pertusini', ...
                'Andreas Krietemeyer', ...
                'Alice Bonfiglio', ...
                'Stefano Barindelli',...
                'Alessandra Mascitelli', ...
                }, 7);
            Core_UI.insertEmpty(credits_new, GUI_About.BG_COLOR)

            % IMPORTANT NOTE:
            % If you are a contributor and your name is not in this list feel free to add your name

            this.insertBoldText(credits_new, 'Acknoledgments', 8);
            this.insertText(credits_new, {'This release is funded by', 'GReD srl (www.g-red.eu)'}, 7);
            txt = this.insertText(credits_new, {'I dedicate my work on this software to my father, Tiziano Gatti, ', 'who taught me, among countless things, the importance of putting passion in everything you choose to do. I will never forget you,'}, 7, [], 'right'); txt.FontAngle = 'italic';
            txt = this.insertText(credits_new, {'Andrea Gatti'}, 7, [20 183 242]/255, 'right'); txt.FontAngle = 'italic';

            credits_new.Heights = [22 5 18 14*2 5 18 14*7 5 18 -1 14*3 28];

            % Manage dimension -------------------------------------------------------------------------------------------

            main_vb.Heights = [84 -1];

            %session_height = sum(left_bv.Children(2).Children(1).Heights);

            this.win.Visible = 'on';
            %uiwait(this.win);
        end
    end
    %% METHODS INSERT
    % ==================================================================================================================================================
    methods (Static)
        function txt = insertBoldText(parent, title, font_size, color, alignment)
            if nargin < 4 || isempty(color)
                color = Core_UI.WHITE;
            end
            if nargin < 5 || isempty(alignment)
                alignment = 'center';
            end
            txt = uicontrol('Parent', parent, ...
                'Style', 'Text', ...
                'String', title, ...
                'ForegroundColor', color, ...
                'HorizontalAlignment', alignment, ...
                'FontSize', Core_UI.getFontSize(font_size), ...
                'FontWeight', 'bold', ...
                'BackgroundColor', GUI_About.BG_COLOR);
        end

        function txt = insertText(parent, title, font_size, color, alignment)
            if nargin < 4 || isempty(color)
                color = Core_UI.WHITE;
            end
            if nargin < 5 || isempty(alignment)
                alignment = 'center';
            end
            txt = uicontrol('Parent', parent, ...
                'Style', 'Text', ...
                'String', title, ...
                'ForegroundColor', color, ...
                'HorizontalAlignment', alignment, ...
                'FontSize', Core_UI.getFontSize(font_size), ...
                'BackgroundColor', GUI_About.BG_COLOR);
        end

    end
    %% METHODS getters
    % ==================================================================================================================================================
    methods
    end

    %% METHODS EVENTS
    % ==================================================================================================================================================
    methods (Access = public)
    end
end


function complainif_toomanyargs(fnargin,limit,callfun)

if nargin<3
    callfun = mfilename;
end

if fnargin>limit
   error('%s: Too many input arguments.',upper(callfun));
end


function tf=isNonFailure(obj)
% return whether this test was a non-failure
%
% tf=isSuccess(obj)
%
% Input:
%   obj                     MoxUnitPassedTestOutcome object
%
% Output:
%   tf                      set to true, because a passed test is not a
%                           failure
%
% See also: @MoxUnitTestOutcome

    tf=true;


function progFigure = progressdlg(varargin)
%progressdlg show/update progress dialog
%
% progressdlg creates or updates an existing progress dialog that reports on the
% progress of a task including the estimated time remaining as well as a button to
% cancel the task. It does not use drawnow in order to improve performance when using
% one or several other figures (drawnow refreshes all graphics objects in all figures).
%
% Syntax:
%   progressdlg                 creates default progress dialog
%
%   progressdlg('message');     creates default progress dialog with custom message
%
%   progressdlg(n);             creates default progress dialog with initial value n
%                               or updates existing progress dialog to value n
%
%   progressdlg(n,'message');   creates default progress dialog with message and value n
%                               or updates existing progress dialog to value n and message
%
%   progressdlg('PropertyName',PropertyValue,...);  creates or updates progress dialog with
%                                                   properties PropertyName/PropertyValue
%
%   handle = progressdlg(...);  returns the handle to the progress dialog
%                               handle is empty if user aborted by pressing cancel
%
%  PropertyName  | Description                                | Type           | Default
% ---------------|--------------------------------------------|----------------|------------------
%  Cancel        | Displays a cancel button to abort          | 'on,off'       | 'off'
%  Indeterminate | Sets the ProgressBar to indeterminate      | 'on,off'       | 'off'
%  Min           | Minimum value of ProgressBar               | double         | 0
%  Max           | Minimum value of ProgressBar               | double         | 100
%  Parent        | Parent Figure for Positioning              | figure_handle  | []
%  Position      | Override position of dialog                | [int x, int y] | []
%  ShowTime      | Displays an estimate of the remaining time | 'on/off'       | 'on'
%  Size          | Factor for dialog size (width=400px)       | double         | 1
%  String        | Descriptive text above ProgressBar         | char           | 'Progress'
%  Title         | Title of the dialog                        | char           | 'Progress'
%  Value         | Current Value of ProgressBar               | double         | 0
%  WindowStyle   | Normal or modal window behavior            | 'normal/modal' | 'modal'
%
%
% Notes:
%   1) Does not use drawnow to refresh the progress bar in order to improve performance,
%      especially when using one or several additional figures with many graphics objects.
%   2) Performance is slightly decreased when using the remaining time estimation and/or
%      cancel button
%
% Examples:
%   progressdlg('Calculating magic square');
%   for n=1:100
%       magic(1000);
%       progressdlg(n);
%   end
%
%   progressdlg('Title','Progress Dialog','String','Calculating magic squares','Min',0,'Max',1000,'Value',0);
%   for n=1:1000
%       magic(400);
%       progressdlg(n);
%   end
%
%   progressdlg('Title','Progress Dialog','String','Calculating magic squares','Position',[100 100],'WindowStyle','normal');
%   for n=1:10
%       magic(10000);
%       progressdlg(n*10,['Calculating magic square - Round: ' num2str(n)]);
%   end
%
%   h = progressdlg('Title','Progress','String','Calculating magic square','ShowTime','on','Cancel','on','Size',1.5);
%   for n=1:100
%       magic(4000);
%       h = progressdlg(n);
%       if isempty(h)
%           break;
%       end
%   end
%
% Warning:
%   This code heavily relies on undocumented and unsupported Matlab
%   functionality. It works on Matlab 7+, but use at your own risk!
%
% Bugs and suggestions:
%   Please send to Felix Ruhnow (felix.ruhnow at tu-dresden dot de)
%
% See also: WAITBAR, TIMEBAR, PROGRESSBAR (on the File Exchange)
%
% Adapted from:
% Daniel Claxton's WORKBAR
%
% Inspired by:
% Yair M. Altman's STATUSBAR
%
% Release history:
%    1.0  2013-06-10: initial version
%
% License to use and modify this code is granted freely to all interested, as long as the original author is
% referenced and attributed as such. The original author maintains the right to be solely associated with this work.
%
% Programmed and Copyright by Felix Ruhnow: felix.ruhnow(at)tu-dresden.de

    % keep variables for next call of progressdlg
    persistent p min max cancel progHandles showtime starttime;
    message = 'Progress';
    value = 0;
    text = [];
    est_text = 'Estimated time remaining: ';

    % check input arguments
    if nargin < 1
        % progressdlg; creates default progress dialog
        progHandles = [];

    elseif nargin == 1
        if ischar(varargin{1})
            % progressdlg('close'); closes progress dialog
            if strcmp(varargin{1},'close')
                if isfield(progHandles,'figure') && ishandle(progHandles.figure)
                    close(progHandles.figure);
                end
                progHandles = [];
                progFigure =[];
                return
            else
                % progressdlg('message'); creates default progress dialog with custom message
                message = varargin{1};
                progHandles = [];
            end

        elseif isnumeric(varargin{1})
            % progressdlg(n); creates default progress dialog with initial value n
            %                 or updates existing progress dialog to value n
            value = varargin{1};
        end
        varargin(:) = [];

    elseif nargin == 2 && isnumeric(varargin{1})
        % progressdlg(n,'message');
        if isempty(progHandles)
            % creates default progress dialog with message and value n
            value = varargin{1};
            message = varargin{2};
            varargin(:) = [];
        else
            % updates existing progress dialog to value n and message
            value = varargin{1};
            text = varargin{2};
        end

    elseif isfield(progHandles,'figure') && ishandle(progHandles.figure)
        % progressdlg('PropertyName',PropertyValue,...); updates progress dialog
        parse(p,varargin{1:end});
        value = p.Results.value;
        text = p.Results.string;

    else
        % progressdlg('PropertyName',PropertyValue,...); creates progress dialog
        progHandles = [];
    end

    if isempty(progHandles)
        % if handles are empty create new dialog
        cancel = 0;
        showtime = 0;

        % get initial input arguments
        p = checkInput(value,message);
        parse(p,varargin{1:end});
        prog = p.Results;
        min = prog.min;
        max = prog.max;

        % define height w/o estimated time remaining or cancel button
        height = 90;
        if strcmp(prog.showtime,'on') && ~strcmp(prog.indeterminate,'on')
            showtime = 1;
            height = height + 20;
        end
        if strcmp(prog.cancel,'on')
            cancel = 1;
            height = height + 30;
        end

        % get position of progress dialog (middle of screen, if not otherwise)
        if isempty(prog.position)
            if isempty(prog.parent)
                screen = get(0,'ScreenSize');
                pos = ceil([(screen(3)-400*prog.size)/2 (screen(4)-height*prog.size)/2 400 height]);
            else
                units = get(prog.parent,'Units');
                set(prog.parent,'Units','Pixel');
                pos_parent = get(prog.parent,'Position');
                set(prog.parent,'Units',units);
                pos = ceil([pos_parent(1)+(pos_parent(3)-400*prog.size)/2 pos_parent(2)+(pos_parent(4)-height*prog.size)/2 400 height]);
            end
        else
           pos = ceil([prog.position 400 height]);
        end

        % create dialog dialog
        progFigure = figure('Menubar','none','Numbertitle','off','Resize','off','Tag','ProgressDlg',...
                            'Units','pixels','Visible','off','DockControls','off','IntegerHandle','off',...
                            'Name',prog.title,'Position',pos,'WindowStyle','normal');%prog.windowstyle);

        % get background color of figure to adjust background of its children
        uiColor = get(progFigure,'Color');
        jColor = java.awt.Color(uiColor(1),uiColor(2),uiColor(3));

        if ispc
            barsize = 20;
            buttonsize = 25;
            buttonfont = 11;
        else
            barsize = 40;
            buttonsize = 30;
            buttonfont = 14;
        end

        % create descriptive text from PropertyName 'String', use java for updating dialog
        text1 = javaObjectEDT('javax.swing.JTextArea');
        [jText(1),cText(1)] = javacomponent(text1,[20 height-30 300 20],progFigure);
        set(jText(1),'Background',jColor,'Text',prog.string,...
                     'Font',java.awt.Font('Helvetica',java.awt.Font.PLAIN,14*prog.size));
        set(cText(1),'units','normalized');

        % create text for estimated remaining time if 'ShowTime' is 'on', use java for updating dialog
        if showtime
            text2 = javaObjectEDT('javax.swing.JTextArea');
            [jText(2),cText(2)] = javacomponent(text2,[20 height-90 300 20],progFigure);
            set(jText(2),'Background',jColor,'Text',est_text,...
                         'Font',java.awt.Font('Helvetica',java.awt.Font.PLAIN,14*prog.size));
            set(cText(2),'Units','Normalized');

        end

        % create cancel button if 'Cancel' is 'on', Click on button closes the dialog
        if cancel
            button = uicontrol(progFigure,'Style','pushbutton','Position',[120 10 160 buttonsize],...
                                          'String','cancel','Callback','close','FontSize',buttonfont*prog.size);
            set(button,'Units','Normalized');
        end

        % create ProgressBar with java JProgressBar class
        jProgressBar = javaObjectEDT('javax.swing.JProgressBar');
        jProgressBar.setStringPainted(true);
        set(jProgressBar,'Background',uiColor,'Minimum',prog.min,'Maximum',prog.max,'Value',prog.value);
        if strcmp(prog.indeterminate,'on')
            jProgressBar.setIndeterminate(true);
            showtime = 0;
        end
        [hProgressBar,cProgressBar] = javacomponent(jProgressBar,[20 height-65 360 barsize],progFigure);
        set(cProgressBar,'units','normalized','Tag','ProgressBar');

        % resize progress dialog according to PropertyName 'Size'
        set(progFigure,'Position',[pos(1:2) pos(3:4)*prog.size],'Visible','on');

        % save handles of the created objects
        progHandles.figure = progFigure;
        progHandles.progress = hProgressBar;
        progHandles.text = jText;

        % update dialog (only once!)
        drawnow;

        %save start time for progress
        starttime = clock;
    else
        % if handles are present update progress dialog
        progFigure = progHandles.figure;

        % update ProgressBar
        set(progHandles.progress,'Value',value);

        % update descriptive text if required
        if ~isempty(text)
            set(progHandles.text(1),'Text',text);
        end

        % calculate and update remaining time if required
        if showtime
            if value == min
                starttime=clock;
            else
                runtime = etime(clock,starttime);
                timeleft = runtime*(max-min)/(value-min) - runtime;
                timeleftstr = sec2timestr(timeleft);
                set(progHandles.text(2),'Text',[est_text timeleftstr]);
            end
        end

        % check event queue for callback of the 'cancel' button
        if cancel
            pause(10^-12); %flush event queue
            if ~ishandle(progHandles.figure)
                % if figure was delete via 'close' callback of 'cancel' button
                progHandles = [];
                progFigure = [];
                return;   % return empty handle
            end
        end
    end

    if value==max
        % if 'Maximum' value reached close and reset progress dialog
        close(progHandles.figure);
        progHandles =[];
        progFigure = [];
    end

%% Define input parameters and their default values
function p = checkInput(value,message)
    p = inputParser;
    states = {'on','off'};
    style = {'normal','modal'};
    addParamValue(p,'title','Progress');
    addParamValue(p,'size',1);
    addParamValue(p,'value',value);
    addParamValue(p,'min',0);
    addParamValue(p,'max',100);
    addParamValue(p,'position',[],@isnumeric);
    addParamValue(p,'string',message);
    addParamValue(p,'parent',[],@ishandle);
    addParamValue(p,'cancel','off',@(x) any(validatestring(x,states)))
    addParamValue(p,'showtime','on',@(x) any(validatestring(x,states)))
    addParamValue(p,'indeterminate','off',@(x) any(validatestring(x,states)))
    addParamValue(p,'windowstyle','modal',@(x) any(validatestring(x,style)))

%% Convert seconds to hh:mm:ss
function timestr = sec2timestr(sec)
    h = floor(sec/3600); % Hours
    sec = sec - h*3600;
    m = floor(sec/60); % Minutes
    sec = sec - m*60;
    s = floor(sec); % Seconds
    timestr = sprintf('%02d:%02d:%02d',h,m,s);


dirs = {'potentials/Tables', ...
	'CPDs/@discrete_CPD', ...
      'inference/static/@jtree_sparse_inf_engine', ...
      'inference/static/@gibbs_sampling_inf_engine/private'};

BNT_HOME = '/home/ai2/murphyk/matlab/FullBNT'; % edit this
%global BNT_HOME

for d=1:length(dirs)
  f = fullfile(BNT_HOME, 'BNT', dirs{d});
  fprintf('removing Cmex files from %s\n', f);
  cd(f)
  delete *.mex*
  delete *.dll
  delete *.obj
  delete *.o
end


function varargout = struct2single(varargin)

% This function is a backward compatibility wrapper. It allows existing
% MATLAB scripts that do not use the new FieldTrip ft_xxx function naming
% scheme to work with recent versions of the FieldTrip toolbox.
%
% Please look in ft_xxx for the help of the function that you are looking
% for, where xxx is the name of the function that you were looking for.

% Copyright (C) 2009, Robert Oostenveld

prefix    = 'ft_';
funname   = mfilename;
warning([upper(mfilename) ' is only a compatibility wrapper, which will soon be removed. Please instead call ' upper(prefix) upper(funname) '.']);
funhandle = str2func([prefix funname]);
[varargout{1:nargout}] = funhandle(varargin{:});


function hObj = findobj2(h, propname, propvalue, options)

% Find graphic object handle given the parent (or grandparent, etc) handle
% and property name/value pair

if ~exist('options','var')
    options = '';
end

hObj = [];
hc = get(h, 'children');
for ii = 1:length(hc)
    try
        if eval( sprintf('strcmp(get(hc(ii), ''%s''), ''%s'')', propname, propvalue) )
            hObj = hc(ii);
            return;
        elseif ~optionExist(options, 'flat')
            hObj = findobj2(hc(ii), propname, propvalue);
            if ~isempty(hObj)
                return;
            end
        end
    catch
        continue
    end
end


function [meta] = getmeta(db,index)
 meta = db.enteries(index);
end


%TestSuiteTest Unit tests for TestSuite class

classdef TestRunLoggerTest < TestCaseInDir

   methods
      function self = TestRunLoggerTest(name)
         self = self@TestCaseInDir(name, ...
             fullfile(fileparts(which(mfilename)), 'helper_classes'));
      end

      function testTwoPassingTests(self)
         logger = TestRunLogger;
         suite = TestSuite('TwoPassingTests');
         suite.run(logger);

         assertEqual(logger.Log, ...
             {'TestRunStarted', ...
             'TestComponentStarted', ...
             'TestComponentStarted', 'TestComponentFinished', ...
             'TestComponentStarted', 'TestComponentFinished', ...
             'TestComponentFinished', ...
             'TestRunFinished'});

         assertEqual(logger.NumTestCases, 2);
         assertEqual(logger.NumFailures, 0);
         assertEqual(logger.NumErrors, 0);
         assertTrue(isempty(logger.Faults));
      end

      function testFailingTestCase(self)
         logger = TestRunLogger;
         suite = TestSuite('FailingTestCase');
         suite.run(logger);

         assertEqual(logger.Log, ...
             {'TestRunStarted', ...
             'TestComponentStarted', ...
             'TestComponentStarted', 'TestCaseFailure', 'TestComponentFinished', ...
             'TestComponentFinished', ...
             'TestRunFinished'});

         assertEqual(logger.NumTestCases, 1);
         assertEqual(logger.NumFailures, 1);
         assertEqual(logger.NumErrors, 0);
         assertEqual(numel(logger.Faults), 1);
         assertEqual(logger.Faults(1).Type, 'failure');
      end

   end

end


function anonTextureS = defineAnonTexture()
%
% function anonTextureS = defineAnonCerroptions()
%
% Defines the anonymous "texture" data structure. The fields containing PHI have
% been left out by default. In order to leave out additional fields, remove
% them from the list below.
%
% The following three operations are allowed per field of the input data structure:
% 1. Keep the value as is: listed as 'keep' in the list below.
% 2. Allow only the specific values: permitted values listed within a cell array.
%    If no match is found, a default anonymous string will be inserted.
% 3. Insert dummy date: listed as 'date' in the list below. Date will be
%    replaced by a dummy value of 11/11/1111.
%
% APA, 1/11/2018

anonTextureS = struct( ...
    'category',  'keep', ...
    'description',  'keep', ...
    'patchSize',  'keep', ...
    'patchUnit',  'keep', ...
    'paramS',  'keep', ...
    'assocScanUID',  'keep', ...
    'assocStructUID',  'keep', ...
    'textureUID',  'keep' ...
           );


function c = getNamespace()
global namespace

% fprintf('In getNamespace:\n');

if length(namespace)==1
    c = namespace(1).name;
    return;
end

c = '';
s = dbstack();
if isempty(s)
    return;
end

for jj = length(s):-1:1
%     fprintf('  s(%d).file = %s:\n', jj, s(jj).file);
%     fprintf('  s(%d).name = %s:\n', jj, s(jj).name);

    try
        pname = filesepStandard(which(s(jj).file));
    catch
        continue
    end
    for ii = 1:length(namespace)
%         fprintf('  namespace = [%s, %s]\n', namespace(ii).name, namespace(ii).pname);
        if isRootpathsSame(pname, namespace(ii).pname)
            c = namespace(ii).name;
            return;
        end
    end
%     fprintf('\n');
end

% ---------------------------------------------------------
function b = isRootpathsSame(p1, p2)
b = false;
p1 = filesepStandard(p1);
p2 = filesepStandard(p2);
k = findstr(p1, p2);
if isempty(k)
    return;
end
b = true;


%% The Class EBSDhex
%
%%
%


function item = subsasgn(item, subs, varargin)

% function item = subsasgn(item, subs, varargin)
% This function implements subsasgn for all classes derived from cfg_item.
% It relies on the capability of each class constructor to re-classify a
% struct object after a new value has been assigned to its underlying
% struct (This capability has to be implemented in the derived class).
% The structure of a configuration tree does not permit any arrays of
% cfg_item objects. Therefore, the only subscript reference and
% assignment within an cfg_item is a dot assignment to fields of this
% cfg_item.
% Subscript references we have to deal with are:
% one level
% item.(field)   - i.e. struct('type',{'.'} ,'subs',{field})
%
% to be dealt with elsewhere
% item.(field){fidx}
%
% In a future version, '()' and '{}' subscripts may be supported to
% access val fields of a cfg_item tree as if they were part of a
% harvested job. For cfg_branch objects (where dot assignments are used
% for val fields in their job tree) it is mandatory to index the job as a
% struct array to access harvested fields.
% This function is identical for all classes derived from cfg_item. A
% copy of it must be present in each derived class to be able to access
% derived fields.
%
% This code is part of a batch job configuration system for MATLAB. See
%      help matlabbatch
% for a general overview.
%_______________________________________________________________________
% Copyright (C) 2007 Freiburg Brain Imaging

% Volkmar Glauche
% $Id: subsasgn.m 5678 2013-10-11 14:58:04Z volkmar $

rev = '$Rev: 5678 $'; %#ok

persistent local_mysubs_fields;
persistent par_class;
persistent par_fields;
if ~iscell(local_mysubs_fields)
    local_mysubs_fields = mysubs_fields;
    citem = class(item);
    switch citem
        case 'cfg_exbranch',
            par_class = 'cfg_branch';
            pf1 = subs_fields(item.cfg_branch);
            pf2 = subs_fields(cfg_item);
            par_fields = [pf1(:); pf2(:)]';
        case 'cfg_item',
            par_class = '';
            par_fields = {};
        otherwise
            par_class = 'cfg_item';
            par_fields = subs_fields(item.cfg_item);
    end;
end
if numel(item) ~= 1
    cfg_message('matlabbatch:subsasgn', ...
          'Arrays of cfg_item objects not supported.');
end;

switch subs(1).type,
    case {'.'},
        if numel(item) == 1 && nargin == 3
            if numel(subs) > 1
                % Only part of field value(s) assigned. Get old field value(s),
                % assign values to it.
                if any(strcmp(subs(1).subs,par_fields))
                    val0 = item.(par_class).(subs(1).subs);
                else
                    val0 = item.(subs(1).subs);
                end
                val1 = cfg_callbuiltin('subsasgn',val0,subs(2:end),varargin{1});
            else
                % Field values to assign
                val1 = varargin{1};
            end
            [ok, val] = subsasgn_check(item,subs,val1);
            if ok,
                switch subs(1).subs
                    case par_fields,
                        item.(par_class).(subs(1).subs) = val;
                    case local_mysubs_fields,
                        item.(subs(1).subs) = val;
                    otherwise
                        cfg_message('matlabbatch:subsasgn', ...
                                    ['Reference to unknown field ''%s''.\n' ...
                                     'To assign to a field in the job structure, use a reference like ' ...
                                     '''(x).%s''.'], subs(1).subs, subs(1).subs);
                end;
            end;
        else
            cfg_message('matlabbatch:subsasgn', ...
                        ['Array assignments not supported for fields of cfg_item objects.\n' ...
                         'To assign to a field in the job structure, use a reference like ' ...
                         '''(x).%s''.'], subs(1).subs);

        end;
    case {'()','{}'},
        cfg_message('matlabbatch:subsasgn', ...
                    'Subscript type ''%s'' reserved for future use.', subs(1).type);
    otherwise
        cfg_message('matlabbatch:subsasgn', ...
                    'Unknown subsref type: ''%s''. This should not happen.', subs(1).type);
end;
return;


%PLOT Mapping overload (generates error)


function [sts, val] = subsasgn_check(item,subs,val)

% function [sts, val] = subsasgn_check(item,subs,val)
% Check whether type of val conforms to configuration tree specification.
%
% This code is part of a batch job configuration system for MATLAB. See
%      help matlabbatch
% for a general overview.
%_______________________________________________________________________
% Copyright (C) 2007 Freiburg Brain Imaging

% Volkmar Glauche
% $Id: subsasgn_check.m 2512 2008-12-01 13:21:29Z volkmar $

rev = '$Rev: 2512 $'; %#ok

sts = true;

% check, whether arguments for 'val' are cfg_items
switch subs(1).subs
    case {'val'}
        sts = ~cfg_get_defaults('cfg_item.checkval') || subsasgn_check_valcfg(subs,val,[0 Inf]);
end;


function varargout = lvd_EditEnginesGUI(varargin)
% LVD_EDITENGINESGUI MATLAB code for lvd_EditEnginesGUI.fig
%      LVD_EDITENGINESGUI, by itself, creates a new LVD_EDITENGINESGUI or raises the existing
%      singleton*.
%
%      H = LVD_EDITENGINESGUI returns the handle to a new LVD_EDITENGINESGUI or the handle to
%      the existing singleton*.
%
%      LVD_EDITENGINESGUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in LVD_EDITENGINESGUI.M with the given input arguments.
%
%      LVD_EDITENGINESGUI('Property','Value',...) creates a new LVD_EDITENGINESGUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before lvd_EditEnginesGUI_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to lvd_EditEnginesGUI_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help lvd_EditEnginesGUI

% Last Modified by GUIDE v2.5 03-Dec-2018 17:11:04

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @lvd_EditEnginesGUI_OpeningFcn, ...
                   'gui_OutputFcn',  @lvd_EditEnginesGUI_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before lvd_EditEnginesGUI is made visible.
function lvd_EditEnginesGUI_OpeningFcn(hObject, eventdata, handles, varargin)
    % This function has no output args, see OutputFcn.
    % hObject    handle to figure
    % eventdata  reserved - to be defined in a future version of MATLAB
    % handles    structure with handles and user data (see GUIDATA)
    % varargin   command line arguments to lvd_EditEnginesGUI (see VARARGIN)

    % Choose default command line output for lvd_EditEnginesGUI
    handles.output = hObject;

    lvdData = varargin{1};
    setappdata(hObject,'lvdData',lvdData);

    populateGUI(handles, lvdData);

    % Update handles structure
    guidata(hObject, handles);

    % UIWAIT makes lvd_EditEnginesGUI wait for user response (see UIRESUME)
    uiwait(handles.lvd_EditEnginesGUI);

function populateGUI(handles, lvdData)
    set(handles.enginesListBox,'String',lvdData.launchVehicle.getEnginesListBoxStr());

    numEngines = length(get(handles.enginesListBox,'String'));
    if(numEngines <= 1)
        handles.removeEngineButton.Enable = 'off';
    end

% --- Outputs from this function are returned to the command line.
function varargout = lvd_EditEnginesGUI_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
    if(isempty(handles))
        varargout{1} = [];
    else
        close(handles.lvd_EditEnginesGUI);
    end

% --- Executes on button press in closeButton.
function closeButton_Callback(hObject, eventdata, handles)
% hObject    handle to closeButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    uiresume(handles.lvd_EditEnginesGUI);

% --- Executes on selection change in enginesListBox.
function enginesListBox_Callback(hObject, eventdata, handles)
% hObject    handle to enginesListBox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns enginesListBox contents as cell array
%        contents{get(hObject,'Value')} returns selected item from enginesListBox
    if(strcmpi(get(handles.lvd_EditEnginesGUI,'SelectionType'),'open'))
        lvdData = getappdata(handles.lvd_EditEnginesGUI,'lvdData');
        lv = lvdData.launchVehicle;

        selEngine = get(handles.enginesListBox,'Value');
        engine = lv.getEngineForInd(selEngine);
        stageState = getStageStateForEngine(engine, lvdData);
        oldEngineState = stageState.getStateForEngine(engine);
        stageState.removeEngineStateForEngine(engine);

        lvd_EditEngineGUI(engine);

        stageState = getStageStateForEngine(engine, lvdData);
        newEngineState = LaunchVehicleEngineState(stageState);
        newEngineState.engine = engine;

        if(not(isempty(oldEngineState)))
            newEngineState.active = oldEngineState.active;
        end
        stageState.addEngineState(newEngineState);

        set(handles.enginesListBox,'String',lvdData.launchVehicle.getEnginesListBoxStr());
    end

function stageState = getStageStateForEngine(engine, lvdData)
        stage = engine.stage;
        stageStates = lvdData.initStateModel.stageStates;
        stageStateInd = find([stageStates.stage] == stage,1,'first');
        stageState = stageStates(stageStateInd);

% --- Executes during object creation, after setting all properties.
function enginesListBox_CreateFcn(hObject, eventdata, handles)
% hObject    handle to enginesListBox (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in addEngineButton.
function addEngineButton_Callback(hObject, eventdata, handles)
% hObject    handle to addEngineButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    lvdData = getappdata(handles.lvd_EditEnginesGUI,'lvdData');

    initStage = lvdData.launchVehicle.getStageForInd(1);

    engine = LaunchVehicleEngine(initStage);
    useEngine = lvd_EditEngineGUI(engine);

    if(useEngine)
%         engine.stage.addEngine(engine);

        stageStates = lvdData.initStateModel.stageStates;
        stageStateInd = find([stageStates.stage] == engine.stage,1,'first');
        stageState = stageStates(stageStateInd);

        newEngineState = LaunchVehicleEngineState(stageState);
        newEngineState.engine = engine;
        stageState.addEngineState(newEngineState);

        set(handles.enginesListBox,'String',lvdData.launchVehicle.getEnginesListBoxStr());

        handles.removeEngineButton.Enable = 'on';
    end

% --- Executes on button press in removeEngineButton.
function removeEngineButton_Callback(hObject, eventdata, handles)
% hObject    handle to removeEngineButton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    lvdData = getappdata(handles.lvd_EditEnginesGUI,'lvdData');
    lv = lvdData.launchVehicle;

    selEngine = get(handles.enginesListBox,'Value');
    engine = lv.getEngineForInd(selEngine);

    tf = engine.isInUse();

    if(tf == false)
        stage = engine.stage;

        lv.removeAllEngineToTanksConnsWithEngine(engine);

        stageStates = lvdData.initStateModel.stageStates;
        stageStateInd = find([stageStates.stage] == stage,1,'first');
        stageState = stageStates(stageStateInd);

        stageState.removeEngineStateForEngine(engine);

        stage.removeEngine(engine);

        listBoxStr = lvdData.launchVehicle.getEnginesListBoxStr();
        set(handles.enginesListBox,'String',listBoxStr);

        numEngines = length(listBoxStr);
        if(selEngine > numEngines)
            set(handles.enginesListBox,'Value',numEngines);
        end

        if(numEngines <= 1)
            handles.removeEngineButton.Enable = 'off';
        end
    else
        warndlg(sprintf('Could not delete the engine "%s" because it is in use as part of an event termination condition, event action, objective function, or constraint.  Remove the engine dependencies before attempting to delete the engine.', engine.name),'Cannot Delete Engine','modal');
    end

% --------------------------------------------------------------------
function copyEngineMenu_Callback(hObject, eventdata, handles)
% hObject    handle to copyEngineMenu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
    lvdData = getappdata(handles.lvd_EditEnginesGUI,'lvdData');
    lv = lvdData.launchVehicle;

    selEngine = get(handles.enginesListBox,'Value');
    engine = lv.getEngineForInd(selEngine);

    newEngine = engine.copy();
    initStage = newEngine.stage;

	newEngine.stage.addEngine(newEngine);

    stageStates = lvdData.initStateModel.stageStates;
    stageStateInd = find([stageStates.stage] == initStage,1,'first');
    stageState = stageStates(stageStateInd);

    newEngineState = LaunchVehicleEngineState(stageState);
    newEngineState.engine = newEngine;
    stageState.addEngineState(newEngineState);

    set(handles.enginesListBox,'String',lvdData.launchVehicle.getEnginesListBoxStr());

    handles.removeEngineButton.Enable = 'on';

% --------------------------------------------------------------------
function enginesListboxContextMenu_Callback(hObject, eventdata, handles)
% hObject    handle to enginesListboxContextMenu (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% --- Executes on key press with focus on lvd_EditEnginesGUI or any of its controls.
function lvd_EditEnginesGUI_WindowKeyPressFcn(hObject, eventdata, handles)
% hObject    handle to lvd_EditEnginesGUI (see GCBO)
% eventdata  structure with the following fields (see MATLAB.UI.FIGURE)
%	Key: name of the key that was pressed, in lower case
%	Character: character interpretation of the key(s) that was pressed
%	Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles    structure with handles and user data (see GUIDATA)
    switch(eventdata.Key)
        case 'return'
            uiresume(handles.lvd_EditEnginesGUI);
        case 'enter'
            uiresume(handles.lvd_EditEnginesGUI);
        case 'escape'
            uiresume(handles.lvd_EditEnginesGUI);
    end


function tf=isNonFailure(obj)
% return whether this test was a non-failure
%
% tf=isSuccess(obj)
%
% Input:
%   obj                     MoxUnitPassedTestOutcome object
%
% Output:
%   tf                      set to true, because a skipped test is not a
%                           failure
%
% See also: @MoxUnitTestOutcome

    tf=true;


function out = callerFile(field)
%CALLERFILE infor of current function's caller file
%USAGE
% s = callerFile
% s
% .name
% .file
% .line
% .path
%
% c = callerFile(field)
%
%

% carry with some debug info
% st(1): funcName st(2): currently running function

ST = dbstack('-completenames', 1);
L = length(ST);

if L < 2
    out.file = [];
    out.name = [];
    out.line = [];
    out.path = cd;
else
    out = ST(2);
    out.path = fileparts(out.file);
end

if nargin ~= 0
	out = out.(field);
end

% carry with some debug info
% st(1): funcName st(2): currently running function


function tf=moxunit_isa_test_skipped_exception(exception)
% return true if the input is a MOxUnit test-skipped exception
%
% tf=moxunit_isa_test_skipped_exception(exception)
%
% Input:
%   exception           an exception struct or object with field
%                       .identifier
%
% Output:
%   tf                  true if exception.identifer is equal to that
%                       thrown by moxunit_throw_test_skipped_exception
%
% Notes:
%   - if this exception is thrown when running a test through
%     a MOxUnitTestReport instance, this instance will record the test as
%     skipped, not as a failure
%
% NNO Jan 2014

    persistent cached_test_skipped_identifier

    if isempty(cached_test_skipped_identifier)
        try
            moxunit_throw_test_skipped_exception('error');
            assert(false,'should never get here');
        catch
            last_caught_error=lasterror();
        end

        cached_test_skipped_identifier=last_caught_error(1).identifier;
    end

    tf=strcmp(exception.identifier,...
                cached_test_skipped_identifier);