read ascii file from complex fortran format() -- genfromtxt
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? Andrew
Have you tried
http://code.google.com/p/python-fortranformat/
It's not officially released yet but it's probably worth a try.
David H.
On Tue, Sep 21, 2010 at 8:25 AM, Andrew Jaffe
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?
Andrew _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
On 21/09/2010 18:29, David Huard wrote:
Have you tried
http://code.google.com/p/python-fortranformat/
It's not officially released yet but it's probably worth a try.
Well, I noticed it, bugt the website does say "This is a work in progress, a working version is not yet available"! Andrew
David H.
On Tue, Sep 21, 2010 at 8:25 AM, Andrew Jaffe
mailto:a.h.jaffe@gmail.com> 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?
Andrew _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org mailto:NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
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.
participants (3)
-
Andrew Jaffe
-
David Huard
-
Pierre GM