function [a,d,bins] = dp() 
%DPC Read in a file called dpc.csv and display a histogram of the data
%    in columns. 
%    a = average histogram
%    d = matrix with the histogram for each challenge
%    bins = bin centers (x-axis values to correspond to a and d)
NumBins = 50;

bins = 0:1./NumBins:10;

j = 1;
for i=2:395
   [fname,fname_errmsg]= sprintf('out/%0d.txt', i);
   if (exist (fname) ) 
      disp (fname);
      data = [];
      data = csvread(fname);


      [histogram_file_data,bin_centers] = hist (data, bins);
      %[histogram_data,bin_centers] = hist (data, NumBins);
      %disp(bin_centers);
      %disp (j);
      histogram_data(:,j) = histogram_file_data';
      j = j + 1;
   end 

end

%disp(histogram_data);

[cols, rows] = size (histogram_data);
%disp ( rows);
%disp ( cols);
% Clear the 0 bin. We don't really care how many zeros there were,
% since they are caused by empty data in the square matrix
histogram_data(1,:) = zeros(1,rows);
histogram_sums = cumsum (histogram_data);
[cols, rows] = size (histogram_sums);
%disp (histogram_sums(cols,:));

% Normalize the histograms
for i=1:cols
   histogram_data(i,:) = histogram_data(i,:) ./ histogram_sums(cols,:);
end
subplot(2,1,1);
plot(bin_centers,histogram_data);
%plot(histogram_data(:,1));
grid on;
title('Individual Challenges');

hist_tavg = mean(histogram_data');
hist_avg = hist_tavg';

subplot(2,1,2);
plot(bin_centers,hist_avg);
grid on;
title('Challenge Average');

[cols, rows] = size (data);
avg_sum = zeros(rows,1);
avg_count = zeros(rows,1);
for i=1:cols
   for j=1:rows
      k = data(i,j);
      if (0 ~= k)
         avg_sum(j) = avg_sum(j) + k;
         avg_count(j) = avg_count(j) + 1;
      end
   end
end

d = histogram_data;
%disp (avg_sum);
%disp (avg_count);
a = avg_sum ./ avg_count;
%disp (a);
