[Fwd: (j3.2006) Fortran 2003 compiler features]

Brooks Moses brooks.moses@codesourcery.com
Wed Feb 7 09:52:00 GMT 2007


Dominique Dhumieres wrote:
> OK, my wording did not reflected what I had in mind:
> 
> (a) assuming the conformity of the recursive IO to the F2003 standard,
> (b) assuming that I want to "optimize" the piece of code:
> 
>> tmp=fun(...)
>> print *, tmp
> 
> to
> 
>> print *, fun(...)
> 
> give me a conforming example of fun(...) giving different outputs
> for the two cases.

You are correct in your earlier conclusion; there is no such example, 
assuming that tmp and fun() are the same type and kind, and are not 
derived types.

> My example does not count for the present
> implementation of gfortran under Linux: the result is the same
> in both cases.  Now what I have in the back of my head, is that
> if my bold and ignorant statement is true, this class of "false"
> recursive IO could be implemented quite easily by using temporaries
> ouside the IO instead of inside.

WRITE(*,*) (fun(i), i=0, 100000)

I think it's more important not to pessimize legal code, however 
pathological, than it is to get illegal code "correct".

> Also if someone can give me an
> example of a nontrivial application of recursive IO, I'll be interested.

Assuming you mean recursive I/O with external units, I'll suggest the 
one case where it _is_ permitted in Fortran 2003 -- user-defined 
derived-type I/O.  Given

   TYPE ALLOCARRAY
     INTEGER, ALLOCATABLE :: VALUES(:)
   END TYPE

you might want to define a derived-type I/O function which reads in an 
integer for the array size, allocates VALUES(), and then reads in the 
relevant number of element values.  Make VALUES() an array of other 
derived types, and this can get as non-trivial as you want:

   TYPE POINT
     REAL :: X, Y, Z
   END TYPE
   TYPE TRIANGLE
     INTEGER :: VERTEX_NUMBER(3)
   END TYPE
   TYPE TRIGRID
     TYPE(POINT), ALLOCATABLE :: VERTEX(:)
     TYPE(TRIANGLE), ALLOCATABLE :: TRIANGLE(:)
   END TYPE

   ! user-defined I/O stuff goes here

   TYPE(TRIGRID) grid
   READ (*,*) grid

- Brooks



More information about the Fortran mailing list