FORTRAN 90 FAQ: Compilation and Execution

How do I compile my program?
Suppose your program file is named as test.f90. The following command line compiles your program and generates an executable file a.out:
f90 test.f90
If you displike a.out, you can specify name for the executable file. For example, if you want to call your executable file test, the following command line compiles your program to an executable file test:
f90 test.f90 -o test
What is new here is adding -o test.
How do I execute my program?
Suppose your have compiled your source and generated an executable a.out. The following command line executes your program:
a.out
If the executable is called test, the following command line executes test:
test
How do I read data from a file rather than from the keyboard?
Suppose your executable is called a.out and your data are stored in a data file called data.in. The following command line executes your program and redirects all keyboard to the file:
a.out < data.in
If the executable is called test, the following command line executes test and takes input from data.in.
test < data.in
How do I send the screen output to a file?
Suppose your executable is called a.out and your want to send the screen output to a file called data.out. The following command line executes your program and redirects all screen output to the file:
a.out > data.out
If the executable is called test, the following command line executes test and send screen output to file data.out.
test > data.out
Note that if you see a message like File already exists, then remove data.out and execute again.

How do I save compiler error messages to a file?
Suppose your source program is test.f90 and you want to save compiler error messages to a file called test.err. The following is a possible solution:
f90 test.f90 >& test.err
Or, if you do not compile test.f90 to a.out, then do the following, where test is name of the executable:
f90 test.f90 -o test >& test.err
Note that if you see a message like File already exists, then remove test.err and execute again.

When I compile my program, I got the following message. What is the problem?
ld: fatal: file means: unknown type, unable to process using elf(3E) libraries
ld: fatal: File processing errors.  No output written to a.out
This is a common mistake. You must forgot adding the file extension .f90. For example, you perhaps compiled your program with the following command line:
f90 test
where test is your program file test.f90. Please note that the file extention .f90 cannot be omitted.

Why does the FORTRAN compiler always complain I made an error at a place where I don't see anything wrong?
FORTRAN compilers are not as smart as human. Sometimes, it would just keep processing your program until it hits a road block. At that moment, it is too late for the FORTRAN compiler to give you any meaningful message. Therefore, when you encounter this problem, you look for the mistakes in nearby statements.

How come my a.out does not work?
Check the following: