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

write(*,*) in function called by another write(*,*)

Simon1
Principiante
2.077 Vistas

Hello,

I used to put some "write(*,*)" in my code when I want quick and easy checks of what is happening.

Today I encountered an error while doing this with ifort :

Here the sample program :

program test
implicit none

write(*,*) func(),func()

contains

function func()
real(8) :: func
func=0.d0
write(*,*) "Inside func"
end function func

And the output:
 forrtl: severe (40): recursive I/O operation, unit -1, file unknown

I guess, someway the compiler get lost with a write to * inside a write to *.
Indeed if I change write(*,*) "Inside func" to write(6,*) "Inside func" (6 being preconnected to the default output), the error disappears.

Changing to

write(*,*) func()
write(*,*) func()

in the main part is ok too.

Am I missing something in write mechanism that should forbide me to use it this way ?

Gfortran compile and execute without error the code.
Ifort version 14.0.2

Simon.

0 kudos
1 Solución
Steven_L_Intel1
Empleados
2.077 Vistas

The standard does not allow you to start an I/O operation on a unit while another operation is already in progress. In ifort, by default, unit * and unit 6 are not the same unit. gfortran apparently has an extension to allow you to do this, but it is an extension.

Ver la solución en mensaje original publicado

5 Respuestas
Steven_L_Intel1
Empleados
2.078 Vistas

The standard does not allow you to start an I/O operation on a unit while another operation is already in progress. In ifort, by default, unit * and unit 6 are not the same unit. gfortran apparently has an extension to allow you to do this, but it is an extension.

Simon1
Principiante
2.077 Vistas

Ok, thanks for the answer, I didn't know that but It makes sense.

I suppose that even if the second change (only one write(*,*) func() per line) works fine, it is incorrect and should not be used.

Steven_L_Intel1
Empleados
2.077 Vistas

Technically, that is also not allowed.

jimdempseyatthecove
Colaborador Distinguido III
2.077 Vistas

For tracing purposes, you could call the appropriate C runtime library routine directly (after formatting to "internal file"/text variable).

Jim Dempsey

Simon1
Principiante
2.077 Vistas

Hello Jim.

I'm not certain to well understand your suggestion.
Can you develop a little more ?

Responder