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

WRITE to an existing file that another program has linked to - possible?

davidspurr
Beginner
504 Views
One of my programs outputs a file in .csv format. Each run completely re-writes the file (basic structure of the file remains constant). The open statement is of the form:

OPEN (fileNum, file = 'Hazard.csv', iostat=ios)

While debugging, I want to view the contents of 'Hazard.csv' in a GIS program as the easiest way to quickly assess whether the output is correct.

In the GIS program (Manifold) I have a Table linked to 'Hazard.csv'. The Table in the GIS program is linked to a Drawing layer displayed in a Map. An alternative would be to have the Drawing directly linked to 'Hazard.csv', but 'Hazard.csv' does not contain any Latitude & Longitude data. (FWIW, I find the GIS program a very powerful debugging aid in many situations).

Ideally, I would like to leave the GIS program open, with the link to 'Hazard.csv' live, so that after running my Fortran program, I could go straight to my GIS program & view what changes had occurred. Since there may be 'many' iterations during the debugging process, it would help if I can run the Fortran program while link from the GIS program is still open.

However, if I attempt this I get an error message indicating that the Fortran program cannot write to 'Hazard.csv' (same as the message I get if I have the file open in Excel).

Is there anyway around this? ie. anyway to force a write (overwrite) of a file that is open or linked to by another program?

Part of the objective with linked files in the GIS program is to allow external programs to modify the data externally & have the changes show up in the GIS program.

0 Kudos
4 Replies
DavidWhite
Valued Contributor II
504 Views

David,

I suspect that both processes are attempting to open the file for exclusive access. You could try SHARE='DENYNONE' in your open statement. Obviously, this leaves you vulnerable to corrupting the file, as both programs could write to the file at any time. If the GIS program has already opened the file exclusively, you may still not be able to open the file from your program.

Regards, David

0 Kudos
davidspurr
Beginner
504 Views
Thanks, David

Still not able to write the file though, so possibly the problem is at the GIS program end.

I just hoped there was a way to force the overwrite from within the Fortran program (as that is under my control)


0 Kudos
davidspurr
Beginner
504 Views
Yes, I just tried opening the file in Excel & got a message saying the file was locked for editing by 'another user'. Offered 'Read only' access.

Looks like I have to investigate whether the GIS program can link to the file without locking it.

0 Kudos
criga
Beginner
504 Views
Quoting - davidspurr
Yes, I just tried opening the file in Excel & got a message saying the file was locked for editing by 'another user'. Offered 'Read only' access.

Looks like I have to investigate whether the GIS program can link to the file without locking it.


We use Manifold as well, and as far as I know, Maniold locks a file when it links to it. That's why you get the sharing violation. It would be neat to find a way around it.

What I normally do is: Set up a table in Manifold with the same format as your csv file. Link a drawing to that table. I use Crimson Editor as a text editor that does not lock a file, so my code can overwrite it while it's open in Crimson. I cut-and-paste updated data from the text editorinto the table in Manifold (once cleared). Then refresh the drawing. This approach got a few extra steps in it, but I find it still faster than re-linking the csv file every time, or close and reopen Manifold, so it will release the csv file for overwrtiting.

How do you write your CSV files in Fortran though? I'm having a hard time figuring that out. Are there any code examples / references around online?

Thanks, Chris

0 Kudos
Reply