pure binary files in fortran on RS6000 (xlf)

John D. McCalpin mccalpin at perelandra.cms.udel.edu
Thu May 23 05:54:27 AEST 1991


>On 22 May 91 19:04:38 GMT,freese at dalvm41b.vnet.ibm.com (Bradley Freese) said:

Bradley> fn at fractal.math.yale.edu (Francois Normant) writes:

> 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) ?

Bradley> No, xlf does not have such a function.  However, xlf does not
Bradley> add any extraneous characters to an unformatted file (other
Bradley> than an EOF record).  It only writes the data you write to
Bradley> the file.

------------------
This is *wrong*!

When a file is opened with open(unit=70,form='unformatted'), the
Fortran run-time system places control words in the output file before
and after each record.  The control word is a 32-bit integer which is
set to the number of *bytes* in the record.

This behavior is compatible with Sun and Silicon Graphics systems.

-----------------
If you want a *pure binary* file from xlf, you have to open the file
with
	open(unit=70,form='unformatted',access='direct',recl=NNN)

where NNN is the number of *bytes* that you are going to write in each
*fixed-length* record.

This behavior is compatible with Sun systems.  It is almost compatible
with Silicon Graphics systems, which by default specify the record
length in *words* instead of bytes.

I use a library routine on each machine to allow portable source:
	integer sizeof
	external sizeof
	open(unit=70,form='unformatted',access='direct',
     $		recl=sizeof('REAL')*NNN)

where NNN is the number of REAL variables per record.  On my IBM and
Sun machines I have written a sizeof routine that returns the number 4
for an argument of 'REAL', while on the SGI machines it returns 1.
I have placed the sizeof() function in a local library
/usr/lib/libocal.a which is accessed by the '-local' flag on the 
xlf command line....
--
John D. McCalpin			mccalpin at perelandra.cms.udel.edu
Assistant Professor			mccalpin at brahms.udel.edu
College of Marine Studies, U. Del.	J.MCCALPIN/OMNET



More information about the Comp.unix.aix mailing list