function analyze_this(info, dirs)

%% input
test        = 'B4';
file        = 'b_4.mat';
plotting    = 0;
% model id time
idtime      = [200    1000];
% data id time
idtime_data = [150     500];  
% Filter Frequency
fb          = 0.1465;


%% read xboutput
fname            = fullfile(dirs.output, 'xboutput.nc');
point_zs         = nc_varget(fname, 'point_zs'); 
point_u          = nc_varget(fname, 'point_u'); 
point_zb         = nc_varget(fname, 'point_zb'); point_zb = squeeze(point_zb(1,:));
globalx          = nc_varget(fname, 'globalx'); 
t                = nc_varget(fname, 'globaltime');
zb               = nc_varget(fname, 'zb'); zb = squeeze(zb(1,:,:));
zs               = nc_varget(fname, 'zs');
u                = nc_varget(fname, 'u');
hh               = nc_varget(fname, 'hh');
point_time       = nc_varget(fname, 'pointtime');
pointx           = nc_varget(fname, 'pointx');

%% create spectrum
idwanted    = point_time > idtime(1) & point_time < idtime(2);
for i = 1:length(pointx)
    result.time(i,:)    = point_time(idwanted);
    result.wl(i,:)      = squeeze(point_zs(idwanted,i));
    % Spectrum
    [fx, result.vy(i,:)]= spectrumsimple(point_time(idwanted), squeeze(point_zs(idwanted,i)), 'fresolution', 0.01,'detrend',1, 'figures', plotting);
    result.fx = fx;  
    result.Hs(i)        = swan_hs(fx,result.vy(i,:));
    
    %filter low frequency 
    [result.zs_l(i,:) , Hs_l]   = Band_filter(result.time(i,:), result.wl(i,:), fb);
    [fx, result.vy_low(i,:)]    = spectrumsimple(point_time(idwanted), result.zs_l(i,:), 'fresolution', 0.01,'detrend',1, 'figures', plotting);
    result.Hs_low_f(i)          = swan_hs(fx, result.vy_low(i,:));
end

%% open data
% A files
dat = load(fullfile(dirs.data, file));
dat = dat.b_4;
dat.slope.vel = dat.slope.EMS./10;
dat.slope.horvel = dat.slope.vel(:,[2 4 6 8]);
dat.slope.vervel = dat.slope.vel(:,[1 3 5 7]);

%% create time slice
f = 25;
dt = 1/f;

%% flume set-up
gauge_loc = dat.slope.positions;
gauge_loc(80) = 36.5;
EMS_loc = dat.slope.EMSpositions;
bed = ones(1,40*10+1) * 0.7;
bed(86:end) = linspace(0.7,-0.2,316);
bed_gauge = interp1(linspace(0,40,401),bed, gauge_loc);

% Boundary starts at x=6
gauge_loc= gauge_loc - 6;

%% create spectrum data

wl = dat.slope.wavsig3;
for i = 1:length(pointx)
    nt = length(dat.slope.wavsig3(:,i));
    time =linspace(0,nt*dt-dt,nt);
    idwanted    = time > idtime_data (1) & time < idtime_data (2);
    data.time(i,:) = time(idwanted);
    
    offset(i) = mean(wl(1:200,i));
    data.wl(i,:) =  squeeze(wl(idwanted,i)) - offset(i);
    %% create spectrum
    [fx1, data.vy(i,:)] = spectrumsimple(squeeze(time(idwanted)), data.wl(i,:), 'fresolution', 0.01,'detrend',1, 'figures', 0);
    data.Hs(i) = swan_hs(fx1,data.vy(i,:));
    data.fx = fx1;
    %low freq
    [data.zs_l(i,:), Hs_low] = Band_filter(data.time(i,:), data.wl(i,:), fb);
    [fx1, data.vy_low(i,:)] = spectrumsimple(squeeze(time(idwanted)), data.zs_l(i,:), 'fresolution', 0.01,'detrend',1, 'figures', 0);
    data.Hs_low_f(i) = swan_hs(fx1, data.vy_low(i,:));
end


%% plotten
time_slice = 50;

%% flume
figure
plot(globalx, squeeze(zs(time_slice,1,:)),'linewidth',2)
hold on
plot(globalx, zb(:),'linewidth',2)
xlabel('Distance[m]')
ylabel('Elevation [m]')


%% plot Hs
figure
subplot(2,1,1)
plot(gauge_loc,data.Hs(:)/sqrt(2),'ko','MarkerFaceColor', 'b','MarkerEdgeColor',[1 17 181]./255,'MarkerSize',8,'linewidth',1)
hold on
plot(pointx, result.Hs(:)/sqrt(2),'linewidth',3,'color',[205 5 9]./255)
title(['Total wave height'])
ylabel('H_{rms} [m]')
xlabel('Distance [m]')
legend('Data','XBeach')

subplot(2,1,2)
plot(gauge_loc, data.Hs_low_f(:)/sqrt(2),'ko','MarkerFaceColor', 'b','MarkerEdgeColor',[1 17 181]./255,'MarkerSize',8,'linewidth',1)
hold on
plot(pointx, result.Hs_low_f(:)/sqrt(2),'linewidth',3,'color',[205 5 9]./255)
ylabel('H_{rms,lf} [m]')
xlabel('Distance [m]')
legend('Data','XBeach')
title(['Filtered signal (f=' num2str(fb) ' Hz)'])

xb_write_plot(gcf, dirs.output, 'B4');

save('data_B4','data','gauge_loc')
save('xb_B4','result','pointx')
end




