SUBROUTINE ReadGeom_turbomole

!----------------------------------------------------------------------
!  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
  Use Io_module

  IMPLICIT NONE

  CHARACTER(132) :: Line

  INTEGER(KINT) :: I, J, JStart

  LOGICAL :: Debug

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

  debug=valid('Read_geom').or.Valid('readgeom_turbomole')

 if (debug) Call Header("Entering ReadGeom_Turbomole")

  if (debug) WRITE(*,*) "NgeomI:",NGeomI

     DO I=1,NGeomI
        IF (DEBUG) WRITE(*,*) "Reading Geom :",I
        JStart=1
! read the $coord line, or $user-defined, or $end
        Line='$ok'
        DO WHILE (Line(1:1).EQ."$")
           READ(IOIN,'(A)') Line 
           Line=AdjustL(Line)
        END DO
        J=1
        READ(Line,*) XyzGeomI(I,1:3,J),AtName(J)
        DO J=2,NAt
           READ(IOIN,*) XyzGeomI(I,1:3,J),AtName(J)
        END DO
        XyzGeomI(I,:,:)= XyzGeomI(I,:,:)*a0
        If (Debug) THEN
           WRITE(*,*) "Geom ",I
           DO J=1,NAt
              WRITE(*,'(1X,A2,3(1X,F15.6))') AtName(J),XyzGeomI(I,1:3,J)
           END DO
        END IF
     END DO

 if (debug) Call Header("Exiting ReadGeom_turbomole")

END SUBROUTINE ReadGeom_turbomole
