function [Direction_3,Direction_4]=Direction_Edge(mesh,Base)

%--define the direction for the Mixed finite element method, the DOF is
%--edge integral with the tangential or norminal direction------------
% if Base = [], we define the direction for the finite element method
%-- define the local and global normal or tangent direction relation
%--------------------------------------------------------------------------

%--HEHU XIE----------------------------------------------------------------
%--------compute the base value at the integral points---------------------
Nr_elem=size(mesh.elem,1);
%----get the number of triangles and rectangles----------------------------
II3 = find(mesh.elem(:,4)<0);
Nr_elem3 = length(II3);
II4 = setdiff([1:Nr_elem]',II3);
Nr_elem4 = length(II4);
Direction_3 = [];
Direction_4 = [];
if nargin == 2
    %-----compute the direction of mixed finite element method-------------
    %----define the directions---------------------------------------------
    %----triangles----------------------------------------
    Direction_3 = [ones(Nr_elem3,3*Base.DOF_3(1)),-ones(Nr_elem3,3*sum(Base.DOF_3(1:2))),ones(Nr_elem3,Base.DOF_3(3))]; 
    Index       = find(mesh.elem(II3,2)==mesh.node4edge(mesh.edge(II3,1),1));
    Direction_3(Index,3*Base.DOF_3(1)+3*[0:Base.DOF_3(2)-1]+1) = 1;
    Index       = find(mesh.elem(II3,3)==mesh.node4edge(mesh.edge(II3,2),1));
    Direction_3(Index,3*Base.DOF_3(1)+3*[0:Base.DOF_3(2)-1]+2) = 1;
    Index       = find(mesh.elem(II3,1)==mesh.node4edge(mesh.edge(II3,3),1));
    Direction_3(Index,3*Base.DOF_3(1)+3*[0:Base.DOF_3(2)-1]+3) = 1;
    %---rectangles---------------------------------------
    Direction_4 = [ones(Nr_elem4,4*Base.DOF_4(1)),-ones(Nr_elem4,4*sum(Base.DOF_4(1:2))),ones(Nr_elem4,Base.DOF_4(3))]; 
    Index       = find(mesh.elem(II4,1)==mesh.node4edge(mesh.edge(II4,1),1));
    Direction_4(Index,4*Base.DOF_4(1)+4*[0:Base.DOF_4(2)-1]+1) = 1;
    Index       = find(mesh.elem(II4,2)==mesh.node4edge(mesh.edge(II4,2),1));
    Direction_4(Index,4*Base.DOF_4(1)+4*[0:Base.DOF_4(2)-1]+2) = 1;
    Index       = find(mesh.elem(II4,3)==mesh.node4edge(mesh.edge(II4,3),1));
    Direction_4(Index,4*Base.DOF_4(1)+4*[0:Base.DOF_4(2)-1]+3) = 1;
    Index       = find(mesh.elem(II4,4)==mesh.node4edge(mesh.edge(II4,4),1));
    Direction_4(Index,4*Base.DOF_4(1)+4*[0:Base.DOF_4(2)-1]+4) = 1;
end
if nargin ==1 
    %-----compute the direction of  finite element method------------------
    %------Triangle--------------------------------------------------------
    Direction_3 = -ones(Nr_elem3,3);
    Index       = find(mesh.elem(II3,2)==mesh.node4edge(mesh.edge(II3,1),1));
    Direction_3(Index,1) = 1;
    Index       = find(mesh.elem(II3,3)==mesh.node4edge(mesh.edge(II3,2),1));
    Direction_3(Index,2) = 1;
    Index       = find(mesh.elem(II3,1)==mesh.node4edge(mesh.edge(II3,3),1));
    Direction_3(Index,3) = 1;    
    %---rectangles---------------------------------------------------------
    Direction_4 = -ones(Nr_elem4,4);
    Index       = find(mesh.elem(II4,1)==mesh.node4edge(mesh.edge(II4,1),1));
    Direction_4(Index,1) = 1;
    Index       = find(mesh.elem(II4,2)==mesh.node4edge(mesh.edge(II4,2),1));
    Direction_4(Index,2) = 1;
    Index       = find(mesh.elem(II4,3)==mesh.node4edge(mesh.edge(II4,3),1));
    Direction_4(Index,3) = 1;
    Index       = find(mesh.elem(II4,4)==mesh.node4edge(mesh.edge(II4,4),1));
    Direction_4(Index,4) = 1;
    
end