Reputation: 390
I am going through and analyzing a legacy FORTRAN code and i found in some of the places where COMMON is used and the list of variables used do not have any data type
DIMENSION X(50),Y(50),VER(20),FCUR(20),H3(6),H4(6),G(6),TTAT(20),
XX(50),YY(50),EFFS(5),EFFI(5),PARA(6,9),ZZ(50)
COMMON X,Y,PARA,TTAT,TTAT1,TTAT2,TTAT4,XQ,XL,WZ, SA1,K7,
FVOL1,K1,K2,M5,RFIL,TNO,SAF,CFT,CFY,DSH
COMMON ACUL,AFMAX,AL,ALA,ALF,ALP,AKC,AKP,AMC,AS,AMP,AKE1,ATG,
AN1,AMPF,ALG,AKE,BC,BG,BA,BT,BAT,BTMAX,CUST1,CUST2,CUST3,CUST4,
CAP,CYCLE,CYCLL,CYCLH,CW,CH, CAT,CAR,CMT,CMR,CAPL,CAPH,DATE1,
DATE2,DATE3,D1,DA,DB,DAMP,DY1,DBAR,D2L1,D2L2,DC,D4,DEND,ER,EX,
I have seen that this variables X,Y,PARA,TTAT,TTAT1,TTAT2,TTAT4,XQ
etc. are used in calculation but no data type is declared for them .
I assume the following rule is implemented here
Fortran variables with names starting [I J K L M N]
were INTEGER and everything else was REAL.
SO is the same rule followed for common also ?
Thanks in advance
Upvotes: 1
Views: 650
Reputation: 724
Exactly.
You should probably start with IMPLICIT NONE in each routine and explicitly define the variables. INTENT also makes for ease of reading the goes-into and comes-outta ...
e.g.:
SUBROUTINE A(B, C, I, IO)
USE My_Module_from_a_common
IMPLICIT NONE
DOUBLE, DIMENSION(:), INTENT(IN ) :: B
REAL, , INTENT(INOUT) :: C
INTEGER, , INTENT( OUT) :: I
LOGICAL, , INTENT(IN ) :: IO
In modern code, a module is compiled. Then the USE statement is like an import for the module.
A USE -module- is effectively the merge of the /common/ block and INCLUDE '-file-'... with some additional benefits. All the items defined as PUBLIC are global, and private are internal.
e.g.:
MODULE My_Module_From_a_Common
PUBLIC
REAL, DIMENSION(50), CONTIGUOUS :: X, Y, YY, ZZ
REAL, DIMENSION(6 ), CONTIGUOUS :: H3, H4
!etc X(50),Y(50),VER(20),FCUR(20),H3(6),H4(6),G(6),TTAT(20),
!etc XX(50),YY(50),EFFS(5),EFFI(5),PARA(6,9),ZZ(50)
!etc COMMON X,Y,PARA,TTAT,TTAT1,TTAT2,TTAT4,XQ,XL,WZ, SA1,K7,
!etc FVOL1,K1,K2,M5,RFIL,TNO,SAF,CFT,CFY,DSH
!etc COMMON ACUL,AFMAX,AL,ALA,ALF,ALP,AKC,AKP,AMC,AS,AMP,AKE1,ATG,
!etc AN1,AMPF,ALG,AKE,BC,BG,BA,BT,BAT,BTMAX,CUST1,CUST2,CUST3,CUST4,
!etc CAP,CYCLE,CYCLL,CYCLH,CW,CH, CAT,CAR,CMT,CMR,CAPL,CAPH,DATE1,
!etc DATE2,DATE3,D1,DA,DB,DAMP,DY1,DBAR,D2L1,D2L2,DC,D4,DEND,ER,EX,
END MODULE My_Module_From_a_Common
The advantage is that the use makes all the common instantiations the same if you need to add, change, or remove a variable.
When you compile -check all and -warn all, or -check uninit and -warn unused can be helpful to work out stuff...
In a routine or function save is implied by = something... e.g. these are the same, otherwise there is no saving of the result the next time in.
REAL :: A = 22.1
REAL, SAVE :: A
Upvotes: 2
Reputation: 60008
Yes, the implicit rules are in effect. If a common block is defined in an include find, it is really better to define the types of all variables because you can include it in procedures with different implicit rules then (including implicit none
). Common blocks included from an include file follow the rules of the subroutine which includes it.
Upvotes: 1