%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Weber AM, Wong FK, Tufford AR, Schlichter LC, Matveev V, Stanley EF
%        N-type Ca2+ channels carry the largest current: 
%    implications for nanodomains and transmitter release.
%
%              Nature Neuroscience 13: 1348-1350.
%
%      This script plots Figs. S6 & S8 using data produced
%              by CalC script GenerateData.par
%
%               Victor Matveev, August 8, 2012
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Darray = [0 0.05];    % Array of buffer diffusivities
ND = length(Darray);

kappa = 50;   % Buffering capacity
T     = 0.5;  % Simulation time

hold off;
cls    = {'b', 'r', 'k', 'c', 'm', 'g', 'y'};
lst    = {'-', '-.'};
prefix = {'N', 'L'};
ind    = 6;

for V = [65 40];
    
    figure(ind); 
    tstr = sprintf('Fig. S%d', ind);
    ind = ind + 2;
    lgnd = {};

    for j = 1 : ND;
        D = Darray(j);
        for i = 1 : length(prefix)
            fname = ['1Dr_V', num2str(V), '_Ca_', prefix{i}, '_kappa_', num2str(kappa), '_BD_', num2str(D), '_300x300.dat'];
            A = process(fname);
            I = find(A(1,1,:)>=T);
            it = I(1)-1;    
            lgnd = [ lgnd, ['I_{Ca,', prefix{i}, '} D_B=', num2str(D*1000), '\mum^2/s'] ];
            plot(A(2,:,it)*1000, PWR*log(A(3,:,it))/log(10), [cls{j}, lst{i}], 'linewidth', 2 ); hold on;
        end
    end

    set(gca,'box','off');
    axis([0 150 0 log(500)/log(10)]);
    grid on;

    if ind==2
        legend(lgnd);
    end;
    set(gca, 'YTick', [-1, 0, log(5)/log(10), 1, 2]);
    set(gca, 'YTickLabel', '0.1 uM | 1 uM | 5 uM | 10 uM | 100 uM');
    set(gca, 'XTick', [0:10:XM]);
    xlabel('Distance (nm)');
    ylabel('log [Ca^{2+}] (\muM)');
    tstr = sprintf('%s: Buffer capacity=%d; time=%.2g ms', tstr, kappa,A(1,1,it));
    title(tstr);
end
