home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / fortran / 4783 < prev    next >
Encoding:
Internet Message Format  |  1992-12-16  |  1.8 KB

  1. Path: sparky!uunet!airgun!hmsp04.wg3.waii.com!miller
  2. From: miller@hmsp04.wg3.waii.com (Griff Miller X7114)
  3. Newsgroups: comp.lang.fortran
  4. Subject: Re: swapping bytes on a two byte integer
  5. Message-ID: <1712@airgun.wg.waii.com>
  6. Date: 16 Dec 92 21:38:31 GMT
  7. References: <BzB6rI.LI7@acsu.buffalo.edu>
  8. Sender: news@airgun.wg.waii.com
  9. Organization: Western Geo. - Div of Western Atlas Intn'l Inc., Houston, TX
  10. Lines: 57
  11. Nntp-Posting-Host: hmsp04.wg3.waii.com
  12.  
  13. In article <BzB6rI.LI7@acsu.buffalo.edu> acscmaw@ubvmsb.cc.buffalo.edu (MARK WIECZOREK) writes:
  14. >
  15. >I have a very simple problem. I have a binary data file composed of two byte
  16. >integers. After reading the data I would like to change the order of the 
  17. >bytes and write the result to a file. I've looked through the vax fortran
  18. >manuals and couldn't find a way to do this. Any help would be greatly
  19. >appreciated. 
  20. >
  21. >Mark Wieczorek
  22.  
  23. How about: 
  24.  
  25.       CHARACTER*1 CWORK
  26.       CHARACTER*2 C2BYT
  27.       INTEGER IUNIT,OUNIT
  28.  
  29.       IUNIT=1
  30.       OUNIT=2
  31. C (OR WHATEVER)
  32.  
  33.       READ (IUNIT) C2BYT
  34.       CWORK=C2BYT(1:1)
  35.       C2BYT(1:1)=C2BYT(2:2)
  36.       C2BYT(2:2)=CWORK
  37.       WRITE (OUNIT) C2BYT 
  38.  
  39.       END
  40.  
  41. IUNIT and OUNIT should be opened for unformatted I/O .  If, for some
  42. reason, that's not possible or feasible then try:
  43.  
  44.       CHARACTER*1 CWORK
  45.       CHARACTER*2 C2BYT
  46.  
  47.       INTEGER IUNIT,OUNIT
  48.       IUNIT=1
  49.       OUNIT=2
  50. C (OR WHATEVER)
  51.  
  52.       READ (IUNIT,10) C2BYT
  53.    10 FORMAT (A2)
  54.       CWORK=C2BYT(1:1)
  55.       C2BYT(1:1)=C2BYT(2:2)
  56.       C2BYT(2:2)=CWORK
  57.       WRITE (OUNIT,10) C2BYT
  58.  
  59.       END
  60.  
  61. Note: Even though I used all caps, I do not presume to be a 
  62. Real Programmer.  :-)
  63. --
  64. Griff Miller > miller@monarch.wg3.waii.com < use this for email.
  65.  
  66.           *** My opinions are mine, not Western's. ***
  67.  
  68.    "The fear of the Lord is the beginning of knowledge, but 
  69.     fools despise wisdom and discipline."   - Proverbs 1:7 
  70.