Re: Re: ReadList of Mixed Data Types???
- To: mathgroup@smc.vnet.net
- Subject: [mg12200] Re: [mg12154] Re: ReadList of Mixed Data Types???
- From: Sean Ross <seanross@worldnet.att.net>
- Date: Fri, 1 May 1998 03:08:49 -0400
- References: <199804170740.DAA00258@smc.vnet.net.> <6hrro5$h7c$2@dragonfly.wolfram.com> <199804270546.BAA09588@smc.vnet.net.>
David Keith wrote: > > "ToExpression" is also a technique I have used. In fact, I believe Todd > could read the comma delimited data as Words using ReadList with > WordSeparators->{","}, and then use ToExpression to convert the Words > to integers. > > Unfortunately, this will not work for Reals expressed in Fortran > E-format. The problem is that while ReadList very conveniently > understands E-format, Mathematica in general does not, so neither does > ToExpression. I very frequently use Mathematica to process DOS text > format data files which have been stored by an HP semiconductor > analyzer, which really only wants to record comma delimited data. > > What I *really* need is for ReadList to accept a WordSeperator->{","} > option when reading numbers - - - - but I would be very grateful to > anyone who could point me to a good work-around for this in Mathematica > 3.0. > > Thanks. > > Sean Ross wrote in message <6hrro5$h7c$2@dragonfly.wolfram.com>... > >Todd A. Guillory wrote: > >> > >> I need to read this file into Mathematica: > >> > >> George Washington > >> 1732,2,22 > >> 1777,12,15 > >> 1778,1,20 > >> > >> This is just a test, but the data file format HAS to be this way. I > >> also have to use ReadList. Don't ask! > >> > >> Anyway, I've tried several variations of ReadList with WordSeparator and > >> such NEVER get all the data, just parts. > >> > >> The first record is a string, the remaining three need to be 3-3 part > >> list of numbers. > >> > >> Any suggestions greatly appreciated. > >> > >> email tag@io.com > > > > > >I have also had trouble with ReadList, but I have a work around that has > >never failed me. I read the entire data file in as a string using > >Read[stream,String]. I then use the string manipulation commands to > >massage it into the correct format and use ToExpression at the end to > >convert it into a numerical expression. -- > >Remove the _nospam_ in the return address to respond. > > > > > > To effectively read a list of data in as a string, then use ToExpression, you have to manipulate it a bit first. If you have Fortran type numbers, then do a StringReplace["E"->"10^"] before using ToExpression. The same thing holds for missing commas, braces, double precision notation etc.