Fortran 77

Here is my view on Fortran 77 and its numerical computation capabilities.

I got my first taste of computing with Fortran 77, mainly for numerical computations, because that is what was taught to structural engineers (which I am) during the 80s. Despite all the things that programming language experts point out as the short comings of Fortran, it could do some amazing things. Here are some of its capabilities that make it outstanding for numerical computations:
  • Its portability across platforms. Fortran programs that were developed on mainframes in the 70s would compile and run IBM PCs with no changes. Only when proprietary code was written to optimize disk operations would this observation not be valid.
  • Its ability to create arrays with user defined index limits is not available in most modern programming languages.
  • Its ability to pass one dimensioned arrays into a function or subroutine but view it as a multi-dimensioned array with index limits passed on as parameters was uncanny. It completely did away with the need for dynamic memory allocation. Most programs that I used would define a large one dimensioned array in the main program and map all other arrays into it within subroutine. Kind of, a poor man's dynamic memory allocation combined with dynamic arrays whose dimensions and indices could be determined at run time.
  • Repetition counters in output formatting
In spite of not being buzzword compliant it would get the job done in the shortest possible time. Here are some buzzwords that Fortran 77 is not compliant with:
  • Object oriented Programming, with its associated buzzwords such as function overloading, operator over loading.
  • Dynamic memory allocation.
  • Graphical User Interfaces
  • System programming
Now that there are Fortran 90 and Fortran 95, many of its idiosyncrasies have been ironed out. You can, for example:
  • Write free format code.
  • Avoid GOTO statements
  • Use a richer set of control statements
  • Create dynamic arrays
Unfortunately, I haven't had the opportunity to work with either of these versions of Fortran much and hence can't comment. But thanks to the GNU Compiler Collection (GCC) that we can get our hands on them if we want to. I believe it is a tragedy that most educational institutions, at least here in India have completely dropped Fortran from their curricula for no apparent reason other than wanting to be buzzword compliant. In the process, they have adopted programming languages such as C or C++ which are ill suited to teach numerical computations. As a result, fresh engineering graduates have little or no numerical computational skills, which I think is very sad.

C234567890
      REAL A(10000)
      READ(*,*) M, N
      CALL READMAT(M, N, A(1))
      READ(*,*) M1, N1
      CALL READMAT(M1, N1, A(M*N+1))
      STOP
      END

      SUBROUTINE READMAT(M, N, X)
      REAL X(M, N)
      DO 10 I = 1, M
        READ(*,*) (X(I, J), J = 1, N)
10    CONTINUE
      RETURN
      END

In the above Fortran 77 program, the code up to the STOP and END statements constitutes the main program (main() function for C programmers). It has a one dimensioned real array A with 10000 elements. SUBROUTINE READMAT reads values from the standard input (keyboard) and puts them into what it believes is a two dimensioned array X with M rows and N columns.

When READMAT is called first time CALL READMAT(M, N, A(1)), the third argument is A(1). Therefore A(1) is mapped to X(1) and since M*N elements are read it occupies the space in A from A(1) to A(M*N).

When READMAT is called the second time READMAT(M1, N1, A(M*N+1)), X(1) in the subroutine is mapped to A(M*N+1) and occupies the space from A(M*N+1) to A(M*N+M1*N1).

It is thus, the programmer's responsibility to ensure that the elements of the two arrays do not overlap. Further, there are no names for these variables in the main program, and the programmer must use integers to remember the start location and size of each array. It is certainly not intuitive, but then we must remeber that Fortran was developed in the 1050s, and make some allowance for that fact.

Resources

  • MinGW - Minimalist GNU for Windows, Fortran Compiler
  • Vim - Vi Improved, a versatile programmer's editor
  • You can get Gfortran for any Linux distribution. The best is Debian. You can try Ubuntu
Comments