Fortran pros and cons (was Re: Coding style article with interesting section on white space)

Michael Tobis mt at
Mon Jan 31 05:04:26 CET 2005

beliavsky at wrote:
> Michael Tobis wrote:

> Fortran 90/95 is more expressive than Fortran 77 in many ways, as
> described in ...
> .

> ... expresses more science per
> line of code and per programming workday.

The example shown on p 10 illustrates a shorter piece of code in f90
than in f77, but it is not obviously more expressive or less complex.
Arguably the f77 code is easier to write and maintain, even though it
has more linefeeds in it, so I find the example far from compelling.

In fact, I find the f90 example impenetrable. Specifically, what does
array_copy(source,dest,n,nn) do? I note that n and nn are uninitialized
at call time. Are these outputs from array_copy(), appearing, in that
inimitable Fortran way, in the call signature?

Here it is in Python with NumArray:

b = sort(compress(less(v,200.) * greater(v,100.),m ))
result = b[(len(b)+3)//4]

I certainly think this example is competitive for whatever that's
worth. It has the added benefit of handling the case of an empty list
with a nice catchable IndexError exception.

However, if this were intended to be maintainable code I would find it
most effectively expressed something like this:

... def magthresh(vel,mag,vmin=100.,vmax=200.):
...    selector = less(vel,vmax) * greater(vel,vmin)
...    sortedmags = sort(compress(selector,mag))
...    if len(sortedmags):
...       index = (len(sortedmags) + 3) // 4
...       return sortedmags[index]
...    else:
...       raise IndexError,"No velocities in range."


More information about the Python-list mailing list