fn@fractal.math.yale.edu (Francois Normant) (04/05/91)
I'm trying to write pure binary files in fortran in order to read them in C. On CRAY 2, I usually open an unformatted file open(unit=70,status='new',form='unformatted',file='foo.out') and call the setpure function to avoid any control characters call setpure(70) The question is: Is there a function equivalent to setpure in xlf (RS6000 fortran) ? Thanks -- Francois Normant - fn@math.yale.edu Yale University - Mathematics Department Box 2155 - Yale Station New Haven CT 06520
mccalpin@perelandra.cms.udel.edu (John D. McCalpin) (04/05/91)
> On 4 Apr 91 16:12:31 GMT, fn@fractal.math.yale.edu (Francois Normant) said:
Francois> I'm trying to write pure binary files in fortran in order to
Francois> read them in C.
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.
--
John D. McCalpin mccalpin@perelandra.cms.udel.edu
Assistant Professor mccalpin@brahms.udel.edu
College of Marine Studies, U. Del. J.MCCALPIN/OMNET
torda@igc.ethz.ch (Andrew Torda ) (04/05/91)
In article <MCCALPIN.91Apr4115200@pereland.cms.udel.edu>, mccalpin@perelandra.cms.udel.edu (John D. McCalpin) writes: > > On 4 Apr 91 16:12:31 GMT, fn@fractal.math.yale.edu (Francois Normant) said: > > Francois> I'm trying to write pure binary files in fortran in order to > Francois> read them in C. > > 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. No. On sun, convex and sgi, each fortran record starts with four bytes which tell you the length of the record that is coming. Each record ends with the same four bytes. On sun and convex, the four bytes tell you how many bytes are coming, on the irises, it is how many words are coming unless you have compiled with an option for backwards compatibility. You can even write fortran binary records on a convex and read them in C on your sun or iris if you are prepared to divide or multiply by 4 (I have forgotten which way it goes). -- Andrew Torda, ETH, Zurich
mccalpin@perelandra.cms.udel.edu (John D. McCalpin) (04/05/91)
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