Re: question about readf [message #49623 is a reply to message #49570] |
Fri, 04 August 2006 07:23   |
savoie
Messages: 68 Registered: September 1996
|
Member |
|
|
rlayberry@hotmail.com writes:
> I am trying to get data out of MS-Excel and into IDL as a float array.
>
> I laboriously save each Excel worksheet as a csv.
>
> I then readf the CSV into a float array.
>
> The problem is that there are some missing data values. for example
> ,10.0,,,0.0,10
> so a missing data value is given by two commas next to each other.
> readf assumes no data is there and all my formatting goes to pot. is
> there anyway of getting either excel to write csvs out with dummy
> values (-99.9 for example) or of getting IDL to read in a missing data
> point as a dummy value?
I do this by reading in the entire line first, and then using stregex.
lformat = '(%"%100s")' ; a really long string to read in each line
readf, lun, FORMAT = lformat, line
delimiter = ','
parts = strsplit( line, delimiter, $
count = count, /EXTRACT, /PRESERVE_NULL )
parts = strcompress( parts, /REMOVE_ALL )
nullidx = where( parts eq '', count )
if count gt 0 then begin
parts[ nullidx ] = !values.F_NAN
endif
Just remember the keyword to strsplit: /PRESERVE_NULL.
Hope this helps. If not, I hope someone has a better answer.
Matt
--
Matthew Savoie - Scientific Programmer
National Snow and Ice Data Center
(303) 735-0785 http://nsidc.org
|
|
|