Before learning how to write a Fortran program, let's start with some information about Fortran and where to find tutorials and documentation.
To get started, you can follow on of these links:
Gunnar Wollan (previously teached GEO4060) has compiled a set of documents. I have used his material to build this course. You can find these documents at
http://folk.uio.no/gunnarw/GEO4060/
Seen in a historical perspective Fortran is an old programming language:
1954: John W. Backus and his team at IBM begin developing the scientific programming language Fortran.
1959: a new version, Fortran II was introduced.
1962: a new version called Fortran IV emerged. This version had among it’s features the
ability to read and write direct access files and also had a new data-type called LOGICAL.
1978: Fortran 77 was introduced. This version contained better loop and test structures.
1992: Fortran 90 was formally introduced as an ANSI/ISO standard. This is a major revision of Fortran and it has made the
language into a modern programming language.
1995: Fortran 95 is a minor revision of Fortran 90
2004: Fortran 2003, officially published as ISO/IEC 1539-1:2004, is a major revision introducing many new features.
2010: The most recent standard, ISO/IEC 1539-1:2010, informally known as Fortran 2008, was approved in September 2010.
It is a minor upgrade of Fortran 2003.
But a new programming language too: it evolves with user needs and technologies.
For instance Fortran 2003 incorporates object-oriented programming support
with type extension and inheritance, polymorphism, dynamic type allocation and
type-bound procedures and the latest standard Fortran 2008 includes a parallel execution model (coarrays).
So why Learning Fortran?
But the (best) reasons why it's still useful to learn Fortran are:
Fortran is well suited for numerical computations (Likely over 50\% of scientific applications are written in Fortran)
It generates fast code (compilers can optimize well)
Array data types and manipulation are very easy
It is relatively easy to write clear and portable Fortran code
There are many optimized numerical libraries available (such as BLAS, LAPACK, LINPACK, EISPACK, MINPACK, ARPACK, IMSL, NAG, etc.)
Compiling, Linking...
gfortran myprog.f90 -o myprog.exe
There are compiler options which makes your code to fail if it does not comply
to the chosen Fortran standard. With Gfortran, use -std i.e.:
gfortran myprog.f90 -o myprog -std=f95
gfortran myprog.f90 -o myprog -std=f2003
gfortran myprog.f90 -o myprog -std=f2008
And with Intel Fortran compilers (ifort):
ifort myprog.f90 -o myprog -std95
ifort myprog.f90 -o myprog -std03
ifort myprog.f90 -o myprog -std08
Not all Fortran 2003 or 2008 features have been implemented for all available compilers. To get an overview of the current status visit:
Compile your code with debug options (bound checkings, etc.)
Add meaningful comments
Do you use a standard indentation style? Can you easily identify loops (beginning and ending), branching statements (IF-THEN-ELSE), etc.?
Do you use procedures (SUBROUTINE, FUNCTION) or Fortran modules (MODULE, INTERFACE)? If yes, does
it make the code easier to understand? Easier to add new developments?
Do you ask users for inputs and if yes how? Do you use NAMELIST, input files, program arguments, or read environment variables?
How do you store the results? Do you simply print them on the screen, write an ascii file or binary file? Do you use standard output
format (such as PGM, HDF, netCDF, GRIB,etc.)?
Learn from examples: read codes that have been written by others and comment on their coding style!
Starting from an existing example is usually the best way to learn Fortran. Take it, compile it, test it and then start to modify it.
Try to add a new "feature" (add a new test, change the way the output results are written, or how the input parameters are provided, etc.), a new algorithm, etc.
Use a version control system
Keep your code and documents safe: this is true that having backup is one of the most important
best practices, but it should be maintained in well managed way. If you have multiple copies of the
same source code or document, then it will create confusion and it would be difficult to identify
the latest code or document. This is why it is mandatory to use a proper source code version control
system (such as git, mercurial, etc.) for your assignment project: it helps to keep track of your files. For our project,
we will be using git and github to collaborate.
You can find several good tutorials on the web. Here is a short list on git tutorials but feel free to
use any other resources: