- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We have a strange problem writing to a file. The setting is as follows. Fortran subroutine A1 (part of libA.lib) calls subroutine B1 (part of libB.lib) for opening a file (e.g. Test.txt') for write with unit number 21. Next A1 calls B2 (part of libB.lib) that contains the write statements. The resulting 'Test.txt' is empty and a file 'fort.21' is created with the content missing in 'Test.txt'.
This indicates that 'Test.txt' has been closed before write-statements are executed. However, this is not the case. We have verified that the file is open upon write.
A workaround for making it work is to include a CLOSE-statement and a OPEN with 'Old' in subroutine A1 between calls to B1 and B2.
We have checked that the correct system/runtime libs and dll's are loaded/used. Also the project settings seems OK.
We are using Visual Studio 2005 (8.0.50727.762 with SP.050727-7600) with Intel Fortran Compiler Integration (10.1.4159). Subroutine A1 is called from a C++ method. libA.lib and libB.lib are statically linked in a dll.
On our previous platform Visual Studio C++ 6.0 with Compaq Visual Fortran Standard Edition 6.6.B this worked fine.
Do anyone have an idea of what might be the problem?
This indicates that 'Test.txt' has been closed before write-statements are executed. However, this is not the case. We have verified that the file is open upon write.
A workaround for making it work is to include a CLOSE-statement and a OPEN with 'Old' in subroutine A1 between calls to B1 and B2.
We have checked that the correct system/runtime libs and dll's are loaded/used. Also the project settings seems OK.
We are using Visual Studio 2005 (8.0.50727.762 with SP.050727-7600) with Intel Fortran Compiler Integration (10.1.4159). Subroutine A1 is called from a C++ method. libA.lib and libB.lib are statically linked in a dll.
On our previous platform Visual Studio C++ 6.0 with Compaq Visual Fortran Standard Edition 6.6.B this worked fine.
Do anyone have an idea of what might be the problem?
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - norheim
We have a strange problem writing to a file. The setting is as follows. Fortran subroutine A1 (part of libA.lib) calls subroutine B1 (part of libB.lib) for opening a file (e.g. Test.txt') for write with unit number 21. Next A1 calls B2 (part of libB.lib) that contains the write statements. The resulting 'Test.txt' is empty and a file 'fort.21' is created with the content missing in 'Test.txt'.
This indicates that 'Test.txt' has been closed before write-statements are executed. However, this is not the case. We have verified that the file is open upon write.
A workaround for making it work is to include a CLOSE-statement and a OPEN with 'Old' in subroutine A1 between calls to B1 and B2.
We have checked that the correct system/runtime libs and dll's are loaded/used. Also the project settings seems OK.
We are using Visual Studio 2005 (8.0.50727.762 with SP.050727-7600) with Intel Fortran Compiler Integration (10.1.4159). Subroutine A1 is called from a C++ method. libA.lib and libB.lib are statically linked in a dll.
On our previous platform Visual Studio C++ 6.0 with Compaq Visual Fortran Standard Edition 6.6.B this worked fine.
Do anyone have an idea of what might be the problem?
This indicates that 'Test.txt' has been closed before write-statements are executed. However, this is not the case. We have verified that the file is open upon write.
A workaround for making it work is to include a CLOSE-statement and a OPEN with 'Old' in subroutine A1 between calls to B1 and B2.
We have checked that the correct system/runtime libs and dll's are loaded/used. Also the project settings seems OK.
We are using Visual Studio 2005 (8.0.50727.762 with SP.050727-7600) with Intel Fortran Compiler Integration (10.1.4159). Subroutine A1 is called from a C++ method. libA.lib and libB.lib are statically linked in a dll.
On our previous platform Visual Studio C++ 6.0 with Compaq Visual Fortran Standard Edition 6.6.B this worked fine.
Do anyone have an idea of what might be the problem?
If you copy the relevant code into a pure Fortran project do you still get the problem?
Use the inquire statement with the unit number to see if the file is opened.
logical :: od
inquire(unit=21, opened=od)
Put this statement in B1, before B2 and in B2.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You arepassinga filename string to a Fortran-compiled library LibASubroutinefroma C program?
You are then connecting stream 21 to the file with the name in the string using an OPEN statement?
You then call subroutine B in library Bto write to stream 21, but it appears not to know that stream 21 has been attached to a file, so it sends the data to FOR21 by default. I suggest ensuring that both library projectsare linked using IDENTICAL Fortran library settings and that the calling C program is also similarly linked.
You are then connecting stream 21 to the file with the name in the string using an OPEN statement?
You then call subroutine B in library Bto write to stream 21, but it appears not to know that stream 21 has been attached to a file, so it sends the data to FOR21 by default. I suggest ensuring that both library projectsare linked using IDENTICAL Fortran library settings and that the calling C program is also similarly linked.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - anthonyrichards
You arepassinga filename string to a Fortran-compiled library LibASubroutinefroma C program?
You are then connecting stream 21 to the file with the name in the string using an OPEN statement?
You then call subroutine B in library Bto write to stream 21, but it appears not to know that stream 21 has been attached to a file, so it sends the data to FOR21 by default. I suggest ensuring that both library projectsare linked using IDENTICAL Fortran library settings and that the calling C program is also similarly linked.
You are then connecting stream 21 to the file with the name in the string using an OPEN statement?
You then call subroutine B in library Bto write to stream 21, but it appears not to know that stream 21 has been attached to a file, so it sends the data to FOR21 by default. I suggest ensuring that both library projectsare linked using IDENTICAL Fortran library settings and that the calling C program is also similarly linked.
It seems like a mix of libifcoremd.lib/libifcoremdd.lib created the problem. The log of the Debug build showed that fortran calls (_for_open, _for_close, etc.) are loaded more consistently from libifcoremdd.lib when the CLOSE and OPEN statements were included in A1. Strange. We then decided to force the linker to use libifcoremd.lib by changing the Debug settings of the project creating the dll; added this lib to the "Additional Dependencies" and libifcoremdd.lib to the "Ignore Specific Library" Linker->Input options. The WRITE problem immediately disappeared.
We are rather sure that our problem is not relevant for a Release build and we have done some preliminar tests showing that this is correct. Of course, this should have been discovered earlier but better late than never. Any comments?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
libifcoremdd.lib is the Debug version of the library. It seems you had/have a mixture of debug and release libraries
Les

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page