 SUBROUTINE WriteInput_siesta(GeomCart,FileUnit)
!----------------------------------------------------------------------
!  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.
!----------------------------------------------------------------------

! This routine writes an input for Siesta

  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 WriteList(Input,Unit)
        ! This routine reads an input template for Siesta

       use VarTypes
       use Io_module

       IMPLICIT NONE

     ! Input
       TYPE (Input_line), POINTER, INTENT(IN) :: Input
       INTEGER(KINT), OPTIONAL, INTENT(IN) :: Unit
       
     END SUBROUTINE WriteList

  END INTERFACE

!Input
 ! Geometry in cartesian coordinates
  REAL(KREAL), INTENT (IN) :: geomcart(Nat,3)
! Unit to write to
  INTEGER(KINT), INTENT(IN) :: FileUnit
  
  LOGICAL :: Debug
  INTEGER(KINT) :: I,Iat

  Debug=Valid("WriteInput").OR.Valid("WriteInput_siesta")

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


  Call WriteList(Siesta_input,Unit=FileUnit)

  WRITE(FileUnit,*) 

  WRITE(FileUnit,'(1X,A)')  '%block AtomicCoordinatesAndAtomicSpecies' 

  DO I=1,Nat
     If (renum) THEN
        Iat=Order(I)
        WRITE(FileUnit,'(1X,3(1X,F15.8),1X,I5,1X,A)') GeomCart(Iat,:)/Siesta_Unit_Read, IdxSpecies(Iat),TRIM(Siesta_Paste(I))
     ELSE
        Iat=OrderInv(I)
        WRITE(FileUnit,'(1X,3(1X,F15.8),1X,I5,1X,A)') GeomCart(I,:)/Siesta_Unit_Read, IdxSpecies(Iat), TRIM(Siesta_Paste(Iat))
     END IF
  END DO

  WRITE(FileUnit,'(1X,A)')  '%endblock AtomicCoordinatesAndAtomicSpecies'
  WRITE(FileUnit,*) 



  if (debug) Call Header("Exiting WriteInput_Siesta")
  
END SUBROUTINE WRITEINPUT_SIESTA
