Reads neutral populations from file and puts it in neut
subroutine read_neutrals
!+ Reads neutral populations from file and puts it in [[libfida:neut]]
integer(HID_T) :: fid, gid
integer(HSIZE_T), dimension(4) :: dims
integer :: error,nx,ny,nz
logical :: exis,fatal_error
if(inputs%verbose.ge.1) then
write(*,'(a)') '---- loading neutrals ----'
endif
inquire(file=inputs%neutrals_file,exist=exis)
if(exis) then
if(inputs%verbose.ge.1) then
write(*,'(T2,"Neutrals file: ",a)') trim(inputs%neutrals_file)
write(*,*) ''
endif
else
if(inputs%verbose.ge.0) then
write(*,'(a,a)') 'READ_NEUTRALS: Neutrals file does not exist: ',inputs%neutrals_file
endif
stop
endif
!Open HDF5 interface
call h5open_f(error)
!Create file overwriting any existing file
call h5fopen_f(inputs%neutrals_file, H5F_ACC_RDONLY_F, fid, error)
call h5gopen_f(fid, "/grid", gid, error)
call h5ltread_dataset_int_scalar_f(gid,"nx", nx, error)
call h5ltread_dataset_int_scalar_f(gid,"ny", ny, error)
call h5ltread_dataset_int_scalar_f(gid,"nz", nz, error)
call h5gclose_f(gid, error)
fatal_error = .False.
if((nx.ne.beam_grid%nx).or. &
(ny.ne.beam_grid%ny).or. &
(nz.ne.beam_grid%nz)) then
if(inputs%verbose.ge.0) then
write(*,'(a)') 'READ_NEUTRALS: Neutrals file has incompatable grid dimensions'
endif
fatal_error = .True.
endif
!Check to make sure the neutrals file has all the needed neutrals
call h5ltpath_valid_f(fid, "/full", .True., exis, error)
if((.not.exis).and.(inputs%calc_nbi_dens.ge.1)) then
if(inputs%verbose.ge.0) then
write(*,'(a)') 'READ_NEUTRALS: Full energy neutral population is not in the neutrals file'
endif
fatal_error = .True.
endif
call h5ltpath_valid_f(fid, "/half", .True., exis, error)
if((.not.exis).and.(inputs%calc_nbi_dens.ge.1)) then
if(inputs%verbose.ge.0) then
write(*,'(a)') 'READ_NEUTRALS: Half energy neutral population is not in the neutrals file'
endif
fatal_error = .True.
endif
call h5ltpath_valid_f(fid, "/third", .True., exis, error)
if((.not.exis).and.(inputs%calc_nbi_dens.ge.1)) then
if(inputs%verbose.ge.0) then
write(*,'(a)') 'READ_NEUTRALS: Third energy neutral population is not in the neutrals file'
endif
fatal_error = .True.
endif
call h5ltpath_valid_f(fid, "/dcx", .True., exis, error)
if((.not.exis).and.(inputs%calc_dcx_dens.ge.1)) then
if(inputs%verbose.ge.0) then
write(*,'(a)') 'READ_NEUTRALS: Direct Charge Exchange (DCX) neutral population is not in the neutrals file'
endif
fatal_error = .True.
endif
call h5ltpath_valid_f(fid, "/halo", .True., exis, error)
if((.not.exis).and.(inputs%calc_halo_dens.ge.1)) then
if(inputs%verbose.ge.0) then
write(*,'(a)') 'READ_NEUTRALS: Thermal Halo neutral population is not in the neutrals file'
endif
fatal_error = .True.
endif
if(fatal_error) stop
if(inputs%calc_nbi_dens.ge.1) then
call h5gopen_f(fid, "/full", gid, error)
call read_neutral_population(gid, neut%full, error)
call h5gclose_f(gid, error)
call h5gopen_f(fid, "/half", gid, error)
call read_neutral_population(gid, neut%half, error)
call h5gclose_f(gid, error)
call h5gopen_f(fid, "/third", gid, error)
call read_neutral_population(gid, neut%third, error)
call h5gclose_f(gid, error)
endif
if(inputs%calc_dcx_dens.ge.1) then
call h5gopen_f(fid, "/dcx", gid, error)
call read_neutral_population(gid, neut%dcx, error)
call h5gclose_f(gid, error)
endif
if(inputs%calc_halo_dens.ge.1) then
call h5gopen_f(fid, "/halo", gid, error)
call read_neutral_population(gid, neut%halo, error)
call h5gclose_f(gid, error)
endif
!Close file
call h5fclose_f(fid, error)
!Close HDF5 interface
call h5close_f(error)
end subroutine read_neutrals