- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi!
When i use array constructor following problem appears (example). I wrote some comments there.
! file f1.f90
PROGRAM Main
USE MyModule
IMPLICIT NONE
REAL,DIMENSION(0:3):: x
CALL TestFN(myFN,x)
END PROGRAM Main
! file f2.f90
MODULE MyModule
IMPLICIT NONE
CONTAINS
SUBROUTINE TestFN(myFN,x)
REAL,EXTERNAL :: myFN
REAL,DIMENSION(0:),INTENT(OUT) :: x
INTEGER i
x=[(myFN(i),i=0,UBOUND(x,DIM=1))]
END SUBROUTINE TestFN
REAL FUNCTION myFN(x,param)
REAL,INTENT(IN) :: x
REAL,INTENT(IN),OPTIONAL :: param
PRINT*,PRESENT(param)
!here is a trouble
!actually "param" is not PRESENT
!but on the first step
!it is .TRUE.
!after printing this function there is
!TFFF, but must be FFFF
myFN=x
END FUNCTION myFN
END MODULE MyModule
Is it a bug of array constructor? (Version 9.1.3291)
When i use array constructor following problem appears (example). I wrote some comments there.
! file f1.f90
PROGRAM Main
USE MyModule
IMPLICIT NONE
REAL,DIMENSION(0:3):: x
CALL TestFN(myFN,x)
END PROGRAM Main
! file f2.f90
MODULE MyModule
IMPLICIT NONE
CONTAINS
SUBROUTINE TestFN(myFN,x)
REAL,EXTERNAL :: myFN
REAL,DIMENSION(0:),INTENT(OUT) :: x
INTEGER i
x=[(myFN(i),i=0,UBOUND(x,DIM=1))]
END SUBROUTINE TestFN
REAL FUNCTION myFN(x,param)
REAL,INTENT(IN) :: x
REAL,INTENT(IN),OPTIONAL :: param
PRINT*,PRESENT(param)
!here is a trouble
!actually "param" is not PRESENT
!but on the first step
!it is .TRUE.
!after printing this function there is
!TFFF, but must be FFFF
myFN=x
END FUNCTION myFN
END MODULE MyModule
Is it a bug of array constructor? (Version 9.1.3291)
Link Copied
7 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
No, it's your bug, but very understandable. In TestFN, when you declared the passed argument myFN as EXTERNAL, that means it has an implicit interface. But the routine you're actually calling, the module procedure myFN, requires an explicit interface because it has an OPTIONAL argument.
The solution is to replace:
REAL,EXTERNAL :: myFN
with:
The solution is to replace:
REAL,EXTERNAL :: myFN
with:
INTERFACE
REAL FUNCTION myFN(x,param)
REAL,INTENT(IN) :: x
REAL,INTENT(IN),OPTIONAL :: param
END FUNCTION myFN
END INTERFACE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
BIG thanks for solution of my problem! :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
And how can i make "assumed-shape" interface?
I mean calling external functions with different interfaces.
For example:
SUBROUTINE TestFN(FN,x)
...
x=[(FN(i),i=0,UBOUND(x,DIM=1))]
...
END SUBROUTINE TestFN
REAL FUNCTION myFN(x,param)
INTEGER,INTENT(IN) :: x
REAL,INTENT(IN),OPTIONAL :: param
...
END FUNCTION myFN
REAL FUNCTION myFN1(x)
INTEGER,INTENT(IN) :: x
...
END FUNCTION myFN
And i want to call TestFN with functions myFN,myFN1 as arguments.
Is there any other way, except making "pseudo" argument "param" in myFN1?
I mean calling external functions with different interfaces.
For example:
SUBROUTINE TestFN(FN,x)
...
x=[(FN(i),i=0,UBOUND(x,DIM=1))]
...
END SUBROUTINE TestFN
REAL FUNCTION myFN(x,param)
INTEGER,INTENT(IN) :: x
REAL,INTENT(IN),OPTIONAL :: param
...
END FUNCTION myFN
REAL FUNCTION myFN1(x)
INTEGER,INTENT(IN) :: x
...
END FUNCTION myFN
And i want to call TestFN with functions myFN,myFN1 as arguments.
Is there any other way, except making "pseudo" argument "param" in myFN1?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The only way I can think of to do this sort of thing is to have a set of intermediate "call it" routines, one for each signature. When you pass the routine to the first routine, it declares it as EXTERNAL and then calls an appropriate second routine, passing the argument along. Each second routine declares the argument with the correct interface and then calls.
This is all very complicated and error-prone. What exactly are you trying to accomplish here? Perhaps there's a better way.
This is all very complicated and error-prone. What exactly are you trying to accomplish here? Perhaps there's a better way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
heh... really complicated...
I would like to make a subroutine SOLVE(outfuncition,equation,startmeanings,method)
where "method" is external subroutine. Every method has it's own interface but with one common argument "x", other arguments differ from each other. Think to make other arguments except "x" OPTIONAL and make one interface for all methods (in which i will declare unused optional arguments). The task of making such subroutine is because i solve only small part of big calculation problem. =
I would like to make a subroutine SOLVE(outfuncition,equation,startmeanings,method)
where "method" is external subroutine. Every method has it's own interface but with one common argument "x", other arguments differ from each other. Think to make other arguments except "x" OPTIONAL and make one interface for all methods (in which i will declare unused optional arguments). The task of making such subroutine is because i solve only small part of big calculation problem. =
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I suggest not using OPTIONAL or anything that would require an explicit interface. Use some other method to determine whether or not arguments are present.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I will try to think out something. Thanks for consultation, Steve! :)

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