@@ -300,51 +300,53 @@ integer function open(filename, mode) result(u)
300
300
301
301
mode_ = parse_mode(optval(mode, " " ))
302
302
303
- if (mode_(1 :2 ) == ' r ' ) then
303
+ select case (mode_(1 :2 ))
304
+ case (' r' )
304
305
action_= ' read'
305
306
position_= ' asis'
306
307
status_= ' old'
307
- else if (mode_( 1 : 2 ) == ' w ' ) then
308
+ case ( ' w ' )
308
309
action_= ' write'
309
310
position_= ' asis'
310
311
status_= ' replace'
311
- else if (mode_( 1 : 2 ) == ' a ' ) then
312
+ case ( ' a ' )
312
313
action_= ' write'
313
314
position_= ' append'
314
315
status_= ' old'
315
- else if (mode_( 1 : 2 ) == ' x ' ) then
316
+ case ( ' x ' )
316
317
action_= ' write'
317
318
position_= ' asis'
318
319
status_= ' new'
319
- else if (mode_( 1 : 2 ) == ' r+' ) then
320
+ case ( ' r+' )
320
321
action_= ' readwrite'
321
322
position_= ' asis'
322
323
status_= ' old'
323
- else if (mode_( 1 : 2 ) == ' w+' ) then
324
+ case ( ' w+' )
324
325
action_= ' readwrite'
325
326
position_= ' asis'
326
327
status_= ' replace'
327
- else if (mode_( 1 : 2 ) == ' a+' ) then
328
+ case ( ' a+' )
328
329
action_= ' readwrite'
329
330
position_= ' append'
330
331
status_= ' old'
331
- else if (mode_( 1 : 2 ) == ' x+' ) then
332
+ case ( ' x+' )
332
333
action_= ' readwrite'
333
334
position_= ' asis'
334
335
status_= ' new'
335
- else
336
+ case default
336
337
call error_stop(" Unsupported mode: " // mode_(1 :2 ))
337
- end if
338
+ end select
338
339
339
- if (mode_(3 :3 ) == ' t' ) then
340
+ select case (mode_(3 :3 ))
341
+ case (' t' )
340
342
access_= ' sequential'
341
343
form_= ' formatted'
342
- else if (mode_( 3 : 3 ) == ' b' .or. mode_( 3 : 3 ) == ' s' ) then
344
+ case ( ' b' , ' s' )
343
345
access_= ' stream'
344
346
form_= ' unformatted'
345
- else
347
+ case default
346
348
call error_stop(" Unsupported mode: " // mode_(3 :3 ))
347
- endif
349
+ end select
348
350
349
351
open (newunit= u, file= filename, &
350
352
action = action_, position = position_, status = status_, &
@@ -365,21 +367,18 @@ integer function open(filename, mode) result(u)
365
367
a= trim (adjustl (mode))
366
368
367
369
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' )
373
372
mode_(1 :1 ) = a(i:i)
374
- else if (a(i:i) == ' +' ) then
373
+ case ( ' +' )
375
374
mode_(2 :2 ) = a(i:i)
376
- else if (a(i:i) == ' t' .or. a(i:i) == ' b' ) then
375
+ case ( ' t' , ' b' )
377
376
mode_(3 :3 ) = a(i:i)
378
- else if (a(i:i) == ' ' ) then
379
- cycle
380
- else
377
+ case ( ' ' )
378
+ cycle
379
+ case default
381
380
call error_stop(" Wrong character: " // a(i:i))
382
- endif
381
+ end select
383
382
end do
384
383
385
384
end function
0 commit comments