- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I hope you would not mind my ignorance. I am having a hard time trying to figure out how I can pass an allocatable array from a subroutine to a FORTRAN DLL, or if I am doing anything wrong. The source below does work and the values inside the allocateable array is passed to FORTRAN DLL, but it may seem that it may be overwriting something else? Below is the sample code which we are using currently:
SUBROUTINE CL1(J1) REAL*4, ALLOCATABLE :: FFF(:,:) ! HERE I READ A LOGICAL FILE AFTER WHICH I KNOW THE SIZE OF MY ARRAY (ND AND NTSTEPS) IF(.NOT.ALLOCATED(FFF)) THEN IATTEMPT1 = 1 ALLOCATE (FFF(ND,NTSTEPS), STAT= IALLOC1) END IF ! Here I will call the DLL file and pass on the allocatable array and the size as arguments CALL NUKE(FFF,ND,NTSTEPS) IF(ALLOCATED(FFF)) THEN DEALLOCATE(FFF, STAT= IDEALL1) END IF RETURN END SUBROUTINE NUKE(FFF,NX,NS) !Expose subroutine NUKE to users of this DLL !DEC$ ATTRIBUTES DLLEXPORT::NUKE DIMENSION FFF(NX,NT) ! DO SOME MORE CALCULATION AND PASS THIS ARRAY TO OTHER SUBROUTINES RETURN END
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As long as you do not treat FFF as an allocatable argument in NUKE or other subroutines called from NUKE, things should work fine. What you cannot do in the DLL is to evaluate ALLOCATED(FFF), attempt to deallocate, reallocate or obtain the size of FFF.
What makes you suspect that "it may seem that it may be overwriting something else"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mecej,
Thank you for your response. I am not sure, but it seems that the program does not return correct values after initial iteration is performed (iteration means that the allocateable array is passed to the DLL and back).
This may be due to some other reason like not being able to access logical file on subsequent iterations etc, but I think I will have to debug through the source to reach a conclusion.
Can you please also suggest a better approach on how allocatable arrays can be passed to DLLs?
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is nothing special about allocatable arrays here. You will need to debug the program to find out what is going wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
You are right, the allocatable array is working correctly. There was another issue in my source which was causing this issue.
Thank you Steve and Mecej for your help.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page