Re: Double-Precision Byte Swap [message #11588] |
Wed, 29 April 1998 00:00 |
rkj
Messages: 66 Registered: February 1996
|
Member |
|
|
R. Kyle Justice (rkj@dukebar.crml.uab.edu) wrote:
: : Assuming that the data are IEEE double-precision (almost certainly), yes, you
: : just need to reverse the order of each number's 8 bytes.
: : (But note that if it's Digital Unix that you're using then you should NOT
: : re-order.)
: : I don't use PV-Wave, but here's a little IDL routine for the job:
: : ;==================================
: : ; Reverse the byte order of a whatever
: : pro byterev,v
: : j=size(v) &nj=n_elements(j) &t=j(nj-2) &n=j(nj-1)
: : if (t le 1) or (t ge 7) then return ;undefined, or inappropriate type
: : case t of
: : 2:byteorder,v,/sswap ;short
: : 3:byteorder,v,/lswap ;long
: : 4:byteorder,v,/lswap ;float
: : 5:begin &for i=0L,n-1L do v(i)=double(rotate(byte(v(i),0,8),2),0) &end ;double
: : 6:byteorder,v,/lswap ;complex (it works, too!)
: : endcase
: : return
: : end
: : ;==================================
: : Peter Mason
: Works like a charm! This ought to be in the user library.
: Thanks.
: Kyle
Actually, a similar routine (wbyteorder.pro) is indeed in the pv-wave
user library. I guess I didn't look hard enough . . . but I still like
the elegance of this solution.
Kyle
|
|
|
Re: Double-Precision Byte Swap [message #11590 is a reply to message #11588] |
Wed, 29 April 1998 00:00  |
rkj
Messages: 66 Registered: February 1996
|
Member |
|
|
: Assuming that the data are IEEE double-precision (almost certainly), yes, you
: just need to reverse the order of each number's 8 bytes.
: (But note that if it's Digital Unix that you're using then you should NOT
: re-order.)
: I don't use PV-Wave, but here's a little IDL routine for the job:
: ;==================================
: ; Reverse the byte order of a whatever
: pro byterev,v
: j=size(v) &nj=n_elements(j) &t=j(nj-2) &n=j(nj-1)
: if (t le 1) or (t ge 7) then return ;undefined, or inappropriate type
: case t of
: 2:byteorder,v,/sswap ;short
: 3:byteorder,v,/lswap ;long
: 4:byteorder,v,/lswap ;float
: 5:begin &for i=0L,n-1L do v(i)=double(rotate(byte(v(i),0,8),2),0) &end ;double
: 6:byteorder,v,/lswap ;complex (it works, too!)
: endcase
: return
: end
: ;==================================
: Peter Mason
Works like a charm! This ought to be in the user library.
Thanks.
Kyle
|
|
|
Re: Double-Precision Byte Swap [message #11595 is a reply to message #11588] |
Tue, 28 April 1998 00:00  |
Peter Mason
Messages: 145 Registered: June 1996
|
Senior Member |
|
|
On 28 Apr 1998, R. Kyle Justice wrote:
> Using PV-Wave in UNIX, is there a way to read
> double-precision floating point data generated
> on a PC?
> I think I need something something similar to
> the BYTEORDER procedure, but I need to (or do I?)
> swap 8 instead of 4 bytes.
Assuming that the data are IEEE double-precision (almost certainly), yes, you
just need to reverse the order of each number's 8 bytes.
(But note that if it's Digital Unix that you're using then you should NOT
re-order.)
I don't use PV-Wave, but here's a little IDL routine for the job:
;==================================
; Reverse the byte order of a whatever
pro byterev,v
j=size(v) &nj=n_elements(j) &t=j(nj-2) &n=j(nj-1)
if (t le 1) or (t ge 7) then return ;undefined, or inappropriate type
case t of
2:byteorder,v,/sswap ;short
3:byteorder,v,/lswap ;long
4:byteorder,v,/lswap ;float
5:begin &for i=0L,n-1L do v(i)=double(rotate(byte(v(i),0,8),2),0) &end ;double
6:byteorder,v,/lswap ;complex (it works, too!)
endcase
return
end
;==================================
Peter Mason
|
|
|