Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!wuarchive!mit-eddie!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: 30 Aug 90 06:47:43 GMT References: <46016@masscomp.ccur.com> <1990Aug29.173235.9405@ux1.cso.uiuc.edu> Sender: burley@world.std.com (James C Burley) Organization: The World Lines: 42 In-Reply-To: mcdonald@aries.scs.uiuc.edu's message of 29 Aug 90 17:32:35 GMT 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. Doug MCDonald 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. In Fortran, you can "seek" to a given record (if you've specified this desire in the OPEN statement, I think), but not to a given byte. As far as "HAS to be possible...as C requires it", this statement suggest you think C is written in Fortran? Or maybe I misunderstand what is meant by this. Generally speaking, Fortran demands a lot less from the operating system it runs on in terms of file support than C, even if it demands more from the run-time library to implement all its "features". For example, I remember that PRIMOS couldn't exactly implement C files, since PRIMOS bytes were 8 bits but its file system (like the internal memory organization) was based on 16-bit chunks. If you wrote 21 bytes to a new file, closed it, and later read it, you'd get 22 bytes. Unless they did some trick like check for a zero in the final byte, in which case if you wrote 22 bytes to a new file, the last one being zero, and later read it, you'd get 21 bytes. (If any circa-1982 PRIMOS experts read this and know any different, please let me know how they got around this problem.) To do C correctly, PRIMOS would have needed a change to its file system to add the ability to track file length down to byte granularity. Fortran support, however, rarely requires any changes to any file system, no matter how primitive. In Fortran, you can "seek" to a given record (if you've specified this desire in the OPEN statement, I think), but not to a given byte. James Craig Burley, Software Craftsperson burley@world.std.com