Path: utzoo!utgpu!watserv1!watmath!att!rutgers!usc!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!cica!iuvax!copper!bomgard From: bomgard@copper.ucs.indiana.edu (Tim Bomgardner) Newsgroups: comp.lang.fortran Subject: Re: File handling in Fortran 77 Message-ID: <56015@iuvax.cs.indiana.edu> Date: 31 Aug 90 18:42:32 GMT References: <46016@masscomp.ccur.com> <1990Aug29.173235.9405@ux1.cso.uiuc.edu> <55875@iuvax.cs.indiana.edu> Sender: news@iuvax.cs.indiana.edu Organization: Indiana University, Bloomington IN. Lines: 124 In article burley@world.std.com (James C Burley) writes: >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. Accessing a file AS IF it was individually accessible on a char-by-char level is the ONLY way a (disk) file CAN be accessed. Files are accessed by blocks, and SOME layer of software SOMEWHERE peels off the chars for you one at a time. It may be in the operating system (unix), or in another dimension (VMS), or in the language runtime library. >However, it does NOT guarantee you that you're accessing the contents of the >file itself on that basis. I guarantee you're NOT accessing the (disk) file on char-by-char 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. Like you said, it depends on the system. My system stores 80 bytes in 80 bytes. How you open the file will also affect this. See my other post containing the promised source code. >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. I draw a finer distinction between the language and the OS. The lowest level of (disk) file organization is the block, and that's usually NOT what C (or any other) programmers want. C's "byte-level access" is itself a "higher layer on the system's native layer." >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. Well, sure, since C doesn't HAVE any I/O formats. The library is simply an interface to the Unix (style) file system. In any case, take a look at my other post and tell me what you think. >James Craig Burley, Software Craftsperson burley@world.std.com Tim Bomgardner, Software Contortionist (sorry about this:) xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxx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