Writes neut to a HDF5 file
subroutine write_neutrals
!+ Writes [[libfida:neut]] to a HDF5 file
integer(HID_T) :: fid
integer(HSIZE_T), dimension(4) :: dims
integer(HSIZE_T), dimension(1) :: d
integer :: error
character(charlim) :: filename
filename=trim(adjustl(inputs%result_dir))//"/"//trim(adjustl(inputs%runid))//"_neutrals.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)
dims = [nlevs, beam_grid%nx, beam_grid%ny, beam_grid%nz]
d(1) =1
call h5ltmake_dataset_int_f(fid,"/nlevel", 0, d, [nlevs], error)
call h5ltset_attribute_string_f(fid,"/nlevel","description", &
"Number of atomic energy levels", error)
if(inputs%calc_nbi_dens.ge.1) then
call h5ltmake_compressed_dataset_double_f(fid, "/fdens", 4, dims, &
neut%full, error)
call h5ltset_attribute_string_f(fid,"/fdens","units","neutrals*cm^-3",error)
call h5ltmake_compressed_dataset_double_f(fid, "/hdens", 4, dims, &
neut%half, error)
call h5ltmake_compressed_dataset_double_f(fid, "/tdens", 4, dims, &
neut%third, error)
call h5ltset_attribute_string_f(fid,"/fdens","description", &
"Neutral density for the full energy component of the beam: fdens(level,x,y,z)", error)
call h5ltset_attribute_string_f(fid,"/hdens","description", &
"Neutral density for the half energy component of the beam: hdens(level,x,y,z)", error)
call h5ltset_attribute_string_f(fid,"/hdens","units","neutrals*cm^-3",error)
call h5ltset_attribute_string_f(fid,"/tdens","description", &
"Neutral density for the third energy component of the beam: tdens(level,x,y,z)", error)
call h5ltset_attribute_string_f(fid,"/tdens","units","neutrals*cm^-3",error)
endif
if(inputs%calc_dcx_dens.ge.1) then
call h5ltmake_compressed_dataset_double_f(fid, "/dcxdens", 4, dims, &
neut%dcx, error)
call h5ltset_attribute_string_f(fid,"/dcxdens","description", &
"Direct Charge Exchange (DCX) neutral density: dcxdens(level,x,y,z)", error)
call h5ltset_attribute_string_f(fid,"/dcxdens","units","neutrals*cm^-3",error)
endif
if(inputs%calc_halo_dens.ge.1) then
call h5ltmake_compressed_dataset_double_f(fid, "/halodens", 4, dims, &
neut%halo, error)
call h5ltset_attribute_string_f(fid,"/halodens","description", &
"Neutral density of the beam halo: halodens(level,x,y,z)", error)
call h5ltset_attribute_string_f(fid,"/halodens","units","neutrals*cm^-3",error)
endif
call h5ltset_attribute_string_f(fid, "/", "version", version, error)
call h5ltset_attribute_string_f(fid,"/","description", &
"Beam neutral density calculated by FIDASIM", error)
!Close file
call h5fclose_f(fid, error)
!Close HDF5 interface
call h5close_f(error)
if(inputs%verbose.ge.1) then
write(*,'(T4,a,a)') 'neutral density written to: ',trim(filename)
endif
end subroutine write_neutrals