Re: type/rank mismatch error
- From: estevino@xxxxxxxxx
- Date: Fri, 29 Jun 2007 09:40:37 -0700
On Jun 29, 9:14 am, "Les" <l.neil...@xxxxxxxxxxxxxxxxxxx> wrote:
<estev...@xxxxxxxxx> wrote in message
news:1183130878.777871.123690@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Richard, Jugoslav,
Thank you both for clarifying the issue, which was one of scope and a
namespace confusion. My previous post was perhaps not clear --
probably as opaque as this code. As before, the module is
<snip>
After your informative posts, I reread the scoping rules (surprise,
noob F90 programmer). I realized that the external driver would make
a call to number1 like this:
PROGRAM driver
USE calculate <-------- this USE allows the driver
to use the subroutine in module calculate
USE various <-------- contains subroutines that
do dirty work
! variables...
call number1(aa,bb,some_op) <-------- here I can address the
name of the subroutine directly
...
END PROGRAM
Inside MODULE various, both the SUBROUTINE declarations, AND any
subsequent nested subroutine calls that also need 'some_op' inside
must have a different name for their dummies, with an appropriate
EXTERNAL declaration for those dummy args. So, the original module
various should look more like
MODULE various
USE calculate
CONTAINS
SUBROUTINE number1(x1,y1,op1)
EXTERNAL :: op1
REAL :: x1,y1
... other calcs
call number2(x1,y1,op1)
END SUBROUTINE number1
!
SUBROUTINE number2(x2,y2,op2)
EXTERNAL :: op2
call number3(x2,y2,op2)
END SUBROUTINE number2
...
END MODULE various
This way, there isn't confusion about the naming of the module.
However, this seems to me an obfuscated way of coding. Is there some
way to name the subroutine some_op consistently?
Thanks for your help and expertise!
If you are _always_ going to eventually call "some_op" then there is no need
to pass it to the various "number" routines - just do a call some_op at the
appropriate place, providing you have the appropriate "USE calculate" giving
you access to the some_op subroutine (which you do have in the code you
showed).
But if the "number" routines are to be general purpose then *any*
appropriate routine can be passed, from the caller, as the actual argument
to op1, op2 etc, along with *any* appropriate values/variables for the other
arguments. In fact you could replace op1, op2 etc with just op in each of
the number routines indicating that each expects an external routine of some
sort.
Les
Thanks Les! In this case, passing the subroutine is really not
necessary. Your comment turned the light bulb on in my head!
Thanks everyone for their help!
.
- References:
- type/rank mismatch error
- From: estevino
- Re: type/rank mismatch error
- From: Jugoslav Dujic
- Re: type/rank mismatch error
- From: Richard Maine
- Re: type/rank mismatch error
- From: Jugoslav Dujic
- Re: type/rank mismatch error
- From: estevino
- Re: type/rank mismatch error
- From: Les
- type/rank mismatch error
- Prev by Date: Re: Need Help: compiling old Fortran program
- Next by Date: Re: Need Help: compiling old Fortran program
- Previous by thread: Re: type/rank mismatch error
- Next by thread: [ ] for arrays and co-arrays
- Index(es):
Relevant Pages
|