Prev: This implicit statement is not positioned correctly within the scope unit
Next: quest6ion about preceding spaces
From: monir on 4 Aug 2010 11:59 On Aug 4, 11:30 am, Steven Correll <steven.corr...(a)gmail.com> wrote: > On Aug 3, 12:17 pm, monir <mon...(a)rogers.com> wrote: > Hello; I've just retrieved your latest reply while I was in the process of posting mine. Please allow me some time. In the meantime here's what I was preparing to post: ----------------------------------------------------- 1) In your example (but only invoking the module procedure), I've replaced Subroutine mysubr() with Function mysubr(). The Interface in MODULE mymodule is now split into two interfaces; one for the Sub and one for the Func. That's because it appears that Interfaces must all be either functions or subroutines. There must be a logic behind such restriction. 2)I'm sure the code listed below would look pretty crummy for (most of) you, but at least it works as desired and it's a half step forward for me! (g95 Win O/S) ! Results: ! I am a module procedure 7 ! I am also a module procedure 8 MODULE mymodule implicit none Interface mmysub module procedure mysubi End Interface mmysub Interface mmysubr module procedure myFunr End Interface mmysubr Contains Subroutine mysubi(arg) integer :: arg(:) print *, 'I am a module procedure', size(arg) End Subroutine mysubi Function myFunr(arg) character(1) :: myFunr real :: arg(:) myFunr = 'I' print *, myFunr,' am also a module procedure', size(arg) End Function myFunr END module mymodule Program myprog implicit none integer :: myint(7) real :: myreal(8) call call_module_procedures() Contains Subroutine call_module_procedures() USE mymodule call mmysub(myint) myreal = ichar(myFunr(myreal)) End Subroutine call_module_procedures END Program myprog 3) The next task is to have "arg" in Function myFunr(arg) as a function, which would bring me much closer to the OP sample code. The thought of having its interface "within" the relevant interface in MODULE mymodule is a scary thought! Will look at some F90 for F77 programmers ref. texts and will try it shortly, but my guess it wouldn't work. Any suggestion ?? ----------------------------------------------------- Thank you. Monir
From: Richard Maine on 4 Aug 2010 12:33 monir <monirg(a)rogers.com> wrote: > That's because it appears that Interfaces must all be either functions > or subroutines. There must be a logic behind such restriction. There is a small element of truth in there, but sure not one that could be seen by reading those words without looking at the code. The correct version is that the specific procedures in a generic procedure must either all be subroutines or all be functions. There are interfaces that have nothing to do with generics. This restriction has nothing to do with them. And, of course, as even your code shows, you aren't talking about all generic interfaces, but just all the interfaces for a particular generic. Generics are for selecting a specific based on the arguments (particularly, the type kind, and rank). The exact rules are quite messy - some of the messier stuff in the language. There is at least one picky point in them that I've never understood myself. (No, I'm not going to bother to detail it in this thread any more than I would lecture on partial differential equations to a class on fractions). Fortunately, most cases can be explained without citing the exact rules. Subroutines and functions differ in ways other than the type, kind and rank of their arguments. I don't think I'll even try to explain why the rules could not also distinguish based on function returns as well as on arguments. That one has been asked before, but it is enough more complicated than the matters otherwise in question here that I cannot imagine it being fruitful to try to explain it. -- Richard Maine | Good judgment comes from experience; email: last name at domain . net | experience comes from bad judgment. domain: summertriangle | -- Mark Twain
From: Steven Correll on 6 Aug 2010 11:22 If I understand, you're asking how to declare a dummy argument to be a function. Here's an example. The Fortran 'interface' syntax is used for a couple of different purposes, which can be confusing. Previously I was using it to create a generic (a single name that can be used to call various specific procedures depending on the argument type/kind/ rank.) Here it is simply describing the argument and result of the dummy function myfuncarg: module mymod1 implicit none contains subroutine caller(myfuncarg) interface function myfuncarg(myarg) real :: myfuncarg, myarg(:) end function myfuncarg end interface real :: rv, myarray(3) rv = myfuncarg(myarray) print *, rv end subroutine caller function myfunc(myarg) real :: myfunc, myarg(:) myfunc = size(myarg) print *, 'I am a module procedure', myfunc end function myfunc end module mymod1 program myprog1 use mymod1 implicit none call caller(myfunc) end program myprog1 In a situation where Fortran doesn't require an explicit interface for a procedure (again, see a text for the rules) you can use "external" as a shortcut. You'll notice that this example has to use "myarg(myargsize)" rather than "myarg(:)" to stay within the rules: module mymod1 implicit none contains subroutine caller(myfuncarg) real, external :: myfuncarg real :: rv, myarray(3) rv = myfuncarg(myarray, size(myarray)) print *, rv end subroutine caller function myfunc(myarg, myargsize) integer :: myargsize real :: myfunc, myarg(myargsize) myfunc = myargsize print *, 'I am a module procedure', myfunc end function myfunc end module mymod1 program myprog1 use mymod1 implicit none call caller(myfunc) end program myprog1
From: monir on 6 Aug 2010 20:33 On Aug 6, 11:22 am, Steven Correll <steven.corr...(a)gmail.com> wrote: Steven; Fantastic! ... Thank you for your thoughtful and helpful replies. Your in-depth knowledge of the language and your expertise are clearly demonstrated by the examples you kindly provided which appear to be written with such ease and perfection in almost no time! I'm re-examining each scenario one more time with the hope to tailor each as the case maybe to suit the OP sample code. I should get it right this time. No excuse! Thanks again for your generous time and tremendous help. Regards. Monir
First
|
Prev
|
Pages: 1 2 3 4 Prev: This implicit statement is not positioned correctly within the scope unit Next: quest6ion about preceding spaces |