Calling dll from Intel Fortran.

Calling dll from Intel Fortran.

I am new to Intel fortran. I have dll created by FORTRAN power station. Unfortunately, i don't have the source code for the dll. But i need to call the function through intel fortran. How to call the dll? any sample source code?

8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I don't know how much this may help but assuming you have the Composer XE 2013 SP1 product installed, there is a DLL sample provided with the product located under the default installation path:

C:\Program Files (x86)\Intel\Composer XE 2013 SP1\Samples\en_US\Fortran\DLL.zip

Lorri Menard (Intel)'s picture

That is an interesting problem.   Microsoft Powerstation Fortran was obsoleted in the 1990's.   It was last supported using VS98 and was always IA32 only.  Hopefully there aren't any C library issues.

You will need to use the IA32 version of the Intel Fortran compiler.

Your calls to the routines in the DLL will need to have the CVF attribute specified with
!DEC$ ATTRIBUTES CVF :: external-routine-name

Do you know the declarations of the routines that you are trying to call?   There may be other attributes to be set for compatibility.

Finally, do you have the export library for this dll?  It probably has the same name as the .dll file, but with the .lib extension.

                     --Lorri

Kevin,

I went through the dll sample. but did not help much.

Thanks

 

 

 

 

Lorri,

Yes. I do have export library file (.lib). Even though, i don't have the source code, i have module file which call the subroutine. Here is the code.

Thanks.

Rasa

	MODULE IRD_DLL

	 INTERFACE 


	  LOGICAL FUNCTION IRD_SET(INPUTU,ERRU,INFILE,ERRFILE,GCMNT,IERR)
	   !MS$ATTRIBUTES DLLIMPORT::IRD_SET
	   INTEGER INPUTU,ERRU,IERR
	   CHARACTER*(*) INFILE,ERRFILE
	   CHARACTER*(*), OPTIONAL:: GCMNT
	  END FUNCTION IRD_SET

	  LOGICAL FUNCTION IRD_GETDATALINE(NO_CMNT)
	   !MS$ATTRIBUTES DLLIMPORT::IRD_GETDATALINE
	   INTEGER, OPTIONAL::NO_CMNT
	  END FUNCTION IRD_GETDATALINE

	  INTEGER FUNCTION IRD_DTACOL()
	   !MS$ATTRIBUTES DLLEXPORT::IRD_DTACOL
	  END FUNCTION IRD_DTACOL

	  LOGICAL FUNCTION IRD_INTREAD(INTVAL,ERR_CMNT,MINVAL,MAXVAL)
	   !MS$ATTRIBUTES DLLIMPORT::IRD_INTREAD
	   INTEGER INTVAL
	   CHARACTER*(*), OPTIONAL:: ERR_CMNT
	   INTEGER, OPTIONAL:: MINVAL,MAXVAL
	  END FUNCTION IRD_INTREAD

	  LOGICAL FUNCTION IRD_DFREAD(DVAL,ERR_CMNT,MINVAL,MNEQ,
	1                              MAXVAL,MXEQ)
	   !MS$ATTRIBUTES DLLIMPORT::IRD_DFREAD
	   DOUBLE PRECISION DVAL
	   CHARACTER*(*), OPTIONAL:: ERR_CMNT
	   DOUBLE PRECISION, OPTIONAL:: MINVAL,MAXVAL
	   LOGICAL, OPTIONAL:: MNEQ,MXEQ
	  END FUNCTION IRD_DFREAD

	  LOGICAL FUNCTION IRD_STRREAD(STR,ERR_CMNT)
	   !MS$ATTRIBUTES DLLIMPORT::IRD_STRREAD
	   CHARACTER*(*) STR
	   CHARACTER*(*), OPTIONAL:: ERR_CMNT
	  END FUNCTION IRD_STRREAD

	  LOGICAL FUNCTION IRD_GETSTR(STR)
	   !MS$ATTRIBUTES DLLIMPORT::IRD_GETSTR
	   CHARACTER*(*) STR
	  END FUNCTION IRD_GETSTR

	  LOGICAL FUNCTION IRD_CHKEXTRA(NO_ERR)
	   !MS$ATTRIBUTES DLLIMPORT::IRD_CHKEXTRA
	   INTEGER, OPTIONAL::NO_ERR
	  END FUNCTION IRD_CHKEXTRA

	  LOGICAL FUNCTION IRD_CHECKFILE(FNAME,IMODE)
	   !MS$ATTRIBUTES DLLIMPORT::IRD_CHECKFILE
	   CHARACTER*(*) FNAME
	   INTEGER IMODE			!- [1] READ [2] WRITE
	  END FUNCTION IRD_CHECKFILE

	  INTEGER FUNCTION IRD_GETFILESIZE(MINLINES)
	   !MS$ATTRIBUTES DLLIMPORT::IRD_GETFILESIZE
	   INTEGER MINLINES
	  END FUNCTION IRD_GETFILESIZE

	  SUBROUTINE IRD_CLOSE
	   !MS$ATTRIBUTES DLLIMPORT::IRD_CLOSE
	  END SUBROUTINE IRD_CLOSE

	 END INTERFACE

	END MODULE IRD_DLL

 

 

mecej4's picture

Rasa: I cannot give direct advice since I do not know  about the old DLL that you wish to use (not even its name has been disclosed yet!), but here is a simple example that may help. Using FPS4 on the file FDLL.F90, which contains

!  FortDLL.f90
!
subroutine ARRAYTEST(arr)

  ! Expose subroutine FortDLL to users of this DLL
  !
    REAL(4) arr(3, 7)
    INTEGER i, j
    PRINT *, "Fortran DLL is called ... "
    DO i = 1, 3
        DO j = 1, 7
            arr (i, j) = 11.0 * i + j
            PRINT *, "arr(i,j) = ", arr(i,j)
        END DO
    END DO
  ! Variables
   PRINT *, "END of Fortran DLL ..."
 ! Body of FortDLL

end subroutine ARRAYTEST

I built the DLL using the command (output also shown)

s:\lang>fl32 /LD fdll.f90 /link /export:_ARRAYTEST@4
Microsoft (R) Fortran PowerStation  Version 4.00
Copyright (C) Microsoft Corp 1982-1995. All rights reserved.

fdll.f90
Microsoft (R) 32-Bit Incremental Linker Version 3.00.5270
Copyright (C) Microsoft Corp 1992-1995. All rights reserved.

   Creating library fdll.lib and object fdll.exp

I then switched to Intel Fortran, and build an application that uses this DLL. The source file, testdll.f90, contains

    program FortTest

    implicit none
!DEC$ ATTRIBUTES CVF :: ARRAYTEST
    REAL(4) rarray (3,7)
    CALL ARRAYTEST(rarray)
    ! Variables

    ! Body of FortTest
    print *, 'Hello World'

    end program FortTest

The command line (and output from the build):

S:\lang>ifort testdll.f90 fdll.lib
Intel(R) Visual Fortran Compiler XE for applications running on IA-32, Version 15.0.0.030 Beta Build 20140318
Copyright (C) 1985-2014 Intel Corporation.  All rights reserved.

ifort: NOTE: The Beta evaluation period for this product ends on 25-sep-2014 UTC.
Microsoft (R) Incremental Linker Version 11.00.61030.0
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:testdll.exe
-subsystem:console
-incremental:no
testdll.obj
fdll.lib

One thing that you can try is to compile the module file for which you listed the source code, using the Intel compiler with the option /iface:CVF. Then, using the newly compiled .MOD file, compile your application and link with the import library for the DLL. For this approach to work, your application must contain "USE IRD_DLL" in every subprogram that calls one or more of the DLL routines.

 Lorri,

You are right. I forgot to change the attributes (!MS Attribute) in the module and main code. I changed it. It works.

Thanks for the help.

Rasa

 

 

 

Mecej4,

Thanks for detailed explanation. I changed the attribute to CVF. It is working.

Rasa

 

Login to leave a comment.