|
|
1.1 root 1: .TI F77/STYLE "Sep. 4, 1985"
2: Programming Style: fsplit; include and parameter statements
3:
4: This help file discusses several elements of programming style that
5: make Fortran programs easier to read, debug, and maintain.
6:
7: First it is best to keep each program in a separate directory with each
8: subprogram in a separate file. This minimizes compilation time as
9: you will only have to recompile those subroutines you have changed.
10: You can use the 'fsplit' utility to split up a source file with many
11: program units into separate files for each program unit, e.g.:
12:
13: fsplit bigsource
14:
15: Put each common block declaration in a separate file and use the
16: \&'include' statement to include the declaration in the source stream.
17: For example, if you have a common block 'c2' declared in several
18: program units as:
19:
20: .nf
21: ...
22: integer cnt2, ivec2(20), tot
23: common /c2/ cnt2, ivec2, tot
24: ...
25: .fi
26:
27: replace the declarations in the program units by:
28:
29: .nf
30: ...
31: include 'c2.h'
32: ...
33: .fi
34:
35: and create a two line file 'c2.h':
36:
37: .nf
38: integer cnt2, ivec2(20), tot
39: common /c2/ cnt2, ivec2, tot
40: .fi
41:
42: This eliminates problems of different common block declarations in different
43: program units, and makes it easier to maintain the program. Use the 'make'
44: utility to keep updating the object files if you change a common block
45: (see "help f77 make").
46:
47: Use parameter statements to define symbolic constants that may be used in
48: dimension statements and arithmetic expressions. You may say:
49:
50: .nf
51: parameter (NROWS=20, NCOLS=30, LENBUF=800)
52: parameter (PI=3.1415926535)
53: real a(NROWS,NCOLS), b(NROWS,NCOLS)
54: character buffer(LENBUF)
55: ...
56: do 100 i = 1,NROWS
57: do 90 j = 1,NCOLS
58: a(i,j) = b(i,j)*PI
59: ...
60: .fi
61:
62: instead of:
63:
64: .nf
65: real a(20,30),b(20,30)
66: character buffer(800)
67: ...
68: do 100 i = 1,20
69: do 90 j = 1,30
70: a(i,j) = b(i,j)*3.1415926535
71: ...
72: .fi
73:
74: .LP
75: Parameters are useful for dimensions, and limits. This way, you
76: don't have to remember the meaning of each number when you decide to
77: change the numerical values of the dimensions. Parameters can also be
78: used for constants (e.g. 'PI' above). Although the parameters are written
79: in upper case letters in this example, remember that f77 normally does
80: not distinguish case so that 'PI' and 'pi' are the same.
81: Parameter statements that are repeated in several subprogram units
82: should be put into include files.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.