comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: question about readf
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: question about readf [message #49565 is a reply to message #49564] Thu, 03 August 2006 02:46 Go to previous messageGo to previous message
rlayberry is currently offline  rlayberry
Messages: 33
Registered: November 2004
Member
Nicolas Decoster wrote:
> 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

I have just been playing, and it seems to work when I do

line to be read...
10,0,,10,10

a=fltarr(6)

readf,1,format='(5f)',a

print,a
10,0,0,10

I now have the probelm that I have some missing headers

line to be read
head1,head2,,head3

and i want to read this into a strarr which gives head1,head2,0,head3

any ideas?
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: can't change PATH preference under Windows?
Next Topic: readcol problems

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Oct 12 10:04:27 PDT 2025

Total time taken to generate the page: 0.48025 seconds