Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28854 Discussions

Problem with iostat in read statement in Intel® Fortran Compiler Classic 2021.11.0 [Intel(R) 64]

ATr
Novice
975 Views

Can anyone explain me why iostat in read statement fails when using newest Intel® Fortran Compiler Classic 2021.11.0 [Intel(R) 64] ?

 

in all older Intel  ifort compilers it was enough to put iostat=.... only and

any kind of the error did not stop the execution

 now you have to add err=.., end=... and then it seems to work

isn't it a bug in compiler ?

if not why it was working for past 20 years without any problem ?

 

regards

AT

 

here is a MWE

 

 

subroutine trace_bug
implicit none
character*128 :: tmp, msg
integer*4 :: err_code, ia
logical*4 :: done

! this works fine

tmp = '123456'
READ (tmp,'(i6)') ia


tmp = 'aaaaa'
! this fails
READ (tmp,'(i5)',iostat=err_code) ia
! this works
READ (tmp,'(i5)',iostat=err_code,err=999,end=999) ia
if ( err_code.ne.0) then
continue
end if
999 continue

! similar problem
open (1,file='testfile.txt')
write(1,*) 'aaaa'
close (1)

! iostat

open (1,file='testfile.txt')
done = .false.
do while (.not.done)
! this fails
read(1,*,iostat=err_code) tmp
! this works
read(1,*,iostat=err_code,err=9999,end=9999) tmp
if ( err_code.ne.0) then
return
end if
end do
9999 continue

end

0 Kudos
2 Replies
Steve_Lionel
Honored Contributor III
955 Views

Your test program is missing a main. I don't get any error with this - what are you seeing?

D:\Projects\Console9>type console9.f90
subroutine trace_bug
implicit none
character*128 :: tmp, msg
integer*4 :: err_code, ia
logical*4 :: done

! this works fine

tmp = '123456'
READ (tmp,'(i6)') ia


tmp = 'aaaaa'
! this fails
READ (tmp,'(i5)',iostat=err_code) ia
! this works
READ (tmp,'(i5)',iostat=err_code,err=999,end=999) ia
if ( err_code.ne.0) then
continue
end if
999 continue

! similar problem
open (1,file='testfile.txt')
write(1,*) 'aaaa'
close (1)

! iostat

open (1,file='testfile.txt')
done = .false.
do while (.not.done)
! this fails
read(1,*,iostat=err_code) tmp
! this works
read(1,*,iostat=err_code,err=9999,end=9999) tmp
if ( err_code.ne.0) then
return
end if
end do
9999 continue

    end
    program test
    call trace_bug
    end
D:\Projects\Console9>ifort console9.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.11.1 Build 20231117_000000
Copyright (C) 1985-2023 Intel Corporation.  All rights reserved.

ifort: remark #10448: Intel(R) Fortran Compiler Classic (ifort) is now deprecated and will be discontinued late 2024. Intel recommends that customers transition now to using the LLVM-based Intel(R) Fortran Compiler (ifx) for continued Windows* and Linux* support, new language support, new language features, and optimizations. Use '/Qdiag-disable:10448' to disable this message.
Microsoft (R) Incremental Linker Version 14.38.33135.0
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:console9.exe
-subsystem:console
console9.obj

D:\Projects\Console9>console9.exe

D:\Projects\Console9>
0 Kudos
ATr
Novice
914 Views

Thanks Steve for prompt answer; I was not precise when describing this case as this routine was placed in a larger fortran project compiled to DLL format and certain functions from this DLL were called from another EXE generated with C++ code;

but..... the exe was built under VSC++ 2019 while the dll was built in newest environment (VS 2022 and recent Intel IFORT compiler;) when both the exe and the dll are built using compatible tools everything works fine;

thanks again

 

AT

0 Kudos
Reply