function dop=dopSelectFile(dop)
% dopOSCCI Mark II: dopSelectFile ~ 16-11-2010 (last edit)
%
% select the to-be-imported doppler file
%
try
    %% get next file name
    % starting simply with a straight list of files
    dop.sum.count=dop.sum.count+1;
    dop.sum.fileNameLoc=dop.data.fileList{dop.sum.count};%dop.data.TXfiles{dop.sum.count};
    [dop.sum.filePath dop.sum.fileTxt dop.sum.fileExt]=...
        fileparts(dop.sum.fileNameLoc); % update current file
    dop.sum.fileName=[dop.sum.fileTxt,dop.sum.fileExt];
    dop.sum.skip=0;
    dop.sum.skipReason=[];
    %% save individual notes (command output)
    dop.sum.notesFileNameLoc=dopSaveNotes('fileTxt',['B',dop.sum.fileTxt],...
        'saveDir',[dop.def.saveDir,'notes/'],'saveNotes',dop.def.saveNotes(2),...
        'saveData',dop.def.saveData);
    
    %% report on file:
    fprintf('%s\n%s\n\t%s\n','----------------------------------',...
        ['Summarising Doppler File: ',num2str(dop.sum.count),...
        ' of ', num2str(dop.sum.totalFiles)],...
        ['File name = ',dop.sum.fileName]);
    %% report on summary timing
    % George really likes this!
    if ~isfield(dop.sum,'timer')
        dop.sum.timer=[];
    else
        dop.sum.timer(end+1)=toc;
        dop.sum.timeSec=mean(dop.sum.timer);
        dop.sum.timeMin=dop.sum.timeSec/60;
        dop.sum.timeEstSec=dop.sum.timeSec*(dop.sum.totalFiles-dop.sum.count+1);
        dop.sum.timeEstMin=dop.sum.timeMin*(dop.sum.totalFiles-dop.sum.count+1);
        fprintf('\t\t%s %2.2f %s%2.0f %s\n\n','Estimated time',...
            dop.sum.timeEstMin,' mins (',dop.sum.timeEstSec,'secs)');
    end
    tic;
    %% group?
    if dop.def.grpFileChk
        dop.sum.grpMatch=0;
        for i=1:length(dop.grp.fileList)
            if strcmp(dop.sum.fileNameLoc,dop.grp.fileList{i})
                dop.grp.grpMatch=i;
                break
            end
        end
        dop.sum.grp=0; % this means there was a problem...
        dop.sum.grpName=[];
        if dop.grp.grpMatch
            dop.sum.grp=dop.grp.grpNumbers(dop.grp.grpMatch);
            dop.sum.grpName=dop.grp.grpNames{dop.sum.grp};
            fprintf('\t%s\n',['Group: ',num2str(dop.sum.grp),...
                '(',dop.sum.grpName,')']);
        else
            fprintf('\t%s\n','Group match not found...');
        end
    end
    
    %% finished
    % when exhausted available files, adjust finish variable and the summary
    % loop will stop (see dopOSCCIsummary)
    if dop.sum.totalFiles==dop.sum.count
        dop.sum.finish=1;
        fprintf('\t%s\n','Last file.');
    end
%     plong
catch err
    %% catch dopOSCCI error
    % 
%     commandwindow; % bring command window to front
%     cl=[fileparts(which('dopOSCCI')),'Data\dopOSCCIdebug/']; % caught location
%     cfn=['caught_',mfilename,'_',datestr(now,30)]; % caught file name
%     cfnl=[cl,cfn]; % caught file name location
%     save(cfnl); % save all variables to a mat file
%     fprintf('\t%s\n\n\t%s\n\t%s\n\n\n\t%s\n\t\t%s\n',...
%             'Error: Saving caught variables:',...
%             ['Dir: ',cl],['File: ',cfn],...
%             'Access by typing:',['load(''',cfnl,''')']);
%     rethrow(err); 
    save(dopOSCCIdebug(mfilename));rethrow(err); 
%     dopOSCCIcrash(err,dop,mfilename);
end