billgray1234
Programmer
- Mar 14, 2011
- 39
i'm using Fortran 90. i use lots of subroutines (each of which are given the PUBLIC attribute). in most of these subroutines i'm using ALLOCATABLE matrices -- which are "locally within" each subroutine.
for ease of programming, i've thought of a "universal" way of naming INTEGER variables relating to the dimensions of these matrices. i'm currently using the "same naming of INTEGER variables" in all such subroutines. for example, in 2 different subroutines, i might have :-
.......SUBROUTINE SUB_1
.......INTEGER :: IB1 , JB1
.......INTEGER :: IB2
.......INTEGER :: IB3 , JB3
.......REAL ,ALLOCATABLE ,DIMENSION , :: MAT_1
.......REAL ,ALLOCATABLE ,DIMENSION ) :: MAT_2
.......REAL ,ALLOCATABLE ,DIMENSION , :: MAT_3
.......IB1 = ??
.......JB1 = ??
.......IB2 = ??
.......IB3 = ??
.......JB3 = ??
.......ALLOCATE ( MAT_1 ( IB1 , JB1 ) )
.......ALLOCATE ( MAT_2 ( IB2 ) )
.......ALLOCATE ( MAT_3 ( IB3 , JB3 ) )
.......END SUBROUTINE SUB_1
---------------------------
.......SUBROUTINE SUB_2
.......INTEGER :: IB1 , JB1
.......INTEGER :: IB2
.......INTEGER :: IB3 , JB3
.......REAL ,ALLOCATABLE ,DIMENSION , :: MAT_10
.......REAL ,ALLOCATABLE ,DIMENSION ) :: MAT_11
.......REAL ,ALLOCATABLE ,DIMENSION , :: MAT_12
.......IB1 = ??
.......JB1 = ??
.......IB2 = ??
.......IB3 = ??
.......JB3 = ??
.......ALLOCATE ( MAT_10 ( IB1 , JB1 ) )
.......ALLOCATE ( MAT_11 ( IB2 ) )
.......ALLOCATE ( MAT_12 ( IB3 , JB3 ) )
.......END SUBROUTINE SUB_2
---------------------------
note that the emphasis is on the INTEGER variables IB1, JB1, IB2, etc (and not the matrices).
my question is :-
if :-
a) 2 or more of these subroutines are called by the same calling code (SUBROUTINE CALL_SUBS, say), and
b) as noted above, the subroutines being called (i.e. SUB_1 and SUB_2) are declared as being PUBLIC. to my understanding, this means that each of the subroutines being called (and all variables that are "locally within" each subroutine being called) are "available" to the code that calls each subroutine. please correct me if i'm wrong here.
then is it valid to use the above universal "same names for all INTEGER variables" system ? because, does this mean that these "same names for all INTEGER variables" would be "available" to the code that calls each subroutine (and, therefore, would effectively be declared more than once, in the calling code).
my only thought is :- if it is NOT valid (for the reason i've stated), then can i instead make it valid by declaring the "local" INTEGER variables as being PRIVATE ? for example, can i change :-
.......INTEGER :: IB1 , JB1
.......INTEGER :: IB2
.......INTEGER :: IB3 , JB3
to
.......INTEGER ,PRIVATE :: IB1 , JB1
.......INTEGER ,PRIVATE :: IB2
.......INTEGER ,PRIVATE :: IB3 , JB3
for ease of programming, i've thought of a "universal" way of naming INTEGER variables relating to the dimensions of these matrices. i'm currently using the "same naming of INTEGER variables" in all such subroutines. for example, in 2 different subroutines, i might have :-
.......SUBROUTINE SUB_1
.......INTEGER :: IB1 , JB1
.......INTEGER :: IB2
.......INTEGER :: IB3 , JB3
.......REAL ,ALLOCATABLE ,DIMENSION , :: MAT_1
.......REAL ,ALLOCATABLE ,DIMENSION ) :: MAT_2
.......REAL ,ALLOCATABLE ,DIMENSION , :: MAT_3
.......IB1 = ??
.......JB1 = ??
.......IB2 = ??
.......IB3 = ??
.......JB3 = ??
.......ALLOCATE ( MAT_1 ( IB1 , JB1 ) )
.......ALLOCATE ( MAT_2 ( IB2 ) )
.......ALLOCATE ( MAT_3 ( IB3 , JB3 ) )
.......END SUBROUTINE SUB_1
---------------------------
.......SUBROUTINE SUB_2
.......INTEGER :: IB1 , JB1
.......INTEGER :: IB2
.......INTEGER :: IB3 , JB3
.......REAL ,ALLOCATABLE ,DIMENSION , :: MAT_10
.......REAL ,ALLOCATABLE ,DIMENSION ) :: MAT_11
.......REAL ,ALLOCATABLE ,DIMENSION , :: MAT_12
.......IB1 = ??
.......JB1 = ??
.......IB2 = ??
.......IB3 = ??
.......JB3 = ??
.......ALLOCATE ( MAT_10 ( IB1 , JB1 ) )
.......ALLOCATE ( MAT_11 ( IB2 ) )
.......ALLOCATE ( MAT_12 ( IB3 , JB3 ) )
.......END SUBROUTINE SUB_2
---------------------------
note that the emphasis is on the INTEGER variables IB1, JB1, IB2, etc (and not the matrices).
my question is :-
if :-
a) 2 or more of these subroutines are called by the same calling code (SUBROUTINE CALL_SUBS, say), and
b) as noted above, the subroutines being called (i.e. SUB_1 and SUB_2) are declared as being PUBLIC. to my understanding, this means that each of the subroutines being called (and all variables that are "locally within" each subroutine being called) are "available" to the code that calls each subroutine. please correct me if i'm wrong here.
then is it valid to use the above universal "same names for all INTEGER variables" system ? because, does this mean that these "same names for all INTEGER variables" would be "available" to the code that calls each subroutine (and, therefore, would effectively be declared more than once, in the calling code).
my only thought is :- if it is NOT valid (for the reason i've stated), then can i instead make it valid by declaring the "local" INTEGER variables as being PRIVATE ? for example, can i change :-
.......INTEGER :: IB1 , JB1
.......INTEGER :: IB2
.......INTEGER :: IB3 , JB3
to
.......INTEGER ,PRIVATE :: IB1 , JB1
.......INTEGER ,PRIVATE :: IB2
.......INTEGER ,PRIVATE :: IB3 , JB3