call system command


I have a question regarding using “call system” to invoke an external Linux program in a piece of Fortran code. I am wondering if there is a way to have the compiler wait for the command wrapped in “call system” to finish before executing the following lines in the Fortran code.

In my Fortran code, I use “call system” to use a software called Ferret to spatially interpolate an input dataset onto a new grid and write the regridded data into an output file. The rest of the Fortran code then read that file to extract the regridded data. I suspect that, often times, the program starts reading the Ferret output file too soon before that file is fully written, which gives erroneous results. I am wondering if I can mandate the compiler to wait for the command invoked by “call system” to finish before executing the rest of the code. Any suggestions?


Hi Guangyu,

The “system” call in Fortran is just a wrapper to the C “system” call. The program will block waiting for this call to finish so I suspect something else is wrong. Exactly what, I’m not sure.