function [polyup, polylow, Aup, Alow] = discharge_Area( X, Y, Xdup, Ydup, Xdlow, Ydlow )
%UNTITLED4 Summary of this function goes here
%   Xup, Yup, Xdown, Ydown, Aup, Adown
B = unique([X', Y'],'rows', 'stable');
X = B(:, 1); Y = B(:, 2);
trapp = polyshape(X, Y);
d_up = polyshape(Xdup, Ydup);
d_low = polyshape(Xdlow, Ydlow);
polyup = intersect(trapp, d_up);
polylow = intersect(trapp, d_low);

Aup = area(polyup); Alow = area(polylow);

% Xup = 2e10*ones(1, length(X)); Yup = Xup; Ydown = Xup; Xdown = Xup;
% for ii = 1 : length(X)
%     if Y(ii) >= dup, Xup(ii) = X(ii); Yup(ii) = Y(ii); end
%     if Y(ii) <= -ddown, Xdown(ii) = X(ii); Ydown(ii) = Y(ii) ; end
% end
% 
% Xup(Xup >= 1e10) = [];
% Yup(Yup >= 1e10) = [];
% Xdown(Xdown >= 1e10) = [];
% Ydown(Ydown >= 1e10) = [];
% 
% if length(Xup) >= 1, Aup = polyarea( Xup, Yup );
% else Xup = 0; Yup = 0; Aup = 0; end
% 
% if length(Xdown) >= 1, Adown = polyarea( Xdown, Ydown );
% else Xdown = 0; Ydown = 0; Adown = 0; end

end