Commit e6940309 authored by Matthias Redies's avatar Matthias Redies

remove numpy outputs

parent 51d239f8
......@@ -41,8 +41,6 @@ sysinfo.F90
check_arguments.F90
check_para.F90
xmlOutput.F90
npy.F90
endian_swap.f90
)
if (JUDFT_USE_MPI)
target_compile_definitions(juDFT PUBLIC CPP_MPI)
......
module endian_swap
implicit none
PRIVATE
PUBLIC :: Big_Endian
PUBLIC :: Swap_Endian
INTERFACE Swap_Endian
module procedure SWAP_I1
module procedure SWAP_I2
module procedure SWAP_I4
module procedure SWAP_I8
module procedure SWAP_F4
module procedure SWAP_F8
module procedure SWAP_F16
module procedure SWAP_C4
module procedure SWAP_C8
END INTERFACE Swap_Endian
CONTAINS
FUNCTION Big_Endian()
LOGICAL :: Big_Endian
Big_Endian = ichar(transfer(1,'a')) == 0
END FUNCTION Big_Endian
function SWAP_I4(input) result(output)
implicit none
integer(4), parameter :: b_sz = 4
integer(b_sz), intent(in) :: input
integer(b_sz) :: output
integer(1) :: byte_arr(b_sz), byte_arr_tmp(b_sz)
integer(1) :: i
byte_arr_tmp = transfer(input, byte_arr_tmp)
do i = 1,b_sz
byte_arr(i) = byte_arr_tmp(1 + b_sz - i)
enddo
output = transfer(byte_arr, output)
end function SWAP_I4
function SWAP_I2(input) result(output)
implicit none
integer(4), parameter :: b_sz = 2
integer(b_sz), intent(in) :: input
integer(b_sz) :: output
integer(1) :: byte_arr(b_sz), byte_arr_tmp(b_sz)
integer(1) :: i
byte_arr_tmp = transfer(input, byte_arr_tmp)
do i = 1,b_sz
byte_arr(i) = byte_arr_tmp(1 + b_sz - i)
enddo
output = transfer(byte_arr, output)
end function SWAP_I2
function SWAP_I1(input) result(output)
implicit none
integer(4), parameter :: b_sz = 1
integer(b_sz), intent(in) :: input
integer(b_sz) :: output
integer(1) :: byte_arr(b_sz), byte_arr_tmp(b_sz)
integer(1) :: i
byte_arr_tmp = transfer(input, byte_arr_tmp)
do i = 1,b_sz
byte_arr(i) = byte_arr_tmp(1 + b_sz - i)
enddo
output = transfer(byte_arr, output)
end function SWAP_I1
function SWAP_I8(input) result(output)
implicit none
integer(4), parameter :: b_sz = 8
integer(b_sz), intent(in) :: input
integer(b_sz) :: output
integer(1) :: byte_arr(b_sz), byte_arr_tmp(b_sz)
integer(1) :: i
byte_arr_tmp = transfer(input, byte_arr_tmp)
do i = 1,b_sz
byte_arr(i) = byte_arr_tmp(1 + b_sz - i)
enddo
output = transfer(byte_arr, output)
end function SWAP_I8
function SWAP_F4(input) result(output)
implicit none
integer(4), parameter :: b_sz = 4
real(b_sz), intent(in) :: input
real(b_sz) :: output
integer(1) :: byte_arr(b_sz), byte_arr_tmp(b_sz)
integer(1) :: i
byte_arr_tmp = transfer(input, byte_arr_tmp)
do i = 1,b_sz
byte_arr(i) = byte_arr_tmp(1 + b_sz - i)
enddo
output = transfer(byte_arr, output)
end function SWAP_F4
function SWAP_F8(input) result(output)
implicit none
integer(4), parameter :: b_sz = 8
real(b_sz), intent(in) :: input
real(b_sz) :: output
integer(1) :: byte_arr(b_sz), byte_arr_tmp(b_sz)
integer(1) :: i
byte_arr_tmp = transfer(input, byte_arr_tmp)
do i = 1,b_sz
byte_arr(i) = byte_arr_tmp(1 + b_sz - i)
enddo
output = transfer(byte_arr, output)
end function SWAP_F8
function SWAP_F16(input) result(output)
implicit none
integer(4), parameter :: b_sz = 16
real(b_sz), intent(in) :: input
real(b_sz) :: output
integer(1) :: byte_arr(b_sz), byte_arr_tmp(b_sz)
integer(1) :: i
byte_arr_tmp = transfer(input, byte_arr_tmp)
do i = 1,b_sz
byte_arr(i) = byte_arr_tmp(1 + b_sz - i)
enddo
output = transfer(byte_arr, output)
end function SWAP_F16
function SWAP_C8(input) result(output)
implicit none
integer(4), parameter :: b_sz = 8
complex(b_sz), intent(in) :: input
complex(b_sz) :: output
real(b_sz) :: re, im
re = Swap_Endian(real(input))
im = Swap_Endian(aimag(input))
output = cmplx(re, im)
end function swap_c8
function SWAP_C4(input) result(output)
implicit none
integer(4), parameter :: b_sz = 4
complex(b_sz), intent(in) :: input
complex(b_sz) :: output
real(b_sz) :: re, im
re = Swap_Endian(real(input))
im = Swap_Endian(aimag(input))
output = cmplx(re, im)
end function swap_c4
END module endian_swap
module m_npy
use endian_swap
implicit none
integer(4), parameter :: p_un = 23
character, parameter :: magic_num = achar(147) ! x93
character, parameter :: major = achar(2) !major *.npy version
character, parameter :: minor = achar(0) !minor *.npy version
logical, parameter :: use_big_endian = .False.
character(len=*), parameter :: zip_flag = "-q0"
character(len=*), parameter :: magic_str = "NUMPY"
interface save_npy
module procedure write_int64_vec, write_int64_mtx, &
write_int32_vec, write_int32_mtx, &
write_int16_vec, write_int16_mtx, &
write_int8_vec, write_int8_mtx, &
write_dbl_vec, write_dbl_mtx, &
write_sng_vec, write_sng_mtx, &
write_cmplx_sgn_vec, write_cmplx_sgn_mtx, &
write_cmplx_dbl_vec, write_cmplx_dbl_mtx, &
write_sng_3dT, write_dbl_3dT, &
write_cmplx_dbl_3dT
end interface save_npy
interface add_npz
module procedure addrpl_int8_vec, addrpl_int8_mtx, &
addrpl_int16_vec, addrpl_int16_mtx, &
addrpl_int32_vec, addrpl_int32_mtx, &
addrpl_int64_vec, addrpl_int64_mtx, &
addrpl_sng_vec, addrpl_sng_mtx, &
addrpl_dbl_vec, addrpl_dbl_mtx, &
addrpl_cmplx_dbl_vec, addrpl_cmplx_dbl_mtx, &
addrpl_cmplx_sng_vec, addrpl_cmplx_sng_mtx
end interface add_npz
contains
subroutine run_sys(cmd, stat)
implicit none
character(len=*), intent(in) :: cmd
integer(4), intent(out) :: stat
call execute_command_line(cmd, wait=.True., exitstat=stat)
end subroutine run_sys
subroutine addrpl_cmplx_sng_vec(zipfile, var_name, vec)
implicit none
complex(4), intent(in) :: vec(:)
character(len=*), intent(in) :: zipfile, var_name
character(len=:), allocatable :: npy_name
integer(4) :: succ
npy_name = var_name // ".npy"
call save_npy(npy_name, vec)
! just store and be quite while zipping
call run_sys("zip " // zip_flag // " " // zipfile &
// " " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute zip command"
endif
call run_sys("rm " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute rm command"
endif
end subroutine addrpl_cmplx_sng_vec
subroutine addrpl_cmplx_sng_mtx(zipfile, var_name, mtx)
implicit none
complex(4), intent(in) :: mtx(:,:)
character(len=*), intent(in) :: zipfile, var_name
character(len=:), allocatable :: npy_name
integer(4) :: succ
npy_name = var_name // ".npy"
call save_npy(npy_name, mtx)
! just store and be quite while zipping
call run_sys("zip " // zip_flag // " " // zipfile &
// " " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute zip command"
endif
call run_sys("rm " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute rm command"
endif
end subroutine addrpl_cmplx_sng_mtx
subroutine addrpl_cmplx_dbl_vec(zipfile, var_name, vec)
implicit none
complex(8), intent(in) :: vec(:)
character(len=*), intent(in) :: zipfile, var_name
character(len=:), allocatable :: npy_name
integer(4) :: succ
npy_name = var_name // ".npy"
call save_npy(npy_name, vec)
! just store and be quite while zipping
call run_sys("zip " // zip_flag // " " // zipfile &
// " " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute zip command"
endif
call run_sys("rm " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute rm command"
endif
end subroutine addrpl_cmplx_dbl_vec
subroutine addrpl_cmplx_dbl_mtx(zipfile, var_name, mtx)
implicit none
complex(8), intent(in) :: mtx(:,:)
character(len=*), intent(in) :: zipfile, var_name
character(len=:), allocatable :: npy_name
integer(4) :: succ
npy_name = var_name // ".npy"
call save_npy(npy_name, mtx)
! just store and be quite while zipping
call run_sys("zip " // zip_flag // " " // zipfile &
// " " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute zip command"
endif
call run_sys("rm " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute rm command"
endif
end subroutine addrpl_cmplx_dbl_mtx
subroutine addrpl_dbl_vec(zipfile, var_name, vec)
implicit none
real(8), intent(in) :: vec(:)
character(len=*), intent(in) :: zipfile, var_name
character(len=:), allocatable :: npy_name
integer(4) :: succ
npy_name = var_name // ".npy"
call save_npy(npy_name, vec)
! just store and be quite while zipping
call run_sys("zip " // zip_flag // " " // zipfile &
// " " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute zip command"
endif
call run_sys("rm " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute rm command"
endif
end subroutine addrpl_dbl_vec
subroutine addrpl_dbl_mtx(zipfile, var_name, mtx)
implicit none
real(8), intent(in) :: mtx(:,:)
character(len=*), intent(in) :: zipfile, var_name
character(len=:), allocatable :: npy_name
integer(4) :: succ
npy_name = var_name // ".npy"
call save_npy(npy_name, mtx)
! just store and be quite while zipping
call run_sys("zip " // zip_flag // " " // zipfile &
// " " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute zip command"
endif
call run_sys("rm " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute rm command"
endif
end subroutine addrpl_dbl_mtx
subroutine addrpl_sng_vec(zipfile, var_name, vec)
implicit none
real(4), intent(in) :: vec(:)
character(len=*), intent(in) :: zipfile, var_name
character(len=:), allocatable :: npy_name
integer(4) :: succ
npy_name = var_name // ".npy"
call save_npy(npy_name, vec)
! just store and be quite while zipping
call run_sys("zip " // zip_flag // " " // zipfile &
// " " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute zip command"
endif
call run_sys("rm " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute rm command"
endif
end subroutine addrpl_sng_vec
subroutine addrpl_sng_mtx(zipfile, var_name, mtx)
implicit none
real(4), intent(in) :: mtx(:,:)
character(len=*), intent(in) :: zipfile, var_name
character(len=:), allocatable :: npy_name
integer(4) :: succ
npy_name = var_name // ".npy"
call save_npy(npy_name, mtx)
! just store and be quite while zipping
call run_sys("zip " // zip_flag // " " // zipfile &
// " " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute zip command"
endif
call run_sys("rm " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute rm command"
endif
end subroutine addrpl_sng_mtx
subroutine addrpl_int8_vec(zipfile, var_name, vec)
implicit none
integer(1), intent(in) :: vec(:)
character(len=*), intent(in) :: zipfile, var_name
character(len=:), allocatable :: npy_name
integer(4) :: succ
npy_name = var_name // ".npy"
call save_npy(npy_name, vec)
! just store and be quite while zipping
call run_sys("zip " // zip_flag // " " // zipfile &
// " " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute zip command"
endif
call run_sys("rm " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute rm command"
endif
end subroutine addrpl_int8_vec
subroutine addrpl_int8_mtx(zipfile, var_name, mtx)
implicit none
integer(1), intent(in) :: mtx(:,:)
character(len=*), intent(in) :: zipfile, var_name
character(len=:), allocatable :: npy_name
integer(4) :: succ
npy_name = var_name // ".npy"
call save_npy(npy_name, mtx)
! just store and be quite while zipping
call run_sys("zip " // zip_flag // " " // zipfile &
// " " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute zip command"
endif
call run_sys("rm " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute rm command"
endif
end subroutine addrpl_int8_mtx
subroutine addrpl_int16_vec(zipfile, var_name, vec)
implicit none
integer(2), intent(in) :: vec(:)
character(len=*), intent(in) :: zipfile, var_name
character(len=:), allocatable :: npy_name
integer(4) :: succ
npy_name = var_name // ".npy"
call save_npy(npy_name, vec)
! just store and be quite while zipping
call run_sys("zip " // zip_flag // " " // zipfile &
// " " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute zip command"
endif
call run_sys("rm " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute rm command"
endif
end subroutine addrpl_int16_vec
subroutine addrpl_int16_mtx(zipfile, var_name, mtx)
implicit none
integer(2), intent(in) :: mtx(:,:)
character(len=*), intent(in) :: zipfile, var_name
character(len=:), allocatable :: npy_name
integer(4) :: succ
npy_name = var_name // ".npy"
call save_npy(npy_name, mtx)
! just store and be quite while zipping
call run_sys("zip " // zip_flag // " " // zipfile &
// " " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute zip command"
endif
call run_sys("rm " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute rm command"
endif
end subroutine addrpl_int16_mtx
subroutine addrpl_int32_vec(zipfile, var_name, vec)
implicit none
integer(4), intent(in) :: vec(:)
character(len=*), intent(in) :: zipfile, var_name
character(len=:), allocatable :: npy_name
integer(4) :: succ
npy_name = var_name // ".npy"
call save_npy(npy_name, vec)
! just store and be quite while zipping
call run_sys("zip " // zip_flag // " " // zipfile &
// " " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute zip command"
endif
call run_sys("rm " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute rm command"
endif
end subroutine addrpl_int32_vec
subroutine addrpl_int32_mtx(zipfile, var_name, mtx)
implicit none
integer(4), intent(in) :: mtx(:,:)
character(len=*), intent(in) :: zipfile, var_name
character(len=:), allocatable :: npy_name
integer(4) :: succ
npy_name = var_name // ".npy"
call save_npy(npy_name, mtx)
! just store and be quite while zipping
call run_sys("zip " // zip_flag // " " // zipfile &
// " " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute zip command"
endif
call run_sys("rm " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute rm command"
endif
end subroutine addrpl_int32_mtx
subroutine addrpl_int64_vec(zipfile, var_name, vec)
implicit none
integer(8), intent(in) :: vec(:)
character(len=*), intent(in) :: zipfile, var_name
character(len=:), allocatable :: npy_name
integer(4) :: succ
npy_name = var_name // ".npy"
call save_npy(npy_name, vec)
! just store and be quite while zipping
call run_sys("zip " // zip_flag // " " // zipfile &
// " " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute zip command"
endif
call run_sys("rm " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute rm command"
endif
end subroutine addrpl_int64_vec
subroutine addrpl_int64_mtx(zipfile, var_name, mtx)
implicit none
integer(8), intent(in) :: mtx(:,:)
character(len=*), intent(in) :: zipfile, var_name
character(len=:), allocatable :: npy_name
integer(4) :: succ
npy_name = var_name // ".npy"
call save_npy(npy_name, mtx)
! just store and be quite while zipping
call run_sys("zip " // zip_flag // " " // zipfile &
// " " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute zip command"
endif
call run_sys("rm " // npy_name, succ)
if(succ /= 0) then
write (*,*) "Can't execute rm command"
endif
end subroutine addrpl_int64_mtx
Subroutine write_cmplx_sgn_mtx(filename, mtx)
Implicit None
character(len=*), intent(in) :: filename
complex(4), intent(in) :: mtx(:,:)
character(len=*), parameter :: var_type = "<c8"
integer(4) :: header_len, s_mtx(2), i, j
s_mtx = shape(mtx)
header_len = len(dict_str(var_type, s_mtx))