Skip to content

Commit 670cb04

Browse files
committed
fix the arguments of inquire routine
The Fortran standard says "The value of a file-unit-number shall identify a valid unit.". Once the newunit value generated by open(newunit=..) is not connected to a unit, it is not valid. When the unit number is not valid, the compiler can do anything from return .TRUE., .FALSE., raise an error. Therefore, I added the iostat argument for the inquire routine.
1 parent b251ced commit 670cb04

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/stdlib_logger.f90

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ subroutine add_log_unit( self, unit, stat )
308308
integer :: lun
309309
character(12) :: specifier
310310
logical :: question
311+
integer :: istat
312+
character(len=80) :: msgtxt
311313

312314
call validate_unit()
313315
if ( present(stat) ) then
@@ -350,7 +352,8 @@ subroutine validate_unit()
350352
end if
351353

352354
! Check that unit is opened
353-
inquire( unit, opened=question )
355+
inquire( unit, opened=question, iostat=istat, iomsg=msgtxt)
356+
if(istat/=0) question=.false.
354357
if ( .not. question ) then
355358
if ( present(stat) ) then
356359
stat = unopened_in_error

src/tests/logger/test_stdlib_logger.f90

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,8 @@ end subroutine test_adding_log_files
417417
subroutine test_removing_log_units()
418418

419419
logical :: opened
420+
integer :: istat
421+
character(len=80) :: msgtxt
420422

421423
print *
422424
print *, 'running test_removing_log_units'
@@ -462,7 +464,8 @@ subroutine test_removing_log_units()
462464

463465
end if
464466

465-
inquire( unit4, opened=opened )
467+
inquire( unit4, opened=opened ,iostat=istat,iomsg=msgtxt)
468+
if(istat/=0) opened=.false.
466469
if ( opened ) then
467470
error stop 'UNIT4 is opened contrary to expectations.'
468471

0 commit comments

Comments
 (0)