PDA

View Full Version : [LF] Help! Creating & using DLL


Lahey Support
08-15-2003, 01:19 AM
Dear All:

Is there any one know how to complie a DLL written by FORTRAN90

and then call it with another FORTRAN90 code? I've wrote a code

as follwing, I can get *.dll and *.exe, but when excuting, the

Win95 replied me 'Not enough ram!' That's strange, 'cause when

I complied it by usual way, not complied it to DLL, it worked

fine... What's wrong?


Thanks.

Cosine
Jan/23/1999 UT


ls.f90 contains the following:

! Last change: C 23 Jan 1999 6:26 pm
!----------------------------------------------------
function Simple_Gauss(Grid) RESULT(Solu)
implicit none
dll_export Simple_Gauss
REAL(8) :: Grid(:,:)
REAL(8) :: Solu( SIZE(Grid,1) )
REAL(8) :: G( SIZE(Grid,1), SIZE(Grid,2) ), G_pivot

INTEGER :: N, L, i, j


if ( SIZE(Grid,2) /= SIZE(Grid,1)+1 ) then
WRITE(*,*) ' Bad Grid shape!'
WRITE(*,*)
STOP
endif

N = SIZE(Grid,1)
G = Grid

do L = 1,N,1
if ( ABS(G(L,L)) < 1.e-4 ) then
WRITE(*,*) ' Zero encountered in pivot!'
WRITE(*,*)
STOP
end if

G_pivot = G(L,L)

do j = 1,( N+1 ),1
G(L,j) = G(L,j)/G_pivot
end do ! j loop

do i = 1,N,1
do j = 1,( N+1 ),1
if ( i /= L .and. j /= L ) then
G(i,j) = G(i,j)-G(i,L)*G(L,j)
end if
end do ! j loop
end do ! i loop
end do ! L loop

do i = 1,N,1
Solu(i) = G( i,N+1 )
end do ! i loop


return
end function Simple_Gauss


!----------------------------------------------------
function Pivot_Gauss(Grid) RESULT(Solu)
implicit none
dll_export Pivot_Gauss
REAL(8) :: Grid(:,:)
REAL(8) :: Solu( SIZE(Grid,1) )
REAL(8) :: G( SIZE(Grid,1), SIZE(Grid,2) ), G_pivot
INTEGER :: P( SIZE(Grid,1),2 )

INTEGER :: N, L, i, j, k


if ( SIZE(Grid,2) /= SIZE(Grid,1)+1 ) then
WRITE(*,*) ' Bad Grid shape!'
WRITE(*,*)
STOP
endif

N = SIZE(Grid,1)
G = Grid

do L = 1,N,1
G_pivot = -1

do i = 1,N,1
Inner_pivot_search: &
do j = 1,N,1
do k = 1,( L-1 ),1
if ( i == P(k,1) .or. j == P(k,2) ) cycle Inner_pivot_search
end do ! k loop

if ( ABS(G(i,j)) > G_pivot ) then
G_pivot = ABS(G(i,j))
P(L,1) = i
P(L,2) = j
end if

end do Inner_pivot_search ! j loop
end do ! i loop

if ( ABS( G( P(L,1),P(L,2) ) ) < 1.e-4 ) then
WRITE(*,*) ' Ill conditioned matrix!'
WRITE(*,*)
STOP
end if

G_pivot = G( P(L,1),P(L,2) )

do j = 1,( N+1 ),1
G( P(L,1),j ) = G( P(L,1),j )/G_pivot
end do ! j loop

do i = 1,N,1
do j = 1,( N+1 ),1
if ( i /= P(L,1) .and. j /= P(L,2) ) then
G(i,j) = G(i,j)-G( i,P(L,2) )*G( P(L,1),j )
end if
end do ! j loop
end do ! i loop
end do ! L loop

do i = 1,N,1
Solu(P(i,2)) = G( P(i,1),N+1 )
end do ! i loop


return
end function Pivot_Gauss

Then I use this to get ls.dll etc.
lf90 ls -win -ml lf90 -dll

After that, I use
lf90 a -win -ml lf90 -dll ls.imp
to get a.exe

a.f90 contains the following:

! Last change: C 23 Jan 1999 6:27 pm
program tarray
implicit none
dll_import Simple_Gauss
dll_import Pivot_Gauss
REAL(8) :: Simple_Gauss, Pivot_Gauss
REAL(8) :: a(2,3), solu(2)


a(1,1) = 1.
a(2,1) = 2.
a(1,2) = 3.
a(2,2) = 4.
a(1,3) = 5.
a(2,3) = 6.


solu = Simple_Gauss(a)
WRITE(*,*) '----------------------'
WRITE(*,*) ' By Simple_Gauss: '
WRITE(*,*) solu

solu = Pivot_gauss(a)
WRITE(*,*) '----------------------'
WRITE(*,*) ' By Pivot_Gauss: '
WRITE(*,*) solu


stop
end program tarray

__________________________________________________ ____
Get Your Private, Free Email at http://www.hotmail.com