home *** CD-ROM | disk | FTP | other *** search
- 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
- From: ake@dayton.saic.com (Earle Ake)
- Newsgroups: comp.lang.fortran
- Subject: Re: swapping bytes on a two byte integer
- Date: 22 Dec 1992 13:35:49 -0500
- Organization: Science Applications Intl Corp - Dayton, Ohio
- Lines: 54
- Message-ID: <1h7n65INNdnm@dayub.dayton.saic.com>
- References: <1712@airgun.wg.waii.com>
- NNTP-Posting-Host: dayton.saic.com
- X-Newsreader: TIN [version 1.1 PL8]
-
- Griff Miller X7114 (miller@hmsp04.wg3.waii.com) wrote:
- : 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
-
- REAL FORTRAN programmers use equivalence statements to get the job
- done with no wasted space!
-
- CHARACTER*2 AWORD
- CHARACTER*1 ABYTE(2)
- EQUIVALENCE (AWORD, ABYTE(1))
-
- READ(1) ABYTE(2), ABYTE(1)
- WRITE(2) AWORD
-
- END
-
-
- : Note: Even though I used all caps, I do not presume to be a
- : Real Programmer. :-)
-
- I am not going by my own rules here but a real FORTRAN programmer does
- not use character variables and only uses 6 spaces at the beginning of the line
- instead of the wimpy tab character that so many compilers allow now. Remember,
- key punches didn't deal with the tab key very well.
-
-
- -Earle
- --
- Earle Ake Internet: <ake@dayton.saic.com> NSI-DECnet (SPAN): 28276::ake
-