!===============================================================================
!
! ildg_io_single_pe_r8.F90
!
!-------------------------------------------------------------------------------
!
! Copyright (C) 2007-2014 Hinnerk Stueben
!
! 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 ildg_io_r8(action, u, words_per_site, cksum)

  use module_lattice_io
  use module_vol
  implicit none
  character(*), intent(in)        :: action
  GAUGE_FIELD_ILDG, intent(inout) :: u
  integer, intent(in)             :: words_per_site
  INT8, intent(out)               :: cksum

  integer, parameter              :: bytes_per_word = ILDG_KIND
  INT8                            :: words
  INT8                            :: bytes
  INT8                            :: bytes_total

  words = words_per_site
  words = words * volume
  bytes = words * bytes_per_word

  cksum = 0
  bytes_total = 0

  if (action == "read") then
     call ildg_read(u, bytes)
     call cksum2(u, bytes, cksum, bytes_total)
  endif

  if (action == "write") then
     call swap_endian8(words, u)
     call cksum2(u, bytes, cksum, bytes_total)
     call ildg_write(u, bytes)
  endif

  call swap_endian8(words, u)
  call cksum2_end(cksum, bytes_total)
end

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