module wf_dump
  !! array output for debugging
  use sep
  !---------------
  implicit none

  interface wfdump
     module procedure wfdumpI1
     module procedure wfdumpI2
     module procedure wfdumpI3
     module procedure wfdumpI4
     module procedure wfdumpI5

     module procedure wfdumpR1
     module procedure wfdumpR2
     module procedure wfdumpR3
     module procedure wfdumpR4
     module procedure wfdumpR5

     module procedure wfdumpC1
     module procedure wfdumpC2
     module procedure wfdumpC3
     module procedure wfdumpC4
     module procedure wfdumpC5
  end interface

  character(len=128), public :: dumpname

contains
  !----------------------------------------------------------------
  subroutine wfdumpI1(array)
    integer, dimension(:), pointer            :: array
    integer :: esize
    integer :: n1

    call auxscr(trim(dumpname))

    esize = 1
    call auxputch("esize",'i',esize,trim(dumpname))
    n1 = size(array,1)
    call auxputch("n1",'i',n1,trim(dumpname))

    call srite(trim(dumpname),array,n1*esize)
  end subroutine wfdumpI1
  !----------------------------------------------------------------
  subroutine wfdumpI2(array)
    integer, dimension(:,:), pointer          :: array
    integer :: esize
    integer :: n1,n2

    call auxscr(trim(dumpname))

    esize = 1
    call auxputch("esize",'i',esize,trim(dumpname))
    n1 = size(array,1)
    call auxputch("n1",'i',n1,trim(dumpname))
    n2 = size(array,2)
    call auxputch("n2",'i',n2,trim(dumpname))

    call srite(trim(dumpname),array,n1*n2*esize)
  end subroutine wfdumpI2
  !----------------------------------------------------------------
  subroutine wfdumpI3(array)
    integer, dimension(:,:,:), pointer        :: array
    integer :: esize
    integer :: n1,n2,n3

    call auxscr(trim(dumpname))

    esize = 1
    call auxputch("esize",'i',esize,trim(dumpname))
    n1 = size(array,1)
    call auxputch("n1",'i',n1,trim(dumpname))
    n2 = size(array,2)
    call auxputch("n2",'i',n2,trim(dumpname))
    n3 = size(array,3)
    call auxputch("n3",'i',n3,trim(dumpname))

    call srite(trim(dumpname),array,n1*n2*n3*esize)
  end subroutine wfdumpI3
  !----------------------------------------------------------------
  subroutine wfdumpI4(array)
    integer, dimension(:,:,:,:), pointer      :: array
    integer :: esize
    integer :: n1,n2,n3,n4

    call auxscr(trim(dumpname))

    esize = 1
    call auxputch("esize",'i',esize,trim(dumpname))
    n1 = size(array,1)
    call auxputch("n1",'i',n1,trim(dumpname))
    n2 = size(array,2)
    call auxputch("n2",'i',n2,trim(dumpname))
    n3 = size(array,3)
    call auxputch("n3",'i',n3,trim(dumpname))
    n4 = size(array,4)
    call auxputch("n4",'i',n4,trim(dumpname))

    call srite(trim(dumpname),n1*n2*n3*n4*esize)
  end subroutine wfdumpI4
  !----------------------------------------------------------------
  subroutine wfdumpI5(array)
    integer, dimension(:,:,:,:,:), pointer    :: array
    integer :: esize
    integer :: n1,n2,n3,n4,n5

    call auxscr(trim(dumpname))

    esize = 1
    call auxputch("esize",'i',esize,trim(dumpname))
    n1 = size(array,1)
    call auxputch("n1",'i',n1,trim(dumpname))
    n2 = size(array,2)
    call auxputch("n2",'i',n2,trim(dumpname))
    n3 = size(array,3)
    call auxputch("n3",'i',n3,trim(dumpname))
    n4 = size(array,4)
    call auxputch("n4",'i',n4,trim(dumpname))
    n5 = size(array,5)
    call auxputch("n5",'i',n5,trim(dumpname))

    call srite(trim(dumpname),array,n1*n2*n3*n4*n5*esize)
  end subroutine wfdumpI5
  !----------------------------------------------------------------

  !----------------------------------------------------------------
  subroutine wfdumpR1(array)
    real, dimension(:), pointer            :: array
    integer :: esize
    integer :: n1

    call auxscr(trim(dumpname))

    esize = 4
    call auxputch("esize",'i',esize,trim(dumpname))
    n1 = size(array,1)
    call auxputch("n1",'i',n1,trim(dumpname))

    call sep_write(array,trim(dumpname))
  end subroutine wfdumpR1
  !----------------------------------------------------------------
  subroutine wfdumpR2(array)
    real, dimension(:,:), pointer          :: array
    integer :: esize
    integer :: n1,n2

    call auxscr(trim(dumpname))

    esize = 4
    call auxputch("esize",'i',esize,trim(dumpname))
    n1 = size(array,1)
    call auxputch("n1",'i',n1,trim(dumpname))
    n2 = size(array,2)
    call auxputch("n2",'i',n2,trim(dumpname))

    call sep_write(array,trim(dumpname))
  end subroutine wfdumpR2
  !----------------------------------------------------------------
  subroutine wfdumpR3(array)
    real, dimension(:,:,:), pointer        :: array
    integer :: esize
    integer :: n1,n2,n3

    call auxscr(trim(dumpname))

    esize = 4
    call auxputch("esize",'i',esize,trim(dumpname))
    n1 = size(array,1)
    call auxputch("n1",'i',n1,trim(dumpname))
    n2 = size(array,2)
    call auxputch("n2",'i',n2,trim(dumpname))
    n3 = size(array,3)
    call auxputch("n3",'i',n3,trim(dumpname))

    call sep_write(array,trim(dumpname))
  end subroutine wfdumpR3
  !----------------------------------------------------------------
  subroutine wfdumpR4(array)
    real, dimension(:,:,:,:), pointer      :: array
    integer :: esize
    integer :: n1,n2,n3,n4

    call auxscr(trim(dumpname))

    esize = 4
    call auxputch("esize",'i',esize,trim(dumpname))
    n1 = size(array,1)
    call auxputch("n1",'i',n1,trim(dumpname))
    n2 = size(array,2)
    call auxputch("n2",'i',n2,trim(dumpname))
    n3 = size(array,3)
    call auxputch("n3",'i',n3,trim(dumpname))
    n4 = size(array,4)
    call auxputch("n4",'i',n4,trim(dumpname))

    call sep_write(array,trim(dumpname))
  end subroutine wfdumpR4
  !----------------------------------------------------------------
  subroutine wfdumpR5(array)
    real, dimension(:,:,:,:,:), pointer    :: array
    integer :: esize
    integer :: n1,n2,n3,n4,n5

    call auxscr(trim(dumpname))

    esize = 4
    call auxputch("esize",'i',esize,trim(dumpname))
    n1 = size(array,1)
    call auxputch("n1",'i',n1,trim(dumpname))
    n2 = size(array,2)
    call auxputch("n2",'i',n2,trim(dumpname))
    n3 = size(array,3)
    call auxputch("n3",'i',n3,trim(dumpname))
    n4 = size(array,4)
    call auxputch("n4",'i',n4,trim(dumpname))
    n5 = size(array,5)
    call auxputch("n5",'i',n5,trim(dumpname))

    call sep_write(array,trim(dumpname))
  end subroutine wfdumpR5
  !----------------------------------------------------------------

  !----------------------------------------------------------------
  subroutine wfdumpC1(array)
    complex, dimension(:), pointer         :: array
    integer :: esize
    integer :: n1

    call auxscr(trim(dumpname))

    esize = 8
    call auxputch("esize",'i',esize,trim(dumpname))
    n1 = size(array,1)
    call auxputch("n1",'i',n1,trim(dumpname))

    call sep_write(array,trim(dumpname))
  end subroutine wfdumpC1
  !----------------------------------------------------------------
  subroutine wfdumpC2(array)
    complex, dimension(:,:), pointer       :: array
    integer :: esize
    integer :: n1,n2

    call auxscr(trim(dumpname))

    esize = 8
    call auxputch("esize",'i',esize,trim(dumpname))
    n1 = size(array,1)
    call auxputch("n1",'i',n1,trim(dumpname))
    n2 = size(array,2)
    call auxputch("n2",'i',n2,trim(dumpname))

    call sep_write(array,trim(dumpname))
  end subroutine wfdumpC2
  !----------------------------------------------------------------
  subroutine wfdumpC3(array)
    complex, dimension(:,:,:), pointer     :: array
    integer :: esize
    integer :: n1,n2,n3

    call auxscr(trim(dumpname))

    esize = 8
    call auxputch("esize",'i',esize,trim(dumpname))
    n1 = size(array,1)
    call auxputch("n1",'i',n1,trim(dumpname))
    n2 = size(array,2)
    call auxputch("n2",'i',n2,trim(dumpname))
    n3 = size(array,3)
    call auxputch("n3",'i',n3,trim(dumpname))

    call sep_write(array,trim(dumpname))
  end subroutine wfdumpC3
  !----------------------------------------------------------------
  subroutine wfdumpC4(array)
    complex, dimension(:,:,:,:), pointer   :: array
    integer :: esize
    integer :: n1,n2,n3,n4

    call auxscr(trim(dumpname))

    esize = 8
    call auxputch("esize",'i',esize,trim(dumpname))
    n1 = size(array,1)
    call auxputch("n1",'i',n1,trim(dumpname))
    n2 = size(array,2)
    call auxputch("n2",'i',n2,trim(dumpname))
    n3 = size(array,3)
    call auxputch("n3",'i',n3,trim(dumpname))
    n4 = size(array,4)
    call auxputch("n4",'i',n4,trim(dumpname))

    call sep_write(array,trim(dumpname))
  end subroutine wfdumpC4
  !----------------------------------------------------------------
  subroutine wfdumpC5(array)
    complex, dimension(:,:,:,:,:), pointer :: array
    integer :: esize
    integer :: n1,n2,n3,n4,n5

    call auxscr(trim(dumpname))

    esize = 8
    call auxputch("esize",'i',esize,trim(dumpname))
    n1 = size(array,1)
    call auxputch("n1",'i',n1,trim(dumpname))
    n2 = size(array,2)
    call auxputch("n2",'i',n2,trim(dumpname))
    n3 = size(array,3)
    call auxputch("n3",'i',n3,trim(dumpname))
    n4 = size(array,4)
    call auxputch("n4",'i',n4,trim(dumpname))
    n5 = size(array,5)
    call auxputch("n5",'i',n5,trim(dumpname))

    call sep_write(array,trim(dumpname))
  end subroutine wfdumpC5
  !----------------------------------------------------------------
end module wf_dump





