Table gives a mapping between FORTRAN and Java data types.
Table: Mapping between data types
FORTRAN complex and character types need some special treatment.
The issue is that Java does not have complex type and it does not
support operator overloading. Thus, we have defined a class named
Complex, which includes two data fields for real and imaginary
parts of a complex quantity and methods corresponding to
primitive arithmetic operations
(+, -, *, /). Moreover, a simple
copy method is included to mimic assignment between two
complex variables. (the standard clone() method seems unnecessarily
complicated to use for our purpose.)
For the following example,
program complx complex com1,com2 com1 = (1.2,2.3)+(2.3,2.2)*(2.3,2.5) com2 = (1.0,1.0)/(1.0,1.0)*(1.0,1.0)-(4.3,3.4) com2 = com1 endCorresponding Java program looks like,
class complx_mc { public static void main(String args[]) { Complex com1,com2; com1 = ((new Complex((float)1.2,(float)2.3))) .add((new Complex((float)2.3,(float)2.2)) .mult((float)2.3,(float)2.5)); com2 = ((new Complex((float)1.0,(float)1.0)) .div((float)1.0,(float)1.0).mult((float)1.0,(float)1.0)) .minus((new Complex((float)4.3,(float)3.4))) ; com2 = com1.copy(); } }
FORTRAN character data are fixed length strings of characters. Java String has variable length. There are two possible ways to map FORTRAN character data to Java elements, either to char arrays, or to Strings. We decided on the latter. Thus, the following,
character * 10 s1, s2 s1 = '1234567890' s2 = s1(2:4)//'abc' s1(2:4) = 'xyz'
is translated into
String s1, s2; s1 = "1234567890"; s2 = s1.substring(1,4) + "abc"; s1 = s1.substring(0,1) + "xyz" + s1.substring(4,s1.length());
Note that we have taken care of the difference between substring designations in FORTRAN and Java. The fact that String object is read-only does not hurt here, since a new object is created and old one is to be garbage collected automatically.
There are some simple issues such as array declaration and element accessing within the program unit where the array is declared. They can be treated readily. For instance, the following program
program foo integer a(1:10) integer b(1:10,-10:10) integer c(1:10,-10:10,-10:0) integer i,j,k do 10 i=1,10 a(i)=10 - i do 10 j=10,-10,-1 b(i,j) = i + j do 10 k = -10,0,2 10 c(i,j,k) = i + j - k * i / j end
is translated by our converter into:
class foo_mc { public static void main(String args[]) { int a[] = new int [10-1+1] ; int b[][] = new int [10-1+1][10-(-10)+1] ; int c[][][] = new int [10-1+1][10-(-10)+1][0-(-10)+1] ; int i,j,k ; for (i=1; i<=10; i=i+1) { a[i-1] = 10-i ; for (j=10; j>=-10; j=j-1) { b[i-1][j-(-10)] = i+j ; for (k=-10; k<=0; k=k+2) j10: c[i-1][j-(-10)][k-(-10)] = i+j-k*i/j ; } } } }
However, the major problem occurs when passing arrays to subprograms. This is because Java array is `semantically' different from FORTRAN array (and also different from C array). A FORTRAN array is a collection of consecutive memory locations, organized according to dimensioning information. And a Java array is not required to keep its elements together. In fact, we should expect the elements of a multiple dimensional Java array scattered in the memory, (see section 15.9.1 of reference [3]). As a result there is no concept of storage majority for Java arrays.
This makes some well established practice in FORTRAN programming, which takes the advantage of consecutiveness of array elements, hard to have an effective Java counterpart. The following is an example (provided by one of attendants of the workshop).
REAL X(10) ... CALL F(X,10) CALL F(X(3),8) ... END SUBROUTINE F(A,N) REAL A(N) ... END
Things will be even more interesting, if multiple dimension arrays are involved as arguments. We have not come to a satisfactory scheme yet. An attractive solution is to linearize all arrays to single dimension and pass array name together with a starting index to method.