- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Pulling my hair out...hoping some can help.
I've created a dll in fortran which uses the EXP intrinsic function and am calling the dll in excel.The exp function is called from a large fortran program I wrote, so I created a test dll to demonstrate the problem:
! Dll1.f90
!
! FUNCTIONS/SUBROUTINES exported from Dll1.dll:
! Dll1 - function
!
Real(8) function TestExp(a)
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL::TestExp
!DEC$ ATTRIBUTES ALIAS:'TestExp' :: TestExp
!DEC$ ATTRIBUTES REFERENCE :: a
IMPLICIT NONE
Real(8), intent(in) :: a
TestExp = dexp(a)
end function TestExp
It is then called from Excel using the declare statment in a VB module:
Declare Function TestExp Lib "D:\Default User\My Documents\Visual Studio 2005\Projects\Excel\Dll1\Dll1\Release\Dll1.dll" (ByRef a As Double) As Double
Unfortunately, the dllbombs when trying to calculate the exp for no ryhme or reason that I can think. Interestingly, I can change the EXP(a) to a SQRT(a) and the function works properly. This is obviously extremely aggravating and I can't figure out why it will work with some intrinsic functions and not the exponential. Any help would be greatly appreciated.
Bryant
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Pulling my hair out...hoping some can help.
I've created a dll in fortran which uses the EXP intrinsic function and am calling the dll in excel.The exp function is called from a large fortran program I wrote, so I created a test dll to demonstrate the problem:
! Dll1.f90
!
! FUNCTIONS/SUBROUTINES exported from Dll1.dll:
! Dll1 - function
!
Real(8) function TestExp(a)
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL::TestExp
!DEC$ ATTRIBUTES ALIAS:'TestExp' :: TestExp
!DEC$ ATTRIBUTES REFERENCE :: a
IMPLICIT NONE
Real(8), intent(in) :: a
TestExp = dexp(a)
end function TestExp
It is then called from Excel using the declare statment in a VB module:
Declare Function TestExp Lib "D:Default UserMy DocumentsVisual Studio 2005ProjectsExcelDll1Dll1ReleaseDll1.dll" (ByRef a As Double) As Double
Unfortunately, the dllbombs when trying to calculate the exp for no ryhme or reason that I can think. Interestingly, I can change the EXP(a) to a SQRT(a) and the function works properly. This is obviously extremely aggravating and I can't figure out why it will work with some intrinsic functions and not the exponential. Any help would be greatly appreciated.
Bryant
Bryant,
Have you checked that that value of a is being passed correctly? If this is being corrupted by the interface, then I could imagine values where SQRT(a) is still valid, while EXP(a) would cause an overflow. On error, the DLL will attempt to write an error to the console, and this will cause Excel to fail.
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
afort func TextExp
-1.00E-10 -1E-10
-1.00E-09 -0.000000001
-1.00E-08 -0.00000001
-1.00E-07-0.0000001
-1.00E-06 -0.000001
-1.00E-05 -0.00001
-1.00E-04 -0.0001
-1.00E-03 -0.001
-1.00E-02 -0.01
-1.00E-01 -0.1
-1.00E+00 -1
-1.00E+01 -10
-1.00E+02 -100
Bryant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Bryant,
Have you checked that that value of a is being passed correctly? If this is being corrupted by the interface, then I could imagine values where SQRT(a) is still valid, while EXP(a) would cause an overflow. On error, the DLL will attempt to write an error to the console, and this will cause Excel to fail.
David
I assume these values are in your calling routine. What is important, is the values are inside the DLL. If the data types and convention for passing data across the interface are not correct, then the values inside the routine may be meaningless. Copying the values back to the calling routine as you have done will give meaningful values in the calling routine, but not in the DLL.
In the DLL add some code like
OPEN(1, FILE="C:Test.out", POSITION="APPEND")
WRITE(1,*) A
CLOSE(1)
Then look at the file after calling with the examples you gave. If the data is being corrupted across the interface, you will see it.
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
So is there any way to diagnose where the error might be? Are there certain settings that I should be checking/changing at when compiling the dll.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page