How Can Fortran 90 Ensure External Executable Completion Before Proceeding?

  • Context: Fortran 
  • Thread starter Thread starter andredoc
  • Start date Start date
  • Tags Tags
    Fortran90
Click For Summary

Discussion Overview

The discussion revolves around ensuring that an external executable completes its task before a Fortran 90 program attempts to read the output file it generates. Participants explore issues related to file handling, timing, and potential errors in the execution of the external program.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • André describes a problem where the Fortran program reads a text file generated by an external executable before it is fully written, resulting in incomplete data.
  • Some participants suggest that good programming practice requires closing the file after writing, or flushing the buffer to ensure complete data is available before reading.
  • There is a mention of the RUNQQ instruction, which André found unrecognized by the compiler, raising questions about its compatibility with the version of Fortran being used.
  • Mathmate points out that if the external program encounters an error and aborts, the output file may remain incomplete and open, which could lead to the issues described.
  • André later indicates that even using a sleep instruction to delay reading the file does not guarantee that the file is complete, suggesting that the root cause may lie in the external executable's execution rather than the timing of the read operation.

Areas of Agreement / Disagreement

Participants generally agree that the issue may stem from the external executable not completing its task, but there is no consensus on the best method to ensure the file is fully generated before reading it. Multiple views on file handling practices and potential errors in the external program remain unresolved.

Contextual Notes

Limitations include the lack of clarity on the specific behavior of the external executable and its error handling, as well as the potential incompatibility of certain Fortran instructions with the compiler version being used.

andredoc
Messages
5
Reaction score
0
Hello! I’m programming in Fortran 90 using Force, version 3.0.0. beta2 compiler. The program calls an executable external file with the instruction call system (‘name of file’). This executable file calculates the estimation variance of a set of data and automatically generates an output txt file. Then, the program opens the txt file to read the values generated. But, when the program reads the txt file, sometimes the file is still incomplete and some values assume the value of -999 because when the file is open these values aren’t completely generated.

Is there any instruction that allows the code to proceed only when the executable file is finished? I searched the tutorials and found an instruction called runqq with the sintax:
RUNQQ (filename, commandline)

I’ve tryed to run this command on the compiler but the program doesn’t recognize this instruction. Is it because of the compiler I’m using? Can anyone help me?

Thanks in advance

André
 
Technology news on Phys.org
It seems that the file was still open when you tried to access the file.
Good programmig practice would require that the file be closed when there is no more informtion to be written. In case the writer expects to write more later, it would either close and reopen lalter in append mode, or flush the buffer so the file can be read to the end by someone else.
If the version of Fortran you use does not allow flushing of the buffer, you can always close file and reopen it, hoping that no one else took possession of it in the mean time.
 
mathmate said:
It seems that the file was still open when you tried to access the file.
Good programmig practice would require that the file be closed when there is no more informtion to be written. In case the writer expects to write more later, it would either close and reopen lalter in append mode, or flush the buffer so the file can be read to the end by someone else.
If the version of Fortran you use does not allow flushing of the buffer, you can always close file and reopen it, hoping that no one else took possession of it in the mean time.

Mathmate,

the executable external file and the txt file generated by this executable file, are inserted in a do cicle. In each cycle a new txt file is opened, the values are read and the file is closed and deleted.

The problem is that when the txt file (generated automatically by the executable file) is read, it's not completely generated.

The image below ilustrates the problem:

http://1.bp.blogspot.com/_hEyr1VZJRlU/SRl7-aEIqzI/AAAAAAAAADY/O8C_YWziMOo/s1600-h/ilustracao.jpg

Thanks in advance

Best regards

André
 
Last edited by a moderator:
Did you find out why it was not completely generated? The problem seems to lie there.
If there is an error and the program is aborted, then the file will be incomplete and left open.
 
Mathmate, I thought it was because the txt was not fully created when it was read, but now I've found that it wasn't because of that. I use the instruction sleep and found that, even if I delayed the program for a few seconds, the txt file was still incomplete for some iterations. Now I known where to focus, there must be an error on the code somewhere and, as you say, the program is aborted and the file is incomplete and left open.

Thanks mathmate
 
Glad to be of help.
Let us know if you solved your problem.
 

Similar threads

  • · Replies 22 ·
Replies
22
Views
2K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
18K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
30K
  • · Replies 9 ·
Replies
9
Views
9K
Replies
14
Views
4K
  • · Replies 6 ·
Replies
6
Views
5K