      PROGRAM FORMA
      implicit none
      real*8, allocatable:: cell(:,:), forces(:,:)
      real*8 :: ev_to_Ryd, ang_to_au, factor
      integer :: n, n_atoms,i,j,k
      integer, allocatable:: n_type(:)
      character(len=30) :: qe_format 
           
      open(9, file='FORCE')
      open(10, file='forces.qe')
      open(11, file='forces.dftb')

     
      ev_to_Ryd = 0.073498618
      ang_to_au = 1.8897261339213
      factor = ev_to_Ryd/ang_to_au

      allocate (cell(3,3))

      do i=1,3
           read(9,*) cell(i,1), cell(i,2), cell(i,3)
      end do

      read (9,*) n_atoms

      allocate (n_type(n_atoms), forces(n_atoms,3)) 
    

      write(10,*)"   Forces acting on atoms (Ry/au):"

      write(11,*) "forces              :real:2:3,",n_atoms
      write(10,*) " "
      do i=1,n_atoms
  
        read(9,*) n_type(i), forces(i,1), forces(i,2), forces(i,3)
        forces(i,:) = forces(i,:)*factor
        write(10,100) "atom",i,"type",n_type(i),"force =",forces(i,:)
        write(11,110) forces(i,:)

      end do


  100 format(4X,A4,1X,I5,1X,A4,1X,I3,1X,A7,1X,F20.15,F20.15,F20.15)
  110 format(2X,F20.15,F20.15,F20.15)

      deallocate(cell, forces) 
      
      END PROGRAM FORMA 
