home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!airgun!hmsp04.wg3.waii.com!miller
- From: miller@hmsp04.wg3.waii.com (Griff Miller X7114)
- Newsgroups: comp.lang.fortran
- Subject: Re: swapping bytes on a two byte integer
- Message-ID: <1712@airgun.wg.waii.com>
- Date: 16 Dec 92 21:38:31 GMT
- References: <BzB6rI.LI7@acsu.buffalo.edu>
- Sender: news@airgun.wg.waii.com
- Organization: Western Geo. - Div of Western Atlas Intn'l Inc., Houston, TX
- Lines: 57
- Nntp-Posting-Host: hmsp04.wg3.waii.com
-
- In article <BzB6rI.LI7@acsu.buffalo.edu> acscmaw@ubvmsb.cc.buffalo.edu (MARK WIECZOREK) writes:
- >
- >I have a very simple problem. I have a binary data file composed of two byte
- >integers. After reading the data I would like to change the order of the
- >bytes and write the result to a file. I've looked through the vax fortran
- >manuals and couldn't find a way to do this. Any help would be greatly
- >appreciated.
- >
- >Mark Wieczorek
-
- How about:
-
- CHARACTER*1 CWORK
- CHARACTER*2 C2BYT
- INTEGER IUNIT,OUNIT
-
- IUNIT=1
- OUNIT=2
- C (OR WHATEVER)
-
- READ (IUNIT) C2BYT
- CWORK=C2BYT(1:1)
- C2BYT(1:1)=C2BYT(2:2)
- C2BYT(2:2)=CWORK
- WRITE (OUNIT) C2BYT
-
- END
-
- IUNIT and OUNIT should be opened for unformatted I/O . If, for some
- reason, that's not possible or feasible then try:
-
- CHARACTER*1 CWORK
- CHARACTER*2 C2BYT
-
- INTEGER IUNIT,OUNIT
- IUNIT=1
- OUNIT=2
- C (OR WHATEVER)
-
- READ (IUNIT,10) C2BYT
- 10 FORMAT (A2)
- CWORK=C2BYT(1:1)
- C2BYT(1:1)=C2BYT(2:2)
- C2BYT(2:2)=CWORK
- WRITE (OUNIT,10) C2BYT
-
- END
-
- Note: Even though I used all caps, I do not presume to be a
- Real Programmer. :-)
- --
- Griff Miller > miller@monarch.wg3.waii.com < use this for email.
-
- *** My opinions are mine, not Western's. ***
-
- "The fear of the Lord is the beginning of knowledge, but
- fools despise wisdom and discipline." - Proverbs 1:7
-