
set(0,'DefaultTextInterpreter','none');

rates = {'RATE_HYBRID' 'RATE_KDP' 'RATE_KDP_ZDR' 'RATE_ZH' ...
         'RATE_Z_ZDR'};
elevs = {'e1' 'e2' 'e3' 'e4'};


clear P; P = struct();

% Q = load('bin20111001_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111001_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111002_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111004_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111012_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111014_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111016_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111018_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111020_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111022_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111023_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111024_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111026_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111111_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111112_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111118_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111123_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111124_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111126_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111127_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111208_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111209_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111215_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111216_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111219_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111220_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111221_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111222_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111223_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});
Q = load('bin20111224_precip.mat'); q = fields(Q); P.(q{1}) = Q.(q{1});

pdays = fields(P);

ptmp = zeros([ numel(pdays)  360 ]);

p_az = struct();

for kk=1:numel(elevs);
    p_az.(elevs{kk}) = struct();
    for jj=1:numel(rates);
        p_az.(elevs{kk}).(rates{jj}) = [];
    end;
end;

for nn=1:numel(rates);
    for kk=1:numel(elevs);
        for jj=1:numel(pdays);
            ptmp(jj,:) = p_az_tot(P.(pdays{jj}).(elevs{kk}).(rates{nn}) );
        end;
        p_az.(elevs{kk}).(rates{nn}) = sum(ptmp);
        ptmp = zeros([ numel(pdays)  360 ]);
    end;
end;

% sum the bins by const azimuth for all days, preserving 200 intervals

totbins = struct();
totbins.e1 = struct();
totbins.e2 = struct();
totbins.e3 = struct();
totbins.e4 = struct();

for nn=1:numel(elevs);
    for jj=1:numel(rates);
        totbins.(elevs{nn}).(rates{jj}) = zeros([200,360]);
    end;
end;

for nn=1:numel(rates);
    for kk=1:numel(elevs);
        for jj=1:numel(pdays);
            totbins.(elevs{kk}).(rates{nn}) = ...
                totbins.(elevs{kk}).(rates{nn}) + P.(pdays{jj}).(elevs{kk}).(rates{nn});
        end;
    end;
end;

% create a plot time tag to add to plots as a textbox
    nowtag = sprintf('%02d:', clock); nowtag = nowtag(1:16);

figure;
plot(1:360,p_az.e3.RATE_KDP,'k')
hold on
plot(1:360,p_az.e3.RATE_ZH,'r')
set(gcf,'OuterPosition', [ 0 1000 1200 400]);
set(gca,'Position',[.05 .1 .9 .8 ]);
set(gca,'XLim',[0 360]);
ylabel('Azimuthally-Summed Precip Rates, 17-70km');
xlabel('Azimuth, degrees');
title(['Along-beam Integrated Precip Total Comparisons (filtered on RATE_KDP exists).  2.5 ' ...
       'deg Elevation'],'FontWeight','bold', 'FontSize', 11);
lgnd = {'from RATE_KDP' 'from RATE_ZH'};
legend(lgnd,  'Interpreter', 'none','Location','SouthWest');
tHandle = text( 'String', nowtag, 'Units', 'normalized', ...
                'Position', [0.9,.92],'Color', [.7 .7 .7] );
hold off

figure;
plot(1:360,p_az.e1.RATE_KDP) 
hold on
plot(1:360,p_az.e2.RATE_KDP,'r')
plot(1:360,p_az.e3.RATE_KDP,'k')
plot(1:360,p_az.e4.RATE_KDP,'c')
set(gca,'XLim',[0 360]);
set(gcf,'OuterPosition', [ 50 1000 1200 400]);
set(gca,'Position',[.05 .1 .9 .8 ]);
ylabel('Azimuthally-Summed Precip Totals (mm/hr), 17-70km');
xlabel('Azimuth, degrees');
title(['Along-beam Integrated Precip Totals, RATE_KDP (filtered on RATE_KDP exists).'], ...
       'FontWeight','bold', 'FontSize', 11);
lgnd = {'@ 0.5' '@ 1.5' ...
        '@ 2.5' '@ 3.5'};
legend(lgnd,  'Interpreter', 'none','Location','SouthWest');
tHandle = text( 'String', nowtag, 'Units', 'normalized', ...
                'Position', [0.9,.92],'Color', [.7 .7 .7] );
hold off

figure;
plot(1:360,p_az.e1.RATE_ZH) 
hold on
plot(1:360,p_az.e2.RATE_ZH,'r')
plot(1:360,p_az.e3.RATE_ZH,'k')
plot(1:360,p_az.e4.RATE_ZH,'c')
set(gca,'XLim',[0 360]);
set(gcf,'OuterPosition', [ 100 1000 1200 400]);
set(gca,'Position',[.05 .1 .9 .8 ]);
ylabel('Azimuthally-Summed Precip Totals (mm/hr), 17-70km');
xlabel('Azimuth, degrees');
title(['Along-beam Integrated Precip Totals, RATE_ZH (filtered on RATE_KDP exists).'], ...
       'FontWeight','bold', 'FontSize', 11);
lgnd = {'@ 0.5' '@ 1.5' ...
        '@ 2.5' '@ 3.5'};
legend(lgnd,  'Interpreter', 'none','Location','SouthWest');
tHandle = text( 'String', nowtag, 'Units', 'normalized', ...
                'Position', [0.9,.92],'Color', [.7 .7 .7] );
hold off

figure;
plot(1:360,p_az.e1.RATE_ZH./p_az.e1.RATE_KDP)
hold on
plot(1:360,p_az.e2.RATE_ZH./p_az.e2.RATE_KDP,'r')
plot(1:360,p_az.e3.RATE_ZH./p_az.e3.RATE_KDP,'k')
plot(1:360,p_az.e4.RATE_ZH./p_az.e4.RATE_KDP,'c')
set(gca,'XLim',[0 360]); set(gca,'YLim',[0 2.0]);
set(gcf,'OuterPosition', [ 200 1000 1200 400]);
set(gca,'Position',[.05 .1 .9 .8 ]);
ylabel('Azimuthally-Summed Precip Rate Ratios, 17-70km');
xlabel('Azimuth, degrees');
title(['Along-beam Integrated Precip Comparisons (filtered on RATE_KDP exists).'], ...
       'FontWeight','bold', 'FontSize', 11);
lgnd = {'RATE_ZH/RATE_KDP, both @ 0.5' 'RATE_ZH/RATE_KDP, both @ 1.5' ...
        'RATE_ZH/RATE_KDP, both @ 2.5' 'RATE_ZH/RATE_KDP, both @ 3.5'};
legend(lgnd,  'Interpreter', 'none','Location','SouthWest');
tHandle = text( 'String', nowtag, 'Units', 'normalized', ...
                'Position', [0.9,.92],'Color', [.7 .7 .7] );
hold off

figure;
plot(1:360,p_az.e1.RATE_ZH./p_az.e3.RATE_KDP)
hold on
plot(1:360,p_az.e2.RATE_ZH./p_az.e3.RATE_KDP,'r')
plot(1:360,p_az.e3.RATE_ZH./p_az.e3.RATE_KDP,'k')
plot(1:360,p_az.e4.RATE_ZH./p_az.e3.RATE_KDP,'c')
set(gca,'XLim',[0 360]); set(gca,'YLim',[0 2.0]);
set(gcf,'OuterPosition', [ 300 1000 1200 400]);
set(gca,'Position',[.05 .1 .9 .8 ]);
ylabel('Azimuthally-Summed Precip Rate Ratios, 17-70km');
xlabel('Azimuth, degrees');
title(['Ratios of Along-beam Integrated Precip Rates, RATE_ZH compared to RATE_KDP @ 2.5 deg (filtered on RATE_KDP exists).'], ...
       'FontWeight','bold', 'FontSize', 11);
lgnd = {' @ 0.5' ' @ 1.5' ...
        ' @ 2.5' ' @ 3.5'};
legend(lgnd,  'Interpreter', 'none','Location','SouthWest');
tHandle = text( 'String', nowtag, 'Units', 'normalized', ...
                'Position', [0.9,.92],'Color', [.7 .7 .7] );
hold off

figure
plot(1:360,p_az.e1.RATE_KDP./p_az.e4.RATE_KDP)
hold on
plot(1:360,p_az.e2.RATE_KDP./p_az.e4.RATE_KDP,'r')
plot(1:360,p_az.e3.RATE_KDP./p_az.e4.RATE_KDP,'k')
plot(1:360,p_az.e4.RATE_KDP./p_az.e4.RATE_KDP,'c')
set(gca,'XLim',[0 360]); set(gca,'YLim',[0 2.0]);
set(gcf,'OuterPosition', [ 400 1000 1200 400]);
set(gca,'Position',[.05 .1 .9 .8 ]);
ylabel('Azimuthally-Summed Precip Rate Ratios, 17-70km');
xlabel('Azimuth, degrees');
title(['Ratios of Along-beam Integrated Precip Rates, RATE_KDP compared to RATE_KDP@3.5 (filtered on RATE_KDP exists).'], ...
       'FontWeight','bold', 'FontSize', 11);
lgnd = {'@ 0.5' '@ 1.5' '@ 2.5' '@ 3.5'};
legend(lgnd,  'Interpreter', 'none','Location','SouthWest');
tHandle = text( 'String', nowtag, 'Units', 'normalized', ...
                'Position', [0.9,.92],'Color', [.7 .7 .7] );
hold off

figure
plot(1:360,p_az.e1.RATE_ZH./p_az.e4.RATE_ZH)
hold on
plot(1:360,p_az.e2.RATE_ZH./p_az.e4.RATE_ZH,'r')
plot(1:360,p_az.e3.RATE_ZH./p_az.e4.RATE_ZH,'k')
plot(1:360,p_az.e4.RATE_ZH./p_az.e4.RATE_ZH,'c')
set(gca,'XLim',[0 360]); set(gca,'YLim',[0 2.0]);
set(gcf,'OuterPosition', [ 500 1000 1200 400]);
set(gca,'Position',[.05 .1 .9 .8 ]);
ylabel('Azimuthally-Summed Precip Rate Ratios, 17-70km');
xlabel('Azimuth, degrees');
title(['Ratios of Along-beam Integrated Precip Rates, RATE_ZH compared to RATE_ZH@3.5 (filtered on RATE_KDP exists).'], ...
       'FontWeight','bold', 'FontSize', 11);
lgnd = {'@ 0.5' '@ 1.5' '@ 2.5' '@ 3.5'};
legend(lgnd,  'Interpreter', 'none','Location','SouthWest');
tHandle = text( 'String', nowtag, 'Units', 'normalized', ...
                'Position', [0.9,.92],'Color', [.7 .7 .7] );
hold off

figure
plot(1:360,p_az.e1.RATE_ZH./p_az.e4.RATE_KDP)
hold on
plot(1:360,p_az.e2.RATE_ZH./p_az.e4.RATE_KDP,'r')
plot(1:360,p_az.e3.RATE_ZH./p_az.e4.RATE_KDP,'k')
plot(1:360,p_az.e4.RATE_ZH./p_az.e4.RATE_KDP,'c')
set(gca,'XLim',[0 360]); set(gca,'YLim',[0 2.0]);
set(gcf,'OuterPosition', [ 600 1000 1200 400]);
set(gca,'Position',[.05 .1 .9 .8 ]);
ylabel('Azimuthally-Summed Precip Rate Ratios, 17-70km');
xlabel('Azimuth, degrees');
title(['Ratios of Along-beam Integrated Precip Rates, RATE_ZH compared to RATE_KDP@3.5 (filtered on RATE_KDP exists).'], ...
       'FontWeight','bold', 'FontSize', 11);
lgnd = {'@ 0.5' '@ 1.5' '@ 2.5' '@ 3.5'};
legend(lgnd,  'Interpreter', 'none','Location','SouthWest');
tHandle = text( 'String', nowtag, 'Units', 'normalized', ...
                'Position', [0.9,.92],'Color', [.7 .7 .7] );
hold off

ymax = 1.5e6; figure;
mydist = sum(totbins.e3.RATE_ZH');
tot_gates = sum(mydist)
bar(1:200,mydist);
set(gcf,'OuterPosition', [ 0 0 900 400]);
set(gca,'Position',[.1 .1 .8 .8 ]);
set(gca,'XLim',[0 200]); set(gca,'YLim',[0 ymax]);
xlabel('Computed Rain Rate  (mm/hr)');
ylabel('Number Occurance');
title(['Single-gate Rain Rate NumDist, 2.5-deg tilt, DYNAMO Entire ' ...
       'Project.   RATE_ZH'],'FontWeight','bold', 'FontSize', 11 );
tHandle = text( 'String', nowtag, 'Units', 'normalized', ...
                'Position', [0.85,.92],'Color', [.7 .7 .7] );

figure;
mydist = sum(totbins.e3.RATE_Z_ZDR');
tot_gates = sum(mydist)
bar(1:200,mydist);
set(gcf,'OuterPosition', [ 100 100 900 400]);
set(gca,'Position',[.1 .1 .8 .8 ]);
set(gca,'XLim',[0 200]); set(gca,'YLim',[0 ymax]);
xlabel('Computed Rain Rate  (mm/hr)');
ylabel('Number Occurance');
title(['Single-gate Rain Rate NumDist, 2.5-deg tilt, DYNAMO Entire ' ...
       'Project.   RATE_Z_ZDR'],'FontWeight','bold', 'FontSize', 11 );
tHandle = text( 'String', nowtag, 'Units', 'normalized', ...
                'Position', [0.85,.92],'Color', [.7 .7 .7] );

figure;
mydist = sum(totbins.e3.RATE_HYBRID');
tot_gates = sum(mydist)
bar(1:200,mydist);
set(gcf,'OuterPosition', [ 200 200 900 400]);
set(gca,'Position',[.1 .1 .8 .8 ]);
set(gca,'XLim',[0 200]); set(gca,'YLim',[0 ymax]);
xlabel('Computed Rain Rate  (mm/hr)');
ylabel('Number Occurance');
title(['Single-gate Rain Rate NumDist, 2.5-deg tilt, DYNAMO Entire ' ...
       'Project.   RATE_HYBRID'],'FontWeight','bold', 'FontSize', 11 );
tHandle = text( 'String', nowtag, 'Units', 'normalized', ...
                'Position', [0.85,.92],'Color', [.7 .7 .7] );

figure;
mydist = sum(totbins.e3.RATE_KDP');
tot_gates = sum(mydist)
bar(1:200,mydist);
set(gcf,'OuterPosition', [ 300 300 900 400]);
set(gca,'Position',[.1 .1 .8 .8 ]);
set(gca,'XLim',[0 200]); set(gca,'YLim',[0 ymax]);
xlabel('Computed Rain Rate  (mm/hr)');
ylabel('Number Occurance');
title(['Single-gate Rain Rate NumDist, 2.5-deg tilt, DYNAMO Entire ' ...
       'Project.   RATE_KDP'],'FontWeight','bold', 'FontSize', 11 );
tHandle = text( 'String', nowtag, 'Units', 'normalized', ...
                'Position', [0.85,.92],'Color', [.7 .7 .7] );

figure;
mydist = sum(totbins.e3.RATE_KDP_ZDR');
tot_gates = sum(mydist)
bar(1:200,mydist);
set(gcf,'OuterPosition', [ 400 400 900 400]);
set(gca,'Position',[.1 .1 .8 .8 ]);
set(gca,'XLim',[0 200]);
set(gca,'YLim',[0 ymax]);
xlabel('Computed Rain Rate  (mm/hr)'); ylabel('Number Occurance');
title(['Single-gate Rain Rate NumDist, 2.5-deg tilt, DYNAMO Entire ' ...
       'Project.   RATE_KDP_ZDR'],'FontWeight','bold', 'FontSize', 11 );
tHandle = text( 'String', nowtag, 'Units', 'normalized', ...
                'Position', [0.85,.92],'Color', [.7 .7 .7] );
