[comp.sys.sgi] Binary files on 4D machines

blbates@AERO4.LARC.NASA.GOV ("Brent L. Bates AAD/TAB MS361 x42854") (08/16/90)

   Does anyone know if SGI plans on FIXING their FORTRAN, so that
we can write true binary files, the way we can on the 3000's.
This capability is SUPPOSE to be in release 3.3, however, it doesn't
work.  I want to open a file with a command like:

    open(unit,file='filename',form='binary')

   Then write to the file:

    write(unit) data

   Writting to a binary file should be as easy as writing to a
sequential unformatted file, the ONLY thing I should have to
change is the 'form' parameter in the open statement.
--

					Brent

mccalpin@perelandra.cms.udel.edu (John D. McCalpin) (08/16/90)

>>>>> On 15 Aug 90 19:31:14 GMT, blbates@AERO4.LARC.NASA.GOV ("Brent L. Bates AAD/TAB MS361 x42854") said:

"Brent>    Does anyone know if SGI plans on FIXING their FORTRAN, so that
"Brent> we can write true binary files, the way we can on the 3000's.

It ain't broke, so it don't need to be fixed....

The FORTRAN standard does not specify the inner details of a file 
opened with form=unformatted, so vendors are free to do what they
wish.  In this case, SGI (following MIPS, I suppose) decided to
implement what is called a "control-word delimited" file in CDC-land.
Each record in a sequential, unformatted file is preceded and followed
by a 32-bit integer containing the number of bytes in the record.

Three things to keep in mind:
(1) This format is actually very convenient, since it is identical
    to the format used by Sun for sequential unformatted files.
(2) You can get rid of the control words by writing a direct-access
    file instead of a sequential one.  Of course, then the compiler
    expects the records to all be of the same length.
(3) C is often faster for low-level binary I/O, and can be linked
    with the FORTRAN fairly easily.
--
John D. McCalpin			mccalpin@perelandra.cms.udel.edu
Assistant Professor			mccalpin@vax1.udel.edu
College of Marine Studies, U. Del.	J.MCCALPIN/OMNET

blbates@AERO4.LARC.NASA.GOV ("Brent L. Bates AAD/TAB MS361 x42854") (08/16/90)

    We already tried what the FORTRAN release notes say, and it
doesn't work all the time.  We have a person who made a VERY short
program to read a file that worked, but when they tried to do
the same thing in their real program it doesn't work.
    It doesn't seem that much thought went into the "fix".
If they were going to really fix this they should have kept the
same syntax as what is used on the 3000's.
--

	Brent L. Bates
	NASA-Langley Research Center
	M.S. 361
	Hampton, Virginia  23665-5225
	(804) 864-2854
	E-mail: blbates@aero4.larc.nasa.gov or blbates@aero2.larc.nasa.gov

blbates@AERO4.LARC.NASA.GOV ("Brent L. Bates AAD/TAB MS361 x42854") (08/16/90)

   Yes it is broken.  I didn't say to change the UNFORMATTED form.
All I want, and others too, is a binary file.

   (1) I find unformatted very inconvenient.
   (2) Direct-access is even more inconvenient.
   (3) I haven't tried to call C from FORTRAN on our new 4D, yet.
       However, if it is like the 3000's, it will be a royal pain.
--

	Brent L. Bates
	NASA-Langley Research Center
	M.S. 361
	Hampton, Virginia  23665-5225
	(804) 864-2854
	E-mail: blbates@aero4.larc.nasa.gov or blbates@aero2.larc.nasa.gov

calvin@dinkum.wpd.sgi.com (Calvin H. Vu) (08/17/90)

In <9008151931.AA04768@aero4.larc.nasa.gov> blbates@AERO4.LARC.NASA.GOV ("Brent L. Bates AAD/TAB MS361 x42854") writes:


|    Does anyone know if SGI plans on FIXING their FORTRAN, so that
| we can write true binary files, the way we can on the 3000's.
| This capability is SUPPOSE to be in release 3.3, however, it doesn't
| work.  I want to open a file with a command like:
| 
|     open(unit,file='filename',form='binary')
| 
|    Then write to the file:
| 
|     write(unit) data
| 
|    Writting to a binary file should be as easy as writing to a
| sequential unformatted file, the ONLY thing I should have to
| change is the 'form' parameter in the open statement.
| --

In 3.3, there are two new ways to open a file:

1) open(unit,file='filename',form='binary')
	allows you you to read/write binary data using formatted I/O.  E.g:

	I = 10
	write (1, 10) i
10	format(a4)
	rewind(1)
	read(1, 10) j
	print *, i, j
	end
	It is not the same as FORM='BINARY' on the 3000 series, however.

2) open(unit, file='filename', access='direct', recl=1, form='unformatted')
	provides the same capability as opening file with FORM='BINARY'
	on the 3000 series.  There will be no record marks and the file
	is treated as sequence of bytes to be consumed/written.  To make
	this work the program has to be compiled with -old_rl option so
	that the record length is interpreted as the number of bytes (the 
	default is number of words).
	You only need to change the OPEN statement of the 3000 series' Fortran
	to make it work in the same way on the 4D i.e. you only need to 
	modify one line for each opened binary data file.   READ/WRITE 
	statements won't need to be changed. 
	

| 
| 					Brent

There's also a write-up in the release notes for this.   If you experience
any incompatibility besides the cosmetic change in the way the file is opened
please let us know.

- calvin
--
-----------------------------------------------------------------------------
Calvin H. Vu			   | "We are each of us angels with only one
Silicon Graphics Computer Systems  | wing.  And we can only fly embracing
calvin@sgi.com   (415) 962-3679	   | each other."

calvin@dinkum.wpd.sgi.com (Calvin H. Vu) (08/17/90)

In <9008161144.AA07423@aero4.larc.nasa.gov> blbates@AERO4.LARC.NASA.GOV ("Brent L. Bates AAD/TAB MS361 x42854") writes:


|     We already tried what the FORTRAN release notes say, and it
| doesn't work all the time.  We have a person who made a VERY short
| program to read a file that worked, but when they tried to do
| the same thing in their real program it doesn't work.
	If you can't find anything to prove that "binary" file does not
work then the problem may very well be due to something else.  Making
statement like "my real program doesn't work and it must be due to the
the binary file incompatibility somehow" does not help to get the problem,
if any, resolved.

|     It doesn't seem that much thought went into the "fix".
| If they were going to really fix this they should have kept the
| same syntax as what is used on the 3000's.
| --
The FORM='BINARY' enhancement was implemented in 3.2 release already.  In 3.3 
I thought it would be nice to have a compatible file operation to the 3000 
series FORM='binary' so I put it in.  
(Actually, if you read the Fortran programmers' guide, this binary operation 
was in F77 all along and I only needed to make a few changes to make it work
as documented.  So you were right. Not much thought regarding the syntax
was needed for that "fix")
Sorry to hear that it doesn't have a
convenient form for you since I can no longer use FORM='BINARY' for it.  
Maybe running your program through 'sed' could help to convert one syntax 
to another.

I'll probably make something like FORM='SYSTEM' the equivalent of the 3000
series' FORM='BINARY' in the next release to make it more convenient to
use.   How's that for a compromise ?

| 	Brent L. Bates
| 	NASA-Langley Research Center
| 	M.S. 361
| 	Hampton, Virginia  23665-5225
| 	(804) 864-2854
| 	E-mail: blbates@aero4.larc.nasa.gov or blbates@aero2.larc.nasa.gov

Calvin Vu
-------------------------------------------------------------------------
"A little crack in the windshield can be an eyesore but, until proven 
otherwise, it does not cause a malfunction in the engine".
--
-----------------------------------------------------------------------------
Calvin H. Vu			   | "We are each of us angels with only one
Silicon Graphics Computer Systems  | wing.  And we can only fly embracing
calvin@sgi.com   (415) 962-3679	   | each other."

blbates@AERO4.LARC.NASA.GOV ("Brent L. Bates AAD/TAB MS361 x42854") (08/17/90)

    The mail turn around time seems to be kind of long.  My last message
was sent out before I recieved your last message.
    I tried what you said in one of MY programs and it seems to work for
me.  Thanks!  The release notes are not clear at all on what you need to
do, if they had had one sample line for the open statement it would have
been easier.  I don't know why the guy here was/is having a problem with
the binary files.  He talked to the hot line and tried everything they
said but it only half worked.
    If the only thing I had to change was the FORM option on the open
that would be ok.  But, having to put in direct access (which doesn't
make any sense when you think about it), recl=1, FORM='unformatted', and
compile it with a -old_rl option is too much work.  Especially when
the documentation is poor.  Can you get the "FORM='SYSTEM'" in the
3.3.1 release or maybe a 3.3.1.1 or what ever problem fix release?
   Thanks again.

(If the documentation is poor, RTFM wont help)
--

	Brent L. Bates
	NASA-Langley Research Center
	M.S. 361
	Hampton, Virginia  23665-5225
	(804) 864-2854
	E-mail: blbates@aero4.larc.nasa.gov or blbates@aero2.larc.nasa.gov