function dopOSCCI(varargin)
% dopOSCCI Mark II ~ 17-11-2010 (last edit)
% Tuesday the 10th of August 2010:
%
% OSCCI's (Oxford Study of Children's Communcation Impairment)
% Functional Transcranial Doppler Ultrasonography (fTCD) data summary suite
%
% imports and summarises fTCD data files created by the Multi-Dop hardware.
%
% Mark II:
% - additional facility to summarise fTCD files based upon muliple external
%    channel cues: 1) condition cuing and 2) variable baseline to stimulus
%   onset cuing.
%   Rather than amend the earlier version a complete overhaul is needed.
%
% -------------------------------------------------------------------------
% dopOSCCI provides facility for:
% - summarising multiple fTCD data files in single process
% - raw data trimming and overall or by epoch normalisation
% - automatic activation epoch/trial screening
% - baseline corrected laterality index calculation within
%   specified periods of interest
% - visualisation of raw, normalised, averaged, epoch, behavioural, and
%   overall(grouped) data - figures can be exported to image or mat files.
%
% - data output summaries suitable for spreadsheet interegation (e.g.,
%   R, EXCEL, SPSS)
% - data graphing output = averaged numbers for individuals for graphing in
%   external packages.
%
% - manual trial screening = e.g.,with respect to behavioural observations
% - group summaries = data separation by groups
% - behavioural summaries = trial separation by condition or response
% - session analysis = combining multiple sessions per individual
%
% -------------------------------------------------------------------------
% Use:
% the dopOSCCI function is designed to be used as a commandline function as
% well as to call a graphical user interface (gui).
%  - dopOSCCI('nogui') = command line
%  - dopOSCCI = calls gui
%
% variable inputs are accepted: see dopOSCCIdef for most inputs
%
% -------------------------------------------------------------------------
% debugging:
% dopOSCCI utilises series of try/catch statements to save variables if a
% program crashes.  load codes and then available at the command window to
% easily retrieve this data for debugging purposes.
%   see 'dopOSCCIdebug' for further details.
%   see also 'dopOSCCIclean'
%
% -------------------------------------------------------------------------
%     'dopOSCCI' summarises functional transcranial Doppler ultrasonography
%     (fTCD) data.  The primary function of the software is to assess the
%     hemispheric lateralization of cognitive function.
%
%     Copyright (C) 2011 the Chancellor, Masters and Scholars of the
%     University of Oxford.
% 
%     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/> 
%     or write to the Free Software Foundation, Inc., 51 Franklin Street,
%     Fifth Floor, Boston, MA 02110-1301, USA.
%
%     Authors: Nic Badcock, Georgina Holt, Anneka Holden, & Dorothy Bishop.
%       contact: nicholas.badcock@gmail.com
%
fprintf('\n\n%s\n',['Running ',mfilename]);

%% add dopOSCCI path
% make sure matlab knows about all the dopOSCCI running files
dl=fileparts(which('dopOSCCI'));
addpath(genpath(dl)); % place all dopOSCCI files on the matlab path
fprintf('\t%s\n\t\t%s\n',...
    'Added dopOSCCI directory to the matlab path:',dl);

%% setGetInputsStruct
% uses generic setGetInputsStruct function to examine inputs provided.
% keep this list simple -
inputs.varargin=varargin;
inputs.turnOn={'nogui',... % if inputted, gui is not displayed
    'test',... % if inputted saves dop structure to be examined
    };
inputs.turnOff={'saveCrash',... % default save variables if problem see dopOSCCIcrash
    'clear',... % run clc at start of dopOSCCI
    };
inputs.defaults=struct('saveDop',0);
dop=setGetInputsStruct(inputs);
dop.inputs=varargin; % use the same set on inputs for next steps
%% clear screen
if dop.clear
    clc; % clc screen contents and then repeat opening info
    fprintf('\n\n%s\n',['Running ',mfilename]);
    fprintf('\t%s\n\t\t%s\n',...
        'Added dopOSCCI directory to the matlab path:',dl);
end
%% licence info
help dopOSCCIlicenseFunction % present the basic license info

%% dopOSCCI mode: cmd line or gui?
if dop.nogui % = command line
    fprintf('\t%s\n','> at the command line:');
%     dop.inputs=varargin; % use the same set on inputs
    dopOSCCIrun(dop);
else % if not nogui > open gui...
    fprintf('\t%s\n','> gui style:');
    dopOSCCIgui(dop);
end

clear inputs dop