[Numpy-discussion] read ascii file from complex fortran format() -- genfromtxt

Pierre GM pgmdevlist@gmail....
Wed Sep 22 06:51:15 CDT 2010

On Sep 21, 2010, at 2:25 PM, Andrew Jaffe wrote:

> Hi all,
> I've got an ascii file with a relatively complicated structure, 
> originally written by fortran with the format:
>     135    format(a12,1x,2(f10.5,1x),i3,1x,4(f9.3,1x),4(i2,1x),3x,
>          1 16(f7.2,1x),i3,3x,f13.5,1x,f10.5,1x,f10.6,1x,i3,1x,
>          2 4(f10.6,1x),
>          2 i2,1x,f5.2,1x,f10.3,1x,i3,1x,f7.2,1x,f7.2,3x,4(f7.4,1x),
>          3 4(f7.2,1x),3x,f7.2,1x,i4,3x,f10.3,1x,14(f6.2,1x),i3,1x,
>          1  3x,2f10.5,8f11.2,2f10.5,f12.3,3x,
>          4 2(a6,1x),a23,1x,a22,1x,a22)
> Note, in particular, that many of the strings contain white space.
> Is there a relatively straightforward way to translate this into  dtype 
> (and delimiter?) arguments for use with genfromtxt or do I just have to 
> do it by hand?

By hand might be the easiest. If possible, try to put the empty spaces at the beginning of the string (eg, your 3x,f13.5 would be 16 characters). Use `autostrip=True`. Use a sequence as delimiter (like in your case (12,11,11,3,10,10,10,10,3,3,10,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,4,16...)), that should be more efficient.

More information about the NumPy-Discussion mailing list