!===============================================================================
!
! hmc_lpf.F90
!
!-------------------------------------------------------------------------------
!
! Copyright (C) 2008 Yoshifumi Nakamura 
!
! This file is part of BQCD -- Berlin Quantum ChromoDynamics program
!
! BQCD 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.
!
! BQCD 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 BQCD.  If not, see <http://www.gnu.org/licenses/>.
!
!-------------------------------------------------------------------------------
# include "defs.h"

!-------------------------------------------------------------------------------
subroutine hmc_lpfsts_integrator(fac)
  use module_integrator
  implicit none
  REAL, intent(in) :: fac
  integer :: n

  iscale = iscale + 1
  if(iscale > n_time_scale) call die("scale>n_time_scale")
  if(itraj + 1 > tot_pq_loop) call die("traj+1>tot_pq_loop ")

  len =  len / m_scale(iscale) * fac
  do n = 1, m_scale(iscale)
     if (iscale == n_time_scale) then
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * HALF
        itraj = itraj + 1
        step_p(itraj)        = step_p(itraj)        + len
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * HALF
     else
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * HALF
        call subintegrator(ONE)
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * HALF
     endif
  enddo

  len = len *  m_scale(iscale) / fac
  iscale = iscale - 1

end

!-------------------------------------------------------------------------------
subroutine hmc_lpftst_integrator(fac, set)
  use module_integrator
  implicit none
  REAL, intent(in) :: fac
  logical, intent(in) :: set
  integer :: n

  iscale = iscale + 1
  if(iscale > n_time_scale) call die("scale>n_time_scale")
  if(itraj + 2 > tot_pq_loop) call die("traj+2>tot_pq_loop ")

  len =  len / m_scale(iscale) * fac
  do n = 1, m_scale(iscale)
     if (iscale == n_time_scale) then
        itraj = itraj + 1
        step_p(itraj)        = step_p(itraj)        + len * HALF
        step_q(itraj,iscale) = step_q(itraj,iscale) + len
        itraj = itraj + 1
        step_p(itraj)        = step_p(itraj)        + len * HALF
     else
        call subintegrator(HALF, set)
        step_q(itraj,iscale) = step_q(itraj,iscale) + len
        call subintegrator(HALF, set)
     endif
  enddo

  len = len *  m_scale(iscale) / fac
  iscale = iscale - 1

end

!===============================================================================
