Silverfrost Forums

Welcome to our forums

Parameters of subroutines

29 Jan 2008 6:36 #2714

Hi, if a call the NAG-subroutine D01AJF directly from the main program it works well. But an 'Access Violation' is accured if D01AJF called from Qd-sig. The problem is to give the name of the function 'Fst' via Qd-sig to D01AJF.

 PROGRAM MAINEW             
	  IMPLICIT NONE
! --- Input / Output ---
	  Real*8      Fst, a, b ,RESU      ! I: Integrand & Grenzen
! --- Locals of D01AJF ---
	  Real*8      EPSAB, EPSRE           ! Abs.&Rel. Genauigk.: sig
	  Parameter   ( EPSAB = 0.D0, EPSRE = 1.D-4 )
 	  Integer     LW, LIW, IFAIL
	  Parameter   ( LW = 800, LIW = LW/4 )
	  Real*8      W(LW), ABSE
      Integer     IW(LIW)
! --- External ---
	  External    Fst, D01AJF, Qd_sig                     ! Integrand 
! --- Settings ---
	  IFAIL = 1
      a = 0.D0
      b = 2 * 3.14D0
! --- Integration ---
	  Call D01AJF(Fst, a, b, EPSAB, EPSRE, RESU, ABSE, W, LW, IW, LIW, IFAIL)
      PRINT*,'D01AJF-RESU =',RESU
	  Call Qd_sig(Fst, a, b, EPSAB, EPSRE, RESU)
      PRINT*,'Qd_sig-RESU =',RESU

      END


Subroutine Qd_sig (Fkt, a, b, EPSAB, EPSRE, RESU)             

	  IMPLICIT NONE
	  Real*8       Fkt, a, b        ! I: Integrand & Grenzen
	  Real*8       EPSAB, EPSRE     ! I: Abs.& Rel. Genauigk.
	  Real*8       RESU             ! O: Integrations Resultat
! --- Locals of D01AJF ---
	  Integer     LW, LIW, IFAIL
	  Parameter   ( LW = 800, LIW = LW/4 ) !Zu Testzwecken
	  Real*8      W(LW), Fkt, ABSE 
      Integer     IW(LIW)
! --- External ---
	  External    Fkt, D01AJF                     ! Integrand 
! --- Settings ---
	  IFAIL = 1
	  Call D01AJF(Fkt, a, b, EPSAB, EPSRE, RESU, ABSE, W, LW, IW, LIW, IFAIL)
 
      Return
	  END 

How can I solve my problem? Thanks in advance for any idea.

regards Martin

29 Jan 2008 7:03 #2716

The NAG routines will use STDCALL.

Most users use /import_lib on the FTN95 command line and link together using the NAG DLL.

You will need to do something like this for the main program and any libraries that call the NAG routines.

In a Plato project you can use the Properties of a DLL Reference for this purpose.

31 Jan 2008 6:30 #2722

Hello Paul,

I tried all your suggestions and also your sugesstions from my posted 'Problem of two libraries'. I have examinate Qd-sig from my Fortran library to focus the problem. The main problem is to give a name of a function (Fst) via a subroutine (Qd_sig) to the NAG-subroutine. If I examinate Fst from the parameter list in Qd-sig and give the name dircet to the NAG-subroutine, then it works.

I use /import_lib for any compilation.

Thanks in advance or any idea

regards Martin

1 Feb 2008 8:25 #2723

If you are passing an FTN95 subroutine to a NAG library routine then I would expect that it should be declared as F_STDCALL in your code. I have never tried to do this but logically it is what one would expect.

It would look like this in your code...

F_STDCALL SUBROUTINE foo(x) REAL x ...

Please login to reply.