Reading Formatted Data
- To: mathgroup at yoda.physics.unc.edu
- Subject: Reading Formatted Data
- From: Patrick Bradshaw <bradshaw at dirac.scri.fsu.edu>
- Date: Fri, 1 Jul 1994 14:49:06 -0500 (EDT)
This is a note regarding my last message about reading in formatted data into Mathematica. First let me say thank you to all those who responded. I got a wealth of responses. However, I'm not sure I was very clear with my original message. The function ReadList or any of the built-in Read functions don't do what I need. (This was suggested by almost everyone, but I had tried it already). I should have made more clear the format of my data: data is organized in columns, *without* decimal places where they should be, and data *isn't* necessarily separated by spaces. For example, if my data file looked like this: 49765 4 1250 98743223 89 with the first series in columns 1-6 with 3 decimal places, the second series in columns 7-8 with no decimal, the next series in columns 9-13, with 2 decimal places, (my real data file is much bigger, this is simply an example-- my file was witten by someone else in Fortran), so this is to be read into a list that looks like this: {{49.765, 4., 12.50}, {987.432, 23., .89}} (note the placement of decimals) As far as I can tell, Mma's ReadList statements can't handle this. The ReadList (and OpenRead) commands will read in data that's delimited by whatever (user's choice) and already has decimals in the proper places (I say this with reasonable assurance but I'm more than willing to stand corrected here). Using the above dataset, ReadList gives me {{49765., 4., 1250.}, {98743223., 89.}} which is not correct. That said, a friend referred me to the book "Applied Mathematica" (authors Shaw and Tigg) that gives a package to do this, it defines a command called FortranRead, and you define a Format statement just like in regular Fortran, so I did end up with the answer to my question after all. (This is a lengthy package-- it's not a trivial thing to do) I'm still open to suggestions, though. Thanks again for the many responses. Patrick Bradshaw bradshaw at dirac.scri.fsu.edu