- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Is it possible to create a function with the same interface as the elemental intrinsic bessel_jn(n, x), where n is always a scalar and x may be an array? It looks like it is not possible. Why not?
In general that would be nice, but it introduces one serious limitation: elemental type-bound procedures. I would like to write something like
type :: Foo
contains
procedure :: func => Foo_func
end type
type, extends(Foo) :: Bar
real :: param
contains
procedure :: func => Bar_func
end type
elemental function Foo_func(self, x)
class(Foo) :: self
real :: x, Foo_func
Foo_func=x+1.d0
end function
elemental function Bar_func(self, x)
class(Bar) :: self
real :: x, Bar_func
Bar_func=x*self%param
end function
But this would not work, because I would need to provide an array of self's.
Did I misunderstood something? Why shouldn't this be allowed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You forgot to add the INTENT(IN) attribute to the arguments.
Apart from that, I don't think there's an issue. The arguments to an elemental function just need to be conformable. A scalar is conformable with an array.
(Similarly your description of the intrinsic bessel_jn isn't quite right - n doesn't always have to be scalar - it can be an array with the same shape as the other argument.)
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You forgot to add the INTENT(IN) attribute to the arguments.
Apart from that, I don't think there's an issue. The arguments to an elemental function just need to be conformable. A scalar is conformable with an array.
(Similarly your description of the intrinsic bessel_jn isn't quite right - n doesn't always have to be scalar - it can be an array with the same shape as the other argument.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Uhm, now I feel extremely stupid. Why didn't I test the code before posting here!!!??? I had some stupid preconceived idea and went for it.
It works like a charm :) Thank you!

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