io_params_template_model_s.f90 Source File


Contents


Source Code

submodule (params_template_m) io_params_template_model_s
    !! Handles I/O of model parameters of template models
    use parallelisation_setup_m, only : is_rank_info_writer
    use screen_io_m, only : get_stdout
    use error_handling_grillix_m, only: handle_error
    use status_codes_grillix_m, only : GRILLIX_ERR_NAMELIST
    implicit none

    namelist / model_template / dperp_coeff_dens, dperp_coeff_parmom, dperp_coeff_pion, &
        dpar_coeff_dens, dpar_coeff_parmom, dpar_coeff_pion, ion_heat_cond_coeff

contains

    module subroutine read_params_template_model(optional_filepath)
        !! Initializes parameters related with model configuration
        character(len=*), intent(in), optional :: optional_filepath
        !! Filename, where to read model parameters from

        character(len=:), allocatable :: fpath
        integer :: io_unit, io_error
        character(len=256) :: io_errmsg

        if (present(optional_filepath)) then
            fpath = optional_filepath
        else
            fpath = path_params
        endif

        open(newunit=io_unit, file=fpath, 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=model_template, 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

    module subroutine display_params_template_model()

        if (is_rank_info_writer) then
            write(get_stdout(), nml=model_template)
        endif

    end subroutine

end submodule