!===============================================================================
!
! hmc_2mn.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_2mnsts_integrator(fac)
  use module_integrator
  implicit none
  REAL, parameter :: lambda = 0.1931833275037836_8
  REAL, parameter :: one_two_lambda = ONE - TWO * lambda
  REAL, intent(in) :: fac
  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
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * lambda
        itraj = itraj + 1
        step_p(itraj)        = step_p(itraj)        + len * HALF
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * one_two_lambda
        itraj = itraj + 1
        step_p(itraj)        = step_p(itraj)        + len * HALF
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * lambda
     else
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * lambda
        call subintegrator(HALF)
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * one_two_lambda
        call subintegrator(HALF)
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * lambda
     endif
  enddo

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

end

!-------------------------------------------------------------------------------
subroutine hmc_2mntst_integrator(fac)
  use module_integrator
  implicit none
  REAL, parameter :: lambda = 0.1931833275037836_8
  REAL, parameter :: one_two_lambda = ONE - TWO * lambda
  REAL, intent(in) :: fac
  integer :: n

  iscale = iscale + 1
  if(iscale > n_time_scale) call die("scale>n_time_scale")
  if(itraj + 3 > tot_pq_loop) call die("traj+3>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 * lambda
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * HALF
        itraj = itraj + 1
        step_p(itraj)        = step_p(itraj)        + len * one_two_lambda
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * HALF
        itraj = itraj + 1
        step_p(itraj)        = step_p(itraj)        + len * lambda
     else
        call subintegrator(lambda)
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * HALF
        call subintegrator(one_two_lambda)
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * HALF
        call subintegrator(lambda)
     endif
  enddo

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

end

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