 SUBROUTINE PrintAnaList(FileUnit)
! This routines prints the list of geometrical variables to monitor

!----------------------------------------------------------------------
!  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 VarTypes
  use Path_module
  use Io_module

  IMPLICIT NONE

  INTERFACE
     function valid(string) result (isValid)
       CHARACTER(*), intent(in) :: string
       logical                  :: isValid
     END function VALID

     SUBROUTINE die(routine, msg, file, line, unit)

       Use VarTypes
       Use io_module

       implicit none

       character(len=*), intent(in)           :: routine, msg
       character(len=*), intent(in), optional :: file
       integer(KINT), intent(in), optional      :: line, unit

     END SUBROUTINE die

  END INTERFACE
! Input
! Unit to print the description
  INTEGER(KINT) :: FileUnit

! Local
  LOGICAL :: Debug
  INTEGER(KINT) :: I,J,At1,At2,At3,At4

  Debug=Valid('PrintAnaList')

  If (Debug) Call Header("Entering PrintAnaList")

  WRITE(FileUnit,'(A)') "# Centers of mass used "

  CurBary => Bary

  DO I=1,NbCom
     WRITe(*,*) "Dbg PrintAnalist: I,NbCom",I,NbCom
     At1=CurBary%ListAtoms(0)
     if (debug)      WRITE(*,'("# c ",I4,20(A3,I3))') At1, &
                (AtName(CurBary%ListAtoms(j)),CurBary%ListAtoms(j),j=1,At1)

     WRITE(FileUnit,'("# c ",I4,20(A3,I3))') At1, &
                (AtName(CurBary%ListAtoms(j)),CurBary%ListAtoms(j),j=1,At1)
     if (associated(CurBary%Next)) CurBary=> CurBary%Next
  END DO

  WRITE(FileUnit,'(A)') "# Variables monitored "

  CurVar => GeomList
  DO I=1,NbVar
     SELECT CASE (CurVar%Type)
        CASE ('BOND') 
! this is a bond
           At1=CurVar%At1
           AT2=CurVar%At2
           if (debug) WRITE(*,'("# b ",2(1X,A,I3))') TRIM(AtName(At1)),At1,AtName(At2),At2
           WRITE(FileUnit,'("# b ",2(1X,A,I3))') TRIM(AtName(At1)),At1,AtName(At2),At2
        CASE ('ANGLE') 
! this is an angle
           At1=CurVar%At1
           AT2=CurVar%At2
           At3=CurVar%At3
           if (debug) WRITE(*,'("# a ",4(A3,I3))') AtName(At1),At1,AtName(At2),At2,AtName(At3),At3
           WRITE(FileUnit,'("# a ",4(A3,I3))') AtName(At1),At1,AtName(At2),At2,AtName(At3),At3
        CASE ('DIHEDRAL') 
! this is a dihedral
           At1=CurVar%At1
           AT2=CurVar%At2
           At3=CurVar%At3
           At4=CurVar%At4
           if (debug) WRITE(*,'("# d ",4(A3,I3))') AtName(At1),At1,AtName(At2),At2,AtName(At3),At3,AtName(At4),At4
           WRITE(FileUnit,'("# d ",4(A3,I3))') AtName(At1),At1,AtName(At2),At2,AtName(At3),At3,AtName(At4),At4
     END SELECT
     If (Associated(CurVar%Next)) CurVar => CurVar%next
  END DO

  If (Debug) Call Header("Exiting PrintAnaList")

END SUBROUTINE PrintAnaList
