MODULE mode_lattid
!
!**********************************************************************************
!*  MODE_LATTID                                                                   *
!**********************************************************************************
!* This module aims at identifying the lattice type each atom belongs to.         *
!* Lattice "identifiers" (latid) follow the numbering used in OVITO:              *
!*   0 = Other, unknown coordination structure                                    *
!*   1 = FCC, face-centered cubic                                                 *
!*   2 = HCP, hexagonal close-packed                                              *
!*   3 = BCC, body-centered cubic                                                 *
!*   4 = ICO, icosahedral coordination                                            *
!*   5 = SC, simple cubic                                                         *
!*   6 = Cubic diamond                                                            *
!*   7 = Hexagonal diamond                                                        *
!*   8 = Graphene                                                                 *
!**********************************************************************************
!* (C) October 2022 - Pierre Hirel                                                *
!*     Université de Lille, Sciences et Technologies                              *
!*     UMR CNRS 8207, UMET - C6, F-59655 Villeneuve D'Ascq, France                *
!*     pierre.hirel@univ-lille.fr                                                 *
!* Last modification: P. Hirel - 21 Oct. 2022                                     *
!**********************************************************************************
!* This program is free software: you can redistribute it and/or modify           *
!* it under the terms of the GNU General Public License as published by           *
!* the Free Software Foundation, either version 3 of the License, or              *
!* (at your option) any later version.                                            *
!*                                                                                *
!* This program 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 General Public License for more details.                                   *
!*                                                                                *
!* You should have received a copy of the GNU General Public License              *
!* along with this program.  If not, see <http://www.gnu.org/licenses/>.          *
!**********************************************************************************
!
USE atoms
USE comv
USE constants
USE messages
USE files
USE subroutines
USE readin
USE options
USE writeout
!
!
CONTAINS
!
!
SUBROUTINE STRUCTURE_ID(inputfile,options_array,prefix,outfileformats)
!
!
IMPLICIT NONE
CHARACTER(LEN=*),INTENT(IN):: inputfile
CHARACTER(LEN=*),INTENT(IN):: prefix
!
CHARACTER(LEN=2):: species
CHARACTER(LEN=128):: msg, temp
CHARACTER(LEN=5),DIMENSION(:),ALLOCATABLE:: outfileformats !list of output file formats
CHARACTER(LEN=128),DIMENSION(:),ALLOCATABLE:: AUXNAMES, newAUXNAMES !names of auxiliary properties
CHARACTER(LEN=128),DIMENSION(:),ALLOCATABLE:: comment
CHARACTER(LEN=128),DIMENSION(:),ALLOCATABLE:: options_array !options and their parameters
LOGICAL,DIMENSION(:),ALLOCATABLE:: SELECT  !mask for atom list
INTEGER:: c             !column in AUX that will contain the central symmetry parameters c(i)
INTEGER:: i, ipairs, j, k, ktemp
INTEGER:: Mdefault      !most common number of neighbors
INTEGER,PARAMETER:: Nmax=14 !maximum number of neighbors for any lattice
INTEGER:: Nneigh        !number of neighbors of an atom
INTEGER:: Nspecies      !number of species in the system
INTEGER,DIMENSION(:,:),ALLOCATABLE:: NeighList !list of index of neighbors
INTEGER,DIMENSION(:),ALLOCATABLE:: newindex  !list of index after sorting
INTEGER,DIMENSION(:,:),ALLOCATABLE:: pairs  !indexes of pairs of atoms
REAL(dp):: distance, dmin
REAL(dp):: sum_dj       !sum of |d_j|²
REAL(dp),DIMENSION(3,3):: Huc   !Box vectors of unit cell (unknown, set to 0 here)
REAL(dp),DIMENSION(3,3):: H       !Base vectors of the supercell
REAL(dp),DIMENSION(3,3):: ORIENT  !crystallographic orientation of the system (mode create)
REAL(dp),DIMENSION(9,9):: C_tensor  !elastic tensor
REAL(dp),DIMENSION(:),ALLOCATABLE:: pairs_distances  !distances
REAL(dp),DIMENSION(:),ALLOCATABLE:: three_angles     !angles
REAL(dp),DIMENSION(:,:),ALLOCATABLE:: aentries    !array containing result
REAL(dp),DIMENSION(:,:),ALLOCATABLE:: AUX, newAUX !auxiliary properties
REAL(dp),DIMENSION(:,:),ALLOCATABLE:: P, S     !positions of atoms, shells
REAL(dp),DIMENSION(:,:),ALLOCATABLE:: PosList
!
!
!Initialize variables
Nspecies = 0
Huc(:,:) = 0.d0
 C_tensor(:,:) = 0.d0
!
!
msg = 'ENTERING LATTICE_ID...'
CALL ATOMSK_MSG(999,(/TRIM(msg)/),(/0.d0/))
!

!
!
END SUBROUTINE STRUCTURE_ID
!
!
END MODULE mode_structid
