Rewrite subroutine write_variables_h5().

- the primitive variables in the 'p' file are stored now with single
   precision;

 - the subroutine has been also rewritten in order to simplify it;
This commit is contained in:
Grzegorz Kowal 2011-06-08 21:24:17 -03:00
parent eb19e3ea2f
commit a5e146b2db

View File

@ -3109,7 +3109,7 @@ module io
use hdf5 , only : hid_t, hsize_t use hdf5 , only : hid_t, hsize_t
use hdf5 , only : h5gcreate_f, h5gclose_f use hdf5 , only : h5gcreate_f, h5gclose_f
use scheme , only : cons2prim use scheme , only : cons2prim
use variables , only : nvr, nqt use variables , only : nqt
use variables , only : idn, ivx, ivy, ivz use variables , only : idn, ivx, ivy, ivz
#ifdef ADI #ifdef ADI
use variables , only : ipr use variables , only : ipr
@ -3138,13 +3138,13 @@ module io
! local allocatable arrays ! local allocatable arrays
! !
real(kind=8), dimension(:,:,:,:), allocatable :: u, q real , dimension(:,:,:,:), allocatable :: u, q
real(kind=8), dimension(:,:,:,:), allocatable :: dens, velx, vely, velz real(kind=4), dimension(:,:,:,:), allocatable :: dens, velx, vely, velz
#ifdef ADI #ifdef ADI
real(kind=8), dimension(:,:,:,:), allocatable :: pres real(kind=4), dimension(:,:,:,:), allocatable :: pres
#endif /* ADI */ #endif /* ADI */
#ifdef MHD #ifdef MHD
real(kind=8), dimension(:,:,:,:), allocatable :: magx, magy, magz real(kind=4), dimension(:,:,:,:), allocatable :: magx, magy, magz
#endif /* MHD */ #endif /* MHD */
! local pointers ! local pointers
@ -3153,30 +3153,34 @@ module io
! !
!------------------------------------------------------------------------------- !-------------------------------------------------------------------------------
! !
! create a group to store global attributes ! create a group to store primitive variables
! !
call h5gcreate_f(fid, 'variables', gid, err) call h5gcreate_f(fid, 'variables', gid, err)
! check if the group has been created successfuly ! print an error, if the group couldn't be created
! !
if (err .ge. 0) then if (err .eq. -1) call print_error("io::write_variables_h5" &
, "Cannot create the group 'variables'!")
! store variables only if there are some data blocks on the current processor ! store variables only if there are at least one data block on the current
! processor
! !
if (get_dblocks() .gt. 0) then if (get_dblocks() .gt. 0) then
! prepare dimensions ! prepare the variable dimensions
! !
dm(1) = get_dblocks() dm(1) = get_dblocks()
dm(2) = in dm(2) = in
dm(3) = jn dm(3) = jn
dm(4) = kn dm(4) = kn
! allocate arrays to store variables from all datablocks ! allocate arrays for conservative and primitive variables
! !
allocate(u(nvr ,im,jm,km)) allocate(u(nqt,im,jm,km))
allocate(q(nvr ,im,jm,km)) allocate(q(nqt,im,jm,km))
! allocate arrays to store the variables from current processor data blocks
!
allocate(dens(dm(1),dm(2),dm(3),dm(4))) allocate(dens(dm(1),dm(2),dm(3),dm(4)))
allocate(velx(dm(1),dm(2),dm(3),dm(4))) allocate(velx(dm(1),dm(2),dm(3),dm(4)))
allocate(vely(dm(1),dm(2),dm(3),dm(4))) allocate(vely(dm(1),dm(2),dm(3),dm(4)))
@ -3190,7 +3194,7 @@ module io
allocate(magz(dm(1),dm(2),dm(3),dm(4))) allocate(magz(dm(1),dm(2),dm(3),dm(4)))
#endif /* MHD */ #endif /* MHD */
! iterate over all data blocks and fill in the arrays ! iterate over the data blocks on current processor
! !
l = 1 l = 1
pdata => list_data pdata => list_data
@ -3200,47 +3204,55 @@ module io
! !
u(1:nqt,1:im,1:jm,1:km) = pdata%u(1:nqt,1:im,1:jm,1:km) u(1:nqt,1:im,1:jm,1:km) = pdata%u(1:nqt,1:im,1:jm,1:km)
! obtain the primitive variables from the conserved ones ! convert the conservative variables to their primitive representation
! !
do k = 1, km do k = 1, km
do j = 1, jm do j = 1, jm
call cons2prim(im, u(:,:,j,k), q(:,:,j,k)) call cons2prim(im, u(1:nqt,1:im,j,k), q(1:nqt,1:im,j,k))
end do end do
end do end do
dens(l,1:in,1:jn,1:kn) = q(idn,ib:ie,jb:je,kb:ke) ! copy the primitive variables to the stored arrays
velx(l,1:in,1:jn,1:kn) = q(ivx,ib:ie,jb:je,kb:ke)
vely(l,1:in,1:jn,1:kn) = q(ivy,ib:ie,jb:je,kb:ke)
velz(l,1:in,1:jn,1:kn) = q(ivz,ib:ie,jb:je,kb:ke)
#ifdef ADI
pres(l,1:in,1:jn,1:kn) = q(ipr,ib:ie,jb:je,kb:ke)
#endif /* ADI */
#ifdef MHD
magx(l,1:in,1:jn,1:kn) = q(ibx,ib:ie,jb:je,kb:ke)
magy(l,1:in,1:jn,1:kn) = q(iby,ib:ie,jb:je,kb:ke)
magz(l,1:in,1:jn,1:kn) = q(ibz,ib:ie,jb:je,kb:ke)
#endif /* MHD */
l = l + 1
pdata => pdata%next
end do
! write the variables to the HDF5 file
! !
call write_array4_double_h5(gid, 'dens', dm, dens) dens(l,1:in,1:jn,1:kn) = real(q(idn,ib:ie,jb:je,kb:ke),kind=4)
call write_array4_double_h5(gid, 'velx', dm, velx) velx(l,1:in,1:jn,1:kn) = real(q(ivx,ib:ie,jb:je,kb:ke),kind=4)
call write_array4_double_h5(gid, 'vely', dm, vely) vely(l,1:in,1:jn,1:kn) = real(q(ivy,ib:ie,jb:je,kb:ke),kind=4)
call write_array4_double_h5(gid, 'velz', dm, velz) velz(l,1:in,1:jn,1:kn) = real(q(ivz,ib:ie,jb:je,kb:ke),kind=4)
#ifdef ADI #ifdef ADI
call write_array4_double_h5(gid, 'pres', dm, pres) pres(l,1:in,1:jn,1:kn) = real(q(ipr,ib:ie,jb:je,kb:ke),kind=4)
#endif /* ADI */ #endif /* ADI */
#ifdef MHD #ifdef MHD
call write_array4_double_h5(gid, 'magx', dm, magx) magx(l,1:in,1:jn,1:kn) = real(q(ibx,ib:ie,jb:je,kb:ke),kind=4)
call write_array4_double_h5(gid, 'magy', dm, magy) magy(l,1:in,1:jn,1:kn) = real(q(iby,ib:ie,jb:je,kb:ke),kind=4)
call write_array4_double_h5(gid, 'magz', dm, magz) magz(l,1:in,1:jn,1:kn) = real(q(ibz,ib:ie,jb:je,kb:ke),kind=4)
#endif /* MHD */ #endif /* MHD */
! deallocate allocatable arrays ! increase the block number
!
l = l + 1
! associate the data block pointer with the next block
!
pdata => pdata%next
end do
! store the primitive variables in the HDF5 file
!
call write_array4_float_h5(gid, 'dens', dm(:), dens(:,:,:,:))
call write_array4_float_h5(gid, 'velx', dm(:), velx(:,:,:,:))
call write_array4_float_h5(gid, 'vely', dm(:), vely(:,:,:,:))
call write_array4_float_h5(gid, 'velz', dm(:), velz(:,:,:,:))
#ifdef ADI
call write_array4_float_h5(gid, 'pres', dm(:), pres(:,:,:,:))
#endif /* ADI */
#ifdef MHD
call write_array4_float_h5(gid, 'magx', dm(:), magx(:,:,:,:))
call write_array4_float_h5(gid, 'magy', dm(:), magy(:,:,:,:))
call write_array4_float_h5(gid, 'magz', dm(:), magz(:,:,:,:))
#endif /* MHD */
! deallocate the temporary arrays
! !
if (allocated(dens)) deallocate(dens) if (allocated(dens)) deallocate(dens)
if (allocated(velx)) deallocate(velx) if (allocated(velx)) deallocate(velx)
@ -3259,27 +3271,14 @@ module io
end if ! dblocks > 0 end if ! dblocks > 0
! close the attribute group ! close the variables group
! !
call h5gclose_f(gid, err) call h5gclose_f(gid, err)
! check if the group has been closed successfuly ! print an error, if the group couldn't be closed
! !
if (err .gt. 0) then if (err .eq. -1) call print_error("io::write_variables_h5" &
, "Cannot close the group 'variables'!")
! print error about the problem with closing the group
!
call print_error("io::write_variables_h5", "Cannot close the group!")
end if
else
! print error about the problem with creating the group
!
call print_error("io::write_variables_h5", "Cannot create the group!")
end if
!------------------------------------------------------------------------------- !-------------------------------------------------------------------------------
! !