|
我想写一个函数,共有三个参数:
[Fortran] 纯文本查看 复制代码 1 | function func ( a , b , c ) result ( output ) |
2 | real ( 8 ) , intent ( in ) :: a , b , c |
3 | real ( 8 ) , intent ( inout ) :: output |
如今我传了三个整数给a、b、c,程序报错:Type mismatch in argument passed INTEGER(4) to REAL(8)
实例如下:
[Fortran] 纯文本查看 复制代码 03 | real , allocatable :: array ( : ) |
05 | array = linspace ( 0 . , 1 . , 11 ) |
06 | print '(*(f3.1,/))' , array |
09 | function linspace ( arg 1 , arg 2 , N ) result ( output ) |
13 | real ( 8 ) , dimension ( N ) :: output |
20 | output ( i ) = arg 1 + ( i -1 ) * ( arg 2 - arg 1 ) / ( N -1 ) |
我看了我们网站的教程:为什么要在数学函数前面加D,加C加Q?如dsin - Fortran教程 - Fortran Coder 程序员聚集地 (fcode.cn)
了解到 Generic Procedure 可以实现统一接口的功能。
但如果 a、b、c 为单精度呢?为2字节的整型呢?...参数类型组合有十几种都不止。
难道要为每一中组合都写一个函数吗?
除了 Generic Procedure,有没有其它处理办法?比如在传递参数时进行类型转换。
|
|