function [IntersectA IntersectB intersections]=CalcintersectionsArea(A,B,MSLevel,wavebase,xas)

% intersections between two profiles
[intersections.A.B]=calcIntersections(A,B,xas);

% intersections between MSL and profile A
MSL=MSLevel*ones(1,length(A));
[intersections.A.MSL]=calcIntersections(A,MSL,xas);

% intersections between MSL and profile B
MSL=MSLevel*ones(1,length(B));
[intersections.B.MSL]=calcIntersections(MSL,B,xas);

% intersections between wavebase and profile A
wavebaseheight=wavebase*ones(1,length(A));
[intersections.A.wavebase]=calcIntersections(wavebaseheight,A,xas);

% intersections between wavebase and profile B
wavebaseheight=wavebase*ones(1,length(B));
[intersections.B.wavebase]=calcIntersections(wavebaseheight,B,xas);

all_x_A=[xas;A];
all_x_B=[xas;B];

intersection_and_A=[intersections.A.B,all_x_A];
[row, column]=sort(intersection_and_A(1,:));
IntersectA=intersection_and_A(:,column);

intersection_and_B=[intersections.A.B,all_x_B];
[row, column]=sort(intersection_and_B(1,:));
IntersectB=intersection_and_B(:,column);

%delete double points

hulprow1=[1,IntersectA(1,:)];
hulprow2=[IntersectA(1,:),1];
[rij,kolom]=find((hulprow2-hulprow1)==0);

IntersectA(:,kolom)=[];

hulprow3=[1,IntersectB(1,:)];
hulprow4=[IntersectB(1,:),1];
[rij2,kolom2]=find((hulprow4-hulprow3)==0);

IntersectB(:,kolom2)=[];
