0

我应该如何调用 Fortran 函数?

我正在尝试调用DLANSY,但它错误地返回 0。请参阅下面的代码和程序输出。

      SUBROUTINE COND(TYP,N,A,LDA,IPIV,WORK,LWORK,IWORK,INFO,RCOND)

      INTEGER TYP, N, LDA, IPIV(*), IWORK(*), INFO, LWORK
      DOUBLE PRECISION A(LDA,*), ANORM, RCOND, WORK(*)
      CHARACTER*1 UPLO
      EXTERNAL DLANSY, DSYTRF, DSYCON

      IF (TYP .EQ. 0) THEN 
        UPLO = 'L'
      ELSE
        UPLO = 'U'
      ENDIF

      DO I = 1, N
        DO J = 1,N 
          WRITE(*,*) I,J,A(I,J)
        END DO
      END DO

      WRITE(*,*) 'TYPE ',UPLO
      WRITE(*,*) 'N    ',N
      WRITE(*,*) 'LDA  ',LDA

      ANORM = DLANSY('1', UPLO, N, A, LDA, WORK)
C      ANORM = 10;

      WRITE(*,*) 'ANORM  ',ANORM

      END

它打印的内容:

           1           1   1.0000000000000000     
           1           2   2.0000000000000000     
           1           3   3.0000000000000000     
           1           4   4.0000000000000000     
           2           1   1.0000000000000000     
           2           2   2.0000000000000000     
           2           3   3.0000000000000000     
           2           4   4.0000000000000000     
           3           1   1.0000000000000000     
           3           2   2.0000000000000000     
           3           3   3.0000000000000000     
           3           4   4.0000000000000000     
           4           1   1.0000000000000000     
           4           2   2.0000000000000000     
           4           3   3.0000000000000000     
           4           4   4.0000000000000000     
 TYPE L
 N               4
 LDA             4
 ANORM     0.0000000000000000   

在输入数组中具有适当的大小。

到底是怎么回事?

4

1 回答 1

4

您需要告诉编译器 DLANSY 返回一个双精度值,而不是真实值,这是您当前通过隐式类型规则获得的值。例如,像这样的线

double precision, external :: dlansy

或者,如果出于某种奇怪的原因,仅限于某些不支持 F90 的古老编译器:

DOUBLE PRECISION DLANSY
EXTERNAL DLANSY
于 2012-01-11T13:58:37.857 回答