2

I have 101 files each with a lot of data. from C output. (.out files) I have imported them to Mathematica 9. However, Mathematica reads the data from each file as an element of a table. So I used StringSplit, to split the data and it looks like this

{{{"425060", "0.214235E+07", "0.48", "0.01", "0.39", "0.49", "0.01", 
   "0.38", "1.64", "-1.65", "-2.13", "518"}, {"6650479", 
   "0.934695E+06", "0.48", "0.39", "0.43", "0.49", "0.39", "0.44", 
   "2.20", "-0.72", "0.51", "226"}, {"1248079", "0.153025E+07", 
   "0.04", "0.07", "0.30", "0.04", "0.07", "0.31", "-0.44", "-0.52", 
   "3.36", "370"}, {"4482147", "0.595558E+06", "0.39", "0.26", "0.38",
    "0.39", "0.28", "0.41", "0.95", "2.76", "5.47", "144"}, ......

My problem is with the E+07 etc terms, when I try to convert this entire data to expressions, using ToExpression, Mathematica converts E -> e=2.73 and evaluates the value. I have tried using HoldForm and Hold etc, however I do need those values to weed out a large portion of data. I have looked into ImportString, StringReplace etc options that were posted here, however they were for individual strings and not a list.

RunnyKine
  • 33,088
  • 3
  • 109
  • 176
HuShu
  • 439
  • 2
  • 14
  • s = {"425060", "0.214235E+07", "0.48", "0.01", "0.39", "0.49", "0.01", "0.38", "1.64", "-1.65", "-2.13", "518"}; InternalStringToDouble[#] & /@ s`, see http://mathematica.stackexchange.com/questions/1737/how-do-you-convert-a-string-containing-a-number-in-c-scientific-notation-to-a-ma – Nasser Oct 10 '14 at 05:58
  • Thanks, I read that post but I was discouraged by the statement " However, if you are trying to convert many such numbers at once, the standard, documented methods (Import, Read, etc.), are likely to represent better approaches. " – HuShu Oct 10 '14 at 06:12

1 Answers1

4

You can use Internal`StringToDouble:

Map[Internal`StringToDouble, {{"425060", "0.214235E+07", "0.48", 
   "0.01", "0.39", "0.49", "0.01", "0.38", "1.64", "-1.65", "-2.13", 
   "518"}, {"6650479", "0.934695E+06", "0.48", "0.39", "0.43", "0.49",
    "0.39", "0.44", "2.20", "-0.72", "0.51", "226"}, {"1248079", 
   "0.153025E+07", "0.04", "0.07", "0.30", "0.04", "0.07", "0.31", 
   "-0.44", "-0.52", "3.36", "370"}, {"4482147", "0.595558E+06", 
   "0.39", "0.26", "0.38", "0.39", "0.28", "0.41", "0.95", "2.76", 
   "5.47", "144"}}, {2}]

Mathematica graphics

RunnyKine
  • 33,088
  • 3
  • 109
  • 176
  • Thank you very much. Is it possible to apply this for a list of matrices? That's because my data is really a list of matrices, and I have about 100 of such matrices. So I tried Table[Map[Internal`StringToDouble, S[[i]], {2}], {i, 1, 100}], where S[[i]] are the matrices. Thanks. – HuShu Oct 10 '14 at 06:10
  • @NilanjanBanik, no need for that. Just change {2} to {3} in my code but with your list of matrices. – RunnyKine Oct 10 '14 at 06:15
  • @NilanjanBanik. My pleasure. Welcome to MMA.SE! – RunnyKine Oct 10 '14 at 06:41