function dop=dopOverallDataVert(dop)
% dopOSCCI Mark II: dopOverallDataVert ~ 14-Dec-2010 (last edit)
%
% save vertically aligned graphing data - easily placed into Prism (for
% example) for plotting.
%
% vertical alligned refers to the rows being samples and the columns being
% individual participants' data, all left, right, dif, avg.
%
fprintf('%s\n',['Running ',mfilename]);
try
    if dop.def.saveData && dop.def.saveGraphDataVert && isfield(dop,'grd') ...
            && isfield(dop.grd,'okay') && dop.grd.okay
        for i=1:dop.grd.n
            % get the file parts
            [dop.tmp.dir dop.tmp.name dop.tmp.ext]=fileparts(dop.grd.fileList{i});
            % new file name location
            dop.tmp.ndir=[dop.tmp.dir,'\vert\'];
            if ~exist(dop.tmp.ndir,'dir')
                mkdir(dop.tmp.ndir);
            end
            dop.tmp.nfnl=[dop.tmp.ndir,dop.tmp.name,'_vert',dop.tmp.ext];
            %% create headers
            dop.tmp.fid=fopen(dop.tmp.nfnl,'w');
            fprintf(dop.tmp.fid,'%s\t','data');
            %% > abbreviation header
            for j=1:numel(dop.grd.data(i).chInclude)
                if dop.grd.data(i).chInclude(j)
                    for jj=1:numel(dop.grd.data(i).fileList)
                    fprintf(dop.tmp.fid,'%s\t',...
                        [dop.grd.data(i).chAbb{j},'_',num2str(jj)]);
                    end
                end
            end
%             fprintf(dop.tmp.fid,'\n'); % new line
            fprintf(dop.tmp.fid,'\n%s\t','timeSamples'); % new line and extra label
            %% > individual file header
            for j=1:numel(dop.grd.data(i).chInclude)
                if dop.grd.data(i).chInclude(j)
                    for jj=1:numel(dop.grd.data(i).fileList)
                    fprintf(dop.tmp.fid,'%s\t',dop.grd.data(i).fileList{jj});
                    end
                end
            end
            fprintf(dop.tmp.fid,'\n'); % new line
            fclose(dop.tmp.fid); % close the file
            %% append data
            dop.tmp.data=dop.grd.data(i).time(dop.grd.data(i).maxIndices(1)+1:dop.grd.data(i).maxIndices(2))';
            for j=1:numel(dop.grd.data(i).chInclude)
                if dop.grd.data(i).chInclude(j)
                   dop.tmp.data=[dop.tmp.data,dop.grd.data(i).(dop.grd.data(i).chAbb{j})'];
                end
            end
            dlmwrite(dop.tmp.nfnl,dop.tmp.data,'-append','delimiter','\t');    
        end
        %% clear tmp
        if isfield(dop,'tmp')
            dop=rmfield(dop,'tmp');
        end
    end
catch err
    %% catch dopOSCCI error
    % 
save(dopOSCCIdebug(mfilename));rethrow(err); 
%     dopOSCCIcrash(err,dop,mfilename);
end