3
3
## Formatted input/output
4
4
5
5
These examples illustrate various forms of I/O lists with some simple
6
- formats (see
7
- <a href =" #Edit_descriptors " class =" wikilink " title =" below " >below</a >):
6
+ formats (see [ below] ( edit_descriptors ) ):
8
7
9
8
``` f90
10
9
integer :: i
@@ -60,8 +59,7 @@ print form, q
60
59
```
61
60
62
61
or as an asterisk this is a type of I/O known as * list-directed* I/O
63
- (see
64
- <a href =" #List-directed_I/O " class =" wikilink " title =" below " >below</a >),
62
+ (see [ below] ( list-directed-i/o ) ,
65
63
in which the format is defined by the computer system:
66
64
67
65
``` f90
@@ -75,27 +73,26 @@ do not reference any unit number: this is referred to as terminal I/O.
75
73
Otherwise the form is:
76
74
77
75
``` f90
78
- read (UNIT =4, FMT ="(f10.3)") q
79
- read (UNIT =newunit, FMT ="(f10.3)") q
80
- read (UNIT =4 * i + j, FMT ="(f10.3)") a
76
+ read (unit =4, fmt ="(f10.3)") q
77
+ read (unit =newunit, fmt ="(f10.3)") q
78
+ read (unit =4 * i + j, fmt ="(f10.3)") a
81
79
```
82
80
83
81
where ` unit= ` is optional. The value may be any nonnegative integer
84
- allowed by the system for this purpose (but ` 0 ` , ` 5 ` and ` 6 ` often denote the
85
- error, keyboard and terminal, respectively).
82
+ allowed by the system for this purpose (but ` 0 ` , ` 5 ` and ` 6 ` often
83
+ denote the error, keyboard and terminal, respectively).
86
84
87
85
An asterisk is a variantagain from the keyboard:
88
86
89
87
``` f90
90
- read (UNIT =*, FMT ="(f10.3)") q
88
+ read (unit =*, fmt ="(f10.3)") q
91
89
```
92
90
93
91
A read with a unit specifier allows
94
- <a href="exception_handling" class="wikilink"
95
- title="exception handling">exception handling</a >:
92
+ [ exception handling] ( https://en.wikipedia.org/wiki/Exception_handling ) :
96
93
97
94
``` f90
98
- read (UNIT=NUNIT, FMT ="(3f10.3)", IOSTAT =ios) a, b, c
95
+ read (unit=nunit, fmt ="(3f10.3)", iostat =ios) a, b, c
99
96
if (ios == 0) then
100
97
! Successful read - continue execution.
101
98
:
@@ -105,11 +102,11 @@ else
105
102
end if
106
103
```
107
104
108
- There a second type of formatted output statement, the ` write `
105
+ There is a second type of formatted output statement, the ` write `
109
106
statement:
110
107
111
108
``` f90
112
- write (UNIT =nout, FMT ="(10f10.3)", IOSTAT =ios) a
109
+ write (unit =nout, fmt ="(10f10.3)", iostat =ios) a
113
110
```
114
111
115
112
## Internal files
@@ -121,11 +118,12 @@ itself.
121
118
``` f90
122
119
integer, dimension(30) :: ival
123
120
integer :: key
124
- character(LEN=30) :: buffer
125
- character(LEN=6), dimension(3), parameter :: form = (/"(30i1)", "(15i2)", "(10i3)"/)
121
+ character(len=30) :: buffer
122
+ character(len=6), dimension(3), parameter :: form = (/"(30i1)", &
123
+ "(15i2)", "(10i3)"/)
126
124
127
- read (UNIT =*, FMT ="(a30,i1)") buffer, key
128
- read (UNIT =buffer, FMT =form(key)) ival(1:30 / key)
125
+ read (unit =*, fmt ="(a30,i1)") buffer, key
126
+ read (unit =buffer, fmt =form(key)) ival(1:30 / key)
129
127
```
130
128
131
129
If an internal file is a scalar, it has a single record whose length is
@@ -140,11 +138,11 @@ An example using a `write` statement is
140
138
``` f90
141
139
integer :: day
142
140
real :: cash
143
- character(LEN =50) :: line
141
+ character(len =50) :: line
144
142
:
145
143
! write into line
146
- write (UNIT =line, FMT ="(a, i2, a, f8.2, a)") "Takings for day ", day, &
147
- & " are ", cash, " dollars"
144
+ write (unit =line, fmt ="(a, i2, a, f8.2, a)") "Takings for day ", day, &
145
+ " are ", cash, " dollars"
148
146
```
149
147
150
148
that might write
@@ -162,8 +160,8 @@ integer :: i
162
160
real :: a
163
161
complex, dimension(2) :: field
164
162
logical :: flag
165
- character(LEN =12) :: title
166
- character(LEN =4) :: word
163
+ character(len =12) :: title
164
+ character(len =4) :: word
167
165
:
168
166
read *,i, a, field, flag, title, word
169
167
```
@@ -191,10 +189,10 @@ non-advancing I/O statement performs no such repositioning and may
191
189
therefore leave the file positioned within a record.
192
190
193
191
``` f90
194
- character(LEN =3) :: key
192
+ character(len =3) :: key
195
193
integer :: u, s, ios
196
194
:
197
- read (UNIT =u, FMT ="(a3)", ADVANCE ="no", SIZE =s, IOSTAT =ios) key
195
+ read (unit =u, fmt ="(a3)", advance ="no", size =s, iostat =ios) key
198
196
if (ios == 0) then
199
197
:
200
198
else
@@ -212,8 +210,8 @@ next character position on the screen without an intervening line-feed,
212
210
we can write
213
211
214
212
``` f90
215
- write (UNIT =*, FMT ="(a)", ADVANCE ="no") "enter next prime number:"
216
- read (UNIT =*, FMT ="(i10)") prime_number
213
+ write (unit =*, fmt ="(a)", advance ="no") "enter next prime number:"
214
+ read (unit =*, fmt ="(i10)") prime_number
217
215
```
218
216
219
217
Non-advancing I/O is for external files, and is not available for
@@ -225,8 +223,8 @@ It is possible to specify that an edit descriptor be repeated a
225
223
specified number of times, using a * repeat count* : ` 10f12.3 `
226
224
227
225
The slash edit descriptor (see
228
- <a href="#Control_edit_descriptors" class="wikilink"
229
- title="below">below</ a >) may have a repeat count, and a repeat count can
226
+ [ below ] ( control-edit-descriptors ) )
227
+ may have a repeat count, and a repeat count can
230
228
also apply to a group of edit descriptors, enclosed in parentheses, with
231
229
nesting:
232
230
@@ -258,9 +256,9 @@ computer or another computer using the same internal number
258
256
representations:
259
257
260
258
``` f90
261
- open (UNIT =4, FILE ='test', FORM ='unformatted')
262
- read (UNIT =4) q
263
- write (UNIT =nout, IOSTAT =ios) a ! no fmt=
259
+ open (unit =4, file ='test', form ='unformatted')
260
+ read (unit =4) q
261
+ write (unit =nout, iostat =ios) a ! no fmt=
264
262
```
265
263
266
264
## Direct-access files
@@ -276,21 +274,22 @@ real, dimension(length) :: a
276
274
real, dimension(length + 1:2*length) :: b
277
275
integer :: i, rec_length
278
276
:
279
- inquire (IOLENGTH=rec_length) a
280
- open (UNIT=nunit, ACCESS="direct", RECL=rec_length, STATUS="scratch", ACTION="readwrite")
277
+ inquire (iolength=rec_length) a
278
+ open (unit=nunit, access="direct", recl=rec_length, status="scratch", &
279
+ action="readwrite")
281
280
:
282
281
! Write array b to direct-access file in record 14
283
- write (UNIT =nunit, REC =14) b
282
+ write (unit =nunit, rec =14) b
284
283
:
285
284
! Read the array back into array a
286
- read (UNIT =nunit, REC =14) a
285
+ read (unit =nunit, rec =14) a
287
286
288
287
do i = 1, length / 2
289
288
a(i) = i
290
289
end do
291
290
292
291
! Replace modified record
293
- write (UNIT =nunit, REC =14) a
292
+ write (unit =nunit, rec =14) a
294
293
```
295
294
296
295
The file must be an external file and list-directed formatting and
0 commit comments