Re: Reading data, from a file [message #79930] |
Fri, 13 April 2012 04:35 |
Yngvar Larsen
Messages: 134 Registered: January 2010
|
Senior Member |
|
|
On Friday, 13 April 2012 13:05:59 UTC+2, shambhu wrote:
> Hi,
>
> Please check the following code. I want to print the data from the
> first line, but when i assign t=dummy(0) it taking 5th value from the
> dummy. So please help me on this.
>
> dummy = strarr(5)
>
> openr,lun,'cdays.dat.old',/get_lun
>
> for j=0, 2 do begin
> readf,lun,dummy
> ;readf, lun ,dummy(0)
> t=dummy(0) & print,'T val is', t
> print,dummy
> endfor
>
> free_lun,lun
This code is not doing what you think it does. "readf, lun, dummy" will read 5 lines from the data file. Thus, "dummy[0]" will contain the first of these.
You want something like this:
file = 'cdays.dat.old'
nLines = file_lines(file)
data = strarr(nLines)
openr, lun, file, /get_lun
readf, lun, data
free_lun, lun
data = (strsplit(data, /extract)).toarray() ; Requires IDL 8 (loop over lines in IDL 7)
data = double(data)
--
Yngvar
|
|
|