سؤال

How should I call a Fortran function?

I am trying to call DLANSY but it erroneously returns 0. See the code and the program output below.

      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

And what it prints:

           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   

In the input arrays are of proper size.

What is going on?

هل كانت مفيدة؟

المحلول

You need to tell the compiler that DLANSY returns a double precision value, rather than real, which is what you get currently via the implicit typing rules. E.g. with a line like

double precision, external :: dlansy

Or, if for some strange reason one is limited to some ancient compiler that does not support F90:

DOUBLE PRECISION DLANSY
EXTERNAL DLANSY
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top