home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / sys / hp / 9243 < prev    next >
Encoding:
Internet Message Format  |  1992-08-13  |  2.5 KB

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