read_name_real Function

public function read_name_real(name_str, default_val, unit_in, unit_out) result(res)

Reads single precision value from name file

Skips comments (!) and returns default value if name is not present in name file

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: name_str

Name of value in name file

real, intent(in) :: default_val

Default value

integer, intent(in) :: unit_in

Name file unit

integer, intent(in) :: unit_out

Log file unit

Return Value real

Value found in name file (or default value)


Called by

proc~~read_name_real~~CalledByGraph proc~read_name_real read_name_real interface~read_name read_name interface~read_name->proc~read_name_real proc~uemep_read_config uEMEP_read_config proc~uemep_read_config->proc~read_name_real program~uemep uEMEP program~uemep->proc~uemep_read_config

Source Code

    function read_name_real(name_str, default_val, unit_in, unit_out) result(res)
        !! Reads single precision value from name file
        !!
        !! Skips comments (!) and returns default value if name is not present in name file
        character(len=*), intent(in) :: name_str !! Name of value in name file
        real, intent(in) :: default_val !! Default value
        integer, intent(in) :: unit_in !! Name file unit
        integer, intent(in) :: unit_out !! Log file unit
        real :: res !! Value found in name file (or default value)

        ! Local variables
        integer :: i, index_val, io
        character(len=256) :: temp_str, temp_str1, temp_str2

        ! Initially, set to default value
        res = default_val

        rewind(unit_in)
        do
            read(unit_in, "(a)", iostat=io) temp_str
            if (io /= 0) then
                exit
            end if

            ! Remove tabs
            index_val = 0
            do i = 1, len(temp_str)
                if (ichar(temp_str(i:i)) .ne. 9) then
                    index_val = index_val + 1
                    temp_str1(index_val:index_val) = temp_str(i:i)
                end if
            end do
            temp_str = ADJUSTL(temp_str1)
            temp_str1 = ''

            ! If not a comment
            if (trim(temp_str(1:1)) .ne. '!') then
                ! Find the position of the equals sign if there is one
                index_val = index(temp_str, '=', back=.false.)
                if (index_val .gt. 1) then
                    ! Create the string before the equals sign
                    temp_str1 = trim(temp_str(1:index_val-1))

                    ! Check to see if it is a matching string
                    if (trim(temp_str1) .eq. trim(name_str)) then
                        ! Create the string after the equals sign
                        temp_str2=temp_str(index_val+1:)
                        temp_str2=adjustl(temp_str2)
                        if (len(trim(temp_str2)) .ge. 1) then
                            read(temp_str2,*, iostat=io) res
                            if (io /= 0) then
                                cycle
                            end if
                            write(unit_out,'(A,es12.4)') 'Setting: '//trim(name_str)//' = ', res
                        end if
                    end if
                end if
            end if
        end do
    end function read_name_real