Silverfrost Forums

Welcome to our forums

Using NAG DLLs and CHECKMATE

6 Nov 2008 2:55 #3975

When you compile your source code with an option that performs run-time checking there are subtle changes made to the way some routines are called. These changes allow run-time checking to be performed and are normally hidden from view. However, if you are trying to interface your code with DLLs produced with another compiler then you may need to give additional instructions.

For example if you want to pass a user defined function to NAG libraries compiled with Intel Visual Fortran you will need to define the function using F_STDCALL. In addition you should provide an interface in the calling routine.

The code below shows a modified example of passing a function ‘F’ to the NAG routine C05ADF:

*     C05ADF Example Program Text
*     Mark 14 Revised. NAG Copyright 1989.
*     .. Parameters ..
      INTEGER          NOUT
      PARAMETER        (NOUT=6)
*     .. Local Scalars ..
      DOUBLE PRECISION A, B, EPS, ETA, X
      INTEGER          IFAIL
*     .. External Functions ..
      DOUBLE PRECISION F
      INTERFACE
        F_STDCALL DOUBLE PRECISION FUNCTION F(X)
        DOUBLE PRECISION            X
        END FUNCTION F
      END INTERFACE
*     .. External Subroutines ..
      EXTERNAL         C05ADF
*     .. Executable Statements ..
      WRITE (NOUT,*) 'C05ADF Example Program Results'
      A = 0.0D0
      B = 1.0D0
      EPS = 1.0D-5
      ETA = 0.0D0
      IFAIL = 1
*
      CALL C05ADF(A,B,EPS,ETA,F,X,IFAIL)
*
      WRITE (NOUT,*)
      IF (IFAIL.EQ.0) THEN
         WRITE (NOUT,99999) 'Zero at X =', X
      ELSE
         WRITE (NOUT,99998) 'IFAIL =', IFAIL
         IF (IFAIL.EQ.2 .OR. IFAIL.EQ.3) WRITE (NOUT,99999)
     +       'Final point = ', X
      END IF
*
99999 FORMAT (1X,A,F12.5)
99998 FORMAT (1x,A,I3)
      END

      F_STDCALL DOUBLE PRECISION FUNCTION F(X)
      DOUBLE PRECISION            X
      INTRINSIC                   EXP
      F = EXP(-X) - X
      END

-- Admin Silverfrost Limited
This forum is locked.