%%
clear

DISP = 25285;
[ tI, yI ] = leia_TCABR( DISP, 'IP' );
[ tn, yn ] = leia_TCABR( DISP, 'ne' );
[ tM, yM ] = leia_TCABR( DISP, 'Mref' );

figure( 'position', [50 50 800 650] )
handle_MASTER = subplot( 5, 1, 1:3 );
plot( tI, yI*1e-3, '-b', tn, yn*1e-20, '-r', tM, yM/10, '-k' )
xlim( [25 160] )
ylim( [-0.1 0.2] )
ylabel( 'I_P (MA), n_e (10^{20}m^{-3}), Mirnov (a.u.)', 'fontsize', 16 )
% xlabel( 'time (ms)', 'fontsize', 16 )
legend( 'I_P', 'n_e', 'Mirnov', 'fontsize', 14 )
title( sprintf( 'TCABR #%d', DISP ), 'fontsize', 16 )
set( gca, 'fontsize', 14, 'tickdir', 'out' )
XLIM_MASTER = xlim;
YLIM_MASTER = ylim;
hold on

[X,Y,BUTTON] = ginput(2);

subplot( 5, 1, 4 )
% plot( tM( tM>=X(1) & tM<=X(2) ), yM( tM>=X(1) & tM<=X(2) ), '-k' )
% indSEL = find( tn>=X(1) & tn<=X(2) );
% plot( tn( indSEL ), yn( indSEL ), '-r' )
indSEL = find( tM>=X(1) & tM<=(X(1)+1) );
plot( tM( indSEL ), yM( indSEL ), '-m' )
axis tight
plot( handle_MASTER, [X(1) X(1)], YLIM_MASTER, '-m' )

subplot( 5, 1, 5 )
% plot( tM( tM>=X(1) & tM<=X(2) ), yM( tM>=X(1) & tM<=X(2) ), '-k' )
indSEL = find( tM>=X(2) & tM<=(X(2)+1) );
plot( tM( indSEL ), yM( indSEL ), '-g' )
axis tight
plot( handle_MASTER, [X(2) X(2)], YLIM_MASTER, '-g' )

