% plotWeatherPie(D,lflag,Nflag)
%
% plots a pie chart of weather data which is coded as
%   -1 rain
%    0 cloud
%    1 sun
%    2 dark
% rain is specially marked
% 
% in:
%       D       -   data, N=length(D)
%       lflag   -   flag determining whether to show legend
%       Nflag   -   flag determining whether to show N
function plotWeatherPie(D,lflag,Nflag)

if nargin<3
    Nflag = 0;
    if nargin<2
        lflag = 0;
    end
end

nums = histc(D,-1:2);
ind = find(nums>0);
ind = ind(:)';
warning off MATLAB:pie:NonPositiveData
h = pie(nums,[1,0,0,0]);
warning on MATLAB:pie:NonPositiveData

cols = [0,0,150;127,127,127;250,210,90;55,0,0]/255;

for i=1:length(ind)
    set(h(i*2-1),'FaceColor',cols(ind(i),:));
end

if lflag
    ltxt = {'rain','cloud','sun','dark'};
    legend(ltxt(ind),'Location','BestOutside','Orientation','Horizontal')
    legend('boxoff')
end

if Nflag
    text(-0.15,0.8,sprintf('N=%d',length(D)),'Units','normalized',...
         'HorizontalAlignment','center',...
         'FontUnits','normalized','FontSize',.07)
end