Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to read a file which contains seven columns of real numbers. Mathematica seems to have a problem with the high precision I need.

My code:

solFile = OpenRead["sol_Je9"]; 
data = ReadList[solFile, {Real, Real, Real, Real, Real, Real, Real}];

The error messages:

General::digit: Digit at position 1 in -239.916104094628030 is too large to be used in base 10. ReadList::readn: Invalid real number found when reading from sol_Je9.

How can I fix this?

share|improve this question
Apparently it needs the numbers to be in Fortran format... – cormullion Oct 5 '13 at 10:59
Does Number instead of Real work? – ssch Oct 5 '13 at 11:01
@ssch: Number gives the same error – physicsGuy Oct 5 '13 at 11:03
@Thomas Can you post the file? – R Hall Oct 5 '13 at 11:27
Have you considered Import as alternative ReadList? – m_goldberg Oct 5 '13 at 11:44
up vote 6 down vote accepted

Try using Record and one of the options of ReadList

data = ReadList["filename", Table[Record, {7}], RecordSeparators -> {"\t", "\n"}]

Then use ToExpression to convert the elements (since they have Head String) to Reals.


Or combine both into one line

 data = ToExpression @ ReadList["filename", Table[Record, {7}], RecordSeparators -> {"\t", "\n"}]

Note that I used tabs ("\t") as one of my RecordSeparators, since you haven't posted the files, so I just copied that number and created a look-alike file. You'll have to read in the first few lines of your file and use FullForm and InputForm to see what RecordSeparators you should use. But this should work.

EDIT For completeness here is how you can use InputForm to view the structure of your file and determine what RecordSeparators to use.

You can Read in the first three lines of your file as follows:

ReadList["filename", String, 3]

In my made up file, here is what I get:

{" -239.916104094628030234   -239.916104094628030543     \
-239.916104094628030233", " -239.916104094628030345  \
-239.916104094628030570  -239.916104094628030355", " \
-239.916104094628030678  -239.916104094628030442     \

Then using InputForm gives:

{" -239.916104094628030234\t -239.916104094628030543\t -239.916104094628030233", 
 " -239.916104094628030345\t -239.916104094628030570\t -239.916104094628030355", 
 " -239.916104094628030678\t -239.916104094628030442\t -239.916104094628030654"}

And you can see that "\t" is visible.

Now using

data = ToExpression@ReadList["filename", Table[Record, {3}], RecordSeparators -> {"\t", "\n"}]


   {{-239.916104094628030234, -239.916104094628030543, -239.916104094628030233},  
   {-239.916104094628030345, -239.916104094628030570, -239.916104094628030355}, 
{-239.916104094628030678, -239.916104094628030442, -239.916104094628030654}}

Now, Head[data[[1,1]]] gives Real

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.