Re: Reading non-standard variable sizes [message #81372] |
Mon, 10 September 2012 11:56 |
Brian Daniel
Messages: 80 Registered: July 2009
|
Member |
|
|
Thanks for your advice Mike and Craig. After trying and failing with double() and swapping endians (which only reverses the answers you get with double(var,0) and double(var,1)), I realized the data is ASCII and the ICD is really describing the number of characters in the string, not the number of bytes in the binary data. But again, thanks for your help.
-B
On Friday, September 7, 2012 4:44:21 PM UTC-4, Brian J. Daniel wrote:
> I'm attempting to read values from a binary file with some strange variable formats. Specifically, I have a field of data that uses 9 bytes. No IDL data format has 9 bytes. I can do the following:
>
>
>
> data = bytarr(9)
>
> ReadU, lun, data
>
>
>
> And lun will be ready to read the next variable, but how do I convert the 9 byte variable into a single 8-byte double number?
>
>
>
> Unfortunately, I can't change the format of this data because its a standard. Thanks for your interest.
>
>
>
> -Brian
|
|
|
Re: Reading non-standard variable sizes [message #81393 is a reply to message #81372] |
Fri, 07 September 2012 20:49  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
On Friday, September 7, 2012 5:23:15 PM UTC-4, Mike Galloy wrote:
> On 9/7/12 2:44 PM, Brian J. Daniel wrote:
>
>> I'm attempting to read values from a binary file with some strange variable formats. Specifically, I have a field of data that uses 9 bytes. No IDL data format has 9 bytes. I can do the following:
>
>>
>
>> data = bytarr(9)
>
>> ReadU, lun, data
>
>>
>
>> And lun will be ready to read the next variable, but how do I convert the 9 byte variable into a single 8-byte double number?
>
>>
>
>> Unfortunately, I can't change the format of this data because its a standard. Thanks for your interest.
>
>>
>
>> -Brian
>
>>
>
>
>
> Check out the DOUBLE function. I think you want something like:
>
>
>
> d = double(data, 0)
>
>
>
> or
>
>
>
> d = double(data, 1)
>
>
>
> depending on which 8 bytes of the 9 bytes are used.
...
And then pray to gods of endianness. A sacrifice at the altar of SWAP_ENDIAN may allow you to receive your wish.
Craig
|
|
|
Re: Reading non-standard variable sizes [message #81397 is a reply to message #81393] |
Fri, 07 September 2012 14:23  |
Michael Galloy
Messages: 1114 Registered: April 2006
|
Senior Member |
|
|
On 9/7/12 2:44 PM, Brian J. Daniel wrote:
> I'm attempting to read values from a binary file with some strange variable formats. Specifically, I have a field of data that uses 9 bytes. No IDL data format has 9 bytes. I can do the following:
>
> data = bytarr(9)
> ReadU, lun, data
>
> And lun will be ready to read the next variable, but how do I convert the 9 byte variable into a single 8-byte double number?
>
> Unfortunately, I can't change the format of this data because its a standard. Thanks for your interest.
>
> -Brian
>
Check out the DOUBLE function. I think you want something like:
d = double(data, 0)
or
d = double(data, 1)
depending on which 8 bytes of the 9 bytes are used.
Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Research Mathematician
Tech-X Corporation
|
|
|