Re: question about readf [message #49567 is a reply to message #49565] |
Thu, 03 August 2006 01:59  |
Nicolas Decoster
Messages: 34 Registered: March 2000
|
Member |
|
|
rlayberry@hotmail.com a �crit :
> 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?
>
> thanks in advance
>
> russ
>
I had the same problem but with ";" instead of ",". Here is an extract
what I am doing :
file = 'data.csv'
openr, lun, file, /get_lun
while not eof(lun) do begin
readf, lun, string
string = strcompress(string) ;; in case there are some
;; spaces or tabs.
strings = strsplit(string, ',', /extract, /preserve_null)
n = n_elements(strings)
tab = fltarr(n)
for i = 0, n - 1 do begin
if (strings[i] eq '') then begin
tab[i] = -99.9
endif else begin
reads, strings[i], value ;; we can't use tab[i]
;; directly, IDL needs
;; a named variable for reads.
tab[i] = value
endelse
endfor
help, tab
print, tab
endwhile
free_lun, lun
If your file contains this line: ",10.0,,,0.0,10", IDL writes:
TAB FLOAT = Array[6]
-99.9000 10.0000 -99.9000 -99.9000 0.00000 10.0000
|
|
|