 clear all
%XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

bmin=0.5;  % Lower threshold for magnitude to consider error

spec='bz';
name='ACC_final_';
load ([name spec '_field_and_sem'])
%semz=sem;
%ogmfz=ogmf;
non0=find(abs(ogmf)>bmin);
bznon=abs(ogmf(non0));
semz1=sem(non0);
del=semz1./bznon; bz=del;
nz10=length(find(del<=0.1))/length(del)
nz20=length(find(del<=0.2))/length(del)
nz30=length(find(del<=0.3))/length(del)
%% Physical error <30% of mean magnitude value
mean_error_z_nT = mean(semz1(find(del<=0.3)))
number_of_valus_less_bmin_z=100*length(del)/161/1441
clear sem ogmf

disp(' ')
spec='bx';
name='ACC_final_';
load ([name spec '_field_and_sem'])
%semx=sem;
%ogmfx=ogmf;
non0=find(abs(ogmf)>bmin);
bxnon=abs(ogmf(non0));
semx1=sem(non0);
del=semx1./bxnon; bx=del;
nx10=length(find(del<=0.1))/length(del)
nx20=length(find(del<=0.2))/length(del)
nx30=length(find(del<=0.3))/length(del)
%% Physical error <30% of mean magnitude value
mean_error_x_nT = mean(semx1(find(del<=0.3)))
number_of_valus_less_bmin_x=100*length(del)/161/1441

figure
subplot(121)
hist(bz,100,'k')
xlim([0 0.8])
ylim([0 10000])
grid on
set(gca,'position',[ 0.1300   0.2   0.3232   0.6150])
xlabel('\delta_z')
ylabel('Frequency')
text(0.65,600,'a)','FontSize',10)
line([0.1 0.1],[0 10000],'Color','r')
line([0.2 0.2],[0 10000],'Color','r')
line([0.3 0.3],[0 10000],'Color','r')

subplot(122)
hist(bx,100,'k')
xlim([0 0.8])
ylim([0 10000])
grid on
set(gca, 'position',[ 0.5818   0.2   0.3232   0.6150])
xlabel('\delta_x')
ylabel('Frequency')
text(0.65,900,'b)','FontSize',10)
line([0.1 0.1],[0 10000],'Color','r')
line([0.2 0.2],[0 10000],'Color','r')
line([0.3 0.3],[0 10000],'Color','r')

%print ("-djpg", 'ACC_two_sem_hist')


