Tyler wrote: > 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:
In plain Python, you can read each line in to a string, break the string into "words" using split, and then convert the words into variables of the desired types. If you are new to Python, this is an important idiom to learn. I don't know if NumPy has facilities to do this more easily. > I write the files as such: > WRITE(90,'(A30)') fgeo_name > WRITE(90,'(A30)') fmed_name Let me comment on the Fortran code. For the following lines using list-directed output, the compiler has considerable freedom in how it writes the output. I guess you expect the integers nfault and npoint to be written on one line and the vectors xpt and ypt to each be written on separate lines. The compiler could print each number on a separate line and be standard-conforming. This does not matter if you are going to use a Fortran list-directed read to read the file, but it will matter if you are using other languages. I suggest that you use format strings to get more control over the ouptput format before you think about reading the output files in Python. Otherwise you will be trying to hit a moving target. <snip> -- http://mail.python.org/mailman/listinfo/python-list