Bug 31053 - print file name when file cannot be opened for writing
Summary: print file name when file cannot be opened for writing
Status: RESOLVED DUPLICATE of bug 30005
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-03-05 22:28 UTC by Vivek Rao
Modified: 2007-03-07 14:24 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.0
Known to fail: 4.2.0
Last reconfirmed: 2007-03-06 19:32:57


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vivek Rao 2007-03-05 22:28:37 UTC
On Windows, if a file is open in Excel, one cannot write to it in a Fortran program. So if "junk.csv" is opened in Excel and I compile and run the code

program xopen
! check what happens when program tries to open file already open
implicit none
integer, parameter :: iu = 20
character (len=*), parameter :: xfile="junk.csv"
open (unit=iu,file=xfile,action="write",status="replace")
end program xopen

gfortran
Target: i386-pc-mingw32
Configured with: ../trunk/configure --prefix=/mingw --enable-languages=c,fortran --with-gmp=/home/coudert/local --disable-nls --with-ld=/mingw/bin/ld --with-as=/mingw/bin/as --disable-werror --enable-bootstrap --enable-threads --host=i386-pc-mingw32 --disable-shared --enable-libgomp
Thread model: win32
gcc version 4.3.0 20061021 (experimental)

says

At line 6 of file xopen_error.f90
Fortran runtime error: Permission denied

I'd like it to say that file "junk.csv" could not be opened, to make debugging easier for the user. For example, Intel Visual Fortran says

forrtl: The process cannot access the file because it is being used by another process.
forrtl: severe (30): open failure, unit 20, file U:\vrao\fortran\junk.csv
Image              PC        Routine            Line        Source             
ifort_xopen_error  0044382E  Unknown               Unknown  Unknown
ifort_xopen_error  00440AEC  Unknown               Unknown  Unknown
ifort_xopen_error  00405DFA  Unknown               Unknown  Unknown
ifort_xopen_error  00405A17  Unknown               Unknown  Unknown
ifort_xopen_error  00401C81  Unknown               Unknown  Unknown
ifort_xopen_error  0040106F  _MAIN__                     6  xopen_error.f90
ifort_xopen_error  00449970  Unknown               Unknown  Unknown
ifort_xopen_error  0042EBB8  Unknown               Unknown  Unknown
kernel32.dll       7C816FD7  Unknown               Unknown  Unknown
Comment 1 Thomas Koenig 2007-03-06 19:32:57 UTC
Yes, this would be useful.

Confirmed.
Comment 2 Tobias Burnus 2007-03-07 07:17:54 UTC
> gcc version 4.3.0 20061021 (experimental)

I believe this has been fixed already by PR30005 since December 5.

At least my gfortran prints:

At line 6 of file foo.f90
Fortran runtime error: Permission denied trying to open file 'junk.csv'
Comment 3 Thomas Koenig 2007-03-07 14:24:06 UTC
(In reply to comment #2)

> I believe this has been fixed already by PR30005 since December 5.

Correct.  The fix isn't in 4.2 though (which is what I tried :-)

Closing as a duplicate of 30005.


*** This bug has been marked as a duplicate of 30005 ***