2
$\begingroup$

I have a complicated data set (see the image below), and I need to read the magnitude of Etot from this data set. Any idea how can I do that?

file

$\endgroup$
2
$\begingroup$

Import the data into Mathematica as text, line-by-line:

raw = Import["https://pastebin.com/raw/nhnDApae", {"Text", "Lines"}];

Select the lines that contain Etot:

sl = Select[raw, StringContainsQ[#, "Etot"] &];

Finally, use StringCases[] with NumberString to extract the numerical data, and convert them with ToExpression[]:

etotList = ToExpression[First[StringCases[#, NumberString]], InputForm] & /@ sl
   {-76137.07, -76237.9692, -76166.3972, -76178.2419, -75963.3368}

If you are okay with undocumented functions:

etotList = Internal`StringToDouble[First[StringCases[#, NumberString]]] & /@ sl
$\endgroup$
  • 3
    $\begingroup$ Note that InternalStringToDouble` does not return any error if it fails, but simply 0., which might be a pitfall. $\endgroup$ – Theo Tiger Oct 4 '18 at 19:58
1
$\begingroup$
data = Import["https://pastebin.com/raw/nhnDApae", {"Text", "Lines"}];

Join @@ StringCases[data, "Etot   =" ~~ a__ ~~ "EKtot"  :> ToExpression@ a]

{-76137.07, -76237.9692, -76166.3972, -76178.2419, -75963.3368}

$\endgroup$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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