Exercise: Array Reversal

Part 1: Subroutine

Create a subroutine to reverse the order of a one-dimensional array of integers. The subroutine name must be ireverse and it takes the array as the sole argument. For example, if the array on input is (3, 17, -5, 2, 614), then the array on output should be (614, 2, -5, 17, 3). The subroutine must be contained in a module called arraytools. Ensure that the subroutine compiles into object code without errors or warnings.

Part 2: Program

Create a short program using your module which calls the subroutine with sample data and displays the results. Compile this program separately and then link its object code against your subroutine object code. Run the resulting program to verify that your subroutine works.

Part 3: Share

Exchange your subroutine object code only with your neighbour. Now, without recompiling, link your test program against their subroutine object. Check that the resulting program still runs and produces the same output.

Bonus points

Try this exercise again, but without using modules at all. You will have to write an interface block for the subroutine before you can use it in your program.

Solutions: Fortran.