阅读Fortran数据 [英] Reading Fortran Data

查看:70
本文介绍了阅读Fortran数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好:


在尝试找到Matlab(或IDL)的开源替代品之后,我现在已经熟悉了Python,并且特别是SciPy,

NumPy和Matplotlib。当我等待交付Travis Oliphant的

NumPy手册时,我有一个关于如何阅读Fortran书面数据中的
的快速问题(希望如此)。 >

数据文件不是二进制文件,而是没有格式化的ASCII文本文件

和混合数据类型(字符串,整数,浮点数)。例如,我在我的Fortran代码中有以下写语句



我这样写文件:

WRITE (90,''(A30)'')fgeo_name

WRITE(90,''(A30)'')fmed_name

WRITE(90,*)nfault,npoint

WRITE(90,*)(xpt(n),n = 1,npoint)

WRITE(90,*)(ypt(n),n = 1, npoint)


和,


WRITE(10,''(A30)'')fname

DO i = 1,nfault

WRITE(10,*)dbn(i),dtn(i),xfwnt(i),yfwnt(i),xfent(i),yfent(i),& ;

& slpvlS(i),slpvlD(i),slpvlT(i),segdp1(i)

END DO

然后我分别将它们读入Fortran:

READ(70,''(A30)'')fgeo_name

READ(70,''(A30)'')fmed_name

READ(70, *)nfault,npoint

READ(70,*)(x(n),n = 1,npoint)

READ(70,*)(y(n) ,n = 1,npoint)


和,


READ(20,''(A30)'')fname

DO i = 1,nfault

READ(20,*)dbn(i),dtn(i),xfwnt(i),yfwnt(i),xfent(i),yfent (i),&

& slpvlS(i),slpvlD(i),slpvlT(i),segdp1(i)

END DO


我还将它们读入IDL以进行可视化使用READF命令。

我想知道如何使用

NumPy将其读入Python。如果这不是微不足道的,请告诉我,我会等到

NumPy手册到货。


干杯,


t。

Hello All:

After trying to find an open source alternative to Matlab (or IDL), I
am currently getting acquainted with Python and, in particular SciPy,
NumPy, and Matplotlib. While I await the delivery of Travis Oliphant''s
NumPy manual, I have a quick question (hopefully) regarding how to read
in Fortran written data.

The data files are not binary, but ASCII text files with no formatting
and mixed data types (strings, integers, floats). For example, I have
the following write statements in my Fortran code:

I write the files as such:
WRITE(90,''(A30)'') fgeo_name
WRITE(90,''(A30)'') fmed_name
WRITE(90,*) nfault,npoint
WRITE(90,*) (xpt(n), n=1,npoint)
WRITE(90,*) (ypt(n), n=1,npoint)

and,

WRITE(10,''(A30)'') fname
DO i=1,nfault
WRITE(10,*) dbn(i),dtn(i),xfwnt(i),yfwnt(i),xfent(i),yfent(i), &
& slpvlS(i),slpvlD(i),slpvlT(i),segdp1(i)
END DO
I then respectively read them into Fortran as:
READ(70,''(A30)'') fgeo_name
READ(70,''(A30)'') fmed_name
READ(70,*) nfault,npoint
READ(70,*) (x(n), n=1,npoint)
READ(70,*) (y(n), n=1,npoint)

and,

READ(20,''(A30)'') fname
DO i=1,nfault
READ(20,*) dbn(i),dtn(i),xfwnt(i),yfwnt(i),xfent(i),yfent(i), &
& slpvlS(i),slpvlD(i),slpvlT(i),segdp1(i)
END DO

I also read them into IDL for visualization using the "READF" command.
I was wondering how I might go about reading this into Python using
NumPy. If this is not trivial, let me know and I''ll just wait until the
NumPy manual arrives.

Cheers,

t.

推荐答案

我不知道这是否有帮助但是(或者为此问题

当前)。 http://cens.ioc.ee/projects/f2py2e/ 优惠一些建议

看起来你也可以用c代码。

Tyler写道:
I don''t know if this is helpfull or not but (or for that matter
current). http://cens.ioc.ee/projects/f2py2e/ offers some suggestions
and it looks like you can use it with c code also.
Tyler wrote:

大家好:


在尝试找到Matlab(或IDL)的开源替代品之后,我现在已经熟悉了Python,特别是SciPy ,

NumPy和Matplotlib。当我等待交付Travis Oliphant的

NumPy手册时,我有一个关于如何阅读Fortran书面数据中的
的快速问题(希望如此)。 >

数据文件不是二进制文件,而是没有格式化的ASCII文本文件

和混合数据类型(字符串,整数,浮点数)。例如,我在我的Fortran代码中有以下写语句



我这样写文件:

WRITE (90,''(A30)'')fgeo_name

WRITE(90,''(A30)'')fmed_name

WRITE(90,*)nfault,npoint

WRITE(90,*)(xpt(n),n = 1,npoint)

WRITE(90,*)(ypt(n),n = 1, npoint)


和,


WRITE(10,''(A30)'')fname

DO i = 1,nfault

WRITE(10,*)dbn(i),dtn(i),xfwnt(i),yfwnt(i),xfent(i),yfent(i),& ;

& slpvlS(i),slpvlD(i),slpvlT(i),segdp1(i)

END DO


然后我分别将它们读入Fortran:

READ(70,''(A30)'')fgeo_name

READ(70,''(A30)'')fmed_name

READ(70,*)nfault,npoint

READ(70,*)(x(n),n = 1,npoint)

READ(70,*)( y(n),n = 1,npoint)


和,


READ(20,''(A30)'')fname

DO i = 1,nfault

READ(20,*)dbn(i),dtn(i),xfwnt(i),yfwnt(i),xfent( i),yfent(i),&

& slpvlS(i),slpvlD(i),slpvlT(i),segdp1(i)

END DO


我还将它们读入IDL以进行可视化使用READF命令。

我想知道如何使用

NumPy将其读入Python。如果这不是微不足道的,请告诉我,我会等到

NumPy手册到货。


干杯,


t。
Hello All:

After trying to find an open source alternative to Matlab (or IDL), I
am currently getting acquainted with Python and, in particular SciPy,
NumPy, and Matplotlib. While I await the delivery of Travis Oliphant''s
NumPy manual, I have a quick question (hopefully) regarding how to read
in Fortran written data.

The data files are not binary, but ASCII text files with no formatting
and mixed data types (strings, integers, floats). For example, I have
the following write statements in my Fortran code:

I write the files as such:
WRITE(90,''(A30)'') fgeo_name
WRITE(90,''(A30)'') fmed_name
WRITE(90,*) nfault,npoint
WRITE(90,*) (xpt(n), n=1,npoint)
WRITE(90,*) (ypt(n), n=1,npoint)

and,

WRITE(10,''(A30)'') fname
DO i=1,nfault
WRITE(10,*) dbn(i),dtn(i),xfwnt(i),yfwnt(i),xfent(i),yfent(i), &
& slpvlS(i),slpvlD(i),slpvlT(i),segdp1(i)
END DO
I then respectively read them into Fortran as:
READ(70,''(A30)'') fgeo_name
READ(70,''(A30)'') fmed_name
READ(70,*) nfault,npoint
READ(70,*) (x(n), n=1,npoint)
READ(70,*) (y(n), n=1,npoint)

and,

READ(20,''(A30)'') fname
DO i=1,nfault
READ(20,*) dbn(i),dtn(i),xfwnt(i),yfwnt(i),xfent(i),yfent(i), &
& slpvlS(i),slpvlD(i),slpvlT(i),segdp1(i)
END DO

I also read them into IDL for visualization using the "READF" command.
I was wondering how I might go about reading this into Python using
NumPy. If this is not trivial, let me know and I''ll just wait until the
NumPy manual arrives.

Cheers,

t.


Er ******* **@msn.com 写道:

我不知道这是否有用但是(或者就此而言)

当前)。 http://cens.ioc.ee/projects/f2py2e/ 优惠一些建议

,看起来你也可以用c代码。
I don''t know if this is helpfull or not but (or for that matter
current). http://cens.ioc.ee/projects/f2py2e/ offers some suggestions
and it looks like you can use it with c code also.



f2py已被折叠成numpy。


-

Robert Kern

我已经开始相信整个世界都是一个谜,一个无害的谜团

由于我们疯狂地试图解释它而变得可怕有一个潜在的真相。

- Umberto Eco

f2py has been folded into numpy.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco


Tyler写道:
Tyler wrote:

你好全部:


在尝试找到Matlab(或IDL)的开源替代品后,我

目前正在熟悉Python,特别是SciPy,

NumPy和Matplotlib。当我等待交付Travis Oliphant的

NumPy手册时,我有一个关于如何阅读Fortran书面数据中的
的快速问题(希望如此)。 >

数据文件不是二进制文件,而是没有格式化的ASCII文本文件

和混合数据类型(字符串,整数,浮点数)。例如,我在我的Fortran代码中有以下写语句:
Hello All:

After trying to find an open source alternative to Matlab (or IDL), I
am currently getting acquainted with Python and, in particular SciPy,
NumPy, and Matplotlib. While I await the delivery of Travis Oliphant''s
NumPy manual, I have a quick question (hopefully) regarding how to read
in Fortran written data.

The data files are not binary, but ASCII text files with no formatting
and mixed data types (strings, integers, floats). For example, I have
the following write statements in my Fortran code:



Konrad Hinsen有一个用于读取此类文件的模块。

http://dirac.cnrs-orleans.fr / ScientificPython /


具体来说,Scientific.IO.FortranFormat。


-

Robert克恩


我开始相信整个世界都是一个谜,一个无害的谜团

由于我们疯狂的解释而变得可怕好像它有一个潜在的真相。

- Umberto Eco

Konrad Hinsen has a module for reading this kind of file.

http://dirac.cnrs-orleans.fr/ScientificPython/

Specifically, Scientific.IO.FortranFormat .

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco


这篇关于阅读Fortran数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆