Your First Program

We'll assume that you know how to log-in to the computer that you will be using, and how to run the Fortran compiler. If you are a Haverford student, instructions for all of this are on the H205 manual page. Otherwise ask the instructor at your institution.


We'll start by writing a simple "hello world" program., shown below

program hello 
  implicit none
    write (*,*) "hello world!" 
    stop
end program hello

Let's go line by line to see what this means:

program hello
states that this is the beginning of a main program which is named "hello"
  implicit none
states that all of the variables will need to be explicitly defined. In our program, we don't have any variables, so this statement is kind of useless in the present case. That being said, it is a good habit to get into, as you can have many problems later on if you don't do this. You'll also note that this line is slightly indented. F90 is free-format, meaning that the position in the columns is not meaningful (unlike F77). Indenting helps you understand the flow of your program better.
    write (*,*) "hello world!"
causes the text-string "hello world!" to be written into the standard-output (i.e., the screen, unless you have redirected on the command line). Later on, we'll learn how we can put different specifications instead of the two asterisks to specify writing into a specific file or with a specific format.
    stop
tells the program to stop running. This is kind of redundant (as the program should stop once the program ends (in the next line), but again, it is not a bad idea to put it in place.
end program hello
specifies that the program "hello" ends here.

That's it! Pretty easy, huh? Compile and run this to make sure it works. In the next section we'll learn how to do calculations.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License