I had a ticket open about not getting a warning with several compilers a while back as well as some issues with INQUIRE. Trying it now with gfortran you get an error now with “open(newunit=unum)” which is good, and I only had to comment out PRESENT= on the INQUIRE and the only output that looked wrong was for EXIST when the file did not exist; which is a dramatic improvment. Usually testing INQUIRE generates at least one bug report with each compiler every time I drag out this test procedure.
program main
! gfortran -std=f2018 -Wall -Wextra -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace
use,intrinsic :: iso_fortran_env, only : compiler_version
use,intrinsic :: iso_fortran_env, only : compiler_options
integer :: iostat
integer :: tapen
integer,parameter :: lun=40
print '(4a)', &
'This file was compiled by ', compiler_version(), &
' using the options ', compiler_options()
call print_inquire(lun_in=LUN)
write(40,*)'something new'
call print_inquire(lun_in=LUN)
!open(newunit=tapen) ! Yeah. gfortran now generates an error
tapen=44
open(unit=tapen)
call print_inquire(lun_in=tapen)
!close(unit=LUN,status='delete',iostat=iostat)
!close(unit=tapen,status='delete',iostat=iostat)
contains
subroutine print_inquire(lun_in,namein_in)
integer,intent(in),optional :: lun_in
character(len=*),intent(in),optional :: namein_in
integer :: iostat
character(len=256) :: message
character(len=:),allocatable :: namein
integer :: lun
character(len=20) :: access ; namelist/inquire/access
character(len=20) :: asynchronous ; namelist/inquire/asynchronous
character(len=20) :: blank ; namelist/inquire/blank
character(len=20) :: decimal ; namelist/inquire/decimal
character(len=20) :: delim ; namelist/inquire/delim
character(len=20) :: direct ; namelist/inquire/direct
character(len=20) :: encoding ; namelist/inquire/encoding
logical :: exist ; namelist/inquire/exist
character(len=20) :: form ; namelist/inquire/form
character(len=20) :: formatted ; namelist/inquire/formatted
character(len=20) :: unformatted ; namelist/inquire/unformatted
integer :: id ; namelist/inquire/id
character(len=20) :: name ; namelist/inquire/name
logical :: named ; namelist/inquire/named
integer :: nextrec ; namelist/inquire/nextrec
integer :: number ; namelist/inquire/number
logical :: opened ; namelist/inquire/opened
character(len=20) :: pad ; namelist/inquire/pad
logical :: pending ; namelist/inquire/pending
integer :: pos ; namelist/inquire/pos
character(len=20) :: position ; namelist/inquire/position
character(len=20) :: action ; namelist/inquire/action
character(len=20) :: read ; namelist/inquire/read
character(len=20) :: readwrite ; namelist/inquire/readwrite
character(len=20) :: write ; namelist/inquire/write
integer :: recl ; namelist/inquire/recl
character(len=20) :: round ; namelist/inquire/round
character(len=20) :: sequential ; namelist/inquire/sequential
character(len=20) :: sign ; namelist/inquire/sign
integer :: size ; namelist/inquire/size
character(len=20) :: stream ; namelist/inquire/stream
if(present(namein_in))then
namein=namein_in
else
namein=repeat(' ',1024)
endif
lun=merge(lun_in,-1,present(lun_in))
name=''
if(namein == ''.and.lun /= -1)then
write(*,*)'*print_inquire* checking unit',lun
inquire(unit=lun, &
& recl=recl,nextrec=nextrec,pos=pos,size=size, &
& position=position, &
& name=name, &
& form=form,formatted=formatted,unformatted=unformatted, &
& access=access,sequential=sequential,direct=direct,stream=stream, &
& action=action,read=read,write=write,readwrite=readwrite, &
& sign=sign, &
& round=round, &
& blank=blank,decimal=decimal,delim=delim,encoding=encoding,pad=pad, &
& named=named, &
& opened=opened, &
& exist=exist, &
& number=number, &
! & pending=pending, &
& asynchronous=asynchronous, &
& iostat=iostat,err=999,iomsg=message)
elseif(namein /= '')then
write(*,*)'*print_inquire* checking file',namein
inquire(file=namein, &
& recl=recl,nextrec=nextrec,pos=pos,size=size, &
& position=position, &
& name=name, &
& form=form,formatted=formatted,unformatted=unformatted, &
& access=access,sequential=sequential,direct=direct,stream=stream, &
& action=action,read=read,write=write,readwrite=readwrite, &
& sign=sign, &
& round=round, &
& blank=blank,decimal=decimal,delim=delim,encoding=encoding,pad=pad, &
& named=named,opened=opened,exist=exist,number=number, &
& pending=pending,asynchronous=asynchronous, &
& iostat=iostat,err=999,iomsg=message)
if(name == '')name=namein
else
write(*,*)'*print_inquire* must specify either filename or unit number'
endif
write(*,nml=inquire,delim='none')
return
999 continue
write(*,*)'*print_inquire* bad inquire'
write(*,*) '*print_inquire* inquire call failed,iostat=',iostat,'message=',message
end subroutine print_inquire
end program main