We have implemented translation of three kinds of I/O statements in their primitive forms: WRITE, PRINT and READ. FORTRAN provides sophisticated formatting facility for I/O through edit descriptors [6, page 13-5,], while Java does not [4, page 189,]. This discrepancy makes it difficult to faithfully translate FORTRAN I/O statements to Java. Thus, in our first attempt, formatting information is largely ignored. Nevertheless, some ``important'' formatting information, such as data items interleaved with pre-specified character strings, is properly translated. Thus, for the FORTRAN program:
program io integer a,b,c,d,e 100 format (i3,'Happy Day!') 200 format (i5,'Get',i8,'Hello') a=9 b=6 c=5 write(*,200) a,b,c print 200, a,b,c write(*,200) a,b,b,c print 200, a,b,c,d write(*,100) a,b,c print 100, a,b,c write(*,*) 'A=',a,'B=',b,'C' print *, 'A=',a,'B=',b,'C' write(*,'(i5,i9)') a,b print '(i5,i9)', a,b end
f2j converts it into:
class io_mc { public static void main(String args[]) { int a,b,c,d,e ; a=9 ; b=6 ; c=5 ; System.out.println(a+" "+"Get"+" "+b+" "+"Hello"+"\n"+c+" "+"Get"); System.out.println(a+" "+"Get"+" "+b+" "+"Hello"+"\n"+c+" "+"Get"); System.out.println(a+" "+"Get"+" "+b+" "+"Hello"+"\n" +b+" "+"Get"+" "+c+" "+"Hello"); System.out.println(a+" "+"Get"+" "+b+" "+"Hello"+"\n" +b+" "+"Get"+" "+c+" "+"Hello"); System.out.println(a+" "+"Happy Day!"+"\n"+b+" "+"Happy Day!"+"\n" +c+" "+"Happy Day!"); System.out.println(a+" "+"Happy Day!"+"\n"+b+" "+"Happy Day!"+"\n" +c+" "+"Happy Day!"); System.out.println("A="+" "+a+" "+"B="+" "+b+" "+"C"); System.out.println("A="+" "+a+" "+"B="+" "+b+" "+"C"); System.out.println(a+" "+b); System.out.println(a+" "+b); } }
Notice that we have inserted a blank space between two consecutive data items, and we have translated the effect of cyclic use of formatting rules.