Faster string to double

You can check out the latest implementation str2num_m

The core algorithm is now in an elemental subroutine:

elemental subroutine str2real_base(s,r,p,stat)
    ! -- In/out Variables
    character(*), intent(in) :: s !< input string
    real(wp), intent(inout)  :: r !< Output real value
    integer(1), intent(out)  :: p !< position within the number
    integer(1), intent(out)  :: stat !< status upon success or failure to read
...
end subroutine

And both user interfaces are kept with the functions

elemental function str2real(s) result(r)
    ...
    call str2real_base(s,r,p,stat)
end function

function str2real_p(s,stat) result(r)
    character(len=:), pointer :: s !< input string
    ...
    call str2real_base(s,r,p,err)
    p = min( p , len(s) )
    s => s(p:)
    if(present(stat)) stat = err
end function

I did nothing fancy regarding the error status for the moment. just a constant value at the beginning and 0 if success

1 Like