COMPRESSION, IO: Initialize compression in initialize_io().

Signed-off-by: Grzegorz Kowal <grzegorz@amuncode.org>
This commit is contained in:
Grzegorz Kowal 2020-08-10 15:34:20 -03:00
parent ab3b5d6877
commit 08b7e81f6a
2 changed files with 32 additions and 20 deletions

View File

@ -72,11 +72,10 @@ module compression
! cformat - the compression format string;
! clevel - the compression level;
! suffix - the compressed file suffix;
! success - returns the compression format set;
!
!===============================================================================
!
subroutine set_compression(cformat, clevel, suffix, success)
subroutine set_compression(cformat, clevel, suffix)
implicit none
@ -85,17 +84,14 @@ module compression
character(len=*) , intent(in) :: cformat
integer , intent(in) :: clevel
character(len=8) , intent(out) :: suffix
logical , intent(out) :: success
!-------------------------------------------------------------------------------
!
success = .false.
select case(trim(adjustl(cformat)))
case default
compression_format = compression_none
compression_level = 0
compression_level = clevel
suffix = ""
success = .true.
end select
!-------------------------------------------------------------------------------
@ -148,16 +144,12 @@ module compression
integer(kind=1), dimension(:), target, intent(out) :: output
integer(kind=8) , intent(out) :: csize
! local variables
!
integer(kind=8) :: bsize
!-------------------------------------------------------------------------------
!
bsize = min(size(input), size(output))
csize = min(size(input), size(output))
select case(compression_format)
case default
output(1:bsize) = input(1:bsize)
output(1:csize) = input(1:csize)
end select
!-------------------------------------------------------------------------------

View File

@ -172,6 +172,15 @@ module io
!
logical , save :: with_xdmf = .false.
! the compression format and level of the XML+binary files
!
character(len=255), save :: cformat = "none" ! compression format
integer , save :: clevel = 3 ! compression level
! the suffix of binary files in the XML+binary format
!
character(len=8) , save :: binary_file_suffix = ".bin"
#ifdef HDF5
! compression type
!
@ -181,10 +190,6 @@ module io
!
integer , save :: compression = 0
! compression level
!
integer , save :: clevel = 0
! HDF5 property object identifier
!
integer(hid_t) , save :: pid
@ -238,6 +243,7 @@ module io
! import external procedures
!
use compression , only : set_compression, get_compression
#ifdef HDF5
use hdf5 , only : hsize_t
use hdf5 , only : H5P_DATASET_CREATE_F, H5Z_FLAG_OPTIONAL_F
@ -258,10 +264,12 @@ module io
! local variables
!
logical :: success
character(len=255) :: sformat = "xml"
character(len=255) :: precise = "off"
character(len=255) :: ghosts = "on"
character(len=255) :: xdmf = "off"
character(len=255) :: suffix = "" ! compression file suffix
#ifdef HDF5
logical :: cmpstatus = .false.
integer(hsize_t) :: cd_nelmts = 1
@ -334,6 +342,16 @@ module io
restart_format = snapshot_xml
end select
! get compression format and level for XML+binary files
!
call get_parameter("compression_format", cformat)
call get_parameter("compression_level" , clevel)
call set_compression(cformat, clevel, suffix)
if (get_compression() > 0) then
binary_file_suffix = ".bin" // trim(adjustl(suffix))
print *, trim(cformat), clevel, suffix, trim(binary_file_suffix)
end if
! check the snapshot type
!
select case(ftype)
@ -2639,12 +2657,12 @@ module io
! store metablock data
!
write(fname,"(a,'.bin')") "metablock_fields"
write(fname,"(a,a)") "metablock_fields", trim(binary_file_suffix)
call write_binary_xml(trim(dname), trim(fname), &
transfer(fields, [ 0_1 ]), bytes, digest)
call write_attribute_xml(lun, "fields", trim(fname), bytes, digest)
write(fname,"(a,'.bin')") "metablock_bounds"
write(fname,"(a,a)") "metablock_bounds", trim(binary_file_suffix)
call write_binary_xml(trim(dname), trim(fname), &
transfer(bounds, [ 0_1 ]), bytes, digest)
call write_attribute_xml(lun, "bounds", trim(fname), bytes, digest)
@ -2706,13 +2724,15 @@ module io
end do ! data blocks
write(fname,"(a,'_',a,'_',i6.6,'.bin')") "datablock", "ids", nproc
write(fname,"(a,'_',a,'_',i6.6,a)") "datablock", "ids", &
nproc, trim(binary_file_suffix)
call write_binary_xml(trim(dname), trim(fname), &
transfer(ids, [ 0_1 ]), bytes, digest)
call write_attribute_xml(lun, "ids", trim(fname), bytes, digest)
do p = 1, nv
write(fname,"(a,'_',a,'_',i6.6,'.bin')") "datablock", trim(pvars(p)), nproc
write(fname,"(a,'_',a,'_',i6.6,a)") "datablock", trim(pvars(p)), &
nproc, trim(binary_file_suffix)
call write_binary_xml(trim(dname), trim(fname), &
transfer(arrays(p,:,:,:,:), [ 0_1 ]), bytes, digest)
call write_attribute_xml(lun, trim(pvars(p)), trim(fname), bytes, digest)