Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!udel!nigel.ee.udel.edu!mccalpin From: mccalpin@perelandra.cms.udel.edu (John D. McCalpin) Newsgroups: comp.lang.fortran Subject: Re: pure binary files in fortran on RS6000 (xlf) Message-ID: Date: 5 Apr 91 14:09:52 GMT References: <29850@cs.yale.edu> <1991Apr5.083950@igc.ethz.ch> Sender: usenet@ee.udel.edu Organization: College of Marine Studies, U. Del. Lines: 64 Nntp-Posting-Host: perelandra.cms.udel.edu In-reply-to: torda@igc.ethz.ch's message of 5 Apr 91 06:39:50 GMT On 4 Apr 91 16:12:31 GMT, fn@fractal.math.yale.edu (Francois Normant) said: > I'm trying to write pure binary files in fortran in order > to read them in C. To which I replied: > On most UNIX workstations, the only way to do this is to open the > file as unformatted and direct access. This is true of the IBM RS/6000, > Sun, and SGI machines. > The obvious disadvantage is that the record lengths must be fixed. > On 5 Apr 91 06:39:50 GMT, torda@igc.ethz.ch (Andrew Torda ) said: Andrew> No. Andrew> On sun, convex and sgi, each fortran record starts with four bytes Andrew> which tell you the length of the record that is coming. Each record Andrew> ends with the same four bytes. This is incorrect. Please note that I said that the file must be opened for *direct access*. If this is done, then no control-words are written to the file. Try it yourself. (See the test code below) Andrew> On sun and convex, the four bytes tell you how many bytes are Andrew> coming, on the irises, it is how many words are coming unless Andrew> you have compiled with an option for backwards compatibility. This is also incorrect. The SGI machines always write the number of *bytes* in the control word. What is selectable by the flag is whether *direct access* record lengths are *specified in the program* in bytes or 32-bit words. The actual format of the binary data file does not change. The Stardent Titan machines use a control word containing the number of 32-bit words in a record. A simple C program can convert this to the more commonly used format. (There might also be a byte-swapping problem, too -- I can't recall off-hand). * ------------- Test code: fred.F ----------------- #ifdef sgi parameter (isize=1) #else parameter (isize=4) #endif open (unit=3,file='foobar',form='unformatted', $ access='direct',recl=isize*4) a = 1.0 b = 2.0 c = 4.0 d = 8.0 write (3,rec=1) a,b,c,d end This produces the following file: -rw-r--r-- 1 mccalpin user 16 Apr 5 09:06 foobar With contents: Offset: 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef 00000000: 3f 80 00 00 40 00 00 00 40 80 00 00 41 00 00 00 |?...@...@...A...| Clearly there are no control words. The file contains only the 4 32-bit floating-point numbers. -- John D. McCalpin mccalpin@perelandra.cms.udel.edu Assistant Professor mccalpin@brahms.udel.edu College of Marine Studies, U. Del. J.MCCALPIN/OMNET