comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Byte Swapping
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Byte Swapping [message #37023] Thu, 20 November 2003 16:20
Richard French is currently offline  Richard French
Messages: 173
Registered: December 2000
Senior Member
On 11/20/03 3:27 PM, in article MPG.1a26d18d7232577998974f@news.frii.com,
"David Fanning" <david@dfanning.com> wrote:

> Mike W writes:
>
>> I am having trouble converting binary data from little endian to big
>> endian. Here are my commands:
>>
>> brr=fltarr(1090,820)
>> byteorder,brr,/swap_if_big_endian
>> openr,1,'ndvi0006.d'
>> readu,1,brr
>> close,1
>>
>> and I get this error message as well:
>>
>> % READU: End of file encountered. Unit: 1, File: ndvi0006.d
>> % Execution halted at: $MAIN$
>

In your example, you are swapping a zero-filled array BEFORE you actually
read the data. If you want to use byteorder, you have to do it AFTER you
read the data. Or, you can use the /swap_if_big_endian on the openr command,
as others have pointed out.
Dick French
Re: Byte Swapping [message #37025 is a reply to message #37023] Thu, 20 November 2003 14:35 Go to previous message
bc25 is currently offline  bc25
Messages: 1
Registered: November 2003
Junior Member
mwatson@met.fsu.edu (Mike W) wrote in message news:<eb94e153.0311201151.428e6819@posting.google.com>...
> I have a large set of data that apparently was created on a little
> endian platform. I am working on a big endian platform and cannot get
> the data to read in correctly. These are my commands:
>
> brr=fltarr(1090,820)
> byteorder,brr,/swap_if_big_endian
> openr,1,'ndvi0006.d'
> readu,1,brr
> close,1
>
> and i get this error message:
>
> % READU: End of file encountered. Unit: 1, File: ndvi0006.d
> % Execution halted at: $MAIN$
>
> The data is not read correctly and is also very important when I do
> convert the data. I should get values in the array from -1 to 1. The
> negative values seem to be OK but the positive values are much too
> large. The data works fine when it was read on a little endian machine
> so that is why I assumed that this is the byte order of the data. Any
> help would be greatly appreciated.
>
> -Mike Watson
> -Florida State University

You may want to try:

brr=fltarr(1090,820)
openr,inunit,fname,/GET_LUN,/SWAP_IF_BIG_ENDIAN
readu,inunit,brr
FREE_LUN,inunit

This works for me on Mac, Unix and PC reading data written by a PC.
Re: Byte Swapping [message #37032 is a reply to message #37025] Thu, 20 November 2003 12:27 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Mike W writes:

> I am having trouble converting binary data from little endian to big
> endian. Here are my commands:
>
> brr=fltarr(1090,820)
> byteorder,brr,/swap_if_big_endian
> openr,1,'ndvi0006.d'
> readu,1,brr
> close,1
>
> and I get this error message as well:
>
> % READU: End of file encountered. Unit: 1, File: ndvi0006.d
> % Execution halted at: $MAIN$

Not sure I can help with the READU error,
but I'm pretty sure you want this instead of
what you have:

brr = fltarr(1090,820)
openr, 1, ,'ndvi0006.d',/swap_if_big_endian
readu,1,brr
close,1

Cheers,

David
--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: PostScript output from iTools
Next Topic: Re: IDLWave Reference Card?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:37:30 PDT 2025

Total time taken to generate the page: 0.00531 seconds