function analyze_zebra(info, dirs)

% read measurements
m       = load(fullfile(dirs.data, 'T01data.mat'));

% read dimensions
d       = xb_read_dims;
t       = [0 0.1 0.3 1.0 2.04 6.0];
[mn i]  = closest(1000+t*3600, d.t);

% read output
xbo1    = xb_read_output(pwd, 'vars', 'zb', 'index', i);
xbo2    = xs_peel(xb_read_output(pwd, 'vars', {'zb' 'ccg' 'dzbed' 'pbbed'}, 'index', [0 d.nt]));
if (size(xbo2.dzbed,1) > 2)
    % apply indexing, because it does not work for netcdf.
    xbo2.dzbed(2:end-1,:,:,:) = [];
    xbo2.ccg(2:end-1,:,:,:) = [];
    xbo2.pbbed(2:end-1,:,:,:,:) = [];
    xbo2.zb(2:end-1,:,:) = [];
end

% plot output
% xb_plot_profile(xbo1, 'measured', [m.x' m.z']);

% xb_write_plot(gcf, dirs.output, 'profiles');

x       = repmat(d.x',d.bed_layers+1,1)';

p       = [];
cmap    = get_cmap();
for i = 1:2

    fh = figure; hold on;

    colormap(cmap);

    z           = zeros(d.globalx,d.bed_layers+1);
    c           = zeros(d.globalx,d.bed_layers+1);

    dz          = z;
    dz(:,2:end) = squeeze(cumsum(xbo2.dzbed(i,:,:,:),2))';

    z           = repmat(squeeze(xbo2.zb(i,:,:)),1,d.bed_layers+1) - dz;

    c(:,2:end)  = squeeze(xbo2.pbbed(i,1,:,:,:))';
    c(:,1)      = c(:,2);

    pcolor(x,z,c);

    view(2);
    colorbar;
    caxis([0 1]);
    shading flat;

    p(1)        = plot(d.x',squeeze(xbo2.zb(1,:,:)),':k','LineWidth',2,'DisplayName','Initial bed level');

    plot(d.x',squeeze(xbo2.zb(i,:,:)),'-k','LineWidth',2);

    p(2)        = plot(d.x',2650*squeeze(xbo2.ccg(i,1,:,:)),'LineWidth',2,'Color',cmap(1,:),  'DisplayName','Concentration blue');
    p(3)        = plot(d.x',2650*squeeze(xbo2.ccg(i,2,:,:)),'LineWidth',2,'Color',cmap(end,:),'DisplayName','Concentration red');

    axis([41 220 -4.5 2]);

    legend(p,'location','SouthEast');

    title('Grain distribution and sediment concentrations');

    xlabel('distance [m]')
    ylabel('height [m] and concentration (g/l)');

    xb_write_plot(fh, dirs.output, sprintf('fig%1d', i));

end

% remove all but the first and last outputs
for iv = 2:length(xbo1.data)
    if length(size(xbo1.data(iv).value)) == 3
        xbo1.data(iv).value = xbo1.data(iv).value([1 end],:,:);
    end
end

xb_plot_profile(xbo1,'measured',[m.x' m.z(end,:)'])
title(['profiles ' info.test ' ' info.run], 'interpreter', 'none')
xb_write_plot(gcf, dirs.output, 'final_profiles')

end

function cmap = get_cmap()

% red-yellow-blue
cmap= [ 0.0784    0.1686    0.5490
        0.0834    0.1731    0.5461
        0.0883    0.1776    0.5431
        0.0933    0.1820    0.5402
        0.0983    0.1865    0.5372
        0.1032    0.1910    0.5343
        0.1082    0.1954    0.5313
        0.1438    0.2276    0.5101
        0.1795    0.2598    0.4888
        0.2152    0.2920    0.4676
        0.2509    0.3242    0.4463
        0.2865    0.3564    0.4250
        0.3222    0.3885    0.4038
        0.3579    0.4207    0.3825
        0.3935    0.4529    0.3613
        0.4292    0.4851    0.3400
        0.4649    0.5173    0.3188
        0.5006    0.5494    0.2975
        0.5362    0.5816    0.2763
        0.5719    0.6138    0.2550
        0.6076    0.6460    0.2338
        0.6433    0.6782    0.2125
        0.6789    0.7104    0.1913
        0.7146    0.7425    0.1700
        0.7503    0.7747    0.1488
        0.7860    0.8069    0.1275
        0.8216    0.8391    0.1063
        0.8573    0.8713    0.0850
        0.8930    0.9035    0.0638
        0.9287    0.9356    0.0425
        0.9643    0.9678    0.0213
        1.0000    1.0000         0
        0.9936    0.9647         0
        0.9871    0.9293         0
        0.9807    0.8940         0
        0.9742    0.8586         0
        0.9678    0.8233         0
        0.9613    0.7879         0
        0.9549    0.7526         0
        0.9485    0.7172         0
        0.9420    0.6819         0
        0.9356    0.6465         0
        0.9291    0.6112         0
        0.9227    0.5758         0
        0.9163    0.5405         0
        0.9098    0.5051         0
        0.9034    0.4698         0
        0.8969    0.4344         0
        0.8905    0.3991         0
        0.8840    0.3637         0
        0.8776    0.3284         0
        0.8712    0.2931         0
        0.8647    0.2577         0
        0.8583    0.2224         0
        0.8518    0.1870         0
        0.8513    0.1841         0
        0.8508    0.1812         0
        0.8502    0.1783         0
        0.8497    0.1754         0
        0.8492    0.1724         0
        0.8487    0.1695         0
        0.8481    0.1666         0
        0.8476    0.1637         0
        0.8471    0.1608         0
];

end