COSC 152
PROGRAMMING LANGUAGES
Fortran 77 Examples
We'll be looking at Fortran 77 this semester. I've chosen to
focus on F77 because it captures the pieces of Fortran 95 (the latest
version of Fortran) that are most different from other modern languages.
To compile and run a Fortran program on studsys, use your favorite
text editor to create a source file with a .f extension. Don't forget
to watch which columns you're starting and stopping in. You can
then compile your program with the g77 command. Assuming your
program was in the file myprog.f, you would type:
g77 myprog.f
This will compile the program and leave the executable in a.out. Like
with the C compiler, you can specify a different executable with the
-o option:
g77 myprog.f -o myprog
You can then run your program by typing its name. For instance, after
the second command above one would just type
myprog
You can read more about the g77 compiler
with the command
info g77
Here are a few sample programs.
- try.f and try2.f
- These two short programs demonstrate formatted I/O.
- grid.f
- This is one of the programs discussed in class. It simulates
heat distribution on a metal plate.
- grid2.f
- This is another version of grid which uses common blocks to
share variables between subprograms.
- roll.f
- This simple little program uses random numbers to simulate
the roll of a die.
- textp49.f
- Here is an example from an earlier version of Sebesta's book.
Back to COSC 152 homepage.