Fortran1

From SourceWiki
Jump to navigation Jump to search

Fortran1: The Basics

We'll forge our path through the verdant garden of Fortran90 using a number of examples. To get your copy of these examples, from the version control repository, login to your favourite linux machine (perhaps dylan), and type:

svn co http://source.ggy.bris.ac.uk/subversion/fortran1/trunk --username=guest ./fortran1

hello, world

Without further ado, and in-keeping with the most venerable of traditions, let's meet our first example--"hello, world":

cd fortran1/examples/example1

and type:

make

Now type:

./hello_world.exe

Bingo! You've just compiled and run, perhaps your first, Fortran90 program. Hurrah! we're on our way:) Everybody whoop!

OK, you'd better reign in your excitement. Let's take a look inside the source code file. Open-up hello_world.f90, using cat, less, more or your favourite text editor, and you'll see:

!
! This is a comment line.
! Below is a simple 'hello, world' program written in Fortran90.
! It illustrates creating a main 'program' unit together
! with good habits, such as using 'implicit none' and comments.
!
program hello_world
  implicit none
  write(*,*)  "hello, world"
end program hello_world

We have:

  1. some comment lines, giving us a helpful narrative
  2. the start of the main program unit
  3. the implicit none statement (more of that in a moment)
  4. a write statement, printing our greeting to the screen
  5. and last, but not least, the end of the main program.

Baskets and the Types of Things

If, Do, Select and Other Ways to Control the Flow

Not one, Many!

If Things get Hectic, Outsource!

You can Have That, and I'll Have This