function [Volume]=calcVolume(IntersectA, IntersectB,x1,x2)
% This function calculates the area between the intersections of IntersectA
% and IntersectB. IntersectA and IntersectB are the intersections between
% profile A and B, the intersections between wavebase and profile A resp.
% B, the intersections between profile A or B with MSL and the profile
% y-values. These IntersectA and IntersectB values are being calculated
% with calcIntersections. x1 and x2 are the lower and upper x-boundaries
% 
% 
% left limit is derived.
[row, column]=find((IntersectA(1,:)>=x1),1);

% right limit is derived
[rowinter, columninter]=find((IntersectA(1,:)<=x2));
row2=rowinter(end);
column2=columninter(end);

difference=[zeros(1,column-1),(IntersectA(2,column:column2)-IntersectB(2,column:column2)),zeros(1,(length(IntersectA(1,:))-column2))];
for j=1:length(difference)-1;
    Volume.all(j)=(difference(j))*(IntersectB(1,j+1)-IntersectB(1,j));
end

Volume.erosion=sum(Volume.all((Volume.all>0)));
Volume.accretion=abs(sum(Volume.all((Volume.all<0))));
Volume.total=sum(Volume.all);

% not in use
% % calculates the area of profile A between the lower and upper x-boundary of 
% for j=column+1:column2;
%     Opp_A(j)=(abs((IntersectA(2,j))+(IntersectA(2,(j-1))))/2)*(IntersectA(1,j)- IntersectA(1,(j-1)));
% end
% 
% % calculates the area of profile B between the lower and upper x-boundary of
% for j=column+1:column2;
%     Opp_B(j)=(abs((IntersectB(2,j))+(IntersectB(2,(j-1))))/2)*(IntersectB(1,j)- IntersectB(1,(j-1)));
% end