how do you lock a file in pgf90?

Does anyone know how to lock an open file in pgf90, so that other processes cannot open it?
My fortran90 program is a back-end for a Java GUI which checks for the existence of a file, then opens it – but, often before the file has been closed by the fortran back-end. I want a way to tell the Java front-end to wait until the file is closed.
–Chris @ RPI

Hi Chris,

As far as I know there is nothing in Fortran that allows you to directly lock a file. You could probably use the C system ‘fcntl’ function, but this might be a bit of a headache since you’ll need to write a C interface to both Fortran and Java.

Another solution might be to create a temporary file and have your Java program poll for the existence of the temp file. Once your done writing to the data file, also close the temp file using the CLOSE specifier ‘STATUS=DELETE’ to delete the file. Once the temp file is gone, the front-end knows it can read from the data file.

Hope this helps,