Some very simple examples that new Fortran 95* users may find
useful:
Example of an array
constructor
Example that shows the use of
automatic and assumed-shape arrays
Example that reads a data file
(data.txt) which contains an unknown
number of data points
Example which shows
the usage of preprocessor (my_header_file.h)
Example which shows how to assign
constants
Example which shows the
many ways in which a function can be defined
Example which shows the use of
'cycle' and 'exit' in nested loops; Example which shows the use of
'where' statement
Example which shows the use of
elemental procedures, defined for scalar arguments but are
(conveniently) applicable to arrays
Example which shows the use of
recursive procedures (Here's
another version)
Example which shows the use of
derived data types
Examples 1, 2 and 3 that show the use of
pointers
Example which shows the
use of allocatable in derived data types
Example which
shows how to load an intrinsic operator (Here's another example)
Example which shows a
custom operator being overloaded (Here's the same code but
now illustrates the use of public/private attributes in
modules)
Example which shows the
use of the assignment (=) operator (Here's the same code
but with public/private attributes)
Example which
illustrates subroutine/function overloading
Example which shows how to a pass
a procedure as an argument
Example which shows how to a pass
a procedure as an argument using external attribute
Example which shows the
use of optional arguments in subroutines (also possible in
functions)
Example which shows the use of 'save'
attribute in subroutines (also possible in functions)
Small example that solves Ax=b using
the vanilla conjugate gradient method (requires the solvers module which in turn uses the
utilities module). And here's the Makefile
Same problem as in the previous example except that now we use PETSc to solve it (with the
solver/PC being specified at runtime); Here's another version which reads the
linear system from a binary file (PETSc) and solves it in
parallel
Example which shows the
~maximum memory in 'Mb' that can be allocated on your machine
Example which shows how to
create a linked list
Example which leaks memory and
shows how to use Valgrind to detect it (Btw Valgrind can also be
used for cache profiling and here's
an example)
Some other small examples which
use popular numerical libraries like BLAS/LAPACK, ScaLAPACK, PETSc,
MUMPS etc.
The simplest MPI + OpenMP (hybrid) example. And here's its co-array counterpart
If you want to display Fortran code on web with syntax highlighting
then you can use the ':TOhtml' command in Vim to create the html
file (and this will look like
this)
If you really have the need to display data graphically within a
program then use a library like DISLIN (installation instructions
are available here)
Some other tips (useful while writing
code)
Finally, one of the reasons why you
should not use python for serious numerical computing ;-]
[*] Newer compilers such as Intel 10.0+, Sun Studio 12+, IBM XL
9.1+, G95 (no OpenMP but supports co-arrays), GFortran 4.0+ etc.
support many features of the 2003 Fortran standard. Refer to
Chapman's or
Metcalf,
Reid and Cohen's latest book for Fortran 2003 specific
examples.