home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / fortran / 4834 < prev    next >
Encoding:
Internet Message Format  |  1992-12-22  |  1.9 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!sdd.hp.com!network.ucsd.edu!mvb.saic.com!dayton.saic.com!dayton.saic.com!not-for-mail
  2. From: ake@dayton.saic.com (Earle Ake)
  3. Newsgroups: comp.lang.fortran
  4. Subject: Re: swapping bytes on a two byte integer
  5. Date: 22 Dec 1992 13:35:49 -0500
  6. Organization: Science Applications Intl Corp - Dayton, Ohio
  7. Lines: 54
  8. Message-ID: <1h7n65INNdnm@dayub.dayton.saic.com>
  9. References: <1712@airgun.wg.waii.com>
  10. NNTP-Posting-Host: dayton.saic.com
  11. X-Newsreader: TIN [version 1.1 PL8]
  12.  
  13. Griff Miller X7114 (miller@hmsp04.wg3.waii.com) wrote:
  14. : In article <BzB6rI.LI7@acsu.buffalo.edu> acscmaw@ubvmsb.cc.buffalo.edu (MARK WIECZOREK) writes:
  15. : >
  16. : >I have a very simple problem. I have a binary data file composed of two byte
  17. : >integers. After reading the data I would like to change the order of the 
  18. : >bytes and write the result to a file. I've looked through the vax fortran
  19. : >manuals and couldn't find a way to do this. Any help would be greatly
  20. : >appreciated. 
  21. : >
  22. : >Mark Wieczorek
  23.  
  24. : How about: 
  25.  
  26. :       CHARACTER*1 CWORK
  27. :       CHARACTER*2 C2BYT
  28. :       INTEGER IUNIT,OUNIT
  29.  
  30. :       IUNIT=1
  31. :       OUNIT=2
  32. : C (OR WHATEVER)
  33.  
  34. :       READ (IUNIT) C2BYT
  35. :       CWORK=C2BYT(1:1)
  36. :       C2BYT(1:1)=C2BYT(2:2)
  37. :       C2BYT(2:2)=CWORK
  38. :       WRITE (OUNIT) C2BYT 
  39.  
  40. :       END
  41.  
  42.     REAL FORTRAN programmers use equivalence statements to get the job
  43. done with no wasted space!
  44.  
  45.     CHARACTER*2 AWORD
  46.     CHARACTER*1 ABYTE(2)
  47.     EQUIVALENCE (AWORD, ABYTE(1))
  48.  
  49.     READ(1) ABYTE(2), ABYTE(1)
  50.     WRITE(2) AWORD
  51.  
  52.     END
  53.  
  54.  
  55. : Note: Even though I used all caps, I do not presume to be a 
  56. : Real Programmer.  :-)
  57.  
  58.     I am not going by my own rules here but a real FORTRAN programmer does
  59. not use character variables and only uses 6 spaces at the beginning of the line
  60. instead of the wimpy tab character that so many compilers allow now.  Remember,
  61. key punches didn't deal with the tab key very well.
  62.  
  63.  
  64. -Earle
  65. -- 
  66. Earle Ake  Internet: <ake@dayton.saic.com>  NSI-DECnet (SPAN): 28276::ake
  67.