new_profiles Subroutine

public subroutine new_profiles(profiles, table, error)

Construct new profiles array from a TOML data structure

Arguments

Type IntentOptional Attributes Name
type(profile_config_t), intent(out), allocatable :: profiles(:)

Instance of the profile configuration array

type(toml_table), intent(inout) :: table

Instance of the TOML data structure

type(error_t), intent(out), allocatable :: error

Error handling


Source Code

    subroutine new_profiles(profiles, table, error)

        !> Instance of the profile configuration array
        type(profile_config_t), allocatable, intent(out) :: profiles(:)

        !> Instance of the TOML data structure
        type(toml_table), intent(inout) :: table

        !> Error handling
        type(error_t), allocatable, intent(out) :: error

        type(toml_array), pointer :: array_node
        type(toml_key), allocatable :: list(:)
        integer :: iprofile, stat

        call table%get_keys(list)

        if (size(list) < 1) then
            allocate(profiles(0))
            return
        end if

        allocate(profiles(size(list)))

        do iprofile = 1, size(list)
            call get_value(table, list(iprofile)%key, array_node, stat=stat)
            if (stat /= toml_stat%success) then
                call fatal_error(error, "Profile "//list(iprofile)%key//" must be an array of feature names")
                exit
            end if
            call new_profile(profiles(iprofile), array_node, list(iprofile)%key, error)
            if (allocated(error)) exit
        end do

    end subroutine new_profiles