MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: ReadList, mix Words & Numbers?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30934] Re: ReadList, mix Words & Numbers?
  • From: Robert Love <rlove at neosoft.com>
  • Date: Thu, 27 Sep 2001 02:16:54 -0400 (EDT)
  • Organization: Internet America (using Airnews.net!)
  • References: <9oetdp$im0$1@smc.vnet.net> <9ojv4p$m6b$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Mariusz Jankowski  wrote :

>Robert, here is the solution. I used the following approach - read the data
>as a list of records and use string operations to locate the numbers and
>extract.

I didn't catch the error in this method until I tried it for myself.  Every number generated from a string representing a number in "Exponent" form fails to convert correctly.  For example, a string of "  -0.7623174679E-008"  becomes -10.0722

Is there a way I can  correctly convert strings of the form I have to numbers?

Thanks again for all  assistance.




>In[19]:=
>rawdata = Flatten[ReadList["almanac.txt",
>    {Record}]] ;
>
>
>This deletes the header records
>
>In[21]:=
>tmp = Select[rawdata,  !StringMatchQ[#1, "*almanac*"] & ]
>
>
>Here I search each string for the character ":" and extract the number
>In[34]:=
>values = (ToExpression[StringDrop[#1,
>      First[Flatten[StringPosition[#1, ":"]]]]] & ) /@ tmp
>
>Out[34]=
>{1, 0, -0.6150340397452159, 319488., 0.9654515552,
>  -10.072193720509482, 5153.727051, 1.770381612241071,
>  -1.702684969, 0.6520090636422935, -2.4944906649096104,
>  0., 99, 2, 0, -0.4199863658579357, 319488.,
>  0.9324469998, -10.224423843839208, 5153.597656,
>  0.6048908201090217, -2.027413647, 1.537113200919309,
>  -5.244330671054458, -12.977810336677443, 99}
>
>
>Similarly, I extract the label
>
>In[35]:=
>labels =
>  (StringTake[#1, First[Flatten[StringPosition[#1,
>        ":"]]]] & ) /@ tmp
>
>Out[35]=
>{"ID:", "Health:", "Eccentricity:",
>  "Time of Applicability(s):",
>  "Orbital Inclination(rad):",
>  "Rate of Right Ascen(r/s):", "SQRT(A)  (m 1/2):",
>  "Right Ascen at Week(rad):",
>  "Argument of Perigee(rad):", "Mean Anom(rad):",
>  "Af0(s):", "Af1(s/s):", "week:", "ID:", "Health:",
>  "Eccentricity:", "Time of Applicability(s):",
>  "Orbital Inclination(rad):",
>  "Rate of Right Ascen(r/s):", "SQRT(A)  (m 1/2):",
>  "Right Ascen at Week(rad):",
>  "Argument of Perigee(rad):", "Mean Anom(rad):",
>  "Af0(s):", "Af1(s/s):", "week:"}
>
>Here I display the result
>
>In[38]:=
>Transpose[{labels, values}] // TableForm
>
>
>
>Good luck, Mariusz
>



  • Prev by Date: Trinomialtree
  • Next by Date: Re: Export table problem
  • Previous by thread: Re: ReadList, mix Words & Numbers?
  • Next by thread: Re: Re: ReadList, mix Words & Numbers?