Writes birth to a HDF5 file
subroutine write_birth_profile
!+ Writes [[libfida:birth]] to a HDF5 file
integer(HID_T) :: fid
integer(HSIZE_T), dimension(4) :: dim4
integer(HSIZE_T), dimension(2) :: dim2
integer(HSIZE_T), dimension(1) :: d
integer :: error, i, npart
character(charlim) :: filename
real(Float64), dimension(:,:), allocatable :: ri
real(Float64), dimension(:,:), allocatable :: vi
real(Float64), dimension(3) :: xyz,uvw,v_uvw
npart = birth%cnt-1
allocate(ri(3,npart))
allocate(vi(3,npart))
do i=1,npart
! Convert position to rzphi
xyz = birth%ri(:,i)
call xyz_to_uvw(xyz,uvw)
ri(1,i) = sqrt(uvw(1)*uvw(1) + uvw(2)*uvw(2))
ri(2,i) = uvw(3)
ri(3,i) = atan2(uvw(2),uvw(1))
! Convert velocity to rzphi
v_uvw = matmul(beam_grid%basis, birth%vi(:,i))
vi(1,i) = v_uvw(1)*cos(ri(3,i)) + v_uvw(2)*sin(ri(3,i))
vi(2,i) = v_uvw(3)
vi(3,i) = -v_uvw(1)*sin(ri(3,i)) + v_uvw(2)*cos(ri(3,i))
enddo
filename=trim(adjustl(inputs%result_dir))//"/"//trim(adjustl(inputs%runid))//"_birth.h5"
!Open HDF5 interface
call h5open_f(error)
!Create file overwriting any existing file
call h5fcreate_f(filename, H5F_ACC_TRUNC_F, fid, error)
!Write variables
call write_beam_grid(fid, error)
d(1) = 1
call h5ltmake_dataset_int_f(fid, "/n_birth", 0, d, [npart], error)
dim4 = shape(birth%dens)
call h5ltmake_compressed_dataset_double_f(fid,"/dens", 4, dim4, birth%dens, error)
dim2 = [3, npart]
call h5ltmake_compressed_dataset_double_f(fid,"/ri", 2, dim2, ri, error)
call h5ltmake_compressed_dataset_double_f(fid,"/vi", 2, dim2, vi, error)
call h5ltmake_compressed_dataset_int_f(fid,"/ind", 2, dim2, birth%ind, error)
call h5ltmake_compressed_dataset_int_f(fid,"/type", 1, dim2(2:2), birth%neut_type, error)
!Add attributes
call h5ltset_attribute_string_f(fid, "/n_birth","description", &
"Number of birth mc particles deposited", error)
call h5ltset_attribute_string_f(fid, "/dens", "description", &
"Birth density: dens(beam_component,x,y,z)", error)
call h5ltset_attribute_string_f(fid, "/dens", "units", &
"fast-ions/(s*cm^3)", error)
call h5ltset_attribute_string_f(fid, "/ri", "description", &
"Fast-ion birth position in R-Z-Phi: ri([r,z,phi],particle)", error)
call h5ltset_attribute_string_f(fid, "/ri", "units", "cm, radians", error)
call h5ltset_attribute_string_f(fid, "/vi", "description", &
"Fast-ion birth velocity in R-Z-Phi: vi([r,z,phi],particle)", error)
call h5ltset_attribute_string_f(fid, "/vi", "units", "cm/s", error)
call h5ltset_attribute_string_f(fid, "/ind", "description", &
"Fast-ion birth beam grid indices: ind([i,j,k],particle)", error)
call h5ltset_attribute_string_f(fid, "/type", "description", &
"Fast-ion birth type (1=Full, 2=Half, 3=Third)", error)
call h5ltset_attribute_string_f(fid, "/", "coordinate_system", &
"Cylindrical (R,Z,Phi)",error)
call h5ltset_attribute_string_f(fid, "/", "version", version, error)
call h5ltset_attribute_string_f(fid, "/", "description", &
"Birth density and particles calculated by FIDASIM", error)
!!Close file
call h5fclose_f(fid, error)
!!Close HDF5 interface
call h5close_f(error)
deallocate(ri,vi)
if(inputs%verbose.ge.1) then
write(*,'(T4,a,a)') 'birth profile written to: ',trim(filename)
endif
end subroutine write_birth_profile