Unmatched quote and type mismatch errors

The code below compiles with g95 and Intel Fortran but not with PVF 7.0.7. I’ve noticed that exchanging the order of the following declaration lines inside realToChar function:

real(rp), intent(in)          :: num
character(getRealLength(num)) :: char

resolves the first error (type mismatch), but the second remains. A (not so) minimal test case follows:

module printUtils

    implicit none

    private
    
    integer, parameter :: rp = selected_real_kind(p=15);

    interface strLen
        module procedure getRealLength
    end interface strLen

    interface toChar
        module procedure realToChar
    end interface toChar

contains

    pure function getRealLength(num) result(len)
        integer              :: len
        real(rp), intent(in) :: num
        character(50)        :: tmp

        write(tmp, *) num
        len = len_trim(tmp)

    end function getRealLength


    pure function realToChar(num) result(char)
        character(getRealLength(num)) :: char
        real(rp), intent(in)          :: num

        write(char, *) num

    end function realToChar
    
    pure function len_nopath(fname) result(len)
        character(*), intent(in) :: fname
        integer :: len, fin

        fin = len_trim(fname)
        len = fin - index(trim(fname), '/', back=.true.)
        if (len == fin) len = fin - index(trim(fname), '\', back=.true.)
        if (len == fin) len = fin

    end function len_nopath

end module printUtils

Hi Bernhard,

The error is caused by the use of the escape character in a string. To fix, escape the escape character:

if (len == fin) len = fin - index(trim(fname), '\\', back=.true.)

Hope this helps,
Mat

Got it. But what is the cause of the first error?

Thanks again,

Bernhard Enders

In this code:

pure function realToChar(num) result(char)
character(getRealLength(num)) :: char
real(rp), intent(in) :: num

You are using num as an argument (at runtime) to getRealLength() before it
is explicitly defined as having type real(rp). It defaults to type integer. This is sort of a gray area of the spec, sort of a bug. We are working on fixing these types of problems, since as you point out other compilers can handle it