function dopGraphTest(filenameloc,varargin)
% dopOSCCI Mark II: dopGetTest ~ 11-Jan-2012 (last edit)
%
% I want to be able to look at the raw and normed data without having to
% run through all the dopOSCCI functions each time.
%
% use:
% dopGraphTest(filenameloc,[definition structure],[definition filename],[graph name],[graph number])

% -------------------------------------------------------------------------
%     '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
%
%     Type 'dopOSCCIlicense' for license details or see dopOSCCIlicense.txt
%
 msg_h = msgbox('Creating graph/s - loading the data may take some time','Loading:');
try
    %% setGet inputs
    inputs.varargin=varargin;
    inputs.defaults=struct(...
        'def',[],... definiton structure
        'defFileNameLoc',[],... definition file name location
        'graphName','raw',... default
        'dopChs',[1 2],... % doppler left and right channel numbers
        'evChs',3,... % doppler event channel number/s
        'evNames',[],... % event marker channel names
        'rawSample',100,... % raw multidop sampling rate in hertz
        'outSample',25,... % desired down sampling rate in hertz
        'epoch',[],... % lower and upper epoch values for data triming and trial normalisation
        'trim',0,... % request for raw data trimming - yes or no
        'epochNorm',0,... % request for trial normalisation - yes or no
        'markHeight',1000,...); % height of Multi-dop trigger/marker pulses - look for pulses greater than this (see dopFindRawMarkers)
        'evType',2,...        'evType',2,...% event type: 0 = base, 1 = stim only, 2 = both
        'evMatch',0,...); %'evMatch',0,...% if event type = 0 or 1, it needs a match with another 1 or 0 type, only 2 is independent
        'shortWarn',1);
    %         ); % % event marker channel names
    gt=setGetInputsStruct(inputs); % gt = graph test
    gt.fileNameLoc = filenameloc;
    if iscell(gt.fileNameLoc) && numel(gt.fileNameLoc)>1
        gt.fileNameLoc(2:end) = []; % just want to do one at a time
    end
    [gt.file_dir gt.file_text gt.file_ext] = fileparts(gt.fileNameLoc);
    gt.quit = 0;
    if exist(gt.fileNameLoc,'file')==2
        %% defition
        if isempty(gt.def) && ~isempty(gt.defFileNameLoc) && exist(gt.defFileNameLoc,'file')==2
            % get definition information from file
            gt = dopOSCCIdef('defFileNameLoc',gt.defFileNameLoc);
        end
        if ~isempty(gt.def)
            %             gt.defList = fieldnames(dg.def);
            gt.defList = {'dopChs','evChs','downHertz','epoch','trim',...
                'epochNorm','markHeight','evType','evMatch','shortWarn',...
                'fileType','sep','epochs','actRej','base'};
            % put the structured information into - don't have to do all of
            % these... probably should create a list:
            
            for i = 1 : numel(gt.defList)
                gt.(gt.defList{i}) = gt.def.(gt.defList{i});
            end
        else
            gt.quit = 1;
        end
        
        if ~gt.quit
            [gt.inData gt.inLabels gt.data.foundMarkers gt.data.rawInfo gt.raw.data]=...
                dopProcessRawDataFile(gt.fileNameLoc,...
                'dopChs',gt.dopChs,... % doppler left and right channel numbers
                'evChs',gt.evChs,... % doppler event channel number/s
                'downHertz',gt.downHertz,... % desired down sampling rate in hertz
                'epoch',gt.epoch,... % lower and upper epoch values for data triming and trial normalisation
                'rawTrim',gt.trim,... % request for raw data trimming - yes or no
                'epochNorm',gt.epochNorm,... % request for trial normalisation - yes or no
                'markHeight',gt.markHeight,...); % height of Multi-dop trigger/marker pulses - look for pulses greater than this (see dopFindRawMarkers)
                'evType',gt.evType,...        'evType',2,...% event type: 0 = base, 1 = stim only, 2 = both
                'evMatch',gt.evMatch,...); %'evMatch',0,...% if event type = 0 or 1, it needs a match with another 1 or 0 type, only 2 is independent
                'fileName',gt.file_text,...% something to id file
                'shortWarn',gt.shortWarn);
            %     'evNames',gt.evNames); % % event marker channel names
            try close(msg_h); end % close the message box
            %% ------------------------------------------------------------
            %% Raw Graph
            switch gt.graphName
                %% raw
                case {'raw','Raw','RAW'}
                    [gt.h gt.names]=dopGraph1Raw(gt.raw.data,...%gt.tmp.rawData,...
                        'sampleRate',gt.data.rawInfo.sampleRate,...%gt.downHertz,...
                        'indName',gt.file_text,...
                        'fileType',gt.fileType,...
                        'info',gt.data.rawInfo);
                 %% norm   
                case {'norm','Norm','NORM'};
                    gt.mk = dopEventMarks(gt.inData(:,3:end,:),...
                        'epochs',gt.epochs,'sep',gt.sep,'sample',gt.downHertz,...
                        'eventLabels',gt.evNames,'evChs',gt.evChs,...
                        'evType',gt.evType,'evMatch',gt.evMatch);
                    
                    [gt.h gt.names]=dopGraph2Norm(gt.inData(:,1:2,:),...
                                'mk',gt.mk,...
                                'sampleRate',gt.downHertz,...
                                'indName',gt.file_text,...
                                'actRej',gt.actRej,...
                                'epoch',gt.epoch,...
                                'base',gt.base,...
                                'evType',gt.evType);
                %% individual/average
                % just as well to run on an individual file to see this I
                % think 13-Jan-2012
%                 case {'ind','Ind','IND'}
%                     
%                     gt.mk = dopEventMarks(gt.inData(:,3:end,:),...
%                         'epochs',gt.epochs,'sep',gt.sep,'sample',gt.downHertz,...
%                         'eventLabels',gt.evNames,'evChs',gt.evChs,...
%                         'evType',gt.evType,'evMatch',gt.evMatch);
%                     % stack the data
%         dop.stack=dopEventStack(dop.inData(:,1:2),dop.mk,...
%             'epoch',dop.def.epoch,'sample',dop.def.downHertz,...
%             'eventLabels',dop.def.evNames,'evChs',dop.def.evChs);
                otherwise
                    
            end
            set(gt.h,'visible','on','OuterPosition',[0 0.25 1 .75]);
            pause;
            try close(gt.h);end % try to close, sometime deleted already by user
            
            %             %% report on import
            %             fprintf('%s\n\t%s\n','Import Report:','File info - ');
            %             if gt.data.foundMarkers
            %                 gt.tmp.txLabels=fieldnames(gt.data.rawInfo);
            %                 for i=1:length(gt.tmp.txLabels)
            %                     gt.tmp.txLab=gt.tmp.txLabels{i};
            %                     gt.tmp.txData=gt.data.rawInfo.(gt.tmp.txLab);
            %                     if ~iscell(gt.tmp.txData)
            %                         gt.tmp.info=[gt.tmp.txLab,': ',gt.tmp.txData];
            %                         if isnumeric(gt.tmp.txData)
            %                             gt.tmp.info=[gt.tmp.txLab,': ',num2str(gt.tmp.txData)];
            %                         end
            %                         fprintf('\t%s\n',gt.tmp.info);
            %                     end
            %                 end
            %                 %% save raw data for graphing?
            %                 % two options here - raw data for external graphing or raw data for
            %                 % import plot
            %             else
            %                 %% No markers > skip summary
            %                 fprintf('\t%s\n\t\t%s\n',...
            %                     'No event markers found, therefore skipping:',gt.sum.fileName);
            %                 gt.sum.skip=1;
            %                 gt.sum.skipReason='No event markers found';
            %             end
            %             if size(gt.inData,3)==1 && sum(sum(isnan(gt.inData)))
            %                 gt.sum.skip=1;
            %                 gt.sum.skipReason='Imported data is problematic - not numeric';
            %             elseif size(gt.inData,3)==4 && sum(sum(sum(isnan(gt.inData)))) % 4 was previously 2...
            %                 gt.sum.skip=1;
            %                 gt.sum.skipReason='Imported data is problematic - not numeric';
            %             elseif ~sum(gt.inData)
            %                 gt.sum.skip=1;
            %                 gt.sum.skipReason='Imported data is problematic - empty';
            %             end
            %
            %
            %         else
            %             gt.tmp.report = sprintf('File: \n\t%s\n was not found.\n',gt.sum.fileNameLoc);
            %             disp(gt.tmp.report);
            %             warndlg(gt.tmp.report,'File Not Found:');
            %         end
        end
    end
    clear msg_h
catch err
    %% catch dopOSCCI error
    try delete(msg_h); end
    save(dopOSCCIdebug(mfilename));rethrow(err);
end
