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

NEWUNIT= and CLOSE

John4
Valued Contributor I
1,726 Views

Hi,

When compiling and running the following code with the Intel Fortran Compiler, I get an error after entering the same (negative) integer value provided by NEWUNIT=, but gfortran runs the code without problem.

implicit none

integer :: someunit = 1492, ios

open (NEWUNIT = someunit, FILE = 'someting', IOSTAT = ios)
print *, someunit
close (someunit, STATUS = 'DELETE')

read *, someunit
close (someunit)

stop 'Program finished properly'

end

 

If I recall correctly, the standard says that the CLOSE statement shouldn't fail when trying to close a unit that's not connected... but the standard also says that the number for the unit must not be a negative one.  So, is there a conflict in the standard and both compilers are rignt? Was it an oversight?

The output when compiling and running the code is shown below:

~$ ll `which ifort`
-rwxr-xr-x 1 root root 3955056 Jan 24 07:03 /opt/intel/composer_xe_2013_sp1.2.144/bin/intel64/ifort*
~$ ifort test_close.f90
~$ ./a.out
-129
-129
forrtl: severe (32): invalid logical unit number, unit -129, file unknown
Image PC Routine Line Source
a.out 00000000004024D2 Unknown Unknown Unknown
a.out 0000000000402356 Unknown Unknown Unknown
libc.so.6 00007F07674A3B45 Unknown Unknown Unknown
a.out 0000000000402249 Unknown Unknown Unknown
~$ ll `which gfortran`
lrwxrwxrwx 1 root root 12 Jan 17 04:19 /usr/bin/gfortran -> gfortran-4.8*
~$ gfortran test_close.f90
~$ ./a.out
-10
-10
STOP Program finished properly


 



 

0 Kudos
1 Solution
Steven_L_Intel1
Employee
1,726 Views

It's a bug - I'll let the developers know. Issue ID is DPD200255119.

View solution in original post

0 Kudos
4 Replies
zuch
Beginner
1,726 Views

I am not sure about F03 standard but the intel documentation states 

"If a CLOSE statement is specified for a unit that is not open, it has no effect." 

consider using

close (someunit, IOSTAT = ios)

 

 

 

 

0 Kudos
John4
Valued Contributor I
1,727 Views

My question wasn't really about how to circumvent the error (since I know IOSTAT= can be used with any input/output statement), but rather if there was a bug in either compiler ---i.e., an issue or conflict in the interpretation of the standard.

--

John.

 

0 Kudos
Steven_L_Intel1
Employee
1,727 Views

It's a bug - I'll let the developers know. Issue ID is DPD200255119.

0 Kudos
Steven_L_Intel1
Employee
1,727 Views

Fixed for a release later this year.

0 Kudos
Reply