gfortran stdout overwrite

Janne Blomqvist blomqvist.janne@gmail.com
Fri Jan 11 20:36:00 GMT 2019


On Fri, Jan 11, 2019 at 3:32 PM Matthias Redies <m.redies@fz-juelich.de>
wrote:

> Hello,
>
> By setting export GFORTRAN_STDOUT_UNIT=777 I want to change my stdout in
> gfortran. If I run the program
>
>     program main
>        implicit none
>
>        write (*,*) "*"
>        write (6,*) "6"
>        write (777,*) "777"
>     end program main
>
>
> it will output
>
> > $ ./a.out
>  777
>
>
> and create a file:
>
> > $ cat fort.6
>  *
>  6
>
>
> Why isn't * forwarded to the stdout (now 777) anymore? Is this a gfortran
> bug or intended behaviour?
>

As mentioned in the discussion under the stackoverflow question you posted
at https://stackoverflow.com/questions/54147151/changing-stdout-in-gfortran
, a slight modification of your program like

program main
  use iso_fortran_env
  implicit none

  write (*,*) "* ", output_unit
  write (6,*) "6"
  write (777,*) "777"
end program main

allows one to verify that the unit '*' and output_unit are the same. If
they wouldn't be, at least that would be a clear standards conformance bug.

That being said, the current behavior is admittedly nonintuitive. Then
again, if one wanted to fix it to be intuitive, that is, that unit '*' and
output_unit would be specified by GFORTRAN_STDOUT_UNIT, how to do that
isn't clear either since OUTPUT_UNIT is, per the standard, a named constant
and not a variable.

With these constraints, is there any useful function for
GFORTRAN_STDOUT_UNIT, or should it just be removed outright (and same for
GFORTRAN_STDIN_UNIT and GFORTRAN_STDERR_UNIT)?

-- 
Janne Blomqvist



More information about the Fortran mailing list