Writes Neutral Population to HDF5 group
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=HID_T), | intent(inout) | :: | id | HDF5 group ID |
||
type(NeutralPopulation), | intent(in) | :: | pop | Neutral Population to write |
||
integer, | intent(out) | :: | error | Error code |
subroutine write_neutral_population(id, pop, error)
!+ Writes Neutral Population to HDF5 group
integer(HID_T), intent(inout) :: id
!+ HDF5 group ID
type(NeutralPopulation), intent(in) :: pop
!+ Neutral Population to write
integer, intent(out) :: error
!+ Error code
integer(HID_T) :: gid
integer(HSIZE_T), dimension(1) :: d
integer(HSIZE_T), dimension(4) :: dims4
integer(HSIZE_T), dimension(5) :: dims5
real(Float64), dimension(:,:,:,:,:), allocatable :: v
real(Float64), dimension(:,:,:,:), allocatable :: w
integer(Int32), dimension(:,:,:), allocatable :: n
integer :: ic, ir, i, j, k, ind(3), nx, ny, nz, nk
nx = beam_grid%nx
ny = beam_grid%ny
nz = beam_grid%nz
dims4 = [nlevs, nx, ny, nz]
d(1) =1
call h5ltmake_dataset_int_f(id,"nlevel", 0, d, [nlevs], error)
call h5ltset_attribute_string_f(id,"nlevel","description", &
"Number of atomic energy levels", error)
call h5ltmake_compressed_dataset_double_f(id, "dens", 4, dims4, pop%dens, error)
call h5ltset_attribute_string_f(id,"dens","units","neutrals*cm^-3",error)
call h5ltset_attribute_string_f(id,"dens","description", &
"Neutral density dens(level,x,y,z)", error)
dims5 = [3, reservoir_size, nx, ny, nz]
allocate(v(3,reservoir_size, nx, ny, nz))
allocate(w(reservoir_size, nx, ny, nz))
allocate(n(nx, ny, nz))
v = 0.d0; w = 0.d0
n = 0
do ic=1,beam_grid%ngrid
call ind2sub(beam_grid%dims,ic,ind)
i = ind(1) ; j = ind(2) ; k = ind(3)
n(i,j,k) = pop%res(i,j,k)%n
nk = min(pop%res(i,j,k)%k, pop%res(i,j,k)%n)
w(1:nk,i,j,k) = pop%res(i,j,k)%R(1:nk)%w
do ir=1, nk
v(:,ir,i,j,k) = pop%res(i,j,k)%R(ir)%v
enddo
enddo
!Create reservoir group
if(inputs%output_neutral_reservoir.eq.1) then
call h5gcreate_f(id, "reservoir", gid, error)
call h5ltset_attribute_string_f(id,"reservoir","description", &
"Neutral Particle Reservoir",error)
call h5ltmake_dataset_int_f(gid,"k", 0, d, [maxval(pop%res%k)], error)
call h5ltset_attribute_string_f(gid,"k","description", &
"Reservoir Size", error)
call h5ltmake_compressed_dataset_int_f(gid, "n", 3, dims4(2:4), n, error)
call h5ltset_attribute_string_f(gid, "n", "description", &
"Number of particles in each reservoir", error)
call h5ltmake_compressed_dataset_double_f(gid, "w", 4, dims5(2:5), w, error, compress=.False.)
call h5ltset_attribute_string_f(gid, "w", "description", &
"Neutral Particle Weight", error)
call h5ltmake_compressed_dataset_double_f(gid, "v", 5, dims5, v, error, compress=.False.)
call h5ltset_attribute_string_f(gid,"v","units","cm/s",error)
call h5ltset_attribute_string_f(gid,"v","description", &
"Neutral Particle velocity in beam grid coordinates v(:,particle,i,j,k)", error)
!Close reservoir group
call h5gclose_f(gid, error)
endif
deallocate(v,w,n)
end subroutine write_neutral_population