posted
9/09/2005

Fortran's array manipulations

I was impressed by the strength in array manipulations introduced in Fortran 90 and Fortran 95. Two aspects particularly useful for scientific computing are:

  1. Flexible array slicing, or "sections", very similar to Matlab. For example,
    A(2:4, :)
    A( (/10, 99, 1, 7/) )
    A(10 : 1 : -1)
    
  2. Intrinsic "elemental" functions, that is, operating element by element in arrays. All basic math functions like sin, log, ..., in addition to the fundamental operators +, -, *, /, ** are of this kind. Again, very similar to the way Matlab works.

Moreover, user-defined functions can be elemental, starting with Fortran 95.

As far as I know, C++ is not as elegant or flexible in this regard.