Skip to content

Commit 8b06c6b

Browse files
committed
use select instead of if for clarity/brevity
1 parent c789d1f commit 8b06c6b

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

src/stdlib_experimental_io.f90

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -300,51 +300,53 @@ integer function open(filename, mode) result(u)
300300

301301
mode_ = parse_mode(optval(mode, ""))
302302

303-
if (mode_(1:2) == 'r ') then
303+
select case (mode_(1:2))
304+
case('r')
304305
action_='read'
305306
position_='asis'
306307
status_='old'
307-
else if (mode_(1:2) == 'w ') then
308+
case('w')
308309
action_='write'
309310
position_='asis'
310311
status_='replace'
311-
else if (mode_(1:2) == 'a ') then
312+
case('a')
312313
action_='write'
313314
position_='append'
314315
status_='old'
315-
else if (mode_(1:2) == 'x ') then
316+
case('x')
316317
action_='write'
317318
position_='asis'
318319
status_='new'
319-
else if (mode_(1:2) == 'r+') then
320+
case('r+')
320321
action_='readwrite'
321322
position_='asis'
322323
status_='old'
323-
else if (mode_(1:2) == 'w+') then
324+
case('w+')
324325
action_='readwrite'
325326
position_='asis'
326327
status_='replace'
327-
else if (mode_(1:2) == 'a+') then
328+
case('a+')
328329
action_='readwrite'
329330
position_='append'
330331
status_='old'
331-
else if (mode_(1:2) == 'x+') then
332+
case('x+')
332333
action_='readwrite'
333334
position_='asis'
334335
status_='new'
335-
else
336+
case default
336337
call error_stop("Unsupported mode: "//mode_(1:2))
337-
end if
338+
end select
338339

339-
if (mode_(3:3) == 't') then
340+
select case (mode_(3:3))
341+
case('t')
340342
access_='sequential'
341343
form_='formatted'
342-
else if (mode_(3:3) == 'b' .or. mode_(3:3) == 's') then
344+
case('b', 's')
343345
access_='stream'
344346
form_='unformatted'
345-
else
347+
case default
346348
call error_stop("Unsupported mode: "//mode_(3:3))
347-
endif
349+
end select
348350

349351
open(newunit=u, file=filename, &
350352
action = action_, position = position_, status = status_, &
@@ -365,21 +367,18 @@ integer function open(filename, mode) result(u)
365367
a=trim(adjustl(mode))
366368

367369
do i=1,len(a)
368-
if (a(i:i) == 'r' &
369-
.or. a(i:i) == 'w' &
370-
.or. a(i:i) == 'a' &
371-
.or. a(i:i) == 'x' &
372-
) then
370+
select case (a(i:i))
371+
case('r', 'w', 'a', 'x')
373372
mode_(1:1) = a(i:i)
374-
else if (a(i:i) == '+') then
373+
case('+')
375374
mode_(2:2) = a(i:i)
376-
else if (a(i:i) == 't' .or. a(i:i) == 'b') then
375+
case('t', 'b')
377376
mode_(3:3) = a(i:i)
378-
else if (a(i:i) == ' ') then
379-
cycle
380-
else
377+
case(' ')
378+
cycle
379+
case default
381380
call error_stop("Wrong character: "//a(i:i))
382-
endif
381+
end select
383382
end do
384383

385384
end function

0 commit comments

Comments
 (0)