COMMON statements are widely used in FORTRAN libraries as a means to implement global data, and allow storage sharing among different program units. In Java, public static variables can be accessed and shared from all other classes. So we convert a COMMON block into a class with variables in the COMMON block being translated into public static variables in the class.
In this case, some additional naming rules are needed:
As an example, the following FORTRAN program,
program comm integer a,b,fff,i1,i2 real d,f,f10 common a,b,d common /c0/fff,f a =0 b =10 d = 5.0 fff = 987.0 f = 3.456 end integer function myfunc() integer b,d,i real c,f1,f2 common b,d,c common /c0/i,f1 b = 10 d = 5 c = 0.1 i = 3 f1 =19.844 myfunc = d + b end
is translated into
class NonameCommon { public static int a; public static int b; public static float d; } class c0_c { public static int fff; public static float f; } class comm_mc { public static void main(String args[]) { myfunc_c myfunc_o ; int ReplaceMentVar0,i1,i2 ; float ReplaceMentVar1,f10 ; NonameCommon.a = 0 ; NonameCommon.b = 10 ; NonameCommon.d = (float)5.0 ; c0_c.fff = (float)987.0 ; c0_c.f = (float)3.456 ; } } class myfunc_c { public static int myfunc() { int ReplaceMentVar2 ; float ReplaceMentVar3,f2 ; NonameCommon.a = 10 ; NonameCommon.b = 5 ; NonameCommon.d = (float)0.1 ; c0_c.fff = 3 ; c0_c.f = (float)19.844 ; return(NonameCommon.b+NonameCommon.a); } }
This scheme solves global variable problem, and partly solves storage sharing problem. It fails when two corresponding common variables have different type, such as in
PROGRAM MAIN INTEGER A, B, C COMMON /C1/A,B,C ... END SUBROUTINE FOO() REAL X,Y,Z COMMON /C1/X,Y,Z ... END
A similar drawback is also associated with our current treatment for EQUIVALENCE statement.