      program x
      implicit none
      integer          NDIM,NSTEPS,NCYCLES
      double precision AMP
      parameter(NDIM=1000,AMP=0.5D0,NSTEPS=8,NCYCLES=5)
      double precision u(NDIM,3),pos(NDIM,3),theta
      integer          i,j,n,k,mode,natoms
      character*4      type(NDIM)
      character*10     dump_str
      character        dump_char
      integer          dump_int

      integer          iargc,nargs
      character*80     fxyz,mstr,nstr

c     check arguments
      nargs=iargc()
      if (nargs.eq.2) then
         call getarg(1,fxyz)
         call getarg(2,mstr)
      else
         write(*,*) 'syntax:'
         write(*,*) 'gvib xyz.file mode'
         stop
      endif

      open(unit=10,file="fort.22")
      open(unit=11,file=fxyz)
      read(11,*) nstr
      read(nstr,*) natoms
      read(mstr,*) mode      

      do i=1,natoms
        read(11,*) type(i),(pos(i,k),k=1,3)
      end do
      do i=1,mode
        read(10,*) dump_int,dump_char,dump_str
        do n=1,natoms
          read(10,*) (u(n,k),k=1,3)
        end do
      end do

      write(*,*) " "
      write(*,*) natoms
      write(*,*) " "
      do j=1,natoms
        write(*,20) type(j),(pos(j,k),k=1,3)
      end do 
      do i=1,NCYCLES
        theta=0.0d0
        do n=1,NSTEPS
          theta=theta+2.0*3.1415926535/dble(NSTEPS)

      write(*,*) " "
          write(*,*) natoms
          write(*,*) " "
          do j=1,natoms
            write(*,20) type(j),(pos(j,k)+AMP*sin(theta)*
     & u(j,k),k=1,3)
          end do

        end do
      end do
      close(unit=10)
20    format(A6,3F16.10)
      stop
      end
