Re: type/rank mismatch error



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

MODULE calculate
CONTAINS
SUBROUTINE some_op(a,b,c)
USE nrtype
IMPLICIT NONE
REAL, INTENT(IN) :: a
REAL, DIMENSION(:), INTENT(IN) :: b
REAL, DIMENSION(:), INTENT(OUT) :: c
c = a*b
END SUBROUTINE some_op
END MODULE calculate

Of course, an external routine would USE calculate and call some_op,
having already defined what a,b,c are.

The module throwing the error contains four subroutines, each of which
take a subroutine as a procedure argument. What is worse, two
subroutines call other subroutines that also have the *same* procedure
argument. In code,

MODULE various
USE calculate
CONTAINS
SUBROUTINE number1(x,y,some_op)
....
call number2(x,y,some_op)
END SUBROUTINE number1
SUBROUTINE number2(x,y,some_op)
call number3(x,y,some_op)
END SUBROUTINE number2
....
END MODULE various

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!

.



Relevant Pages

  • Re: type/rank mismatch error
    ... | SUBROUTINE some_op ... *Any formal argument of a routine must be declared locally ... END SUBROUTINE number1 ... END INTERFACE ...
    (comp.lang.fortran)
  • Re: type/rank mismatch error
    ... namespace confusion. ... to use the subroutine in module calculate ... END SUBROUTINE number1 ... the number routines indicating that each expects an external routine of some ...
    (comp.lang.fortran)