down

Exercise 6: CVS, Makefiles, Project 1 Part 1

This exercise is an introduction to CVS, make and makefiles, and is also the first part of Project 1. Understanding make and makefiles is a prerequisite for Project 1, and while carrying out the makefile exercise you also get to work on array-valued functions that are needed for the project.

Project 1 brings together a number of components from the first five Sections of the course, and is a comprehensive test of what you (should ;-) have learnt so far. In particular, it tests your ability to handle a reasonably large project, by focusing sometimes on the big picture, sometimes on the small pieces.

The situation is similar to one you would (will) encounter in a collaborative programming project. You are responsible for completing a larger program, by collecting a number of program pieces, and then adding some missing parts.

You may assume that the pieces you get have been tested and are working correctly. Correspondingly, it is your responsibility to make sure, by testing, that the pieces you add or modify are working as intended.

First be sure to pick up your bonus points!   Credits: 5/5

Subsections
  approx time  
CVS

40 min

Spline derivatives
50 min
Spline integrals
75 min
Home Work
1 hour


down up  CVS

[about 40 minutes]

This time, you will use CVS (Concurrent Versions System) to pick up the exercise material from a directory, importing it into a private CVS repository, and then extract a working copy into the directory where you will work on Project 1.

If you would like to read more about CVS or tkcvs, or look up details about a command, there are links and on-line documentation. Or, find out how to download WinCVS, MacCVS, TortoiseCVS or tkcvs.  


down up  Spline Derivatives

[about 50 minutes]

Your starting point for this part of the exercise is an example that illustrates array-valued functions, Fortran modules, and UNIX makefiles. The example is built around an array-valued function for spline derivatives. After having pondered enough upon the example to understand the relation between the files involved, you are to add a set of similar routines for spline integrals.

In principle, you could compile and run the test with the commands
       gfortran splines.f90 derivative_test.f90 
       ./a.out

However, to help introduce you to and try out a makefile that you will need anyway, the skeleton Makefile should be used to run the test.

To check that you understand the makefile relations and the notations used to describe them, please answer the following questions (if you are uncertain about these questions, review the subsection about makefiles in the Section 6 lecture notes):

The clean target is often present in Makefiles (this is by convention, not by requirement). As the name suggests, it is used to clean-up; i.e., remove all files that can easily be reconstructed -- basically all files that result from compilation. As it stands, your Makefile does not remove certain files. To find out which ones, run "make", then run "make clean", then run "cvs -n update". The "cvs -n update" does nothing, but shows what would be done by "cvs update". As a useful side effect, it shows files that CVS knows nothing about, with a question mark in front.

As supplied, the spline_derivative function has the three arguments x, y, n, where n is the number of elements in the arrays x and y. By using the Fortran-90 standard function SIZE(a), that returns the number of elements in the array a, you may eliminate the need to pass n in the argument list.


down top Spline integrals

[about 75 minutes]

You should now have enough experience to carry out the next step; to write an array-valued function named spline_integral, that returns the integral of a spline, defined by its function values and derivatives at a number of 'knots', x(i).

The function should return an array with SIZE(x) elements. Each element is equal to the integral of f(x) from x(1) to x(i) (the first value is thus always zero). f(x) is the cubic spline through the given function values y(i) at the knots x(i).

The spline_integral itself should be callable as follows:

        q = spline_integral (x, y)

i.e, it too should use the SIZE() function to specify the number of elements in x and y (and in the result). The formula to use for the integral is in the lecture notes.

In terms of files, you need to change and / or create the following files:

If all goes well, you should be able to run the test with the command make integral_test, or just make, if you made a smart update of the Makefile.

A hint is available [-1]   Credits: -1/-1

The plain "make" command should run first the derivate test, then the integral test (since the latter depends on the former).

If everything seems OK, but you get NOK for an answer, then maybe this hint helps [-1]   Credits: -1/-1

The last points are given when you submit the working source code for our inspection:

Here is my working version of the spline_integral routine -- it is included in splines.f90 Locate and upload your splines.f90 file: Credits: 5/-5
OK


top top Home work

[about 1 hour]

When you are done with the points above you have Project 1 well in hand. The physics and programming aspects of the project are presented in the next lecture, and the next exercise file contains the instructions for finishing the project.

One of the programming aspects that is central in the project is how to fill in values in an array, row-wise and column-wise. To help you prepare for this, here are a two examples.

It may be a good idea to print these out from your browser, study them, and try to guess what the output would be when executed. You can also save them in your Project1 directory, compile and execute them, and check if your guess was correct.

It is also a good idea to (re-)read the sections in your Fortran book about array indexing and argument passing, especially about "assumed-shape" arrays, "automatic arrays", and "allocatable arrays".