clear all; clc; close all;

titlestr = { 'Cdc13T', 'preMPF', 'Ste9', 'Slp1T', 'Slp1', ...
                                          'IEP', 'Rum1T', 'SK', 'MPF', 'Mass'};
                                      
ismutant = false;

if ismutant
    YeastType = 'DM';
else
    YeastType = 'WT';
end

tmax = 600;
systemsize = 5000;

% [htimecourse,hcyclestats] = ccmodel(systemsize,ismutant);
% solmac = htimecourse(tmax,false);
% solmes = htimecourse(tmax,true);
% 
% save(['ccdata', YeastType], 'solmac', 'solmes')
% 

load(['ccdata_', YeastType], 'solmac', 'solmes')


numax = 2; dy = .02;

figure('Name', ['Mean mass and MPF for ', YeastType])
ax0 = axes('Visible', 'off');
pos0 = get(ax0, 'Position');
pos0(2) = 0.13;
pos0(4) = (pos0(4) - (numax-1)*dy)/numax;

[pos{1:2}] = deal(pos0);

ax = zeros(1,numax);
ax(1) = axes('Position', pos{1});

for i=2:numax
    pos{i}(2) = pos{i-1}(2) + pos0(4) + dy;
    ax(i) = axes('Position', pos{i});
end

spind = [9,10];

for i=1:numax
    macy = solmac.y(:,spind(i));
    mesy = solmes.y(:,spind(i));
    hPlot(i,:) = plot(ax(i), solmac.t, macy, '-.b', solmes.t, mesy, '-r');
    %----------------------------------------------------------------------
    ylabel(ax(i), [titlestr{spind(i)}, ' (a.u.)'])
    temp = [ solmac.y(:,spind(i)); solmes.y(:,spind(i)) ];
    mintemp = min([macy;mesy]);
    maxtemp = max([macy;mesy]);
    mintemp = (1-0.1*sign(mintemp))*mintemp;
    maxtemp = (1+0.1*sign(maxtemp))*maxtemp;    
    ylim(ax(i), [mintemp maxtemp])    
end

set(ax, 'Box', 'on', 'TickDir', 'in')
set(ax(2:numax), 'XTickLabel', [])

set(hPlot(:,1), 'LineWidth', 1.2)

xlabel(ax(1), 'Time (min)')

%%

numax = 2; dy = .02;

figure('Name', ['(co)variance of/between Cdc13T and PreMPF for ', YeastType])
ax0 = prepaxes('Visible', 'off');
pos0 = get(ax0, 'Position');
pos0(2) = 0.13;
pos0(4) = (pos0(4) - (numax-1)*dy)/numax;

[pos{1:2}] = deal(pos0);

ax = zeros(1,numax);
ax(1) = axes('Position', pos{1});

for i=2:numax
    pos{i}(2) = pos{i-1}(2) + pos0(4) + dy;
    ax(i) = axes('Position', pos{i});
end

for i=1:numax
    xcov = solmes.w(:,solmes.kout(i,1));
    
    plot(ax(i), solmes.t, xcov);
    %----------------------------------------------------------------------
    
    mintemp = min(xcov);
    maxtemp = max(xcov);
    mintemp = (1-0.1*sign(mintemp))*mintemp;
    maxtemp = (1+0.1*sign(maxtemp))*maxtemp;    
    ylim(ax(i), [mintemp maxtemp])     
end

ylabel(ax(1), '$\sigma_{11}$', 'Interpreter', 'latex')
ylabel(ax(2), '$\sigma_{12}$', 'Interpreter', 'latex')

set(ax, 'Box', 'on', 'TickDir', 'in')
set(ax(2:numax), 'XTickLabel', [])

if ~ismutant
    set(ax, 'YTick', [0 0.01 0.02])
end

xlabel(ax(1), 'Time (min)')

%%------------------------------------------------------------------------
