%%
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] )
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;

[ n_j, ind_n ] = coisas_em_janelas( yn, round( [1 .1]./mean(diff(tn)) ), 'std_til' );
[ n_j2, ind_n ] = coisas_em_janelas( yn, round( [1 .1]./mean(diff(tn)) ), 'std' );
subplot( 5, 1, 4 )
plot( mean( tn(ind_n), 2 ), n_j, '.-r',  mean( tn(ind_n), 2 ), n_j2, '.-m' )
xlim( XLIM_MASTER )

[ M_j, ind_M ] = std_em_janelas( yM, round( [1 .1]./mean(diff(tM)) ) );
subplot( 5, 1, 5 )
plot( mean( tM(ind_M), 2 ), M_j, '.-k' )
xlim( XLIM_MASTER )
