[SciPy-User] Padded data structure

Warren Weckesser warren.weckesser at enthought.com
Sun Feb 21 03:02:09 EST 2010


Miguel de Val Borro wrote:
> On Sat, Feb 20, 2010 at 10:55:59PM -0800, Christopher Barker wrote:
>   
>>> I would like to read padded output files from C structures that look
>>> like this file: http://spec.jpl.nasa.gov/ftp/pub/catalog/catdir.cat 
>>> The second row is a 13 character string that contains whitespaces.  I
>>> have looked at the align option in dtype passed as a parameter to
>>> loadtxt but could not make it work. 
>>>       
>> Since there is whitespace between all those columns, I don't think you 
>> need align.  I suspect that a dtype something like:
>>
>> ('i4', 'S13', 'i4', 'f8', 'f8','f8','f8','f8','f8','f8', 'i2')
>>     
>
> The problem is that the S13 string contains whitespaces, which is also
> the separator between columns. Using this dtype I get the error:
>
> ValueError: invalid literal for float(): v2,2v2,v
>
>   

Any chance you can upgrade your numpy version to the current trunk?  
Somewhere between version 1.3.0 and the current trunk, the 'delimiter' 
argument of genfromtxt() was enhanced to accept a list of field widths.  
The attached script shows how it can be used to read the file "catdir.dat".

Warren


> Miguel
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>   

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: read_catdir.py
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20100221/a81de899/attachment.ksh>


More information about the SciPy-User mailing list