I have two old fortran programs that talk to each other using the text files. One of these was recompiled as a DLL and ever since then (actually since switching to the Intel compiler from the discontinued DIGITIAL Visual Fortran) and error would occasionally (not always) occurs, where one or the other of the two programs would have issues opening a text file written by the other one.
The resulting error is something like (sorry, had too translate from German): ====forrtl: The process with a File with an opened domain, which is assigned to a user, is not possible/allowed
Followed by: forrtl: severe (38): error during write, unit 88, file....
The error happens occasionally, even with identical instructions, the program would run couple of times ok, have an error on one or two runs and then run ok again.
I was looking through the code and everything seems legit. I do have some concerns that the file initialization and actual writing to the file happen at different subroutines. Also the file being written too is often being reused from the previous iteration. The program1 and 2 can iterate between each other up to 50 times writing/overwriting back and forth into the same file, but each program closes the file when done. E.g.
Subroutine Init_File ...code Open(10, File = FileName, Status ='UNKNOWN') ...code End Subbroutine Subroutine write_file Write(10,*) InputString1 ...code End Subroutine LOGICAL FUNCTION Program_Main ...code Close(10) END FUNCTION
I have also been trying to get the two programs to talk to each other without the text files in-between, and it works fine when I send over the needed data from the DLL using a derived type. But I was also trying to make the change as minimally intrusive as possible (because the DLL is also used by other programs). Hence I tried to send the data over using a common block:
! Program 1 REAL(8) FUNCTION Program1(Infile, Outfile) !DEC$ ATTRIBUTES DLLEXPORT :: Program1, /X/ USE MODULE_with_custom_type COMMON /X/ DataExchange Type(CustomType) :: DataExchange ...code Return END FUNCTION ! Program 2 MODULE DLL_Interface USE MODULE_with_custom_type INTERFACE REAL(8) FUNCTION Program1(Infile, Outfile) !DEC$ ATTRIBUTES DLLIMPORT :: Program1, /X/ IMPORT :: CustomType CHARACTER(200) Infile, Outfile Common /X/ DataExchage Type(CustomModule):: DataExchange END INTERFACE END MODULE ! in main program USE DLL_Interface DUMMY = Program1(Infile, Outfile) ...
The question is how to I make the common block visible to the main program? I tried declaring without the interface: it works but eventually causes call stack corruption.