Re: question about readf [message #49701 is a reply to message #49623] |
Fri, 11 August 2006 11:08  |
Paul[2]
Messages: 13 Registered: January 2006
|
Junior Member |
|
|
savoie@nsidc.org wrote:
> 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
I'm now reading .xls files natively in IDL using IDL's COM import
bridge and the Excel Application Object. I *may* be able to preview it
if anyone wants to "alpha" test it. I can't put the code out yet
because we had to enhance one of IDL's internal dlls to make this
possible. Anyone interested in testing it? Is there a project anyone
is working on that could benefit from such functionality?? Contact me
directly for more info: psommer@ittvis.com
|
|
|