read_neutrals Subroutine

public subroutine read_neutrals()

Reads neutral density from file and puts it in neut

Arguments

None

Calls

proc~~read_neutrals~~CallsGraph proc~read_neutrals read_neutrals h5close_f h5close_f proc~read_neutrals->h5close_f h5gopen_f h5gopen_f proc~read_neutrals->h5gopen_f h5ltpath_valid_f h5ltpath_valid_f proc~read_neutrals->h5ltpath_valid_f h5gclose_f h5gclose_f proc~read_neutrals->h5gclose_f h5open_f h5open_f proc~read_neutrals->h5open_f h5ltread_dataset_double_f h5ltread_dataset_double_f proc~read_neutrals->h5ltread_dataset_double_f proc~h5ltread_dataset_int_scalar_f h5ltread_dataset_int_scalar_f proc~read_neutrals->proc~h5ltread_dataset_int_scalar_f h5fclose_f h5fclose_f proc~read_neutrals->h5fclose_f h5fopen_f h5fopen_f proc~read_neutrals->h5fopen_f h5ltread_dataset_int_f h5ltread_dataset_int_f proc~h5ltread_dataset_int_scalar_f->h5ltread_dataset_int_f

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 density 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, "/fdens", .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 density is not in the neutrals file'
        endif
        fatal_error = .True.
    endif
    call h5ltpath_valid_f(fid, "/hdens", .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 density is not in the neutrals file'
        endif
        fatal_error = .True.
    endif
    call h5ltpath_valid_f(fid, "/tdens", .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 density is not in the neutrals file'
        endif
        fatal_error = .True.
    endif
    call h5ltpath_valid_f(fid, "/dcxdens", .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 density is not in the neutrals file'
        endif
        fatal_error = .True.
    endif
    call h5ltpath_valid_f(fid, "/halodens", .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 density is not in the neutrals file'
        endif
        fatal_error = .True.
    endif

    if(fatal_error) stop

    dims = [nlevs, nx, ny, nz]
    if(inputs%calc_nbi_dens.ge.1) then
        call h5ltread_dataset_double_f(fid,"/fdens", &
             neut%full, dims, error)
        call h5ltread_dataset_double_f(fid,"/hdens", &
             neut%half, dims, error)
        call h5ltread_dataset_double_f(fid,"/tdens", &
             neut%third, dims, error)
    endif
    if(inputs%calc_dcx_dens.ge.1) then
        call h5ltread_dataset_double_f(fid,"/dcxdens", &
             neut%dcx, dims, error)
    endif
    if(inputs%calc_halo_dens.ge.1) then
        call h5ltread_dataset_double_f(fid,"/halodens", &
             neut%halo, dims, error)
    endif

    !Close file
    call h5fclose_f(fid, error)

    !Close HDF5 interface
    call h5close_f(error)

end subroutine read_neutrals