33## Formatted input/output
44
55These 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 ) ):
87
98``` f90
109integer :: i
@@ -60,8 +59,7 @@ print form, q
6059```
6160
6261or 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 ) ,
6563in which the format is defined by the computer system:
6664
6765``` f90
@@ -75,27 +73,26 @@ do not reference any unit number: this is referred to as terminal I/O.
7573Otherwise the form is:
7674
7775``` 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
8179```
8280
8381where ` 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).
8684
8785An asterisk is a variantagain from the keyboard:
8886
8987``` f90
90- read (UNIT =*, FMT ="(f10.3)") q
88+ read (unit =*, fmt ="(f10.3)") q
9189```
9290
9391A 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 ) :
9693
9794``` 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
9996if (ios == 0) then
10097 ! Successful read - continue execution.
10198 :
@@ -105,11 +102,11 @@ else
105102end if
106103```
107104
108- There a second type of formatted output statement, the ` write `
105+ There is a second type of formatted output statement, the ` write `
109106statement:
110107
111108``` f90
112- write (UNIT =nout, FMT ="(10f10.3)", IOSTAT =ios) a
109+ write (unit =nout, fmt ="(10f10.3)", iostat =ios) a
113110```
114111
115112## Internal files
@@ -121,11 +118,12 @@ itself.
121118``` f90
122119integer, dimension(30) :: ival
123120integer :: 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)"/)
126124
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)
129127```
130128
131129If 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
140138``` f90
141139integer :: day
142140real :: cash
143- character(LEN =50) :: line
141+ character(len =50) :: line
144142:
145143! 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"
148146```
149147
150148that might write
@@ -162,8 +160,8 @@ integer :: i
162160real :: a
163161complex, dimension(2) :: field
164162logical :: flag
165- character(LEN =12) :: title
166- character(LEN =4) :: word
163+ character(len =12) :: title
164+ character(len =4) :: word
167165:
168166read *,i, a, field, flag, title, word
169167```
@@ -191,10 +189,10 @@ non-advancing I/O statement performs no such repositioning and may
191189therefore leave the file positioned within a record.
192190
193191``` f90
194- character(LEN =3) :: key
192+ character(len =3) :: key
195193integer :: u, s, ios
196194:
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
198196if (ios == 0) then
199197 :
200198else
@@ -212,8 +210,8 @@ next character position on the screen without an intervening line-feed,
212210we can write
213211
214212``` 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
217215```
218216
219217Non-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
225223specified number of times, using a * repeat count* : ` 10f12.3 `
226224
227225The 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
230228also apply to a group of edit descriptors, enclosed in parentheses, with
231229nesting:
232230
@@ -258,9 +256,9 @@ computer or another computer using the same internal number
258256representations:
259257
260258``` 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=
264262```
265263
266264## Direct-access files
@@ -276,21 +274,22 @@ real, dimension(length) :: a
276274real, dimension(length + 1:2*length) :: b
277275integer :: i, rec_length
278276:
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")
281280:
282281! Write array b to direct-access file in record 14
283- write (UNIT =nunit, REC =14) b
282+ write (unit =nunit, rec =14) b
284283:
285284! Read the array back into array a
286- read (UNIT =nunit, REC =14) a
285+ read (unit =nunit, rec =14) a
287286
288287do i = 1, length / 2
289288 a(i) = i
290289end do
291290
292291! Replace modified record
293- write (UNIT =nunit, REC =14) a
292+ write (unit =nunit, rec =14) a
294293```
295294
296295The file must be an external file and list-directed formatting and
0 commit comments