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

Wait for ... possible?

h-faber
Beginner
804 Views
Hi,
currently I write in a file, close it and directly afterwards I use somewhat like

System('myprogram.exe')

Nothing special so far. The problem now is: myprogram (a second Fortran program) tries to open the file I just created in the main Fortran program. But it seems that the file writing is not finished when myprogram tries to open it. Error message is "cannot open file".
Is there an easy way to wait until the file writing is complete and the file can be accessed by other programs then? I do not want to impelement some stupid dummy loop to win time. Is there a smarter solution possible?
0 Kudos
3 Replies
anthonyrichards
New Contributor III
804 Views
What's wrong with a 'stupid' dummy loop if it does the job?
Logical logopen
logopen=.true.
...
DO WHILE(logopen )
INQUIRE(FILE='filename', err= 9999, OPENED=logopen)
enddo
call systemqq('myprogram.exe filename')
9999 ....
0 Kudos
Steven_L_Intel1
Employee
804 Views
Please put a call to sleepqq in there, to wait for, say, half a second between tries.
0 Kudos
h-faber
Beginner
804 Views
Hi Steve and Anthony,
of course there is nothing wrong with your loop - I just didn't consider this idea. I am still not familiar with the newer Fortran/Library so my idea was much simpler like
DO 200 Z=1, 1000
DO 100 I=1,1000
K =K + 1
100 continue
P = P + 1
200 continue
Your suggestion is much better of course and less "stupid" :)
I turned it into

Code:
      logopen=.true.
      delay = 250
      DO WHILE(logopen)
        INQUIRE(FILE=wkfile, err=999, OPENED=logopen)
        CALL SLEEPQQ(delay)
      enddo

and it works fine. Thanks again.

0 Kudos
Reply