Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!apple!snorkelwacker!bloom-beacon!world!burley From: burley@world.std.com (James C Burley) Newsgroups: comp.lang.fortran Subject: Re: File handling in Fortran 77 Message-ID: Date: 31 Aug 90 07:31:36 GMT References: <46016@masscomp.ccur.com> <1990Aug29.173235.9405@ux1.cso.uiuc.edu> <55875@iuvax.cs.indiana.edu> Sender: burley@world.std.com (James C Burley) Organization: The World Lines: 53 In-Reply-To: bomgard@copper.ucs.indiana.edu's message of 30 Aug 90 19:16:07 GMT In article <55875@iuvax.cs.indiana.edu> bomgard@copper.ucs.indiana.edu (Tim Bomgardner) writes: In article burley@world.std.com (James C Burley) writes: >In article <1990Aug29.173235.9405@ux1.cso.uiuc.edu> mcdonald@aries.scs.uiuc.edu (Doug McDonald) writes: > > This has always bothered me. A file is just a sequence of it, usually > organized as bytes - a text file must be in "bytes". > > So how, in standard Fortran, do you dothe exact analog of the most primitive > file operations - those expressed in C as flavors of get, put, and seek. > It HAS to be possible to do this, as C requires it. > >You don't. Standard Fortran is built on older and more baroque/primitive >file storage technology than C/UNIX. Fortran allows systems to implement >files as consisting of zero or more fixed-length records, in particular. >So while, in C, you can (or could if ANSI C and its libraries ran on such >a system) read and write to arbitrary bytes in the file, in Fortran you >can't do it without using system calls, tricks, or nonstandard usage. > Rubbish. The answer is right there in front of you. Set RECL=1, ACCESS='DIRECT' in the open statement. For those of you who don't believe me, I'll be happy to email you fortran implementations of get, put, and seek that use no tricks whatsoever. Tim Bomgardner What you talk about allows you to read/write a file AS IF it was individually accessible on a character-by-character level. However, it does NOT guarantee you that you're accessing the contents of the file itself on that basis. In fact on most systems on which I've used Fortran, what you get from using the above technique to write, say, 80 bytes, is 240 bytes or some such thing: two bytes to specify some kind of record information (length, type, formatting, whatever) and one byte of data. Some systems even pad to an even byte, so you get 320 bytes. The original questions seemed to be asking about base-level file access on a byte-by-byte basis, which is either promised by standard C or simply implemented by nearly everybody. I haven't been concerned with justifying "joke" or "deficient" systems by pointing out that they can always simulate C's byte-level access by providing a higher layer on top of the system's native layer -- as PRIMOS could (and may) have. C programmers usually demand access to the lowest level organization of files and want to use that level to implement their own organizations. In other words, I doubt you can consistently use the solution you show above to implement the exact same behavior as C's byte-level access on the SAME FILE. Any (or almost any) standard C (with library) implementation can fully implement all Fortran's I/O formats, but I don't think the opposite is true. James Craig Burley, Software Craftsperson burley@world.std.com