Add to_hdf5 type-bound procedure to RegularMesh

This commit is contained in:
Paul Romano 2017-08-09 12:49:27 -05:00
parent 6e82c34a58
commit 01fcdf9acd
2 changed files with 31 additions and 16 deletions

View file

@ -1,9 +1,16 @@
module mesh_header
use hdf5
use constants, only: NO_BIN_FOUND
use hdf5_interface
use string, only: to_str
implicit none
private
public :: RegularMesh, meshes
!===============================================================================
! STRUCTUREDMESH represents a tessellation of n-dimensional Euclidean space by
! congruent squares or cubes
@ -24,6 +31,7 @@ module mesh_header
procedure :: get_bin_from_indices => regular_get_bin_from_indices
procedure :: get_indices_from_bin => regular_get_indices_from_bin
procedure :: intersects => regular_intersects
procedure :: to_hdf5 => regular_to_hdf5
end type RegularMesh
type(RegularMesh), allocatable, target :: meshes(:)
@ -379,4 +387,25 @@ contains
end function mesh_intersects_3d
!===============================================================================
! TO_HDF5 writes the mesh data to an HDF5 group
!===============================================================================
subroutine regular_to_hdf5(this, group)
class(RegularMesh), intent(in) :: this
integer(HID_T), intent(in) :: group
integer(HID_T) :: mesh_group
mesh_group = create_group(group, "mesh " // trim(to_str(this % id)))
call write_dataset(mesh_group, "type", "regular")
call write_dataset(mesh_group, "dimension", this % dimension)
call write_dataset(mesh_group, "lower_left", this % lower_left)
call write_dataset(mesh_group, "upper_right", this % upper_right)
call write_dataset(mesh_group, "width", this % width)
call close_group(mesh_group)
end subroutine regular_to_hdf5
end module mesh_header

View file

@ -45,7 +45,7 @@ contains
integer, allocatable :: id_array(:)
integer(HID_T) :: file_id
integer(HID_T) :: cmfd_group, tallies_group, tally_group, meshes_group, &
mesh_group, filters_group, filter_group, derivs_group, &
filters_group, filter_group, derivs_group, &
deriv_group, runtime_group
integer(C_INT) :: err
real(C_DOUBLE) :: k_combined(2)
@ -158,21 +158,7 @@ contains
! Write information for meshes
MESH_LOOP: do i = 1, n_meshes
associate (m => meshes(i))
mesh_group = create_group(meshes_group, "mesh " &
// trim(to_str(m % id)))
select case (m % type)
case (MESH_REGULAR)
call write_dataset(mesh_group, "type", "regular")
end select
call write_dataset(mesh_group, "dimension", m % dimension)
call write_dataset(mesh_group, "lower_left", m % lower_left)
call write_dataset(mesh_group, "upper_right", m % upper_right)
call write_dataset(mesh_group, "width", m % width)
call close_group(mesh_group)
end associate
call meshes(i) % to_hdf5(meshes_group)
end do MESH_LOOP
end if