Professional Documents
Culture Documents
Michael Metcalf
Formerly of CERN; Geneva, Switzerland
John Reid
JKR Associates, Oxfordshire
and
Malcolm Cohen
The Numerical Algorithms Group
Oxfordshire
OXFORD
UNIVERSITY PRESS
Contents
1 Whence Fortran?
1.1 Introduction
1.2 Fortran's early history
1.3 The drive for the Fortran 90 standard
1.4 Language evolution
1.5 Fortran 95
1.6 Extensions to Fortran 95
1.7 Fortran 2003
1.8 Conformance
2 Language elements
2.1 Introduction
2.2 Fortran character set
2.3 Tokens
2.4 Source form
2.5 Concept of type
2.6 Literal constants of intrinsic type
2.6.1 Integer literal constants
2.6.2 Real literal constants
2.6.3 Complex literal constants
2.6.4 Character literal constants
2.6.5 Logical literal constants
2.7 Names
2.8 Scalar variables of intrinsic type
2.9 Derived data types
2.10 Arrays of intrinsic type
2.11 Character substrings
2.12 Objects and subobjects
2.13 Pointers
2.14 Summary
2.15 Exercises
3 Expressions and assignments
3.1 Introduction
1
2
3
4
4
5
6
7
9
9
9
10
11
13
13
14
15
16
17
19
19
20
21
22
25
26
27
28
29
33
33
x Contents
34
37
38
38
39
41
42
45
46
48
48
51
51
4 Control constructs
4.1 Introduction
4.2 The go to statement
4.3 The if statement and construct
4.4 The case construct
4.5 The do construct
4.6 Summary
4.7 Exercises
53
53
53
54
56
58
63
65
67
67
68
69
69
70
73
73
75
76
77
77
77
79
80
81
83
84
85
86
88
89
Contents xi
91
95
96
96
97
6 Array features
6.1 Introduction
6.2 Zero-sized arrays
6.3 Assumed-shape arrays
6.4 Automatic objects
6.5 Heap storage
6.5.1 Allocatable arrays
6.5.2 The allocate statement
6.5.3 The deallocate statement
6.5.4 The nullify statement
6.6 Elemental operations and assignments
6.7 Array-valued functions
6.8 The where statement and construct
6.9 The forall statement and construct
6.10 Pure procedures
6.11 Elemental procedures
6.12 Array elements
6.13 Array subobjects
6.14 Arrays of pointers
6.15 Pointers as aliases
6.16 Array constructors
6.17 Mask arrays
6.18 Summary
6.19 Exercises
99
99
99
100
100
102
102
103
105
105
106
106
107
110
113
114
116
117
120
121
122
123
124
127
7 Specification statements
7.1 Introduction
7.2 Implicit typing
7.3 Declaring entities of differing shapes
7.4 Named constants and initialization expressions
7.5 Initial values for variables
7.5.1 Initialization in type declaration statements
7.5.2 The data statement
7.5.3 Pointer initialization and the function null
7.5.4 Default initialization of components
7.6 The public and private attributes
7.7 The pointer, target, and allocatable statements
7.8 The intent and optional statements
7.9 The save attribute
129
129
129
132
132
135
135
135
138
139
140
142
142
143
xii Contents
8.1 Introduction
8.1.1 Keyword calls
8.1.2 Categories of intrinsic procedures
8.1.3 The intrinsic statement
8.1.4 Argument intents
8.2 Inquiry functions for any type
8.3 Elemental numeric functions
8.3.1 Elemental functions that may convert
8.3.2 Elemental functions that do not convert
8.4 Elemental mathematical functions
8.5 Elemental character and logical functions
8.5.1 Characterinteger conversions
8.5.2 Lexical comparison functions
8.5.3 String-handling elemental functions
8.5.4 Logical conversion
8.6 Non-elemental string-handling functions
8.6.1 String-handling inquiry function
8.6.2 String-handling transformational functions
8.7 Numeric inquiry and manipulation functions
8.7.1 Models for integer and real data
8.7.2 Numeric inquiry functions
8.7.3 Elemental functions to manipulate reals
8.7.4 Transformational functions for kind values
8.8 Bit manipulation procedures
8.8.1 Inquiry function
8.8.2 Elemental functions
8.8.3 Elemental subroutine
8.9 Transfer function
8.10 Vector and matrix multiplication functions
8.11 Transformational functions that reduce arrays
8.11,1 Single argument case
8.11.2 Optional argument dim
8.11.3 Optional argument mask
8.12 Array inquiry functions
144
147
149
150
151
152
153
154
156
159
159
159
160
160
160
160
161
161
162
163
164
164
164
165
165
166
166
166
166
166
167
168
169
169
169
170
171
171
172
172
172
173
173
174
Contents xi
174
174
174
174
175
175
176
176
176
176
177
177
177
178
179
179
180
9 Data transfer
9.1 Introduction
9.2 Number conversion
9.3 1/0 lists
9.4 Format definition
9.5 Unit numbers
9.6 Internal files
9.7 Fonnatted input
9.8 Formatted output
9.9 List-directed 1/0
9.10 Namelist 1/0
9.11 Non-advancing 1/0
9.12 Edit descriptors
9.12.1 Repeat counts
9.12.2 Data edit descriptors
9.12.3 Minimal field width editing
9.12.4 Character string edit descriptor
9.12.5 Control edit descriptors
9.13 Unformatted1/0
9.14 Direct-access files
9.15 Execution of a data transfer statement
9.16 Summary
9.17 Exercises
181
181
181
182
184
186
187
188
190
190
192
194
195
195
197
199
200
200
203
203
205
206
207
209
209
210
xiv Contents
10.2.1 The backspace statement
10.2.2 The rewind statement
10.2.3 The endfile statement
10.2.4 Data transfer statements
10.3 The open statement
10.4 The close statement
10.5 The inquire statement
10.6 Summary
10.7 Exercises
210
210
211
211
212
214
215
218
218
219
219
220
221
223
224
224
225
225
225
226
226
227
228
228
229
230
232
232
233
233
234
234
235
237
239
239
240
240
241
244
245
245
Contents xv
13.2 Submodules
13.2.1 Separate module procedures
13.2.2 Submodules of submodules
13.2.3 Submodule entities
13.2.4 Submodules and use association
13.3 The advantages of submodules
246
246
247
247
248
248
14 Interoperability with C
14.1 Introduction
14.2 Interoperability of intrinsic types
14.3 Interoperability with C pointer types
14.4 Interoperability of derived types
14.5 Interoperability of variables
14.6 The value attribute
14.7 Interoperability of procedures
14.8 Interoperability of global data
14.9 Invoking a C function from Fortran
14.10 Invoking Fortran from C
14.11 Enumerations
249
249
249
251
252
253
254
255
256
257
257
260
261
261
261
262
262
262
264
264
265
265
267
267
267
268
270
16 Object-oriented programming
16.1 Introduction
16.2 Type extension
16.2.1 Type extension and type parameters
16.3 Polymorphic entities
16.3.1 Unlimited polymorphic entities
16.4 The associate construct
16.5 The select type construct
16.6 Type-bound procedures
271
271
271
273
273
274
275
276
279
xvi Contents
279
281
282
284
284
286
288
290
291
293
293
293
293
295
295
296
297
297
298
298
299
300
300
301
302
303
303
18 Miscellaneous enhancements
18.1 Introduction
18.2 Pointer intent
18.3 The volatile attribute
18.3.1 Volatile semantics
18.3.2 Volatile scoping
18.3.3 Volatile arguments
18.4 The import statement
18.5 Intrinsic modules
18.6 Access to the computing environment
18.6.1 Environment variables
18.6.2 Command arguments and the command line
18.7 Support for internationalization
18.7.1 Character sets
18.7.2 ASCII character set
18.7.3 ISO 10646 character set
305
305
305
305
306
307
308
308
310
311
311
312
312
313
313
314
Contents xv
314
315
316
316
317
318
318
318
319
19 Input/output enhancements
19.1 Introduction
19.2 Non-default derived-type input/output
19.3 Asynchronous input/output
19.4 The asynchronous attribute
19.5 Input and output of IEEE exceptional values
19.6 Stream access input/output
19.7 Recursive input/output
19.8 The flush statement
19.9 Comma after a P edit descriptor
19.10 'The iomsg= specifier
19.11 The round= specifier
19.12 The sign= specifier
19.13 Kind type parameters of integer specifiers
19.14 Intrinsic functions for 1/0 status testing
19.15 Some inquire statement enhancements
321
321
321
324
326
327
327
328
328
328
329
329
329
329
329
330
20 Other features
20.1 Introduction
20.2 Storage association
20.2.1 Storage units
20.2.2 The equivalence statement
20.2.3 The common block
20.2.4 The block data program unit
20.3 Shape and character length disagreement
20.4 The entry statement
20.5 The include line
20.6 The do while form of loop control
20.7 Double precision real
20.8 The dimension and parameter statements
20.9 Specific names of intrinsic procedures
331
331
331
331
332
334
336
337
339
340
341
341
342
343
A Intrinsic procedures
347
B Obsolescent features
353
353
353
354
354
355
355
356
357
357
358
359
359
C Pointer example
361
371
E Fortran terms
375
F Solutions to exercises
391
Index
405