Edit Steps
1. 1
Start by having a good idea of what your program will do. Think about what sort of data is needed as input, how to structure the output, and include some intermediate output so you can monitor the progress of your calculation. This will be very useful if you know your calculation will run for a long time or involves multiple complicated steps.
2.
2
If you already know another programming language, you might be able to just start learning the syntax and looking up equivalents to various commands. Otherwise, you should do this:
3. 3
Learn how to compile and run a basic program, this will be your first program, typically it will just print "Hello World" to the screen and exit. Don't worry about all the minor details of the syntax, just become comfortable with compiling and running.
4. 4
Learn about variable types (INTEGER, REAL, CHARACTER, LOGICAL)
5. 5
Learn about the concept of variables, arrays, functions, and subroutines. Variables are where information is stored, functions and subroutines are pieces of code that can be executed, and arrays are groups of variables.
6. 6
Learn conditional statements, such as the "IF" and "SELECT CASE" statements. The "IF" statement will be one of your most frequently used statements, you can execute code based on whether a condition is true or not (e.g. whether the color the user provided was red).
7. 7
Learn loops and the "EXIT" and "CYCLE" statements.
8. 8
Learn about SUBROUTINES and FUNCTIONS.
9. 9
Learn Recursion (F90 and later) and other advanced topics
10. 10
Read or look up some books on Scientific Programming. For example, the book "Numerical Recipes in Fortran" is both a good text on scientific programming algorithms and a good introduction to how to put together codes. More recent editions include chapters on how to program in a mixed-language environment and parallel programming.
1. 1
A simple "Hello World" Code:
NOTE you have to space each line over 7 spaces
C HELLO.F -- HELLO WORLD PROGRAM C PUBLIC DOMAIN PROGRAM HELLO WRITE(*,*) 'Hello World' END PROGRAM
1. 1 write(*,*) means write some unformatted text to standard output
1. 1
Why the spaces? This is a relic from the past. In the early days of computer, there were no terminals. You entered data via punchcards. A "C" in the first line on the punch card indicated a comment line. The next 4 spaces were reserved for line numbers and the 6th space indicated that the current line is a continuation of the previous line. This is needed because punch cards were only 80 characters wide. So, any line longer than 72 characters would be chopped off! Because of this legacy, lines of fortran are sometimes called "Cards"
1. 1
Fortran 90 introduced the "Free Form" source code, allowing code to be written without the spaces and without the 72 character limit. For example, "Hello, World" could be written as
! HELLO.F90 -- HELLO WORLD PROGRAM
! PUBLIC DOMAIN
PROGRAM HELLO WRITE (*, *) 'Hello, World!' ! Display 'Hello, World'
END PROGRAM
1. 1