Write beam_grid to an HDF5 file
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=HID_T), | intent(inout) | :: | id | HDF5 file ID |
||
integer, | intent(out) | :: | error | Error code |
subroutine write_beam_grid(id, error)
!+ Write [[libfida:beam_grid]] to an HDF5 file
integer(HID_T), intent(inout) :: id
!+ HDF5 file ID
integer, intent(out) :: error
!+ Error code
integer(HID_T) :: gid
integer(HSIZE_T), dimension(3) :: dims
real(Float64), dimension(beam_grid%nx,beam_grid%ny,beam_grid%nz) :: u_grid, v_grid, w_grid
real(Float64) :: xyz(3),uvw(3)
integer :: i,j,k
!Create uvw grids
do k=1, beam_grid%nz
do j=1, beam_grid%ny
do i=1, beam_grid%nx
xyz = [beam_grid%xc(i), &
beam_grid%yc(j), &
beam_grid%zc(k)]
call xyz_to_uvw(xyz,uvw)
u_grid(i,j,k) = uvw(1)
v_grid(i,j,k) = uvw(2)
w_grid(i,j,k) = uvw(3)
enddo
enddo
enddo
!Create grid group
call h5gcreate_f(id, "grid", gid, error)
!Write variables
dims(1) = 1
call h5ltmake_dataset_int_f(gid,"nx", 0, dims(1:1), [beam_grid%nx], error)
call h5ltmake_dataset_int_f(gid,"ny", 0, dims(1:1), [beam_grid%ny], error)
call h5ltmake_dataset_int_f(gid,"nz", 0, dims(1:1), [beam_grid%nz], error)
dims = [beam_grid%nx, beam_grid%ny, beam_grid%nz]
call h5ltmake_compressed_dataset_double_f(gid,"x", 1, dims(1:1), beam_grid%xc, error)
call h5ltmake_compressed_dataset_double_f(gid,"y", 1, dims(2:2), beam_grid%yc, error)
call h5ltmake_compressed_dataset_double_f(gid,"z", 1, dims(3:3), beam_grid%zc, error)
call h5ltmake_compressed_dataset_double_f(gid,"x_grid", 3, dims, u_grid, error)
call h5ltmake_compressed_dataset_double_f(gid,"y_grid", 3, dims, v_grid, error)
call h5ltmake_compressed_dataset_double_f(gid,"z_grid", 3, dims, w_grid, error)
!Write attributes
call h5ltset_attribute_string_f(gid,"nx","description", &
"Number of cells in the X direction", error)
call h5ltset_attribute_string_f(gid,"ny","description", &
"Number of cells in the Y direction", error)
call h5ltset_attribute_string_f(gid,"nz","description", &
"Number of cells in the Z direction", error)
call h5ltset_attribute_string_f(gid,"x","description", &
"X value of cell center in beam grid coordinates", error)
call h5ltset_attribute_string_f(gid,"x","units", "cm", error)
call h5ltset_attribute_string_f(gid,"y","description", &
"Y value of cell center in beam grid coordinates", error)
call h5ltset_attribute_string_f(gid,"y","units", "cm", error)
call h5ltset_attribute_string_f(gid,"z","description", &
"Z value of cell center in beam grid coordinates", error)
call h5ltset_attribute_string_f(gid,"z","units", "cm", error)
call h5ltset_attribute_string_f(gid,"x_grid","description", &
"X value of cell center in machine coordinates: x_grid(x,y,z)", error)
call h5ltset_attribute_string_f(gid,"x_grid","units", "cm", error)
call h5ltset_attribute_string_f(gid,"y_grid","description", &
"Y value of cell center in machine coordinates: y_grid(x,y,z)", error)
call h5ltset_attribute_string_f(gid,"y_grid","units", "cm", error)
call h5ltset_attribute_string_f(gid,"z_grid","description", &
"Z value of cell center in machine coordinates: z_grid(x,y,z)", error)
call h5ltset_attribute_string_f(gid,"z_grid","units", "cm", error)
call h5ltset_attribute_string_f(id,"grid","coordinate_system", &
"Right-handed cartesian",error)
!Close grid group
call h5gclose_f(gid, error)
end subroutine write_beam_grid