Toml_input.f90 Source File


This file depends on

sourcefile~~toml_input.f90~~EfferentGraph sourcefile~toml_input.f90 Toml_input.f90 sourcefile~argument.f90 Argument.f90 sourcefile~toml_input.f90->sourcefile~argument.f90 sourcefile~config.f90 Config.f90 sourcefile~toml_input.f90->sourcefile~config.f90

Contents

Source Code


Source Code

!> 读取 toml
module toml_input_m

    use argument_m, only: get_path
    use config_m, only: in_path, out_path, dofile, lua_script, form
    use error_stop_m, only: error_stop
    use easy_string_m, only: to_string
    use stdlib_logger, only: stdlog => global_logger
    use swift_file_m, only: is_exist
    use tomlf, only: toml_table, get_value, toml_parse

contains

    !> 获取工程路径
    subroutine get_access()
        type(toml_table), allocatable :: access_table
        type(toml_table), pointer :: subtable
        character(:), allocatable :: cwd
        call get_path(cwd)
        if (.not. is_exist(cwd//'/access.toml')) then
            call error_stop('access.toml not found', &
                            'toml_input%get_access')
        end if

        open (1, file=cwd//'/access.toml', status='old')
        call toml_parse(access_table, 1)
        close (1)

        call get_value(access_table, 'access', subtable)
        call get_value(subtable, 'in', in_path)
        call get_value(subtable, 'out', out_path)

        call stdlog%log_information('in_path: '//in_path)
        call stdlog%log_information('out_path: '//out_path)

        nullify (subtable)
    end subroutine get_access

    !> 读取前处理配置
    subroutine get_ini()
        type(toml_table), allocatable :: ini_table
        type(toml_table), pointer :: subtable
        if (.not. is_exist(in_path//'/sph.toml')) then
            call error_stop('sph.toml not found', &
                            'toml_input%get_ini')
        end if

        open (1, file=in_path//'/sph.toml', status='old')
        call toml_parse(ini_table, 1)
        close (1)

        call get_value(ini_table, 'pre-process', subtable)
        call get_value(subtable, 'dofile', dofile, .false.)
        call get_value(subtable, 'lua_script', lua_script, 'ini_lua_script.lua')
        call get_value(subtable, 'form', form, 'unformatted')
        if (form /= 'unformatted' .and. form /= 'formatted') then
            call error_stop('form must be unformatted or formatted', &
                            'toml_input%get_ini')
        end if

        call stdlog%log_information('dofile: '//to_string(dofile))
        call stdlog%log_information('lua_script: '//lua_script)
        call stdlog%log_information('form: '//form)

        nullify (subtable)
    end subroutine get_ini

end module toml_input_m