IO: Rewrite subroutine store_coordinates_h5().

Signed-off-by: Grzegorz Kowal <grzegorz@amuncode.org>
This commit is contained in:
Grzegorz Kowal 2021-11-23 09:55:59 -03:00
parent 6287c18ded
commit 7dd68c6ea7

View File

@ -5151,76 +5151,74 @@ module io
status = 0
call h5gcreate_f(loc_id, 'coordinates', grp_id, status)
if (status >= 0) then
if (status /= 0) then
call print_message(loc, "Could not create group 'coordinates'!")
return
end if
if (get_dblocks() > 0) then
n = get_dblocks()
am(1) = toplev
im(1) = n
cm(1) = NDIMS
cm(2) = n
bm(1) = NDIMS
bm(2) = 2
bm(3) = n
allocate(ids(n), levels(n), coords(NDIMS,n), &
bounds(NDIMS,2,n), stat=status)
if (status /= 0) then
call print_message(loc, "Could not allocate space for coordinates!")
else
n = 0
pdata => list_data
do while(associated(pdata))
pmeta => pdata%meta
n = n + 1
ids(n) = pmeta%id
levels(n) = pmeta%level
coords(:,n) = pmeta%coords(:)
bounds(1,:,n) = [ pmeta%xmin, pmeta%xmax ]
bounds(2,:,n) = [ pmeta%ymin, pmeta%ymax ]
am(1) = toplev
call store_dataset_h5(grp_id, 'dx', H5T_NATIVE_DOUBLE, am, adx, status)
call store_dataset_h5(grp_id, 'dy', H5T_NATIVE_DOUBLE, am, ady, status)
#if NDIMS == 3
bounds(3,:,n) = [ pmeta%zmin, pmeta%zmax ]
call store_dataset_h5(grp_id, 'dz', H5T_NATIVE_DOUBLE, am, adz, status)
#endif /* NDIMS == 3 */
pdata => pdata%next
end do
if (get_dblocks() > 0) then
call store_dataset_h5(grp_id, 'ids', &
H5T_NATIVE_INTEGER, im, ids, status)
call store_dataset_h5(grp_id, 'levels', &
H5T_NATIVE_INTEGER, im, levels, status)
call store_dataset_h5(grp_id, 'coords', &
H5T_NATIVE_INTEGER, cm, coords, status)
call store_dataset_h5(grp_id, 'bounds', &
H5T_NATIVE_DOUBLE, bm, bounds, status)
call store_dataset_h5(grp_id, 'dx', &
H5T_NATIVE_DOUBLE, am, adx, status)
call store_dataset_h5(grp_id, 'dy', &
H5T_NATIVE_DOUBLE, am, ady, status)
n = get_dblocks()
im(1) = n
cm(1) = NDIMS
cm(2) = n
bm(1) = NDIMS
bm(2) = 2
bm(3) = n
allocate(ids(n), levels(n), coords(NDIMS,n), &
bounds(NDIMS,2,n), stat=status)
if (status /= 0) then
call print_message(loc, "Could not allocate space for coordinates!")
else
n = 0
pdata => list_data
do while(associated(pdata))
pmeta => pdata%meta
n = n + 1
ids(n) = pmeta%id
levels(n) = pmeta%level
coords(:,n) = pmeta%coords(:)
bounds(1,:,n) = [ pmeta%xmin, pmeta%xmax ]
bounds(2,:,n) = [ pmeta%ymin, pmeta%ymax ]
#if NDIMS == 3
call store_dataset_h5(grp_id, 'dz', &
H5T_NATIVE_DOUBLE, am, adz, status)
bounds(3,:,n) = [ pmeta%zmin, pmeta%zmax ]
#endif /* NDIMS == 3 */
deallocate(ids, levels, coords, bounds, stat=status)
if (status > 0) &
call print_message(loc, "Could not deallocate the variables array!")
end if
pdata => pdata%next
end do
call store_dataset_h5(grp_id, 'ids', &
H5T_NATIVE_INTEGER, im, ids, status)
call store_dataset_h5(grp_id, 'levels', &
H5T_NATIVE_INTEGER, im, levels, status)
call store_dataset_h5(grp_id, 'coords', &
H5T_NATIVE_INTEGER, cm, coords, status)
call store_dataset_h5(grp_id, 'bounds', &
H5T_NATIVE_DOUBLE, bm, bounds, status)
deallocate(ids, levels, coords, bounds, stat=status)
if (status > 0) &
call print_message(loc, "Could not deallocate the coordinate space!")
end if
call h5gclose_f(grp_id, status)
if (status < 0) &
call print_message(loc, "Could not close group 'coordinates'!")
else
call print_message(loc, "Could not create group 'coordinates'!")
end if
call h5gclose_f(grp_id, status)
if (status < 0) &
call print_message(loc, "Could not close group 'coordinates'!")
!-------------------------------------------------------------------------------
!
end subroutine store_coordinates_h5