编写了将字符转换为整数
的例程Integer :: j
Write (*,*) '# Call str_to_num ("12", j)'
Call str_to_num ("12", j)
Write (*,*) "j: ", j
我正在使用类(*)并收到错误
Program received signal 11 (SIGSEGV): Segmentation fault.
但是当我用Class(*)
更改Integer
时,我确实得到了
" Subroutine str_to_num"
正在打印。
此外,更改为Intent(inout)
而不是Intent(out)
工作的惯例
Subroutine str_to_num(s, num, fmt, wrn)
Character (len=*), Intent (in) :: s
Character (len=*), Intent (in), Optional :: fmt
Class (*), Intent (out) :: num
Character (len=*), Intent (inout), Optional :: wrn
Integer :: ios
Character (len=65) :: frmt
Write (*,*) " Subroutine str_to_num"
Select Type (num)
Type Is (Integer)
Read (s, *, iostat=ios) num
Type Is (Real)
Read (s, *, iostat=ios) num
Type Is (Double Precision)
Read (s, *, iostat=ios) num
Type Is (Real(Real128))
Read (s, *, iostat=ios) num
End Select
End Subroutine