      SUBROUTINE AddLigne(i,n1,n2,n3,n4,ind_zmat,val_zmat,x,y,z)

!----------------------------------------------------------------------
!  Copyright 2003-2014 Ecole Normale Supérieure de Lyon, 
!  Centre National de la Recherche Scientifique,
!  Université Claude Bernard Lyon 1. All rights reserved.
!
!  This work is registered with the Agency for the Protection of Programs 
!  as IDDN.FR.001.100009.000.S.P.2014.000.30625
!
!  Authors: P. Fleurat-Lessard, P. Dayal
!  Contact: optnpath@gmail.com
!
! This file is part of "Opt'n Path".
!
!  "Opt'n Path" is free software: you can redistribute it and/or modify
!  it under the terms of the GNU Affero General Public License as
!  published by the Free Software Foundation, either version 3 of the License,
!  or (at your option) any later version.
!
!  "Opt'n Path" is distributed in the hope that it will be useful,
!  but WITHOUT ANY WARRANTY; without even the implied warranty of
!
!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
!  GNU Affero General Public License for more details.
!
!  You should have received a copy of the GNU Affero General Public License
!  along with "Opt'n Path". If not, see <http://www.gnu.org/licenses/>.
!
! Contact The Office of Technology Licensing, valorisation@ens-lyon.fr,
! for commercial licensing opportunities.
!----------------------------------------------------------------------

      use Path_module, only : Nat, KINT, KREAL

      integer(KINT) :: ind_zmat(Nat, 5)
      real(KREAL) ::  x(Nat), y(Nat), z(Nat), val_zmat(Nat, 3)

      real(KREAL) :: vx1,vy1,vz1,norm1
      real(KREAL) ::  vx2,vy2,vz2,norm2
      real(KREAL) ::  vx3,vy3,vz3,norm3
      real(KREAL) ::  vx4,vy4,vz4,norm4
      real(KREAL) ::  vx5,vy5,vz5,norm5
      real(KREAL) ::  val,val_d

!     WRITE(IOOUT,*) 'Addligne:',i,n1,n2,n3,n4

      CALL vecteur(n2,n1,x,y,z,vx1,vy1,vz1,norm1)

      CALL vecteur(n2,n3,x,y,z,vx2,vy2,vz2,norm2)
      val=angle(vx1,vy1,vz1,norm1, &
           vx2,vy2,vz2,norm2)

      CALL vecteur(n3,n4,x,y,z,vx3,vy3,vz3,norm3)
      CALL produit_vect(vx1,vy1,vz1, &
           vx2,vy2,vz2, &
           vx4,vy4,vz4,norm4)
      CALL produit_vect(vx3,vy3,vz3, &
           vx2,vy2,vz2, &
           vx5,vy5,vz5,norm5)

      val_d=angle_d(vx4,vy4,vz4,norm4, &
           vx5,vy5,vz5,norm5, &
           vx2,vy2,vz2,norm2)

!     write(*,11) n1,n2,norm1,n3,val,n4,val_d
! 11   format (2(1x,i3),1x,f8.4,2(1x,i3,1x,f8.3))

      ind_zmat(i,1)=n1
      ind_zmat(i,2)=n2
      ind_zmat(i,3)=n3
      ind_zmat(i,4)=n4
      ind_zmat(i,5)=0
      val_zmat(i,1)=norm1
      val_zmat(i,2)=val
      val_zmat(i,3)=val_d

!     WRITE(*,*) "Addligne",i,n1,n2,n3,n4,norm1,val,val_d
      END


