ReadList with mixed strings and numbers
- To: mathgroup at smc.vnet.net
- Subject: [mg34813] ReadList with mixed strings and numbers
- From: Goyder Dr HGD <H.Goyder at rmcs.cranfield.ac.uk>
- Date: Sat, 8 Jun 2002 05:21:23 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
A data capture system gives me an ASCII file which I wish to read into Mathematica for analysis. The file contains strings of useful information, such as date and time of capture and sample rate, followed by data pairs, as approximate numbers in "E" format. The numbers are followed by more strings and then more numbers... What I would like to do is to use a sequence of ReadLists as follows str=OpenRead["filename"]; h1=ReadList[str,String,n1]; d1=ReadList[str,{Number,Number},n2]; h2=ReadList[str,String,n3]; d2=ReadList[str,{Number,Number},n4]; ... however I do not know the size of n1, n2, n3, n4... so I can't do the above. I can do str=OpenRead["filename"]; a=ReadList[str,String]; Close[str] and read everything as a String. I then have to sort out the strings into strings and numbers which I attempt to do using h = {}; d = {}; Do[If[t = Read[StringToStream[a[[i]]], {Number, Number}]; NumberQ[t[[1]]] == True, AppendTo[d, t], AppendTo[h, a[[i]]]], {i,Length[a]}] which works but gives me warning messages and may not be foolproof. Is there a recommended method for reading data which consists of mixed strings and numbers so that the numbers get recognised as numbers and the strings as strings? Thanks Hugh Goyder