MODULE Io_Module
! This module contains all variables related to IO

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

  IMPLICIT NONE

  SAVE

  INTEGER(KINT) :: IOIN=11, IOOUT=12, IOCART=14
  INTEGER(KINT) :: IOGEOM=15, IODAT=16,IoGplot=17
  INTEGER(KINT), PARAMETER :: IOTMP=21,IOTMP2=22, IOTMP3=23
  INTEGER(KINT), PARAMETER :: IOERR=0
  CHARACTER(SCHARS) :: RunMode

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! System dependent delimiter for filename
! / on Linux; \ on windows, ...
  CHARACTER :: FileDelim


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! 
!  Some parameters for unit conversion
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  REAL(KREAL), PARAMETER :: au2eV=27.21183d0
  REAL(KREAL), PARAMETER :: ev2au= 1.d0/au2eV
  REAL(KREAL), PARAMETER :: au2kcal=627.509608d0
  REAL(KREAL), PARAMETER :: eV2kcal=23.06035d0

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Variables for Gaussian input
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  TYPE (Input_line), POINTER :: Gauss_Root, Gauss_End, Gauss_Comment
  TYPE (Input_Line), POINTER :: Current, Previous

  CHARACTER(LCHARS) :: Gauss_Charge
  CHARACTER(LCHARS), ALLOCATABLE :: Gauss_paste(:)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Variables for MOPAC input
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  TYPE (Input_line), POINTER :: Mopac_Root, Mopac_End, Mopac_Comment
  TYPE (Input_Line), POINTER :: CurCom
  CHARACTER(LCHARS) :: Mopac_EndGeom

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Variables for VASP input/output
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  CHARACTER(LCHARS) :: Vasp_Title, Vasp_Types, Vasp_comment, Vasp_direct
  CHARACTER(LCHARS) :: Vasp_Types_User
  REAL(KREAL) :: vasp_Param
  CHARACTER(4), ALLOCATABLE :: FFF(:,:) !(3,na)
  INTEGER(KINT) :: NbTypes
  INTEGER(KINT), PARAMETER :: MaxType=100
  CHARACTER(2) :: Attypes(MaxType)='  '
! VASP5 is true when the POSCAR is in the new POSCAR file
  LOGICAL :: VASP5
! VASP_SelectD is true if Selective Dynamic is selected
  LOGICAL :: VASP_SelectD


! WriteVasp controls the printing of the images coordinates in POSCAR files.
  LOGICAL :: WriteVasp

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! Variables for SIESTA input
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  TYPE (Input_line), POINTER :: Siesta_Input
  TYPE (Input_line), POINTER :: Siesta_Comment_Species,Siesta_Comment_Coord
  TYPE (Input_Line), POINTER :: CurComSpec, CurComCoord
  CHARACTER(LCHARS) :: Siesta_Label, Siesta_CoordFile
! Number of species used in Siesta
  INTEGER(KINT) :: Siesta_NbSpecies
! Mass number for each species (atomic number)
  INTEGER(KINT), ALLOCATABLE :: Siesta_SpeciesMass(:) ! NbSpecies
! Name of each species
  CHARACTER(LCHARS), ALLOCATABLE :: Siesta_SpeciesName(:) ! NbSpecies
! Species for each atom
  INTEGER(KINT), ALLOCATABLE :: IdxSpecies(:) ! NAt
! What to add at the end of each coordinate line
  CHARACTER(LCHARS), ALLOCATABLE :: Siesta_Paste(:) ! Nat
! This is the unit (ang or bohr) to read/write the coordinates
  REAL(KREAL) :: Siesta_Unit_Read, Siesta_Unit_Write
! The lattice constant in case we are in periodic calculation
  REAL(KREAL) :: Siesta_LatticeConstant,Siesta_lat_unit

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! For debug
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  CHARACTER(132) :: DebugFile='Path.valid'

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! For Printing
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  CHARACTER(LCHARS) :: PathName

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! For Energy+Gradient calculations
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! CalcName: Prefix for the files used for the energy and gradient calculations
  CHARACTER(LCHARS) :: CalcName

! ISuffix: Suffix for the input file
  CHARACTER(LCHARS) :: ISuffix
! OSuffix: suffix for the output file.
  CHARACTER(LCHARS) :: OSuffix

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! For printing energies
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Name of the unit used by internally by the 'engine' program
  CHARACTER(SCHARS) :: UnitProg="au"
! Conversion factor from energy program to kcal/mol
  REAL(KREAL) :: ConvE

END MODULE IO_MODULE
