read_neutrals Subroutine

public subroutine read_neutrals()

Reads neutral populations from file and puts it in neut

Arguments

None

Calls

proc~~read_neutrals~~CallsGraph proc~read_neutrals read_neutrals h5gopen_f h5gopen_f proc~read_neutrals->h5gopen_f h5ltpath_valid_f h5ltpath_valid_f proc~read_neutrals->h5ltpath_valid_f h5fopen_f h5fopen_f proc~read_neutrals->h5fopen_f proc~h5ltread_dataset_int_scalar_f h5ltread_dataset_int_scalar_f proc~read_neutrals->proc~h5ltread_dataset_int_scalar_f h5open_f h5open_f proc~read_neutrals->h5open_f h5fclose_f h5fclose_f proc~read_neutrals->h5fclose_f h5gclose_f h5gclose_f proc~read_neutrals->h5gclose_f h5close_f h5close_f proc~read_neutrals->h5close_f proc~read_neutral_population read_neutral_population proc~read_neutrals->proc~read_neutral_population h5ltread_dataset_int_f h5ltread_dataset_int_f proc~h5ltread_dataset_int_scalar_f->h5ltread_dataset_int_f proc~read_neutral_population->h5gopen_f proc~read_neutral_population->proc~h5ltread_dataset_int_scalar_f proc~read_neutral_population->h5gclose_f proc~init_reservoir init_reservoir proc~read_neutral_population->proc~init_reservoir proc~ind2sub ind2sub proc~read_neutral_population->proc~ind2sub proc~read_neutral_population->h5ltread_dataset_int_f h5ltread_dataset_double_f h5ltread_dataset_double_f proc~read_neutral_population->h5ltread_dataset_double_f proc~init_neutral_population init_neutral_population proc~read_neutral_population->proc~init_neutral_population interface~randu randu proc~init_reservoir->interface~randu

Called by

proc~~read_neutrals~~CalledByGraph proc~read_neutrals read_neutrals program~fidasim fidasim program~fidasim->proc~read_neutrals

Contents

Source Code


Source Code

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