      FUNCTION ConvertNumAt(ATOM)

!----------------------------------------------------------------------
!  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, only : Nom, max_Z

      IMPLICIT NONE

      INTEGER(4) :: I,Long,ConvertNumAt,IC
      character(*) :: ATOM
      CHARACTER(3) :: ATOME
      CHARACTER(10) :: L_Atom

!     Verifie qu'il n'y a que des lettres et des espaces dans ATOM

      L_atom=ADJUSTL(Atom)
      IF (ATOM(1:1).LT.'A') L_ATOM(1:1)=' '
      IC=Ichar(ATOM(1:1))
      IF ((ic.le.123).AND.(ic.ge.97)) L_ATOM(1:1)=CHAr(IC-32)
      IF (ATOM(2:2).LT.'A') L_ATOM(2:2)=' '
      IC=Ichar(ATOM(2:2))
      IF ((ic.le.123).AND.(ic.ge.97)) L_ATOM(2:2)=CHAr(IC-32)

!     Justifie le nom sur la droite (et non sur la gauche comme souvent...)
      Long=INDEX(L_ATOM,' ')-1
      ATOME=' ' // L_ATOM(1:2)
      IF (Long.EQ.1) L_ATOM=ATOME(1:2)
      I=max_Z
      DO WHILE ((nom(I).NE.L_ATOM(1:2)) .AND. (I.GT.0))
         I=I-1
      END DO

      ConvertNumAT=I

      END

