Fortran类(*)

时间:2014-12-12 15:39:52

标签: fortran polymorphism

编写了将字符转换为整数

的例程
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

0 个答案:

没有答案