function plotData(smFactor, normFact, quest, inton, individuals, meanPlot)


%%
%   Written by Dave Moffat Jan 2015
%   plotData reads in all csv files from attached dataset and analyses the
%   data to produce and save a range of plots based on imput values
%   smFactor:      Smoothing factor used to smooth initial noisy data (50)
%   normFact:      Boolean Flag as whether to normalise time and frequency
%                  axes of data (1)
%   quest:         Specific question types, eg: 'YN', Wh', 'all' 
%   inton:         Specific intonation tyoes, eg: 'RF', 'F', 'FR', 'R', 'H'
%   individuals:   Boolean flag to plot all individual intonation patterns
%   meanPlot:      Boolean flag to plot mean for intonation patterns



trackData = readCSV('DataSetSummary.csv');
trackRange = size(trackData,1);
plotCol = ['b','k','y','m','c','r','g'];
plotCol = ['k','k'];
colIndex = 1;
figure;
if(meanPlot)
    zerosPlot = [0:0.1:1];
    totalF = zeros(1,length(zerosPlot));
end
if(~individuals)
    hold on;
end

qList = findInCellArray(trackData,5,quest);
if(isempty(qList))
    qList = [1:trackRange];
end
iList = findInCellArray(trackData,6,inton);
if(isempty(iList))
    iList = [1:trackRange];
end

trackSearch = intersect(qList, iList);
noTracks = length(trackSearch);

for i = trackSearch
    i
	songTrack = csvread(strcat('T',num2str(i),'/01m.csv'));    
    songTrack = songTrack(:,1:2);
    if(normFact)
%         Vertical
        songTrack(:,2) = songTrack(:,2) - min(songTrack(:,2));
        songTrack(:,2) = songTrack(:,2) / max(songTrack(:,2));
%         Horizontal
        songTrack(:,1) = songTrack(:,1) - min(songTrack(:,1));
        songTrack(:,1) = songTrack(:,1) / max(songTrack(:,1));
    end
    if(smFactor > 0)
        songTrack(:,2) = smooth(songTrack(:,2),smFactor);
    end
    plot(songTrack(:,1),songTrack(:,2),plotCol(mod(colIndex,length(plotCol))+1));
	
    if(individuals)
        xlabel('Normalised Time');
        ylabel('Normalised Frequency');
        plotTitle =strcat('Question ',num2str(i),' Data Plot');
        title(plotTitle);
        saveas(gcf,strcat('plots/plot',num2str(i)),'jpg');
    else
    	colIndex = colIndex +1;
    end
    if(meanPlot)
        if(isnan(songTrack(:,1)))
            noTracks = noTracks - 1;
        else
            songTrack(:,1);
            totalF = totalF + interp1(songTrack(:,1),songTrack(:,2),zerosPlot); 
        end
    end
end

% if(~individuals)
%     xlabel('Normalised Time');
%     ylabel('Normalised Frequency');
%     plotTitle = strcat('plots/Questions:',quest,'-Intonation:',inton,' plot');
%     title(plotTitle);
%     filename = strcat(quest,'Q-',inton,'I');
%     saveas(gcf,filename,'jpg');
% end
if(meanPlot)
    totalF = totalF / length(trackSearch);
%     figure;
    plot(zerosPlot,totalF,'LineWidth',2);
    xlabel('Normalised Time');
    ylabel('Normalised Frequency');
    plotTitle = strcat('plots/Questions:',quest,'-Intonation:',inton,' All Intonations and Mean plot');
%     title(plotTitle);
    filename = strcat(quest,'Q-',inton,'-IMean-ALL');
    saveas(gcf,filename,'pdf');
end


end