Software Archive
Read-only legacy content
17061 Discussions

Sharing Data between Fortran programs

Tote_Licences
Beginner
429 Views
Hi there,
I have been unsuccessfully trying to use the MODULEstatement and a DLL to allow sharing of data.

First I set up a dll contining this code :-

module Global_Commons

implicit none

INTEGER*4 FIRST, LAST

COMMON /TSKCOM/ FIRST

COMMON /TSKCOM/ LAST

VOLATILE :: /TSKCOM/

end module Global_Commons

I use one program to set values in the new TSKCOM

program Console1

use Global_Commons

implicit none

CHARACTER*4 RESPONDER

FIRST=1

LAST=2

Write (*,100) FIRST, LAST

100 FORMAT (" Written to common FIRST=",I5," LAST=",I5)

read (*,200) RESPONDER

200 FORMAT (A)

end program Console1

and another to read the new TSKCOM

program Console2

use Global_Commons

implicit none

CHARACTER*4 RESPONDER

Write (*,100) FIRST, LAST

100 FORMAT (" In common FIRST=",I5," LAST=",I5)

read (*,200) RESPONDER

200 FORMAT (A)

END

The second program displays both values as zero.

Could you possibly explain what I have done wrong?
0 Kudos
1 Reply
prandf
Beginner
429 Views
hi

This works but I am having problems with connecting a C program to the shared memory module.
I suspect it is something to do withthe build options.
I have a C version of the datastructure Global_Commons.

module Global_Commons

implicit none

INTEGER*4 :: FIRST = 678

INTEGER*4 :: LAST

COMMON /TSKCOM/ FIRST

COMMON /TSKCOM/ LAST

VOLATILE :: /TSKCOM/

!DEC$ ATTRIBUTES DLLEXPORT :: /TSKCOM/

end module Global_Commons



program Console1

use Global_Commons

implicit none

CHARACTER*4 RESPONDER

FIRST=1

LAST=2

Write (*, "('First and Last begin as : ',I5,I5)") FIRST, LAST

RESPONDER = '0000'

do while (RESPONDER .ne. '9999')

write(*,"('press return to continue - 9999 to finish')")

read (*,"(A)") RESPONDER

write (*,"('Now First and Last are = ',I5,I5)") FIRST, LAST

write (*,"('enter new value for FIRST ')")

read (*,"(I8)") FIRST

write (*,"('enter new value for LAST ')")

read (*,"(I8)") LAST

write (*,"('Now First and Last are = ',I5,I5)") FIRST, LAST

enddo

end program Console1

program Console2

use Global_Commons

implicit none

CHARACTER*4 RESPONDER

Write (*,"('First and Last begin as : ',I5,I5)") FIRST, LAST

RESPONDER = '0000'

do while (RESPONDER .ne. '9999')

write(*,"('press return to continue - 9999 to finish')")

read (*,"(A)") RESPONDER

write (*,"('Now First and Last are = ',I5,I5)") FIRST, LAST

write (*,"('enter new value for FIRST ')")

read (*,"(I8)") FIRST

write (*,"('enter new value for LAST ')")

read (*,"(I8)") LAST

write (*,"('Now First and Last are = ',I5,I5)") FIRST, LAST

enddo

END

the build file looks like this

rem build Global_Commons

ifort /nologo /dll Global_Commons.f90 /link /section:.data,RWS

rem build Console1

ifort /nologo /libs:dll Console1.f90 Global_Commons.lib

rem build Console2

ifort /nologo /libs:dll Console2.f90 Global_Commons.lib

rem "all done"


Any ideas on getting the C routine to share the Fortran shared global module?

regards

Peter.

0 Kudos
Reply