home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.hp
- Path: sparky!uunet!stanford.edu!ames!nsisrv!climate.gsfc.nasa.gov!merritt
- From: merritt@climate.gsfc.nasa.gov (John H. Merritt)
- Subject: Re: Help for my binary read !!!
- Message-ID: <1992Aug13.200221.27528@nsisrv.gsfc.nasa.gov>
- Sender: usenet@nsisrv.gsfc.nasa.gov (Usenet)
- Nntp-Posting-Host: climate.gsfc.nasa.gov
- Organization: Climate and Radiation Branch
- References: <Aug.12.15.40.21.1992.3094@paul.rutgers.edu> <1159@deere.com>
- Date: Thu, 13 Aug 1992 20:02:21 GMT
- Lines: 44
-
- In article <1159@deere.com>, jrh@de.deere.com (John R. Howell) writes:
- |> 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).
-
- This is only half of the story. The unformatted Fortran records
- on the IRIS machines are encapsulated by the byte count. That is,
- each record has a 4-byte integer value which indicates the length
- of the record, in bytes, that immediately follows, then there is a
- 4-byte integer value following the record which represents the length,
- in bytes, of the data you just saw (only when you read from the begining
- of the file to the end). To illustrate:
-
-
- -----+----------------------+-----+-----+---------------------+-----+
- | n1 | n1 bytes | n1 | n2 | n2 bytes | n2 | etc.
- -----+----------------------+-----+-----+---------------------+-----+
-
- Where the size of n1, n2, etc, is 4 bytes.
-
- Thus, the C code that can writes unformatted Fortran records is:
-
- int iriswrite(FILE *outfile, char *buffer, int n)
- {
-
- /* Write an IRIS fortran unformatted file. */
- fwrite(&n, sizeof(n), 1, outfile);
- fwrite(buffer, sizeof(char), n, outfile);
- fwrite(&n, sizeof(n), 1, outfile);
- /* Return actual number of bytes written; include descriptor bytes. */
- return (n+8);
- }
-
-
-
- \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
- John H. Merritt --> merritt@climate.gsfc.nasa.gov
- "I am generally intolerant of ignorance,
- but I have made an exception in your case."
-