params_brag_floors_m.f90 Source File


Contents


Source Code

module params_brag_floors_m
    !! Parameters for the BRAGINSKII model related with floors
    use precision_grillix_m, only : GP, GP_EPS
    use error_handling_grillix_m, only: handle_error
    use status_codes_grillix_m, only : GRILLIX_ERR_NAMELIST
    use screen_io_m, only : get_stdout
    implicit none
         
    real(GP), protected :: floor_ne = GP_EPS
    !! Floor value for density
    real(GP), protected :: floor_te = GP_EPS
    !! Floor value for electron temperature
    real(GP), protected :: floor_ti = GP_EPS
    !! Floor value for ion temperature        
    
    public :: read_params_brag_floors
    public :: write_params_brag_floors
    
    namelist / brag_floors / &
        floor_ne, &
        floor_te, &
        floor_ti
    private brag_floors
    
contains
        
    subroutine read_params_brag_floors(filename)
        !! Reads parameters related with brag_floors
        character(len=*), intent(in) :: filename
        !! Filename, to read from 
        
        integer :: io_unit, io_error
        character(len=256) :: io_errmsg 
         
        open(newunit=io_unit, file=filename, status='old', action='read', &
            iostat=io_error, iomsg=io_errmsg)
        if (io_error /= 0) then
            call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, &
                              __LINE__, __FILE__)
        endif
  
        read(io_unit, nml=brag_floors, iostat=io_error, iomsg=io_errmsg)
        if (io_error /= 0) then
            call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, &
                              __LINE__, __FILE__)
        endif

        close(io_unit)

    end subroutine

    subroutine write_params_brag_floors(filename)
        !! Reads parameters related with brag_floors
        character(len=*), intent(in), optional :: filename
        !! If present, filename where params are written to, 
        !! if not present, writes to screen 
        
        integer :: io_unit, io_error
        character(len=256) :: io_errmsg 
         
        if (present(filename)) then
            open(newunit=io_unit, file=filename, status='unknown', &
                access='append', action='write', &
                iostat=io_error, iomsg=io_errmsg )
            if (io_error /= 0) then
                call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, &
                                  __LINE__, __FILE__)
            endif
        else
            io_unit = get_stdout()
        endif

        write(io_unit, nml=brag_floors, iostat=io_error, iomsg=io_errmsg)
        if (io_error /= 0) then
            call handle_error(io_errmsg, GRILLIX_ERR_NAMELIST, &
                              __LINE__, __FILE__)
        endif

        if (present(filename)) then
            close(io_unit)
        endif

    end subroutine
    
end module