!===============================================================================
!
! hmc_4mn.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_4mn5fv_integrator(fac)
  use module_integrator
  implicit none
  REAL, parameter :: theta =  0.08398315262876693_8
  REAL, parameter :: rho =     0.2539785108410595_8
  REAL, parameter :: lambda =  0.6822365335719091_8
  REAL, parameter :: mu =    -0.03230286765269967_8
  REAL, parameter :: hmlt = HALF-(lambda+theta)
  REAL, parameter :: omtmurho = ONE-TWO*(mu+rho)
  REAL, intent(in) :: fac
  integer :: n

  iscale = iscale + 1
  if(iscale > n_time_scale) call die("scale>n_time_scale")
  if(itraj + 5 > tot_pq_loop) call die("traj+5>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 * theta
        itraj = itraj + 1
        step_p(itraj)        = step_p(itraj)        + len * rho
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * lambda
        itraj = itraj + 1
        step_p(itraj)        = step_p(itraj)        + len * mu
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * hmlt
        itraj = itraj + 1
        step_p(itraj)        = step_p(itraj)        + len * omtmurho
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * hmlt
        itraj = itraj + 1
        step_p(itraj)        = step_p(itraj)        + len * mu
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * lambda
        itraj = itraj + 1
        step_p(itraj)        = step_p(itraj)        + len * rho
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * theta
     else
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * theta
        call subintegrator(rho)
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * lambda
        call subintegrator(mu)
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * hmlt
        call subintegrator(omtmurho)
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * hmlt
        call subintegrator(mu)
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * lambda
        call subintegrator(rho)
        step_q(itraj,iscale) = step_q(itraj,iscale) + len * theta
     endif
  enddo

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

end

!-------------------------------------------------------------------------------
subroutine hmc_4mn4fp_integrator(fac)
  use module_integrator
  implicit none
  REAL, parameter :: rho =      0.1786178958448091_8
  REAL, parameter :: theta =  -0.06626458266981843_8
  REAL, parameter :: lambda =   0.7123418310626056_8
  REAL, parameter :: one_minus_two_lambda_by2 = HALF-lambda
  REAL, parameter :: one_minus_two_theta_plus_rho = ONE-TWO*(theta+rho)
  REAL, intent(in) :: fac
  integer :: n

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

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

end

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