From: kenbell@panix.com (Ken Bell)
Subject: Re: byte swapping to get data readable on a decstations
Date: 11 Nov 1994 04:31:31 -0500 [thread overview]
Message-ID: <39vdlj$944@panix2.panix.com> (raw)
In-Reply-To: EJH.94Nov10084407@larry.gsfc.nasa.gov
In article <EJH.94Nov10084407@larry.gsfc.nasa.gov>,
Edward Hartnett <ejh@larry.gsfc.nasa.gov> wrote:
>
>Howdy all.
>
>We here distribute some floating point (IEEE) data to various
>users. We generate it on a cray and various workstations, and now we
>have a user who wants to read the data from a fortran program on a
>decstation. He complains that he can't do this because of the order
>that the bytes are stored in. Is there any hope that we can help him
>solve his problem?
>--
>Edward Hartnett ejh@larry.gsfc.nasa.gov
> (301) 286-2396 fax: (301) 286-1754
>
>"Tut! Tut!" cried Sherlock Holmes. "You must act, man, or you are
>lost. Nothing but energy can save you. This is no time for dispair."
In C, you can use the swab() function to swap bytes ... exchanges
adjacent even and odd bytes in a given array. It's easy enough
to write such a routine in fortran, something like ...
SUBROUTINE SWAB( A, NBYTES )
REAL*4 A(*)
INTEGER NBYTES
C
REAL*4 NOTVAX, VAX
CHAR*1 SWAPIN(4), SWAPOU(4)
EQUIVALENCE (NOTVAX, SWAPIN)
EQUIVALENCE (VAX, SWAPOU)
C
C "NBYTES" must be even
C
IF (MOD(NBYTES,2) .EQ. 0) THEN
N = NBYTES
ELSE
N = NBYTES - 1
ENDIF
C
DO 10 I = 1, N
NOTVAX = A(I)
SWAPOU(1) = SWAPIN(2)
SWAPOU(2) = SWAPIN(1)
SWAPOU(3) = SWAPIN(4)
SWAPOU(4) = SWAPIN(3)
A(I) = VAX
10 CONTINUE
RETURN
END
--
Ken Bell :: kenbell@panix.com :: (212) 475-4976
======== :: syklb@nasagiss.giss.nasa.gov :: (212) 678-5545
next prev parent reply other threads:[~1994-11-11 9:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
1994-11-10 13:44 byte swapping to get data readable on a decstations Edward Hartnett
1994-11-10 16:07 ` Steve Lionel
1994-11-10 16:47 ` Chuck Campbell
1994-11-11 9:31 ` Ken Bell [this message]
1994-11-14 21:55 ` Eric Frey
1994-11-11 23:18 ` Ken Bell
1994-11-14 14:19 ` Roger Grady
1994-11-16 4:06 ` byte swapping to get data readable on a dec John Lovell
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox