- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have in my program a subroutine of the form...
I'd like to make the arguments 'image', 'callback' and 'c_object' to be optional. It's obvious enough how to do this with the parameter arguments, but where would I put the word 'optional' within the procedure interface? Is this even possible?
Stephen.
[bash] subroutine MapCentre(fitobj, centre_x, centre_y, sidelength, image, callback, c_object, error)
type(FitObject), intent(inout), target :: fitobj
integer, intent(in) :: centre_x, centre_y, sidelength
integer(4), intent(out), dimension(:,:), target :: image
type(c_ptr), intent(in) :: c_object
integer, optional, intent(out) :: error
interface
subroutine callback(c_object) bind(c) ! N.B. 'bind(c)' implies 'external'
use, intrinsic :: iso_c_binding
type(c_ptr), intent(in) :: c_object
end subroutine callback
end interface
...
end subroutine MapCentre[/bash]I'd like to make the arguments 'image', 'callback' and 'c_object' to be optional. It's obvious enough how to do this with the parameter arguments, but where would I put the word 'optional' within the procedure interface? Is this even possible?
Stephen.
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You do it with an abstract interface and PROCEDURE. Like this:
[fortran] abstract interface
subroutine callback_int(c_object) bind(c) ! N.B. 'bind(c)' implies 'external'
use, intrinsic :: iso_c_binding
type(c_ptr), intent(in) :: c_object
end subroutine callback_int
end interface
...
subroutine MapCentre(fitobj, centre_x, centre_y, sidelength, image, callback, c_object, error)
use, intrinsic :: iso_c_binding
type(FitObject), intent(inout), target :: fitobj
integer, intent(in) :: centre_x, centre_y, sidelength
integer(4), intent(out), dimension(:,:), target :: image
type(c_ptr), intent(in) :: c_object
integer, optional, intent(out) :: error
procedure(callback_int), optional :: callback
end subroutine MapCentre [/fortran]
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You do it with an abstract interface and PROCEDURE. Like this:
[fortran] abstract interface
subroutine callback_int(c_object) bind(c) ! N.B. 'bind(c)' implies 'external'
use, intrinsic :: iso_c_binding
type(c_ptr), intent(in) :: c_object
end subroutine callback_int
end interface
...
subroutine MapCentre(fitobj, centre_x, centre_y, sidelength, image, callback, c_object, error)
use, intrinsic :: iso_c_binding
type(FitObject), intent(inout), target :: fitobj
integer, intent(in) :: centre_x, centre_y, sidelength
integer(4), intent(out), dimension(:,:), target :: image
type(c_ptr), intent(in) :: c_object
integer, optional, intent(out) :: error
procedure(callback_int), optional :: callback
end subroutine MapCentre [/fortran]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Looks like just the ticket. Thank you 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