MathGroup Archive 2002

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

Search the Archive

RE: ReadList of Data containing "nan"

  • To: mathgroup at smc.vnet.net
  • Subject: [mg32827] RE: [mg32798] ReadList of Data containing "nan"
  • From: David.Annetts at csiro.au
  • Date: Thu, 14 Feb 2002 01:43:52 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Adalbert,

> from a measuring instrument, I get an tab-delimited ASCII 
> file of records, each consisting of five numbers.
> 
> Up to now, I used to read those records like this (I 
> deliberately skip the first two lines):
> 
>        fil=OpenRead[fileName];
>        liste={};				(* start with 
> an empty list *)
>        Read[fil,String];		(* skip the first and the   *)
>        str=Read[fil,String];		(* second line in the file  *)
>        While[(str=Read[fil,String])=!=EndOfFile
>             ,strstr=StringToStream[str];
>              zeile=ReadList[strstr, Real, WordSeparators->{"\t"}];
>              Close[strstr];
>              liste=Append[liste,zeile];
>             ];
>       Close[fil];
>       (* now liste contains all the data from the file *)
> 
> This works fine for me. Now I am getting results, which have 
> lines, where one or more of the numbers in a line are "nan" 
> because of an out-off-range condition of the measuring 
> instrument. I want to read those lines nevertheless, but I 
> want the "nan"-items be represented by Indeterminate in Mathematica.
> 
> Which is the best way to read all the data simultaneously 
> converting the figures "nan" to Indeterminate in Mathematica?

After the header lines, you might try reading your file as a series of words
-- 
	wdata = ReadList[fil, Word];

Next, perform a global string replacement --
	rdata = StringReplace[#, {"NAN"->"Indeterminate"}]& /@ rdata;

The final step should be something like --
	fdata = ToExpression[rdata];

No, it's not a single step, but it should be straightforward ....

Regards,

Dave.
--------------------------------------------------------
  Dr. David Annetts             EM Modelling Analyst
  Tel: (+612) 9490 5416         CSIRO DEM, North Ryde
  Fax: (+612) 9490 5467         David.Annetts at csiro.au
--------------------------------------------------------


  • Prev by Date: RE: ReadList of Data containing "nan"
  • Next by Date: Mathematica, sounds and placing graphics
  • Previous by thread: RE: ReadList of Data containing "nan"
  • Next by thread: Generate expression from result