[SciPy-User] SciPy-User Digest, Vol 80, Issue 24

Tom Kuiper kuiper@jpl.nasa....
Tue Apr 13 15:18:24 CDT 2010


> Date: Tue, 13 Apr 2010 13:13:04 -0400
> From: Scott Ransom <sransom@nrao.edu>
>   
...
> On Tuesday 13 April 2010 12:22:12 pm Tom Kuiper wrote:
>   
>> Scott Ransom wrote:
>>     
>>> On Tuesday 13 April 2010 11:39:21 am Tom Kuiper wrote:
>>>       
>>>> Thanks for the tip Robert.
>>>>
>>>> On my 32-bit laptop:
>>>> In [11]: calcsize('HHHH L HHH L d L H')
>>>> Out[11]: 38
>>>>
>>>> On a 64-bit machine:
>>>> In [3]: calcsize('HHHH L HHH L d L H')
>>>> Out[3]: 50
>>>>         
>>> That's probably not because of the padding.  It is likely due to the
>>> fact that longs are 4 bytes on 32-bit machines and 8 bytes on 64-bit
>>> machines.
>>>       
>> I thought of that.  4xL would be the same as Q.  But I'm confused that
>> the 'pads' are not always adjacent to the longs.
>>
>> This works on my 32-bit machine.  (The file was written by the 64-bit
>> machine.)
>>
>> header = unpack_from('=4H L H 4x 2H L 4x d L 4x H',buf)
>>
>> If I changed all the longs to long longs on my 32-bit machine, I don't
>> think it would solve the problem.
>>     
> I think most padding is actually done next to the shorts.  That is because
> the compiler tries to make all of the data align on 4- or more typically
> 8-byte boundaries.  Therefore, if you rearrange and put all the longs
> first, they will naturally be aligned (esp on 64-bit platforms) and the
> first short afterwards will also be aligned automatically.  If you have an
> odd number of shorts, though, there will likely be padding at the end of
> the shorts if you have another datatype afterwards.
>   
You were right the first time Scott and I should just have tried it:

  buf = fd.read(50)
  header = unpack_from('=4H Q HHH Q d Q H',buf)

SPC 13 VSR 1 channel 6 b/s 8
1000000 samps/sec
error flag 0
date/time 2010 100 83760
Frequency: 32024000000.0
Averages/sec: 1000
2 subchannels

All the right numbers without padding!

Thanks

Tom



More information about the SciPy-User mailing list