get_filetype Function

public elemental function get_filetype(file) result(ftype)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: file

Name of the file

Return Value integer

File type from extension


Source Code

elemental function get_filetype(file) result(ftype)

   !> Name of the file
   character(len=*), intent(in) :: file

   !> File type from extension
   integer :: ftype

   integer :: iext, isep

   ftype = filetype%unknown
   iext = index(file, '.', back=.true.)
   isep = scan(file, '\/', back=.true.)

   if (iext > isep .and. iext > 0) then
      select case(to_lower(file(iext+1:)))
      case('coord', 'tmol')
         ftype = filetype%tmol
      case('xyz', 'log')
         ftype = filetype%xyz
      case('mol')
         ftype = filetype%molfile
      case('sdf')
         ftype = filetype%sdf
      case('poscar', 'contcar', 'vasp')
         ftype = filetype%vasp
      case('pdb')
         ftype = filetype%pdb
      case('gen')
         ftype = filetype%gen
      case('ein')
         ftype = filetype%gaussian
      case('json')
         ftype = filetype%qcschema
      case('cjson')
         ftype = filetype%cjson
      case('qchem')
         ftype = filetype%qchem
      end select
      if (ftype /= filetype%unknown) return
   else
      iext = len(file) + 1
   end if

   if (iext > isep) then
      if (file(isep+1:) == 'geometry.in') then
         ftype = filetype%aims
      end if

      select case(to_lower(file(isep+1:iext-1)))
      case('geometry.in')
         ftype = filetype%aims
      case('coord')
         ftype = filetype%tmol
      case('poscar', 'contcar')
         ftype = filetype%vasp
      end select
   end if

end function get_filetype