home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.sys.hp:9243 comp.sys.sgi:12337
- Path: sparky!uunet!deere!jrh@de.deere.com
- From: jrh@de.deere.com (John R. Howell)
- Newsgroups: comp.sys.hp,comp.sys.sgi
- Subject: Re: Help for my binary read !!!
- Message-ID: <1159@deere.com>
- Date: 13 Aug 92 12:58:30 GMT
- References: <Aug.12.15.40.21.1992.3094@paul.rutgers.edu>
- Sender: usenet@deere.com
- Followup-To: comp.sys.hp
- Organization: Deere & Company
- Lines: 51
-
- In article <Aug.12.15.40.21.1992.3094@paul.rutgers.edu>, slu@paul.rutgers.edu (shen lu) writes:
- > I have the following c-code which reads in a binary file
- > generated by Fortran program write: write(10) n1,n2,n3,n4
- > (Here, n1=40,n2=60, n3=17, n4=1)
- >
- > Interestingly, the c-code will give me the following results:
- > 16 40 60 17
- > ^^
- > (What's is 16 doing here ? )
- >
- >
- > What's going on ?
- > I tested both code on SGI IRIS and HP 835 machines, they give the
- > same unmatching results.
- >
- > Could somebody out there give me some hint ?
-
-
- Fortran writes binary data as "records". One record for every write. This
- way you can read just the first variable off of every record, just like
- you can read the first variable off of every line with formatted i/o.
-
- Therefore fortran is "record oriented" which is quite different from C which
- doesn't have records. You just start reading from the beginning. If you
- want a number on a second line, you have to read through everything on
- the first line to get to it.
-
- OK ... In fortran unformatted io, the file has to know where records start
- and end. There are a number of ways to do this and there doesn't appear
- to be much of a standard for this. Under IRIX, I believe the records start
- with a number (4bytes) that tells how many bytes follow for this record. So
- for your example you wrote four Integer*4 values which is 16 bytes. Now
- when you read the first 4byte integer, you get the size of the record. If
- your c code would have read one more integer, you would have picked up the
- next integer you were looking for (1).
-
- An interesting sidelight ...
- I stumbled across this unformatted file record structure back in the old
- SGI 3000 days after staring at many a hexdump. That machine stored
- records differently by using a special "end of record" character. If the
- "end of record" character appeared in the data somewhere, it was escaped
- by a special "escape" character. The current way on the 4D is much
- better IMHO and appears to be more consistant.
-
- I don't know how HP stores unformatted records. Perhaps you should do
- a couple hexdumps (od).
-
- John
-
-
-
-