Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to flush stdout in Fortran 90?

I see a lot online on using the flush function in Fortran to flush output. I am wondering, specifically for Fortran 90, and specifically for stdout, what form this should take as a one-liner to put into my code?

My guess is flush(*).

like image 684
NeutronStar Avatar asked May 26 '16 21:05

NeutronStar


1 Answers

flush() is not a function, but either a non-standard intrinsic subroutine, and hence invoked in a call statement

 call flush(unit_number)

or a standard statement in Fortran 2003, hence invoked as a statement

flush(unit_number)

Commonly, standard output is pre-connected to unit 6, but to be sure you can use the standard constant output_unit from module iso_fortran_env (see Standard input and output units in Fortran 90?)

That again requires Fortran 2003.

Note that almost any compiler nowadays supports these features. But if you really specifically need the 26 years old Fortran 90, then you must consult your compiler's manual, which unit numbers it uses for the pre-connected files. Very likely it will be 6 for standard output.

like image 115
Vladimir F Героям слава Avatar answered Oct 09 '22 08:10

Vladimir F Героям слава