Home > Archive > Fortran > December 2004 > Recursive I/O on internal files in Fortran 95?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Recursive I/O on internal files in Fortran 95?
|
|
| Harald Anlauf 2004-12-20, 8:58 am |
| Hi,
what is the status of recursive I/O on internal files in Fortran 95?
I have a book on my desk that is rather unclear on that point and can
be read as allowing it in that particular case.
I checked the F2k3 draft, where in section 9.11 it appears that it is
allowed (now?), although I have a hard time understanding the following
excerpt:
"A recursive input/output statement shall not modify the value of any
internal unit except that a recursive WRITE statement may modify the
internal unit identified by that recursive WRITE statement."
I'm not a native speaker, so can somebody please explain it in some
detail?
In particular, I'd like to know whether the following code is legal:
program test_rec_io
implicit none
character (len=4) :: s
write (s, '(a)') foo (1234)
write (*,*) s
contains
pure recursive function foo (i) result (s)
integer, intent(in) :: i
character (len=4) :: s
! Internal I/O, allowed recursive in f2k3
write (s, '(i4.4)') i
end function foo
end program test_rec_io
None of the compilers I tried complained during compilation with options
set to strictest conformance. But only the runtime of Intel's ifort 8.1
actually printed the (my) expected result. All others failed, i.e., the
runtime trapped the recursion or gave funny results.
--
Cheers,
-ha
| |
| James Van Buskirk 2004-12-20, 3:59 pm |
| "Harald Anlauf" <anlauf@hep.tu-darmstadt.de> wrote in message
news:ubllbtqlid.fsf@heplix.ikp.physik.tu-darmstadt.de...
> what is the status of recursive I/O on internal files in Fortran 95?
It's not allowed. I was kind of shocked to find out that f95
had this totally artifical restriction when I posted some code
on my website that use writes to internal files to compose
output, code that worked on CVF and LF95, and people told me
that it caused errors on other compilers. I had to post a
new version of my code that didn't do recursive I/O to internal
files as your example does. My code would have been OK in f03,
but it recursive I/O to internal files didn't sneak through as
a rider to any TR.
--
write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, &
6.0134700243160014d-154/),(/'x'/)); end
| |
| Richard E Maine 2004-12-20, 8:58 pm |
| Harald Anlauf <anlauf@hep.tu-darmstadt.de> writes:
> what is the status of recursive I/O on internal files in Fortran 95?
Not standard. Some compilers do it anyway.
> I checked the F2k3 draft, where in section 9.11 it appears that it is
> allowed (now?),
Yes. In limitted cases.
> although I have a hard time understanding the following excerpt:
>
> "A recursive input/output statement shall not modify the value of any
> internal unit except that a recursive WRITE statement may modify the
> internal unit identified by that recursive WRITE statement."
>
> I'm not a native speaker, so can somebody please explain it in some
> detail?
It is written pretty obscurely isn't it. I'm on vacation without any
texts here, plus not feeling like spending much time, so I won't
try the word-by-word decomposition. Instead, the simple version is
that you can do recursive I/O in 2 cases.
1. In a UDDTIOP, in which case you are writing to whatever unit number
got passed in.
2. Internal I/O.
In both cases, you have all the "obvious" limitations that you can't
"muck" with something that is in "use" by the parent I/O statement.
One of the things that would be "in use" is the internal file if
the parent I/O statement is an internal one. So you can't "muck
with it".....unless you are in a UDDTIOP and do it via the unit
number passed in, which might represent that internal file.
I'm not sure all that was any more clear than the standard. :-(
But it is probably simpler just to think of it as that if there
is an "obvious" problem, you can't do it... And internal
I/O to external files is not allowed except for the UDDTIOP case.
> In particular, I'd like to know whether the following code is legal:
Nothing that I see wrong (in f2k3) there... though the use of the
name s for 2 unrelated thinsg is confusing.
Not legal in f95. And compilers aren't required to catch that.
--
Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain
|
|
|
|
|