Path: utzoo!attcan!uunet!wuarchive!julius.cs.uiuc.edu!apple!amdahl!key!sjc From: sjc@key.COM (Steve Correll) Newsgroups: comp.lang.fortran Subject: Re: record length for direct access files (corrected) Message-ID: <2152@key.COM> Date: 1 Oct 90 23:50:19 GMT References: <2146@key.COM> <2151@key.COM> Organization: Key Computer Labs, Fremont, CA Lines: 58 I may or may not have posted a half-finished message on this subject (postnews somehow grabbed the wrong file, placed it in our /usr/spool/news directory, and then gave me a "no message posted" message). Here's a more concise version, with errors corrected. Please ignore the first one if you got it, and accept my apology for whatever it was I did wrong: ======================================= Thanks for bringing INQUIRE/IOLENGTH to my attention. I have a couple of questions for Fortran 90 experts: 1. Is there anything in the Fortran 90 standard which forbids the following? (The intent is to write an element-count "icnt" followed by that number of elements of an array). dimension x(5000) integer record_length ... read *, icnt inquire(iolength=record_length) icnt, (x(j), j=1, icnt) open(unit=io, file='myfile', form='unformatted', & access='direct', recl=record_length, & status='new', action='readwrite') write(unit=io,rec=1) icnt, (x(j), j=1, icnt) close(unit=io) 2. If that example is legal, then I believe it's not possible to compute at compilation time how long the records will actually be. Is it intended that the INQUIRE/IOLENGTH construct be computed at execution time rather than at compilation time? 3. Now suppose another program wants to read the file back in. Is there anything in the Fortran 90 standard that forbids the following example? inquire(iolength=record_length) icnt, (x(j), j=1, icnt) open(unit=ii, file='myfile', form='unformatted', & access='direct', recl=record_length, & status='old', action='readwrite', iostat=iostat) read(unit=ii) icnt, (x(j), j=1, icnt) 4. If that example is legal, then is the compiler allowed to give the "wrong" answer by using the value of "icnt" at the time of the INQUIRE/IOLENGTH statement even though that value will change during the READ statement? S8.115 section 9.6.3 says INQUIRE/IOLENGTH computes a suitable record length for "input/output statements with the same input/output list", as if it were always possible to do so correctly. (Incidentally, a less perverse example which _is_ computable at compilation time, but not trivially so, is the following, which writes a triangular portion of a matrix. Any guesses on how many Fortran 90 compilers will get this stuff wrong the first time out?) dimension x(5000, 5000) inquire(iolength=il) ((x(i, j), i=1, j), j=1, 5000) ... write(unit=io) ((x(i, j), i=1, j), j=1, 5000) -- sjc@key.com or ...{sun,pyramid}!pacbell!key!sjc Steve Correll