From: helvio on
Hi,

Within the same module, how do you rename module procedures that are
called by other module procedures? It sounds confusing... I'll explain
better. When I call a module from an external procedure, I know I can
rename the internal procedures contained in that module in the
following way:


module mod
private
public :: func
contains
real function func()
! some executable statements...
end function func
end module

program prog
real :: x
call subr(x)
stop
end program prog

subroutine subr(x)
use mod, only : newname => func
real, intent(out) :: x
x = newname()
return
end subroutine subr


But if the subroutine is also a module procedure of the same module, I
don't know how to rename it:


module mod
private
public :: func, subr
contains
real function func()
! some executable statements...
end function func
subroutine subr(x)
real, intent(out) :: x
x = func() ! <-- but i'd like 'func' to have a
different name inside 'subr'
return
end subroutine subr
end module

program prog
use mod, only : subr
real :: x
call subr(x)
stop
end program prog


Is it possible to rename 'func' inside 'subr'? Or does the fact that
'func' and 'subr' have the same scope somehow forbids that? I also
tried to create a generic interface for 'func' inside 'subr', but it
didn't work, or I did it wrong...

Cheers,

-- helvio
From: dpb on
helvio wrote:
....
> But if the subroutine is also a module procedure of the same module, I
> don't know how to rename it:
....
> module mod
> private
> public :: func, subr
> contains
> real function func()
> ! some executable statements...
> end function func
> subroutine subr(x)
> real, intent(out) :: x
> x = func() ! <-- but i'd like 'func' to have a
> different name inside 'subr'
> return
> end subroutine subr
> end module
....
> Is it possible to rename 'func' inside 'subr'?

....

Don't see how; the only facility for doing that is via USE which would
require func() be in a module of its own in order to be USEd.

As for the generic question, post what your test code was...

--
From: helvio on
On Sep 30, 3:26 pm, dpb <n...(a)non.net> wrote:

> Don't see how; the only facility for doing that is via USE which would
> require func() be in a module of its own in order to be USEd.

:( Too bad! That would be useful, if it was possible.

> As for the generic question, post what your test code was...

Do you mean my try at using a generic interface? (I think that's how
they're called) :/
My actual code is rather long, and I wouldn't like to post it here.
But here is the code I used as a first test at the possibility of
using generic interfaces for module procedures of the same scope:

! START OF THE CODE

module mod
implicit none
private
public :: func, subr
contains

function func() result(res)
real :: res
real, parameter :: one = 1.
res = one
end function func

subroutine subr(x)
interface newname
function func()
end function func
end interface
real, intent(out) :: x
x = newname()
end subroutine subr

end module mod

program prog
use mod, only : subr
real :: x
call subr(x)
write(*,*) x
end program prog

! END OF THE CODE


When I try to compile it with G95 in Cygwin, it results in the
following line:

/cygdrive/c/Users/HLVIO~1/AppData/Local/Temp/ccKvomx9.o:test.f90:(.text
+0x27): undefined reference to `func_'

-- helvio
From: helvio on
I guess it's not possible to do a renaming like this. I'll just have
to use different names for the other variables. I just wanted to know
if there was an easy way to perform such a renaming, similar to what
we can do with USE.

Thanks anyway!

-- helvio
From: James Van Buskirk on
"helvio" <helvio.vairinhos(a)googlemail.com> wrote in message
news:2e53ff76-548a-4d2e-a88f-25f563d7d074(a)j4g2000yqa.googlegroups.com...

> interface newname
module procedure func
> end interface

--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end


 |  Next  |  Last
Pages: 1 2 3 4
Prev: ENTRY statement
Next: Namelist/module-question