% intVScount
clear;
close all

data = read_nc_data;


%% take measurement IVb
intervall = 1800; %seconds
delta_t = 1/24/60/60*intervall;
salti_nr = [1 4];

clear epoch int_par U_threshold

t = 1; go =1;
while go
    if (data.time_begin(1) + (t-1)*delta_t) >data.time_end(6)
        break
    end
    t
    time_index = data.time_num>data.time_begin(1) + (t-1)*delta_t & ...
        data.time_num<data.time_begin(1)+t*delta_t;
    
    
    %     time_index = data.time_num>data.time_begin(5) & data.time_num<data.time_end(5);
    
    % determine intermittency
    epoch(t) = data.time_begin(1) + t*delta_t-0.5*delta_t;
    [U_mean(t),U_std(t),U_mean_conf(t,:),U_std_conf(t,:)] = normfit(data.wind1(time_index,1));
    
    int_par(1,t) = 1-sum(data.Salti(time_index,salti_nr(1))==0)/length(data.Salti(time_index,salti_nr(1)));
    U_threshold(1,t) = icdf('Normal',1-int_par(1,t),U_mean(t),U_std(t));
    tot_count(1,t) = sum(data.Salti(time_index,salti_nr(1)));
    
    int_par(2,t) = 1-sum(data.Salti(time_index,salti_nr(2))==0)/length(data.Salti(time_index,salti_nr(2)));
    U_threshold(2,t) = icdf('Normal',1-int_par(2,t),U_mean(t),U_std(t));
    tot_count(2,t) = sum(data.Salti(time_index,salti_nr(2)));
    
    t=t+1;
end

figure
title(['time intervall = ' num2str(intervall) 's'])
plot(tot_count(1,:),int_par(1,:),'.');
hold all
plot(tot_count(2,:),int_par(2,:),'s');
xlabel('Total counts')
ylabel('intermittency (\lambda_p)')
ylim([0 1])
set(gcf,'PaperPosition',[0.634517 6.34517 10 5])

figure
title(['time intervall = ' num2str(intervall) 's'])
plot(int_par(1,:),tot_count(1,:),'.');
hold all
plot(int_par(2,:),tot_count(2,:),'s');
ylabel('Total counts')
xlabel('intermittency (\lambda_p)')
xlim([0 1])
