[PYTHON MATRIX-SIG] Reading text files

Jim Phillips jim@ks.uiuc.edu
Tue, 11 Mar 97 12:34:38 -0600


Alan Watson wrote:
> I'm not going to touch text files, but if someone else wants to they
> are welcome to join in.

It has been my dream to be able to emulate the following FORTRAN idiom  
(sorry, I don't remember the syntax very well) in Python.

   READ (FILE,"F4.8, F4.8") A(I), B(I), I=1,100

It would be nice if the fortran formatting codes could be used verbatim.  I  
imagine the call would be something like...

   readFortran(file, "F4.8, F4.8", A[0:100], B[0:100])

A and B would need to be preallocated.  If the format was left out one could  
revert to the fortran "*" format, taking types from the arrays.  I like using  
sub-arrays because then one can do things like:

  I = zeros(100,'i')
  A = zeros((3,100),'f')
  readFortran(file, I, A[0], A[1], A[2])

Of course, there are many issues I haven't though about.  One would also want  
to be able to write these files.  More importantly, it would be nice to be  
able to work with FORTRAN binary files which have cryptic block-header stuff  
attached.  Perhaps those should have their own file class.

I've considered attacking this, but the task seemed to daunting.  Would the  
easiest way be to use the fortran library directly?  This would require people  
to get f2c who don't have fortran, but I imagine code would have to be stolen  
from there anyway, and it could run faster if you had an optimized fortran  
library.

-Jim

_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________