Fortran COMMON block to module conversion
by mostlyharmless from LinuxQuestions.org on (#539DX)
Ok, I've exhausted my google fu, and I've ordered a fortran 90 book, but in the meantime, here's a question for anyone with FORTRAN 77 to fortran 90+ skills:
I'm working on some FORTRAN 77 code with a number of COMMON blocks that look like this
Code: PARAMETER (N=22,MM=180)
COMMON /VECS/ X1A(MM),X2A(MM,N),YA(MM,N)Many of the subroutines share data using these COMMON blocks, but also use the parameters N and MM, including using them in local (only for that subroutine) statements like Code:DIMENSION XYZ(MM)At this point, any change to the parameters N and MM, or the COMMON blocks has to be changed in every subroutine, with the possibility of inconsistencies or missing one. Hence, the drive to update the code using modules in fortran 90+
Clearly I can put the COMMON block data in a module, such as
Code: module initialize
integer, parameter :: MM=180, N=22and even add the arraysCode: real*4 :: X2A(MM,N),YA(MM,N),Y2A(MM,N)or Code: real, dimension (:,:), allocatable :: X2A,YA,Y2Aand later allocate them. However, what about the local matrix XYZ above that gets declared with global parameter MM?
Putting in the local subroutineCode:subroutine helpme
use initialize before Code:DIMENSION XYZ(MM)results in the compiler still wanting a value for MM and not declaring the array XYZ.
How are local arrays in a subroutine declared when their dimension depends on a global variable declared in a module?


I'm working on some FORTRAN 77 code with a number of COMMON blocks that look like this
Code: PARAMETER (N=22,MM=180)
COMMON /VECS/ X1A(MM),X2A(MM,N),YA(MM,N)Many of the subroutines share data using these COMMON blocks, but also use the parameters N and MM, including using them in local (only for that subroutine) statements like Code:DIMENSION XYZ(MM)At this point, any change to the parameters N and MM, or the COMMON blocks has to be changed in every subroutine, with the possibility of inconsistencies or missing one. Hence, the drive to update the code using modules in fortran 90+
Clearly I can put the COMMON block data in a module, such as
Code: module initialize
integer, parameter :: MM=180, N=22and even add the arraysCode: real*4 :: X2A(MM,N),YA(MM,N),Y2A(MM,N)or Code: real, dimension (:,:), allocatable :: X2A,YA,Y2Aand later allocate them. However, what about the local matrix XYZ above that gets declared with global parameter MM?
Putting in the local subroutineCode:subroutine helpme
use initialize before Code:DIMENSION XYZ(MM)results in the compiler still wanting a value for MM and not declaring the array XYZ.
How are local arrays in a subroutine declared when their dimension depends on a global variable declared in a module?