home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / hp / 9263 < prev    next >
Encoding:
Text File  |  1992-08-13  |  2.4 KB  |  57 lines

  1. Newsgroups: comp.sys.hp
  2. Path: sparky!uunet!stanford.edu!ames!nsisrv!climate.gsfc.nasa.gov!merritt
  3. From: merritt@climate.gsfc.nasa.gov (John H. Merritt)
  4. Subject: Re: Help for my binary read !!!
  5. Message-ID: <1992Aug13.200221.27528@nsisrv.gsfc.nasa.gov>
  6. Sender: usenet@nsisrv.gsfc.nasa.gov (Usenet)
  7. Nntp-Posting-Host: climate.gsfc.nasa.gov
  8. Organization: Climate and Radiation Branch
  9. References: <Aug.12.15.40.21.1992.3094@paul.rutgers.edu> <1159@deere.com>
  10. Date: Thu, 13 Aug 1992 20:02:21 GMT
  11. Lines: 44
  12.  
  13. In article <1159@deere.com>, jrh@de.deere.com (John R. Howell) writes:
  14. |> OK ... In fortran unformatted io, the file has to know where records start
  15. |> and end.  There are a number of ways to do this and there doesn't appear
  16. |> to be much of a standard for this.  Under IRIX, I believe the records start
  17. |> with a number (4bytes) that tells how many bytes follow for this record. So
  18. |> for your example you wrote four Integer*4 values which is 16 bytes. Now
  19. |> when you read the first 4byte integer, you get the size of the record. If
  20. |> your c code would have read one more integer, you would have picked up the
  21. |> next integer you were looking for (1).
  22.  
  23. This is only half of the story.  The unformatted Fortran records
  24. on the IRIS machines are encapsulated by the byte count.  That is,
  25. each record has a 4-byte integer value which indicates the length
  26. of the record, in bytes,  that immediately follows, then there is a
  27. 4-byte integer value following the record which represents the length,
  28. in bytes, of the data you just saw (only when you read from the begining
  29. of the file to the end).  To illustrate:
  30.  
  31.  
  32. -----+----------------------+-----+-----+---------------------+-----+
  33. | n1 |   n1 bytes           | n1  | n2  |  n2 bytes           | n2  | etc.
  34. -----+----------------------+-----+-----+---------------------+-----+
  35.  
  36. Where the size of n1, n2, etc, is 4 bytes.
  37.  
  38. Thus, the C code that can writes unformatted Fortran records is:
  39.  
  40. int iriswrite(FILE *outfile, char *buffer, int n)
  41. {
  42.  
  43.   /* Write an IRIS fortran unformatted file. */
  44.   fwrite(&n, sizeof(n), 1, outfile);
  45.   fwrite(buffer, sizeof(char), n, outfile);
  46.   fwrite(&n, sizeof(n), 1, outfile);
  47. /* Return actual number of bytes written; include descriptor bytes. */
  48.   return (n+8);
  49. }
  50.  
  51.  
  52.  
  53. \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
  54. John H. Merritt --> merritt@climate.gsfc.nasa.gov
  55. "I am generally intolerant of ignorance,
  56. but I have made an exception in your case."
  57.