SPY HILL Research
Spy-Hill.net

Poughkeepsie, New York [DIR] [UP]

Fortran and Unix
for Physics and Astronomy


A reading course to learn computer programming for scientific coursework and research.

This is the Home Page for an independent study reading course in Fortran and Unix for Physics and Astronomy students.

Textbook Info Instructor/Mentor Exercises Schedule

Introduction

Computer programming is an important skill for experimental, observational and theoretical scientific work, and Fortran is (still!) one of the most important computer languages used for such work. Similarly, the Unix operating system is now in use on most scientific computer systems, ranging from PC's and workstations to supercomputers and computer clusters. The purpose of this course is to introduce students to programming in Fortran 77, while at the same time familiarizing them with the Unix operating system and many of the programming tools available in the Unix environment, including the emacs editor and the Revision Control System (RCS).

The only real way to learn to program is by writing programs, so the course is structured around a set of simple exercises. Each exercise requires that you learn one or more new programming concepts in order to complete that exercise. Once your program works correctly, you can move on to the next exercise.

Why Fortran 77? Why not C or C++?

The latest version of Fortran is Fortran 90, so why does this course use Fortran 77?

First of all, Fortran 90 includes Fortran 77 as a subset, so by learning Fortran 77 you are actually learning the basics of Fortran 90 too. But Fortran 90 also includes extra language elements for manipulating arrays and matrices, and new control structures. These are useful, especially for problems which have to be run on the latest supercomputers, but they can also be confusing for beginners. It is better to start with simpler ideas and work your way up. So you should start by learning Fortran 77, and then later learn the more powerful and specialized constructs of Fortran 90.

A second reason for using Fortran 77 is that Fortran 77 compilers are available everywhere, on all kinds of computers. Many Unix computers come with the f77 compiler included for free, or you can get the GNU Fortran compiler (g77) from the Net for free. In contrast, Fortran 90 compilers are not as widely available right now, and they generally cost extra. (Of course if all you have is a Fortran 90 compiler, it should work fine on Fortran 77 code.)

Some people say it's better to learn C or C++. Why not learn those instead of Fortran?

First of all, Fortran is the easier language to learn, and it is specially designed for scientific and engineering applications. That means you can start immediately to write programs that do useful calculations for your research or classwork. Fortran has continued to be a language used many major scientific computing projects.

C and C++ are certainly both useful languages to know too, but they are a bit more complex and thus harder to learn. C is stricter about grammar and syntax than Fortran. A good way to learn C++ is to first learn C; And for scientists, the best way to learn C is usually to learn Fortran first, as long as you also learn proper style and develop good habits designed to carry over to C. The grammar and style suggestions given in this course are all designed to develop proper programming methods and good habits, so that you can then go on to learn C, and perhaps C++, or any other programming language you may need.

Textbooks

You will need a textbook for the course, but you don't have to buy a particular one - any of a number of books on Fortran 77 can be used. Some recommendations for both a text and some supplementary books can be found here.

Instructor/Mentor

It is possible for you to work through the exercises yourself, without an instructor, but that is not the most effective way to learn Fortran.

Instead, you should have an instructor, or "mentor," who can answer your questions and give you suggestions and guidance while you are writing your programs, and who can read through your programs when they are finished to be sure that they actually meet the requirements of the exercise (see below).

Choose your instructor wisely (if you have a choice). You do not want someone who knows only the technical aspects of Fortran. Just as there is more to writing good prose than obeying the rules of grammar, there is more to writing good computer code than obeying the rules of the language syntax. A good instructor will also give you valuable lessons about proper "style", and may also let you in on some of the tricks that can help you become a master programmer.

Lesson Structure

The entire course consists of 16 lessons. Here is how each lesson works in practice:

  1. You get a copy of the exercise handouts and any other materials that go with the exercise, either from your instructor or from the web as PDF files.

  2. You read in your book about the topics to be covered in the lesson. Since there is no particular textbook for the course, you will have to hunt a bit to find the right sections to read in the book you happen to be using. Use the index to make sure that you have looked at everything. Don't feel that you have to understand everything all at once. The advantage of this approach is that you will get to know your book better, and you won't just be following along, you will be actively participating.

  3. You write a program to accomplish the assigned goal of the exercise. Be careful, the wording in each assignment specifies exactly what the result should be. Be sure to allow time to "debug"your program (fix any errors). Most programs don't work correctly the first time you type them in, even if they run and produce some kind of output. "Debugging" is an important part of the process of writing a program.

  4. When you think your program is finished, print out a copy of the program for your instructor. You should also print out a sample run, demonstrating the operation of your program. (Instructions on how to do this are given in one of the early lessons.) Give your instructor the printed copies of your program and sample run. You should also give an electronic copy of your program to your instructor, usually by copying it to your instructor's "inbox".

  5. After your instructor has reviewed your program, you should get together to discuss it. If your program does not meet the stated goals of the exercise then you will have to work on it further until it does. Your instructor can give you some suggestions. Even if your program does work correctly, you can still learn some things from discussing how it might be improved. But you don't need to make the improvements this time around if your program works as it should. Once your program accomplishes the stated goals of the exercise, you should move on to the next exercise.

Exercises

Continue on to the list of exercises...
  Copyright © 2012 by Spy Hill Research https://www.spy-hill.net/myers/fortran/index.html (served by Islay.spy-hill.com) Last modified: 20 March 2012