Coding Fortran: A basic “Hello World”

When programming in Fortran (say F95), start with the most basic program, our friend “Hello World!”.

program helloWorld

   print *, "Hello World!"

end program helloWorld

A three line program (hello.f95). No need to worry about I/O libraries, or any sort of formatting. It is simple. This is compiled using gfortran as:

gfortran hello.f95

The print statement could have also been replaced with the more traditional:

write (*,*), "Hello World!"

If this were an older Fortran program (pre-F90)  the code would look similar, but wouldn’t allow any free-formatting, for example (hello.for):

1234567      
      program helloWorld

      write (*,*), "Hello World!"

      end program helloWorld

Here the actual code begins in the 7th column, and columns 1-6 are reserved for other things like program labels. If a line of code creeps into those columns, there will be an error of some sort.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.