function p = pathdef
%PATHDEF Search path defaults.
%   PATHDEF returns a string that can be used as input to MATLABPATH
%   in order to set the path.

%   Copyright 1984-2007 The MathWorks, Inc.
%   $Revision: 1.4.2.2 $ $Date: 2007/06/07 14:45:14 $

% DO NOT MODIFY THIS FILE.  IT IS AN AUTOGENERATED FILE.
% EDITING MAY CAUSE THE FILE TO BECOME UNREADABLE TO
% THE PATHTOOL AND THE INSTALLER.

p = [...
%%% BEGIN ENTRIES %%%
     '/afs/inf.ed.ac.uk/user/s08/s0880377/matlab/statscopy:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/project/MATLAB/gitformatlab:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/junk64/dip/common/mlv7_4/diplib:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/junk64/dip/common/mlv7_4/dipimage_mex:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/junk64/dip/common/dipimage:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/project/MATLAB:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/project/MATLAB/residualanalysis:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/project/MATLAB/statfun:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/project/MATLAB/conjgradfunctions:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/project/MATLAB/simulationdatatool:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/project/MATLAB/fit/fitfunctions:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/project/MATLAB/fit:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/project/MATLAB/aux:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/project/MATLAB/rory:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/project/MATLAB/FastICA_25:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/project/MATLAB/image_proc:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/project/MATLAB/ploting:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/project/MATLAB/qdots:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/project/MATLAB/PatternAnalysis:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/project/MATLAB/PatternAnalysis/netlab:', ...
     '/afs/inf.ed.ac.uk/user/s08/s0880377/matlab:', ...
     matlabroot,'/toolbox/matlab/general:', ...
     matlabroot,'/toolbox/matlab/ops:', ...
     matlabroot,'/toolbox/matlab/lang:', ...
     matlabroot,'/toolbox/matlab/elmat:', ...
     matlabroot,'/toolbox/matlab/randfun:', ...
     matlabroot,'/toolbox/matlab/elfun:', ...
     matlabroot,'/toolbox/matlab/specfun:', ...
     matlabroot,'/toolbox/matlab/matfun:', ...
     matlabroot,'/toolbox/matlab/datafun:', ...
     matlabroot,'/toolbox/matlab/polyfun:', ...
     matlabroot,'/toolbox/matlab/funfun:', ...
     matlabroot,'/toolbox/matlab/sparfun:', ...
     matlabroot,'/toolbox/matlab/scribe:', ...
     matlabroot,'/toolbox/matlab/graph2d:', ...
     matlabroot,'/toolbox/matlab/graph3d:', ...
     matlabroot,'/toolbox/matlab/specgraph:', ...
     matlabroot,'/toolbox/matlab/graphics:', ...
     matlabroot,'/toolbox/matlab/uitools:', ...
     matlabroot,'/toolbox/matlab/strfun:', ...
     matlabroot,'/toolbox/matlab/imagesci:', ...
     matlabroot,'/toolbox/matlab/iofun:', ...
     matlabroot,'/toolbox/matlab/audiovideo:', ...
     matlabroot,'/toolbox/matlab/timefun:', ...
     matlabroot,'/toolbox/matlab/datatypes:', ...
     matlabroot,'/toolbox/matlab/verctrl:', ...
     matlabroot,'/toolbox/matlab/codetools:', ...
     matlabroot,'/toolbox/matlab/helptools:', ...
     matlabroot,'/toolbox/matlab/demos:', ...
     matlabroot,'/toolbox/matlab/timeseries:', ...
     matlabroot,'/toolbox/matlab/hds:', ...
     matlabroot,'/toolbox/matlab/guide:', ...
     matlabroot,'/toolbox/matlab/plottools:', ...
     matlabroot,'/toolbox/local:', ...
     matlabroot,'/toolbox/shared/controllib:', ...
     matlabroot,'/toolbox/shared/dastudio:', ...
     matlabroot,'/toolbox/matlab/datamanager:', ...
     matlabroot,'/toolbox/compiler:', ...
     matlabroot,'/toolbox/distcomp:', ...
     matlabroot,'/toolbox/distcomp/user:', ...
     matlabroot,'/toolbox/distcomp/mpi:', ...
     matlabroot,'/toolbox/distcomp/pctdemos:', ...
     matlabroot,'/toolbox/distcomp/parallel:', ...
     matlabroot,'/toolbox/distcomp/parallel/datafun:', ...
     matlabroot,'/toolbox/distcomp/parallel/datatypes:', ...
     matlabroot,'/toolbox/distcomp/parallel/elfun:', ...
     matlabroot,'/toolbox/distcomp/parallel/elmat:', ...
     matlabroot,'/toolbox/distcomp/parallel/lapack:', ...
     matlabroot,'/toolbox/distcomp/parallel/matfun:', ...
     matlabroot,'/toolbox/distcomp/parallel/ops:', ...
     matlabroot,'/toolbox/distcomp/parallel/sparfun:', ...
     matlabroot,'/toolbox/distcomp/parallel/specfun:', ...
     matlabroot,'/toolbox/distcomp/parallel/util:', ...
     matlabroot,'/toolbox/distcomp/lang:', ...
     matlabroot,'/toolbox/gads:', ...
     matlabroot,'/toolbox/gads/gads:', ...
     matlabroot,'/toolbox/gads/gadsdemos:', ...
     matlabroot,'/toolbox/images/colorspaces:', ...
     matlabroot,'/toolbox/images/images:', ...
     matlabroot,'/toolbox/images/imdemos:', ...
     matlabroot,'/toolbox/images/imuitools:', ...
     matlabroot,'/toolbox/images/iptformats:', ...
     matlabroot,'/toolbox/images/iptutils:', ...
     matlabroot,'/toolbox/shared/imageslib:', ...
     matlabroot,'/toolbox/shared/spcuilib:', ...
     matlabroot,'/toolbox/nnet:', ...
     matlabroot,'/toolbox/nnet/nncontrol:', ...
     matlabroot,'/toolbox/nnet/nndemos:', ...
     matlabroot,'/toolbox/nnet/nnet:', ...
     matlabroot,'/toolbox/nnet/nnet/nnanalyze:', ...
     matlabroot,'/toolbox/nnet/nnet/nncustom:', ...
     matlabroot,'/toolbox/nnet/nnet/nndistance:', ...
     matlabroot,'/toolbox/nnet/nnet/nnformat:', ...
     matlabroot,'/toolbox/nnet/nnet/nninit:', ...
     matlabroot,'/toolbox/nnet/nnet/nnlearn:', ...
     matlabroot,'/toolbox/nnet/nnet/nnnetinput:', ...
     matlabroot,'/toolbox/nnet/nnet/nnnetwork:', ...
     matlabroot,'/toolbox/nnet/nnet/nnperformance:', ...
     matlabroot,'/toolbox/nnet/nnet/nnplot:', ...
     matlabroot,'/toolbox/nnet/nnet/nnprocess:', ...
     matlabroot,'/toolbox/nnet/nnet/nnsearch:', ...
     matlabroot,'/toolbox/nnet/nnet/nntopology:', ...
     matlabroot,'/toolbox/nnet/nnet/nntrain:', ...
     matlabroot,'/toolbox/nnet/nnet/nntransfer:', ...
     matlabroot,'/toolbox/nnet/nnet/nnweight:', ...
     matlabroot,'/toolbox/nnet/nnguis:', ...
     matlabroot,'/toolbox/nnet/nnguis/nftool:', ...
     matlabroot,'/toolbox/nnet/nnguis/nntool:', ...
     matlabroot,'/toolbox/nnet/nnobsolete:', ...
     matlabroot,'/toolbox/nnet/nnresource:', ...
     matlabroot,'/toolbox/nnet/nnutils:', ...
     matlabroot,'/toolbox/nnet/nnguis/nnguiutils:', ...
     matlabroot,'/toolbox/nnet/nndemos/nndatasets:', ...
     matlabroot,'/toolbox/nnet/nnguis/nntraintool:', ...
     matlabroot,'/toolbox/optim/optim:', ...
     matlabroot,'/toolbox/optim/optimdemos:', ...
     matlabroot,'/toolbox/shared/optimlib:', ...
     matlabroot,'/toolbox/signal/signal:', ...
     matlabroot,'/toolbox/signal/sigtools:', ...
     matlabroot,'/toolbox/signal/sptoolgui:', ...
     matlabroot,'/toolbox/signal/sigdemos:', ...
     matlabroot,'/toolbox/shared/siglib:', ...
     matlabroot,'/toolbox/stats:', ...
     matlabroot,'/toolbox/shared/statslib:', ...
     matlabroot,'/toolbox/wavelet/wavelet:', ...
     matlabroot,'/toolbox/wavelet/wmultisig1d:', ...
     matlabroot,'/toolbox/wavelet/wavedemo:', ...
     matlabroot,'/toolbox/wavelet/compression:', ...
     matlabroot,'/toolbox/bioinfo/bioinfo:', ...
     matlabroot,'/toolbox/bioinfo/biolearning:', ...
     matlabroot,'/toolbox/bioinfo/microarray:', ...
     matlabroot,'/toolbox/bioinfo/mass_spec:', ...
     matlabroot,'/toolbox/bioinfo/proteins:', ...
     matlabroot,'/toolbox/bioinfo/biomatrices:', ...
     matlabroot,'/toolbox/bioinfo/biodemos:', ...
     matlabroot,'/toolbox/bioinfo/graphtheory:', ...
     matlabroot,'/toolbox/curvefit/curvefit:', ...
     matlabroot,'/toolbox/curvefit/cftoolgui:', ...
     matlabroot,'/toolbox/simbio/simbio:', ...
     matlabroot,'/toolbox/simbio/simbiodemos:', ...
%%% END ENTRIES %%%
     ...
];

p = [userpath,p];


classdef DataReader < handle
methods
    function data = next(this)
        data = this.nextImpl;
    end
    function data = previous(this)
        data = this.previousImpl;
    end
    function data = current(this)
        data = this.currentImpl;
    end
end

methods(Abstract, Access=protected)
    data = nextImpl(this);
    data = previousImpl(this);
    data = currentImpl(this);
end
end


function [servicesUrl, options] = getHostOptions(host)
%% Set the options associated with the services for host.
    csrfUrl = [host '/services'];
    servicesUrl = [host '/services_submit'];
    [cookie, csrftoken] = getSessionInfo(csrfUrl);
    header = ["Content-Type" "application/json"; ...
              "Accept" "application/json"; ...
              "X-CSRFToken" csrftoken; "Cookie" cookie];

    options = weboptions('MediaType', 'application/json', ...
                         'Timeout', 120, 'HeaderFields', header);
end


clear psn_3d_mex;
mex psn_3d_mex.c psn_common.c psn_3d.c


function io_loadworkspace(filename)
% Load workspace from a file.
% io_loadworkspace(filename)
%
% Brings up an appropriate file chooser dialog, if necessary.
%
% In:
%   Filename : workspace file name
%
% See also:
%   io_saveworkspace
%
%                                Christian Kothe, Swartz Center for Computational Neuroscience, UCSD
%                                2010-11-19

% set default
if ~exist('filename','var') || isempty(filename)
    filename = 'bcilab:/resources/workspaces'; end
if ~ischar(filename)
    error('The file name must be given as a string.'); end

% translate to platform-specific path
filename = env_translatepath(filename);

if exist(filename,'dir')
    % load from given directory
    [filename,filepath] = uigetfile({'*.mat','Workspace files (*.mat)'},'Load workspace',filename);
    filename = [filepath filename];
elseif ~exist(filename,'file')
    % open file chooser from current path
    [filename,filepath] = uigetfile({'*.mat','Workspace files (*.mat)'},'Load workspace');
    filename = [filepath filename];
end

if isempty(filename) || ~ischar(filename)
    % user pressed cancel: nothing to do
elseif exist(filename,'file')
    fprintf('Loading workspace...');
    evalin('base',sprintf('clear; io_load(''%s'');',filename));
    fprintf('done.\n');
else
    error(['Could not find ' filename]);
end


function res = sin(x)
res = 9;
end % fucntion sin


function cleanFiles(cleanBefore)
% clean output files in ./tex using make
%FIXME: this file appears to be unused (but it is useful)
%FIXME: adapt this file to take the output directory into account
    if cleanBefore && exist(fullfile('tex','Makefile'),'file')
        fprintf(1, 'Cleaning output files...\n');
        cwd = pwd;
        try
            cd('tex');
            [exitCode, output] = system('make distclean');
            fprintf(1,'%s\n', output);
            assert(exitCode==0, 'Exit code 0 means correct execution');
        catch
            % This might happen when make is not present
            fprintf(2, '\tNot completed succesfully\n\n');
        end
        cd(cwd);
    end
end


classdef FreeFemFilePrinter < FilePrinter

    properties (Access = private)
        printingDir
    end

    properties (Access = protected)
        linesToPrint
    end

    methods (Access = public, Static)

        function p = create(inputData)
            p = FreeFemFilePrinterFactory.create(inputData);
            p.init(inputData);
            p.createOutPutFolder();
        end

    end

    methods (Access = public)

        function print(obj)
            obj.openFile();
            obj.printingLines();
            obj.closeFile();
        end

    end

    methods (Access = private)

        function init(obj,d)
            obj.linesToPrint = d.linesToPrint;
            obj.printingDir  = d.printingDir;
            obj.fileName     = fullfile(obj.printingDir,[d.fileName,'.edp']);
        end

        function createOutPutFolder(obj)
            dir = obj.printingDir;
            if ~exist(dir,'dir')
                mkdir(dir)
                addpath(dir)
            end
        end

    end

    methods (Access = protected, Abstract)
        printingLines(obj)
    end
end


%NE Dataset overload


function varargout = calcChildVariant(varargin)

warning('calcChildVariant is obsolete. Please use "calcVariantId" instead.')

[varargout{1:nargout}] = calcVariantId(varargin{:});


function javaFigs = mrvJavaFeature(javaFigs)
% Turn off javafigures in certain versions of Matlab
%
%    javaFigs = mrvJavaFeature(javaFigs)
%
% Rory turned off Java Figure features in versions 7 - 7.3 because java was
% buggy for Mathworks.  Starting in 7.4 (Matlab 2007a), Mathworks disabled
% this possibility. THey now think that java works great and they want you
% to report any bugs.  So, we only disable for the relevant versions.
%
% There are many places in the code where Rory did this.   Rather than
% finding them all and writing out this little bit, I wrote this routine
% which we should use to replace Rory's test code.  In the fullness of
% time, as everyone migrates beyond Matlab 7.4, we can eliminate these
% calls, too.
%
% Example - You need to alter code like this:
%
%  javaFigs = mrvJavaFeature;
%
% .... code here
%
%  mrvJavaFeature(javaFigs);
% 2007 by BAW.
warning('You are calling an obsolote function: mrvJavaFeature. Please remove it from your code.');
javaFigs = [];
return;

% If the person sent in a javaFigs variable, they want us to restore
if notDefined('javaFigs'), javaFigs = [];
else feature('javafigures',javaFigs); return;
end

% Otherwise, they want us to turn it off for certain versions of Matlab,
% specified here
version = ver('Matlab');
matlabVersion = version.Version;
mVersion = str2double(matlabVersion(1:3));
mMinorVersion = str2double(matlabVersion(3:end));

if ( (mVersion == 7) && (mMinorVersion < 4)) % version 7, < 7.4
    javaFigs = feature('javafigures');
    if ispref('VISTA', 'javaOn') % seems to work diff't for diff't machines
        feature('javafigures', getpref('VISTA', 'javaOn'));
    else
        feature('javafigures', 0);
    end
end

return


%PLUS Dataset overload


function varargout = scoutdetails(varargin)
% SCOUTDETAILS M-file for scoutdetails.fig
%      SCOUTDETAILS, by itself, creates a new SCOUTDETAILS or raises the existing
%      singleton*.
%
%      H = SCOUTDETAILS returns the handle to a new SCOUTDETAILS or the handle to
%      the existing singleton*.
%
%      SCOUTDETAILS('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in SCOUTDETAILS.M with the given input arguments.
%
%      SCOUTDETAILS('Property','Value',...) creates a new SCOUTDETAILS or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before scoutdetails_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to scoutdetails_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

% Copyright 2002-2003 The MathWorks, Inc.

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

% Last Modified by GUIDE v2.5 24-Mar-2005 13:43:51

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @scoutdetails_OpeningFcn, ...
                   'gui_OutputFcn',  @scoutdetails_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 scoutdetails is made visible.
function scoutdetails_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 scoutdetails (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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

%Plot helicopter pictures on startup
scout = imread('scout.bmp');
axes(handles.axes1);
image(scout);
axis off;

yaw_pedals = imread('Yaw Pedals.jpg');
axes(handles.axes3);
image(yaw_pedals);
axis off;

collective_lever = imread('Collective Stick.jpg');
axes(handles.axes4);
image(collective_lever);
axis off;

cyclic_stick = imread('Cockpit Instruments.jpg');
axes(handles.axes5);
image(cyclic_stick);
axis off;

% --- Outputs from this function are returned to the command line.
function varargout = scoutdetails_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;

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

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

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

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

close scoutdetails;

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

handles = guidata(scoutdetails);

set(handles.tab1,'Visible','on');
set(handles.tab2,'Visible','off');
set(handles.tab3,'Visible','off');

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

handles = guidata(scoutdetails);

set(handles.tab1,'Visible','off');
set(handles.tab2,'Visible','on');
set(handles.tab3,'Visible','off');

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

set(handles.tab1,'Visible','off');
set(handles.tab2,'Visible','off');
set(handles.tab3,'Visible','on');


classdef SettingsLevelSetHorizontalInclusion < SettingsLevelSetCreator

    properties (Access = public)
        widthH
    end

    methods (Access = public)

        function obj = SettingsLevelSetHorizontalInclusion(varargin)
            obj.loadParams('paramsLevelSetCreator_HorizontalInclusion.json')
            if nargin == 1
                obj.loadParams(varargin{1})
            end
        end

    end

end


function b = hdf5isvalid(fname)

val = H5F.is_hdf5(fname);
if val > 0
    b = true;
else
    b = false;
    fprintf('File %s is not an HDF5 file.\n', fname);
end


function [tmpS] = dicomrt_d2c_buildscanstr(scanInitS)

% Construct the scan structure
tmpS = [];

tmpS.scanArray            = '';
tmpS.scanType             = 'CT';
tmpS.scanInfo             = scanInitS;
tmpS.uniformScanInfo      = '';
tmpS.scanArraySuperior    = '';
tmpS.scanArrayInferior    = '';


function [ output_args ] = interfaceError( fname,fid )
%

if ~exist(fname,'file')
  e = MException('mtex:fileNotFound',...
    ['File ''' fname ''' not found']);
  throwAsCaller(e);
end

[st] = dbstack(1);
i = find(strncmp('load',{st.name},4),1,'first');
name = st(i).name;

type = regexp(name,'(?<=load)(\w*)(?=_)','match');
interface = regexp(lower(name),'(?<=[a-z]*_)\w*','match');

if nargin > 1
  try
    fclose(fid);
  catch
  end
end

fname = regexprep(fname,'\','/');

e = MException('mtex:wrongInterface',...
  [type{1} ' format ''' upper(interface{1}) ''' does not match the data\n file: ''' fname '''']);
throwAsCaller(e);


%%% void show_video(struct)
%
function show_video(video)
  for i = 1 : video.nrFramesTotal
    frame = video.frames(i).cdata;
    imshow(frame,[],'InitialMagnification','fit');
    disp(i);
    pause(0.01);
  end
end


function simsetup_rot
motionobject = getMotionObject();
if isempty(motionobject)
   testmotion;
   motionobject = getMotionObject();
end
end


function cookbook()
   %cookbook   Cookbook for TraceFilter
   %   Demonstrates the usage of TraceFilter

   disp('TraceFilter Cookbook')
   disp(' - not created, yet -');
end


freeFemSettings = SettingsFreeFemMeshGenerator();


function X = dissect(Y)

X = dissect_internal(Y);


function baseName=fileBaseName(fileName)

[~,baseName]=myfileparts(fileName);

end


function CPD = set_clamped(CPD, bit)

CPD.clamped = bit;


function res = fieldnames(this, varargin)
% Returns names of the fields in .other
% FORMAT res = fieldnames(this)
%
% An overloaded function...
% _______________________________________________________________________
% Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

% Vladimir Litvak
% $Id: fieldnames.m 2720 2009-02-09 19:50:46Z vladimir $

res = fieldnames(this.other, varargin{:});


% =========================================================================
function parser = matlab2tikzInputParser ()
  % Initialize the structure.
  parser = struct ();
  % Public Properties
  parser.Results = {};
  % Enabel/disable parameters case sensitivity.
  parser.CaseSensitive = false;
  % Enable/disable error for parameters not defined by the constructor.
  parser.KeepUnmatched = false;
  % Enable/disable passing arguments in a structure.
  parser.StructExpand = true;
  % Names of parameters defined in input parser constructor.
  parser.Parameters = {};
  % Names of parameters not defined in the constructor.
  parser.Unmatched = struct ();
  % Names of parameters using default values.
  parser.UsingDefaults = {};

  % Handles for functions that act on the object.
  parser.addRequired   = @addRequired;
  parser.addOptional   = @addOptional;
  parser.addParamValue = @addParamValue;
  parser.parse         = @parse;

  % Initialize the parser plan
  parser.plan = {};
end
% =========================================================================
function p = parser_plan (q, arg_type, name, default, validator)
  p = q;
  plan = p.plan;
  if (isempty (plan))
    plan = struct ();
    n = 1;
  else
    n = numel (plan) + 1;
  end
  plan(n).type      = arg_type;
  plan(n).name      = name;
  plan(n).default   = default;
  plan(n).validator = validator;
  p.plan = plan;
end
% =========================================================================
function p = addRequired (p, name, validator)
  p = parser_plan (p, 'required', name, [], validator);
end
% =========================================================================
function p = addOptional (p, name, default, validator)
  p = parser_plan (p, 'optional', name, default, validator);
end
% =========================================================================
function p = addParamValue (p, name, default, validator)
  p = parser_plan (p, 'paramvalue', name, default, validator);
end
% =========================================================================
function p = parse (p, varargin)
  plan = p.plan;
  results = p.Results;
  using_defaults = {};
  if (p.CaseSensitive)
    name_cmp = @strcmp;
  else
    name_cmp = @strcmpi;
  end
  if (p.StructExpand)
    k = find (cellfun (@isstruct, varargin));
    for m = numel(k):-1:1
      n = k(m);
      s = varargin{n};
      c = [fieldnames(s).'; struct2cell(s).'];
      c = c(:).';
      if (n > 1 && n < numel (varargin))
        varargin = horzcat (varargin(1:n-1), c, varargin(n+1:end));
      elseif (numel (varargin) == 1)
        varargin = c;
      elseif (n == 1);
        varargin = horzcat (c, varargin(n+1:end));
      else % n == numel (varargin)
        varargin = horzcat (varargin(1:n-1), c);
      end
    end
  end
  if (isempty (results))
    results = struct ();
  end
  type = {plan.type};
  n = find( strcmp( type, 'paramvalue' ) );
  m = setdiff (1:numel( plan ), n );
  plan = plan ([n,m]);
  for n = 1 : numel (plan)
    found = false;
    results.(plan(n).name) = plan(n).default;
    if (~ isempty (varargin))
      switch plan(n).type
      case 'required'
        found = true;
        if (strcmpi (varargin{1}, plan(n).name))
          varargin(1) = [];
        end
        value = varargin{1};
        varargin(1) = [];
      case 'optional'
        m = find (cellfun (@ischar, varargin));
        k = find (name_cmp (plan(n).name, varargin(m)));
        if (isempty (k) && validate_arg (plan(n).validator, varargin{1}))
          found = true;
          value = varargin{1};
          varargin(1) = [];
        elseif (~ isempty (k))
          m = m(k);
          found = true;
          value = varargin{max(m)+1};
          varargin(union(m,m+1)) = [];
        end
      case 'paramvalue'
        m = find( cellfun (@ischar, varargin) );
        k = find (name_cmp (plan(n).name, varargin(m)));
        if (~ isempty (k))
          found = true;
          m = m(k);
          value = varargin{max(m)+1};
          varargin(union(m,m+1)) = [];
        end
      otherwise
        error( sprintf ('%s:parse', mfilename), ...
               'parse (%s): Invalid argument type.', mfilename ...
             )
      end
    end
    if (found)
      if (validate_arg (plan(n).validator, value))
        results.(plan(n).name) = value;
      else
        error( sprintf ('%s:invalidinput', mfilename), ...
               '%s: Input argument ''%s'' has invalid value.\n', mfilename, plan(n).name ...
             );
      end
      p.Parameters = union (p.Parameters, {plan(n).name});
    elseif (strcmp (plan(n).type, 'required'))
      error( sprintf ('%s:missinginput', mfilename), ...
             '%s: input ''%s'' is missing.\n', mfilename, plan(n).name ...
           );
    else
      using_defaults = union (using_defaults, {plan(n).name});
    end
  end

  if (~ isempty (varargin))
    if (p.KeepUnmatched)
    % Include properties that do not match specified properties
      for n = 1:2:numel(varargin)
        if (ischar (varargin{n}))
          results.(varargin{n}) = varargin{n+1};
        else
          error (sprintf ('%s:invalidinput', mfilename), ...
                 '%s: invalid input', mfilename)
        end
      end
    end
    p.Unmatched = varargin{1:2:end};
  end

  % Store the results of the parsing
  p.Results = results;
  p.UsingDefaults = using_defaults;

end
% =========================================================================
function result = validate_arg (validator, arg)
  try
    result = validator (arg);
  catch
    result = false;
  end
end
% =========================================================================


function varargout = ft_transform_vol(varargin)

% This function is a backward compatibility wrapper for existing MATLAB scripts
% that call a function that is not part of the FieldTrip toolbox any more.
%
% Please update your code to make it future-proof.

oldname = mfilename;
newname = 'ft_transform_geometry';

ft_warning('%s is only a backward compatibility wrapper, which will soon be removed. Please call %s instead.', upper(oldname), upper(newname));

[varargout{1:nargout}] = feval(newname, varargin{:});


function varargout = JAABASplashScreen(varargin)
% JAABASPLASHSCREEN MATLAB code for JAABASplashScreen.fig
%      JAABASPLASHSCREEN, by itself, creates a new JAABASPLASHSCREEN or raises the existing
%      singleton*.
%
%      H = JAABASPLASHSCREEN returns the handle to a new JAABASPLASHSCREEN or the handle to
%      the existing singleton*.
%
%      JAABASPLASHSCREEN('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in JAABASPLASHSCREEN.M with the given input arguments.
%
%      JAABASPLASHSCREEN('Property','Value',...) creates a new JAABASPLASHSCREEN or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before JAABASplashScreen_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to JAABASplashScreen_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 JAABASplashScreen

% Last Modified by GUIDE v2.5 13-May-2012 20:22:42

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @JAABASplashScreen_OpeningFcn, ...
                   'gui_OutputFcn',  @JAABASplashScreen_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 JAABASplashScreen is made visible.
function JAABASplashScreen_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 JAABASplashScreen (see VARARGIN)

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

try
  imname = 'janelia_logo.png';
  versionfile = 'version.txt';
  if exist(imname,'file'),
    im = imread(imname);
  else
    im = 0;
  end
  image(im,'Parent',handles.axes1);
  axis(handles.axes1,'image','off');
  if exist(versionfile,'file'),
    fid = fopen(versionfile,'r');
    while true,
      version = fgetl(fid);
      if ~ischar(version),
        break;
      end
      version = strtrim(version);
      if isempty(version),
        continue;
      end
      break;
    end
    fclose(fid);
  else
    version = '???';
  end

  set(handles.text_info,'String',sprintf('JAABA: The Janelia Automatic Animal Behavior Annotator\nversion %s',version));
end

% Update handles structure
guidata(hObject, handles);

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

% --- Outputs from this function are returned to the command line.
function varargout = JAABASplashScreen_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;
varargout{2} = handles.text_status;


function files = scan_get_files(n, filt, mesg, wd)
% Drop-in replacement for spm_get.
% Main advantage is that it can use spm_select for SPM5+ to mimic older spm_get behavior.
%
% :Usage:
% ::
%
%     files = scan_get_files(n, filt, mesg, wd)

    if(~exist('wd', 'var') || isempty(wd))
        wd = pwd();
    end

    switch(spm('Ver', [], 1))
        case 'SPM2'
            files = spm_get(n, filt, mesg, wd);
        case {'SPM5', 'SPM8'}
            if(any(n < 0))
                typ = 'dir';
                n = abs(n);
                select_filt = strrep(filt, '*', '.*');
            else
                switch(deblank(filt))
                    case {'*.img' '*img' '*.nii' '*nii' '*.hdr' '*hdr'}
                        typ = 'image';
                        select_filt = '.*';
                    case {'*.mat' '*mat'}
                        typ = 'mat';
                        select_filt = '.*';
                    otherwise
                        typ = 'any';
                        select_filt = strrep(filt, '*', '.*');
                end
            end
            files = spm_select(n, typ, mesg, [], wd, select_filt);
    end
end


function s = char(tpl)
%TEMPLATE Convert a template object in a one line description string
%  S = CHAR(TPL) is a class convertor from Template to a string, used
%  in online display.
%
%  See also DISPLAY

%  Copyright (C) 2003 Guillaume Flandin <Guillaume@artefact.tk>
%  $Revision: 1.0 $Date: 2003/05/05 22:19:51 $

s = ['Template Object: root ''',...
		tpl.root,''', ',...
		num2str(length(tpl.file)), ' files, ',...
		num2str(length(tpl.varkeys)), ' keys, ',...
		tpl.unknowns, ' unknowns.'];


function duration=getDuration(obj)
% get the duration of the test
%
% duration=getDuration(obj)
%
% Input:
%   obj                 MOxUnitTestReport instance
%
% Output:
%   duration            total time in seconds that it took to run all tests
%                       in the obj instance

    get_outcome_duration=@(i)getDuration(getTestOutcome(obj,i));

    all_durations=arrayfun(get_outcome_duration,...
                            1:countTestOutcomes(obj));

    duration=sum(all_durations);


function nitfHdr = readDESegSubhdr(nitfHdr,fid,numDEs)
%
% <<<<<<<<<< CLASSIFICATION: UNCLASSIFIED >>>>>>>>>>
%
%READDESEGSUBHDR Read and parse data extension segments

% Written by Matt Donath, NGA, matthew.b.donath@nga.ic.gov
% References:
%  > MIL-STD-2500A, NATIONAL IMAGERY TRANSMISSION FORMAT VERSION 2.0
%  > MIL-STD-2500C, NATIONAL IMAGERY TRANSMISSION FORMAT VERSION 2.1
%  > STDI-0001,     NATIONAL SUPPORT DATA EXTENSIONS (SDE)(VERSION 1.3/CN1)
%                   FOR THE NATIONAL IMAGERY TRANSMISSION FORMAT (NITF)
%  > STDI-0002,     THE COMPENDIUM OF CONTROLLED EXTENSIONS (CE) FOR THE
%                   NATIONAL IMAGERY TRANSMISSION FORMAT (NITF) VERSION 2.1
%
% //////////////////////////////////////////
% /// CLASSIFICATION: UNCLASSIFIED       ///
% //////////////////////////////////////////

%% DETERMINE NITF VERSION
nitfVer = nitfHdr.filehdr.FHDR(6:8);

%% VERSION 2.1

if strcmp(nitfVer ,'2.1')
    nitfHdr.(numDEs).DE = fread(fid,2,'uint8=>char')';
    nitfHdr.(numDEs).DESID = strtrim(fread(fid,25,'uint8=>char')');
    nitfHdr.(numDEs).DESVER = fread(fid,2,'uint8=>char')';
    nitfHdr.(numDEs).DECLAS = fread(fid,1,'uint8=>char')';
    nitfHdr.(numDEs).DESCLSY = fread(fid,2,'uint8=>char')';
    nitfHdr.(numDEs).DESCODE = strtrim(fread(fid,11,'uint8=>char')');
    nitfHdr.(numDEs).DESCTLH = strtrim(fread(fid,2,'uint8=>char')');
    nitfHdr.(numDEs).DESREL =  strtrim(fread(fid,20,'uint8=>char')');
    nitfHdr.(numDEs).DESDCTP =  strtrim(fread(fid,2,'uint8=>char')');
    nitfHdr.(numDEs).DESDCDT =  strtrim(fread(fid,8,'uint8=>char')');
    nitfHdr.(numDEs).DESDCXM =  strtrim(fread(fid,4,'uint8=>char')');
    nitfHdr.(numDEs).DESDG =  fread(fid,1,'uint8=>char')';
    nitfHdr.(numDEs).DESDGDT =  strtrim(fread(fid,8,'uint8=>char')');
    nitfHdr.(numDEs).DESCLTX =  strtrim(fread(fid,43,'uint8=>char')');
    nitfHdr.(numDEs).DESCATP =  fread(fid,1,'uint8=>char')';
    nitfHdr.(numDEs).DESCAUT = strtrim(fread(fid,40,'uint8=>char')');
    nitfHdr.(numDEs).DESCRSN = fread(fid,1,'uint8=>char')';
    nitfHdr.(numDEs).DESSRDT = strtrim(fread(fid,8,'uint8=>char')');
    nitfHdr.(numDEs).DESCTLN = strtrim(fread(fid,15,'uint8=>char')');

    if strcmp(nitfHdr.(numDEs).DESID,'TRE_OVERFLOW')
        nitfHdr.(numDEs).DESOFLW = fread(fid,6,'uint8=>char')';
        nitfHdr.(numDEs).DESITEM = str2double(fread(fid,3,'uint8=>char')');
    end

    nitfHdr.(numDEs).DESSHL = str2double(fread(fid,4,'uint8=>char')');

    if strcmp(nitfHdr.(numDEs).DESID,'TRE_OVERFLOW')
        if nitfHdr.(numDEs).DESSHL > 0
            nitfHdr.(numDEs).DESSHF = fread(fid,nitfHdr.(numDEs).DESSHL,'uint8=>char')';
        end
        TRE = fread(fid,6,'uint8=>char')';
        fseek(fid, -6, 'cof');
        % Check to see if reader function exists for this TRE.
        if exist(strcat('read',TRE,'.m'),'file')
            nitfHdr.(numDEs) = eval(strcat('read',TRE,'(fid)'));
        else
            % Read undefined data
            nitfHdr.(numDEs) = readUndefinedTRE(fid);
        end
    elseif strcmp(nitfHdr.(numDEs).DESID,'STREAMING_FILE_HEADER')
        nitfHdr.(numDEs).SFH_L1 = str2double(fread(fid,7,'uint8=>char')');
        nitfHdr.(numDEs).SFH_DELIM1 = fread(fid,4,'uint8=>char')';
        nitfHdr.(numDEs).SFH_DR = str2double(fread(fid,nitfHdr.(numDEs).SFH_L1,'uint8=>char')');
        nitfHdr.(numDEs).SFH_DELIM2 = fread(fid,4,'uint8=>char')';
        nitfHdr.(numDEs).SFH_L2 = str2double(fread(fid,7,'uint8=>char')');
    elseif strcmp(nitfHdr.(numDEs).DESID,'SICD_XML')
        SICD_xml_string = fread(fid,nitfHdr.filehdr.LD(str2double(numDEs(10:end))),'uint8=>char')';
        nitfHdr.(numDEs).DESDATA = sicdxml2struct( xmlread( java.io.StringBufferInputStream( SICD_xml_string ) ) );
    else % Skip unrecognized DES types
        nitfHdr.(numDEs).DESUSH_OFFSET = ftell(fid); % Record offset, so we can parse user subheaders later
        fseek(fid, nitfHdr.(numDEs).DESSHL, 'cof');
        fseek(fid, nitfHdr.filehdr.LD(str2double(numDEs(10:end))), 'cof');
    end

%% VERSION 2.0

elseif strcmp(nitfVer, '2.0')
    nitfHdr.(numDEs).DE = fread(fid,2,'uint8=>char')';
    nitfHdr.(numDEs).DESTAG = strtrim(fread(fid,25,'uint8=>char')');
    nitfHdr.(numDEs).DESVER = fread(fid,2,'uint8=>char')';

    % nitfHdr.(numDEs).DESSG
    nitfHdr.(numDEs).DESSG.DESCLAS = fread(fid,1,'uint8=>char')';
    nitfHdr.(numDEs).DESSG.DESCODE = strtrim(fread(fid,40,'uint8=>char')');
    nitfHdr.(numDEs).DESSG.DESCTLH = strtrim(fread(fid,40,'uint8=>char')');
    nitfHdr.(numDEs).DESSG.DESREL =  strtrim(fread(fid,40,'uint8=>char')');
    nitfHdr.(numDEs).DESSG.DESCAUT = strtrim(fread(fid,20,'uint8=>char')');
    nitfHdr.(numDEs).DESSG.DESCTLN = strtrim(fread(fid,20,'uint8=>char')');
    nitfHdr.(numDEs).DESSG.DESDWNG = strtrim(fread(fid,6,'uint8=>char')');
    if strcmp(nitfHdr.(numDEs).DESSG.DESDWNG,'999998')
        nitfHdr.(numDEs).DESSG.DESDEVT = strtrim(fread(fid,40,'uint8=>char')');
    end

    if strcmpi(nitfHdr.(numDEs).DESTAG,'Registered Extensions') ||...
            strcmpi(nitfHdr.(numDEs).DESTAG,'Controlled Extensions')
        nitfHdr.(numDEs).DESOFLW = strtrim(fread(fid,6,'uint8=>char')');
        nitfHdr.(numDEs).DESITEM = fread(fid,3,'uint8=>char')';
    end

    nitfHdr.(numDEs).DESSHL = str2double(fread(fid,4,'uint8=>char')');
    if nitfHdr.(numDEs).DESSHL > 0
        nitfHdr.(numDEs).DESSHF = fread(fid,nitfHdr.(numDEs).DESSHL,'uint8=>char')';
    end

    if strcmpi(nitfHdr.(numDEs).DESTAG,'Registered Extensions') ||...
            strcmpi(nitfHdr.(numDEs).DESTAG,'Controlled Extensions')
        % READ TRE
        TRE = fread(fid,6,'uint8=>char')';
        fseek(fid, -6, 'cof');

        % Check to see if reader function exists for this TRE.
        if exist(strcat('read',TRE,'.m'),'file')
            nitfHdr.(numDEs) = eval(strcat('read',TRE,'(fid)'));
        else
            % Read undefined data
            nitfHdr.(numDEs) = readUndefinedTRE(fid);
        end
    end
end

% //////////////////////////////////////////
% /// CLASSIFICATION: UNCLASSIFIED       ///
% //////////////////////////////////////////


function [compiler,options] = mexcompiler
% mexcompiler returns the name of the compiler used by mex.

% Written by Tom Minka

compiler = '';
options = struct;
options.vcvarsopts = '';
if ispc
	mexopts = fullfile(prefdir,'mexopts.bat');
	if ~exist(mexopts,'file')
		return
	end
	fid = fopen(mexopts);
	while 1
		txt = fgetl(fid);
		if ~ischar(txt), break, end
		if isempty(compiler) && strncmp('rem ',txt,4)
			compiler = txt(5:end-8);
		elseif ~isempty(strmatch('set ',txt))
			txt = txt(5:end);
			pos = strfind(txt,'=');
			if ~isempty(pos)
				pos = pos(1);
				field = txt(1:(pos-1));
				txt = txt((pos+1):end);
				txt = strrep(txt,'%MATLAB%',matlabroot);
				options.(field) = txt;
				if strcmp(field,'VSINSTALLDIR')
					vsinstalldir = txt;
					if ~isempty(strmatch(':\Program Files (x86)\',vsinstalldir(2:end)))
						% http://msdn.microsoft.com/en-us/library/x4d2c09s(VS.80).aspx
						if exist(fullfile(vsinstalldir,'VC','bin','x86_amd64','cl.exe'))
							options.vcvarsopts = 'x86_amd64';
						else
							options.vcvarsopts = 'x86';
						end
					end
				end
			end
		end
	end
	fclose(fid);
else
	mexopts = fullfile(prefdir,'mexopts.sh');
	if ~exist(mexopts,'file')
		return
	end
	fid = fopen(mexopts);
	while 1
		txt = fgetl(fid);
		if ~ischar(txt), break, end
		if isempty(compiler) && strncmp('rem ',txt,4)
			compiler = txt(5:end-8);
		else
			pos = strfind(txt,'=');
			if ~isempty(pos)
				pos = pos(1);
				field = txt(1:(pos-1));
				txt = txt((pos+1):end);
				txt = strrep(txt,'%MATLAB%',matlabroot);
				options.(field) = txt;
			end
		end
	end
	fclose(fid);
end


function val = csa_header(s, key)
fld = 'CSAImageHeaderInfo';
if isfield(s, fld) && isfield(s.(fld), key), val = s.(fld).(key); return; end
if isfield(s, key), val = s.(key); return; end % general tag: 2nd choice
try val = s.PerFrameFunctionalGroupsSequence.Item_1.(fld).Item_1.(key); return; end
fld = 'CSASeriesHeaderInfo';
if isfield(s, fld) && isfield(s.(fld), key), val = s.(fld).(key); return; end
val = [];


function tapas_BLT_runITI(params, iTrial)
% tapas_BLT_runITI shows the Fixation Cross
%
% About:
%   Coded by F.Petzschner 19. April 2017
%	Last change: F.Petzschner 19. April 2017

% Show Cue
Screen('DrawTexture', params.screen.window, params.text.imgiti, [], params.screen.fit, 0);
Screen('Flip', params.screen.window);
tapas_BLT_logEvent('iti_on',params);

% Open CO2 valve if specified (and using valves)
if params.valves == 1 && (sum(ismember(params.co2, iTrial)) == 1)
    outp(params.port_address, 2);
    params.CO2valve_open = GetSecs;
end

% Wait
params = wait2_escapeOption(params.dur.iti(iTrial), params);
tapas_BLT_logEvent('iti_off',params);

% Ensure valves are closed
if params.valves == 1
    outp(params.port_address, 0);
end

end


clear; close all; clc;

%%

toolboxPath=fileparts(fileparts(fileparts(mfilename('fullpath'))));
docPath=fullfile(fileparts(fileparts(fileparts(mfilename('fullpath')))),'docs');
libPath=fullfile(fileparts(fileparts(fileparts(mfilename('fullpath')))),'lib');
docToolsPath=fullfile(fileparts(fileparts(fileparts(mfilename('fullpath')))),'docs','docTools');

pathNames={docToolsPath,libPath,docPath};

%% Prepare boilerplate

licenseBoilerPlate=fullfile(toolboxPath,'licenseBoilerPlate.txt');
[T]=txtfile2cell(licenseBoilerPlate);

footerTargetText='% _*GIBBON footer text*_ ';

%%

licenseLink='https://github.com/gibbonCode/GIBBON/blob/master/LICENSE';

%Add comment symbols
for q=1:1:numel(T)
    T{q}=['% ',T{q}];
end

%Add target header
T=[{'%% '};{footerTargetText};{'% '};{['% License: <',licenseLink,'>']};T(1:end)];

%%

fileExtension='.m';

%%

numPaths=numel(pathNames);
for q_path=1:1:numPaths
    pathName=pathNames{q_path};
    files = dir(fullfile(pathName,'*.m'));
    files={files(1:end).name};
    files=sort(files(:));
    numFiles=numel(files);
    for q_file=1:1:numFiles
        fileName=fullfile(pathName,files{q_file});
        [T_now]=txtfile2cell(fileName);
        T_now(end+1:end+numel(T))=T;
        cell2txtfile(fileName,T_now,0);
    end
end

%%
% _*GIBBON footer text*_
%
% License: <https://github.com/gibbonCode/GIBBON/blob/master/LICENSE>
%
% GIBBON: The Geometry and Image-based Bioengineering add-On. A toolbox for
% image segmentation, image-based modeling, meshing, and finite element
% analysis.
%
% Copyright (C) 2006-2022 Kevin Mattheus Moerman and the GIBBON contributors
%
% 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/>.


function saveSession(queryFlag)
%Save the mrSESSION file in HOMEDIR.
%
%  saveSession([queryFlag=0])
%
% 3/26/2001, djh, updated to version 3.0 to also save dataTYPES structure.
% 06/06, ras -- doesn't save any over other info (like vANATOMYPATH)
% that may already be present in the file.
% 10/06, ras -- auto saves a backup file, to help prevent saving over data.

global mrSESSION
global HOMEDIR
global dataTYPES
global vANATOMYPATH

if ~exist('queryFlag','var')
    queryFlag=0;
end

if isempty(HOMEDIR)
    warning(['Writing mrSESSION to: ',pwd]);
    pathStr = fullfile(pwd,'mrSESSION.mat');
else
    pathStr = fullfile(HOMEDIR,'mrSESSION.mat');
end

% save a backup if there's an existing file
if exist(pathStr, 'file')
    tmp = load(pathStr);
    save('mrSESSION_backup.mat', '-struct', 'tmp');
end

% The query flag says ask if the mrSESSION file already exists.
if exist(pathStr, 'file') && queryFlag
    but = questdlg('Over-write existing mrSESSION file?');
    switch but
    case 'Yes',
        save(pathStr,'mrSESSION','dataTYPES', 'vANATOMYPATH');
    otherwise
    end
else
    if exist(pathStr,'file')
        save(pathStr,'mrSESSION','dataTYPES', 'vANATOMYPATH', '-append');
    else
        save(pathStr,'mrSESSION','dataTYPES', 'vANATOMYPATH');
    end
end

return;


function obj = horzcat(obj, varargin)
% Use merge_atlas to combine atlases, or newatlas = (atlas1, atlas2, atlas3);

for i = 1:length(varargin)

    obj = merge_atlases(obj, varargin{i});

end

end


function pre_install (desc)
  dir =  (fileparts (mfilename ("fullpath")));
  putenv ("GEOPDES_INCLUDE_DIR", [ "-I" canonicalize_file_name(dir) filesep() "inst" filesep() "include"]);
endfunction


classdef AnnotationVideoMarker < handle
    properties (Access = public)
        sample;
        label;
        text;
    end

    methods (Access = public)
        function obj = AnnotationVideoMarker(sample,label,text)
            if nargin ~= 0
                obj.sample = sample;
                obj.label = label;
                obj.text = text;
            end
        end
    end
end


function UpdateCondPopupmenu(handles)
global maingui

if isempty(handles)
    return;
end
if isempty(maingui)
    return;
end
if maingui.dataTree.IsEmpty()
    return;
end

iG = maingui.dataTree.GetCurrElemIndexID();
CondNames = maingui.dataTree.groups(iG).GetConditions();
CondNamesCurrElem = maingui.dataTree.currElem.GetConditionsActive();
for jj=1:length(CondNames)
    k = find(strcmp(['-- ', CondNames{jj}], CondNamesCurrElem));
    if ~isempty(k)
        CondNames{jj} = ['-- ', CondNames{jj}];
    end
end
if isempty(CondNames)
   CondNames = {' '};
   set(handles.popupmenuConditions, 'enable', 'off');
else
    set(handles.popupmenuConditions, 'enable', 'on');
end
set(handles.popupmenuConditions, 'string', CondNames);
maingui.condition = get(handles.popupmenuConditions, 'value');


function setFEBioPath(FEBioPathSpec)

% function setFEBioPath(FEBioPathSpec)
% -----------------------------------------------------------------------
% This function sets the FEBio path defined by FEBioPathSpec. Setting the
% path means it is stored in the GIBBON configuration file:
% /GIBBON/config/FEBioPath.txt.
%
% -----------------------------------------------------------------------

%%
filePath=mfilename('fullpath');
toolboxPath=fileparts(fileparts(filePath));
configPath=fullfile(toolboxPath,'config');

fileName=fullfile(configPath,'FEBioPath.txt');

%Import text file containing paths

T{1}='#List paths for febio here, multiple can be given e.g. for use on several platforms. The first valid path found is always used.';

%Set paths in cell
switch class(FEBioPathSpec)
    case 'cell'
        for q=1:1:numel(FEBioPathSpec)
            pathNameNow=FEBioPathSpec{q};
            if exist(pathNameNow,'file')==2
                T{q+1}=FEBioPathSpec{q};
            else
                error('Path specified does not exist')
            end
        end
    otherwise
        if exist(FEBioPathSpec,'file')==2
            T{2}=FEBioPathSpec;
        else
            error('Path specified does not exist')
        end
end

cell2txtfile(fileName,T,0,0); %Write cell to config file

if contains(lower(FEBioPathSpec),'febio2')
        warning('FEBio2 detected. FEBio2 support is depricated. Please upgrade to FEBio3');
end

end

%%
% _*GIBBON footer text*_
%
% License: <https://github.com/gibbonCode/GIBBON/blob/master/LICENSE>
%
% GIBBON: The Geometry and Image-based Bioengineering add-On. A toolbox for
% image segmentation, image-based modeling, meshing, and finite element
% analysis.
%
% Copyright (C) 2006-2022 Kevin Mattheus Moerman and the GIBBON contributors
%
% 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/>.


function VBA_disp (str, options, carriageReturn)
% // VBA toolbox //////////////////////////////////////////////////////////
%
% VBA_disp (str, options)
% display string or cell-arry of strings according to verbose option
%
% IN:
%   - str: string or cell array of strings to display
%   - option structure containing the verbose flag (default: true)
%
% /////////////////////////////////////////////////////////////////////////

% get flag
try
    verbose = options.verbose;
catch
    verbose = true;
end

if nargin < 3
    carriageReturn = true;
end

% conditional display function
if verbose
    if iscell (str)
        for i = 1 : numel(str)
            fprintf(1, str{i});
        end
    else
       fprintf (1, str);
    end
    if carriageReturn
        fprintf ('\n');
    end
end


function l = legend( varargin )
%legend  Create a legend and make it match the background

%   Copyright 2011 The MathWorks, Inc.

l = legend( varargin{:} );
figh = ancestor( l, 'figure' );
set( l, 'Color', get( figh, 'Color' ) );


function [methodinfo,structs,enuminfo,ThunkLibName]=hidapi64mac_proto
%HIDAPI64MAC_PROTO Create structures to define interfaces found in 'hidapi'.

%This function was generated by loadlibrary.m parser version 1.1.6.38 on Thu Jan 23 17:27:34 2014
%perl options:'hidapi.i -outfile=hidapi64mac_proto.m -thunkfile=hidapi64_thunk_maci64.c -header=hidapi.h'
ival={cell(1,0)}; % change 0 to the actual number of functions to preallocate the data.
structs=[];enuminfo=[];fcnNum=1;
fcns=struct('name',ival,'calltype',ival,'LHS',ival,'RHS',ival,'alias',ival,'thunkname', ival);
MfilePath=fileparts(mfilename('fullpath'));
ThunkLibName=fullfile(MfilePath,'hidapi64_thunk_maci64');
% int hid_init ( void );
fcns.thunkname{fcnNum}='int32voidThunk';fcns.name{fcnNum}='hid_init'; fcns.calltype{fcnNum}='Thunk'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}=[];fcnNum=fcnNum+1;
% int hid_exit ( void );
fcns.thunkname{fcnNum}='int32voidThunk';fcns.name{fcnNum}='hid_exit'; fcns.calltype{fcnNum}='Thunk'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}=[];fcnNum=fcnNum+1;
% struct hid_device_info * hid_enumerate ( unsigned short vendor_id , unsigned short product_id );
fcns.thunkname{fcnNum}='voidPtruint16uint16Thunk';fcns.name{fcnNum}='hid_enumerate'; fcns.calltype{fcnNum}='Thunk'; fcns.LHS{fcnNum}='hid_device_infoPtr'; fcns.RHS{fcnNum}={'uint16', 'uint16'};fcnNum=fcnNum+1;
% void hid_free_enumeration ( struct hid_device_info * devs );
fcns.thunkname{fcnNum}='voidvoidPtrThunk';fcns.name{fcnNum}='hid_free_enumeration'; fcns.calltype{fcnNum}='Thunk'; fcns.LHS{fcnNum}=[]; fcns.RHS{fcnNum}={'hid_device_infoPtr'};fcnNum=fcnNum+1;
% hid_device * hid_open ( unsigned short vendor_id , unsigned short product_id , wchar_t * serial_number );
fcns.thunkname{fcnNum}='voidPtruint16uint16voidPtrThunk';fcns.name{fcnNum}='hid_open'; fcns.calltype{fcnNum}='Thunk'; fcns.LHS{fcnNum}='hid_device_Ptr'; fcns.RHS{fcnNum}={'uint16', 'uint16', 'int32Ptr'};fcnNum=fcnNum+1;
% hid_device * hid_open_path ( const char * path );
fcns.thunkname{fcnNum}='voidPtrcstringThunk';fcns.name{fcnNum}='hid_open_path'; fcns.calltype{fcnNum}='Thunk'; fcns.LHS{fcnNum}='hid_device_Ptr'; fcns.RHS{fcnNum}={'cstring'};fcnNum=fcnNum+1;
% int hid_write ( hid_device * device , const unsigned char * data , size_t length );
fcns.thunkname{fcnNum}='int32voidPtrvoidPtrulongThunk';fcns.name{fcnNum}='hid_write'; fcns.calltype{fcnNum}='Thunk'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'hid_device_Ptr', 'uint8Ptr', 'ulong'};fcnNum=fcnNum+1;
% int hid_read_timeout ( hid_device * dev , unsigned char * data , size_t length , int milliseconds );
fcns.thunkname{fcnNum}='int32voidPtrvoidPtrulongint32Thunk';fcns.name{fcnNum}='hid_read_timeout'; fcns.calltype{fcnNum}='Thunk'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'hid_device_Ptr', 'uint8Ptr', 'ulong', 'int32'};fcnNum=fcnNum+1;
% int hid_read ( hid_device * device , unsigned char * data , size_t length );
fcns.thunkname{fcnNum}='int32voidPtrvoidPtrulongThunk';fcns.name{fcnNum}='hid_read'; fcns.calltype{fcnNum}='Thunk'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'hid_device_Ptr', 'uint8Ptr', 'ulong'};fcnNum=fcnNum+1;
% int hid_set_nonblocking ( hid_device * device , int nonblock );
fcns.thunkname{fcnNum}='int32voidPtrint32Thunk';fcns.name{fcnNum}='hid_set_nonblocking'; fcns.calltype{fcnNum}='Thunk'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'hid_device_Ptr', 'int32'};fcnNum=fcnNum+1;
% int hid_send_feature_report ( hid_device * device , const unsigned char * data , size_t length );
fcns.thunkname{fcnNum}='int32voidPtrvoidPtrulongThunk';fcns.name{fcnNum}='hid_send_feature_report'; fcns.calltype{fcnNum}='Thunk'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'hid_device_Ptr', 'uint8Ptr', 'ulong'};fcnNum=fcnNum+1;
% int hid_get_feature_report ( hid_device * device , unsigned char * data , size_t length );
fcns.thunkname{fcnNum}='int32voidPtrvoidPtrulongThunk';fcns.name{fcnNum}='hid_get_feature_report'; fcns.calltype{fcnNum}='Thunk'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'hid_device_Ptr', 'uint8Ptr', 'ulong'};fcnNum=fcnNum+1;
% void hid_close ( hid_device * device );
fcns.thunkname{fcnNum}='voidvoidPtrThunk';fcns.name{fcnNum}='hid_close'; fcns.calltype{fcnNum}='Thunk'; fcns.LHS{fcnNum}=[]; fcns.RHS{fcnNum}={'hid_device_Ptr'};fcnNum=fcnNum+1;
% int hid_get_manufacturer_string ( hid_device * device , wchar_t * string , size_t maxlen );
fcns.thunkname{fcnNum}='int32voidPtrvoidPtrulongThunk';fcns.name{fcnNum}='hid_get_manufacturer_string'; fcns.calltype{fcnNum}='Thunk'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'hid_device_Ptr', 'int32Ptr', 'ulong'};fcnNum=fcnNum+1;
% int hid_get_product_string ( hid_device * device , wchar_t * string , size_t maxlen );
fcns.thunkname{fcnNum}='int32voidPtrvoidPtrulongThunk';fcns.name{fcnNum}='hid_get_product_string'; fcns.calltype{fcnNum}='Thunk'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'hid_device_Ptr', 'int32Ptr', 'ulong'};fcnNum=fcnNum+1;
% int hid_get_serial_number_string ( hid_device * device , wchar_t * string , size_t maxlen );
fcns.thunkname{fcnNum}='int32voidPtrvoidPtrulongThunk';fcns.name{fcnNum}='hid_get_serial_number_string'; fcns.calltype{fcnNum}='Thunk'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'hid_device_Ptr', 'int32Ptr', 'ulong'};fcnNum=fcnNum+1;
% int hid_get_indexed_string ( hid_device * device , int string_index , wchar_t * string , size_t maxlen );
fcns.thunkname{fcnNum}='int32voidPtrint32voidPtrulongThunk';fcns.name{fcnNum}='hid_get_indexed_string'; fcns.calltype{fcnNum}='Thunk'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'hid_device_Ptr', 'int32', 'int32Ptr', 'ulong'};fcnNum=fcnNum+1;
% const wchar_t * hid_error ( hid_device * device );
fcns.thunkname{fcnNum}='voidPtrvoidPtrThunk';fcns.name{fcnNum}='hid_error'; fcns.calltype{fcnNum}='Thunk'; fcns.LHS{fcnNum}='int32Ptr'; fcns.RHS{fcnNum}={'hid_device_Ptr'};fcnNum=fcnNum+1;
structs.hid_device_.members=struct('');
structs.hid_device_info.members=struct('path', 'cstring', 'vendor_id', 'uint16', 'product_id', 'uint16', 'serial_number', 'int32Ptr', 'release_number', 'uint16', 'manufacturer_string', 'int32Ptr', 'product_string', 'int32Ptr', 'usage_page', 'uint16', 'usage', 'uint16', 'interface_number', 'int32', 'next', 'hid_device_infoPtr');
methodinfo=fcns;