How to pas an overloaded subroutine as an argument to another subroutine - Fortran

This is a discussion on How to pas an overloaded subroutine as an argument to another subroutine - Fortran ; Hi! I'd like to pass an overloaded procedure as an argumet to the other procedure, but compiler doesn't let me do it. How can i do something like the following: File1: module some_module_ml public :: a interface a module procedure ...

+ Reply to Thread
Results 1 to 2 of 2

How to pas an overloaded subroutine as an argument to another subroutine

  1. Default How to pas an overloaded subroutine as an argument to another subroutine

    Hi!

    I'd like to pass an overloaded procedure as an argumet to the other
    procedure, but compiler doesn't let me do it.

    How can i do something like the following:

    File1:

    module some_module_ml

    public :: a

    interface a
    module procedure a_int, a_real
    end interface a
    contains
    subroutine a_int(i)
    integer, intent(in) :: i
    ...
    end subroutine a_int
    subroutine a_real(x)
    real, intent(in) :: x
    ....
    end subroutine a_real
    end module some_module_ml

    File2:
    program some_program
    use some_module_ml, only : a

    cal some_other_subroutine(a)

    contains
    subroutine some_other_subroutine(a)
    interface
    subroutine a(i)
    integer, intent(in) :: i
    end subroutine a
    end interface
    ....
    end subroutine some_other_subroutine

    Thanks!


  2. Default Re: How to pas an overloaded subroutine as an argument to another subroutine

    On Aug 20, 4:48 pm, Luksa <klu...> wrote:
    > Hi!
    >
    > I'd like to pass an overloaded procedure as an argumet to the other
    > procedure, but compiler doesn't let me do it.
    >
    > How can i do something like the following:
    >
    > File1:
    >
    > module some_module_ml
    >
    > public :: a
    >
    > interface a
    > module procedure a_int, a_real
    > end interface a
    > contains
    > subroutine a_int(i)
    > integer, intent(in) :: i
    > ...
    > end subroutine a_int
    > subroutine a_real(x)
    > real, intent(in) :: x
    > ...
    > end subroutine a_real
    > end module some_module_ml
    >
    > File2:
    > program some_program
    > use some_module_ml, only : a
    >
    > cal some_other_subroutine(a)
    >
    > contains
    > subroutine some_other_subroutine(a)
    > interface
    > subroutine a(i)
    > integer, intent(in) :: i
    > end subroutine a
    > end interface
    > ...
    > end subroutine some_other_subroutine
    >
    > Thanks!


    Hi!
    I think you will not be able to send overloaded procedure as
    argument.
    Better send the pointer on each procedure. For instance so:

    MODULE some_module_ml

    CONTAINS
    SUBROUTINE a_int(i)
    INTEGER, INTENT(in) :: i
    write(*,*) " a int", i
    ! ...
    END SUBROUTINE a_int
    SUBROUTINE a_real(x)
    REAL, INTENT(in) :: x
    write(*,*) " a REAL", x
    !...
    END SUBROUTINE a_real
    END MODULE some_module_ml

    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    PROGRAM some_program
    USE some_module_ml
    INTEGER PointerToa_int
    INTEGER PointerToa_real
    PointerToa_int = LOC(a_int)
    PointerToa_real = LOC(a_real)
    !...............................
    CALL some_other_subroutine(PointerToa_int)
    !..................................
    CALL some_other_subroutine(PointerToa_real)
    CONTAINS
    SUBROUTINE some_other_subroutine(Pa)
    INTEGER Pa
    IF(Pa == PointerToa_int) THEN
    i = 1
    CALL a_int(i)
    ELSE IF(Pa == PointerToa_real) THEN
    x =2
    CALL a_real(x)
    END IF
    !...
    END SUBROUTINE some_other_subroutine
    END

    Possible also variants with use Cray pointers
    http://gcc.gnu.org/onlinedocs/gfortr...#Cray-pointers


+ Reply to Thread

Similar Threads

  1. Calling C Subroutine
    By Application Development in forum REXX
    Replies: 2
    Last Post: 12-02-2007, 10:16 AM
  2. Calling f90 subroutine from IDL
    By Application Development in forum Idl-pvwave
    Replies: 0
    Last Post: 11-14-2007, 10:41 AM
  3. Replies: 9
    Last Post: 10-29-2007, 01:39 PM
  4. LEN of subroutine variables
    By Application Development in forum Fortran
    Replies: 6
    Last Post: 08-20-2007, 04:19 PM
  5. F77 postscript subroutine
    By Application Development in forum Fortran
    Replies: 0
    Last Post: 06-17-2007, 12:29 PM