Professional Documents
Culture Documents
Version 4.1
Abstract
These class notes are designed for use of the instructor and students of the course PHYS-4007/5007:
Computational Physics taught by Dr. Donald Luttermoser at East Tennessee State University.
II. How To Select a Programming Language
Fortran C IDL
Program Structure
program f main() (no main program structure)
function f(x) double f(double x) function f, x
subroutine f(x) void f(x) pro f, x
Operations
x∗∗y pow(x,y); x∧y
x=y x = y; x=y
do 2 k=1,kmax,1 for (k=1;k<=kmax;k++) for k=0,kmax-1,1 do
do 2 k=kmax,1,-1 for (k=kmax;k>=1;k–) for k=kmax-1,0,-1 do
Control Structure: if
if (den .eq. 0) then if (den == 0) { if den eq then begin
write(∗, ∗) ’Trouble’ printf(“Trouble”); print, ’Trouble’
endif } endif
Fortran C IDL
Switch
goto (1,2), choice switch (choice) { case choice of
1 series = first case 1: 1: series = first
2 series = second series = first; 2: series = second
break; else:
case 2: endcase
series = second;
break;
}
1. Fortran was first developed in 1957 by IBM and was the first
high-level programming language.
a) Its name is derived from “FORmula TRANslation.”
1. Some of you may have copied over the free-ware GNU Fortran 77
compiler. If you plan on using this software, read the readme.txt
for information on installing and running this compiler (note that
this ‘g77’ compiler must be ran from DOS mode). This package
contains the SLATEC mathematical library which is similar to
the LAPACK library (see Appendix A).
2. For those of you running a Fortran 77/90 code from the PCs in
Brown Hall, Digital Visual Fortran 5 has been installed on these
machines. Simply double click on the appropriate menu item in
the Start menu or the Developer Studio icon on the main screen.
3. One then creates a Fortran code in the editor window and used
the various buttons and pull-down menus to compile and run the
code. You will have to retrieve the LAPACK or BLAS libraries
from the netlib web site if you wish to use them. Then, use the
‘Help’ utility (search on “math library”) for instructions on using
external libraries.
iii) The Fortran file (or files) you will need should
already be present in this workspace. If not, open
the needed file (or files) in the “File” menu item.
c) This will bring up the emacs editor window and start writ-
ing your code. When done, click the “Save” button (fol-
lowed by the “Exit” button if you don’t need to make any
more modifications). Let’s say that we edit a second file
which contains some operating system specific command
(like the GETNODE() function that is available on some
Fortran compilers) called atlasunix.f.
2. The Linux operating system uses the GNU Fortran compiler called
g77. Read the ‘man’ pages on fester for a listing of compiler
options.
3. Compiling and linking the code are performed with one command
(again at the Unix prompt):
g77 –o atexe –W atlas.f atlasunix.f
a) Here the “–o” flag tells the linking software to save the
executable code in a file called atexe (if ‘–o’ was not in-
cluded, the executable would be saved in a file named
a.out).
iii) Date.
compiler which you are free to use. They do not have a C com-
piler. As such, if you wish to program in C, you will have to carry
out your calculations on the Linux workststion (see below).
8. ANSI C (1988).
9. 1991 ISO C.